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 |
roquet |
1.3 |
% 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 |
roquet |
1.2 |
% |
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 |
gforget |
1.5 |
% isBAD: 0 |
26 |
roquet |
1.2 |
% t: [1x998 double] |
27 |
|
|
% s: [1x998 double] |
28 |
|
|
% z: [1x998 double] |
29 |
|
|
% t_ERR: [1x998 double] |
30 |
|
|
% s_ERR: [1x998 double] |
31 |
gforget |
1.1 |
|
32 |
|
|
fileIn=[dataset.dirIn dataset.fileInList(nf).name]; |
33 |
|
|
instrType=dataset.subset(3:end); |
34 |
|
|
|
35 |
|
|
if m==0; |
36 |
roquet |
1.2 |
|
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 |
roquet |
1.3 |
dataset.nprofiles=prof_cur; |
55 |
|
|
dataset.index_prof=index_prof; |
56 |
|
|
|
57 |
|
|
varargout(1) = {dataset}; |
58 |
roquet |
1.2 |
|
59 |
|
|
|
60 |
gforget |
1.1 |
else;%if m==0; |
61 |
roquet |
1.2 |
|
62 |
|
|
|
63 |
|
|
% index_prof: position of beginning of each profile block in the .txt |
64 |
roquet |
1.3 |
index_prof=dataset.index_prof; |
65 |
roquet |
1.2 |
|
66 |
|
|
fid_cur=fopen(fileIn,'rt'); |
67 |
|
|
fseek(fid_cur,index_prof(m),'bof'); |
68 |
|
|
data_cur=NaN*zeros(10000,3); %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 |
gforget |
1.1 |
line_cur = fgetl(fid_cur); |
73 |
roquet |
1.2 |
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 |
gforget |
1.1 |
line_cur = fgetl(fid_cur); |
82 |
roquet |
1.2 |
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 |
gforget |
1.1 |
tmp1=cell2mat(var_cur(ii)); |
123 |
|
|
if ~isempty(findstr(tmp1,'Depth')); v_cur=[v_cur; [1 ii]]; end; |
124 |
|
|
if ~isempty(findstr(tmp1,'Temperatur')); v_cur=[v_cur; [2 ii]]; end; |
125 |
|
|
if ~isempty(findstr(tmp1,'Salinity')); v_cur=[v_cur; [3 ii]]; end; |
126 |
roquet |
1.2 |
end; |
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,3); |
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 |
gforget |
1.1 |
data_cur(count_cur,v_cur(:,1))=data_tmp(v_cur(:,2))'; |
145 |
roquet |
1.2 |
%apply loc and global QC: |
146 |
|
|
qc_loc=zeros(1,3); 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 |
gforget |
1.1 |
line_cur = fgetl(fid_cur); |
151 |
|
|
count_cur=count_cur+1; |
152 |
|
|
data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'---.---','**********'})); |
153 |
roquet |
1.2 |
end |
154 |
|
|
|
155 |
|
|
fclose(fid_cur); |
156 |
|
|
|
157 |
|
|
z=data_cur(1:count_cur-1,1); |
158 |
|
|
t=data_cur(1:count_cur-1,2); |
159 |
|
|
s=data_cur(1:count_cur-1,3); |
160 |
|
|
t_ERR=zeros(size(t)); s_ERR=t_ERR; z_ERR=[]; |
161 |
|
|
|
162 |
|
|
|
163 |
|
|
ymd=1e4*Year+1e2*Month+Day; |
164 |
|
|
tmp1=(Time-floor(Time))*3600; |
165 |
|
|
tmp2=floor(tmp1-floor(tmp1/60)*60); |
166 |
|
|
tmp1=floor(tmp1/60); |
167 |
|
|
hms=1e4*floor(Time)+1e2*tmp1+tmp2; |
168 |
|
|
direc=2; |
169 |
gforget |
1.5 |
isBAD=0; |
170 |
roquet |
1.2 |
|
171 |
|
|
profileCur.pnum_txt=pnum_txt; |
172 |
|
|
profileCur.ymd=ymd; profileCur.hms=hms; |
173 |
|
|
profileCur.lat=lat; profileCur.lon=lon; |
174 |
|
|
profileCur.direc=direc; |
175 |
gforget |
1.5 |
profileCur.isBAD=isBAD; |
176 |
gforget |
1.4 |
profileCur.T=t'; |
177 |
|
|
profileCur.S=s'; |
178 |
|
|
profileCur.depth=z'; |
179 |
|
|
profileCur.T_ERR=t_ERR'; |
180 |
|
|
profileCur.S_ERR=s_ERR'; |
181 |
|
|
profileCur.depth_ERR=z_ERR'; |
182 |
roquet |
1.2 |
%by convention profileCur.z etc are line vectors |
183 |
|
|
|
184 |
|
|
varargout = {profileCur}; |
185 |
|
|
|
186 |
gforget |
1.1 |
end; |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|