GenericMappingTools / gmt

The Generic Mapping Tools
https://www.generic-mapping-tools.org
Other
864 stars 359 forks source link

segy2grd fails to parse -M correctly #8630

Closed timhenstock closed 3 days ago

timhenstock commented 4 days ago

Description of the problem gmt segy2grd discards 1st character of the number following -M gmt segy2grd -M16000 expected behaviour is to read 16000 traces but it reads 6000 instead gmt segy2grd -M016000 reads 16000 traces

gmt pssegy works as expected so -M16000 plots 16000 traces.

6.3.0 does not have this bug. 6.5.0 running on Rocky8 using the binaries from the recommended repository does have this bug. 6.5.0 compiled from source on Rocky8 also shows this bug. 6.5.0 compiled from source on Ubuntu 22.04 does have this bug. Comparing the source code I can see 2 differences in 6.5.0 source: 1 Where the parameters are defined pssegy uses uint32_t and segy2grd unsigned int 2 Where the parameters are parsed segy2grd.c

        case 'M':
            n_errors += gmt_M_repeated_module_option (API, Ctrl->M.active);
            n_errors += gmt_get_required_uint (GMT, &opt->arg[1], opt->option, 0, &Ctrl->M.value);
            break;

pssegy.c

        case 'M':
            n_errors += gmt_M_repeated_module_option (API, Ctrl->M.active);
            n_errors += gmt_get_required_uint (GMT, opt->arg, opt->option, 0, &Ctrl->M.value);
            Ctrl->M.value = atoi (opt->arg);
            break;

When I dig in gmt_get_required_uint, it is clear that &opt->arg[1] in segy2grd.c means that the first character of the parameter for the argument is discarded. Corrected code is either:

            n_errors += gmt_get_required_uint (GMT, &opt->arg[0], opt->option, 0, &Ctrl->M.value);

or

            n_errors += gmt_get_required_uint (GMT, opt->arg, opt->option, 0, &Ctrl->M.value);

Same incorrect outcomes and code error in the -L option parsing.

Full script that generated the error

gmt segy2grd  -R0/20000/0/6 -G/tmp/segy.grd /mnt/c/Users/then2/OneDrive\ -\ University\ of\ Southampton/Documents/research/v_shaped_ridges/jc50/jc50stacks/jc50_line1.segy -I1/0.002 -M20000 -Vd

Full error message

No error message. Code runs but produces incorrect outcome.

Actual outcome

Reads 1 trace. -Vd reports segy2grd [INFORMATION]: Number of traces in header is 1

Expected outcome

Reads 20000 traces -Vd reports segy2grd [INFORMATION]: Number of traces in header is 20000

Both of these are correctly produced with my code suggestion above.

System information

welcome[bot] commented 4 days ago

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. We appreciate that you took the time to contribute!

Please make sure you read our Contributing Guide and abide by our Code of Conduct.

joa-quim commented 4 days ago

Hi Tim,

Thanks for finding this. I have applied your suggestion in the PR (Pull Request) #8631