function CALSTRUCT = ReadCalFileHS(CalFileName);

if ~nargin
   [infile inpath] = uigetfile('*.cal','Select HS calibration file',0,0);
   if infile == 0
      CALSTRUCT = [];
      return                            % Return if CANCEL is selected
   end
   CalFileName = [inpath infile];
end

fid = fopen(CalFileName,'r');

if fid == -1
    error('ERROR in %s. Unable to open the file %s', mfilename, CalFileName);
end


S = fgetl(fid);%[General] -Trash
S = fgetl(fid);%[DeviceType] 
Cal.DeviceType = S(12:end);
S = fgetl(fid);%[Serial]
Cal.Serial = S(8:end);
S = fgetl(fid);%{Label]
Cal.Label = S(7:end);
S = fgetl(fid);%[Config]
Cal.Config = S(8:end);
S = fgetl(fid);%[MaxDepth] -Trash
S = fgetl(fid);
LP = min(find(S=='('));
RP = min(find(S==')'));
Cal.CalTime = sscanf(S(9:LP-2), '%f');
Cal.CalTimeStr = S(LP+1:RP-1);
S = fgetl(fid);%[DepthCal]
Cal.DepthCal = sscanf(S(10:end), '%f');
S = fgetl(fid);%[Cal.DepthOff]
Cal.DepthOff = sscanf(S(10:end), '%f');
S = fgetl(fid);%[CalTemp]
Cal.CalTemp= sscanf(S(9:end), '%f');
S = fgetl(fid);%[Blank]

if utc2sdn(Cal.CalTime) < datenum('10/1/2002')%hobi changed cal format and calculations around then 
        Cal.CalType = 0;
    for Chan = 1:3
        S = fgetl(fid);   %[Channel 1:3]
        S = fgetl(fid); %[Name]
        Cal.Ch(Chan).Name = S(6:end);
        for G = 1:5
            S = fgetl(fid);%[Gain Channel 1:5]
            Cal.Ch(Chan).Gain(G) = sscanf(S(7:end), '%f');
        end
        S = fgetl(fid);%[Mu]
        Cal.Ch(Chan).Mu = sscanf(S(4:end), '%f');
        for G = 1:3
            S = fgetl(fid);%[Sigma Channel 1:3]
            Cal.Ch(Chan).Sigma(G) = sscanf(S(8:end), '%f');
        end
        S = fgetl(fid);%[ROut]
        Cal.Ch(Chan).ROutOff = sscanf(S(9:end), '%f');
        S = fgetl(fid);%[RNominal]
        Cal.Ch(Chan).RNominal = sscanf(S(10:end), '%f');
        S = fgetl(fid);%[Beta2Bb]
        Cal.Ch(Chan).Beta2Bb = sscanf(S(9:end), '%f');
        S = fgetl(fid);%[Bb2c]
        Cal.Ch(Chan).Bb2c = sscanf(S(6:end), '%f');
        S = fgetl(fid);%[Temp Coeff]
        Cal.Ch(Chan).TempCoeff = sscanf(S(11:end), '%f');
        S = fgetl(fid);%[Blank till next Channel] -Trash
    end %for chan
    
else %if date
        Cal.CalType = 1;
        for Chan = 1:3
        S = fgetl(fid);   %[Channel 1:3]
        S = fgetl(fid); %[Name]
        Cal.Ch(Chan).Name = S(6:end);
        for G = 1:5
            S = fgetl(fid);%[Gain Channel 1:5]
            Cal.Ch(Chan).Gain(G) = sscanf(S(7:end), '%f');
        end
        S = fgetl(fid);%[Mu]
        Cal.Ch(Chan).Mu = sscanf(S(4:end), '%f');
        for G = 1:3
            S = fgetl(fid);%[Sigma Channel 1:3]
            Cal.Ch(Chan).Sigma(G) = sscanf(S(8:end), '%f');
        end
        S = fgetl(fid);%[SigmaExp]
        Cal.Ch(Chan).SigmaExp = sscanf(S(10:end), '%f');
        S = fgetl(fid);%[RNominal]
        Cal.Ch(Chan).RNominal = sscanf(S(10:end), '%f');
        S = fgetl(fid);%[Beta2Bb]
        Cal.Ch(Chan).Beta2Bb = sscanf(S(9:end), '%f');
        S = fgetl(fid);%[MuRho]
        Cal.Ch(Chan).MuRho = sscanf(S(6:end), '%f');
        S = fgetl(fid);%[Temp Coeff]
        Cal.Ch(Chan).TempCoeff = sscanf(S(11:end), '%f');
        for G = 1:5
            S = fgetl(fid);%[Offset Channel 1:5]
            Cal.Ch(Chan).Offset(G) = sscanf(S(9:end), '%f');
        end
        for G = 1:5
            S = fgetl(fid);%[NomOffset Channel 1:5]
            Cal.Ch(Chan).NomOffset(G) = sscanf(S(12:end), '%f');
        end
        S = fgetl(fid);%[Blank till next Channel] -Trash
        end %for chan
end % if date
    
    
fclose(fid);

CALSTRUCT = Cal;

return
