disp('read_SCS_08')
clear
close all
fclose('all');
% This is the cvs daily file and not the SCS from our system
md=input('Input start mon and day to evaluate (0319 -3/21).... ','s');

prtit = 1;

ict = 0;

read_parameters_ICEALOT; %Reading parameter files flux conf from D:/data/lb/flux_eval_rhb_06
way_raw_data_flux = 'S:\ICEALOT_2008\KNORR\scs\Raw\';
way_images_flux = 'S:\ICEALOT_2008\KNORR\flux\Raw_Images\';
way_images_comp = 'S:\ICEALOT_2008\KNORR\Combined_instruments\comparisons\Raw_Images\';

e=[way_raw_data_flux 'KN08' md '_00.csv'];

disp(['Reading SCS data from file  ',e]);
fid=fopen(e,'r');

    %R/V Knorr Calliope CSV data file  (Time stamps are GMT)
    %Date, Time_GMT, Depth12, Depth35, Air_Temp, WXT5_Ta, WXT5_Pa, dec_lat, dec_lon, EDO_knt, GPS_COG, GPS_SOG, Gyro, IMET_BPR, IMET_SWR, WXT5_Ri, WXT5_Rc, HRH, WXT5_Ua, WXT5_Dm, WXT5_Sm, SBE45C, SBE45S, SBE45T, Salinity, SSCND, Fluorometer, SSTMP, SSV, Wnd_Dir, TWD_5, Wnd_Spd, TWS_5, HdChkSum=52
    %2008/03/22, 00:00:31, , , 4.29, 4.70, 1011.1, 41.1895600, -72.4021870, , 70.00, 11.60, 66.70, 1011.39, -0.40, 0.0, 27.51, 32.91, 35.8, 229, 11.6, 27.03500, 27.17610, 5.5878, 27.1761, , 151.50, 4.4827, 1458.60, 291.10, 278.9, 13.38, 16.5, 52
%3/20/2008, 00:00:58,-999,-999,5.57,5.8,999.9,40.997223,-73.331693,,256.8,6.74,255.5,1000.71,0.6,0,22.82,92.39,95.2,170,1.7,27.1937,26.2969,6.9265,26.2969, ,270.8,4.0286,1455.56,68.2,72.3,4.65,5.1,52
%3/20/2008, 00:01:58,-999,-999,5.49,5.8,999.9,40.99679,-73.334095,,256.6,6.74,255.1,1000.64,0.6,0.7,22.83,92.27,95.3,193,1.8,27.1744,26.2811,6.9203,26.2811, ,272.9,4.0336,1455.56,72.8,79.7,4.75,5.3,52
    
    dmp=fgetl(fid);		    %read 2 header lines
    dmp=fgetl(fid);		    %read 2 header lines

    % for p = 1:4  % short test read
    while feof(fid)==0,
        ict = ict + 1;
        clear st1 stz;
            %st1=fscanf(fid,'%g,%g,%g,%g,%g',[5,inf]);
            dtmp = fgetl(fid);
            data1 = dtmp(26:length(dtmp));
            %DEW 3/23/2008 Early SCS files don't have depth in them 30 cols
            % Files 0319-0321
            C = textscan(data1,'%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f','Delimiter',',','CollectOutput',1);
            tmp = C{:};
            scs(ict,:) = tmp(1,:);
            if 1 
                %2008/03/22, 00:00:31
            tim = dtmp(1:20);
            YY = str2num(tim(:,6:9));
            MM = str2num(tim(:,1));
            DD = str2num(tim(:,3:4));
            hh = str2num(tim(:,12:13));
            mm = str2num(tim(:,15:16));
            ss = str2num(tim(:,18:19));;
            %calculate year day
            yd(ict,1) = datenum(YY,MM,DD,hh,mm,ss)-datenum(YY-1,12,31);
            year = num2str(YY);
            end
%                          1                           2                          3                          4                         5
    end;                        %end while feof

if 1
    Ti = scs(:,2); %IMET_HRH AIR_TEMP
    Tv = scs(:,3); %WXT5_Ta Vaisala Weather Transmitter
    Pv = scs(:,4); %WXT5_Pa
    Lat = scs(:,5);
    Lon = scs(:,6);
    cog = scs(:,8);
    sog = scs(:,9);
    head = scs (:,10);
    Pi = scs(:,11);  % IMET
    sw = scs(:,12);  % Eppley
    Rvi = scs(:,13); %WXT rain intensity
    Rvc = scs(:,14); %WXT rain accumulation 
    RHi = scs(:,15); %IMET
    RHv = scs(:,16); % WXT RH
    WDv = scs(:,17); %WXT Dir Relative
    WSv = scs(:,18); %WXT Spd Relative
    SBsst = scs(:,21); % SeaBid SST
    TSGsst = scs(:,25); % TSG SST
    WDrmy = scs(:,27); % IMET RMY Dir True
    WDvT = scs(:,28);  %WXT Dir True
    WSrmy = scs(:,29); % IMET RMY SPD True
    WSvT = scs(:,30); %WXT Spd True
