disp('read_shp_day')
fclose('all');
clear all;
jd=input('julian day, ddd','s');
plotit=input('plot plots? 0=n, 1=y');
%plotit=0;
prtit=input('append master data file? 0=n, 1=y');
%prtit=1;
%yd=date;
%jif=datevec(yd);
%xx=[jif(1) jif(2) jif(3) 0 0 0];
%jd=num2str(julday(xx)-1);
hr='00';%input('gmt hr','s');
g=0.0098;%adiabatic lapse rate
eps_w=0.97;%emissivity of water
sig_sb=5.67e-8;%Stefan Boltzmann constant
blk=1;%10-min index 
jax=1;
jaxx=1;
backchk=0;
st1=zeros(17,1800);
st2=zeros(17,4500);
for jam=0:2,%cycle thru 24 hourly stats files
   if jam<10,
      hr=['0'num2str(jam)];
   else
      hr=num2str(jam);
   end;
   e=['D:\hp_data\P6_' jd hr];
	flist=fopen(e,'r');
   if flist>0,   %if the file exists, 
      if backchk==0,
         tzilch=jam;
         backchk=1;
      end;%end if
      
      dmp=fgets(flist);%read header lines and skip blanks
      dmp2=fgets(flist);%read header lines and skip blanks
		
      while feof(flist)==0,%go until you run out of 10-min sections
         st1=fscanf(flist,'%g,%g,%g,%g%*c,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,',[17,inf]);
                  %         1  2  3  4     5     6  7  8  9  0  1  2  3  4  5  6  7     
         [nr1,nl1]=size(st1);      
			if nr1==17
      		st2(:,jax:jax+nl1-1)=st1; 
      		jax=jax+nl1;
			else
   			x=fgets(flist)
			end;%end if             
       end;%end while
    end;%end flist
 jam   
end;%end jam
cog=st2(6,:);
sog=st2(7,:);
lrg=st2(14,:);
imu=st2(16,:);
imd=st2(17,:);
jk=ceil(jax/30);
st3=zeros(17,jk);
rdcon=pi/180;
st2(6,:)=sog.*cos(cog*rdcon);
st2(7,:)=sog.*sin(cog*rdcon);
st2(16,:)=imu.*cos(imd*rdcon);
st2(17,:)=imu.*sin(imd*rdcon);
lrgc=cos(lrg*rdcon);
lrgs=sin(lrg*rdcon);
jade=str2num(num2str(jd))+(tzilch+(st2(1,:)-st2(1,1))/60/60)/24;

for j=1:jk
   jl=30*(j-1)+1;jj=min(jax-1,30*j);
   st3(:,j)=median(st2(:,jl:jj)')';
   jad(j)=jade(jl);
   lrgcm(j)=median(lrgc(jl:jj));
   lrgsm(j)=median(lrgs(jl:jj));
end;

sogx=st3(6,:);
sogy=st3(7,:);
imux=st3(16,:);
imuy=st3(17,:);
sogm=sqrt(sogx.*sogx+sogy.*sogy)*.514;%1-min sog
cogm=mod(atan2(sogy,sogx)/rdcon+360,360);
imum=sqrt(imux.*imux+imuy.*imuy)*.514;%1-min imet speed, m/s
imdm=mod(atan2(imuy,imux)/rdcon+360,360);
lrgm=mod(atan2(lrgsm,lrgcm)/rdcon+360,360);%laser ring gyro

gpstim=st3(3,:);
lat=st3(4,:);
lon=st3(5,:);
%
tsg=st3(8,:);
tss=st3(9,:);
imrh=st3(10,:);
imta=st3(11,:);
imsol=st3(12,:);
imrain=st3(13,:);
%
odec=st3(15,:);
jad=str2num(num2str(jd))+(tzilch+(st3(1,:)-st2(1,1))/60/60)/24;
np=jk;


if prtit==1;
  prt_jas_scs;
end;

if plotit==1;
%  set some plot limits
Tll=-25;
hll=70;
uul=10;
vul=10;
Tul=-0;
hul=100;
sul=12;
Rlul=30;
Rlll=-100;
Rtul=300;
Rtll=125;
Rsul=1000;
Rsll=0;

%plot T profiles
j_st=jad(1);
j_en=jad(np);
figure;
plot(jad(1:np),imta(1:np),jad(1:np),tsg(1:np));
xlabel('Jday (1999)');
ylabel('Temperature (C)');
%axis([j_st j_en Rtll Rtul]);
Title('SCS Tair=blu; Tsea=grn'); 
figure;
plot(jad(1:np),sogm(1:np),jad(1:np),odec(1:np));
xlabel('Jday (1999)');
ylabel('SCS Ship Speed (m/s)');
%axis([j_st j_en Rtll Rtul]);
Title('GPS=blu; odec=grn'); 
figure;
plot(jad(1:np),imsol(1:np));
xlabel('Jday (1999)');
ylabel('Psp_imet (W/m^2)');
%axis([j_st j_en Rsll Rsul]);
Title('SCS Downward Solar Flux: Imet'); axis([j_st j_en Rsll Rsul]);

figure;
plot(jad(1:np),imrain(1:np));
xlabel('Jday (1999)');
ylabel('Precipitation  (mm)');
%axis([j_st j_en 0 50]);
Title('SCS Imet Rain Gauge');
figure;
plot(jad(1:np),cogm(1:np),jad(1:np),lrgm(1:np));
xlabel('Jday (1999)');
ylabel('SCS Ship Direction (deg)');
axis([j_st j_en 0 360]);
Title('GPS Cog=blue; Laser Ring Gyro=green');

end; 
