/****************************************************************************/ /* */ /* IAGA_to_IAGA2002.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads an IAGA format data file and writes */ /* out the same data in IAGA2000 format. */ /* */ /* Usage: */ /* IAGA_to_IAGA2002 [-s] [-e | -h] [-o] [-p] [-d] [<] IAGA_file */ /* > IAGA2002_file */ /* [-s YYYYMMDDHH] Time of the first record included. If missing */ /* then start of file is assumed. */ /* [-e YYYYMMDDHH] Time of the record not included anymore. If */ /* missing then end of file is assumed. */ /* [-h HH] Number of hours included. Either -e or -h can */ /* be specified, not both. */ /* [-p] This is used when reading data from pipe */ /* [-o 'Station list'] List of stations delimited by aposthropes */ /* If missing then all stations included. */ /* Stations are identified by three-letter code */ /* and separated by exactly one space. */ /* [-i Header_file] Name of the file containing header lines of the */ /* IAGA2002 file. If this parameter is not defined */ /* then a file with three letter station ID is */ /* searched in the bin/IAGA2002 directory. */ /* [-d Directory] Directory path where the individual station */ /* data files are written. If -d option is not */ /* specified then data from only one station will */ /* be written into stdout. If the given Directory */ /* is 'current' then current working directory is */ /* used. */ /* IAGA_file Name of IAGA-format file. */ /* IAGA2002_file Name of IAGA2002-format file. */ /* */ /****************************************************************************/ /****************************************************************************/ /* Lasse Hakkinen */ /* Finnish Meteorological Institute */ /* Geophysical Research Division */ /* P.O.Box 503 */ /* FIN-00101, Helsinki, Finland */ /* e-mail: Lasse.Hakkinen@fmi.fi */ /* phone : (+358)-9-19294634 */ /* fax : (+358)-9-19294603 */ /* */ /* version 1.02 13.01.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* */ /* 1.02 13.01.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.01 01.02.2017 IAGA2000 -> IAGA2002 + several modifications. */ /* 1.0 03.10.2000 First official release */ /****************************************************************************/ #include #include #include #include "Usage.h" #include "MagnData.h" #include "IAGA.h" #include "IAGA2002.h" char *version = "1.02"; char *date = "13.01.2020"; #define HeaderLineCount 4 #define UsageLineCount 36 char *HeaderText[HeaderLineCount] = { "*******************************************************************", " This program converts magnetometer data from IAGA format into ", " IAGA2002 format. ", "*******************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [-d] [-p] [<] IAGA_file > IAGA2000_file", " [-s YYYYMMDDHH] Time of the first record included. If missing ", " then start of file is assumed. ", " [-e YYYYMMDDHH] Time of the record not included anymore. ", " If missing then end of file is assumed. ", " [-h HH] Number of hours included. Either -e or -h can ", " be specified, not both. ", " [-o 'Station list'] List of stations enclosed in quotes ", " If missing then all stations included. ", " Stations are identified by three-letter code ", " and separated by exactly one space. ", " e.g. 'SOR KEV KIL'. ", " [-i Header_file] Name of the file containing header lines of the", " IAGA2002 file. If this parameter is not defined", " then a file with three letter station ID is" , " searched in the bin/IAGA2002 directory." , " [-d DirectoryName] Directory path where the individual station ", " data files are written. ", " If -d option is not specified then data from ", " only one station (either the first station in ", " StationList or the first station in IAGA_file)", " will be written into stdout. ", " If -d option is specified then data for each ", " station will be written into individual files ", " in the given directory. The file names are ", " according to the IAGA2000 specification as ", " YEARMMD1D2BB.AAA where D1 and D2 are the start", " and end days, BB is sample step and AAA is the", " station identifier. ", " If the given DirectoryName is 'current' then ", " the current working directory is used. ", " [-p] Data is read from pipe. This prevents the ", " info text from appearing. ", " IAGA_file Name of IAGA-format file. ", " IAGA2000_file Name of IAGA2000-format file. ", }; /*--------------------------------------------------------------------------*/ /* The main procedure */ /*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { long params; long status = 0; long FileCount = 0; long HourCount = 0; char FileName[200] = ""; char IAGA2002file[200] = ""; char StartTimeStr[16] = ""; char EndTimeStr[16] = ""; char StationStr[400] = ""; char DirectoryStr[200] = ""; char Header_file[200] = ""; /* Name of the IAGA2002 header file */ Network_struct NETWORK; StationPtr s; /*==========================*/ /* Analyse the command line */ /*==========================*/ if (argc == 1) { /* No arguments, show the usage text */ PrintUsage(argv[0],0,HeaderLineCount,UsageLineCount); return OK; } for (params = 1; params < argc; params++) { if (*argv[params] != '-') { strcpy(FileName,argv[params]); FileCount++; } else { switch (*(argv[params]+1)) { case 's' : strcpy(StartTimeStr,argv[++params]); break; case 'e' : strcpy(EndTimeStr,argv[++params]); break; case 'h' : HourCount = atol(argv[++params]); break; case 'd' : strcpy(DirectoryStr,argv[++params]); break; case 'p' : break; case 'i' : strcpy(Header_file,argv[++params]); break; case 'o' : strcpy(StationStr,argv[++params]); break; default : fprintf(stderr,"\n### %s: \"%s\" is not an option.\n\n", argv[0], argv[params]); PrintUsage(argv[0],1,HeaderLineCount,UsageLineCount); return FAIL; break; } } } /*====================================*/ /* Check the values of the parameters */ /*====================================*/ if (FileCount > 1) { PrintUsage(argv[0],1,HeaderLineCount,UsageLineCount); return FAIL; } if ((HourCount != 0) && (strlen(EndTimeStr) > 0)) { PrintUsage(argv[0],1,HeaderLineCount,UsageLineCount); return FAIL; } if ((HourCount != 0) && (strlen(StartTimeStr) == 0)) { PrintUsage(argv[0],1,HeaderLineCount,UsageLineCount); return FAIL; } if (HourCount != 0) { SecsToStrC(StrToSecsC(StartTimeStr,0)+3600*HourCount,EndTimeStr); } /*===================================================*/ /* Read the data from a IAGA format file into memory */ /*===================================================*/ status = ReadIAGA(FileName,&NETWORK,StartTimeStr,EndTimeStr,StationStr); if (status != 0) { if (status == FileError) fprintf(stderr,"Error in reading file %s\n",FileName); if (status == OutOfMemory) fprintf(stderr,"Out of memory while reading IAGA file %s\n",FileName); if (status == FileFormatError) fprintf(stderr,"%s is not an IAGA format file\n",FileName); return FAIL; } ChangeUnitsUP(&NETWORK); // Resolution in IAGA is 0.1 nT in IAGA2002 is 0.01 nT /*======================================*/ /* Write the data in IAGA2000 format */ /*======================================*/ s = NETWORK.StationList; /* go through the stations */ while (s != NULL) { if (strlen(DirectoryStr) > 0) { // Generate name to IAGA2002 file // To be written } status = WriteIAGA2002(DirectoryStr,&NETWORK,NULL,NULL,s,Header_file); if (status != 0) { fprintf(stderr,"Error %d in genetaring IAGA2002 file\n",status); return FAIL; } s = s->Next; } FreeNetwork(&NETWORK); return OK; }