Skip to content
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

segy2grd fails to parse -M correctly #8630

Closed
timhenstock opened this issue Nov 22, 2024 · 2 comments · Fixed by #8631
Closed

segy2grd fails to parse -M correctly #8630

timhenstock opened this issue Nov 22, 2024 · 2 comments · Fixed by #8631
Labels
bug Something isn't working

Comments

@timhenstock
Copy link

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

  • Operating system:
  • Ubuntu 22.04, Rocky 8
  • GMT version (gmt --version):
  • 6.5.0; bug introduced since 6.3.0
@timhenstock timhenstock added the bug Something isn't working label Nov 22, 2024
Copy link

welcome bot commented Nov 22, 2024

👋 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
Copy link
Member

Hi Tim,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants