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

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=['/home/user1/bin/data/P3_',dfx];%disp(dfl)
dfl=[drive,'\DAY',dfx1,'\P3_',dfx];%disp(dfl)
%disp('Open Gyrocompass File')
flist=fopen(dfl,'r');
headr=fgetl(flist);%disp(headr)
headr=fgetl(flist);
z=fscanf(flist,'%g,%g,%g',[3,inf]);
z=z(:,1:length(z)-1);
t1=z(1,:)-z(1,1);t2=z(2,:)/10000-z(2,1)/10000;
tgyro=t1+t2;clear t1 t2;
heading=z(3,:);

heading=medfilt1(heading);
heading=heading-5.3;                     %correction

%figure;plot(tgyro,heading);title(['JD',dfx1,' Hr',dfx2,' UTC  Gyrocompass Heading']);ylabel('heading in degrees');xlabel('time in sec')

clear ans dfl dfx headr z

Mhead=atan2(mean(sin(heading/180*pi)),mean(cos(heading/180*pi)));

for ii=1:length(Mhead);
   if Mhead(ii)<0,
      Mhead(ii)=Mhead(ii)+2*pi;
   end
end

clear dfx1 dfx2

heading=medfilt1(heading);
heading=heading-5.3;                     %correction
fclose(flist);