main() { outfile = fopen("int32_Steim2_littleEndian.mseed", "w"); int psamples; int precords; MSTrace *mst; char srcname[50]; psamples = 0; int *mychar; mychar = (int *) malloc(50 * sizeof(int)); // Write integers from 1 to 50. int i = 1; for(i; i<51; i++){ mychar[i-1] = i; } mst = mst_init (NULL); /* Populate MSTrace values */ strcpy (mst->network, "XX"); strcpy (mst->station, "TEST"); strcpy (mst->channel, "BHE"); mst->starttime = ms_seedtimestr2hptime ("2004,350,00:00:00.000000"); mst->samprate = 1.0; /* The datasamples pointer and numsamples counter will be adjusted by the packing routine, the datasamples array must be dynamic memory allocated by the malloc() family of routines. */ mst->datasamples = mychar; mst->numsamples = 50; mst->samplecnt = 50; mst->sampletype = 'i'; mst_srcname (mst, srcname, 0); /* Pack 512 byte, big-endian records, ´write Chars */ precords = mst_pack (mst, &record_handler, srcname, 256, DE_STEIM2, 0, &psamples, 1, verbose, NULL); ms_log (0, "Packed %d samples into %d records\n", psamples, precords); fclose(outfile); mst_free (&mst); }
main() { outfile = fopen("fullASCII_bigEndian.mseed", "w"); int psamples; int precords; MSTrace *mst; char srcname[50]; psamples = 0; // Allocate char array. One more allocated char is necessary for // the zero terminating last char. char *mychar = (char *) malloc(96 * sizeof(char)); // Copy contents to char. In this case copy all ASCII chars. strcpy(mychar, " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); mst = mst_init (NULL); /* Populate MSTrace values */ strcpy (mst->network, "XX"); strcpy (mst->station, "TEST"); strcpy (mst->channel, "BHE"); mst->starttime = ms_seedtimestr2hptime ("2004,350,00:00:00.000000"); mst->samprate = 1.0; /* The datasamples pointer and numsamples counter will be adjusted by the packing routine, the datasamples array must be dynamic memory allocated by the malloc() family of routines. */ mst->datasamples = mychar; /* pointer to 8-bit ascii data samples */ mst->numsamples = 95; mst->samplecnt = 95; mst->sampletype = 'a'; /* declare type to be 8 bit ASCII */ mst_srcname (mst, srcname, 0); /* Pack 256 byte, big-endian records, write chars */ precords = mst_pack (mst, &record_handler, srcname, 256, DE_ASCII, 1, &psamples, 1, verbose, NULL); ms_log (0, "Packed %d samples into %d records\n", psamples, precords); fclose(outfile); mst_free (&mst); }
/*************************************************************************** * parameter_proc(): * Process the command line parameters. * * Returns 0 on success, and -1 on failure ***************************************************************************/ static int processparam (int argcount, char **argvec) { int optind; char *matchpattern = 0; char *rejectpattern = 0; char *tptr; /* Process all command line arguments */ for (optind = 1; optind < argcount; optind++) { if (strcmp (argvec[optind], "-V") == 0) { ms_log (1, "%s version: %s\n", PACKAGE, VERSION); exit (0); } else if (strcmp (argvec[optind], "-h") == 0) { usage(); exit (0); } else if (strncmp (argvec[optind], "-v", 2) == 0) { verbose += strspn (&argvec[optind][1], "v"); } else if (strcmp (argvec[optind], "-r") == 0) { reclen = strtol (getoptval(argcount, argvec, optind++), NULL, 10); } else if (strcmp (argvec[optind], "-e") == 0) { encodingstr = getoptval(argcount, argvec, optind++); } else if (strcmp (argvec[optind], "-ts") == 0) { starttime = ms_seedtimestr2hptime (getoptval(argcount, argvec, optind++)); if ( starttime == HPTERROR ) return -1; } else if (strcmp (argvec[optind], "-te") == 0) { endtime = ms_seedtimestr2hptime (getoptval(argcount, argvec, optind++)); if ( endtime == HPTERROR ) return -1; } else if (strcmp (argvec[optind], "-M") == 0) { matchpattern = strdup (getoptval(argcount, argvec, optind++)); } else if (strcmp (argvec[optind], "-R") == 0) { rejectpattern = strdup (getoptval(argcount, argvec, optind++)); } else if (strcmp (argvec[optind], "-n") == 0) { reccntdown = strtol (getoptval(argcount, argvec, optind++), NULL, 10); } else if (strcmp (argvec[optind], "-y") == 0) { skipnotdata = 0; } else if (strncmp (argvec[optind], "-p", 2) == 0) { ppackets += strspn (&argvec[optind][1], "p"); } else if (strcmp (argvec[optind], "-O") == 0) { printoffset = 1; } else if (strcmp (argvec[optind], "-L") == 0) { printlatency = 1; } else if (strcmp (argvec[optind], "-s") == 0) { basicsum = 1; } else if (strcmp (argvec[optind], "-d") == 0) { printdata = 1; } else if (strcmp (argvec[optind], "-D") == 0) { printdata = 2; } else if (strcmp (argvec[optind], "-z") == 0) { printraw = 1; } else if (strcmp (argvec[optind], "-t") == 0) { tracegapsum = 1; } else if (strcmp (argvec[optind], "-T") == 0) { tracegaponly = 1; } else if (strcmp (argvec[optind], "-tg") == 0) { tracegaps = 1; /* -T is assumed if -t/-g is not already set */ if ( ! tracegapsum ) tracegaponly = 1; } else if (strcmp (argvec[optind], "-tt") == 0) { timetol = strtod (getoptval(argcount, argvec, optind++), NULL); } else if (strcmp (argvec[optind], "-rt") == 0) { sampratetol = strtod (getoptval(argcount, argvec, optind++), NULL); } else if (strcmp (argvec[optind], "-g") == 0) { tracegapsum = 2; } else if (strcmp (argvec[optind], "-G") == 0) { tracegaponly = 2; } else if (strcmp (argvec[optind], "-S") == 0) { tracegaponly = 3; } else if (strcmp (argvec[optind], "-gmin") == 0) { mingap = strtod (getoptval(argcount, argvec, optind++), NULL); mingapptr = &mingap; } else if (strcmp (argvec[optind], "-gmax") == 0) { maxgap = strtod (getoptval(argcount, argvec, optind++), NULL); maxgapptr = &maxgap; } else if (strcmp (argvec[optind], "-Q") == 0) { dataquality = 1; } else if (strcmp (argvec[optind], "-tf") == 0) { timeformat = strtol (getoptval(argcount, argvec, optind++), NULL, 10); } else if (strcmp (argvec[optind], "-b") == 0) { binfile = getoptval(argcount, argvec, optind++); } else if (strcmp (argvec[optind], "-o") == 0) { outfile = getoptval(argcount, argvec, optind++); } else if (strncmp (argvec[optind], "-", 1) == 0 && strlen (argvec[optind]) > 1 ) { ms_log (2, "Unknown option: %s\n", argvec[optind]); exit (1); } else { tptr = argvec[optind]; /* Check for an input file list */ if ( tptr[0] == '@' ) { if ( addlistfile (tptr+1) < 0 ) { ms_log (2, "Error adding list file %s", tptr+1); exit (1); } } /* Otherwise this is an input file */ else { /* Add file to global file list */ if ( addfile (tptr) ) { ms_log (2, "Error adding file to input list %s", tptr); exit (1); } } } } /* Make sure input file were specified */ if ( filelist == 0 ) { ms_log (2, "No input files were specified\n\n"); ms_log (1, "%s version %s\n\n", PACKAGE, VERSION); ms_log (1, "Try %s -h for usage\n", PACKAGE); exit (1); } /* Expand match pattern from a file if prefixed by '@' */ if ( matchpattern ) { if ( *matchpattern == '@' ) { tptr = strdup(matchpattern + 1); /* Skip the @ sign */ free (matchpattern); matchpattern = 0; if ( readregexfile (tptr, &matchpattern) <= 0 ) { ms_log (2, "Cannot read match pattern regex file\n"); exit (1); } free (tptr); } } /* Expand reject pattern from a file if prefixed by '@' */ if ( rejectpattern ) { if ( *rejectpattern == '@' ) { tptr = strdup(rejectpattern + 1); /* Skip the @ sign */ free (rejectpattern); rejectpattern = 0; if ( readregexfile (tptr, &rejectpattern) <= 0 ) { ms_log (2, "Cannot read reject pattern regex file\n"); exit (1); } free (tptr); } } /* Compile match and reject patterns */ if ( matchpattern ) { match = (regex_t *) malloc (sizeof(regex_t)); if ( regcomp (match, matchpattern, REG_EXTENDED) != 0) { ms_log (2, "Cannot compile match regex: '%s'\n", matchpattern); } free (matchpattern); } if ( rejectpattern ) { reject = (regex_t *) malloc (sizeof(regex_t)); if ( regcomp (reject, rejectpattern, REG_EXTENDED) != 0) { ms_log (2, "Cannot compile reject regex: '%s'\n", rejectpattern); } free (rejectpattern); } /* Report the program version */ if ( verbose ) ms_log (1, "%s version: %s\n", PACKAGE, VERSION); return 0; } /* End of parameter_proc() */