int main (int argc, char **argv) { SLpacket * slpack; int seqnum; int ptype; #ifndef WIN32 /* Signal handling, use POSIX calls with standardized semantics */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; sa.sa_handler = term_handler; sigaction (SIGINT, &sa, NULL); sigaction (SIGQUIT, &sa, NULL); sigaction (SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); #endif /* Allocate and initialize a new connection description */ slconn = sl_newslcd(); /* Process given parameters (command line and parameter file) */ if (parameter_proc (argc, argv) < 0) { fprintf(stderr, "Parameter processing failed\n\n"); fprintf(stderr, "Try '-h' for detailed help\n"); return -1; } /* Loop with the connection manager */ while ( sl_collect (slconn, &slpack) ) { ptype = sl_packettype (slpack); seqnum = sl_sequence (slpack); packet_handler ((char *) &slpack->msrecord, ptype, seqnum, SLRECSIZE); /* It would be possible to send an in-line INFO request here with sl_request_info(). */ } /* Make sure everything is shut down and save the state file */ if (slconn->link != -1) sl_disconnect (slconn); if (statefile) sl_savestate (slconn, statefile); return 0; } /* End of main() */
int main (int argc, char **argv) { MSRecord *msr = 0; MSTraceGroup *mstg = 0; MSTrace *mst; int retcode; int totalrecs = 0; int totalsamps = 0; int packedsamples; int packedrecords; int lastrecord; int iseqnum = 1; #ifndef WIN32 /* Signal handling, use POSIX calls with standardized semantics */ struct sigaction sa; sa.sa_flags = SA_RESTART; sigemptyset (&sa.sa_mask); sa.sa_handler = term_handler; sigaction (SIGINT, &sa, NULL); sigaction (SIGQUIT, &sa, NULL); sigaction (SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); #endif /* Process given parameters (command line and parameter file) */ if (parameter_proc (argc, argv) < 0) return -1; /* Setup input encoding format if specified */ if ( encodingstr ) { int inputencoding = strtoul (encodingstr, NULL, 10); if ( inputencoding == 0 && errno == EINVAL ) { ms_log (2, "Error parsing input encoding format: %s\n", encodingstr); return -1; } MS_UNPACKENCODINGFORMAT (inputencoding); } /* Init MSTraceGroup */ mstg = mst_initgroup (mstg); /* Loop over the input file */ while ( (retcode = ms_readmsr (&msr, inputfile, reclen, NULL, &lastrecord, 1, 1, verbose)) == MS_NOERROR ) { totalrecs++; totalsamps += msr->samplecnt; msr_print (msr, ppackets); if ( packreclen >= 0 ) msr->reclen = packreclen; else packreclen = msr->reclen; if ( packencoding >= 0 ) msr->encoding = packencoding; else packencoding = msr->encoding; if ( byteorder >= 0 ) msr->byteorder = byteorder; else byteorder = msr->byteorder; /* After unpacking the record, the start time in msr->starttime is a potentially corrected start time, if correction has been applied make sure the correction bit flag is set as it will be used as a packing template. */ if ( msr->fsdh->time_correct && ! (msr->fsdh->act_flags & 0x02) ) { ms_log (1, "Setting time correction applied flag for %s_%s_%s_%s\n", msr->network, msr->station, msr->location, msr->channel); msr->fsdh->act_flags |= 0x02; } /* If no samples in the record just pack the header */ if ( outfile && msr->numsamples == 0 ) { msr_pack_header (msr, 1, verbose); record_handler (msr->record, msr->reclen, NULL); } /* Pack each record individually */ else if ( outfile && ! tracepack ) { msr->sequence_number = iseqnum; packedrecords = msr_pack (msr, &record_handler, NULL, &packedsamples, 1, verbose); if ( packedrecords == -1 ) ms_log (2, "Cannot pack records\n"); else ms_log (1, "Packed %d records\n", packedrecords); iseqnum = msr->sequence_number; } /* Pack records from a MSTraceGroup */ else if ( outfile && tracepack ) { mst = mst_addmsrtogroup (mstg, msr, 0, -1.0, -1.0); if ( ! mst ) { ms_log (2, "Error adding MSRecord to MStrace!\n"); break; } /* Reset sequence number and free previous template */ if ( mst->prvtptr ) { MSRecord *tmsr = (MSRecord *) mst->prvtptr; /* Retain sequence number from previous template */ msr->sequence_number = tmsr->sequence_number; msr_free (&tmsr); } else { msr->sequence_number = 1; } /* Copy MSRecord and store as template */ mst->prvtptr = msr_duplicate (msr, 0); if ( ! mst->prvtptr ) { ms_log (2, "Error duplicating MSRecord for template!\n"); break; } /* Pack traces based on selected method */ packedrecords = 0; if ( tracepack == 1 ) { mst = mstg->traces; while ( mst ) { packedrecords += mst_pack (mst, &record_handler, NULL, packreclen, packencoding, byteorder, &packedsamples, lastrecord, verbose, (MSRecord *)mst->prvtptr); mst = mst->next; } ms_log (1, "Packed %d records\n", packedrecords); } if ( tracepack == 2 && lastrecord ) { mst = mstg->traces; while ( mst ) { packedrecords += mst_pack (mst, &record_handler, NULL, packreclen, packencoding, byteorder, &packedsamples, lastrecord, verbose, (MSRecord *)mst->prvtptr); mst = mst->next; } ms_log (1, "Packed %d records\n", packedrecords); } } } if ( retcode != MS_ENDOFFILE ) ms_log (2, "Error reading %s: %s\n", inputfile, ms_errorstr(retcode)); /* Make sure everything is cleaned up */ ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0, 0); mst_freegroup (&mstg); if ( outfile ) fclose (outfile); getchar(); return 0; } /* End of main() */
int main (int argc, char **argv) { MSTraceGroup *mstg = 0; MSTrace *mst; MSRecord *msr = 0; struct listnode *flp; int retcode; int totalsamps = 0; /* Process given parameters (command line and parameter file) */ if (parameter_proc (argc, argv) < 0) return -1; /* Init MSTraceGroup */ mstg = mst_initgroup (mstg); /* Read input miniSEED files into MSTraceGroup */ flp = filelist; if ( verbose ) fprintf (stderr, "Reading %s\n", flp->data); while ( (retcode = ms_readmsr(&msr, flp->data, reclen, NULL, NULL, 1, 1, verbose-1)) == MS_NOERROR ) { if ( verbose > 1) msr_print (msr, verbose - 2); mst_addmsrtogroup (mstg, msr, 1, timetol, sampratetol); totalsamps += msr->samplecnt; } if ( retcode != MS_ENDOFFILE ) fprintf (stderr, "Error reading %s: %s\n", flp->data, ms_errorstr(retcode)); /* Make sure everything is cleaned up */ ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0, 0); /* If processing each file individually, write ASCII and reset */ if ( indifile ) { mst = mstg->traces; while ( mst ) { writeascii (mst); mst = mst->next; } mstg = mst_initgroup (mstg); } /* Make sure everything is cleaned up */ mst_freegroup (&mstg); if ( ofp ) fclose (ofp); return 0; } /* End of main() */
int main (int argc, char **argv) { DLPacket dlpack; char packetdata[MAXPACKETSIZE]; char timestr[50]; char *infobuf = 0; int infolen; int endflag = 0; #ifndef WIN32 /* Signal handling, use POSIX calls with standardized semantics */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART; sa.sa_handler = term_handler; sigaction (SIGINT, &sa, NULL); sigaction (SIGQUIT, &sa, NULL); sigaction (SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); #endif /* Process given parameters (command line and parameter file) */ if ( parameter_proc (argc, argv) < 0 ) { fprintf (stderr, "Parameter processing failed\n\n"); fprintf (stderr, "Try '-h' for detailed help\n"); return -1; } /* Connect to server */ if ( dl_connect (dlconn) < 0 ) { fprintf (stderr, "Error connecting to server\n"); return -1; } /* Reposition connection */ if ( dlconn->pktid > 0 ) { if ( dl_position (dlconn, dlconn->pktid, dlconn->pkttime) < 0 ) return -1; } /* Send match pattern if supplied */ if ( matchpattern ) { if ( dl_match (dlconn, matchpattern) < 0 ) return -1; } /* Send reject pattern if supplied */ if ( rejectpattern ) { if ( dl_reject (dlconn, rejectpattern) < 0 ) return -1; } /* Request INFO and print returned XML */ if ( infotype ) { if ( (infolen = dl_getinfo (dlconn, infotype, matchpattern, &infobuf, 0)) < 0 ) { dl_log (2, 0, "Problem requesting INFO from server\n"); return -1; } printf ("%.*s\n", infolen, infobuf); if ( infobuf ) free (infobuf); } /* Otherwise collect packets in STREAMing mode */ else { /* Collect packets in streaming mode */ while ( dl_collect (dlconn, &dlpack, packetdata, sizeof(packetdata), endflag) == DLPACKET ) { dl_dltime2seedtimestr (dlpack.datastart, timestr, 1); dl_log (0, 0, "Received %s (%lld), %s, %d\n", dlpack.streamid, dlpack.pktid, timestr, dlpack.datasize); } } /* Make sure everything is shut down and save the state file */ if ( dlconn->link != -1 ) dl_disconnect (dlconn); /* Save the state file */ if ( statefile ) dl_savestate (dlconn, statefile); if ( dlconn ) dl_freedlcp (dlconn); return 0; } /* End of main() */
int main(int argc, char **argv) { #ifndef WIN32 // Signal handling, use POSIX calls with standardized semantics struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sa.sa_handler = term_handler; sigaction(SIGINT, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction(SIGHUP, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); #endif /* printf("LONG_MIN %ld\n", LONG_MIN); printf("LONG_MAX %ld\n", LONG_MAX); printf("INT_MIN %d\n", INT_MIN); printf("INT_MAX %d\n", INT_MAX); */ // set default error message prefix ms_loginit(NULL, NULL, NULL, "ERROR: "); // defaults verbose = 0; strcpy(port_path_hint, "/dev/usbdev1.1"); strcpy(propfile, PROP_FILE_NAME_DEFAULT); // Process input parameters if (parameter_proc(argc, argv) < 0) return 1; init_properties(propfile); // set encoding type // possible: DE_ASCII, DE_INT16, DE_INT32, DE_FLOAT32, DE_FLOAT64, DE_STEIM1, DE_STEIM2 // supported: DE_INT16, DE_INT32, DE_STEIM1, DE_STEIM2 if (strcmp(mswrite_data_encoding_type, "DE_INT16") == 0) { mswrite_data_encoding_type_code = DE_INT16; num_samples_in_record = (SLREC_DATA_SIZE) / 2; } else if (strcmp(mswrite_data_encoding_type, "DE_INT32") == 0) { mswrite_data_encoding_type_code = DE_INT32; num_samples_in_record = (SLREC_DATA_SIZE) / 4; /* } else if (strcmp(mswrite_data_encoding_type, "DE_ASCII") == 0) { mswrite_data_encoding_type_code = DE_ASCII; } else if (strcmp(mswrite_data_encoding_type, "DE_FLOAT32") == 0) { mswrite_data_encoding_type_code = DE_FLOAT32; } else if (strcmp(mswrite_data_encoding_type, "DE_FLOAT64") == 0) { mswrite_data_encoding_type_code = DE_FLOAT64; */ } else if (strcmp(mswrite_data_encoding_type, "DE_STEIM1") == 0) { mswrite_data_encoding_type_code = DE_STEIM1; num_samples_in_record = (SLREC_DATA_SIZE) / 4; // estimate, inefficient, assumes int32 data } else if (strcmp(mswrite_data_encoding_type, "DE_STEIM2") == 0) { mswrite_data_encoding_type_code = DE_STEIM2; num_samples_in_record = (SLREC_DATA_SIZE) / 4; // estimate, inefficient, assumes int32 data } // enter infinite loop, term_handler() performs cleanup while (1) { // find device and connect find_device_and_connect(port_path_hint); // set sample rate and gain for SEP064 if (do_settings_sep064) { if (set_seo064_sample_rate_and_gain(nominal_sample_rate, nominal_gain, TIMEOUT_SMALL, verbose)) { continue; } } // collect data and write if (collect_and_write()) { // collect_and_write() returned error logprintf(ERROR_FLAG, "Reading from %s, will try reconnecting...\n", port_path); disconnect(verbose); } else { break; // collect_and_write() returned normally } } return (0); } /* End of main() */
int main (int argc, char **argv) { MSRecord *msr = 0; int64_t totalrecs = 0; int64_t totalsamps = 0; int retcode; #ifndef WIN32 /* Signal handling, use POSIX calls with standardized semantics */ struct sigaction sa; sa.sa_flags = SA_RESTART; sigemptyset (&sa.sa_mask); sa.sa_handler = term_handler; sigaction (SIGINT, &sa, NULL); sigaction (SIGQUIT, &sa, NULL); sigaction (SIGTERM, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); #endif /* Process given parameters (command line and parameter file) */ if (parameter_proc (argc, argv) < 0) return -1; /* Loop over the input file */ while ((retcode = ms_readmsr (&msr, inputfile, reclen, NULL, NULL, 1, printdata, verbose)) == MS_NOERROR) { totalrecs++; totalsamps += msr->samplecnt; msr_print (msr, ppackets); if (printdata && msr->numsamples > 0) { int line, col, cnt, samplesize; int lines = (msr->numsamples / 6) + 1; void *sptr; if ((samplesize = ms_samplesize (msr->sampletype)) == 0) { ms_log (2, "Unrecognized sample type: '%c'\n", msr->sampletype); } for (cnt = 0, line = 0; line < lines; line++) { for (col = 0; col < 6; col++) { if (cnt < msr->numsamples) { sptr = (char *)msr->datasamples + (cnt * samplesize); if (msr->sampletype == 'i') ms_log (0, "%10d ", *(int32_t *)sptr); else if (msr->sampletype == 'f') ms_log (0, "%10.8g ", *(float *)sptr); else if (msr->sampletype == 'd') ms_log (0, "%10.10g ", *(double *)sptr); cnt++; } } ms_log (0, "\n"); /* If only printing the first 6 samples break out here */ if (printdata == 1) break; } } } if (retcode != MS_ENDOFFILE) ms_log (2, "Cannot read %s: %s\n", inputfile, ms_errorstr (retcode)); /* Make sure everything is cleaned up */ ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0, 0); if (basicsum) ms_log (1, "Records: %" PRId64 ", Samples: %" PRId64 "\n", totalrecs, totalsamps); return 0; } /* End of main() */