1 |
gforget |
1.1 |
function [varargout]=profile_read_wod05(dataset,nf,m); |
2 |
|
|
|
3 |
|
|
fileIn=[dataset.dirIn dataset.fileInList(nf).name]; |
4 |
|
|
instrType=dataset.subset(3:end); |
5 |
|
|
global fid_cur; |
6 |
|
|
|
7 |
|
|
if m==0; |
8 |
|
|
%read the file and put the data in common blocks: |
9 |
|
|
|
10 |
|
|
fid_cur=fopen(fileIn,'rt'); |
11 |
|
|
prof_cur=0; |
12 |
|
|
while ~feof(fid_cur); |
13 |
|
|
line_cur = fgetl(fid_cur); |
14 |
|
|
if ~isempty(findstr(line_cur,'NODC Cruise ID')); |
15 |
|
|
prof_cur=prof_cur+1; |
16 |
|
|
%to jump over second possible occurence of NODC Cruise ID |
17 |
|
|
while isempty(findstr(line_cur,'END OF VARIABLES SECTION')); |
18 |
|
|
line_cur = fgetl(fid_cur); |
19 |
|
|
end; |
20 |
|
|
end; |
21 |
|
|
end; |
22 |
|
|
|
23 |
|
|
varargout(1) = {prof_cur}; |
24 |
|
|
|
25 |
|
|
fclose(fid_cur); |
26 |
|
|
fid_cur=fopen(fileIn,'rt'); |
27 |
|
|
|
28 |
|
|
else;%if m==0; |
29 |
|
|
|
30 |
|
|
data_cur=NaN*zeros(10000,3); %array that is used to store one profile |
31 |
|
|
|
32 |
|
|
line_cur = fgetl(fid_cur); |
33 |
|
|
while isempty(findstr(line_cur,'NODC Cruise ID')); |
34 |
|
|
line_cur = fgetl(fid_cur); |
35 |
|
|
end; |
36 |
|
|
tmp1=findstr(line_cur,',,'); |
37 |
|
|
pnum_txt=['WOD-' instrType '//' deblank(line_cur(tmp1(1)+2:tmp1(2)-1))]; |
38 |
|
|
|
39 |
|
|
probe_type='-1'; Time=12.0; |
40 |
|
|
lon=[]; lat=[]; Year=[]; Month=[]; Day=[]; |
41 |
|
|
|
42 |
|
|
while isempty(findstr(line_cur,'VARIABLES')); |
43 |
|
|
line_cur = fgetl(fid_cur); |
44 |
|
|
var_cur=textscan(line_cur,'%s','delimiter',','); var_cur=var_cur{1}; |
45 |
|
|
|
46 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Latitude')); |
47 |
|
|
lat=str2num(cell2mat(var_cur(3))); |
48 |
|
|
end; |
49 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Longitude')); |
50 |
|
|
lon=str2num(cell2mat(var_cur(3))); |
51 |
|
|
end; |
52 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Year')); |
53 |
|
|
Year=str2num(cell2mat(var_cur(3))); |
54 |
|
|
end; |
55 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Month')); |
56 |
|
|
Month=str2num(cell2mat(var_cur(3))); |
57 |
|
|
end; |
58 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Day')); |
59 |
|
|
Day=str2num(cell2mat(var_cur(3))); |
60 |
|
|
end; |
61 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'Time')); |
62 |
|
|
Time=str2num(cell2mat(var_cur(3))); |
63 |
|
|
end; |
64 |
|
|
if ~isempty(findstr(cell2mat(var_cur(1)),'probe_type')); |
65 |
|
|
probe_type=cell2mat(var_cur(3)); |
66 |
|
|
end; |
67 |
|
|
|
68 |
|
|
end; |
69 |
|
|
|
70 |
|
|
%case when necessary information missing: put dummy info |
71 |
|
|
if isempty(lon)|isempty(lat)|isempty(Year)|isempty(Month)|isempty(Day) |
72 |
|
|
lat=-89.9; lon=0.1; Year=1800; Month=1; Day=1; |
73 |
|
|
elseif Day==0; |
74 |
|
|
lat=-89.9; lon=0.1; Year=1800; Month=1; Day=1; |
75 |
|
|
end; |
76 |
|
|
|
77 |
|
|
if lon < 0; lon=lon+360;end; |
78 |
|
|
|
79 |
|
|
pnum_txt=[pnum_txt '//' deblank(probe_type)]; |
80 |
|
|
|
81 |
|
|
var_cur=textscan(line_cur,'%s','delimiter',','); var_cur=var_cur{1}; |
82 |
|
|
v_cur=[]; |
83 |
|
|
for ii=1:length(var_cur); |
84 |
|
|
tmp1=cell2mat(var_cur(ii)); |
85 |
|
|
if ~isempty(findstr(tmp1,'Depth')); v_cur=[v_cur; [1 ii]]; end; |
86 |
|
|
if ~isempty(findstr(tmp1,'Temperatur')); v_cur=[v_cur; [2 ii]]; end; |
87 |
|
|
if ~isempty(findstr(tmp1,'Salinity')); v_cur=[v_cur; [3 ii]]; end; |
88 |
|
|
end; |
89 |
|
|
line_cur = fgetl(fid_cur); |
90 |
|
|
line_cur = fgetl(fid_cur); |
91 |
|
|
|
92 |
|
|
data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'Prof-Flag'})); |
93 |
|
|
qc_cast=zeros(1,3); |
94 |
|
|
%get cast qc?? |
95 |
|
|
qc_cast(v_cur(:,1))=data_tmp(v_cur(:,2)+1)'; |
96 |
|
|
qc_cast=1*(qc_cast==2|qc_cast==3|qc_cast==9); |
97 |
|
|
%if ~isempty(find(qc_cast>0)); fprintf(['cast qc: ' num2str(qc_cast) ' for ' fileIn ' m=' num2str(m) '\n']); end; |
98 |
|
|
% |
99 |
|
|
|
100 |
|
|
data_cur(:)=NaN; |
101 |
|
|
line_cur = fgetl(fid_cur); |
102 |
|
|
count_cur=1; |
103 |
|
|
data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'---.---','**********'})); |
104 |
|
|
while ~isempty(data_tmp); |
105 |
|
|
%store data: |
106 |
|
|
data_cur(count_cur,v_cur(:,1))=data_tmp(v_cur(:,2))'; |
107 |
|
|
%apply loc and global QC: |
108 |
|
|
qc_loc=zeros(1,3); qc_loc(v_cur(:,1))=data_tmp(v_cur(:,2)+1)'; |
109 |
|
|
qc_bad=find(qc_loc(v_cur(:,1))>0|qc_cast(v_cur(:,1))>0); |
110 |
|
|
data_cur(count_cur,v_cur(qc_bad,1))=NaN; |
111 |
|
|
%read the next line: |
112 |
|
|
line_cur = fgetl(fid_cur); |
113 |
|
|
count_cur=count_cur+1; |
114 |
|
|
data_tmp=cell2mat(textscan(line_cur,'%f','delimiter',',','treatAsEmpty',{'---.---','**********'})); |
115 |
|
|
end |
116 |
|
|
|
117 |
|
|
if feof(fid_cur); fclose(fid_cur); end; |
118 |
|
|
|
119 |
|
|
z=data_cur(1:count_cur-1,1); |
120 |
|
|
t=data_cur(1:count_cur-1,2); |
121 |
|
|
s=data_cur(1:count_cur-1,3); |
122 |
|
|
t_ERR=zeros(size(t)); s_ERR=t_ERR; z_ERR=[]; |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
ymd=1e4*Year+1e2*Month+Day; |
126 |
|
|
tmp1=(Time-floor(Time))*3600; |
127 |
|
|
tmp2=floor(tmp1-floor(tmp1/60)*60); |
128 |
|
|
tmp1=floor(tmp1/60); |
129 |
|
|
hms=1e4*floor(Time)+1e2*tmp1+tmp2; |
130 |
|
|
direc=2; |
131 |
|
|
PorZisBAD=0; |
132 |
|
|
|
133 |
|
|
profileCur.pnum_txt=pnum_txt; |
134 |
|
|
profileCur.ymd=ymd; profileCur.hms=hms; |
135 |
|
|
profileCur.lat=lat; profileCur.lon=lon; |
136 |
|
|
profileCur.direc=direc; |
137 |
|
|
profileCur.PorZisBAD=PorZisBAD; |
138 |
|
|
profileCur.t=t'; |
139 |
|
|
profileCur.s=s'; |
140 |
|
|
profileCur.z=z'; |
141 |
|
|
profileCur.t_ERR=t_ERR'; |
142 |
|
|
profileCur.s_ERR=s_ERR'; |
143 |
|
|
profileCur.z_ERR=z_ERR'; |
144 |
|
|
%by convention profileCur.z etc are line vectors |
145 |
|
|
|
146 |
|
|
varargout = {profileCur}; |
147 |
|
|
|
148 |
|
|
end; |
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|