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

Contents of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_external/profiles_read_odv.m

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


Revision 1.7 - (show annotations) (download)
Mon Feb 15 14:24:17 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.6: +3 -3 lines
- profiles_read_argo.m: revise treatment of QC flags
- all: rename profileCur.PorZisBAD as profileCur.isBAD

1 function [varargout]=profile_read_odv(dataset,nf,m,varargin)
2 % read seal data in the odv spreadsheet format
3 %
4 % if m=0 :
5 % return the information on the nf-th file referenced in
6 % dataset.fileInList.
7 % dataset=profile_read_odv(dataset,nf,0);
8 % dataset.nprofiles: number of profiles in the nf-th file
9 % dataset.Iprofile: index referencing the profile for each dataline
10 %
11 % if m~=0 :
12 % return the m-th profile from the nf-th file referenced in
13 % dataset.fileInList.
14 % profileCur=profile_read_odv(dataset,nf,m);
15 %
16 % profileCur = (m-th profile of nf-th file)
17 % pnum_txt: '5900841'
18 % ymd: 20060101
19 % hms: 3207
20 % lat: -46.709
21 % lon: 137.501
22 % direc: 1
23 % t: [1x115 single]
24 % s: [1x115 single]
25 % p: [1x115 single]
26 % t_ERR: [1x115 single]
27 % s_ERR: [1x115 single]
28 % isBAD: 0
29 %
30 % IMPORTANT: Use three global variables: pnum Date and Data.
31
32 global pnum Date Data
33
34 fileIn=[dataset.dirIn dataset.fileInList(nf).name];
35
36 if m==0;
37
38 % return the number of profiles in the file
39 % also build an index of first-line prosition of profiles: index_prof
40 fid_cur=fopen(fileIn,'rt');
41 nprofiles=0;index_prof=[];
42
43 % jump comment line at the beginning
44 line_cur = fgetl(fid_cur);
45 while ~feof(fid_cur) & strcmp(line_cur(1:2),'//')
46 line_cur = fgetl(fid_cur);
47 continue
48 end
49
50 % analyse data description line
51 I=[0 find(double(line_cur)==9) length(line_cur)+1];
52 format=[];
53 % column index for (in this order) :
54 % Cruise, Station, Date, Lon, Lat, Dep, Dep_qv, Temp,
55 % Temp_qv, Sal, Sal_qv
56 for ii=1:length(I)-1,
57 field=line_cur(I(ii)+1:I(ii+1)-1);
58 field=field(1:min([6 length(field)]));
59 switch field
60 case 'Cruise'
61 format(1)=ii;
62 case 'Statio'
63 format(2)=ii;
64 case 'yyyy-m'
65 format(3)=ii;
66 case {'Longit'}
67 format(4)=ii;
68 case {'Latitu'}
69 format(5)=ii;
70 case {'Depth '}
71 format([6 7])=[ii ii+1];
72 case {'Temper'}
73 format([8 9])=[ii ii+1];
74 case {'Salini'}
75 format([10 11])=[ii ii+1];
76 end
77 end
78
79 % read end of the textfile
80 nlines=0;nbuffer=100000;niter=0;
81 while ~feof(fid_cur);
82 niter=niter+1;
83 data_odv=cell(length(format)-1,nbuffer);
84 for ii=1:nbuffer,
85 tline=fgets(fid_cur);
86 nlines=nlines+1;
87 I_sep=[0 find(double(tline)==9)];
88 data_odv{1,ii}=[ tline(I_sep(format(1))+1:I_sep(format(1)+1)-1) '//' ...
89 tline(I_sep(format(2))+1:I_sep(format(2)+1)-1) ];
90 data_odv{2,ii}=tline(I_sep(format(3))+1:I_sep(format(3)+1)-1);
91 for kk=4:length(format),
92 I=I_sep(format(kk))+1:I_sep(format(kk)+1)-1;
93 if length(I)>1,
94 data_odv{kk-1,ii}=tline(I);
95 elseif isempty(I),
96 data_odv{kk-1,ii}='99999';
97 else
98 val=tline(I);
99 if val==0,
100 data_odv{kk-1,ii}='99999';
101 else
102 data_odv{kk-1,ii}=val;
103 end
104 end
105 end
106 if feof(fid_cur), break, end
107 end
108 data_odv=data_odv(:,1:ii);
109 data=data_odv(3:length(format)-1,:);
110 datanum=sscanf(sprintf('%s,',data{:}), '%g,');
111 datanum(datanum==99999)=NaN;
112
113 %no salinity case
114 if dataset.inclS,
115 datanum=reshape(datanum(:),8,ii);
116 else
117 datanum=reshape(datanum(:),6,ii);
118 end
119
120 fprintf('%d lines\n',nlines);
121 if niter==1,
122 pnum=data_odv(1,:);
123 Date=data_odv(2,:);
124 Data=datanum;
125 else
126 pnum=[pnum data_odv(1,:)];
127 Date=[Date data_odv(2,:)];
128 Data=[Data datanum];
129 end
130
131 end
132 fclose(fid_cur);
133
134 % get rid of empty indicator string
135 [pnum_txt_list,Iprof]=unique(pnum);
136 if size(Iprof,2)==1; Iprof=Iprof'; end;
137 for kk=1:length(pnum),
138 if strcmp(pnum_txt_list{kk},'//'),
139 pnum_txt_list=pnum_txt_list(setdiff(1:length(pnum_txt_list),kk));
140 Iprof(kk)=[];
141 break
142 end
143 end
144
145 % sort index of profile
146 [Iprof_sort,J]=sort(Iprof);
147 pnum_txt_sort=pnum_txt_list(J);
148
149 % write index of profile
150 Iprof_sort=[Iprof_sort nlines+1];
151 Iprofile=zeros(nlines,1);
152 for kk=1:length(Iprof_sort)-1,
153 for ii=Iprof_sort(kk):Iprof_sort(kk+1)-1,
154 Iprofile(ii)=kk;
155 end
156 end
157 dataset.Iprofile=Iprofile;
158
159 % number of profiles
160 dataset.nprofiles=length(Iprof);
161
162 varargout(1) = {dataset};
163
164
165 else;%if m==0;
166
167 % profile coordinates
168 Iprof=find(dataset.Iprofile==m);
169 pnum_txt=pnum{Iprof(1)};
170 lon=Data(1,Iprof(1));
171 lat=Data(2,Iprof(1));
172 strdate=Date{Iprof(1)};
173 if length(strdate)<10, varargout = {[]}; return; end
174 ymd=str2num(strdate([1:4 6:7 9:10]));
175 hms=0;
176 if length(strdate)==19, hms=str2num(strdate([12:13 15:16 18:19])); end
177 if length(strdate)==16, hms=str2num(strdate([12:13 15:16]))*100; end
178 if length(strdate)==13, hms=str2num(strdate([12:13]))*10000; end
179
180 %case when necessary information missing: dont retrieve profile
181 if isempty(lon)|isempty(lat)|isempty(ymd), varargout = {[]}; return; end
182 if lon < 0; lon=lon+360; end;
183
184 % get T/S data
185 z=Data(3,Iprof);
186 z_qv=Data(4,Iprof);z_qv(isempty(z_qv))=1;
187 t=Data(5,Iprof);
188 t_qv=Data(6,Iprof);t_qv(isempty(t_qv))=1;
189 if dataset.inclS,
190 s=Data(7,Iprof);
191 s_qv=Data(8,Iprof);s_qv(isempty(s_qv))=1;
192 else
193 s=t*NaN; s_qv=t*NaN; s_ERR=t*NaN;
194 end
195
196 I=find(isnan(z)|z_qv~=0);
197 z(I)=[]; t(I)=[]; t_qv(I)=[];
198 t(t_qv~=0)=NaN;
199 t_ERR=t*0;
200 if dataset.inclS,
201 s_qv(I)=[]; s(I)=[];
202 s(s_qv~=0)=NaN; s_ERR=s*0;
203 end
204 z_ERR=t*0;
205
206 direc=2;
207 isBAD=0;
208
209 profileCur.pnum_txt=pnum_txt;
210 profileCur.ymd=ymd; profileCur.hms=hms;
211 profileCur.lat=lat; profileCur.lon=lon;
212 profileCur.direc=direc;
213 profileCur.isBAD=isBAD;
214 profileCur.T=t;
215 profileCur.S=s;
216 profileCur.depth=z;
217 profileCur.T_ERR=t_ERR;
218 profileCur.S_ERR=s_ERR;
219 profileCur.depth_ERR=z_ERR;
220
221 varargout = {profileCur};
222
223 end;
224
225
226

  ViewVC Help
Powered by ViewVC 1.1.22