disp('opengps.m')
% Inputs data from ASCII data files
%  Note:  hhh=hour

fclose('all'); 
if hhh<10,
   dfx2=['0',num2str(hhh)];
else,
   dfx2=num2str(hhh);
end;

if ddd<10,
   dfx1=['00',num2str(ddd)];
elseif ddd<100,
   dfx1=['0',num2str(ddd)];
else,
   dfx1=num2str(ddd);
end;

dfx=[dfx1 dfx2];
dfl=['d:\hp_data\day',num2str(ddd),'\P7_',dfx];disp(dfl)

norman=1;
flist=fopen(dfl,'r');
headr=fgetl(flist);disp(headr)
gpshour=[];gpsmin=[];gpssec=[];gpslat=[];gpslon=[];
gpslat_sign=[];gpslon_sign=[];gpsspeed=[];gpshead=[];
while norman==1,
   headr=fgetl(flist);
   if headr==-1,norman=0;break;end;
   for qq=1:length(headr)-5,
      if headr(qq:qq+5)=='$GPRMC' & length(headr) > qq+54,
         gpstime=headr(qq+7:qq+13);
         gpshour=[gpshour str2num(gpstime(1:2))];
         gpsmin=[gpsmin str2num(gpstime(3:4))];
         gpssec=[gpssec str2num(gpstime(5:6))];
         glt=str2num(headr(qq+16:qq+24));
         bb=floor(glt/100);
         glt=(glt-bb*100)/60;
         glt=glt+bb;
         gpslat_sign=headr(qq+26);
         if gpslat_sign=='N',
         else glt=-glt;
         end;
         gpslat=[gpslat glt];
         gln=str2num(headr(qq+28:qq+37));
         bb=floor(gln/100);
         gln=(gln-bb*100)/60;
         gln=gln+bb;
         gpslon_sign=headr(qq+39);
         if gpslon_sign=='E',
         else gln=-gln;
         end;
         gpslon=[gpslon gln];
         gpsspeed=[gpsspeed str2num(headr(qq+41:qq+45))];
         gpshead=[gpshead str2num(headr(qq+47:qq+51))];
      end;
   end;
end;
disp(['Start GPShour = ',num2str(gpshour(1)),'   GPSmin = ',num2str(gpsmin(1)),'   GPSsec = ',num2str(gpssec(1))]),
disp(['Start Latitude  =  ',num2str(gpslat(1)),'     Longitude = ',num2str(gpslon(1))]),
disp(['  End GPShour = ',num2str(gpshour(length(gpshour))),'   GPSmin = ',num2str(gpsmin(length(gpsmin))),'   GPSsec = ',num2str(gpssec(length(gpssec)))]),
disp(['  End Latitude  =  ',num2str(gpslat(length(gpslat))),'     Longitude = ',num2str(gpslon(length(gpslon)))]),

%figure;plot(gpslon,gpslat);title(['JD',dfx1,' Hr',dfx2,' UTC  Longitude/Latitude']);xlabel('longitude in deg');ylabel('latitude in deg');  
%clear ans bb qq norman headr gpstime gpslon_sign gpslat_sign glt gln flist dfx2 dfx1 dfx dfl

clear qq norman headr  glt gln flist dfx1 dfx2 dfl bb ans 

%start_lon=gpslon(1);
%end_lon=gpslon(length(gpslon));

%start_lat=gpslat(1);
%end_lat=gpslat(length(gpslat));

clear gpshour gpsmin gpssec gpstime gpslon_sign gpslat_sign dfx
