/****************************************************************************/ /* */ /* NOR_to_IAGA.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads a NOR-format data file and writes */ /* out the same data in IAGA format. NOR-format is the data format that is */ /* used at Tromso University's Auroral Observatory for storing magnetometer */ /* data e.g. from Svalbard stations. NOR is not an official name of the */ /* data format (NOR = Norway). */ /* */ /* Usage: */ /* NOR_to_IAGA [-s] [-e | -h] [-o] [<] NOR_file > IAGA_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. */ /* [-d SampleStep] Time interval between successive data points. */ /* If not defined then 10 seconds is assumed. */ /* [-c XYZ] Convert data from HDZ representation into XYZ */ /* representation. Conversion is done in default. */ /* -c HDZ won't do any conversions. */ /* [-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. */ /* NOR_file Name of NOR-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.11 12.02.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* */ /* 1.11 12.02.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.1 5.10.2017 Rewrote the file reading routine and accommodated the */ /* changes in NOR2.h */ /* 1.0 29.7.2009 First official release */ /****************************************************************************/ #include #include #include #include #include "Usage.h" #include "MagnData.h" #include "NOR2.h" #include "IAGA.h" char *version = "1.11"; char *date = "12.02.2020"; #define HeaderLineCount 9 #define UsageLineCount 19 char *HeaderText[HeaderLineCount] = { "**************************************************************************", "This program converts magnetometer data from NOR format into IAGA format.", "NOR format is the data format used at Tromso University's Auroral", "Observatory for storing magnetometer data e.g. from the Svalbard stations.", "NOR is not the official name of the data format but in lack of a", "better name it is used here (NOR = Norway).", "Note that the file formats for 1 second, 10 second and 1 minute NOR files", "are different. However, this program handles them all.", "**************************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [<] NOR_file > IAGA_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.", " [-c XYZ] Convert data from HDZ representation into XYZ", " representation. If missing then XYZ conversion", " is made. -c HDZ will prevent the conversion", " [-d SampleStep] Sample step used in the file. If this is not ", " defined then 10 seconds is assumed. ", " [-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. 'NAL BJN NOR'.", " NOR_file Name of NOR-format file.", " IAGA_file Name of IAGA-format file.", }; /*--------------------------------------------------------------------------*/ /* The main procedure */ /*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { long params; long status = 0; long FileCount = 0; long HourCount = 0; char FileName[100] = ""; char StartTimeStr[20] = ""; char EndTimeStr[20] = ""; char StationStr[50] = ""; char CompStr[10] = "XYZ"; Time_sec SampleStep = 10; StationPtr 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 'c' : strcpy(CompStr,argv[++params]); break; case 'h' : HourCount = atol(argv[++params]); break; case 'o' : strcpy(StationStr,argv[++params]); break; case 'd' : SampleStep = atol(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 NOR format file into memory */ /*===================================================*/ status = ReadNOR(FileName,&NETWORK,StartTimeStr,EndTimeStr,StationStr,SampleStep); if (status != 0) { if (status == FileError) fprintf(stderr,"Error in reading NOR file %s\n",FileName); if (status == OutOfMemory) fprintf(stderr,"Out of memory while reading file %s\n",FileName); if (status == FileFormatError) fprintf(stderr,"%s is not a NOR format file\n",FileName); return FAIL; } /*==============================================*/ /* Write the data in IAGA format into stdout */ /*==============================================*/ WriteIAGA(NULL,&NETWORK,NULL,NULL,NULL); FreeNetwork(&NETWORK); return OK; }