function head=IAGA2002_read_head(fid);
% Read of header of IAGA-2002 format data file
%
%               head=iaga2002_read_head(fid);
%
% as structure
%             'Format'
%             'Source'
%             'Station'
%             'Code'
%             'Latitude'
%             'Longitude'
%             'Elevation'
%             'Elements'
%             'Orientation'
%             'Sampling'
%             'DataInterval'
%             'DataType'
%             'Comments'

% 27.06.2009, S.Khomutov

fseek(fid,0,-1);  % возвращаем указатель записи в начало файла

str=fgetl(fid); % Format
    field01=deblank(str(25:length(str)-1));
str=fgetl(fid); % Source of Data
                % is the name of the institute responsible for collecting 
                % the data.
    field02=deblank(str(25:length(str)-1));
str=fgetl(fid); % Station Name
                % Please spell the entire station name; 
                % do not use abbreviations. Capitalize the first letter
    field03=deblank(str(25:length(str)-1));
str=fgetl(fid); % IAGA CODE
                % is the official IAGA 3-letter station code. It should be
                % in capital letters and correspond to the IAGA list 
                % of magnetic observatories. Variation stations must check 
                % observer suggested 3-letter codes against the IAGA list 
                % (WDC SEG, Boulder) and confirm through the IAGA Division V 
                % WG1 or leave the code blank
    field04=deblank(str(25:length(str)-1));
str=fgetl(fid); % Geodetic Latitude (positive north) from -90 to 90 degrees
    field05=deblank(str(25:length(str)-1));
str=fgetl(fid); % Geodetic Longitude (positive east) from -180 to 180 or 0 to 360 degrees
    field06=deblank(str(25:length(str)-1));
str=fgetl(fid); % Elevation in meters above mean sea level
    field07=deblank(str(25:length(str)-1));
str=fgetl(fid); % Reported refers to the magnetic field elements 
                % contained in the data record, in the order recorded 
                % in data record. Valid values are DHIF, DHZF, and XYZF. 
                % Use E/V instead of D/I for declination/inclination 
                % given in intensity units (ONLY if data type is variation).
    field08=deblank(str(25:length(str)-1));
str=fgetl(fid); % Sensor Orientation
                % is the physical orientation of the observing instruments,
                % i.e. XYZF, HDZ
    field09=deblank(str(25:length(str)-1));
str=fgetl(fid); % Digital Sampling
                % is the rate (in seconds) of the data sampling of the
                % magnetic field sensor (instrument) or the digitizing 
                % interval for analogue data
    field10=deblank(str(25:length(str)-1));
str=fgetl(fid); % Data Interval Type
                % is the mean or instantaneous time interval of the
                % data. Common values include 1-minute (00:30-01:29), 
                % 1-minute (00:00-00:59), 1-hour (00-59), 1-day (00-23) 
                % and 1-month (01-31); the last day could also be 
                % 30, 29, or 28. There are many possible intervals, 
                % including a fraction of a second (instant value), 
                % averages by 1-second (501-1500), 1- second (0-1000), 10 second, or 2.5 minute. Define the type of mean and how values are centered in the comment section
    field11=deblank(str(25:length(str)-1));
str=fgetl(fid); % Data Type is provisional, definitive, or variation
    field12=deblank(str(25:length(str)-1));

field13=[];
while 1,        % считываем поле комментария
    str=fgetl(fid);
    if str(1:3)~=' # ', break, end
    field13=strvcat(field13,str);
end

head=struct('Format', field01,...
            'Source', field02,...
            'Station', field03,...
            'Code', field04,...
            'Latitude', field05,...
            'Longitude', field06,...
            'Elevation', field07,...
            'Elements', field08,...
            'Orientation', field09,...
            'Sampling', field10,...
            'DataInterval', field11,...
            'DataType',field12,...
            'Comments', field13);

