% Reading header data.

function [EPOCH_OF_FIRST_MAP, EPOCH_OF_LAST_MAP, INTERVAL, N_OF_MAPS_IN_FILE, MAPPING_FUNCTION, ELEVATION_CUTOFF, N_OF_STATIONS, N_OF_SATELLITES, BASE_RADIUS, MAP_DIMENSION, HGT1_2_D, LAT1_2_D, LON1_2_D, EXPONENT] = ReadingHeader(IONEXFile)

NoHL = CalcNumOfHeaderLines (IONEXFile); % Number of lines in the IONEX file header.
DataFile = fopen(IONEXFile,'r');
fseek(DataFile, 0, 'bof'); 

tline = fgetl(DataFile); 
for i = 1:NoHL
    %disp(tline)
    
        k = strfind(tline, 'EPOCH OF FIRST MAP');
        if ~(isempty(k)), 
            EPOCH_OF_FIRST_MAP = sscanf (tline, '%d %d %d %d %d %d %*s'); 
        end
        k = strfind(tline, 'EPOCH OF LAST MAP'); 
        if ~(isempty(k)), 
            EPOCH_OF_LAST_MAP = sscanf (tline, '%d %d %d %d %d %d %*s'); 
        end
        k = strfind(tline, 'INTERVAL'); 
        if ~(isempty(k)), 
            INTERVAL = sscanf (tline, '%d %*s'); 
        end
        k = strfind(tline, '# OF MAPS IN FILE'); 
        if ~(isempty(k)), 
            N_OF_MAPS_IN_FILE = sscanf (tline, '%d %*s'); 
        end
        k = strfind(tline, 'MAPPING FUNCTION'); 
        if ~(isempty(k)), 
            MAPPING_FUNCTION = sscanf (tline, '%s %*s %*s'); 
        end
        k = strfind(tline, 'ELEVATION CUTOFF'); 
        if ~(isempty(k)), 
            ELEVATION_CUTOFF = sscanf (tline, '%f %*s'); 
        end
        k = strfind(tline, '# OF STATIONS'); 
        if ~(isempty(k)), 
            N_OF_STATIONS = sscanf (tline, '%d %*s'); 
        end
        k = strfind(tline, '# OF SATELLITES'); 
        if ~(isempty(k)), 
            N_OF_SATELLITES = sscanf (tline, '%d %*s'); 
        end
        k = strfind(tline, 'BASE RADIUS'); 
        if ~(isempty(k)), 
            BASE_RADIUS = sscanf (tline, '%f %*s'); 
        end
        k = strfind(tline, 'MAP DIMENSION'); 
        if ~(isempty(k)), 
            MAP_DIMENSION = sscanf (tline, '%d %*s'); 
        end
        k = strfind(tline, 'HGT1 / HGT2 / DHGT'); 
        if ~(isempty(k)), 
            HGT1_2_D = sscanf (tline, '%f %f %f %*s'); 
        end
        k = strfind(tline, 'LAT1 / LAT2 / DLAT'); 
        if ~(isempty(k)), 
            LAT1_2_D = sscanf (tline, '%f %f %f %*s'); 
        end
        k = strfind(tline, 'LON1 / LON2 / DLON'); 
        if ~(isempty(k)), 
            LON1_2_D = sscanf (tline, '%f %f %f %*s'); 
        end
        k = strfind(tline, 'EXPONENT'); 
        if ~(isempty(k)), 
            EXPONENT = sscanf (tline, '%d %*s'); 
        end
                
    tline = fgetl(DataFile); 
    
end

fclose(DataFile);
