function runlog = read_new_gfit_runlog(filename)
% Read new gfit runlog 2009-Feb
% Example:
% filename = '/net/nicolet/raid1/dwunch/lamont_ifs3/gfit_090219/080706_090205/20090130/20090130.grl'; 
% runlog = 
%     Spectrum_File_Name: {820x1 cell}
%                   Year: [820x1 double]
%                    Day: [820x1 double]
%                   Hour: [820x1 double]
%                  oblat: [820x1 double]
%                  oblon: [820x1 double]
%                  obalt: [820x1 double]
%                   ASZA: [820x1 double]
%                   POFF: [820x1 double]
%                   AZIM: [820x1 double]
%                   OSDS: [820x1 double]
%                    OPD: [820x1 double]
%                   FOVI: [820x1 double]
%                   FOVO: [820x1 double]
%                   AMAL: [820x1 double]
%                 IFIRST: [820x1 double]
%                  ILAST: [820x1 double]
%               DELTA_NU: [820x1 double]
%                POINTER: [820x1 double]
%                    BPW: [820x1 double]
%                   ZOFF: [820x1 double]
%                    SNR: [820x1 double]
%                    APF: {820x1 cell}
%                   tins: [820x1 double]
%                   pins: [820x1 double]
%                   hins: [820x1 double]
%                   tout: [820x1 double]
%                   pout: [820x1 double]
%                   hout: [820x1 double]
%                   fvsi: [820x1 double]
%                   wspd: [820x1 double]
%                   wdir: [820x1 double]
%                   lasf: [820x1 double]
%                 wavtkr: [820x1 double]
%                   aipl: [820x1 double]
%                   time: [820x1 double]

fid = fopen(filename,'r');
a = fgetl(fid);
n = str2num(a);
nhead = n(1);
ncol  = n(2);

for i=1:nhead-2
    fgetl(fid);
end

headers = fgetl(fid);
headers = textscan(headers,'%s');
headers = headers{1};

form = '';

for i=1:ncol
    if strcmp(headers{i},'APF')||strcmp(headers{i},'Spectrum_File_Name')
        form = [form '%s'];
    else
        form = [form '%f'];
    end
end

A = textscan(fid,form);
fclose(fid);

runlog = cell2struct(A,headers,2);

runlog.time = datenum(runlog.Year,0,runlog.Day,runlog.Hour,0,0);
runlog.nheaderlines = nhead;
runlog.ncolumns = ncol;