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

Annotation 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.1 - (hide annotations) (download)
Mon Apr 11 21:03:35 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
new interface of import functions, with the possibility to load the dataset when m=0
then retrieve profiles individually
[nprofiles,data]=profile_read_'type'(dataset,nf,0);
then
profileCur=profile_read_'type'(dataset,nf,m,data); (m>0)

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

  ViewVC Help
Powered by ViewVC 1.1.22