end

if 1  
    jad = yd;
    s = way_images_flux;

    figure(1);
    subplot(2,1,1),plot(jad,Ti,'r');
    title('Knorr SCS');
    hold
    subplot(2,1,1),plot(jad,Tv,'k'); 
    xlabel('Year Day (UTC)');
    %subplot(2,1,1),plot(jad,sst,'b');title('Knorr SCS');
    legend('IMET','WXT','Location','Best')
    ylabel('C');
    ylim([-5 15])
    
    subplot(2,1,2),plot(jad,RHi,'r');
    title('Knorr SCS');
    hold
    subplot(2,1,2),plot(jad,RHv,'k');
    xlabel('Year Day (UTC)');
    ylabel('%');
    ylim([0 100])
    legend('IMET','WXT','Location','Best')
    if prtit
    print_buffer = [s 'ICEALOT_scs_trh_' md '.png'];
    print('-dpng ', print_buffer);
    end
    
    figure(2);
    subplot(2,1,1),plot(jad,WSv,'r');
    title('Knorr SCS Rel winds');
    hold
    subplot(2,1,1),plot(jad,sog,'k');title('Knorr SCS');    
    ylabel('m/s');
    ylim([0 40])
        legend('WXT rel','SOG','Location','Best')
    
    subplot(2,1,2),plot(jad,WDv,'r.');xlabel(['Year Day ', year]);
    hold
    subplot(2,1,2),plot(jad,cog,'k');
    subplot(2,1,2),plot(jad,head,'b');
    ylabel('Deg');
    ylim([0 360])
    legend('WXT rel','COG','Heading','Location','Best')
    if prtit
    print_buffer = [s 'ICEALOT_scs_SD_' md '.png'];
    print('-dpng ', print_buffer);
    end
    
figure(3);
    subplot(2,1,1),plot(jad,WSrmy,'r.');
    hold
    subplot(2,1,1),plot(jad,WSvT,'k');title('Knorr SCS True winds');    
    ylabel('Spd (m/s)');
    legend('IMET','XMT','Location','Best')
    ylim([0 30])
    
    subplot(2,1,2),plot(jad,WDrmy,'k.');
    xlabel('Year Day (UTC)');
    hold
    subplot(2,1,2),plot(jad,WDvT,'r');title('Knorr SCS');
    ylabel('Dir (Deg)');
    legend('IMET','WXT','Location','Best')
    ylim([0 360])
    if prtit
    print_buffer = [s 'ICEALOT_scs_SDT_' md '.png'];
    print('-dpng ', print_buffer);
    end
    
    figure(4)
    plot(jad,Pi,'k');title('Knorr SCS');
    hold
    plot(jad,Pv,'r');xlabel(['Year Day ', year])
    ylabel('Pressure (mb)');
    ylim([980 1030])
    legend('IMET','WXT')
    if prtit
    print_buffer = [s 'ICEALOT_scs_P_' md '.png'];
    print('-dpng ', print_buffer);
    end
    
        figure(5)
    subplot(2,1,1),plot(jad,Rvi,'k');
    title('Knorr SCS WXT rain');
    ylabel('Rain intensity');
    subplot(2,1,2),plot(jad,Rvc);
    ylabel('Rain accumulation');
    if prtit
    print_buffer = [s 'ICEALOT_WXT_rain_' md '.png'];
    print('-dpng ', print_buffer);
    end
    
    figure(6);
    plot(jad,SBsst,'k');
    hold
    plot(jad,TSGsst,'b');    
    title('Knorr SCS');
    xlabel('Year Day (UTC)');
    ylabel('SST (C)');
    ylim([-5 15])
    legend('SCS Sea Bird','SCS TSG','Location','Best')
    if prtit
    print_buffer = [s 'ICEALOT_SCS_SST_' md '.png'];
    print('-dpng ', print_buffer);
    end
end %skip any plots

%Save temperature profile to a file for calculating pwv
% after save date/time info in same array
[r,c] = size(scs);
scs(:,c+1) = jad;

        if prtit
            f=[ way_raw_data_flux 'ICEALOT_scs_' md '.txt'];
            flist=fopen(f,'w');
            save( f, 'scs', '-ascii','-tabs')
            fclose('all');
        end;
