-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhp_bot.m
162 lines (139 loc) · 4.37 KB
/
whp_bot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function [bot,varn,units,qualt1,qualt2] = whp_bot(flname,qlevel)
% WHP_BOT Reads in standard WOCE.HY2 or WOCE.SEA ascii file
%
% Usage: [bot,prop_label,units,qwrd1,qwrd2] = whp_bot(flname,quality_level)
%
% Outputs
% bot - array of data (each row is a bottle sample, columns are property)
% prop_label - array of string labels specifying property
% for each column of bot
% units - array of string labels specifying units for each property
% qwrd1 - data quality word #1 (analyst assesment)
% qwrd2 - data quality word #2 (DQE assesment)
%
% Inputs
% flname - full path and name of *.HY2 or *.SEA file
% quality_level - (optional) specifies which data quality flags to use
% data elements which are flagged are assigned to NAN
% 2 - returns only the 'acceptable' measurements (defualt)
% 3 - includes 'questionable' measurements
% 4 - includes 'bad' measurements
% 9 - returns all data as reported in file: no NAN's assigned
%
% Paul E Robbins copywrite 19995
%set quality level to highest standard unless otherwise specified
if nargin == 1
qlevel = 2;
end
fid = fopen(flname,'r');
if fid == -1
%try to find file in matlab_data directory
fid = fopen([getenv('MATLAB_DATA'),flname],'r');
if fid == -1
fid = fopen([getenv('MATLAB_DATA'),'/bottle/woce/',flname],'r');
if fid == -1;
disp(['File ',flname,' not found'])
break
end
end
end
header = fgetl(fid);
propline = fgetl(fid);
%Find positions of quality words
qw = findstr(propline,'QUALT');
nvar = fix(qw(1)/8); % maximum possible number of variables
props = reshape(propline(1:nvar*8),8,nvar)';
ok = ~all(props' == ' '); nvar2 = sum(ok);
varn = props(ok,3:8);
unitline = fgetl(fid);
units = reshape(unitline(1:nvar2*8),8,nvar2)';
units = units(:,2:8);
starline = fgetl(fid);
qualflags = reshape(starline(1:nvar2*8),8,nvar2)';
qualflags = qualflags(:,8)== '*';
nqual = sum(qualflags); % number of quality flags
nqw = length(qw); % number of quality words, (1 or 2)
bot = fscanf(fid,'%f',[nvar2+nqw inf]);
qualt1 = bot(nvar2+1,:)';
q1str = reshape(int2str(qualt1),nqual,length(qualt1))';
if nqw == 2
qualt2 = bot(nvar2+2,:)';
q2str = reshape(int2str(qualt2),nqual,length(qualt2))';
else
qualt2 = [];
end
bot = bot(1:nvar2,:)';
disp(['Loaded ',num2str(size(bot,1)),' bottles of data with ',...
num2str(nvar2),' variables from ',flname])
disp(['Checking quality data flags using quality word #1'])
qflags = find(qualflags)';
nlines = ceil(qflags/9); %number of lines to break up variable report
fprintf(1,'VARIABLE: ')
for col = find(qualflags)'
fprintf(1,'%s ',varn(col,:))
end
fprintf(1,'\n')
fprintf(1,'MISSING: ')
if qlevel < 9
j = 0;
for col = find(qualflags)'
j = j+1;
bad =q1str(:,j) =='9' | q1str(:,j)=='5' | bot(:,col)==-9 | bot(:,col)==-99;
% bad = q1str(:,j) =='9' | q1str(:,j)=='5' | q1str(:,j)=='1'
% | q1str(:,j)=='8' | q1str(:,j)=='7';
bot(bad,col) = nan*bot(bad,col);
fprintf(1,' %5i ',sum(bad))
end
end
fprintf(1,'\n')
fprintf(1,'BAD: ')
if qlevel < 4
j = 0;
for col = find(qualflags)'
j = j+1;
bad = q1str(:,j) =='4';
bot(bad,col) = nan*bot(bad,col);
fprintf(1,' %5i ',sum(bad))
end
end
fprintf(1,'\n')
fprintf(1,'QUESTNBL:')
if qlevel < 3
j = 0;
for col = find(qualflags)'
j = j+1;
bad = q1str(:,j) =='3';
bot(bad,col) = nan*bot(bad,col);
fprintf(1,' %5i ',sum(bad))
end
end
fprintf(1,'\n')
fprintf(1,'REMAINNG:')
if qlevel < 3
j = 0;
for col = find(qualflags)'
j = j+1;
ok = sum(~isnan(bot(:,col)));
fprintf(1,' %5i ',ok)
end
end
fprintf(1,'\n')
allbad = all(isnan(bot));
if any(allbad)
disp(' '); disp(['Eliminating columns of data with no acceptable data...'])
for j = find(allbad)
disp([' ',varn(j,:)])
end
bot = bot(:,~allbad);
varn = varn(~allbad,:);
units = units(~allbad,:);
end
%convert T-90 to T-68 if needed
for j = 1:size(units,1)
if any(findstr(units(j,:),'ITS-90'));
disp([' Converting temperature from ITS-90 to IPTS-68 for ',varn(j,:)])
bot(:,j) = 1.00024*bot(:,j);
units(j,:) = 'IPTS-68';
end
end
fclose(fid);