% WHOTS 2014 :: 2014-07 :: BWB
% reads daily SAMOS ship data system files.
% files e-mailed daily from ship SCS/SAMOS system
disp(['read_scs_day: ', cruise]);

jd=sprintf('%03i',ddd);
                                                 %10-min index
jax=1;                              %line counter
%declare arrays
nr2=43;scsdata=ones(nr2,360*24)*NaN;


for jam=00:23,                                         %cycle thru 24 hourly stats files
    hr=sprintf('%02i',jam);
    e=[way_raw_data_flux, yyyy(3:4),jd,'\scs0', yyyy(3:4) jd hr '_raw.txt'];
    disp(['Reading scs file from doy ',jd,'  hour ',hr]);
    flist=fopen(e,'r');
    temp=[];stx=[];
    if flist>0,                                 %if the file exists,
        while ~feof(flist)
            try
                    %             Date	 Time_GMT	 Dec_Lat	 Dec_Lon	 SPD	 HDT	 COG	 SOG	 WXTP_Ta	 WXTS_Ta	 WXTP_Pa	 WXTS_Pa	 WXTP_Ri	 WXTS_Ri	 WXTP_Rc	 WXTS_Rc	 WXTP_Dm	 WXTS_Dm	 WXTP_Sm	 WXTS_Sm	 WXTP_Ua	 WXTS_Ua	 WXTP_TS	 WXTS_TS	 WXTP_TD	 WXTS_TD	 SWR	 LWR	 SBE45S	 SBE48T	 FLR	 SSV	 Depth12	 Depth35	 HdChkSum=00 
    %             8/11/2013	0:00:01	41.52395	-70.672264	-0.01	24.6	138.8	0.02	22.6	22.5	1014.4	1014.4	0	0	18.86	6.03	226	231	5.5	4.3	77.1	78.2	5.21	3.91	259.61	268.6	12.092	358.9	0.2427	22.979	164.6	1493.09	nan	nan	
                temp=textscan(flist,'%2f%2f%3f %*6c %4f/%2f/%2f %2f:%2f:%2f %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 %f %f %f %*[^\n]','delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN);
                stx=[stx cell2mat(temp)'];
            catch
                nr2=length(temp);
                [lnr2,cnr2]=size(temp{1,nr2});
                for ll=1:nr2
                     if length(temp{1,ll})~=lnr2
                         temp{1,ll}(lnr2+1)=[];
                     end;
                end;
                if isempty(temp{1,1}); continue; end
                if isempty(temp{1,1});
                    disp('Should never do this!')
                    temp{1,7}=temp{1,7}';
                end;
             stx=[stx cell2mat(temp)'];
            end;
        end;  %end while
        stx(end+1,:)=stx(1,:)*0+jam;
        [nr1,nl1]=size(stx);
        scsdata(:,jax:jax+nl1-1)=stx;
        jax=jax+nl1;
    else
        nr2=43;
        stx=ones(nr2,360)*NaN;
        [nr1,nl1]=size(stx);
        scsdata(:,jax:jax+nl1-1)=stx;
        jax=jax+nl1;
    end;      %     end if list
end;         %0-23 hour loop


jd_scs=datenum(scsdata(4,:),scsdata(5,:),scsdata(6,:),scsdata(end,:),scsdata(1,:),scsdata(2,:)+scsdata(3,:)/1000)-datenum(Vdate(1),1,0);   %Day-Of-Year
Dec_Lat=scsdata(10,:); %Latitude	deg	C-Nav GPS receiver
Dec_Lon=scsdata(11,:); %Longitude	deg	C-Nav GPS receiver
SPD=scsdata(12,:); 
HDT=scsdata(13,:);  %heading
COG=scsdata(14,:); %Course Over Ground	deg	C-Nav GPS receiver
SOG=scsdata(15,:); %Speed Over Ground	knots	C-Nav GPS receiver
WXTP_Ta=scsdata(16,:); %Air Temp	C	Port VaisalaWXT520
WXTS_Ta=scsdata(17,:); %Air Temp	C	Starboard VaisalaWXT520
WXTP_Pa=scsdata(18,:); %Pressure	hPa	Port VaisalaWXT520, uncorrected for height
WXTS_Pa=scsdata(19,:); %Pressure	hPa	Starboard VaisalaWXT520, uncorrected for height
WXTP_Ri=scsdata(20,:); %Rainfall Intensity	mm/h	Port VaisalaWXT520
WXTS_Ri=scsdata(21,:); %Rainfall Intensity	mm/h	Starboard VaisalaWXT520
WXTP_Rc=scsdata(22,:); %Cumulative Rainfall	mm	Port VaisalaWXT520
WXTS_Rc=scsdata(23,:); %Cumulative Rainfall	mm	Starboard VaisalaWXT520
WXTP_Dm=scsdata(24,:); %Relative Wind Direction	deg	Port VaisalaWXT520
WXTS_Dm=scsdata(25,:); %Relative Wind Direction	deg	Starboard VaisalaWXT520
WXTP_Sm=scsdata(26,:); %Relative Wind Speed	m/s	Port VaisalaWXT520
WXTS_Sm=scsdata(27,:); %Relative Wind Speed	m/s	Starboard VaisalaWXT520
WXTP_Ua=scsdata(28,:); %Relative Humidity	%	Port VaisalaWXT520
WXTS_Ua=scsdata(29,:); %Relative Humidity	%	Starboard VaisalaWXT520
WXTP_TS=scsdata(30,:); %True Wind Speed	m/s	Port VaisalaWXT520, corrected for ship's gyro, SOG, and COG
WXTS_TS=scsdata(31,:); %True Wind Speed	m/s	Starboard VaisalaWXT520, corrected for ship's gyro, SOG, and COG
WXTP_TD=scsdata(32,:); %True Wind Direction	deg	port VaisalaWXT520, corrected for ship's gyro, SOG, and COG
WXTS_TD=scsdata(33,:); %True Wind Direction	deg	Starboard VaisalaWXT520, corrected for ship's gyro, SOG, and COG
SWR=scsdata(34,:); %Short Wave Radiation	W/m2	IMET (Eppley Laboratories, Inc. pyronometer)
LWR=scsdata(35,:); %Long Wave Radiation	W/m2	IMET (Eppley Laboratories, Inc. pyronometer)
SBE45S=scsdata(37,:);
SBE48T=scsdata(38,:); %%Sea Surface Temperature	C	SeaBird SBE48
FLR=scsdata(39,:); %Fluorescence	mV	WetLabs Wet-StarWS3S-901P
SSV=scsdata(40,:); %Surface Sound Velocity	m/s	Calculated from SSTMP and SSCND
Depth12=scsdata(41,:);
Depth35=scsdata(42,:);
% HdChkSum=00 



  
if plotit && ~isempty(jd_scs)

    figure;subplot(2,1,1)
    plot(jd_scs,WXTP_Sm,jd_scs,WXTS_Sm,jd_scs,WXTP_TS,jd_scs,WXTS_TS);
    xlabel('Hour (UTC)');ylabel('Wind speed (m/s)');xlim([ddd ddd+1])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Wind speed',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    legend('Relative Port','Relative Stbd','True Port','True Stbd','Location','Best'); 
    subplot(2,1,2)
    plot(jd_scs,WXTP_Dm,jd_scs,WXTS_Dm,jd_scs,WXTP_TD,jd_scs,WXTS_TD);
    xlabel('Hour (UTC)');ylabel('Wind direction (deg)');axis([ddd ddd+1 0 360])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Wind direction',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    legend('Relative Port','Relative Stbd','True Port','True Stbd','Location','Best'); 
    grid
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_Wind_Speed_Dir_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

    figure;
    plot(jd_scs,SBE48T,jd_scs,WXTP_Ta,jd_scs,WXTS_Ta);
    xlabel('Hour (UTC)');ylabel('Temperatures (degC)');axis([ddd ddd+1 -10 25])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS temperatures',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    legend('Sea (tsg)','Air Port','Air Stbd','Location','Best')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_Temperatures_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

%     figure;
%     plot(gpstim./24+ddd,tss);
%     xlabel('Hour (UTC)');ylabel('Salinity (psu)');xlim([ddd ddd+1])
%     title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS salinity',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
%     set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
%     xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
%     grid
%     ylim([33.5 36]); % DEW set for DYNAMO 19 Oct 2011
%     annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
%     if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_Salinity_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

    figure;
    plot(jd_scs,WXTP_Ua,jd_scs,WXTS_Ua);
    xlabel('Hour (UTC)');ylabel('RH (%)');axis([ddd ddd+1 50 101])
    legend('Port','Stbd','Location','Best')
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Relative Humidity',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_RH_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

    figure;
    subplot(2,1,1);plot(jd_scs,SWR);
    ylabel('Solar flux (W/m^2)');axis([ddd ddd+1 -5 1200]);
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS solar flux',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    
    subplot(2,1,2);plot(jd_scs,LWR);
    xlabel('Hour (UTC)');ylabel('IR flux (W/m^2)');axis([ddd ddd+1 300 500]);
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS IR flux',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_Solarflux_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

    figure;
    plot(jd_scs,WXTP_Pa,jd_scs,WXTS_Pa);
    legend('Port','Stbd','Location','Best')
    xlabel('Hour (UTC)');ylabel('Pressure (mb)');xlim([ddd ddd+1])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS pressure',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    %legend('Sea (tsg)','Air','Location','Best')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_Pressure_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;


% %     figure;
% %     plot(gpstim./24+ddd,bp);
% %     xlabel('Hour (UTC)');ylabel('Pressure (mb)');
% %     axis([ddd ddd+1 median(bp(~isnan(bp)))-10  median(bp(~isnan(bp)))+10]);
% %     title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS barometric pressure',cruise,Vdate(1),Vdate(2),Vdate(3),+ddd),'FontWeight','Bold','Interpreter','none')
% %     set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
% %     xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
% %     grid
% %     annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
% %     if prtit; print(graphdevice,[way_images_flux  cruise '_SCS_pressure_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end;

%     figure;
%         eval(['map_', currentMname,'(lond,latd,cruise,ship,[Lonmin Lonmax Latmin Latmax])'])
%         annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
%     if prtit
% %         print('-depsc2','-tiff',[way_raw_images_flux 'track' cruise yyyy '_' jd '.eps']);
%         print(graphdevice,[way_images_flux cruise '_SCS_shiptrack_map_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]);
%     end
%     figure;
%     plot(lonm,latm,'.'); title(['DOY',jd,' UTC  Longitude/Latitude from SCS GPS. ', cruise],'Interpreter','none');xlabel('Longitude (deg)');ylabel('Latitude (deg)');
%     annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
%     if prtit; print(graphdevice,[way_images_flux cruise '_SCS_lat_lon_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end

end

%interp to 1min
if length(jd_pc(isnan(jd_pc)))==1440;   %means no data files detected during the 24H period
    jd_pc=ddd+(0:1439)/60/24;       %creates a fake decimal DOY base so that timatch programs work properly
end;
ii=find(~isnan(jd_scs));
Dec_Lat=interp1(jd_scs(ii),Dec_Lat(ii),jd_pc);         %Latitude	deg	C-Nav GPS receiver
Dec_Lon=interp1(jd_scs(ii),Dec_Lon(ii),jd_pc);         %Longitude	deg	C-Nav GPS receiver
SBE48T=interp1(jd_scs(ii),SBE48T(ii),jd_pc);           %Sea Surface Temperature	C	SeaBird SBE48 hull-mounted, 5m below waterline?
SWR=interp1(jd_scs(ii),SWR(ii),jd_pc);            %Short Wave Radiation	W/m2	IMET (Eppley Laboratories, Inc. pyronometer)
LWR=interp1(jd_scs(ii),LWR(ii),jd_pc);            %Long Wave Radiation	W/m2	IMET (Eppley Laboratories, Inc. pyronometer)
WXTP_Ta=interp1(jd_scs(ii),WXTP_Ta(ii),jd_pc) ;       %Air Temp	C	Port VaisalaWXT520
WXTS_Ta=interp1(jd_scs(ii),WXTS_Ta(ii),jd_pc);        %Air Temp	C	Starboard VaisalaWXT520
WXTS_Pa=interp1(jd_scs(ii),WXTS_Pa(ii),jd_pc);        %Pressure	hPa	Starboard VaisalaWXT520, uncorrected for height
WXTP_Pa=interp1(jd_scs(ii),WXTP_Pa(ii),jd_pc);        %Pressure	hPa	Port VaisalaWXT520, uncorrected for height
WXTP_Rc=interp1(jd_scs(ii),WXTP_Rc(ii),jd_pc);        %Cumulative Rainfall	mm	Port VaisalaWXT520
WXTS_Rc=interp1(jd_scs(ii),WXTS_Rc(ii),jd_pc);        %Cumulative Rainfall	mm	Starboard VaisalaWXT520
WXTS_Ri=interp1(jd_scs(ii),WXTS_Ri(ii),jd_pc);        %Rainfall Intensity	mm/h	Starboard VaisalaWXT520
WXTP_Ri=interp1(jd_scs(ii),WXTP_Ri(ii),jd_pc);        %Rainfall Intensity	mm/h	Port VaisalaWXT520
WXTS_Ua=interp1(jd_scs(ii),WXTS_Ua(ii),jd_pc);        %Relative Humidity	%	Port VaisalaWXT520
WXTP_Ua=interp1(jd_scs(ii),WXTP_Ua(ii),jd_pc);        %Relative Humidity	%	Starboard VaisalaWXT520
FLR=interp1(jd_scs(ii),FLR(ii),jd_pc);    %Fluorescence	mV	WetLabs Wet-StarWS3S-901P

rdcon=pi/180;
    spdx=SOG'.*cos(COG'*rdcon);    %convert to N
    spdy=SOG'.*sin(COG'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
SOG=(sqrt(spdxi.*spdxi+spdyi.*spdyi));                         %1-min sog
COG=(mod(atan2(spdyi,spdxi)/rdcon+360,360));
    spdx=WXTS_Sm'.*cos(WXTS_Dm'*rdcon);    %convert to N
    spdy=WXTS_Sm'.*sin(WXTS_Dm'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
WXTS_Sm=(sqrt(spdxi.*spdxi+spdyi.*spdyi));                         %1-min sog
WXTS_Dm=(mod(atan2(spdyi,spdxi)/rdcon+360,360));
    spdx=WXTP_Sm'.*cos(WXTP_Dm'*rdcon);    %convert to N
    spdy=WXTP_Sm'.*sin(WXTP_Dm'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
WXTP_Sm=(sqrt(spdxi.*spdxi+spdyi.*spdyi));                         %1-min sog
WXTP_Dm=(mod(atan2(spdyi,spdxi)/rdcon+360,360));
    spdx=WXTS_TS'.*cos(WXTS_TD'*rdcon);    %convert to N
    spdy=WXTS_TS'.*sin(WXTS_TD'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
WXTS_TS=(sqrt(spdxi.*spdxi+spdyi.*spdyi));                         %1-min sog
WXTS_TD=(mod(atan2(spdyi,spdxi)/rdcon+360,360));
    spdx=WXTP_TS'.*cos(WXTP_TD'*rdcon);    %convert to N
    spdy=WXTP_TS'.*sin(WXTP_TD'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
WXTP_TS=(sqrt(spdxi.*spdxi+spdyi.*spdyi));                         %1-min sog
WXTP_TD=(mod(atan2(spdyi,spdxi)/rdcon+360,360));
    spdx=cos(HDT'*rdcon);    %convert to N
    spdy=sin(HDT'*rdcon);    %convert to E
    spdxi=(interp1(jd_scs(ii),spdx(ii),jd_pc)); 
    spdyi=(interp1(jd_scs(ii),spdy(ii),jd_pc)); 
HDT=(mod(atan2(spdyi,spdxi)/rdcon+360,360));


rhm=WXTP_Ua;
tsgm=SBE48T;
tam=WXTP_Ta;
irm=LWR;
solarm=SWR;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%save dat in one ascii file
if saveit;
    np=length(jd_pc);
    eval(['prt_jas_scs_' currentMname]);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if clearit
    clear scsdata
end;


