function oms_calHR(ncfile,calfile,hrdatafile)
%ncfile fully qualified ncfile location
%calfile fully qualified calibration file location
%hrdatafile fully qualified path name of a single extracted oasis hex data file from the instrument
%note PixCount,PixIncrement,FirstPix must be determined by user
%from oasis hex data find 0ff0 counting from the end 0ff0 characters 81:84 are PixCount,77:80 are PixIncrement,73:76 are FirstPix
%if not provided defaults are 338,4,350

OK = 0; 

if nargin < 3
PixCount = 338;
PixIncrement = 4;
FirstPix = 350;
OK = 1
end


if ~OK
    fid = fopen(hrdatafile);
    X=fgetl(fid);
    
    while findstr(X,'#') > 0
        X=fgetl(fid);
    end
    
    start=findstr(X,'0ff0')+4;
    X=X(start:end);
    PixCount = hex2dec(X(81:84));
    PixIncrement = hex2dec(X(77:80));
    FirstPix = hex2dec(X(73:76));
    X=fclose(fid);
end

    
    
Cal = oms_readHRCal(calfile);
HR = netcdf(ncfile,'write');

for i=1:length(Cal)
    tempa = char(Cal(i).Hr.Chan);
    for j=1:length(HR)
    tempb = char(ncnames(ncvar(HR{j})));
        if strcmp(tempa,tempb)
            match(i)=j;
        end
    end
end;

for i = 1:length(Cal)
    fprintf('Calibrating %s\n',char(ncnames(ncvar(HR{match(i)}))));
    %if strcmp(char(ncnames(ncvar(HR{match(i)}))),'Lu_Wet')        
    %Data = HR{match(i)}(:);
    %Data = Data.*1000;
    %fprintf('Scale Factor by 3');
    %else
    Data = HR{match(i)}(:);
    %end
    
    [r c] = size(Data);
    
    for j=1:r
        
        if j == 1
            pixelNum(j) = FirstPix;
        else
            pixelNum(j) = FirstPix + PixIncrement*j;
        end
        
        lambda(j) = Cal(i).Hr.W(1)+pixelNum(j)*Cal(i).Hr.W(2)+pixelNum(j)^2*Cal(i).Hr.W(3);
        CalDat(j,:)=(Cal(i).Hr.Caldat(pixelNum(j)).e*Cal(i).Hr.Caldat(pixelNum(j)).immer) .* Data(j,:);
            
    end
  HR{match(i)}(:)=CalDat;
  clear lambda;clear pixelNum;clear CalDat;
end
ncquit(HR)