function calfile = getCalFileFromCfg(cfgfile, instrument)
% getCalFileFromCfg - Returns the path to the calibration file from the cfg file
%
% Use as: calfile = getCalFileFromCfg(cfgfile, instrument)

% Brian Schlining
% 01 Dec 2000

fid = fopen(cfgfile, 'rt');

calfile = [];

instrument = lower(instrument);

if fid < 1
   warning(['Unable to open ' cfgfile])
   return
end

warning('off')
while ~feof(fid)
   s = fgetl(fid);
   firstWord = lower(stringtokenizer(s, 1));
   if strcmp(firstWord, instrument)
      calfile = deblank(stringtokenizer(s, 2));
      break;
   end
end
warning('on')

fclose(fid);

if isempty(calfile)
   warning(['Unable to find key word ' instrument ' in ' cfgfile])
end
