diff --git a/ChangeLog b/ChangeLog index d7d125b..08fa9bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ -2023.162: +2023.162: 0.9.3 - Update libmseed to 3.0.15 with fixes for v2 packing. + - Retain format v2 sequence numbers and data quality indicators if + the input and output formats is v2. 2023.161: - Update libmseed to 3.0.14 diff --git a/src/mseedconvert.c b/src/mseedconvert.c index f0a0ae7..b4a7f51 100644 --- a/src/mseedconvert.c +++ b/src/mseedconvert.c @@ -18,9 +18,10 @@ #include #include +#include #include -#define VERSION "0.9.2" +#define VERSION "0.9.3" #define PACKAGE "mseedconvert" static int8_t verbose = 0; @@ -35,6 +36,9 @@ static FILE *outfile = NULL; static char *extraheaderfile = NULL; static char *extraheaderpatch = NULL; +static char insertV2seqnum[6] = {0}; +static char insertV2dataquality = 0; + static int extraheader_init (char *file); static int convertsamples (MS3Record *msr, int packencoding); static int retired_encoding (int8_t encoding); @@ -92,6 +96,19 @@ main (int argc, char **argv) if (verbose >= 1) msr3_print (msr, verbose - 1); + /* Retain v2 sequence number of data quality indicator if input and output are v2. + * Setting these insertion values triggers them to be inserted post-record creation */ + if (msr->formatversion == 2 && packversion == 2 && msr->record) + { + memcpy (insertV2seqnum, pMS2FSDH_SEQNUM (msr->record), 6); + insertV2dataquality = *pMS2FSDH_DATAQUALITY (msr->record); + } + else + { + insertV2seqnum[0] = '\0'; + insertV2dataquality = 0; + } + /* Determine if unpacking data is not needed when converting to version 3 */ if (forcerepack == 0 && packversion == 3 && (packencoding < 0 || packencoding == msr->encoding)) @@ -107,7 +124,7 @@ main (int argc, char **argv) repackheaderV3 = 1; } - /* Integer and float encodings must be litte endian */ + /* Integer and float encodings must be little endian */ else if (msr->encoding == DE_INT16 || msr->encoding == DE_INT32 || msr->encoding == DE_FLOAT32 || msr->encoding == DE_FLOAT64) { @@ -607,6 +624,16 @@ parameter_proc (int argcount, char **argvec) static void record_handler (char *record, int reclen, void *ptr) { + /* Brute force overwrite of v2 sequence number and data quality indicator */ + if (insertV2seqnum[0] != '\0') + { + memcpy (pMS2FSDH_SEQNUM (record), insertV2seqnum, 6); + } + if (insertV2dataquality != 0) + { + *pMS2FSDH_DATAQUALITY (record) = insertV2dataquality; + } + if (fwrite (record, reclen, 1, outfile) != 1) { ms_log (2, "Cannot write to output file\n");