%
% program to reformat 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
%
% Outputs the x & y geographic displacement vectors as well
% by using the "distxy.m" function
%
load alball.dat;
alball=pickout(alball,1,147.9660,148.1243,[1,2,3]);
yd=alball(:,1);
date=day2date(yd);
[hh,mm]=dec2hrm(yd);
hhmm=(hh*100)+mm;
gmt=hhmm+400;
if gmt >= 2400
 gmt=gmt-2400;
end;
lat = alball(:,2);
lon = alball(:,3);
%
% calculate the geographic displacements
%
[x,y]=distxy(lat,lon);
x=x';
y=y';
%
fid = fopen('ag5b2.xyg','w');
for i=1:length(yd);
fprintf(fid,'%7.4f %8.0f %5.0f %5.0f %8.4f %9.4f %6.2f %6.2f\n',...
 yd(i,:),date(i,:),hhmm(i,:),gmt(i,:),lat(i,:),lon(i,:),x(i,:),y(i,:));
end
fclose(fid)
