/[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.5 - (hide annotations) (download)
Sat May 7 20:48:47 2011 UTC (14 years, 2 months ago) by roquet
Branch: MAIN
Changes since 1.4: +8 -8 lines
simplify profiles_IO_external interface:
init loading: dataset=profiles_read_xxx(dataset,nf,0);
then, to load m-th profile: profile=profiles_read_xxx(dataset,nf,m);

1 roquet 1.3 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 roquet 1.5 % 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 roquet 1.3 %
11     % if m~=0 :
12 roquet 1.5 % profileCur=profile_read_argo(dataset,nf,m);
13 roquet 1.3 %
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     % PorZisBAD: 0
27     %
28 gforget 1.1
29     fileIn=[dataset.dirIn dataset.fileInList(nf).name];
30    
31 roquet 1.3 if m==0; % return the number of profile.
32 gforget 1.2
33 roquet 1.3 %get the number of profiles:
34     list_var={'JULD','LATITUDE','LONGITUDE','DIRECTION','PLATFORM_NUMBER',...
35 roquet 1.4 'PRES_ADJUSTED_QC','PRES_QC','TEMP_ADJUSTED_QC','TEMP_QC','PSAL_ADJUSTED_QC','PSAL_QC'};
36 roquet 1.3 argo_data=[];
37     for ii=1:length(list_var),
38     ncload(fileIn,list_var{ii});
39 roquet 1.4 data=eval(list_var{ii});
40     nc=ncopen(fileIn);
41     FillVal=ncgetFillVal(nc,list_var{ii});
42     ncclose(nc);
43     if ischar(FillVal),
44     data(strcmp(data,FillVal))=' ';
45     else
46     data(data==FillVal)=NaN;
47     end
48     argo_data=setfield(argo_data,list_var{ii},data);
49 gforget 1.2 end
50 roquet 1.4 list_var={'PRES_ADJUSTED','PRES','TEMP_ADJUSTED','TEMP','TEMP_ADJUSTED_ERROR',...
51     'PSAL_ADJUSTED','PSAL','PSAL_ADJUSTED_ERROR'};
52     for ii=1:length(list_var),
53     ncload(fileIn,list_var{ii});
54     data=double(eval(list_var{ii}));
55     nc=ncopen(fileIn);
56     FillVal=ncgetFillVal(nc,list_var{ii});
57     ncclose(nc);
58     data(data==FillVal)=NaN;
59     argo_data=setfield(argo_data,list_var{ii},data);
60     end
61    
62 roquet 1.5 dataset.argo_data=argo_data;
63     dataset.nprofiles = length(JULD);
64 gforget 1.2
65 roquet 1.5 varargout{1}=dataset;
66 gforget 1.2
67 roquet 1.3 else;%if m==0;
68 gforget 1.2
69 roquet 1.3 % load data
70 roquet 1.5 argo_data=dataset.argo_data;
71 gforget 1.2
72     %date, position, etc
73 roquet 1.3 juld=argo_data.JULD(m)+datenum(1950,1,1);
74     [Y, M, D, H, MN, S] = datevec(juld);
75     ymd=Y*1e4+M*1e2+D;
76     hms=H*1e4+MN*1e2+S;
77 gforget 1.2
78 roquet 1.3 lat=argo_data.LATITUDE(m);
79     lon=argo_data.LONGITUDE(m); if lon < 0; lon=lon+360;end;
80 gforget 1.2
81 roquet 1.3 direction=argo_data.DIRECTION(m);
82     direc=0;
83     if(direction=='A');direc=1;end;
84     if(direction=='D');direc=2;end
85 gforget 1.2
86 roquet 1.3 pnum_txt=deblank(argo_data.PLATFORM_NUMBER(m,:));
87     pnum_txt=pnum_txt(ismember(pnum_txt,'0123456789')); pnum=str2num(pnum_txt);
88     if isempty(pnum_txt); pnum_txt='9999'; pnum=9999; disp(['no name for profile ' num2str(m)]); end;
89 gforget 1.2
90    
91 roquet 1.3 % pressure data
92 gforget 1.2
93 roquet 1.3 p=argo_data.PRES_ADJUSTED(m,:);
94     p_QC=argo_data.PRES_ADJUSTED_QC(m,:);
95 roquet 1.4 if all(isnan(p)), p=argo_data.PRES(m,:); p_QC=argo_data.PRES_QC(m,:); end
96 roquet 1.3 p_QC(isnan(p))='5';
97 gforget 1.2
98 roquet 1.3 for n=1:length(p)-1; % doubles
99     tmp1=find(p(n+1:end)==p(n)); p(n+tmp1)=NaN; p_QC(n+tmp1)='5';
100 gforget 1.2 end
101    
102     bad_P=0;
103     tmp1=find(p_QC=='4');
104     if(length(tmp1)<=5);
105     %get rid of these few bad points and keep the profile
106 roquet 1.3 p(tmp1)=NaN;p_QC(tmp1)='5';
107 gforget 1.2 else;
108     %flag the profile (will be masked in the main file)
109     %but keep the bad points (to interp and be able to CHECK)
110     bad_P=1;
111     end;
112    
113 roquet 1.3 % temperature data
114     t=argo_data.TEMP_ADJUSTED(m,:);
115     t_QC=argo_data.TEMP_ADJUSTED_QC(m,:);
116     t_ERR=argo_data.TEMP_ADJUSTED_ERROR(m,:);
117     t_ERR(isnan(t_ERR))=0;
118 roquet 1.4 if all(isnan(t)), t=argo_data.TEMP(m,:); t_QC=argo_data.TEMP_QC(m,:); end
119 roquet 1.3
120     % salinity data
121     s=argo_data.PSAL_ADJUSTED(m,:);
122     s_QC=argo_data.PSAL_ADJUSTED_QC(m,:);
123     s_ERR=argo_data.PSAL_ADJUSTED_ERROR(m,:);
124     s_ERR(isnan(s_ERR))=0;
125 roquet 1.4 if all(isnan(s)), s=argo_data.PSAL(m,:); s_QC=argo_data.PSAL_QC(m,:); end
126 gforget 1.2
127 roquet 1.3 if isnan(t(1)); %this file does not contain temperature data...
128 gforget 1.2 t=NaN*p; t_ERR=0*p;
129     else;
130 roquet 1.3 t(~ismember(t_QC,'12'))=NaN;
131 gforget 1.2 end;
132 roquet 1.3 if isnan(s(1)); %this file does not contain salinity data...
133     s=NaN*p; s_ERR=0*p;
134 gforget 1.2 else;
135 roquet 1.3 s(~ismember(s_QC,'12'))=NaN;
136 gforget 1.2 end;
137    
138     profileCur.pnum_txt=pnum_txt;
139     profileCur.ymd=ymd; profileCur.hms=hms;
140     profileCur.lat=lat; profileCur.lon=lon;
141     profileCur.direc=direc;
142     profileCur.t=t;
143     profileCur.s=s;
144     profileCur.p=p;
145     profileCur.t_ERR=t_ERR;
146     profileCur.s_ERR=s_ERR;
147     profileCur.PorZisBAD=bad_P;
148    
149     varargout = {profileCur};
150    
151 gforget 1.1 end;
152    
153    
154    

  ViewVC Help
Powered by ViewVC 1.1.22