#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 18:23:17 2020

@author: JKH

Reads the header file in from OpusHdr output


"""




def read_hdr(hdr1_fname):
#    hdr1_fname = '/home/osboxes/research/tccon/egi2020/results/daily/20140613/matchup/cn20140613_hdr1.dat'
    fid = open(hdr1_fname, 'r') #open for reading
    raw_data = fid.read() #read in all data at once into python
    fid.close()
    
    out_dat = {}
    
    for iLine in raw_data.splitlines():
        if iLine[0:2] == '  ': #starts with an indent
            param_splt = iLine[2:].split(': ', 1) #split at first occurance
            if param_splt[0] in out_dat:
              ValueError('Key %s appears twice in %r' % (param_splt[0], hdr1_fname) )
            out_dat[param_splt[0]] = param_splt[1]
    
    return out_dat



