function out = read_map_2012(filename)
% Read GGG2012 map files
%
% out = read_map(filename);
% 
% Example:
% 
% Input:
% filename = '/net/ccycle/analysis1/tccon/CarbonTracker/TCCON_aprioris/pa2000-2010/pa20000101.map';
% out = 
%                 Height_km: [71x1 double]
%                    Temp_K: [71x1 double]
%              Pressure_hPa: [71x1 double]
%     Density_molecules_cm3: [71x1 double]
%                 h2o_parts: [71x1 double]
%                 hdo_parts: [71x1 double]
%                   co2_ppm: [71x1 double]
%                   n2o_ppb: [71x1 double]
%                    co_ppb: [71x1 double]
%                   ch4_ppb: [71x1 double]
%              gravity_m_s2: [71x1 double]
%                      year: 2000
%                     month: 1
%                       day: 1
%                      time: 730486
%                      site: 'pa'
%                      info: ' WRITE_AUX                Version 1.1.0    23-Mar-2012    DW  '
%                  Avogadro: 6.022141500000000e+23
%                  MDry_Air: 0.028964400000000
%                      MH2O: 0.018015340000000
%                  Latitude: 45.945000000000000

% filename = '/net/ccycle/analysis1/tccon/CarbonTracker/TCCON_aprioris/pa2000-2010/pa20000101.map';
fid = fopen(filename,'r');

h1 = fgetl(fid);
h1 = str2num(h1);
nhead = h1(1);
ncol = h1(2);

fnm = fgetl(fid);
loc = textscan(fnm,'%2c%8c%4c');
dt = datenum(loc{2},'yyyymmdd');

info = fgetl(fid);
if strcmpi(info(1:7),' GSETUP')
    info = fgetl(fid);
end
fgetl(fid);
a = textscan(fgetl(fid),'%s%f','Delimiter',':');
b = textscan(fgetl(fid),'%s%f','Delimiter',':');
c = textscan(fgetl(fid),'%s%f','Delimiter',':');
d = textscan(fgetl(fid),'%s%f','Delimiter',':');


head = fgetl(fid);
unit = fgetl(fid);

head = textscan(head,'%s','Delimiter',',');
head = head{1};

unit = textscan(unit,'%s','Delimiter',',');
unit = unit{1};

for i=1:length(head)
    header{i} = [deblank(head{i}) '_' deblank(unit{i})];
end

form = repmat('%f',1,length(header));
A = textscan(fid,form,'Delimiter',',');

fclose(fid);

out = cell2struct(A,header,2);

out.year = year(dt);
out.month= month(dt);
out.day  = day(dt);
out.time = datenum(out.year,out.month,out.day);
out.site = loc{1};
out.info = info;
out.Avogadro = a{2};
out.MDry_Air = b{2};
out.MH2O = c{2};
out.Latitude = d{2};
