//--------------------------------------------------------------------------------------------- // // Program to automatically transfer phase readings and waveforms from a Seiscomp3 database // to a SEISAN database. // // written by Terje Utheim // Version 1.0 April 2015 // Version 1.15 1 May 2017 // //-------------------------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #define MAXCHA 2500 int printarg = 0; // = 1 gives debug printout int alldump = 1; // = 1 for debug. creates allevents.txt //----------------default values-------------------------------------------- int pretime_def = 1800; // default: seconds back in time //----------------top directories------------------------------------------- char *topdir_sc3 = 0; // top directory seiscomp3 char *topdir = 0; // top directory SEISAN char *topdir_sc2sei = 0; // top directory sc2seisan char *topdir_archive = 0; // top directory archives //----------------input from parameter file----------------------------------------- int preevent = 0; // seconds to record before trigger int postevent = 0; // seconds to record after de-trig int procdelay = 90; // seconds to sleep to finish processing of event float lat_min = 0.0; // minimum latitude float lat_max = 0.0; // maximum latitude float lon_min = 0.0; // minimum longitude float lon_max = 0.0; // maximum longitude float mag_min = 0.0; // minimum magnitude float mag_max = 0.0; // maximum magnitude char dbname[256]; // SEISAN database name int wavedbactive; // char trgdir[80] = ""; // directory for triggers char trgpath[200] = ""; // complete path for triggers //-----------------command line arguments------------------------------------------ char begin[100]; // time to begin search events char end[100]; // time to end search events int request_mode = 0; // switch to decide mode of operation int ret; // return value int nolines = 0; // number of lines in newids.txt1 int control = 0; // switch to check if username password given int arcseg = 0; // switch to decide to read from archives(1) or segments(0) int wavrec = 1; // switch record waveforms. Can be set to 0 in command argument int allcmp = 1; // extract all components specified in parameterfile int manauto = 0; // extract all int delreq = 0; // delayed request char syscmd1[256]; // system command char id[256]; // event id char hostid[200]; // host id for mysql database char sdbnam[200]; // database name char linjer[256]; // line from newids.txt //char idtab[100000][20]; // table containing event ids char cfgnamenew[200]; // name and path of new config-file (p-pases only) char namecfg[200]; // name and path of new config-file (p-phases only) char TRIGGER_TIMES[MAXCHA][200]; char trig_stations[MAXCHA][256]; // station name code (KONO) is extracted from STATION_NAMES char trig_components[MAXCHA][256]; // station component code (HHZ) is extracted from STATION_NAMES char mempar[MAXCHA][256]; // copy of configuration file float res[MAXCHA]; float dis[MAXCHA]; int azi[MAXCHA]; char phasetyp[MAXCHA][10]; char automan[MAXCHA][10]; float weight[MAXCHA]; char vekter[MAXCHA]; char polarization[MAXCHA][10]; char loca[MAXCHA][10]; float amplitudes[MAXCHA]; float period[MAXCHA]; char mag_stations[MAXCHA][20]; char mag_netw[MAXCHA][20]; char mag_cmp[MAXCHA][20]; char mag_typ[MAXCHA][20]; char mag_tim[MAXCHA][20]; float mag_dist[MAXCHA]; int mag_azi[MAXCHA]; char previous_lines[MAXCHA][300]; char tmagn[10][100]; char event_id[50]; int no_magnitudes; char lastids[500][40]; char username[200]; char password[200]; int pretime = 300; char ml[10]; char where[100]; int nostations=0; float rms=0; float magnitude; float dep; float time_unc; // time Err float lat_err; float lng_err; float dep_err; int dep_sw; int geoline=0; int no_lines_bul = 0; // number of lines in bulletin int id_request=0; int azgap; // Azimuthal Gap char earthmodel[100]; char EVENTS_S[200]; char sfilepath[200] = ""; // SEISAN S-file path char SFILETOPICK[256]; FILE *idsnew; // file handler FILE *cfgnew; // file handler FILE *allevt; // file handler static void TIMSEC(); static void DTE(); static void howto (void); static int params(int argcount, char **argvec); static void SECTIM(); static void CreateDirectory(); static int read_bul2(); static void Archives(); static void splitline(); static void create_filename(int ifyrn,int ifmon,int ifday,int ifhrn,int ifmin,float fsek,char dbname[],char FILNAVN[],int no_of_lines_cfg); static int Read_Config_to_MEM(); static void Create_Sfile(); static void format_time(); static int exists(); static void NOWTIME(); static int finn(); //------------------------------------------------------------------------------- // check if process active (seedlink) //------------------------------------------------------------------------------- pid_t proc_find(const char* name) { DIR* dir; struct dirent* ent; char* endptr; char buf[512]; if (!(dir = opendir("/proc"))) { perror("can't open /proc"); return -1; } while((ent = readdir(dir)) != NULL) { /* if endptr is not a null character, the directory is not * entirely numeric, so ignore it */ long lpid = strtol(ent->d_name, &endptr, 10); if (*endptr != '\0') { continue; } /* try to open the cmdline file */ snprintf(buf, sizeof(buf), "/proc/%ld/cmdline", lpid); FILE* fp = fopen(buf, "r"); if (fp) { if (fgets(buf, sizeof(buf), fp) != NULL) { /* check the first token in the file, the program name */ char* first = strtok(buf, " "); if (!strcmp(first, name)) { fclose(fp); closedir(dir); return (pid_t)lpid; } } fclose(fp); } } closedir(dir); return -1; } //----------------------------------------------------------------------------------------- // create waveform filename //----------------------------------------------------------------------------------------- void create_filename(int ifyrn,int ifmon,int ifday,int ifhrn,int ifmin,float fsek,char dbname[],char FILNAVN[],int no_of_lines_cfg) { int i; char tmp[10]; sprintf(tmp,"%3d",no_of_lines_cfg); sprintf(FILNAVN, "%4d-%2d-%2d-%2d%2d-%2d.DBASE%s",ifyrn,ifmon,ifday,ifhrn,ifmin,(int)fsek,tmp); for(i=0;i<35;i++) if(FILNAVN[i] == ' ') FILNAVN[i]='0'; FILNAVN[34]='\0'; FILNAVN[19] = dbname[0]; FILNAVN[20] = dbname[1]; FILNAVN[21] = dbname[2]; FILNAVN[22] = dbname[3]; FILNAVN[23] = dbname[4]; if(printarg == 1) printf("SC2SEI:.waveform filename....: %s\n",FILNAVN); } //----------------------------------------------------------------------------------- // create directory in SEISAN database or in //----------------------------------------------------------------------------------- void create_fullpath(char trgpath[],char dbname[],int ifyrn,int ifmon,char FILNAVN[],char PATHANDFIL[]) { int i; char CRTDIR[256]; if(wavedbactive == 1) { sprintf(PATHANDFIL,"%s/%s/%2d/%2d/%s",trgpath,dbname,ifyrn,ifmon,FILNAVN); for(i=0;i<256;i++) if(PATHANDFIL[i] == ' ') PATHANDFIL[i] = '0'; printf("SC2SEI:.fullpath and filename: %s\n",PATHANDFIL); sprintf(CRTDIR,"%s/%s/%2d/%2d",trgpath,dbname,ifyrn,ifmon); for(i=0;i<256;i++) if(CRTDIR[i] == ' ') CRTDIR[i] = '0'; printf("SC2SEI:.waveform directory...: %s\n",CRTDIR); CreateDirectory(CRTDIR); } if(wavedbactive == 0) { sprintf(PATHANDFIL,"%s/%s",trgpath,FILNAVN); printf("SC2SEI:.fullpath and filename: %s\n",PATHANDFIL); } } void Archives(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring FILE *scart; char fra[100]; // time from char *eof1; fra[0] = '\0'; // Ensure empty line if no input delivered fra[sizeof(fra)-1] = ~'\0'; // Ensure no false-null at end of buffer char til[100]; // time now char *eof2; til[0] = '\0'; // Ensure empty line if no input delivered til[sizeof(til)-1] = ~'\0'; // Ensure no false-null at end of buffer int evts,i,ix,j,l; int statindex; int found_index; char syscmd[256]; char stat[50]; char first[50]; char second[50]; char third[50]; float magnitude; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int no_of_new; int new; int newindx; int nomag; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int newsleep = 0; int registrer = 0; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; char dm[10]; char scartformat[200]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; //--------------------------------------------------------------------------- // get a list of event ids for timewindow: begin-end and store in newids.txt //--------------------------------------------------------------------------- sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,begin,0x22,0x22,end,0x22); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.txt.\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { nolines++; } rewind(idsnew); // fclose(idsnew); if(nolines > 0) // new event or new id ? { // printf("nolines: %d\n",nolines); no_of_new = nolines; while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number if(printarg == 1) printf("Extract ID: %s\n",id); //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(printarg == 1) printf("PLINE: %s",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 switch(manauto) { case 0: registrer = 0; // all printf("Record all events.\n"); break; case 1: registrer = 10; // auto only if(mode[0] == 'a') registrer++; printf("Record automatic processed events only.\n"); break; case 2: registrer = 20; // manual only if(mode[0] == 'm') registrer++; printf("Record manually processed events only.\n"); break; } printf("MODE: %s registrer: %2d\n",mode,registrer); if(registrer == 0 || registrer == 11 || registrer == 21) { dep = (float)depth; sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // subtract n seconds to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(printarg == 1) printf("loca: %s %x %x\n",loca[i],loca[i][0],loca[i][1]); if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time including postevent itmon = mon; // stop time including postevent itday = day; // stop time including postevent ithrn = hrn; // stop time including postevent itmin = min; // stop time including postevent gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(printarg == 1) printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { if(printarg == 1) printf("%12.2f - %12.2f = %12.3f\n",MSECSPST,MSECS_NOW,MSECSPST-MSECS_NOW); if(printarg == 1) printf("no_of_lines_cfg: %d\n",no_of_lines_cfg); if((scart = fopen("scartinput.txt","w")) == NULL) { printf("Can't read scartinput.txt.\n"); exit(0); } for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); if(loc[0] == '.' && loc[1] == '.') { sprintf(stasjon,"%s.%s..%s",nett,stas,cmp); }else{ sprintf(stasjon,"%s.%s.%s.%s",nett,stas,loc,cmp); } sprintf(scartformat,"%4d-%2d-%2d %2d:%2d;%4d-%2d-%2d %2d:%2d;%s\n",ifyrn,ifmon,ifday,ifhrn,ifmin,ityrn,itmon,itday,ithrn,itmin,stasjon); if(scartformat[5] == ' ') scartformat[5] = '0'; if(scartformat[8] == ' ') scartformat[8] = '0'; if(scartformat[11] == ' ') scartformat[11] = '0'; if(scartformat[14] == ' ') scartformat[14] = '0'; if(scartformat[22] == ' ') scartformat[22] = '0'; if(scartformat[25] == ' ') scartformat[25] = '0'; if(scartformat[28] == ' ') scartformat[28] = '0'; if(scartformat[31] == ' ') scartformat[31] = '0'; if(scartformat[36] == '_') scartformat[36] = '.'; if(printarg == 1) printf("%s",scartformat); fprintf(scart,"%s",scartformat); } fclose(scart); // sprintf(syscmd,"scart -dsvE -l scartinput.txt %s/var/lib/archive > %s\n",topdir_sc3,PATHANDFIL); if(wavrec == 1) { sprintf(syscmd,"scart -dsvE -l scartinput.txt %s > %s\n",topdir_archive,PATHANDFIL); if(printarg == 1) printf("%s\n",syscmd); ret = system(syscmd); } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } sprintf(lastids[newindx],"%s",id); newindx++; if(newindx >= 10) newindx=0; } } // for -> number_of_new_events fclose(idsnew); } // if nolines > 0 } //------------------------------------------------------------------------------------ // extract events and phases from sc3 from archives , run forever //------------------------------------------------------------------------------------ void Archives_Con(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring int found_index; FILE *scart; char fra[100]; // time from char *eof1; fra[0] = '\0'; // Ensure empty line if no input delivered fra[sizeof(fra)-1] = ~'\0'; // Ensure no false-null at end of buffer char til[100]; // time now char *eof2; til[0] = '\0'; // Ensure empty line if no input delivered til[sizeof(til)-1] = ~'\0'; // Ensure no false-null at end of buffer int evts,i,ix,j,l,kl; int statindex; char syscmd[256]; char stat[50]; char first[50]; char second[50]; char third[50]; char scartformat[200]; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int nomag; int no_of_new; int new; int newindx; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int newsleep = 0; int fini=0; int col; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; char dm[50]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; for(;;) { gettimeofday(&tv, NULL); // get current time and format into 'til' in scevtls format curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,til); // Current time curtime=curtime - pretime; // current time - pretime and format into 'fra' in scevtls format strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,fra); // Current time - pretime pretime = pretime_def; // set pretime back to default //--------------------------------------------------------------------------- // get a list of event ids for timewindow: fra-til and store in newids.txt //--------------------------------------------------------------------------- sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,fra,0x22,0x22,til,0x22); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.txt.\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // count number of lines in newids.txt file { nolines++; } rewind(idsnew); if(printarg == 1) printf("nolines: %d\n",nolines); if(nolines == 0) fclose(idsnew); if(nolines > 0) // new event or new id ? { no_of_new = nolines; while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number printf("ID: %s\n",id); new = 0; // check if id extracted before for(i=0;i<10;i++) { printf("compare: %s %s\n",id,lastids[i]); ret=strcmp(id,lastids[i]); if(ret == 0) { new = 1; // extracted before printf("%s extracted before\n",id); break; } } if(new == 0) // not extracted before { newsleep = procdelay; printf("Extract ID: %s after sleeping %d seconds\n",id,newsleep); sleep(newsleep); fini=0; for(kl=0;kl<3;kl++) { //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(no_magnitudes != 0) // magnitude finished ?? { fini++; if(printarg == 1) printf("PLINE: %s\n",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 dep = (float)depth; sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); if(printarg == 1) printf("MAGNITUDE: %3.1f LAT: %6.2f LNG: %6.2f DEPTH: %d\n",magnitude,latitude,longitude,depth); }else{ printf("no magnitude yet....wait..\n"); sleep(60); } if(fini==1) sleep(30); if(fini==2) break; } sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // subtract n seconds to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event if(allcmp == 0 || allcmp == 2) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time including postevent itmon = mon; // stop time including postevent itday = day; // stop time including postevent ithrn = hrn; // stop time including postevent itmin = min; // stop time including postevent gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(printarg == 1) printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { if(printarg == 1) printf("%12.2f - %12.2f = %12.3f\n",MSECSPST,MSECS_NOW,MSECSPST-MSECS_NOW); if((MSECSPST - MSECS_NOW) > 0.0) // check if end-time(with postevent) is greater than current time....then sleep { sleep((int)(MSECSPST - MSECS_NOW)); newsleep=postevent; } if((scart = fopen("scartinput.txt","w")) == NULL) { printf("Can't read scartinput.txt.\n"); exit(0); } for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); if(loc[0] == '.' && loc[1] == '.') { sprintf(stasjon,"%s.%s..%s",nett,stas,cmp); }else{ sprintf(stasjon,"%s.%s.%s.%s",nett,stas,loc,cmp); } sprintf(scartformat,"%4d-%2d-%2d %2d:%2d;%4d-%2d-%2d %2d:%2d;%s\n",ifyrn,ifmon,ifday,ifhrn,ifmin,ityrn,itmon,itday,ithrn,itmin,stasjon); if(scartformat[5] == ' ') scartformat[5] = '0'; if(scartformat[8] == ' ') scartformat[8] = '0'; if(scartformat[11] == ' ') scartformat[11] = '0'; if(scartformat[14] == ' ') scartformat[14] = '0'; if(scartformat[22] == ' ') scartformat[22] = '0'; if(scartformat[25] == ' ') scartformat[25] = '0'; if(scartformat[28] == ' ') scartformat[28] = '0'; if(scartformat[31] == ' ') scartformat[31] = '0'; if(scartformat[36] == '_') scartformat[36] = '.'; if(printarg == 1) printf("%s",scartformat); fprintf(scart,"%s",scartformat); } fclose(scart); //wavrec=1; if(wavrec == 1) { sprintf(syscmd,"scart -dsvE -l scartinput.txt %s > %s\n",topdir_archive,PATHANDFIL); if(printarg == 1) printf("%s\n",syscmd); ret = system(syscmd); } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } sprintf(lastids[newindx],"%s",id); newindx++; if(newindx >= 10) newindx=0; for(i=0;i<10;i++) printf("%2d %s\n",i,lastids[i]); } } // for -> number_of_new_events fclose(idsnew); } // if nolines > 0 sleep(60); } // ;; } //------------------------------------------------------------------------------------ // extract events and phases from sc3 database , run forever //------------------------------------------------------------------------------------ void Continous(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring int found_index; char fra[100]; // time from char *eof1; fra[0] = '\0'; // Ensure empty line if no input delivered fra[sizeof(fra)-1] = ~'\0'; // Ensure no false-null at end of buffer char til[100]; // time now char *eof2; til[0] = '\0'; // Ensure empty line if no input delivered til[sizeof(til)-1] = ~'\0'; // Ensure no false-null at end of buffer int evts,i,ix,j,l,kl; int statindex; char syscmd[256]; char stat[50]; char first[50]; char second[50]; char third[50]; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int nomag; int no_of_new; int new; int newindx; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int newsleep = 0; int fini=0; int col; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; char dm[50]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; for(;;) { gettimeofday(&tv, NULL); // get current time and format into 'til' in scevtls format curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,til); // Current time curtime=curtime - pretime; // current time - pretime and format into 'fra' in scevtls format strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,fra); // Current time - pretime pretime = pretime_def; // set pretime back to default //--------------------------------------------------------------------------- // get a list of event ids for timewindow: fra-til and store in newids.txt //--------------------------------------------------------------------------- sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,fra,0x22,0x22,til,0x22); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.txt.\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // count number of lines in newids.txt file { nolines++; } rewind(idsnew); if(printarg == 1) printf("nolines: %d\n",nolines); if(nolines == 0) fclose(idsnew); if(nolines > 0) // new event or new id ? { no_of_new = nolines; while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number printf("ID: %s\n",id); new = 0; // check if id extracted before for(i=0;i<10;i++) { printf("compare: %s %s\n",id,lastids[i]); ret=strcmp(id,lastids[i]); if(ret == 0) { new = 1; // extracted before printf("%s extracted before\n",id); break; } } if(new == 0) // not extracted before { newsleep = procdelay; printf("Extract ID: %s after sleeping %d seconds\n",id,newsleep); sleep(newsleep); fini=0; for(kl=0;kl<3;kl++) { //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(no_magnitudes != 0) // magnitude finished ?? { fini++; if(printarg == 1) printf("PLINE: %s\n",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 dep = (float)depth; sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); if(printarg == 1) printf("MAGNITUDE: %3.1f LAT: %6.2f LNG: %6.2f DEPTH: %d\n",magnitude,latitude,longitude,depth); }else{ printf("no magnitude yet....wait..\n"); sleep(60); } if(fini==1) sleep(30); if(fini==2) break; } sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // subtract n seconds to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0 || allcmp == 2) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time including postevent itmon = mon; // stop time including postevent itday = day; // stop time including postevent ithrn = hrn; // stop time including postevent itmin = min; // stop time including postevent gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { if(printarg == 1) printf("%12.2f - %12.2f = %12.3f\n",MSECSPST,MSECS_NOW,MSECSPST-MSECS_NOW); if((MSECSPST - MSECS_NOW) > 0.0) // check if end-time(with postevent) is greater than current time....then sleep { sleep((int)(MSECSPST - MSECS_NOW)); newsleep=postevent; } for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); // printf("%s %s %s %s\n",nett,stas,loc,cmp); sprintf(stasjon,"%s_%s:%s",nett,stas,cmp); if(wavrec == 1) { sprintf(syscmd,"%s/bin/getwindow -S %c%s.D%c -tw %d,%d,%d,%d,%d,%d:%d,%d,%d,%d,%d,%d -nt 1 -o %s %s",topdir_sc2sei,0x22,stasjon,0x22,ifyrn,ifmon,ifday,ifhrn,ifmin,(int)fsek,ityrn,itmon,itday,ithrn,itmin,(int)tsek,PATHANDFIL,ipserv); if(allcmp == 2) { col = finn(syscmd); if(printarg == 1) printf("place: %d\n",col); syscmd[col-1]='?'; if(printarg == 1) printf("%s\n",syscmd); } if(printarg == 1) printf("%s\n",syscmd); ret = system(syscmd); } } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } sprintf(lastids[newindx],"%s",id); newindx++; if(newindx >= 10) newindx=0; for(i=0;i<10;i++) printf("%2d %s\n",i,lastids[i]); } } // for -> number_of_new_events fclose(idsnew); } // if nolines > 0 sleep(60); } // ;; } //------------------------------------------------------------------------------------- // extract events and phases from sc3 database from within time window and exit when finished //-------------------------------------------------------------------------------------- void Request(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring int found_index; int evts,i,ix,j,l; int statindex; char syscmd[256]; char dm[50]; char stat[50]; char first[50]; char second[50]; char third[50]; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int nomag; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int registrer = 0; int col; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char CRTDIR[256]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; printf("REQUEST\n"); //--------------------------------------------------------------------------- // get a list of event ids for timewindow: fra-til and store in newids.txt //--------------------------------------------------------------------------- begin[10]=' '; end[10]=' '; sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,begin,0x22,0x22,end,0x22); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.tx inside loop (1).\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number if(printarg ==1) printf("%s\n",id); //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(printarg == 1) printf("PLINE: %s\n",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 // 1.15 switch(manauto) { case 0: registrer = 0; // all printf("Record all events.\n"); break; case 1: registrer = 10; // auto only if(mode[0] == 'a') registrer++; printf("Record automatic processed events only.\n"); break; case 2: registrer = 20; // manual only if(mode[0] == 'm') registrer++; printf("Record manually processed events only.\n"); break; } printf("MODE: %s registrer: %2d\n",mode,registrer); if(registrer == 0 || registrer == 11 || registrer == 21) { dep = (float)depth; if(printarg == 1) printf("MAGNITUDE: %3.1f LAT: %6.2f LNG: %6.2f DEPTH: %d\n",magnitude,latitude,longitude,depth); sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // add n minutes to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); printf("FILNAVN: %s\n",FILNAVN); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0 || allcmp == 2) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time itmon = mon; // stop time itday = day; // stop time ithrn = hrn; // stop time itmin = min; // stop time gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(printarg == 1) printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); sprintf(stasjon,"%s_%s:%s",nett,stas,cmp); if(wavrec == 1) { sprintf(syscmd,"%s/bin/getwindow -S %c%s.D%c -tw %d,%d,%d,%d,%d,%d:%d,%d,%d,%d,%d,%d -nt 1 -o %s %s",topdir_sc2sei,0x22,stasjon,0x22,ifyrn,ifmon,ifday,ifhrn,ifmin,(int)fsek,ityrn,itmon,itday,ithrn,itmin,(int)tsek,PATHANDFIL,ipserv); if(allcmp == 2) { col = finn(syscmd); if(printarg == 1) printf("place: %d\n",col); syscmd[col-1]='?'; if(printarg == 1) printf("%s\n",syscmd); } //exit(0); ret = system(syscmd); } } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } } // registrer or not } // nolines fclose(idsnew); exit(0); } //------------------------------------------------------------------------------------ // extract events and phases from sc3 database , run forever //------------------------------------------------------------------------------------ void Delayed_Continous(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring int found_index; FILE *ids; char fra[100]; // time from char *eof1; fra[0] = '\0'; // Ensure empty line if no input delivered fra[sizeof(fra)-1] = ~'\0'; // Ensure no false-null at end of buffer char til[100]; // time now char *eof2; til[0] = '\0'; // Ensure empty line if no input delivered til[sizeof(til)-1] = ~'\0'; // Ensure no false-null at end of buffer int evts,i,ix,j,l,kl; int statindex; char syscmd[256]; char stat[50]; char first[50]; char second[50]; char third[50]; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int nomag; int no_of_new; int new; int newindx; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int newsleep = 0; int fini=0; int col; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char ids_status[100]; char FILNAVN[1024]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; char dm[50]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; int statu=0; int copied=0; // for(i=0;i<10;i++) // sprintf(lastids[i],%s ,%d %d\n",statu,copied); for(;;) { gettimeofday(&tv, NULL); // get current time and format into 'til' in scevtls format curtime=tv.tv_sec; curtime = curtime - 1800; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,til); // Current time curtime=curtime - 1800; // current time - pretime and format into 'fra' in scevtls format curtime=curtime-pretime; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); format_time(buffer,fra); // Current time - pretime // pretime = pretime_def; // set pretime back to default printf("fra: %s - til: %s\n",fra,til); //--------------------------------------------------------------------------- // get a list of event ids for timewindow: fra-til and store in newids.txt //--------------------------------------------------------------------------- sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,fra,0x22,0x22,til,0x22); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.txt.\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // count number of lines in newids.txt file { nolines++; } rewind(idsnew); // if(printarg == 1) printf("nolines: %d\n",nolines); if(nolines == 0) fclose(idsnew); if(nolines > 0) // new event or new id ? { no_of_new = nolines; int teller = 0; while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number // printf("ID: %s\n",id); sprintf(lastids[teller],"%s %d %d",id,statu,copied); printf("%2d %s %2d %2d\n",teller,lastids[teller],statu,copied); //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); // if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); printf("MODE: %s\n",mode); ret=strcmp(mode,"manual"); if(ret == 0) { dep = (float)depth; sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); // if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); // if(printarg == 1) printf("MAGNITUDE: %3.1f LAT: %6.2f LNG: %6.2f DEPTH: %d\n",magnitude,latitude,longitude,depth); sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // subtract n seconds to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0 || allcmp == 2) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time including postevent itmon = mon; // stop time including postevent itday = day; // stop time including postevent ithrn = hrn; // stop time including postevent itmin = min; // stop time including postevent gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { if(printarg == 1) printf("%12.2f - %12.2f = %12.3f\n",MSECSPST,MSECS_NOW,MSECSPST-MSECS_NOW); if((MSECSPST - MSECS_NOW) > 0.0) // check if end-time(with postevent) is greater than current time....then sleep { sleep((int)(MSECSPST - MSECS_NOW)); newsleep=postevent; } for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); // printf("%s %s %s %s\n",nett,stas,loc,cmp); sprintf(stasjon,"%s_%s:%s",nett,stas,cmp); if(wavrec == 1) { sprintf(syscmd,"%s/bin/getwindow -S %c%s.D%c -tw %d,%d,%d,%d,%d,%d:%d,%d,%d,%d,%d,%d -nt 1 -o %s %s",topdir_sc2sei,0x22,stasjon,0x22,ifyrn,ifmon,ifday,ifhrn,ifmin,(int)fsek,ityrn,itmon,itday,ithrn,itmin,(int)tsek,PATHANDFIL,ipserv); if(allcmp == 2) { col = finn(syscmd); if(printarg == 1) printf("place: %d\n",col); syscmd[col-1]='?'; if(printarg == 1) printf("%s\n",syscmd); } if(printarg == 1) printf("%s\n",syscmd); ret = system(syscmd); } } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } sprintf(lastids[newindx],"%s",id); newindx++; if(newindx >= 10) newindx=0; for(i=0;i<10;i++) printf("%2d %s\n",i,lastids[i]); } // for -> number_of_new_events // fclose(idsnew); // exit(0); teller++; } } // if nolines > 0 sleep(60); } // ;; } //------------------------------------------------------------------------------------- // extract events and phases from sc3 database from within delayed time window and exit when finished //-------------------------------------------------------------------------------------- void Delayed_Request(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring int found_index; int evts,i,ix,j,l; int statindex; char syscmd[256]; char dm[50]; char stat[50]; char first[50]; char second[50]; char third[50]; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ifsec; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int nomag; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int registrer = 0; int col; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char CRTDIR[256]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; double MSECS_START; double MSECS_END; printf("Delayed_Request\n"); gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); MSECS_START = MSECS_NOW - 3600.0; MSECS_END = MSECS_START + 1800.0; SECTIM(MSECS_START,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time ifmon = mon; // start time ifday = day; // start time ifhrn = hrn; // start time ifmin = min; // start time ifsec = (int)fsek; printf("%4d %2d %2d %2d %2d %2d\n",ifyrn,ifmon,ifday,ifhrn,ifmin,ifsec); sprintf(begin,"%4d-%2d-%2d %2d:%2d:%2d",ifyrn,ifmon,ifday,ifhrn,ifmin,ifsec); if(begin[5] == ' ')begin[5]='0'; if(begin[8] == ' ')begin[8]='0'; if(begin[11]== ' ')begin[11]='0'; if(begin[14]== ' ')begin[14]='0'; if(begin[17]== ' ')begin[17]='0'; printf("%s\n",begin); SECTIM(MSECS_END,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time ifmon = mon; // start time ifday = day; // start time ifhrn = hrn; // start time ifmin = min; // start time ifsec = (int)fsek; printf("%4d %2d %2d %2d %2d %2d\n",ifyrn,ifmon,ifday,ifhrn,ifmin,ifsec); sprintf(end,"%4d-%2d-%2d %2d:%2d:%2d",ifyrn,ifmon,ifday,ifhrn,ifmin,ifsec); if(end[5] == ' ')end[5]='0'; if(end[8] == ' ')end[8]='0'; if(end[11]== ' ')end[11]='0'; if(end[14]== ' ')end[14]='0'; if(end[17]== ' ')end[17]='0'; printf("%s %s\n",begin,end); // exit(0); //--------------------------------------------------------------------------- // get a list of event ids for timewindow: fra-til and store in newids.txt //--------------------------------------------------------------------------- // sprintf(begin,"2016-10-19 10:10:10"); // sprintf(end,"2017-08-20 23:20:10"); begin[10]=' '; end[10]=' '; sprintf(syscmd,"%s/bin/scevtls -d mysql://%s:%s@%s/%s --begin %c%s%c --end %c%s%c > newids.txt",topdir_sc3,username,password,hostid,sdbnam,0x22,begin,0x22,0x22,end,0x22); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); if((idsnew = fopen("newids.txt","r")) == NULL) { printf("Can't read newids.tx inside loop (1).\n"); exit(0); } nolines=0; // set line counter to 0 while ( fgets ( linjer, sizeof linjer, idsnew ) != NULL ) // read a line from file { sscanf(linjer,"%s",id); // read event id-number if(printarg ==1) printf("%s\n",id); //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(printarg == 1) printf("PLINE: %s\n",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 /* switch(manauto) { case 0: registrer = 0; // all break; case 1: registrer = 10; // auto only if(mode[0] == 'a') registrer++; break; case 2: registrer = 20; // manual only if(mode[0] == 'm') registrer++; break; } */ manauto = 2; registrer = 0; if(manauto == 0) registrer = 1; if(manauto == 1 && mode[0] == 'a') registrer = 1; if(manauto == 2 && mode[0] == 'm') registrer = 1; // printf("MODE: %s registrer: %2d\n",mode,registrer); if(registrer == 1) // if(registrer == 0 || registrer == 11 || registrer == 21) { dep = (float)depth; if(printarg == 1) printf("MAGNITUDE: %3.1f LAT: %6.2f LNG: %6.2f DEPTH: %d\n",magnitude,latitude,longitude,depth); sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // add n minutes to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); printf("FILNAVN: %s\n",FILNAVN); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0 || allcmp == 2) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time itmon = mon; // stop time itday = day; // stop time ithrn = hrn; // stop time itmin = min; // stop time gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(printarg == 1) printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); sprintf(stasjon,"%s_%s:%s",nett,stas,cmp); if(wavrec == 1) { sprintf(syscmd,"%s/bin/getwindow -S %c%s.D%c -tw %d,%d,%d,%d,%d,%d:%d,%d,%d,%d,%d,%d -nt 1 -o %s %s",topdir_sc2sei,0x22,stasjon,0x22,ifyrn,ifmon,ifday,ifhrn,ifmin,(int)fsek,ityrn,itmon,itday,ithrn,itmin,(int)tsek,PATHANDFIL,ipserv); if(allcmp == 2) { col = finn(syscmd); if(printarg == 1) printf("place: %d\n",col); syscmd[col-1]='?'; if(printarg == 1) printf("%s\n",syscmd); } //exit(0); ret = system(syscmd); } } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } } } // nolines fclose(idsnew); exit(0); } int finn(char commando[]) { int place=8; int k; for(k=0;k<250;k++) { if(commando[k] == '.' && commando[k+1] == 'D' && commando[k+2] == 0x22) { place=k; break; } } return(place); } //------------------------------------------------------------------------------------- // extract event and phases from sc3 database from archive specified by event ID //-------------------------------------------------------------------------------------- void Archive_ID(char PATHANDFIL[],char pline[],char MINTRGTID[],int no_of_lines_cfg) { struct timeval tv; time_t curtime; char buffer[30]; // format timestring FILE *scart; char fra[100]; // time from char *eof1; fra[0] = '\0'; // Ensure empty line if no input delivered fra[sizeof(fra)-1] = ~'\0'; // Ensure no false-null at end of buffer char til[100]; // time now char *eof2; til[0] = '\0'; // Ensure empty line if no input delivered til[sizeof(til)-1] = ~'\0'; // Ensure no false-null at end of buffer int evts,i,ix,j,l; int statindex; int found_index; char syscmd[256]; char stat[50]; char first[50]; char second[50]; char third[50]; float magnitude; int ifyrn; int ifmon; int ifday; int ifhrn; int ifmin; int ityrn; int itdoy; int itmon; int itday; int ithrn; int itmin; int iyrn_now; int imon_now; int iday_now; int ihrn_now; int imin_now; int idoy_now; int ifsec_now; int nophases; int no_of_new; int new; int newindx; int nomag; int depth; int varighet[MAXCHA]; int cnt; int phindex; int mgindex; int newsleep = 0; float fsek; float fsec_now; float latitude; float longitude; float tsek; long yrn; long mon; long day; long hrn; long min; long doy; long yrn_now; long mon_now; long day_now; long hrn_now; long min_now; long doy_now; char FILNAVN[1024]; char ipserv[256]; char dat[MAXCHA][256]; char net[MAXCHA][256]; char estac[20]; char nett[10]; char stas[10]; char loc[10]; char cmp[10]; char stasjon[20]; char mode[20]; char dm[10]; char scartformat[200]; double MSECSTRG; double MSECSPST; double MSECSPRE; double MSECS_NOW; //---------------------------------------------------------------------------------- // Get bulletin for last new id, and store in event.txt //---------------------------------------------------------------------------------- sprintf(syscmd,"python %s/bin/mybulletin.py -d mysql://%s:%s@%s/%s -E %s -3 -p -q > event.txt",topdir_sc2sei,username,password,hostid,sdbnam,event_id); if(printarg == 1) printf("%s\n",syscmd); ret=system(syscmd); //----------------------------------------------------------------------------------- // Read bulletin last id (event.txt) and search time and location information //----------------------------------------------------------------------------------- statindex=read_bul2(pline); if(printarg == 1) printf("PLINE: %s",pline); splitline(pline,&magnitude,&ifyrn,&ifmon,&ifday,&ifhrn,&ifmin,&fsek,&latitude,&longitude,&depth,mode); // extract information about event from scbulletin sc3 dep = (float)depth; sprintf(MINTRGTID,"%02d/%02d/%4d %02d:%02d:%4.1f",ifday,ifmon,ifyrn,ifhrn,ifmin,fsek); if(printarg == 1) printf("MINTRGTID: %s\n",MINTRGTID); sprintf(ml,"%3.1f",magnitude); yrn=ifyrn; // start time mon=ifmon; // start time day=ifday; // start time hrn=ifhrn; // start time min=ifmin; // start time TIMSEC(yrn,mon,day,hrn,min,fsek,&MSECSTRG); MSECSPRE = MSECSTRG - preevent; // subtract n seconds to get pre event data SECTIM(MSECSPRE,&yrn,&doy,&mon,&day,&hrn,&min,&fsek); ifyrn = yrn; // start time including pre event ifmon = mon; // start time including pre event ifday = day; // start time including pre event ifhrn = hrn; // start time including pre event ifmin = min; // start time including pre event create_filename(ifyrn,ifmon,ifday,ifhrn,ifmin,fsek,dbname,FILNAVN,no_of_lines_cfg); create_fullpath(trgpath,dbname,ifyrn,ifmon,FILNAVN,PATHANDFIL); sprintf(sfilepath,"%s",PATHANDFIL); sprintf(ipserv,"localhost"); // server sprintf(ipserv,"%s",hostid); //----------------------------------------------------------------------------- // Find line in bulletin with Phase arrivals: //----------------------------------------------------------------------------- sprintf(stat,"arrivals:"); // Search for line with "arrivals:" as 3rd word in line sprintf(third,"dummy"); for(i=0;i 100.00) res[i] = 99.99; if(loca[i][0]== 0x0 && loca[i][1]== 0x0) sprintf(loca[i],".."); dis[i]=dis[i] * 111.2; if(weight[i] == 1.0) vekter[0] = ' '; if(weight[i] == 0.0) vekter[0] = '4'; fprintf(cfgnew,"%s %s %s %s\n",net[i],trig_stations[i],loca[i],trig_components[i]); } fclose(cfgnew); if(allcmp == 0) // check if only components with phases are to be recorded { sprintf(namecfg,"cfgnew.cfg"); no_of_lines_cfg = Read_Config_to_MEM(namecfg); if(printarg == 1) printf("NO_OF_LINES_CFG %d\n",no_of_lines_cfg); } //----------------------------------------------------------------------------- // Find second line in bulletin with Station magnitudes: //----------------------------------------------------------------------------- sprintf(stat,"magnitudes:"); // Search for line with "magnitudes:" as 3rd word in line sprintf(third,"dummy"); cnt=0; for(i=0;i 2800, 481-> 2080 }else{ amplitudes[i]=amplitudes[i] *1.0; } } //********************************************************************************** // add postevent time to be extracted from seiscomp archives //********************************************************************************** MSECSPST = MSECSTRG + postevent; // add n minutes to get post event data SECTIM(MSECSPST,&yrn,&doy,&mon,&day,&hrn,&min,&tsek); ityrn = yrn; // stop time including postevent itmon = mon; // stop time including postevent itday = day; // stop time including postevent ithrn = hrn; // stop time including postevent itmin = min; // stop time including postevent gettimeofday(&tv, NULL); // get current time curtime=tv.tv_sec; strftime(buffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(printarg == 1) printf("buffer: %s\n",buffer); sscanf(buffer,"%2d%1c%2d%1c%4d%2c%2d%1c%2d%1c%2d",&imon_now,dm,&iday_now,dm,&iyrn_now,dm,&ihrn_now,dm,&imin_now,dm,&ifsec_now); yrn_now = iyrn_now; mon_now = imon_now; day_now = iday_now; hrn_now = ihrn_now; min_now = imin_now; fsec_now= ifsec_now; TIMSEC(yrn_now,mon_now,day_now,hrn_now,min_now,fsec_now,&MSECS_NOW); if(magnitude >= mag_min && magnitude < mag_max) { if(latitude >= lat_min && latitude <= lat_max && longitude >= lon_min && longitude <= lon_max) { if(printarg == 1) printf("%12.2f - %12.2f = %12.3f\n",MSECSPST,MSECS_NOW,MSECSPST-MSECS_NOW); if(printarg == 1) printf("no_of_lines_cfg: %d\n",no_of_lines_cfg); if((scart = fopen("scartinput.txt","w")) == NULL) { printf("Can't read scartinput.txt.\n"); exit(0); } for(l=0;l<(no_of_lines_cfg-2);l++) { sscanf(mempar[l+2],"%s %s %s %s",nett,stas,loc,cmp); if(loc[0] == '.' && loc[1] == '.') { sprintf(stasjon,"%s.%s..%s",nett,stas,cmp); }else{ sprintf(stasjon,"%s.%s.%s.%s",nett,stas,loc,cmp); } sprintf(scartformat,"%4d-%2d-%2d %2d:%2d;%4d-%2d-%2d %2d:%2d;%s\n",ifyrn,ifmon,ifday,ifhrn,ifmin,ityrn,itmon,itday,ithrn,itmin,stasjon); if(scartformat[5] == ' ') scartformat[5] = '0'; if(scartformat[8] == ' ') scartformat[8] = '0'; if(scartformat[11] == ' ') scartformat[11] = '0'; if(scartformat[14] == ' ') scartformat[14] = '0'; if(scartformat[22] == ' ') scartformat[22] = '0'; if(scartformat[25] == ' ') scartformat[25] = '0'; if(scartformat[28] == ' ') scartformat[28] = '0'; if(scartformat[31] == ' ') scartformat[31] = '0'; if(scartformat[36] == '_') scartformat[36] = '.'; if(printarg == 1) printf("%s",scartformat); fprintf(scart,"%s",scartformat); } fclose(scart); if(wavrec == 1) { sprintf(syscmd,"scart -dsvE -l scartinput.txt %s > %s\n",topdir_archive,PATHANDFIL); if(printarg == 1) printf("%s\n",syscmd); ret = system(syscmd); } if(printarg == 1) printf("Number of lines: %d\n",nolines); if(printarg == 1) printf("SC2SEI:..........................MINTRGTID: %s\n",MINTRGTID); Create_Sfile(MINTRGTID,FILNAVN,nophases,nomag,phindex,mgindex,varighet,latitude,longitude); }else{ printf("Outside defined area.\n"); } }else{ printf("Magnitude not in defined window.\n"); } sprintf(lastids[newindx],"%s",id); newindx++; if(newindx >= 10) newindx=0; // for -> number_of_new_events // if nolines > 0 } void format_time(char buffer[],char tiden[]) { tiden[0]=buffer[6]; tiden[1]=buffer[7]; tiden[2]=buffer[8]; tiden[3]=buffer[9]; tiden[4]='-'; tiden[5]=buffer[0]; tiden[6]=buffer[1]; tiden[7]='-'; tiden[8]=buffer[3]; tiden[9]=buffer[4]; tiden[10]=' '; tiden[11]=buffer[12]; tiden[12]=buffer[13]; tiden[13]=':'; tiden[14]=buffer[15]; tiden[15]=buffer[16]; tiden[16]=':'; tiden[17]=buffer[18]; tiden[18]=buffer[19]; tiden[19]='\0'; } //-------------------------------------------------------------------------------------------- // Line returned from scbulletin sc3 with input event id. // Date, time, latitude and longitude extracted from line //-------------------------------------------------------------------------------------------- void splitline(char pline[],float *magnitude,int *ifyrn,int *ifmon,int *ifday,int *ifhrn,int *ifmin,float *fsek,float *latitude,float *longitude,int *depth,char mmode[]) { char mag[100]; char dato[20]; char tid[20]; float lat; char ns[10]; float lng; char ew[10]; char tmp[20]; int ival; float val; char dp[10]; sscanf(pline,"%s %s %s %f %s %f %s %s %s",mag,dato,tid,&lat,ns,&lng,ew,dp,mmode); tmp[0] = mag[2]; tmp[1] = mag[3]; tmp[2] = mag[4]; tmp[3] = '\0'; sscanf(mag,"%f",&val); (*magnitude) = val; tmp[0] = dato[0]; tmp[1] = dato[1]; tmp[2] = dato[2]; tmp[3] = dato[3]; tmp[4] = '\0'; sscanf(tmp,"%d",&ival); (*ifyrn) = ival; tmp[0] = dato[5]; tmp[1] = dato[6]; tmp[2] = '\0'; sscanf(tmp,"%d",&ival); (*ifmon) = ival; tmp[0] = dato[8]; tmp[1] = dato[9]; tmp[2] = '\0'; sscanf(tmp,"%d",&ival); (*ifday) = ival; tmp[0] = tid[0]; tmp[1] = tid[1]; tmp[2] = '\0'; sscanf(tmp,"%d",&ival); (*ifhrn) = ival; tmp[0] = tid[3]; tmp[1] = tid[4]; tmp[2] = '\0'; sscanf(tmp,"%d",&ival); (*ifmin) = ival; tmp[0] = tid[6]; tmp[1] = tid[7]; tmp[2] = tid[8]; tmp[3] = tid[9]; tmp[4] = '\0'; sscanf(tmp,"%f",&val); (*fsek) = val; (*latitude) = lat; (*longitude)= lng; sscanf(dp,"%d",&ival); (*depth) = ival; } void SECTIM (MSECS,YR,DOY,MTH,DAY,HR,MIN,SEC) double MSECS; int *YR; int *DOY; int *MTH; int *DAY; int *HR; int *MIN; float *SEC; { int DDAY,MMTH; // -- Temporary seconds double SSEC; // -- Seconds per day double SECDAY; // -- Seconds per year double SECYR; // -- Leap-year indicators float IND, SIN; // -- Counter int I; SECDAY=86400.0; SECYR =31536000.0; //*------------------------------------------------------------------------- //* Find year: //* SSEC = 0.0; for(I=1;I<201;I++) { IND = 0.0; // -- Leap year if ((I%4) == 0) IND = 1.0; // -- Add years SSEC = SSEC + SECYR + IND*SECDAY; // -- Year found if (SSEC > MSECS) goto found; SIN = IND; } found: *YR = I - 1; //* //* Find day-of-year and date: //* //c-- Reset remaining seconds SSEC = MSECS - (SSEC - SECYR - IND*SECDAY); for(I=1;I<367;I++) { SSEC = SSEC - SECDAY; if (SSEC < 0) goto incr; } incr: I = I - 1; // -- 366 days of year if (SIN > 0.0) I = I + 1; // -- if (I == 0) { // -- Justifying if change *YR = *YR - 1; // -- of year I = 365; if ((*YR%4) == 0) I = 366; } *DOY = I; //-- convert from doy to date DTE (I,&DDAY,&MMTH,*YR); *DAY=DDAY; *MTH=MMTH; if(*YR >= 100) *YR=*YR-100; /* test for year 2000 or more */ //* //* Find hour: //* SSEC = SSEC + SECDAY; for(I=1;I<25;I++) { SSEC = SSEC - 60.0*60.0; if (SSEC < 0) goto seks; } seks: *HR = I - 1; //* //* Find minutes and remaining seconds: //* SSEC = SSEC + 60.0*60.0; for(I=1;I<61;I++) { SSEC = SSEC - 60.0; if (SSEC < 0) goto otte; } otte: *MIN = I - 1; *SEC = SSEC + 60.0; if(*YR < 50) { *YR=*YR+2000; }else{ *YR=*YR+1900; } } void NOWTIME(nyrn,nmon,nday,nhrn,nmin,nsek) int *nyrn; int *nmon; int *nday; int *nhrn; int *nmin; int *nsek; { char dummy[256]; int iyrn; int imon; int iday; int ihrn; int imin; int isec; int i,j; int BUFSECS; float sek; char dum[50]; time_t now = time(NULL); struct tm *now_s = localtime(&now); sprintf(dummy,"%d-%02d-%02d_%02d:%02d:%02d", 1900+now_s->tm_year, ++now_s ->tm_mon,now_s->tm_mday, now_s->tm_hour, now_s->tm_min,now_s->tm_sec); sscanf(dummy,"%4d%1c%2d%1c%2d%1c%2d%1c%2d%1c%2d",&iyrn,dum,&imon,dum,&iday,dum,&ihrn,dum,&imin,dum,&isec); iyrn=iyrn-2000; *nyrn=iyrn; *nmon=imon; *nday=iday; *nhrn=ihrn; *nmin=imin; *nmon=imon; *nsek=isec; } int S_REC(year,month,day,hour,minute,seconds,dummy,fullpath,filename,nchannels,nomag,phindex,mgindex,trgdur,idsfile,latitude,longitude) char year[]; char month[]; char day[]; char hour[]; char minute[]; char seconds[]; char dummy[]; char fullpath[]; char filename[]; int nchannels; int nomag; int phindex; int mgindex; int trgdur[]; char idsfile[]; float latitude; float longitude; { FILE *sf; char buf[256]; char buf2[256]; char comp[200]; char dm1[200]; char dm2[200]; char phstation[20]; char mgstation[20]; char mags[30]; char mags2[30]; char tt[10]; char mm[10]; int hr1; int mn1; int sc1; int ms1; int skip; int i,j,k; int ch; int cnt; int YR,MTH,DAY,HR,MIN; float SEC; int AR; char magtype[20]; char typem[20]; char msta[20]; int skriv; int cyr; int cmon; int cday; int chrn; int cmin; int cisec; int mtel; int bryter; //printf("SECONDS: %s\n",seconds); sscanf(year,"%d",&YR); //printf("%s %d\n",year,YR); sscanf(month,"%d",&MTH); //printf("%s %d\n",month,MTH); sscanf(day,"%d",&DAY); //printf("%s %d\n",day,DAY); sscanf(hour,"%d",&HR); //printf("%s %d\n",hour,HR); sscanf(minute,"%d",&MIN); //printf("%s %d\n",minute,MIN); sscanf(seconds,"%f",&SEC); //printf("%s %f\n",seconds,SEC); if(printarg == 1) printf("S_REC: IDSFILE: %s\n",idsfile); if(printarg == 1) printf("S_REC NCHANNELS: %d\n",nchannels); for(i=0;i<30;i++) { mags[i]= ' '; mags2[i]=' '; } mags[24]='\0'; mags2[24]='\0'; mtel = 0; for(i=0;i 3) sprintf(buf2," %4d %2d%2d %2d%2d %4.1f R %7.3f%8.3f%5.1f SC3%3d%4.1f%s1",YR,MTH,DAY,HR,MIN,SEC,latitude,longitude,dep,nostations-nost,rms,mags2); }else{ sprintf(buf," %4d %2d%2d %2d%2d %4.1f R %7.3f%8.3f%5.1fF SC3%3d%4.1f%s1",YR,MTH,DAY,HR,MIN,SEC,latitude,longitude,dep,nostations-nost,rms,mags); if(mtel > 3) sprintf(buf2," %4d %2d%2d %2d%2d %4.1f R %7.3f%8.3f%5.1fF SC3%3d%4.1f%s1",YR,MTH,DAY,HR,MIN,SEC,latitude,longitude,dep,nostations-nost,rms,mags2); } for(i=0;i<100;i++) { if(buf[i]=='\0')buf[i]=' '; if(buf2[i]=='\0')buf2[i]=' '; } buf[80]='\0'; buf2[80]='\0'; if(ret == 0) { buf[21] = 'D'; buf2[21]= 'D'; }else{ buf[21] = 'L'; buf2[21]= 'L'; } fprintf(sf,"%s\n",buf); if(mtel > 3) // more than 3 magnitudes fprintf(sf,"%s\n",buf2); for(i=0;i<100;i++) buf[i]=' '; sprintf(buf," GAP=%3d %6.2f %6.1f %6.1f %5.1f",azgap,time_unc,lat_err,lng_err,dep_err); for(i=0;i<100;i++) if(buf[i]=='\0')buf[i]=' '; if(printarg == 1) printf("%s\n",buf); buf[79]='E'; buf[80]='\0'; fprintf(sf,"%s\n",buf); for(i=0;i<100;i++) buf[i]=' '; if(printarg == 1) printf("In S_REC: FILENAME: %s\n",filename); sprintf(buf," %s",filename); if(wavrec == 1) { for(i=0;i<100;i++) if(buf[i]=='\0')buf[i]=' '; buf[79]='6'; buf[80]='\0'; fprintf(sf,"%s\n",buf); } sprintf(dm1,"%4d",YR); sscanf(dm1,"%2c%d",dm2,&AR); for(i=0;i<100;i++) buf[i]=' '; NOWTIME(&cyr,&cmon,&cday,&chrn,&cmin,&cisec); sprintf(buf," ACTION:NEW %2d-%2d-%2d %2d:%2d OP:SEIS STATUS: %s",cyr,cmon,cday,chrn,cmin,idsfile); if(buf[12]==' ')buf[12]='0'; if(buf[15]==' ')buf[15]='0'; if(buf[18]==' ')buf[18]='0'; if(buf[21]==' ')buf[21]='0'; if(buf[24]==' ')buf[24]='0'; for(i=0;i<100;i++) if(buf[i]=='\0')buf[i]=' '; for(i=59;i<73;i++) if(buf[i]==' ')buf[i]='0'; buf[79]='I'; buf[80]='\0'; fprintf(sf,"%s\n",buf); if(printarg == 1) printf("%s\n",where); fprintf(sf,"%s\n",where); sprintf(buf," STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W DIS CAZ7"); fprintf(sf,"%s\n",buf); // STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W // BER BZ IP 2223 6.00 4 if(printarg == 1) printf("nchannels: %d\n",nchannels); for(ch=0;ch -9.99) { fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } if(phasetyp[ch][0] == 'S') { if(res[ch] > -9.99) { fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } break; case 3: if(phasetyp[ch][0] == 'P') { if(res[ch] > -9.99) { fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } if(phasetyp[ch][0] == 'S') { if(res[ch] > -9.99) { fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } break; case 4: if(phasetyp[ch][0] == 'P') { if(res[ch] > -9.99) { fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IP %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } if(phasetyp[ch][0] == 'S') { if(res[ch] > -9.99) { fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s %s IS %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } break; case 5: if(phasetyp[ch][0] == 'P') { if(res[ch] > -9.99) { fprintf(sf," %s%s IP %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s%s IP %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } if(phasetyp[ch][0] == 'S') { if(res[ch] > -9.99) { fprintf(sf," %s%s IS %c%c%c %2d%2d %2d.%1d %5.2f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); }else{ fprintf(sf," %s%s IP %c%c%c %2d%2d %2d.%1d %5.1f %5d%4d\n",trig_stations[ch],comp,vekter[0],automan[ch][0],polarization[ch][0],hr1,mn1,sc1,ms1,res[ch],(int)(dis[ch]),azi[ch]); } } break; break; } // } } for(ch=0;ch 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %7.1f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } }else{ if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %.1e %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } } break; case 3: if(amplitudes[ch] < 100000.0) { if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %7.1f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } }else{ if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %.1e %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } } break; case 4: // printf("%10.9f %5.2f\n",amplitudes[ch],period[ch]); if(amplitudes[ch] < 100000.0) { if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %.1ef %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } }else{ if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %.1e %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } } break; case 5: if(amplitudes[ch] < 100000.0) { if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %7.1f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } }else{ if(period[ch] > 0.0) { fprintf(sf," %s %s %2d%2d %2d.%1d %.1e%5.2f %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],period[ch],(int)(mag_dist[ch]),mag_azi[ch]); }else{ fprintf(sf," %s %s %2d%2d %2d.%1d %.1e %5d%4d\n",msta,typem,hr1,mn1,sc1,ms1,amplitudes[ch],(int)(mag_dist[ch]),mag_azi[ch]); } } break; } } } fclose(sf); for(ch=0;ch < nchannels;ch++) { for(i=0;i<80;i++) TRIGGER_TIMES[ch][i]='\0'; } } } //---------------------------------------------------------------------------- // create seisan s-file //----------------------------------------------------------------------------- void Create_Sfile( tid,filename,nchannels, nomag,phindex,mgindex,trgdur,latitude,longitude) char tid[]; char filename[]; int nchannels; int nomag; int phindex; int mgindex; int trgdur[]; float latitude; float longitude; { int retur; int i; int ret; char fullpath[200]; char syscmd[200]; char comm1[200]; char comm2[200]; char comm4[200]; char snam[200]; char dummy[200]; char year[5]; char month[5]; char day[5]; char hour[5]; char minute[5]; char sec[5]; char idsfile[20]; int yr; int mn; int dy; int ho; int mi; int sc; char seconds[10]; char tempo[80]; for(i=0;i<200;i++) { snam[i]='\0'; fullpath[i]='\0'; } //---------------------------------------- // make sfile name //---------------------------------------- if(printarg == 1) printf("SC2SEI:......................Create_Sfile Time to make Sfile: %s\n",tid); for(i=0;i<23;i++) if(tid[i]==' ')tid[i]='0'; sscanf(tid,"%6s%4s",dummy,year); //printf("Year: %s\n",year); sscanf(tid,"%3s%2s",dummy,month); //printf("Month:%s\n",month); sscanf(tid,"%2s",day); //printf("Day: %s\n",day); sscanf(tid,"%11s%2s",dummy,hour); //printf("Hour; %s\n",hour); sscanf(tid,"%14s%2s",dummy,minute); //printf("Minu: %s\n",minute); sscanf(tid,"%17s%2s",dummy,sec); //printf("Sec: %s\n",sec); sscanf(tid,"%17s%6s",dummy,seconds); sscanf(year,"%d",&yr); sscanf(month,"%d",&mn); sscanf(day,"%d",&dy); sscanf(hour,"%d",&ho); sscanf(minute,"%d",&mi); sscanf(sec,"%d",&sc); sprintf(snam,"%2s-%2s%2s-%2sR.S%4s%2s", day,hour,minute,sec,year,month); for(i=0;i<19;i++) if(snam[i]==' ')snam[i]='0'; if(printarg == 1) printf("CREATE_SFILE: S-filename.......: %s\n",snam); sprintf(sfilepath,"%s/",topdir); sprintf(EVENTS_S,"%s/REA/%s",sfilepath,dbname); sprintf(dummy,"%s/%s/%s",EVENTS_S,year,month); if(printarg == 1) printf("CREATE_SFILE: S-file path......: %s\n",dummy); CreateDirectory(dummy); //-------------------------------------------- // make full path for S-file //-------------------------------------------- sprintf(fullpath,"%s/%s",dummy,snam); if(printarg == 1) printf("CREATE_SFILE: S-file full path.: %s\n",fullpath); retur=exists(fullpath); if(retur == 1) { if(printarg == 1) printf("SC2SEI: Create_Sfile...........: File exist, add 1 second and create new name.\n"); sc = sc +1; if(sc > 59) { sc = 0; mi = mi +1; if(mi > 59) { mi = 0; ho = ho+1; } } sprintf(hour,"%2d",ho); sprintf(minute,"%2d",mi); sprintf(sec,"%2d",sc); sprintf(idsfile,"ID:%4s%2s%2s%2s%2s%2sd",year,month,day,hour,minute,sec); sprintf(snam,"%2s-%2s%2s-%2sR.S%4s%2s",day,hour,minute,sec,year,month); for(i=0;i<19;i++) if(snam[i]==' ')snam[i]='0'; if(printarg == 1) printf("SC2SEI: Create_Sfile......................: S-filename: %s\n",snam); sprintf(fullpath,"%s/%s",dummy,snam); if(printarg == 1) printf("SC2SEI:.Create_Sfile......................: FULLPATH: %s\n",fullpath); }else{ sprintf(idsfile,"ID:%4s%2s%2s%2s%2s%2s",year,month,day,hour,minute,sec); } sprintf(SFILETOPICK,"%s",fullpath); if(printarg == 1) printf("CRT_S NCHANNELS: %d\n",nchannels); S_REC(year,month,day,hour,minute, seconds, dummy,fullpath,filename,nchannels,nomag,phindex,mgindex,trgdur,idsfile,latitude,longitude); } int exists(const char *fname) { FILE *file; if (file = fopen(fname, "r")) { fclose(file); return 1; } return 0; } //---------------------------------------------------------------------- // create directory given in 'buffer' if not present //---------------------------------------------------------------------- void CreateDirectory(char* buffer) { int ret; int i; int siz; char path2[80]; char message[100]; DIR *dirp; struct dirent *direntp; siz=strlen(buffer); buffer[siz]='/'; buffer[siz+1]='\0'; for(i=0;i 0) { strncpy(path2,buffer,i); path2[i]='\0'; dirp = opendir(path2); // check if dir exists if(dirp == NULL) { //--------------------log message------------------------------- sprintf(message,"%s does not exist. Create it !",path2); ret=mkdir(path2,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); } closedir(dirp); } } } //--------------------------------------------------------------------- // read parameter file //--------------------------------------------------------------------- int Read_Parameters() { FILE *par; char dummy[256]; char linjer[256]; char keyword[256]; char text[256]; char parfile[200]; float val; int valint; int br = 0; sprintf(parfile,"%s/par/sc2sei.par",topdir_sc2sei); printf("SC2SEI: Read_Parameters........: %s\n",parfile); par = fopen(parfile,"r"); if(par == NULL) { printf("SC2SEI: %s does not exist.\n",parfile); exit(0); } sprintf(keyword,"PRE_EVENT"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); preevent = (int)val; printf("SC2SEI: PRE_EVENT..............: %3d seconds\n",preevent); break; } } rewind(par); sprintf(keyword,"POST_EVENT"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); postevent = (int)val; printf("SC2SEI: POST_EVENT.............: %3d seconds\n",postevent); break; } } rewind(par); sprintf(keyword,"PROC_DELAY"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); procdelay = (int)val; printf("SC2SEI: PROC_DELAY.............: %3d seconds\n",procdelay); break; } } rewind(par); sprintf(keyword,"LAT_MIN"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); lat_min = val; printf("SC2SEI: LAT_MIN................: %5.2f\n",lat_min); break; } } rewind(par); sprintf(keyword,"LAT_MAX"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); lat_max = val; printf("SC2SEI: LAT_MAX................: %5.2f\n",lat_max); break; } } rewind(par); sprintf(keyword,"LON_MIN"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); lon_min = val; printf("SC2SEI: LON_MIN................: %5.2f\n",lon_min); break; } } rewind(par); sprintf(keyword,"LON_MAX"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); lon_max = val; printf("SC2SEI: LON_MAX................: %5.2f\n",lon_max); break; } } rewind(par); sprintf(keyword,"MAG_MIN"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); mag_min = val; printf("SC2SEI: MAG_MIN................: %5.2f\n",mag_min); break; } } rewind(par); sprintf(keyword,"MAG_MAX"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%f",dummy,&val); mag_max = val; printf("SC2SEI: MAG_MAX................: %5.2f\n",mag_max); break; } } rewind(par); sprintf(keyword,"DBASENAME"); while ( fgets ( linjer, sizeof linjer, par ) != NULL ) // read a line from file { if (strstr(linjer, keyword) ) { if(printarg > 0) printf("%s", linjer); sscanf(linjer,"%40c%s",dummy,text); sprintf(dbname,"%s",text); printf("SC2SEI: DBASENAME..............: %s\n",dbname); break; } } rewind(par); wavedbactive = 1; sprintf(trgdir,"WAV"); sprintf(trgpath,"%s/%s",topdir,trgdir); printf("SC2SEI: WAVEDIR................: %s\n",trgpath); rewind(par); fclose(par); } //------------------------------------------------------------------------------------------ // Read configuration file into memory //------------------------------------------------------------------------------------------ int Read_Config_to_MEM(char config[]) { FILE *par; char filepath[256]; char linjer[500]; int tel,i; sprintf(filepath,"%s/par/%s",topdir_sc2sei,config); printf("SC2SEI: Read_Config_to_MEM.....: %s\n",filepath); par = fopen(filepath,"r"); if(par == NULL) { printf("************RTDET-Read_Config_to_MEM**********************\n"); printf("* %s does not exist.\n",filepath); printf("* Check your configuration file. *\n"); printf("**********************************************************\n"); exit(0); } tel=0; while ( fgets ( linjer, sizeof linjer, par ) != NULL ) /* read a line from file */ { if(linjer[0] == ' ' || linjer[0] == 0xa ) break; if(linjer[0] != '#') { sprintf(mempar[tel],"%s",linjer); tel++; } } fclose(par); return(tel); } //---------------------------------------------------------------------------------------- // read info from bulletin extracted from topdir_sc3 //---------------------------------------------------------------------------------------- int read_bul2(char pline[]) { int ix; int i; int j; int ret; int statindex; int tt; int bryter; // int no_magnitudes; char stat[256]; char first[256]; char second[256]; char third[256]; char linjer[256]; char ddummy[256]; char ddate[100]; char ttime[100]; char tlat[100]; char tlng[100]; char tdepth[100]; char tmode[100]; char tresrms[100]; char tazgap[100]; char tearthmodel[100]; // char tmagn[10][100]; char tns[10]; char tew[10]; char tuncert[10]; char tlat_err[10]; char tlng_err[10]; char tdep_err[10]; FILE *bul; if((bul = fopen("event.txt","r")) == NULL) { printf("Can't open event.txt\n"); exit(0); } for(i=0;i= 1900) YR=YR - 1900; DYR = 0; if((YR % 4) == 0) DYR = 1; IYR = YR/4 - DYR; // -- Seconds to beginning of *MSECS = (float)(IYR*366) + (float)((YR-IYR)*365); // -- current year *MSECS = *MSECS*86400.0; // -- January if (MTH == 1) YDY = DAY; // -- February if (MTH == 2) YDY = DAY + 31; // -- .... if (MTH == 3) YDY = DAY + DYR + 59; if (MTH == 4) YDY = DAY + DYR + 90; if (MTH == 5) YDY = DAY + DYR + 120; if (MTH == 6) YDY = DAY + DYR + 151; if (MTH == 7) YDY = DAY + DYR + 181; if (MTH == 8) YDY = DAY + DYR + 212; if (MTH == 9) YDY = DAY + DYR + 243; if (MTH ==10) YDY = DAY + DYR + 273; if (MTH ==11) YDY = DAY + DYR + 304; if (MTH ==12) YDY = DAY + DYR + 334; *MSECS = *MSECS + (float)(YDY*86400 + HR*3600 + MIN*60) + SECS; } //--------------------------------------------------------------------------- // read command line parameters //--------------------------------------------------------------------------- int params(int argcount, char **argvec) { int optind; int error = 0; int code; char tm[80]; char streamsfull[80]; char *multiselect = 0; char *selectors = 0; code = 0; if (argcount <= 1) error++; if(printarg == 1) printf("argcount: %d\n",argcount); /* Process all command line arguments */ for (optind = 1; optind < argcount; optind++) { if (strcmp (argvec[optind], "-h") == 0) { howto(); exit (0); } else if (strcmp (argvec[optind], "-prt") == 0) // debug print { printarg = atoi (argvec[++optind]); if(printarg > 0) printf("printarg: %d\n",printarg); } else if (strcmp (argvec[optind], "-time") == 0) // hours back in time first time { code = code + 4; pretime = atoi (argvec[++optind]); if(printarg > 0) printf("pretime: %d\n",pretime); pretime = pretime * 60 * 60; if(printarg == 1) printf("pretime: %d\n",pretime); } else if (strcmp (argvec[optind], "-u") == 0) // user name { code = code + 1; strcpy(username, argvec[++optind]); if(printarg == 1) printf("user name: %s\n",username); control++; } else if (strcmp (argvec[optind], "-p") == 0) // password { code = code + 2; strcpy(password, argvec[++optind]); if(printarg == 1) printf("password: %s\n",password); control++; } else if (strcmp (argvec[optind], "-begin") == 0) // begin { code = code + 8; strcpy(begin, argvec[++optind]); if(printarg == 1) printf("begin: %s\n",begin); request_mode++; } else if (strcmp (argvec[optind], "-end") == 0) // end { code = code + 16; strcpy(end, argvec[++optind]); if(printarg == 1) printf("end: %s\n",end); request_mode++; } else if (strcmp (argvec[optind], "-arc") == 0) // read from archives or segments { code = code + 32; arcseg = atoi (argvec[++optind]); if(printarg == 1) printf("arcseg: %d\n",arcseg); if(arcseg == 1) request_mode++; if(arcseg == 2) request_mode = 4; } else if (strcmp (argvec[optind], "-wav") == 0) // read from archives or segments { wavrec = atoi (argvec[++optind]); if(wavrec == 0 || wavrec == 1) { if(wavrec == 0) code = code + 64; if(printarg == 1) printf("wavrec: %d\n",wavrec); }else{ code = 99999; } } else if (strcmp (argvec[optind], "-ID") == 0) // read event with ID from archives { code = code + 128; strcpy(event_id,argvec[++optind]); if(printarg == 1) printf("event_id: %s\n",event_id); request_mode++; } else if (strcmp (argvec[optind], "-allcmp") == 0) // read from archives or segments { allcmp = atoi (argvec[++optind]); if(allcmp == 0 || allcmp == 1 || allcmp == 2) { if(allcmp == 0) code = code + 256; if(printarg == 1) printf("allcmp: %d\n",allcmp); }else{ code = 99999; } } else if (strcmp (argvec[optind], "-man") == 0) // manually processed { code = code + 512; manauto = atoi (argvec[++optind]); // if(printarg == 1) printf("manauto: %d\n",manauto); control++; } else if (strcmp (argvec[optind], "-del") == 0) // delayed request { code = code + 1024; delreq = atoi (argvec[++optind]); // if(printarg == 1) printf("delreq: %d\n",delreq); control++; } else if (strcmp (argvec[optind], "-hid") == 0) // host id for mysql database { // code = code + 128; strcpy(hostid,argvec[++optind]); // if(printarg == 1) printf("hostid: %s\n",hostid); // request_mode++; } else if (strcmp (argvec[optind], "-sdbnam") == 0) // database name for mysql database { // code = code + 128; strcpy(sdbnam,argvec[++optind]); // if(printarg == 1) printf("sdbnam: %s\n",sdbnam); // request_mode++; } } // if(printarg == 1) printf("code %d\n",code); //exit(0); switch(code) { case 59: printf("Archive mode: Extract from archives. Waveforms. All components.\n"); break; case 123: printf("Arvhive mode: Extract from archives. No waveforms. All components.\n"); break; case 315: printf("Archive mode: Extract from archives. Waveforms. p-phase only.\n"); break; case 379: printf("Archive mode: Extract from archives. No waveforms. p-phase only.\n"); break; case 571: break; case 27: printf("Request mode: Extract from segments. Waveforms. All components.\n"); break; case 91: printf("Request mode: Extract from segments. No waveforms. All components.\n"); break; case 283: printf("Request mode: Extract from segments. Waveforms. p-phase only.\n"); break; case 347: printf("Request mode: Extract from segments. No waveforms. p-phase only.\n"); break; case 539: break; case 7: printf("Contin. mode: Extract from segments n hours back in time. Waveforms. All components.\n"); break; case 71: printf("Contin. mode: Extract from segments n hours back in time. No waveforms. All components.\n"); break; case 263: printf("Contin. mode: Extract from segments n hours back in time. Waveforms. p-phase only.\n"); break; case 327: printf("Contin. mode: Extract from segments n hours back in time. No waveforms. p-phase only.\n"); break; case 131: printf("ID mode: Extract event ID %s from archives. Waveform. All components.\n",event_id); break; case 195: printf("ID mode: Extract event ID %s from archives. No waveform. All components\n",event_id); break; case 387: printf("ID mode: Extract event ID %s from archives. Waveform. p-phase only.\n",event_id); break; case 451: printf("ID mode: Extract event ID %s from archives. No waveform. p-phase only.\n",event_id); break; case 1543: request_mode = 5; printf("Delayed mode: Extract from segments. Automatic and manually processed events.\n"); break; default: printf("Argument combination not allowed.\n"); // exit(0); } // exit(0); } //-------------------------------------------------------------------------- // howto: // howto message and exit. //-------------------------------------------------------------------------- static void howto(void) { printf("Options:\n"); printf(" -h show this message\n"); printf(" -time n check for events n hours back in time.\n"); printf(" -arc 1/2 1: extract events from archives. time1 to time2\n"); printf(" 2: extract events from archives, Continuous mode\n"); printf(" -ID n extract the event with this event-id only.\n"); printf(" -u text username\n"); printf(" -p text password\n"); printf(" -hid text hostid (default: localhost)\n"); printf(" -sdbnam text sdbnam (default: seiscomp3)\n"); printf(" -begin time format: %c2012-01-01 00:00:00%c\n",0x22,0x22); printf(" -end time format: %c2012-01-01 00:00:00%c\n",0x22,0x22); printf(" -wav 1/0 1: record waveforms: 1 (default)\n"); printf(" 0: do not record waveforms.\n"); printf(" -allcmp 1/0/2 1: record all components specified in parameterfile. (default)\n"); printf(" 0: record all components with phase readings.\n"); printf(" 2: record all components with phase readings + components without readings.\n"); printf(" -man 0/1/2 0: record automatic and manually processed. (default)\n"); printf(" 1: record automatic processed only.\n"); printf(" 2: record manually processed only.\n"); }