%
% program to interpolate Loran Buoy position file into final format
% using a couple of Ari's functions: "date" and "dec2hrm"
%
% Uses the "fprintf" command inside a For-Loop to generate
% formatted data
%
% Uses Matlab's spline function and Ari's "dec1min" vector
%
% Outputs the x & y geographic displacement vectors as well
% by using the "distxy.m" function
%
load dg5b2.pos;
yd=dg5b2(:,4);
lat = dg5b2(:,1);
lon = dg5b2(:,3);
%
% interpolate to 1-min
%
load dec1min.dat;
yd1m=pickout(dec1min,1,.9660,.9999,[1]);
yd1m=147+yd1m;
yd1m2=pickout(dec1min,1,.0000,.1243,[1]);
yd1m2=148+yd1m2;
yd1m=[yd1m',yd1m2'];
yd1m=yd1m';
slat=spline(yd,lat,yd1m);
slon=spline(yd,lon,yd1m);
%
% calculate the geographic displacements
%
[x,y]=distxy(slat,slon);
x=x';
y=y';
%
date=day2date(yd1m);
[hh,mm]=dec2hrm(yd1m);
hhmm=(hh*100)+mm;
gmt=hhmm+400;
if gmt >= 2400
 gmt=gmt-2400;
end;
%
fid = fopen('dg5b2.xyg','w');
for i=1:length(yd1m);
fprintf(fid,'%7.4f %8.0f %5.0f %5.0f %8.4f %9.4f %9.4f %9.4f\n',...
 yd1m(i,:),date(i,:),hhmm(i,:),gmt(i,:),slat(i,:),slon(i,:),x(i,:),y(i,:));
end
fclose(fid)
