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

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

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


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

  ViewVC Help
Powered by ViewVC 1.1.22