/****************************************************************************/ /* */ /* Dump_to_IAGA2002.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads a Dump-format data file and writes */ /* out the same data in IAGA2002 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] [-i] 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. */ /* [-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. */ /* [-v] Verbose. Print info about program execution. */ /* Dump_file Name of Dump-format file. */ /* IAGA2002_file Name of IAGA2002-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.01 03.01.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* */ /* 1.01 03.01.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.0 29.07.2013 First official release */ /****************************************************************************/ #include #include #include #include "Usage.h" #include "MagnData.h" #include "Dump.h" #include "IAGA2002.h" char *version = "1.01"; char *date = "03.01.2020"; #define HeaderLineCount 3 #define UsageLineCount 27 char *HeaderText[HeaderLineCount] = { "******************************************************************************", "This program converts magnetometer data from Dump format into IAGA2002 format.", "******************************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [-v] [-i] 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.", " [-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.", " [-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 */ long FullMinuteFlag = 0; /* Flag for setting the end time to full minute */ char FileName[100] = ""; /* Name of the dump file */ char StartTimeStr[16] = ""; char EndTimeStr[16] = ""; char StationStr[50] = ""; /* Name of the station */ char Header_file[100] = ""; /* Name of the IAGA2002 header file */ 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 'i' : strcpy(Header_file,argv[++params]); break; case 'f' : FullMinuteFlag = 1; 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; } // if (strlen(Header_file) == 0) { // strcpy(Header_file, "/proj/image/bin/IAGA2002/"); // strcat(Header_file, NETWORK.StationList->StationID); // } // Fix for the NU2 station ID if (strcmp(NETWORK.StationList->StationID, "NU2") == 0) { strcpy(NETWORK.StationList->StationID, "NUR"); } // Set the end time to full minute if (FullMinuteFlag) { NETWORK.StationList->EndTime = 60*(NETWORK.StationList->EndTime/60); } /*==================================================*/ /* Write the data in IAGA2002 format into stdout */ /*==================================================*/ if (VerboseFlag) fprintf(stderr,"-- Writing IAGA2002 file \n"); status = WriteIAGA2002(NULL, &NETWORK, StartTimeStr, EndTimeStr, NETWORK.StationList, Header_file); if (status != 0) { fprintf(stderr,"Error %d in genetaring IAGA2002 file\n",status); return FAIL; } FreeNetwork(&NETWORK); if (VerboseFlag) fprintf(stderr,"-- Execution successful.\n"); return OK; }