CTD sample_keys end in the cast direction — …:cast:9802_008d /
…:cast:9802_008u — so a station occupation that logged both directions is two
sample rows sharing a base.
Details
THE OBVIOUS IMPLEMENTATION IS WRONG. sub("d$", "", x) is fine, but
gsub("d", "", x) or replace(x, 'd', '') also eats the d in the
calcofi_ctd-cast prefix and silently returns a key that matches nothing. The
same trap is called out in ctd_updown_disagreement.sql, which is where it was
first hit.