/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_prep_argo_ifremer_parts.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_prep_argo_ifremer_parts.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Thu May 13 19:51:13 2010 UTC (15 years, 7 months ago) by gforget
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
moving to profiles_process_argo_v1

1 % t_test, s_test description
2 % 0 = valid data
3 % 1 = outside +/-79 lat
4 % 2 = absurd sal value
5 % 3 = doubtful profiler (based on our own evaluations)
6 % 4 = doubtful profiler (based on Argo grey list)
7 % 5 = high climatology/atlas cost - all four of them
8 % 6 = bad Pressure vector
9
10 %clear
11
12 global rep_out filename_out;
13 global t_std s_std t_test s_test t_w s_w t_equi s_equi;
14 global ymd hms pnum pnum_txt lon lat direc dmod ilon ilat imonth;
15 global fill_value_output initChkFile;
16
17 %split in parts:
18 nbparts=16; %numpart=1
19
20 profiles_prep_load_fields;
21
22 %depths of standard levels :
23 dmod=[[5:10:185] [200:20:500] [550:50:1000] [1100:100:6000]];
24 %maximum level to compute : e.g. 2000m for ARGO profiles
25 lev_max=max(find(dmod<=2000)); fprintf(['level max : ' num2str(lev_max) ' \n']);
26 dmod=dmod(1:lev_max);
27 %fill value for the output files :
28 fill_value_output=-9999;
29 %do we start from in situ temperature?
30 TfromINSITUtoPOT=1; %1 => we will convert to potential temperature
31 %do we start from P vertical coordinate?
32 PfromPtoZ=1; %1 => we will convert to depth
33
34 %loop over the data files :
35 for rep_nb=1:3
36 clear fid*; %needed to properly initialize output files
37 switch rep_nb
38 case 1
39 bassin_cur='INDIAN';
40 case 2
41 bassin_cur='PACIFIC';
42 case 3
43 bassin_cur='ATLANTIC';
44 end
45 rep_in=['/net/altix3700/raid4/gforget/ARGO/ifremer/' bassin_cur '/'];
46 rep_out=['/net/altix3700/raid4/gforget/ARGO/ifremer/ECCOformat/PART' num2str(numpart) '/'];
47 eval(['mkdir ' rep_out]);
48 filename_out=[bassin_cur '_ARGO_EDW'];
49
50 initChkFile=1;
51
52 %get the number of files to be treated :
53 fid=fopen(['/net/altix3700/raid4/gforget/ARGO/ifremer/NC_list_' bassin_cur],'r');
54 foo=fread(fid);
55 nfiles=size(foo);
56 nfiles=nfiles(1)/17;
57 fclose(fid);
58
59 %file with the list of source files :
60 fid=fopen(['/net/altix3700/raid4/gforget/ARGO/ifremer/NC_list_' bassin_cur],'r');
61
62 %loop over data files :
63 ktQC=0*ones(1,9);ksQC=0*ones(1,9);
64
65 %split in parts:
66 nfiles_part=ceil(nfiles/nbparts);
67 if numpart~=nbparts; nfiles_part=[1:nfiles_part]+nfiles_part*(numpart-1);
68 else; nfiles_part=[1+nfiles_part*(numpart-1):nfiles]; end;
69
70 %jump over first files if necessary
71 for nf=1:nfiles_part(1)-1
72 name=fread(fid,17,'char');
73 end
74
75
76 for nf=nfiles_part % FILE LOOP
77
78
79 if mod(nf,100)==0|nf==1; fprintf([num2str(nf) ' ' num2str(nfiles) '\n']); end;
80
81 clear PRES* PSAL* TEMP*;
82 TEMP=8888*ones(500,1);PSAL=8888*ones(500,1);
83 name=fread(fid,16,'char');name= setstr(name);name=name';
84 junk=fread(fid,1,'char');
85
86 if ( rep_nb~=1|isempty(findstr(name,'20050911_prof')) )
87
88 eval(['ncload ' rep_in name ';']);
89
90 %some dimensions inversions exist for _QC variables (!?)
91 if size(PRES_QC,1)~=size(PRES,1)
92 PRES_QC=PRES_QC';
93 if ~isempty(who('PRES_ADJUSTED_QC'));PRES_ADJUSTED_QC=PRES_ADJUSTED_QC';end;
94 if ~isempty(who('PSAL_QC'));PSAL_QC=PSAL_QC';end;
95 if ~isempty(who('PSAL_ADJUSTED_QC'));PSAL_ADJUSTED_QC=PSAL_ADJUSTED_QC';end;
96 if ~isempty(who('TEMP_QC'));TEMP_QC=TEMP_QC';end;
97 if ~isempty(who('TEMP_ADJUSTED_QC'));TEMP_ADJUSTED_QC=TEMP_ADJUSTED_QC';end;
98 end
99 if size(PLATFORM_NUMBER,1)~=size(PRES,1); PLATFORM_NUMBER=PLATFORM_NUMBER'; end;
100
101 %get the fillvalues:
102 nc = netcdf([rep_in name], 'nowrite');
103 PRES_fillval=fillval(nc{'PRES'});
104 if PSAL(1,1) ~= 8888; PSAL_fillval=fillval(nc{'PSAL'});end;
105 if TEMP(1,1) ~= 8888; TEMP_fillval=fillval(nc{'TEMP'});end;
106 PLATFORM_NUMBER_fillval=fillval(nc{'PLATFORM_NUMBER'});
107 nc = close(nc);
108
109 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)))'; REFdateOBS=jul_0h(REFdateOBS);
110 VECdateOBS=REFdateOBS+JULD;
111
112 xx=size(PRES);mloc=xx(1);mpts=xx(2);
113
114 for m=1:mloc % LOCATION LOOP
115
116 %date, position, etc
117
118 tmp1=greg_0h(VECdateOBS(m));
119 ymd=tmp1(1)*1e4+tmp1(2)*1e2+tmp1(3);
120 hms=tmp1(4)*1e4+tmp1(5)*1e2+tmp1(6);
121
122 imonth=tmp1(2);
123
124 lat=LATITUDE(m);
125 lon=LONGITUDE(m); if lon < 0; lon=lon+360;end;
126
127 ilon=find(((vec_lon-lon).^2)==min((vec_lon-lon).^2)); ilon=ilon(1);
128 ilat=find(((vec_lat-lat).^2)==min((vec_lat-lat).^2)); ilat=ilat(1);
129
130 direc=0;if(DIRECTION(m)=='A');direc=1;end;if(DIRECTION(m)=='D');direc=2;end
131
132 pnum_txt=deblank(PLATFORM_NUMBER(m,:)); pnum_txt=pnum_txt(pnum_txt~=PLATFORM_NUMBER_fillval);
133 pnum=double(pnum_txt); pnum=pnum(find(pnum>=48&pnum<=57)); pnum=str2num(char(pnum));
134
135 if isempty(pnum); pnum_txt='9999'; pnum=9999; end;
136
137 %observations
138
139 p=PRES_ADJUSTED(m,:);
140 p_QC=PRES_ADJUSTED_QC(m,:);
141 if isempty(find(p~=PRES_fillval)); p=PRES(m,:); p_QC=PRES_QC(m,:); end
142
143 tmp1=find(isnan(p)); p(tmp1)=PRES_fillval; p_QC(tmp1)='5';
144 for n=1:length(p)-1;
145 tmp1=find(p(n+1:end)==p(n)&p(n+1:end)~=PRES_fillval);
146 p(n+tmp1)=PRES_fillval;p_QC(n+tmp1)='5';
147 end
148
149 bad_P=0;
150 tmp1=find(p_QC=='4');
151 if(length(tmp1)<=5);
152 %get rid of these few bad points and keep the profile
153 p(tmp1)=PRES_fillval;p_QC(tmp1)='5';
154 else;
155 %flag the profile (will be masked in the main file)
156 %but keep the bad points (to interp and be able to CHECK)
157 bad_P=1;
158 end;
159
160 if TEMP(m,1) ~= 8888
161 t=TEMP_ADJUSTED(m,:);
162 t_QC=TEMP_ADJUSTED_QC(m,:);
163 t_ERR=TEMP_ADJUSTED_ERROR(m,:);tf=find(t_ERR==TEMP_fillval|isnan(t_ERR));t_ERR(tf)=0;
164 if isempty(find(t~=TEMP_fillval)); t=TEMP(m,:); t_QC=TEMP_QC(m,:); end
165 end
166
167 if PSAL(m,1) ~= 8888
168 s=PSAL_ADJUSTED(m,:);
169 s_QC=PSAL_ADJUSTED_QC(m,:);
170 s_ERR=PSAL_ADJUSTED_ERROR(m,:);sf=find(s_ERR==PSAL_fillval|isnan(s_ERR));,s_ERR(sf)=0;
171 if isempty(find(s~=PSAL_fillval)); s=PSAL(m,:); s_QC=PSAL_QC(m,:); end
172 end
173
174 %convert pressure to depth (if necessary)
175 if PfromPtoZ
176 tmp1=find((p~=PRES_fillval)&(~isnan(p)));
177 if ~isempty(tmp1); p( tmp1 ) = find_depth(p(tmp1),lat); end;
178 end
179
180 %interpolation for T :
181 z_std=dmod; t_std=NaN*z_std; tE_std=t_std;
182 if TEMP(m,1) ~= 8888
183 tmp1=find((t_QC=='1'|t_QC=='2') & (p~=PRES_fillval&~isnan(p)));
184 z_in=p(tmp1); t_in=t(tmp1); tE_in=t_ERR(tmp1);
185 if length(t_in)>5 %...expected to avoid isolated values
186 t_std = interp1(z_in,t_in,z_std);
187 t_std=profiles_prep_test_interp(t_std,z_std,z_in,NaN);
188 tE_std = interp1(z_in,tE_in,z_std);
189 tE_std=profiles_prep_test_interp(tE_std,z_std,z_in,NaN);
190 end
191 end%z_std=gdept; t_std=NaN*z_std;
192 t_std(find(isnan(t_std)))=fill_value_output;
193 tE_std(find(isnan(tE_std)))=fill_value_output;
194
195 %interpolation for S :
196 z_std=dmod; s_std=NaN*z_std; sE_std=s_std;
197 if PSAL(m,1) ~= 8888
198 tmp1=find((s_QC=='1'|s_QC=='2') & (p~=PRES_fillval&~isnan(p)));
199 z_in=p(tmp1); s_in=s(tmp1); sE_in=s_ERR(tmp1);
200 if length(s_in)>5
201 s_std = interp1(z_in,s_in,z_std);
202 s_std=profiles_prep_test_interp(s_std,z_std,z_in,NaN);
203 sE_std = interp1(z_in,sE_in,z_std);
204 sE_std=profiles_prep_test_interp(sE_std,z_std,z_in,NaN);
205 end
206 end%if PSAL(m,1) ~= 8888
207 s_std(find(isnan(s_std)))=fill_value_output;
208 sE_std(find(isnan(sE_std)))=fill_value_output;
209
210 %convert T in situ to T potential (if necessary)
211 if TfromINSITUtoPOT
212 tmpP=0.981*1.027*dmod; tmpS=35*ones(size(t_std));
213 tmpIND=find(t_std~=fill_value_output);
214 if ~isempty(tmpIND)
215 t_std(tmpIND)=sw_ptmp(tmpS(tmpIND),t_std(tmpIND),tmpP(tmpIND),0);
216 end
217 end
218
219
220 %attribute weights: (modified later in profiles_prep_write_nc)
221 %
222 % by assumption: the uncertainty field contains non-zero values
223 % (which avoid the complication of handling horiz interpolation here)
224 % and we do not mask the data (the model will do this, given a mask)
225 %
226 t_w = squeeze(T_weights(ilon,ilat,:)); t_w = interp1(dmod_ref',t_w',dmod')'.^2;
227 tmp1=find(tE_std~=fill_value_output); t_w(tmp1)=t_w(tmp1)+tE_std(tmp1).^2;
228 s_w = squeeze(S_weights(ilon,ilat,:)); s_w = interp1(dmod_ref',s_w',dmod')'.^2;
229 tmp1=find(sE_std~=fill_value_output); s_w(tmp1)=s_w(tmp1)+sE_std(tmp1).^2;
230 t_w=t_w.^-1; s_w=s_w.^-1;
231
232 if ~isempty(find(isnan(t_w.*s_w))); fprintf('error in weighting'); return; end;
233
234
235 %tests of the data values :
236 %--------------------------
237 % t_test>0 or s_test>0 implies the data value is rejected,
238 % the value of t_test indicates on what criterium
239 t_test=zeros(size(t_std)); s_test=t_test;
240
241 %test of the extreme latitudes :
242 if abs(lat)>79; t_test(:)=1; s_test(:)=1; end;
243
244 %test of "absurd" salinity values : test
245 s_test(find( (s_std>42)&(s_std~=fill_value_output) ))=2;
246 s_test(find( (s_std<25)&(s_std~=fill_value_output) ))=2;
247
248 %tests of doubtful profilers :
249 %profiles_prep_test_profiler2;
250 %profiles_prep_test_profiler3;
251 %profiles_prep_test_profiler4;
252
253 %tests of the cost VS the climatology :
254 profiles_prep_test_atlas(50);
255
256 %bad pressure flag:
257 if bad_P==1; t_test(:)=6; s_test(:)=6; end;
258
259 %store/write results:
260 profiles_prep_write_nc(1);
261
262 end % LOCATION LOOP
263 end %if ( rep_nb~=1|isempty(findstr(name,'20050911_prof') )
264 end % FILE LOOP
265 profiles_prep_write_nc(2);
266 end%for rep_nb=1:3
267
268

  ViewVC Help
Powered by ViewVC 1.1.22