%load300
% Read the data from GMD 300m BAO data loggers
% Dave has split these data into daily files and corrected the PRT and Wind Dir
%You are correct on all counts.  yes, m/s on the wind speed.
%The PRT temperature is (accurate to within 0.1 deg C) is:  a0 +
%a1*(D3_PRTRES_Avg) + a2*(D3_PRTRES_Avg)^2 + a3*(D3_PRTRES_Avg)^3,
%a0 =    -246.058
%a1 =      2.36626
%a2 =  0.000923807
%a3 =  2.43906e-007

%The sonic anemometer is on the south boom
% The north pole points to 322 degrees.
%The the true wind direction should then be (SE2_SONICWD_Avg) - 38 degrees
%
% 300m
%"TOA5","CR1000","CR1000","2846","CR1000.Std.11","CPU:060516b_Met.CR1","10044","wkt30m"
%"TIMESTAMP","RECORD","SE1_SONICWS_Avg","SE2_SONICWD_Avg","SE2_SONICWD_Std","SE1_SONICWS_Std",
%"SE3_SONICTEMP_Avg","D3_PRTRES_Avg","D3_PRTTEMPAPPROX_Avg","SE4_HMPTEMP_Avg","SE9_HMPRH_Avg",
%"P1_AIRFLOW_Avg","SE10_ACPOWER","BT_BATVOLT_Min","PRT_AVG","SONICWDT_AVG"
%"TS","RN","ms","Deg","Deg","ms","mV","","Deg C","Deg C","%","Counts","ms","Volts","DegC","Deg True"
%"2007-06-14 14:22:00",0,3.37,230.5,0.502,0.012,13.42,105.8471,14.24,15.09,42.15,0,110.6,13.31,15.0,192.5
%"2007-06-14 14:22:30",1,3.418,231.1,0.269,0.026,13.38,105.8718,14.3,15.11,42.26,0,110.6,13.31,15.1,193.1

function [bao300 dt n] = load300( filename, nmax )

dt = NaN+zeros(nmax,7);
bao300 = NaN+zeros( nmax, 14);

%fprintf(1,'    Reading %s\n', filename );
f300 = fopen(filename,'r');
n = 0;
while ~feof(f300)
    %read in 4 header lines
    temp=fgetl(f300);
    if( temp(2) == '2')
        n = n + 1;
        dt(n,1:6) = sscanf(temp,'"%4d-%2d-%2d %2d:%2d:%2d');
        %dt(n,1:6)
        % start reading the data line after the date/time string
        % convert each , to a blank space then read
        [data]=sscanf(strrep( temp(23:length(temp)), ',', ' ' ),'%f');
        if length(data) == 15;
            bao300(n,1:14) = data(2:15);
        end
    end
end  %while ~feof(f300)

dt(:,7)=datenum(dt(:,1),dt(:,2),dt(:,3),dt(:,4),dt(:,5),dt(:,6));
%bao300(1:n,15) = dt(1:n,7); % Year Day

fclose(f300);
