function [] = camData()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Log camera data to an ascii file.
% INPUTS:  This program must be run in a mission directory containing the
%          binary AUV files navigation.log and camera.log.
% OUTPUTS: Creates file camera.txt.  See embedded comments.
% CHANGELOG:
%  (1) Initial, Rob McEwen, 2010/08/26
%  (2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
  focalLength = 28;      %in mm.

  lognames = {'navigation.log';
	      'camera.log'};
%
% Read in the binary AUV logs:
  for( i=1:length(lognames))
    logname=char(lognames(i));
    if( exist(logname) ~= 2 )
      fprintf('Error: the file %s is not present.  Exiting.\n', logname);
      return
    else
      fprintf('Reading %s.\n', logname);
      tic
      readlog;
      toc
    end
  end
%
% Create the output file:
  fileName = 'camera.txt';
  FID = fopen(fileName,'wt');
  fprintf('Just opened FID%d with name %s\n', FID, fileName)
%
% Interpolate the navigated UTM coordinates and other vehicle states to when the
% photo was taken:
% camx = interp1(dataNav(:,1), dataNav(:,mPos_x), cam.data(:,1));
% camy = interp1(dataNav(:,1), dataNav(:,mPos_y), cam.data(:,1));

% Account for the cos(pi/6) Dvl altitude error:
  camAlt   = interp1(dataNav(:,1), dataNav(:,mAltitude), cam.data(:,1))/cos(pi/6);

  camRoll  = interp1(dataNav(:,1), dataNav(:,mPhi),      cam.data(:,1));
  camPitch = interp1(dataNav(:,1), dataNav(:,mTheta),    cam.data(:,1));
  camYaw   = interp1(dataNav(:,1), dataNav(:,mPsi),      cam.data(:,1));
%
% For now assume the camera line of sight is perpendicular to a planar bottom:
  fovHeight= camAlt * 24/focalLength;
  fovWidth = camAlt * 36/focalLength;
%
% Write comments and data to the output file:
  fprintf(FID, '# Data file for photographs from Mission %s\n', DirName);
  fprintf(FID, '# All units are in SI, with angles in radians, unless otherwise noted.\n');
  fprintf(FID, ['# UnixTime Photo No. Lat(deg) Lon(deg) Depth Altitude Yaw Pitch' ...
		' Roll FOVheight FOVwidth\n']);
%
% Unix time does not include leap seconds since 1 Jan 1970, as UTC does.
fprintf(FID, '%15.2f %4d %13.8f %13.8f %7.3f %7.3f %7.4f %7.4f %7.4f %5.2f %5.2f\n', ...
            [cam.data(:,1), ...
             cam.data(:,2), ...
             cam.data(:,3:4)*180/pi, ...
	     cam.data(:,5),...
             camAlt, ...
             camYaw, camPitch, camRoll,...
	     fovHeight, fovWidth]');
  
  fclose(FID);
  fprintf('Closed FID%d with name %s\n', FID, fileName)

  return
