close all
clear all

global P;
global count;

path = '.\';





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

%Packet Structure
DataSize = 108;
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.LoadDumpVoltage = double(NaN);
S.BatteryVoltage = double(NaN);
S.BatteryCurrent = double(NaN);

S.UpperSpringTemperature = int32(NaN);
S.LowerSpringTemperature = int32(NaN);
S.SeawaterTemperature = int32(NaN);
S.IsothermalTemperature = int32(NaN);
S.UpperSpringPressure = int32(NaN);
S.LowerSpringPressure = int32(NaN);
S.LoadCellForce = int32(NaN);
S.PistonDistance = int32(NaN);


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

  save([path filename])


