function iaga2db (sta_name,year,dir)
% put the data from IAGA2002 files to the DataBase
% input params:
% sta_name - three letters IAGA name of the station ('vos')
% year - year of the IAGA files (2012)
% dir - path to the IAGA files
%----------------------------------------------------------

% read config file db_config.pc

f = fopen('db_config.pc','r');
    serv = fgetl(f);
    log = fgetl(f);
    pass = fgetl(f);
    dbname  = fgetl(f);
    table = fgetl(f);
    
fclose(f);

% open DB
 
 mysql('open', serv,log,pass);
 mysql(['use ' dbname]);
 
% read every file in the year
start_date = datenum(year,1,1);
%days = yeardays(year);
days = sum(eomday(year,1:12));

    for actual = start_date:1:start_date+days-1;
        %thl20111230dmin.min
        iaga_name = [dir, sta_name, datestr(actual,'yyyymmdd'), 'dmin.min'];
        disp(iaga_name);
        fid = fopen(iaga_name);
        if fid > -1
          while ~feof(fid)
              tline = fgetl(fid);
              %2011-12-31 23:59:00.000 365      2510.90  -3229.90  56246.10  88888.80
              if num2str(year) == tline(1:4)
                  
                  time = ['''' tline(1:19) ''''];
                  disp(time);
                  f_x = str2num(tline(31:40));
                  f_y = str2num(tline(41:50));
                  f_z = str2num(tline(51:60));
               %
               %  HERE CONVERT THE XYZ TO HEZ coordinate system
               %   
                    if (f_x < 88888)
                        xs=['''' int2str(round(f_x)) '''']; 
                    else
                        xs = 'NULL';
                    end
                    if (f_y < 88888)
                        ys=['''' int2str(round(f_y)) '''']; 
                    else
                        ys = 'NULL';
                    end             
                    if (f_z < 88888)
                        zs=['''' int2str(round(f_z)) ''''];
                    else
                        zs = 'NULL';
                    end             
                            
                   % add data to the DB
                
                  query = ['INSERT INTO ',table ,' (time,x,y,z) VALUES (',time,',',xs,',',ys,',',zs,') ON DUPLICATE KEY UPDATE x=',xs,',y=',ys,',z=',zs,';'];
				  
                  
                  mysql(query);
                   %disp (query);
              end
          end
          
         fclose(fid); 
        end  
  
           
    end
    
mysql('close'); 
