%BAOPLT300_loop_func
% Plot 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 [retval] = ReadSTIformat( by, bm, bd, ey, em, ed )
%clear

if ( nargin == 0 )
    bys = input('Input year to process (2007) ','s');
    bms = input('Input the month to process (1-12) ','s');
    bds = input('Input the beginning day to process (1-31) ','s');
    eys = input('Input year to process (2007) ','s');
    ems = input('Input the month to process (1-12) ','s');
    eds = input('Input end day to process (1-31) ','s');
    by = str2double( bys );
    bm = str2double( bms );
    bd = str2double( bds );
    ey = str2double( eys );
    em = str2double( ems );
    ed = str2double( eds );
end

bdn = datenum([by bm bd 0 0 0]);
edn = datenum([ey em ed 0 0 0]);

for i = bdn:edn
    dv=datevec(i);
    if i == bdn && dv(4) > 0
        continue
    end
    yday = md2yd( dv(1), dv(2), dv(3) );
   
    datenum = zeros(24,1);
    nhts = zeros(24,1);
    ht = zeros(100,24);
    s = zeros(100,24);
    d = zeros(100,24);
    snrv = zeros(100,24);
    snrn = zeros(100,24);
    snre = zeros(100,24);

    wpath='S:/RICO_2005/SEWARD_JOHNSON/radar/profiler/Processed/Motion_Correction/Corrected_Winds/'

    fname = sprintf('%sric%02d%03d.w1b', wpath, dv(1)-2000, yday );
    fid = fopen(fname, 'r');
    for i=1:50
        line=fgetl(fid);
    end
    
    j = 0;
    while ~feof(fid)
        j = j + 1;
        line=fgetl(fid);
        data = sscanf(line,'%2d%2d %d');
        datenum(j) = datenum(dv(1),dv(2),dv(3),data(1),data(2),0);
        nhts(j) = data(3);
        for i = 1:nhts(j)
            line=fgetl(fid);
            data = sscanf(line,'%f');
            ht(i,j) = data(2);
            s(i,j) = data(3);
            d(i,j) = data(4);
            snrv(i,j) = data(14);
            snrn(i,j) = data(16);
            snre(i,j) = data(18);
        end
    end
    fclose(fid);
      
end % loop though each day
retval = 0;
