Home > robbins > whp_bot.m

whp_bot

PURPOSE ^

WHP_BOT Reads in standard WOCE.HY2 or WOCE.SEA ascii file

SYNOPSIS ^

function [bot,varn,units,qualt1,qualt2] = whp_bot(flname,qlevel)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [bot,varn,units,qualt1,qualt2] = whp_bot(flname,qlevel)
0002 
0003 % WHP_BOT Reads in standard WOCE.HY2 or WOCE.SEA ascii file
0004 %
0005 % Usage: [bot,prop_label,units,qwrd1,qwrd2] = whp_bot(flname,quality_level)
0006 %
0007 %    Outputs
0008 %       bot - array of data (each row is a bottle sample, columns are property)
0009 %       prop_label - array of string labels specifying property
0010 %                    for each column of bot
0011 %       units - array of string labels specifying units for each property
0012 %       qwrd1 - data quality word #1 (analyst assesment)
0013 %       qwrd2 - data quality word #2 (DQE assesment)
0014 %
0015 %    Inputs
0016 %       flname         - full path and name of *.HY2 or *.SEA file
0017 %       quality_level  - (optional) specifies which data quality flags to use
0018 %                        data elements which are flagged are assigned to NAN
0019 %                 2 - returns only the 'acceptable' measurements (defualt)
0020 %                 3 - includes 'questionable' measurements
0021 %                 4 - includes 'bad' measurements
0022 %                 9 - returns all data as reported in file: no NAN's assigned
0023 %
0024 % Paul E Robbins copywrite 19995
0025 
0026 
0027 %set quality level to highest standard unless otherwise specified
0028 if nargin == 1
0029   qlevel = 2;
0030 end
0031 fid = fopen(flname,'r');
0032 if fid == -1
0033   %try to find file in matlab_data directory
0034   fid = fopen([getenv('MATLAB_DATA'),flname],'r');
0035   if fid == -1
0036     fid = fopen([getenv('MATLAB_DATA'),'/bottle/woce/',flname],'r');
0037     if fid == -1;
0038        disp(['File ',flname,' not found'])
0039        break
0040     end
0041   end    
0042 end
0043 
0044 header = fgetl(fid);
0045 propline = fgetl(fid);
0046 %Find positions of quality words
0047 qw = findstr(propline,'QUALT');
0048 nvar = fix(qw(1)/8);         % maximum possible number of variables
0049 props = reshape(propline(1:nvar*8),8,nvar)';
0050 ok = ~all(props' == ' '); nvar2 = sum(ok);
0051 varn = props(ok,3:8);
0052 
0053 unitline = fgetl(fid);
0054 units = reshape(unitline(1:nvar2*8),8,nvar2)';
0055 units = units(:,2:8);
0056 
0057 starline = fgetl(fid);
0058 qualflags = reshape(starline(1:nvar2*8),8,nvar2)';
0059 qualflags = qualflags(:,8)== '*';
0060 nqual = sum(qualflags);            % number of quality flags
0061 nqw = length(qw);            % number of quality words, (1 or 2)
0062 
0063 bot = fscanf(fid,'%f',[nvar2+nqw inf]);
0064 
0065 qualt1 = bot(nvar2+1,:)';
0066 q1str = reshape(int2str(qualt1),nqual,length(qualt1))';
0067 
0068 if nqw == 2
0069   qualt2 = bot(nvar2+2,:)';
0070   q2str = reshape(int2str(qualt2),nqual,length(qualt2))';
0071 else
0072   qualt2 = [];
0073 end
0074 
0075 bot = bot(1:nvar2,:)'; 
0076 
0077 disp(['Loaded ',num2str(size(bot,1)),' bottles of data with ',...
0078     num2str(nvar2),' variables  from ',flname])
0079 disp(['Checking quality data flags using quality word #1'])
0080 
0081 qflags = find(qualflags)';
0082 
0083 nlines  = ceil(qflags/9);   %number of lines to break up variable report
0084 
0085 fprintf(1,'VARIABLE: ')
0086 for col = find(qualflags)'
0087  fprintf(1,'%s ',varn(col,:))
0088 end
0089 fprintf(1,'\n')
0090 
0091 fprintf(1,'MISSING: ')
0092 if qlevel < 9
0093   j = 0;
0094   for col = find(qualflags)'
0095     j = j+1;
0096     bad =q1str(:,j) =='9' | q1str(:,j)=='5' | bot(:,col)==-9 | bot(:,col)==-99;
0097 %    bad = q1str(:,j) =='9' | q1str(:,j)=='5' | q1str(:,j)=='1'
0098              %    | q1str(:,j)=='8' | q1str(:,j)=='7';
0099     bot(bad,col) = nan*bot(bad,col);
0100     fprintf(1,' %5i ',sum(bad)) 
0101   end
0102 end
0103 fprintf(1,'\n')
0104 
0105 fprintf(1,'BAD:     ')
0106 if qlevel < 4
0107   j = 0;
0108   for col = find(qualflags)'
0109     j = j+1;
0110     bad = q1str(:,j) =='4';
0111     bot(bad,col) = nan*bot(bad,col);
0112     fprintf(1,' %5i ',sum(bad)) 
0113   end
0114 end
0115 fprintf(1,'\n')
0116 
0117 fprintf(1,'QUESTNBL:')
0118 if qlevel < 3
0119   j = 0;
0120   for col = find(qualflags)'
0121     j = j+1;
0122     bad = q1str(:,j) =='3';
0123     bot(bad,col) = nan*bot(bad,col);
0124     fprintf(1,' %5i ',sum(bad)) 
0125   end
0126 end
0127 fprintf(1,'\n')
0128 
0129 fprintf(1,'REMAINNG:')
0130 if qlevel < 3
0131   j = 0;
0132   for col = find(qualflags)'
0133     j = j+1;
0134     ok = sum(~isnan(bot(:,col)));
0135     fprintf(1,' %5i ',ok) 
0136   end
0137 end
0138 fprintf(1,'\n')
0139 
0140 allbad = all(isnan(bot));
0141 if any(allbad)
0142   disp(' ');  disp(['Eliminating columns of data with no acceptable data...'])
0143   for j = find(allbad)
0144     disp(['  ',varn(j,:)])
0145   end
0146   bot = bot(:,~allbad);
0147   varn = varn(~allbad,:);
0148   units = units(~allbad,:);
0149 end
0150 
0151 %convert T-90 to T-68 if needed
0152 for j = 1:size(units,1)
0153   if any(findstr(units(j,:),'ITS-90'));
0154     disp(['  Converting temperature from ITS-90 to IPTS-68 for ',varn(j,:)])
0155       bot(:,j) = 1.00024*bot(:,j);
0156       units(j,:) = 'IPTS-68';
0157   end
0158 end
0159 
0160 
0161 fclose(fid);
0162

Generated on Wed 30-Nov-2005 15:40:09 by m2html © 2003