GenericMappingTools / gmt

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

segfault in surface when selecting input columns and generating mask #4466

Closed EJFielding closed 3 years ago

EJFielding commented 3 years ago

Description of the problem

I am using surface to interpolate points from a file that has x y z s records. It was working fine when I ran awk to extract the three x y s values to a separate file. I tried to read the original file with four columns using -i0,1,3 and it crashes with a segmentation violation.

Full script that generated the error

  gmt surface Crucecita-xyzs.txt -i0,1,3 -R-96.56/-95.76/15.48/16.08 -I0.04 -Ll0.0 -M0.05 -T0.25 -Vd -
Gtotal_slip_surface.nc

Crucecita-xyzs.txt

Full error message

... (previous lines scrolled off terminal; full output below)
surface [DEBUG]: Apply all boundary conditions [stride = 1]
surface [DEBUG]: Iteration 331
surface [DEBUG]:    1   D        332    8.85771426741e-05   8.79679227099e-05          430
surface [DEBUG]: Apply all boundary conditions [stride = 1]
surface [DEBUG]: Iteration 332
surface [DEBUG]:    1   D        333    8.72305985186e-05   8.79679227099e-05          431
surface [INFORMATION]:    1 D        333    8.72305985186e-05   8.79679227099e-05          431
surface [INFORMATION]: Compute rms misfit and curvature.
surface [DEBUG]: Apply all boundary conditions [stride = 1]
surface [INFORMATION]: Fit info: N data points  N nodes mean error  rms error   curvature
surface [INFORMATION]:       172         336    -0.00214794283046   0.0609277982353 362.07293583
surface [DEBUG]: GMT_Destroy_Data: freed memory for a Grid for object 2
surface [DEBUG]: gmtlib_unregister_io: Unregistering object no 2 [n_objects = 2]
surface [DEBUG]: gmtlib_unregister_io: Object no 2 has non-NULL resource pointer
surface [DEBUG]: Initializing a vector for handing external Input
surface [DEBUG]: Object ID 3 : Registered Vector Memory Reference 7f811b7001e0 as an Input resource with geometry Point [n_objects = 3]
surface [DEBUG]: Successfully created a new Vector container
surface [DEBUG]: VirtualFile name created: @GMTAPI@-S-I-D-V-T-N-000003
surface [DEBUG]: Object ID 4 : Registered Grid Memory Copy 7f811b700560 as an Output resource with geometry Surface [n_objects = 4]
surface [DEBUG]: Successfully created a new Grid container
surface [DEBUG]: VirtualFile name created: @GMTAPI@-S-O-G-G-G-Y-000004
surface [INFORMATION]: Masking grid nodes away from data points via grdmask
surface [DEBUG]: Calling grdsample with args @GMTAPI@-S-I-D-V-T-N-000003 -G@GMTAPI@-S-O-G-G-G-Y-000004 -R-96.56/-95.76/15.48/16.08 -I0.04/0.04 -NNaN/1/1 -S0.05 -V
surface [DEBUG]: Revised options: @GMTAPI@-S-I-D-V-T-N-000003 -G@GMTAPI@-S-O-G-G-G-Y-000004 -R-96.56/-95.76/15.48/16.08 -I0.04/0.04 -NNaN/1/1 -S0.05 -V
surface (gmtlib_free_tmp_arrays): tried to free unallocated memory
grdmask [DEBUG]: History: Process -R-96.56/-95.76/15.48/16.08
grdmask [DEBUG]: gmt_get_filename: In: -96.56/-95.76/15.48/16.08 Out: -96.56/-95.76/15.48/16.08
grdmask [DEBUG]: Look for file -96.56/-95.76/15.48/16.08 in /Users/fielding/.gmt
grdmask [DEBUG]: Look for file -96.56/-95.76/15.48/16.08 in /Users/fielding/.gmt/cache
grdmask [DEBUG]: Look for file -96.56/-95.76/15.48/16.08 in /Users/fielding/.gmt/server
grdmask [DEBUG]: Got regular w/e/s/n for region (-96.56/-95.76/15.48/16.08)
grdmask [INFORMATION]: Processing input table data
grdmask [INFORMATION]: Cartesian input grid
grdmask [INFORMATION]: Given domain implies x_inc = 0.04
grdmask [INFORMATION]: Given domain implies y_inc = 0.04
grdmask [DEBUG]: Chosen boundary condition for all edges: natural
grdmask [INFORMATION]: Cartesian input grid
grdmask [DEBUG]: Object ID 5 : Registered Grid Memory Reference 7f810b500150 as an Input resource with geometry Surface [n_objects = 5]
grdmask [DEBUG]: Successfully created a new Grid container
grdmask [INFORMATION]: Nodes completely outside the search radius will be set to NaN
grdmask [INFORMATION]: Nodes completely inside the search radius will be set to 1
grdmask [INFORMATION]: Nodes on the search radius boundary will be set to 1
grdmask [DEBUG]: Map distance calculation will be Cartesian
grdmask [DEBUG]: Max node-search half-widths are: half_x = 2, half_y = 2
grdmask [WARNING]: Number of input columns required [2] is less that implied by -i [3]
grdmask [DEBUG]: gmtapi_init_import: Passed family = Data Table and geometry = Point
grdmask [DEBUG]: gmtapi_init_import: Added 1 new sources
grdmask [DEBUG]: GMT_Init_IO: Returned first Input object ID = 3
grdmask [DEBUG]: gmtapi_begin_io: Input resource access is now enabled [container]
grdmask [DEBUG]: gmtapi_import_dataset: Passed ID = -1 and mode = 0
grdmask [INFORMATION]: Referencing data table from user 2 column arrays of length 172
grdmask [DEBUG]: Object ID 6 : Registered Data Table Memory Reference 7f810b500c50 as an Input resource with geometry Point [n_objects = 6]
ERROR: Caught signal number 11 (Segmentation fault: 11) at
0   libgmt.6.dylib                      0x00000001072d6e74 gmt_set_seg_minmax + 164
1   ???                                 0x0000000000000000 0x0 + 0
Stack backtrace:
0   libgmt.6.dylib                      0x000000010725feb2 sig_handler + 578
1   libsystem_platform.dylib            0x00007fff6ba06b5d _sigtramp + 29
2   ???                                 0x0000000000000000 0x0 + 0
3   libgmt.6.dylib                      0x00000001072d7176 gmt_set_tbl_minmax + 358
4   libgmt.6.dylib                      0x00000001072d74c7 gmt_set_dataset_minmax + 263
5   libgmt.6.dylib                      0x000000010728aea2 gmtapi_import_data + 9410
6   libgmt.6.dylib                      0x0000000107271b95 GMT_Read_Data + 4469
7   libgmt.6.dylib                      0x00000001074c7666 GMT_grdmask + 4662
8   libgmt.6.dylib                      0x000000010727f220 GMT_Call_Module + 1632
9   libgmt.6.dylib                      0x00000001075ac2f5 GMT_surface + 26181
10  libgmt.6.dylib                      0x000000010727f220 GMT_Call_Module + 1632
11  gmt                                 0x0000000107256ac2 main + 2418
12  libdyld.dylib                       0x00007fff6b81b3d5 start + 1

surface-error.txt

Actual outcome

No output .nc file.

Expected outcome

Expected an interpolated surface grid.

System information

welcome[bot] commented 3 years 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.

PaulWessel commented 3 years ago

I think I know what is going on (but will check of course). You can see grdmask (called from surface) saying

grdmask [WARNING]: Number of input columns required [2] is less that implied by -i [3]

so I suspect the -o0,1,3 option is blindly passed on to grdmask (which of course is only getting the x,y,s triplets and hence "3" does not exist...

EJFielding commented 3 years ago

Thanks for looking at it. This also looks suspicious: surface (gmtlib_free_tmp_arrays): tried to free unallocated memory

EJFielding commented 3 years ago

Thanks @PaulWessel. It is great to see how much GMT has been improved with all the integration under the hood between the programs. I guess there are occasional problems like this due to the added complexity.

PaulWessel commented 3 years ago

Yes, the -M option to surface is relatively new so not unusual to find lame bugs early on. At least they are usually very simple to fix and just reflect forgetting a step, like here.