close all
clear all

%global P;
%global count;

path = 'C:\Documents and Settings\hamilton\Desktop\FOO\';
filename = 'D000000_120308_164118';
%filename = 'All.dat';


grav = 9.81;  %m/s^2
epoch_serialdate = datenum(1970,1,1,0,0,0);

%Packet Structure
DataSize = 92;
S.EpochUsecs = uint32(NaN);
S.EpochSecs = uint32(NaN);
S.rollAngle = int16(NaN);
S.pitchAngle = int16(NaN);
S.yawAngleTrue = int16(NaN);
S.xRateCorrected = int16(NaN);
S.yRateCorrected = int16(NaN);
S.zRateCorrected = int16(NaN);
S.xAccel = int16(NaN);
S.yAccel = int16(NaN);
S.zAccel = int16(NaN);
S.northVelocity = int16(NaN);
S.eastVelocity = int16(NaN);
S.downVelocity = int16(NaN);
S.longitudeGPS = int32(NaN);
S.latitudeGPS = int32(NaN);
S.altitudeGPS = int16(NaN);
S.xRateTemperature = int16(NaN);
S.timeITOW = uint32(NaN);
S.statusBits = int16(NaN);

S.padBytes = uint16(NaN);

S.CompHeading = double(NaN);
S.CompPitchAngle = double(NaN);
S.CompRollAngle = double(NaN);
S.CompTemperature = double(NaN);
S.CompPressureSense = double(NaN);

  fid = fopen([path filename]);
  count = DataSize;
  ii = 0;
  while (count == DataSize)
    ii = ii+1
    [A, count] = fread(fid,DataSize);
    %A'
    if(count == DataSize)
       P = ParseRawData(uint8(A),S);
       Eng = ScaleData(P,S);
       names = fieldnames(Eng);
       for jj = 1:length(names)
          eval([names{jj} '(ii) = Eng.' names{jj} ';']);
       end
    end
  end
  fclose(fid);

  save([path filename])
 
  clear P Eng
  


