/****************************************************************************/ /* */ /* Dump_to_IAGA.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads a Dump-format data file and writes */ /* out the same data in IAGA format. Dump is a data format used at FMI/GEO */ /* as an intermediate format for storing magnetometer data. */ /* */ /* Usage: */ /* Dump_to_IAGA [-s] [-e | -h] [-o] Dump_file > IAGA_file */ /* [-s YYYYMMDDHH] Time of the first record written into the IAGA */ /* file. If the Dump_file doesn't contain data for */ /* specified time then missing data markers will */ /* be written into IAGA file. If -s option is */ /* missing then start time is the time of first */ /* record in Dump_file. */ /* [-e YYYYMMDDHH] Time of the record not written anymore into */ /* the IAGA file. If the Dump_file doesn't contain */ /* data for the given time then the end of IAGA */ /* file will be filled with missing data markers. */ /* If -e option is not specified then the end time */ /* is the time of the last record in the Dump_file.*/ /* [-h HH] Number of hours included. Either -e or -h can */ /* be specified, not both. */ /* [-o StationName] Three letter station ID (e.g. NUR). If missing */ /* then station code is read from the data file. */ /* If StationName is defined then that value is */ /* used and the value in the data file is ignored. */ /* [-v] Verbose. Print info about program execution. */ /* Dump_file Name of Dump-format file. */ /* IAGA_file Name of IAGA-format file. */ /* */ /****************************************************************************/ /****************************************************************************/ /* Lasse Hakkinen */ /* Finnish Meteorological Institute */ /* Department of Geophysics */ /* P.O.Box 503 */ /* FIN-00101, Helsinki, Finland */ /* e-mail: Lasse.Hakkinen@fmi.fi */ /* phone : (+358)-9-19294634 */ /* fax : (+358)-9-19294603 */ /* */ /* version 1.15 03.01.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* */ /* 1.15 03.01.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.14 18.09.2001 Added Tartu station (T = TAR) into Dump.h. */ /* 1.13 15.10.1999 Modified Dump.h so that the last data is neglected if */ /* it does not end with CR or LF. In some cases this */ /* resulted in unrelated error messages. */ /* 1.12 13.10.1998 Modified Dump.h so that the program execution no longer */ /* breaks if data lines are not in chronological order */ /* 1.11 02.07.1999 Fixed a Y2K bug in NewTime.h file which resulted in */ /* incorrect year in date strings if year >= 2000. */ /* 1.1 21.10.1998 Major modification to Dump.h: Reads data with 0.01 nT */ /* accuracy (earlier 0.1 nT). Also temperature accuracy */ /* changed 0.1 C -> 0.01 C */ /* 1.04 29.09.1998 Modified Dump.h so that the program execution no longer */ /* breaks if data lines are not in chronological order */ /* 1.03 15.09.1998 Modified Dump.h so that the program execution no longer */ /* breaks if two data lines have the same time. */ /* 1.02 17.07.1998 Modified Dump.h so that field strings '*********' are */ /* interpreted as missing data values. */ /* 1.01 5.02.1997 Modified -s and -e options so that the IAGA file will */ /* start at time specified with -s and end at time */ /* specified with -e regardless whether Dump file contains */ /* data for given times. This allows easy creation of full */ /* daily files even if dump files do not contain data for */ /* whole days. */ /* */ /* 1.0 10.11.1996 First official release */ /****************************************************************************/ #include #include #include #include "Usage.h" #include "MagnData.h" #include "Dump.h" #include "IAGA.h" char *version = "1.15"; char *date = "03.01.2020"; #define HeaderLineCount 3 #define UsageLineCount 23 char *HeaderText[HeaderLineCount] = { "**************************************************************************", "This program converts magnetometer data from Dump format into IAGA format.", "**************************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [-v] Dump_file > IAGA_file", " [-s YYYYMMDDHH] Time of the first record written into the IAGA", " file. If the Dump file doesn't contain data", " for the specified time then missing data blocks", " will be written into the beginning of the IAGA", " file. If -s option is missing then start time", " is the time of first record in Dump file.", " [-e YYYYMMDDHH] Time of the record not written anymore into the", " IAGA file. If the Dump file doesn't contain", " data for the given time then the end of the", " IAGA file will be filled with missing data", " blocks. If -e option is not specified then", " the end time is the time of the last record", " in the Dump file.", " [-h HH] Number of hours included. Either -e or -h can", " be specified, not both.", " [-o StationName] Three letter station ID (e.g. NUR). If missing", " then station code is read from the data file.", " If StationName is defined then that value is", " used and the value in the data file is ignored.", " [-v Verbose] Print information about program execution.", " Dump_file Name of Dump-format file.", " IAGA_file Name of IAGA-format file.", }; /*--------------------------------------------------------------------------*/ /* The main procedure */ /*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { long params; /* Number of parameters in command line */ long status = 0; /* Status of file operations */ long FileCount = 0; /* Number of files given to program */ long HourCount = 0; /* Number of hours to be read */ long VerboseFlag = 0; /* Flag for displaying progress info */ char FileName[100] = ""; /* Name of the dump file */ char StartTimeStr[20] = ""; char EndTimeStr[20] = ""; char StationStr[50] = ""; /* Name of the station */ Network_struct NETWORK; /*==========================*/ /* 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 'o' : strcpy(StationStr,argv[++params]); break; case 'v' : VerboseFlag = 1; 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 data from a Dump format file into memory */ /*===============================================*/ if (VerboseFlag) fprintf(stderr,"-- Reading dumpfile %s\n",FileName); status = ReadDump(FileName,&NETWORK,StartTimeStr,EndTimeStr,StationStr); if (status != 0) { if (status == OutOfMemory) fprintf(stderr,"Out of memory while reading file %s\n",FileName); return FAIL; } /*========================================================*/ /* Convert field values from 0.01 nT to 0.1 nT resolution */ /* and temperature values from 0.01 C to 0.1 C */ /*========================================================*/ ChangeUnitsDOWN(&NETWORK); /*==============================================*/ /* Write the data in IAGA format into stdout */ /*==============================================*/ if (VerboseFlag) fprintf(stderr,"-- Writing IAGA file \n"); WriteIAGA(NULL,&NETWORK,StartTimeStr,EndTimeStr,NULL); FreeNetwork(&NETWORK); if (VerboseFlag) fprintf(stderr,"-- Execution successful.\n"); return OK; }