/****************************************************************************/ /* */ /* WDC_to_IAGA.c */ /* */ /****************************************************************************/ /****************************************************************************/ /* This is a filter program that reads a WDC-format data file and writes */ /* out the same data in IAGA format. */ /* */ /* Usage: */ /* WDC_to_IAGA [-s] [-e | -h] [-o] [<] WDC_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. */ /* [-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. */ /* WDC_file Name of WDC-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.04 07.01.2020 */ /****************************************************************************/ /****************************************************************************/ /* Version history: */ /* 1.04 07.01.2020 Date strings must be YYYYMMDD (four digits for year) */ /* Replaced StrToSecs -> StrToSecsC and */ /* SecsToStr -> SecsToStrC. */ /* 1.03 09.09.1999 Fixed a Y2K bug in NewTime.h file which resulted in */ /* incorrect year in date strings if year >= 2000. */ /* 1.02 26.02.1996 Cosmetic change in handling the usage text. No apparent */ /* change in program behaviour. */ /* 1.01 5.1.1996 If WDC-file contained data for four components */ /* (e.g. F,X,Y,Z) program crashed. This was fixed by */ /* skipping all blocks which contain F component. So only */ /* three components are read. */ /* 1.0 13.11.1995 First release */ /****************************************************************************/ #include #include #include #include "Usage.h" #include "MagnData.h" #include "WDC.h" #include "IAGA.h" char *version = "1.04"; char *date = "07.01.2020"; #define HeaderLineCount 3 #define UsageLineCount 14 char *HeaderText[HeaderLineCount] = { "**************************************************************************", "This program converts magnetometer data from WDC format into IAGA format.", "**************************************************************************", }; char *UsageText[UsageLineCount] = { " [-s] [-e | -h] [-o] [<] WDC_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.", " [-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'.", " WDC_file Name of WDC-format file.", " IAGA_file Name of IAGA-format file.", }; /*--------------------------------------------------------------------------*/ /* Convert data from HDZ representation into XYZ representation. */ /* Here the unit of H is 0.1 nT and D is 0.1 arcmin. */ /*--------------------------------------------------------------------------*/ void Convert_HDZ_to_XYZ(StationPtr Station) { long *Xptr = Station->X; long *Yptr = Station->Y; long i,Count; long H,D; double coeff = 2.90888e-5; /* = Pi/(180*600) */ Count = (Station->EndTime - Station->StartTime)/(Station->TimeStep); for (i=0;iComponents,"XYZ"); } /*--------------------------------------------------------------------------*/ /* The main procedure */ /*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { long params; long status = 0; long FileCount = 0; long HourCount = 0; long XYZformat = 0; char FileName[100] = ""; char StartTimeStr[20] = ""; char EndTimeStr[20] = ""; char StationStr[200] = ""; char Components[10] = "XYZ"; Network_struct NETWORK; StationPtr s; long count; /*==========================*/ /* 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(Components,argv[++params]); break; case 'h' : HourCount = atol(argv[++params]); break; case 'o' : strcpy(StationStr,argv[++params]); break; case 'x' : XYZformat = 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 the data from a WDC format file into memory */ /*==================================================*/ status = ReadWDC(FileName,&NETWORK,StartTimeStr,EndTimeStr,StationStr); if (status != 0) { if (status == FileError) fprintf(stderr,"Error in reading WDC file\n"); if (status == OutOfMemory) fprintf(stderr,"Out of memory while reading WDC file\n"); return FAIL; } /*=======================================================*/ /* Mark the components as XYZ although they may be HDZ. */ /* This is an unofficial addition used by FMI internally */ /*=======================================================*/ if (XYZformat == 1) { s = NETWORK.StationList; while (s != NULL) { count = (s->EndTime - s->StartTime)/s->TimeStep; Multiply10(s->Y,count); strcpy(s->Components,"XYZ"); s = s->Next; } } /*=======================================================*/ /* Convert HDZ into XYZ if option -c is set to "XYZ". */ /*=======================================================*/ s = NETWORK.StationList; if ((strncmp(s->Components,"HDZ",3) == 0) && (strncmp(Components,"XYZ",3) == 0)) { Convert_HDZ_to_XYZ(s); } /*===========================================*/ /* Write the data in IAGA format into stdout */ /*===========================================*/ WriteIAGA(NULL,&NETWORK,NULL,NULL,NULL); FreeNetwork(&NETWORK); return OK; }