/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_external/profiles_read_argo.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_external/profiles_read_argo.m

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


Revision 1.1 - (hide annotations) (download)
Thu Oct 21 19:40:12 2010 UTC (14 years, 9 months ago) by gforget
Branch: MAIN
up-to-date matlab codes to process in-situ
data sets to MITgcm/pkg/profiles input format.

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     %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     nc = netcdf(fileIn, 'nowrite');
45     PRES_fillval=fillval(nc{'PRES'});
46     if PSAL(1,1) ~= 8888; PSAL_fillval=fillval(nc{'PSAL'});end;
47     if TEMP(1,1) ~= 8888; TEMP_fillval=fillval(nc{'TEMP'});end;
48     PLATFORM_NUMBER_fillval=fillval(nc{'PLATFORM_NUMBER'});
49     nc = close(nc);
50    
51     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)))';%'
52     REFdateOBS=jul_0h(REFdateOBS);
53     VECdateOBS=REFdateOBS+JULD;
54    
55     xx=size(PRES);mloc=xx(1);mpts=xx(2);
56    
57     varargout(1) = {length(LONGITUDE)};
58    
59     else;%if m==0;
60     %select one profile for output:
61    
62     %date, position, etc
63    
64     tmp1=greg_0h(VECdateOBS(m));
65     ymd=tmp1(1)*1e4+tmp1(2)*1e2+tmp1(3);
66     hms=tmp1(4)*1e4+tmp1(5)*1e2+tmp1(6);
67    
68     lat=LATITUDE(m);
69     lon=LONGITUDE(m); if lon < 0; lon=lon+360;end;
70    
71     %%%%%%%ilon=find(((vec_lon-lon).^2)==min((vec_lon-lon).^2)); ilon=ilon(1);
72     %%%%%%%ilat=find(((vec_lat-lat).^2)==min((vec_lat-lat).^2)); ilat=ilat(1);
73    
74     direc=0;if(DIRECTION(m)=='A');direc=1;end;if(DIRECTION(m)=='D');direc=2;end
75    
76     pnum_txt=deblank(PLATFORM_NUMBER(m,:)); pnum_txt=pnum_txt(pnum_txt~=PLATFORM_NUMBER_fillval);
77     pnum=double(pnum_txt); pnum=pnum(find(pnum>=48&pnum<=57)); pnum=str2num(char(pnum));
78     if isempty(pnum); pnum_txt='9999'; pnum=9999; end;
79    
80     %observations
81    
82     p=PRES_ADJUSTED(m,:);
83     p_QC=PRES_ADJUSTED_QC(m,:);
84     if isempty(find(p~=PRES_fillval)); p=PRES(m,:); p_QC=PRES_QC(m,:); end
85    
86     tmp1=find(isnan(p)); p(tmp1)=PRES_fillval; p_QC(tmp1)='5';
87     for n=1:length(p)-1;
88     tmp1=find(p(n+1:end)==p(n)&p(n+1:end)~=PRES_fillval);
89     p(n+tmp1)=PRES_fillval;p_QC(n+tmp1)='5';
90     end
91    
92     bad_P=0;
93     tmp1=find(p_QC=='4');
94     if(length(tmp1)<=5);
95     %get rid of these few bad points and keep the profile
96     p(tmp1)=PRES_fillval;p_QC(tmp1)='5';
97     else;
98     %flag the profile (will be masked in the main file)
99     %but keep the bad points (to interp and be able to CHECK)
100     bad_P=1;
101     end;
102    
103     if TEMP(m,1) ~= 8888
104     t=TEMP_ADJUSTED(m,:);
105     t_QC=TEMP_ADJUSTED_QC(m,:);
106     t_ERR=TEMP_ADJUSTED_ERROR(m,:);tf=find(t_ERR==TEMP_fillval|isnan(t_ERR));t_ERR(tf)=0;
107     if isempty(find(t~=TEMP_fillval)); t=TEMP(m,:); t_QC=TEMP_QC(m,:); end
108     end
109    
110     if PSAL(m,1) ~= 8888
111     s=PSAL_ADJUSTED(m,:);
112     s_QC=PSAL_ADJUSTED_QC(m,:);
113     s_ERR=PSAL_ADJUSTED_ERROR(m,:);sf=find(s_ERR==PSAL_fillval|isnan(s_ERR));,s_ERR(sf)=0;
114     if isempty(find(s~=PSAL_fillval)); s=PSAL(m,:); s_QC=PSAL_QC(m,:); end
115     end
116    
117    
118     p(p==PRES_fillval)=NaN;
119     p(p==PRES_fillval)=NaN;
120     if isempty(whos('t')); %this file does not contain salinity data...
121     t=NaN*p; t_ERR=0*p;
122     else;
123     t(t_QC~='1'&t_QC~='2')=NaN;
124     end;
125     if isempty(whos('s')); %this file does not contain salinity data...
126     s=NaN*t; s_ERR=0*t_ERR;
127     else;
128     s(s_QC~='1'&s_QC~='2')=NaN;
129     end;
130    
131    
132     profileCur.pnum_txt=pnum_txt;
133     profileCur.ymd=ymd; profileCur.hms=hms;
134     profileCur.lat=lat; profileCur.lon=lon;
135     profileCur.direc=direc;
136     profileCur.t=t;
137     profileCur.s=s;
138     profileCur.p=p;
139     profileCur.t_ERR=t_ERR;
140     profileCur.s_ERR=s_ERR;
141     profileCur.PorZisBAD=bad_P;
142    
143     %bad_latlon=0;
144     %if profileCur.lat<-90|profileCur.lat>90; bad_latlon=1; end;
145     %if profileCur.lon<-180|profileCur.lon>360; bad_latlon=1; end;
146     %profileCur.LONorLATisBAD=bad_latlon;
147    
148     varargout = {profileCur};
149    
150     end;
151    
152    
153    

  ViewVC Help
Powered by ViewVC 1.1.22