1 |
gforget |
1.1 |
function [varargout]=profile_read_argo(dataset,nf,m); |
2 |
|
|
|
3 |
|
|
fileIn=[dataset.dirIn dataset.fileInList(nf).name]; |
4 |
|
|
|
5 |
|
|
%output: |
6 |
|
|
% ymd hms imonth lat lon direc p t s p_ERR t_ERR s_ERR |
7 |
|
|
|
8 |
|
|
%common block: |
9 |
|
|
global PLATFORM_NUMBER_fillval PLATFORM_NUMBER; |
10 |
|
|
global VECdateOBS LATITUDE LONGITUDE DIRECTION; |
11 |
|
|
global PRES PRES_ADJUSTED PRES_ADJUSTED_QC PRES_fillval PRES_QC; |
12 |
|
|
global TEMP TEMP_ADJUSTED TEMP_ADJUSTED_QC TEMP_fillval TEMP_QC TEMP_ADJUSTED_ERROR; |
13 |
|
|
global PSAL PSAL_ADJUSTED PSAL_ADJUSTED_QC PSAL_fillval PSAL_QC PSAL_ADJUSTED_ERROR; |
14 |
|
|
|
15 |
|
|
|
16 |
|
|
if m==0; |
17 |
gforget |
1.2 |
%read the file and put the data in common blocks: |
18 |
|
|
|
19 |
|
|
clear PRES* PSAL* TEMP*; |
20 |
|
|
global PRES PRES_ADJUSTED PRES_ADJUSTED_QC PRES_fillval PRES_QC; |
21 |
|
|
global TEMP TEMP_ADJUSTED TEMP_ADJUSTED_QC TEMP_fillval TEMP_QC TEMP_ADJUSTED_ERROR; |
22 |
|
|
global PSAL PSAL_ADJUSTED PSAL_ADJUSTED_QC PSAL_fillval PSAL_QC PSAL_ADJUSTED_ERROR; |
23 |
|
|
TEMP=8888*ones(500,1);PSAL=8888*ones(500,1); |
24 |
|
|
|
25 |
|
|
%WHAT IS WRONG HERE??? |
26 |
|
|
%if ( rep_nb~=1|isempty(findstr(fileIn,'20050911_prof')) ) |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
eval(['ncload ' fileIn ';']); |
30 |
|
|
|
31 |
|
|
%some dimensions inversions exist for _QC variables (!?) |
32 |
|
|
if size(PRES_QC,1)~=size(PRES,1) |
33 |
|
|
PRES_QC=PRES_QC'; |
34 |
|
|
if ~isempty(who('PRES_ADJUSTED_QC'));PRES_ADJUSTED_QC=PRES_ADJUSTED_QC';end; |
35 |
|
|
if ~isempty(who('PSAL_QC'));PSAL_QC=PSAL_QC';end; |
36 |
|
|
if ~isempty(who('PSAL_ADJUSTED_QC'));PSAL_ADJUSTED_QC=PSAL_ADJUSTED_QC';end; |
37 |
|
|
if ~isempty(who('TEMP_QC'));TEMP_QC=TEMP_QC';end; |
38 |
|
|
if ~isempty(who('TEMP_ADJUSTED_QC'));TEMP_ADJUSTED_QC=TEMP_ADJUSTED_QC';end; |
39 |
|
|
end |
40 |
|
|
|
41 |
|
|
if size(PLATFORM_NUMBER,1)~=size(PRES,1); PLATFORM_NUMBER=PLATFORM_NUMBER'; end; %' |
42 |
|
|
|
43 |
|
|
%get the fillvalues: |
44 |
|
|
global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
45 |
|
|
if (useNativeMatlabNetcdf); |
46 |
|
|
ncid=netcdf.open(fileIn,'nowrite'); |
47 |
|
|
vv = netcdf.inqVarID(ncid,'PRES'); PRES_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); |
48 |
|
|
if PSAL(1,1) ~= 8888; vv = netcdf.inqVarID(ncid,'PSAL'); PSAL_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); end; |
49 |
|
|
if TEMP(1,1) ~= 8888; vv = netcdf.inqVarID(ncid,'TEMP'); TEMP_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); end; |
50 |
|
|
vv = netcdf.inqVarID(ncid,'PLATFORM_NUMBER'); PLATFORM_NUMBER_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); |
51 |
|
|
netcdf.close(ncid); |
52 |
|
|
else;%try to use old mex stuff |
53 |
gforget |
1.1 |
nc = netcdf(fileIn, 'nowrite'); |
54 |
|
|
PRES_fillval=fillval(nc{'PRES'}); |
55 |
|
|
if PSAL(1,1) ~= 8888; PSAL_fillval=fillval(nc{'PSAL'});end; |
56 |
|
|
if TEMP(1,1) ~= 8888; TEMP_fillval=fillval(nc{'TEMP'});end; |
57 |
|
|
PLATFORM_NUMBER_fillval=fillval(nc{'PLATFORM_NUMBER'}); |
58 |
|
|
nc = close(nc); |
59 |
gforget |
1.2 |
end; |
60 |
gforget |
1.1 |
|
61 |
gforget |
1.2 |
|
62 |
|
|
if size(REFERENCE_DATE_TIME,1)>1; REFERENCE_DATE_TIME=REFERENCE_DATE_TIME'; end; |
63 |
|
|
REFdateOBS=str2num(strvcat(REFERENCE_DATE_TIME(1:4),REFERENCE_DATE_TIME(5:6),REFERENCE_DATE_TIME(7:8),REFERENCE_DATE_TIME(9:10),REFERENCE_DATE_TIME(11:12),REFERENCE_DATE_TIME(13:14)))';%' |
64 |
|
|
REFdateOBS=jul_0h(REFdateOBS); |
65 |
|
|
VECdateOBS=REFdateOBS+JULD; |
66 |
|
|
|
67 |
|
|
xx=size(PRES);mloc=xx(1);mpts=xx(2); |
68 |
|
|
|
69 |
|
|
varargout(1) = {length(LONGITUDE)}; |
70 |
|
|
|
71 |
gforget |
1.1 |
else;%if m==0; |
72 |
gforget |
1.2 |
%select one profile for output: |
73 |
|
|
|
74 |
|
|
%date, position, etc |
75 |
|
|
|
76 |
|
|
tmp1=greg_0h(VECdateOBS(m)); |
77 |
|
|
ymd=tmp1(1)*1e4+tmp1(2)*1e2+tmp1(3); |
78 |
|
|
hms=tmp1(4)*1e4+tmp1(5)*1e2+tmp1(6); |
79 |
|
|
|
80 |
|
|
lat=LATITUDE(m); |
81 |
|
|
lon=LONGITUDE(m); if lon < 0; lon=lon+360;end; |
82 |
|
|
|
83 |
|
|
%%%%%%%ilon=find(((vec_lon-lon).^2)==min((vec_lon-lon).^2)); ilon=ilon(1); |
84 |
|
|
%%%%%%%ilat=find(((vec_lat-lat).^2)==min((vec_lat-lat).^2)); ilat=ilat(1); |
85 |
|
|
|
86 |
|
|
direc=0;if(DIRECTION(m)=='A');direc=1;end;if(DIRECTION(m)=='D');direc=2;end |
87 |
|
|
|
88 |
|
|
pnum_txt=deblank(PLATFORM_NUMBER(m,:)); pnum_txt=pnum_txt(pnum_txt~=PLATFORM_NUMBER_fillval); |
89 |
|
|
pnum=double(pnum_txt); pnum=pnum(find(pnum>=48&pnum<=57)); pnum=str2num(char(pnum)); |
90 |
|
|
if isempty(pnum); pnum_txt='9999'; pnum=9999; end; |
91 |
|
|
|
92 |
|
|
%observations |
93 |
|
|
|
94 |
|
|
p=PRES_ADJUSTED(m,:); |
95 |
|
|
p_QC=PRES_ADJUSTED_QC(m,:); |
96 |
|
|
if isempty(find(p~=PRES_fillval)); p=PRES(m,:); p_QC=PRES_QC(m,:); end |
97 |
|
|
|
98 |
|
|
tmp1=find(isnan(p)); p(tmp1)=PRES_fillval; p_QC(tmp1)='5'; |
99 |
|
|
for n=1:length(p)-1; |
100 |
gforget |
1.1 |
tmp1=find(p(n+1:end)==p(n)&p(n+1:end)~=PRES_fillval); |
101 |
|
|
p(n+tmp1)=PRES_fillval;p_QC(n+tmp1)='5'; |
102 |
gforget |
1.2 |
end |
103 |
|
|
|
104 |
|
|
bad_P=0; |
105 |
|
|
tmp1=find(p_QC=='4'); |
106 |
|
|
if(length(tmp1)<=5); |
107 |
|
|
%get rid of these few bad points and keep the profile |
108 |
|
|
p(tmp1)=PRES_fillval;p_QC(tmp1)='5'; |
109 |
|
|
else; |
110 |
|
|
%flag the profile (will be masked in the main file) |
111 |
|
|
%but keep the bad points (to interp and be able to CHECK) |
112 |
|
|
bad_P=1; |
113 |
|
|
end; |
114 |
|
|
|
115 |
|
|
if TEMP(m,1) ~= 8888 |
116 |
|
|
t=TEMP_ADJUSTED(m,:); |
117 |
|
|
t_QC=TEMP_ADJUSTED_QC(m,:); |
118 |
|
|
t_ERR=TEMP_ADJUSTED_ERROR(m,:);tf=find(t_ERR==TEMP_fillval|isnan(t_ERR));t_ERR(tf)=0; |
119 |
|
|
if isempty(find(t~=TEMP_fillval)); t=TEMP(m,:); t_QC=TEMP_QC(m,:); end |
120 |
|
|
end |
121 |
|
|
|
122 |
|
|
if PSAL(m,1) ~= 8888 |
123 |
|
|
s=PSAL_ADJUSTED(m,:); |
124 |
|
|
s_QC=PSAL_ADJUSTED_QC(m,:); |
125 |
|
|
s_ERR=PSAL_ADJUSTED_ERROR(m,:);sf=find(s_ERR==PSAL_fillval|isnan(s_ERR));,s_ERR(sf)=0; |
126 |
|
|
if isempty(find(s~=PSAL_fillval)); s=PSAL(m,:); s_QC=PSAL_QC(m,:); end |
127 |
|
|
end |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
p(p==PRES_fillval)=NaN; |
131 |
|
|
p(p==PRES_fillval)=NaN; |
132 |
|
|
if isempty(whos('t')); %this file does not contain salinity data... |
133 |
|
|
t=NaN*p; t_ERR=0*p; |
134 |
|
|
else; |
135 |
|
|
t(t_QC~='1'&t_QC~='2')=NaN; |
136 |
|
|
end; |
137 |
|
|
if isempty(whos('s')); %this file does not contain salinity data... |
138 |
|
|
s=NaN*t; s_ERR=0*t_ERR; |
139 |
|
|
else; |
140 |
|
|
s(s_QC~='1'&s_QC~='2')=NaN; |
141 |
|
|
end; |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
profileCur.pnum_txt=pnum_txt; |
145 |
|
|
profileCur.ymd=ymd; profileCur.hms=hms; |
146 |
|
|
profileCur.lat=lat; profileCur.lon=lon; |
147 |
|
|
profileCur.direc=direc; |
148 |
|
|
profileCur.t=t; |
149 |
|
|
profileCur.s=s; |
150 |
|
|
profileCur.p=p; |
151 |
|
|
profileCur.t_ERR=t_ERR; |
152 |
|
|
profileCur.s_ERR=s_ERR; |
153 |
|
|
profileCur.PorZisBAD=bad_P; |
154 |
|
|
|
155 |
|
|
%bad_latlon=0; |
156 |
|
|
%if profileCur.lat<-90|profileCur.lat>90; bad_latlon=1; end; |
157 |
|
|
%if profileCur.lon<-180|profileCur.lon>360; bad_latlon=1; end; |
158 |
|
|
%profileCur.LONorLATisBAD=bad_latlon; |
159 |
|
|
|
160 |
|
|
varargout = {profileCur}; |
161 |
|
|
|
162 |
gforget |
1.1 |
end; |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|