disp('nau_ship')
fclose('all');
%g=0.0098;							%adiabatic lapse rate
%eps_w=0.97;							%emissivity of water
%sig_sb=5.67e-8;					%Stefan Boltzmann constant

if hhh<10,
   e=['D:\hp_data\day',num2str(ddd),'\P6_',num2str(ddd),'0',num2str(hhh)];
else
   e=['D:\hp_data\day',num2str(ddd),'\P6_',num2str(ddd),num2str(hhh)];
end;
jax=1;
flist=fopen(e,'r');
clear e
if flist>0,   					%if the file exists, 
   dmp=fgets(flist);			%read header lines and skip blanks
   dmp2=fgets(flist);		%read header lines and skip blanks
   while feof(flist)==0,	
      st1=fscanf(flist,'%g,%g,%g,%g%*c,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,',[17,inf]);
      [nr1,nl1]=size(st1);
	   if nr1==17
         st2(:,jax:jax+nl1-1)=st1;
      	jax=jax+nl1;
		else
   		x=fgets(flist);clear x
		end;
   end;
end;

clear st1 nl1 nr1 flist dmp2 dmp

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);clear sog
st2(16,:)=imu.*cos(imd*rdcon);
st2(17,:)=imu.*sin(imd*rdcon);
lrgc=cos(lrg*rdcon);
lrgs=sin(lrg*rdcon);
jade=str2num(num2str(ddd))+((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;

clear lrgs lrgc lrg jl jk jj jade jax j imu imd cog

sogx=st3(6,:);
sogy=st3(7,:);
imux=st3(16,:);
imuy=st3(17,:);

sogm=sqrt(sogx.*sogx+sogy.*sogy)*.514;				%sog
cogm=mod(atan2(sogy,sogx)/rdcon+360,360);       %cog
imum=sqrt(imux.*imux+imuy.*imuy)*.514;				%imet speed, m/s
imdm=mod(atan2(imuy,imux)/rdcon+360,360);       %imet direction
lrgm=mod(atan2(lrgsm,lrgcm)/rdcon+360,360);		%laser ring gyro

clear imux imuy sogx sogy lrgsm lrgcm rdcon

gpstim=st3(3,:);
lat=st3(4,:);
lon=st3(5,:);
%
tsg=st3(8,:);					%salinity
tss=st3(9,:);					%Tsea thermosalinograph
imrh=st3(10,:);				%imet RH
imta=st3(11,:);				%imet Tair
imsol=st3(12,:);				%imet solar
imrain=st3(13,:);				%imet rain
odec=st3(15,:);				%speed log

jad=str2num(num2str(ddd))+((st3(1,:)-st2(1,1))/60/60)/24;
clear st2 st3

if length(jad)<60,
   jad=[jad jad(length(jad))+0.00001];
   sogm=[sogm sogm(length(sogm))]
   cogm=[cogm cogm(length(cogm))]
   imum=[imum imum(length(imum))]
   imdm=[imdm imdm(length(imdm))]
   lrgm=[lrgm lrgm(length(lrgm))]
   gpstim=[gpstim gpstim(length(gpstim))]
   lat=[lat lat(length(lat))]
   lon=[lon lon(length(lon))]
   tsg=[tsg tsg(length(tsg))]
   tss=[tss tss(length(tss))]
   imrh=[imrh imrh(length(imrh))]
   imta=[imta imta(length(imta))]
   imsol=[imsol imsol(length(imsol))]
   imrain=[imrain imrain(length(imrain))]
   odec=[odec odec(length(odec))];
end;

figure;plot(jad,imta,jad,tsg);xlabel('Jday (1999)');ylabel('Temperature (C)');Title('SCS Tair=blu; Tsea=grn');
figure;plot(jad,sogm,jad,odec);xlabel('Jday (1999)');ylabel('SCS Ship Speed (m/s)');Title('GPS=blu; odec=grn'); 
figure;plot(jad,imsol);xlabel('Jday (1999)');ylabel('Psp_imet (W/m^2)');Title('SCS Downward Solar Flux: Imet'); 
figure;plot(jad,imrain);xlabel('Jday (1999)');ylabel('Precipitation  (mm)');Title('SCS Imet Rain Gauge');
figure;plot(jad,cogm,jad,lrgm);xlabel('Jday (1999)');ylabel('SCS Ship Direction (deg)');Title('GPS Cog=blue; Laser Ring Gyro=green');

fclose('all');