/****************************************************************************/ /* */ /* IAGA2002_to_IAGA.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads a IAGA2002-format data file and */ /* writes out the same data in IAGA format. */ /* */ /* Usage: */ /* IAGA2002_to_IAGA [-s] [-e | -h] [-o] IAGA2002_file > IAGA_file */ /* [-s YYYYMMDDHH] Time of the first record written into the IAGA */ /* file. If the IAGA2002_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 IAGA2002_file. */ /* [-e YYYYMMDDHH] Time of the record not written anymore into */ /* the IAGA file. If the IAGA2002_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 */ /* IAGA2002_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. */ /* [-c XYZ] Convert data from HDZ representation into XYZ */ /* representation. -c HDZ won't do any conversions.*/ /* IAGA2002_file Name of IAGA2002-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.01 11.02.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* */ /* */ /* 1.01 11.02.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.0 02.06.2005 First official release */ /****************************************************************************/ #include #include #include #include "Usage.h" #include "MagnData.h" #include "IAGA2002.h" #include "IAGA.h" char *version = "1.01"; char *date = "11.02.2020"; #define HeaderLineCount 3 #define UsageLineCount 25 char *HeaderText[HeaderLineCount] = { "******************************************************************************", "This program converts magnetometer data from IAGA2002 format into IAGA format.", "******************************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [-v] IAGA2002_file > IAGA_file", " [-s YYYYMMDDHH] Time of the first record written into the IAGA", " file. If the IAGA2002 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 IAGA2002 file.", " [-e YYYYMMDDHH] Time of the record not written anymore into the", " IAGA file. If the IAGA2002 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 IAGA2002 file.", " [-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 no conversion is made", " Currently -c HDZ will have no effect.", " [-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.", " IAGA2002_file Name of IAGA2002-format file.", " IAGA_file Name of IAGA-format file.", }; /*--------------------------------------------------------------------------*/ /* Compute XYZ from HDZ and fill the appropriate data fields in the station */ /* structure. */ /* In IAGA2002 format unit of D is minutes of arc and H is in nT. */ /* After ChangeUnitsDOWN the units in Station structure are then */ /* H : 0.1 nT , D : 0.1 ArcMin. */ /* Computed X and Y should have units 0.1 nT. */ /*--------------------------------------------------------------------------*/ void Convert_HDZ_to_XYZ(StationPtr s) { long *XPtr,*YPtr; long i,count; double H,D; double coeff = 2.908882e-5; /* = Pi/(180*60*10) . Unit of D is 0.01*Arcmin */ /* Set the pointers. Note: IAGA2002.h reads H and D into s->X and s->Y */ XPtr = s->X; YPtr = s->Y; count = (s->EndTime - s->StartTime)/s->TimeStep; for (i=0;i 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 IAGA2002 format file into memory */ /*===================================================*/ status = ReadIAGA2002(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); /*=====================*/ /* Convert HDZ to XYZ */ /*=====================*/ s = NETWORK.StationList; if ((strncmp(CompStr,"XYZ",3) == 0) && (strncmp(s->Components,"HDZ",3) == 0)) { Convert_HDZ_to_XYZ(s); } /*==============================================*/ /* Write the data in IAGA format into stdout */ /*==============================================*/ WriteIAGA(NULL,&NETWORK,StartTimeStr,EndTimeStr,NULL); FreeNetwork(&NETWORK); return OK; }