-
Notifications
You must be signed in to change notification settings - Fork 1
Clock Correction in msmod #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks @dricki Three issues before I can consider merging.
# The clock correction (--cc option) file format is: #
type: {keyword} {parameters}
# Instrument Time Reference Time
{instrument_time_0} {reference_time_0}
{instrument_time_1} {reference_time_1}
....
cc -g -I../libmseed -c msmod.c
msmod.c:298:17: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
298 | if ( retcode = processmods (msr) )
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
msmod.c:298:17: note: place parentheses around the assignment to silence this warning
298 | if ( retcode = processmods (msr) )
| ^
| ( )
msmod.c:298:17: note: use '==' to turn this assignment into an equality comparison
298 | if ( retcode = processmods (msr) )
| ^
| ==
msmod.c:1984:11: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
1984 | if (fabs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^
msmod.c:1984:11: note: use function 'llabs' instead
1984 | if (fabs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^~~~
| llabs
|
|
Hi, Chad -Ok, all three comments are reasonable and I will be happy to implement. Wayne, do you feel like writing text for man page or let me do it?Best regards -IlyaSent from my iPhoneOn Sep 4, 2025, at 11:40, Chad Trabant ***@***.***> wrote:chad-earthscope left a comment (EarthScope/msmod#2)
Thanks @dricki
Also tagging @WayneCrawford
Three issues before I can consider merging.
No documentation in the man page for this new feature. The extended help (-H option) has a bit of detail regarding the option but it doesn't look sufficient for user to understand the features of the clock correction field. Extended help addition is (which also looks to have minor formatting issues):
# The clock correction (--cc option) file format is: #
type: {keyword} {parameters}
# Instrument Time Reference Time
{instrument_time_0} {reference_time_0}
{instrument_time_1} {reference_time_1}
....
Compiler warnings with the new code. General rule is no compiler warnings with latest, or reasonably current, clang and gcc compilers. The warnings:
cc -g -I../libmseed -c msmod.c
msmod.c:298:17: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
298 | if ( retcode = processmods (msr) )
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
msmod.c:298:17: note: place parentheses around the assignment to silence this warning
298 | if ( retcode = processmods (msr) )
| ^
| ( )
msmod.c:298:17: note: use '==' to turn this assignment into an equality comparison
298 | if ( retcode = processmods (msr) )
| ^
| ==
msmod.c:1984:11: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
1984 | if (fabs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^
msmod.c:1984:11: note: use function 'llabs' instead
1984 | if (fabs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^~~~
| llabs
The new code is a large addition relative to the main code. It makes code review difficult and will make future maintenance harder. New code should be in separate file.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
To follow ISTI news and updates please subscribe to our newsletter "the isti letter" at https://www.isti.com/newsletter-sign-up.
|
|
@dricki , I can make a stab at the help text, but would prefer that you add it in once I'm done, as I'm not very familiar/comfortable with pull requests. |
|
Dear Wayne As long as you write the text and simply email me I will do the restBest regards -IlyaSent from my iPhoneOn Sep 4, 2025, at 17:00, Wayne Crawford ***@***.***> wrote:WayneCrawford left a comment (EarthScope/msmod#2)
@dricki , I can make a stab at the help text, but would prefer that you add it in once I'm done, as I'm not very familiar/comfortable with pull requests.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
To follow ISTI news and updates please subscribe to our newsletter "the isti letter" at https://www.isti.com/newsletter-sign-up.
|
|
Here is my recommendation. I'm putting it here so that Chad can verify it's not too long before you go to the bother of inserting it: fprintf (stderr,
"\n"
" # Clock correction (--cc option) #\n"
" Sets timecorrection and modifies starttime in every record according\n"
" to a clock drift specified in the clock correction input file.\n"
"\n"
"The clock correction input file format is:"
" type: {keyword} [{parameters}]\n"
" # Instrument Time Reference Time\n"
" {instrument_time_0} {reference_time_0}\n"
" {instrument_time_1} {reference_time_1}\n"
" ....\n"
"\n"
"The times in each column must monotonically increase and the\n"
"{instrument_time}s must cover the time range of the miniSEED file(s).\n"
"Time format is yyyy-mm-ddTHH:MM:SS(.FFFFF)Z.\n"
"Comment lines start with '#' and have no effect on processing.\n"
"Possible 'type' lines are:\n"
"type: piecewise_linear\n:
" shifts instrument_time to reference_time for each provided value,\n"
" linearly interpolates in between\n"
"type: cubic_spline\n"
" shifts instrument_time to reference_time for each provided value,\n"
" cubic spline interpolation in between\n"
"type: polynomial a0 a1 a2 a3...\n"
" sets corrected_time = instrument_time_0 + a0 + a1*delta + a2*delta**2 + ...,\n"
" where delta = instrument_time - instrument_time_0.\n"
" {instrument_time_n} and {reference_time_n} are used to validate results\n"
"\n"
""Also outputs a text file named {CCFILENAME}.log, with the columns:\n"
" RecNo: the record number\n"
" Instrument time: original instrument time (ISO8601)\n"
" Corrected to reference: corrected time (ISO8601)\n"
" Corrected-Instrument: corrected time minus instrument time (s)\n"
" Instrument-sync_inst[0]: instrument time - instrument_time_0 (s)\n"
"\n"); |
|
[Edit with more clarity] The command line help message The doc/msmod.1 page should include:
|
|
With that in mind, I would recommend shortening the fprintf (stderr,
"\n"
" # Clock correction (--cc option) #\n"
" Sets timecorrection and modifies starttime in every record according\n"
" to the specified clock drift.\n"
"\n"
" Clock correction input file format:"
"\n"
" {type_line}\n"
" {instrument_time_0} {reference_time_0}\n"
" {instrument_time_1} {reference_time_1}\n"
" ....\n"
"\n"
" Possible {type_line}s:\n"
" type: piecewise_linear\n:
" type: cubic_spline\n"
" type: polynomial a0 a1 a2 a3...\n");
"\n"
" Time format: yyyy-mm-ddTHH:MM:SS(.FFFFF)Z.\n" |
|
@chad-earthscope and @WayneCrawford -
.md file is not updated, versions and dates are not updated Please review the pull request |
|
Hi Ilya I will download and test the code. Could you copy the changes you put in msmod.1 to msmod.md? I tried but it requires me to fork. Cheers |
|
Hi, Wayne -
Chad told me that he has a script to convert man2md and he will do it
Cheers -
Ilya
On 9/22/2025 1:48 PM, Wayne Crawford wrote:
*WayneCrawford* left a comment (EarthScope/msmod#2)
<#2 (comment)>
Hi Ilya
I will download and test the code. Could you copy the changes you put
in msmod.1 to msmod.md? I tried but it requires me to fork.
Cheers
Wayne
—
Reply to this email directly, view it on GitHub
<#2 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNDCECG5KBAV6CZ47AHQH33T7HZJAVCNFSM6AAAAACCMINMJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMJYGE4TMNRUGM>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
/To follow ISTI news and updates please subscribe to our newsletter
"the isti letter" at https://www.isti.com/newsletter-sign-up
<https://www.isti.com/newsletter-sign-up>./
--
*To follow ISTI news and updates please subscribe to our newsletter
"the isti letter" at https://www.isti.com/newsletter-sign-up
<https://www.isti.com/newsletter-sign-up>.*
|
|
OK great, I've started looking at the code. First, on my system, I get the following compile warning: cc -g -I../libmseed -c clockcorr.c
clockcorr.c:697:11: warning: absolute value function 'abs' given an argument of type 'hptime_t' (aka 'long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
697 | if (abs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^
clockcorr.c:697:11: note: use function 'llabs' instead
697 | if (abs(cc_config->ref_time[i] - correction - cc_config->inst_time[i]) > SMALL)
| ^~~
| llabs
1 warning generated.Then, when I run # Clock correction (--cc option) #
Sets timecorrection and modifies starttime in every record according
to the specified clock drift.
Clock correction input file format:
{type_line}
{instrument_time_0} {reference_time_0}
{instrument_time_1} {reference_time_1}
....
Possible {type_line}s:
type: piecewise_linear
: type: cubic_spline
type: polynomial a0 a1 a2 a3...
Time format: yyyy-mm-ddTHH:MM:SS(.FFFFF)Z.which I would change to (new stuff in "**", if Chad approves): # Clock correction (--cc option) #
Sets **record header** timecorrection and **starttime fields** according
to the **original starttime and** the specified clock drift.
Clock correction input file format:
**type:** {type_value}
{instrument_time_0} {reference_time_0}
{instrument_time_1} {reference_time_1}
....
Possible {type_value}s are:
piecewise_linear
cubic_spline
polynomial a0 a1 a2 a3...
**{*_time_*}** format: yyyy-mm-ddTHH:MM:SS(.FFFFF)ZFinally, when I run I get ERROR Unknown option: --ccI get the same error for Either I'm not using the command line correctly, or there is some bug that's not accepting "--cc". I will look to see if I find the reason but you will probably be a lot faster than me! Cheers |
|
Complilation warning is gone. cubic_spline file read gives error because it expects ERROR: Badly formatted input file: line 1
ERROR reading CC configuration: 'clock_correct_cubic.txt'maybe could say "unknown type on type line: xxx" Otherwise, all the different test files (linear1, linear2, polynomial and cubic (with "cubic-spline")) give output, I will now check if the output matches the specs. |
|
I checked the code with 9 different input files:
Major bug: miniSEED record header start times are not modifiedIn each new record header, the time correction value is entered and the "time correction applied" flag is set, but the start time is the same as before. Here's an example, pruned from mseed input file, last headers...
start time: 2022,331,01:12:00.000000
time correction: 0
start time: 2022,340,05:14:00.000000
time correction: 0
start time: 2022,349,09:16:00.000000
time correction: 0
start time: 2022,358,13:18:00.000000
time correction: 0
mseed output file, last headers...
start time: 2022,331,01:12:00.000000
time correction: -12713
start time: 2022,340,05:14:00.000000
time correction: -13313
start time: 2022,349,09:16:00.000000
time correction: -13913
start time: 2022,358,13:18:00.000000
time correction: -14512Drift correction values
Output log file
Output miniSEED file
Error catching and signallingTime checking on polynomialWorks, but the Catching a too-late first sync timeWorks for the 1 month offset, not for the 1 second offset. Catching a too-early last sync timeWorks for the 1-month offset, not for the 1-second offset. Catching an out-of-order sync timeWorks. Attached filesThe zipped miniSEED file I ran the tests on: The "bad" test files I used: The code I used to run the tests: The outputs of the different tests: I can also provide the "standard" test clock_correct files and their expected outputs (I had to slightly modify them from what I provided initially, in order to match the msmod output) |
…n to the output file
|
Please ping me when this passes muster @WayneCrawford and I'll merge into the main repo. The plan is to merge this into a |

We added clock correction as an msmod option. Data providers could use this to correct instrument times with a known drift, as is the case for ocean-bottom seismometers where the instrument-reference offset is measured before and after deployment.
The code in msmod.c is commented and generally follow the description in https://github.com/FDSN/OBS-standards/blob/main/other/msmod_drift_addition.md with the following caveats:
/* Revert time to uncorrected value if correction was applied during unpacking */
if ( msr->fsdh->time_correct != 0 && ! (msr->fsdh->act_flags & 0x02) )
{
msr->starttime = msr_starttime_uc (msr);
}
So if the user inputs time-corrected input file and tries to do the same time correction, the input and output files will be identical and no error and error messages are printed out. If this behavior is not what we want I suggest Chad modifies msr_starttime_uc() function.