1 |
function [varargout]=profile_read_argo(dataset,nf,m,varargin); |
2 |
% read hydrographic data in the ARGO netcdf format |
3 |
% return the m-th profile from the nf-th file referenced in |
4 |
% dataset.fileInList. |
5 |
% |
6 |
% if m=0 : |
7 |
% dataset=profile_read_argo(dataset,nf,0); |
8 |
% dataset.nprofiles: number of profiles in the nf-th file |
9 |
% dataset.data_argo: argo data in a struct variable |
10 |
% |
11 |
% if m~=0 : |
12 |
% profileCur=profile_read_argo(dataset,nf,m); |
13 |
% |
14 |
% profileCur = (m-th profile of nf-th file) |
15 |
% pnum_txt: '5900841' |
16 |
% ymd: 20060101 |
17 |
% hms: 3207 |
18 |
% lat: -46.709 |
19 |
% lon: 137.501 |
20 |
% direc: 1 |
21 |
% t: [1x115 single] |
22 |
% s: [1x115 single] |
23 |
% p: [1x115 single] |
24 |
% t_ERR: [1x115 single] |
25 |
% s_ERR: [1x115 single] |
26 |
% isBAD: 0 |
27 |
% |
28 |
|
29 |
fileIn=[dataset.dirIn dataset.fileInList(nf).name]; |
30 |
|
31 |
if m==0; % return the number of profile. |
32 |
|
33 |
%get the number of profiles: |
34 |
list_var={'JULD','LATITUDE','LONGITUDE','DIRECTION','PLATFORM_NUMBER','DATA_MODE',... |
35 |
'JULD_QC','POSITION_QC','PRES_ADJUSTED_QC','PRES_QC',... |
36 |
'TEMP_ADJUSTED_QC','TEMP_QC','PSAL_ADJUSTED_QC','PSAL_QC'}; |
37 |
argo_data=[]; |
38 |
for ii=1:length(list_var), |
39 |
ncload(fileIn,list_var{ii}); |
40 |
data=eval(list_var{ii}); |
41 |
if ~isempty(data); |
42 |
nc=ncopen(fileIn); |
43 |
FillVal=ncgetFillVal(nc,list_var{ii}); |
44 |
ncclose(nc); |
45 |
if ischar(FillVal), |
46 |
data(strcmp(data,FillVal))=' '; |
47 |
else |
48 |
data(data==FillVal)=NaN; |
49 |
end |
50 |
end |
51 |
argo_data=setfield(argo_data,list_var{ii},data); |
52 |
end |
53 |
|
54 |
list_var={'PRES_ADJUSTED','PRES','TEMP_ADJUSTED','TEMP','TEMP_ADJUSTED_ERROR',... |
55 |
'PSAL_ADJUSTED','PSAL','PSAL_ADJUSTED_ERROR'}; |
56 |
for ii=1:length(list_var), |
57 |
ncload(fileIn,list_var{ii}); |
58 |
data=double(eval(list_var{ii})); |
59 |
if ~isempty(data); |
60 |
nc=ncopen(fileIn); |
61 |
FillVal=ncgetFillVal(nc,list_var{ii}); |
62 |
ncclose(nc); |
63 |
data(data==FillVal)=NaN; |
64 |
end; |
65 |
argo_data=setfield(argo_data,list_var{ii},data); |
66 |
end |
67 |
|
68 |
dataset.argo_data=argo_data; |
69 |
dataset.nprofiles = length(JULD); |
70 |
if isempty(dataset.argo_data.TEMP); |
71 |
dataset.nprofiles=0; |
72 |
fprintf(['empty file:' dataset.fileInList(nf).name '\n']); |
73 |
end; |
74 |
|
75 |
if ~isfield(dataset,'greyList'); |
76 |
if ~isempty(dir([dataset.dirIn '../../ar_greylist.txt'])); |
77 |
fidgrey=fopen([dataset.dirIn '../../ar_greylist.txt'],'rt'); |
78 |
tmp1=fgetl(fidgrey); |
79 |
greylist=[]; ii=0; |
80 |
while ~feof(fidgrey); |
81 |
tmp1=fgetl(fidgrey); tmp2=strfind(tmp1,','); |
82 |
|
83 |
cur_pnum=double(tmp1(1:tmp2(1)-1)); |
84 |
cur_pnum=cur_pnum(find(cur_pnum~=0&cur_pnum~=32)); |
85 |
cur_pnum=char(cur_pnum); |
86 |
|
87 |
date_ref=double(tmp1(tmp2(2)+1:tmp2(3)-1)); |
88 |
date_ref=date_ref(find(date_ref~=0&date_ref~=32)); |
89 |
date_ref=char(date_ref); |
90 |
date_ref=[str2num(date_ref(1:4)) str2num(date_ref(5:6)) str2num(date_ref(7:8)) 0 0 0]; |
91 |
|
92 |
vnam=tmp1(tmp2(1)+1:tmp2(2)-1); |
93 |
|
94 |
ii=ii+1; |
95 |
greylist(ii).pnum=cur_pnum; |
96 |
greylist(ii).start=date_ref; |
97 |
greylist(ii).vnam=vnam; |
98 |
end; |
99 |
fclose(fidgrey); |
100 |
|
101 |
dataset.greyList.pnum={greylist(:).pnum}; |
102 |
dataset.greyList.start={greylist(:).start}; |
103 |
dataset.greyList.vnam={greylist(:).vnam}; |
104 |
else; |
105 |
dataset.greyList.pnum=[]; |
106 |
dataset.greyList.start=[]; |
107 |
dataset.greyList.vnam=[]; |
108 |
end; |
109 |
end; |
110 |
|
111 |
varargout{1}=dataset; |
112 |
|
113 |
else;%if m==0; |
114 |
|
115 |
% load data |
116 |
argo_data=dataset.argo_data; |
117 |
|
118 |
%date, position, etc |
119 |
juld=argo_data.JULD(m)+datenum(1950,1,1); |
120 |
[Y, M, D, H, MN, S] = datevec(juld); |
121 |
ymd=Y*1e4+M*1e2+D; |
122 |
hms=H*1e4+MN*1e2+S; |
123 |
|
124 |
lat=argo_data.LATITUDE(m); |
125 |
lon=argo_data.LONGITUDE(m); if lon < 0; lon=lon+360;end; |
126 |
|
127 |
direction=argo_data.DIRECTION(m); |
128 |
direc=0; |
129 |
if(direction=='A');direc=1;end; |
130 |
if(direction=='D');direc=2;end |
131 |
|
132 |
pnum_txt=deblank(argo_data.PLATFORM_NUMBER(m,:)); |
133 |
pnum_txt=pnum_txt(ismember(pnum_txt,'0123456789')); pnum=str2num(pnum_txt); |
134 |
if isempty(pnum_txt); pnum_txt='9999'; pnum=9999; disp(['no name for profile ' num2str(m)]); end; |
135 |
|
136 |
|
137 |
% pressure data |
138 |
|
139 |
p=argo_data.PRES_ADJUSTED(m,:); |
140 |
p_QC=argo_data.PRES_ADJUSTED_QC(m,:); |
141 |
if all(isnan(p)), p=argo_data.PRES(m,:); p_QC=argo_data.PRES_QC(m,:); end |
142 |
p_QC(isnan(p))='5'; |
143 |
|
144 |
for n=1:length(p)-1; % doubles |
145 |
tmp1=find(p(n+1:end)==p(n)); p(n+tmp1)=NaN; p_QC(n+tmp1)='5'; |
146 |
end |
147 |
|
148 |
% QC on position, date and pressure |
149 |
isBAD=0; |
150 |
|
151 |
if ~ismember(argo_data.POSITION_QC(m),'1258'); isBAD=1; end; |
152 |
if ~ismember(argo_data.JULD_QC(m),'1258'); isBAD=1; end; |
153 |
|
154 |
tmp1=find(~ismember(p_QC,'1258')); |
155 |
if(length(tmp1)<=5); |
156 |
%get rid of these few bad points and keep the profile |
157 |
p(tmp1)=NaN; |
158 |
else; |
159 |
%flag the profile (will be masked in the main file) |
160 |
%but keep the bad points (to interp and be able to CHECK) |
161 |
isBAD=1; |
162 |
end; |
163 |
|
164 |
% temperature data |
165 |
%[num2str(m) ' in ' dataset.fileInList(nf).name] |
166 |
t=argo_data.TEMP_ADJUSTED(m,:); |
167 |
t_QC=argo_data.TEMP_ADJUSTED_QC(m,:); |
168 |
t_ERR=argo_data.TEMP_ADJUSTED_ERROR(m,:); |
169 |
t_ERR(isnan(t_ERR))=0; |
170 |
if all(isnan(t)), t=argo_data.TEMP(m,:); t_QC=argo_data.TEMP_QC(m,:); end |
171 |
|
172 |
%accomodate files that have no salinity |
173 |
if isempty(argo_data.PSAL); |
174 |
argo_data.PSAL=NaN*argo_data.TEMP; |
175 |
argo_data.PSAL_QC=char(32*ones(size(argo_data.TEMP_ADJUSTED_QC))); |
176 |
argo_data.PSAL_ADJUSTED=NaN*argo_data.TEMP; |
177 |
argo_data.PSAL_ADJUSTED_ERROR=NaN*argo_data.TEMP; |
178 |
argo_data.PSAL_ADJUSTED_QC=char(32*ones(size(argo_data.TEMP_ADJUSTED_QC))); |
179 |
end; |
180 |
|
181 |
% salinity data |
182 |
s=argo_data.PSAL_ADJUSTED(m,:); |
183 |
s_QC=argo_data.PSAL_ADJUSTED_QC(m,:); |
184 |
s_ERR=argo_data.PSAL_ADJUSTED_ERROR(m,:); |
185 |
s_ERR(isnan(s_ERR))=0; |
186 |
if all(isnan(s)), s=argo_data.PSAL(m,:); s_QC=argo_data.PSAL_QC(m,:); end |
187 |
|
188 |
if isnan(t(1)); %this file does not contain temperature data... |
189 |
t=NaN*p; t_ERR=0*p; |
190 |
else; |
191 |
t(~ismember(t_QC,'1258'))=NaN; |
192 |
end; |
193 |
if isnan(s(1)); %this file does not contain salinity data... |
194 |
s=NaN*p; s_ERR=0*p; |
195 |
else; |
196 |
s(~ismember(s_QC,'1258'))=NaN; |
197 |
end; |
198 |
|
199 |
profileCur.pnum_txt=pnum_txt; |
200 |
profileCur.ymd=ymd; profileCur.hms=hms; |
201 |
profileCur.lat=lat; profileCur.lon=lon; |
202 |
profileCur.direc=direc; |
203 |
profileCur.T=t; |
204 |
profileCur.S=s; |
205 |
profileCur.p=p; |
206 |
profileCur.T_ERR=t_ERR; |
207 |
profileCur.S_ERR=s_ERR; |
208 |
profileCur.isBAD=isBAD; |
209 |
profileCur.DATA_MODE=argo_data.DATA_MODE(m); |
210 |
|
211 |
varargout = {profileCur}; |
212 |
|
213 |
end; |
214 |
|
215 |
|
216 |
|