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

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

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


Revision 1.1 - (hide annotations) (download)
Tue Jul 21 19:50:21 2015 UTC (10 years ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65t
- wod 2013 case (similar to wod 2005 case, but allowing for additional variables).

1 gforget 1.1 function [varargout]=profile_read_wod13(dataset,nf,m,varargin);
2     % read hydrographic data in the WOD05 csv format
3     % return the m-th profile from the nf-th file referenced in
4     % dataset.fileInList.
5     %
6     % if m=0 :
7     % return the information on the nf-th file referenced in
8     % dataset.fileInList.
9     % dataset=profile_read_wod05(dataset,nf,0);
10     % dataset.nprofiles: number of profiles in the nf-th file
11     % dataset.index_prof: list of position number for each profile block
12     %
13     % if m~=0 :
14     % return the m-th profile from the nf-th file referenced in
15     % dataset.fileInList.
16     % profileCur=profile_read_odv(dataset,nf,m);
17     %
18     % profileCur =
19     % pnum_txt: 'WOD-CTD//29-1103//4.'
20     % ymd: 19900210
21     % hms: 82659
22     % lat: 40.94
23     % lon: 2.6467
24     % direc: 2
25     % PorZisBAD: 0
26     % t: [1x998 double]
27     % s: [1x998 double]
28     % z: [1x998 double]
29     % t_ERR: [1x998 double]
30     % s_ERR: [1x998 double]
31    
32     fileIn=[dataset.dirIn dataset.fileInList(nf).name];
33     instrType=dataset.subset(3:end);
34    
35     if m==0;
36    
37     % return the number of profiles in the file
38     % also build an index of first-line prosition of profiles: index_prof
39     fid_cur=fopen(fileIn,'rt');
40     prof_cur=0;index_prof=[];
41     while ~feof(fid_cur);
42     line_cur = fgetl(fid_cur);
43     if ~isempty(findstr(line_cur,'NODC Cruise ID'));
44     prof_cur=prof_cur+1;
45     index_prof(end+1)=ftell(fid_cur)-length(line_cur)-1;
46     %to jump over second possible occurence of NODC Cruise ID
47     while isempty(findstr(line_cur,'END OF VARIABLES SECTION'));
48     line_cur = fgetl(fid_cur);
49     end;
50     end;
51     end;
52     fclose(fid_cur);
53    
54     dataset.nprofiles=prof_cur;
55     dataset.index_prof=index_prof;
56    
57     varargout(1) = {dataset};
58    
59    
60     else;%if m==0;
61    
62    
63     % index_prof: position of beginning of each profile block in the .txt
64     index_prof=dataset.index_prof;
65    
66     fid_cur=fopen(fileIn,'rt');
67     fseek(fid_cur,index_prof(m),'bof');
68     data_cur=NaN*zeros(10000,5); %array that is used to store one profile
69    
70     line_cur = fgetl(fid_cur);
71     while isempty(findstr(line_cur,'NODC Cruise ID'));
72     line_cur = fgetl(fid_cur);
73     end;
74     tmp1=findstr(line_cur,',,');
75     pnum_txt=['WOD-' instrType '//' deblank(line_cur(tmp1(1)+2:tmp1(2)-1))];
76    
77     probe_type='-1'; Time=12.0;
78     lon=[]; lat=[]; Year=[]; Month=[]; Day=[];
79    
80     while isempty(findstr(line_cur,'VARIABLES'));
81     line_cur = fgetl(fid_cur);
82     var_cur=textscan(line_cur,'%s','delimiter',','); var_cur=var_cur{1};
83    
84     if ~isempty(findstr(cell2mat(var_cur(1)),'Latitude'));
85     lat=str2num(cell2mat(var_cur(3)));
86     end;
87     if ~isempty(findstr(cell2mat(var_cur(1)),'Longitude'));
88     lon=str2num(cell2mat(var_cur(3)));
89     end;
90     if ~isempty(findstr(cell2mat(var_cur(1)),'Year'));
91     Year=str2num(cell2mat(var_cur(3)));
92     end;
93     if ~isempty(findstr(cell2mat(var_cur(1)),'Month'));
94     Month=str2num(cell2mat(var_cur(3)));
95     end;
96     if ~isempty(findstr(cell2mat(var_cur(1)),'Day'));
97     Day=str2num(cell2mat(var_cur(3)));
98     end;
99     if ~isempty(findstr(cell2mat(var_cur(1)),'Time'));
100     Time=str2num(cell2mat(var_cur(3)));
101     end;
102     if ~isempty(findstr(cell2mat(var_cur(1)),'probe_type'));
103     probe_type=cell2mat(var_cur(3));
104     end;
105    
106     end;
107    
108     %case when necessary information missing: put dummy info
109     if isempty(lon)|isempty(lat)|isempty(Year)|isempty(Month)|isempty(Day)
110     lat=-89.9; lon=0.1; Year=1800; Month=1; Day=1;
111     elseif Day==0;
112     lat=-89.9; lon=0.1; Year=1800; Month=1; Day=1;
113     end;
114    
115     if lon < 0; lon=lon+360;end;
116    
117     pnum_txt=[pnum_txt '//' deblank(probe_type)];
118    
119     var_cur=textscan(line_cur,'%s','delimiter',','); var_cur=var_cur{1};
120     v_cur=[];
121     for ii=1:length(var_cur);
122     tmp1=deblank(cell2mat(var_cur(ii)));
123     jj=find(strcmp(dataset.var_in,tmp1));
124     if ~isempty(jj); v_cur=[v_cur; [jj ii]]; end;
125     end;
126    
127     line_cur = fgetl(fid_cur);
128     line_cur = fgetl(fid_cur);
129    
130     data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'Prof-Flag'}));
131     qc_cast=zeros(1,5);
132     %get cast qc??
133     qc_cast(v_cur(:,1))=data_tmp(v_cur(:,2)+1)';
134     qc_cast=1*(qc_cast==2|qc_cast==3|qc_cast==9);
135     %if ~isempty(find(qc_cast>0)); fprintf(['cast qc: ' num2str(qc_cast) ' for ' fileIn ' m=' num2str(m) '\n']); end;
136     %
137    
138     data_cur(:)=NaN;
139     line_cur = fgetl(fid_cur);
140     count_cur=1;
141     data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'---.---','**********'}));
142     while ~isempty(data_tmp);
143     %store data:
144     data_cur(count_cur,v_cur(:,1))=data_tmp(v_cur(:,2))';
145     %apply loc and global QC:
146     qc_loc=zeros(1,5); qc_loc(v_cur(:,1))=data_tmp(v_cur(:,2)+1)';
147     qc_bad=find(qc_loc(v_cur(:,1))>0|qc_cast(v_cur(:,1))>0);
148     data_cur(count_cur,v_cur(qc_bad,1))=NaN;
149     %read the next line:
150     line_cur = fgetl(fid_cur);
151     count_cur=count_cur+1;
152     data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'---.---','**********'}));
153     end
154    
155     fclose(fid_cur);
156    
157     %
158    
159     ymd=1e4*Year+1e2*Month+Day;
160     tmp1=(Time-floor(Time))*3600;
161     tmp2=floor(tmp1-floor(tmp1/60)*60);
162     tmp1=floor(tmp1/60);
163     hms=1e4*floor(Time)+1e2*tmp1+tmp2;
164     direc=2;
165     PorZisBAD=0;
166    
167     profileCur.pnum_txt=pnum_txt;
168     profileCur.ymd=ymd; profileCur.hms=hms;
169     profileCur.lat=lat; profileCur.lon=lon;
170     profileCur.direc=direc;
171     profileCur.PorZisBAD=PorZisBAD;
172     %by convention profileCur.z etc are line vectors
173     for ii=1:length(dataset.var_in);
174     jj=find(v_cur(:,1)==ii);
175     if ~isempty(jj);
176     eval(['profileCur.' dataset.var_out{ii} '=data_cur(1:count_cur-1,jj)'';']);
177     %eval(['profileCur.' dataset.var_out{ii} '_ERR=0*data_cur(1:count_cur-1,jj)'';']);
178     else;
179     eval(['profileCur.' dataset.var_out{ii} '=NaN*data_cur(1:count_cur-1,1)'';']);
180     %eval(['profileCur.' dataset.var_out{ii} '_ERR=NaN*data_cur(1:count_cur-1,1)'';']);
181     end;
182     end;
183    
184     varargout = {profileCur};
185    
186     end;
187    
188    
189    

  ViewVC Help
Powered by ViewVC 1.1.22