Bug #945
grdedit -G does not work
| Status: | Closed | Start date: | 2016-07-26 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% | ||
| Category: | - | Estimated time: | 1.00 hour | |
| Target version: | Candidate for next bugfix release | |||
| Affected version: | 5.x-svn | Platform: |
Description
From: http://gmt.soest.hawaii.edu/boards/1/topics/3897?r=3906
The command:
gmt grdedit antarctica_ice_speed_900m.nc -R-2800000/2799800/-2799800/2800000 -D"x [m]/y [m]/ice speed [m/year]" -Gk.nc
does not create a file k.nc
Applies to GMT 5.2 and 5.3, at least.
Associated revisions
Make grdedit -G work again. This fixes issue #945 for GMT 5.3
Make grdedit -G work again. This fixes issue #945 for GMT 5.2
Address issue #945
History
#4
Updated by Remko 12 months ago
Yes, Joaquim, that can be done, but it should not be necessary. Besides, the grid is written again, from scratch, irrespectively, so the -G option actually serves a purpose, because it is faster that way.
But what I find alarming is that when I add -Vd all the debug info looks good, as if a new file is written. But it is not. That means that somewhere deep in the weeds of GMT_Write_Data something goes terribly wrong. And this can have serious effects on all GMT programs ... at least the ones handling grids.
grdedit: Object ID 0 : Registered GMT Grid File antarctica_ice_speed_900m.nc as an Input resource with geometry Surface [n_objects = 1] grdedit: api_begin_io: Input resource access is now enabled [container] grdedit: api_import_grid: Passed ID = 0 and mode = 1 grdedit: Grid is Cartesian grdedit: GMT_End_IO: Input resource access is now disabled G: 1 ./k.nc antarctica_ice_speed_900m.nc ./k.nc grdedit: Editing parameters for grid antarctica_ice_speed_900m.nc: grdedit: Decode and change attributes in file antarctica_ice_speed_900m.nc grdedit: api_begin_io: Input resource access is now enabled [container] grdedit: api_import_grid: Passed ID = 0 and mode = 2 grdedit: Reading grid from file antarctica_ice_speed_900m.nc grdedit: processing at most 480 (10x48) chunks at a time (30.9 MiB)... grdedit: packed z-range: [0,3916.32] grdedit: Grid is Cartesian grdedit: Chosen boundary condition for all edges: natural grdedit: Set boundary condition for all edges: natural grdedit: Set boundary condition for left edge: natural grdedit: Set boundary condition for right edge: natural grdedit: Set boundary condition for bottom edge: natural grdedit: Set boundary condition for top edge: natural grdedit: GMT_End_IO: Input resource access is now disabled grdedit: GMT_End_IO: Input resource access is now disabled grdedit: Reset region in file antarctica_ice_speed_900m.nc to -2.8e+06/2.7998e+06/-2.7998e+06/2.8e+06 grdedit: Reset grid-spacing in file antarctica_ice_speed_900m.nc to 900/900 grdedit: Object ID 1 : Registered GMT Grid File ./k.nc as an Output resource with geometry Surface [n_objects = 2] grdedit: api_begin_io: Output resource access is now enabled [container] grdedit: api_export_grid: Passed ID = 1 and mode = 1 grdedit: Updating grid header for file ./k.nc grdedit: netCDF Library version: 4 grdedit: GMT_End_IO: Output resource access is now disabled grdedit: Modified grid written to file ./k.nc. grdedit: gmtapi_garbage_collection: Destroying object: C=0 A=0 ID=0 W=Input F=GMT Grid M=File S=Used P=7ffbd9400890 D=7ffbd9400890 N=antarctica_ice_speed_900m.nc grdedit: GMTAPI_Garbage_Collection freed 1 memory objects grdedit: gmtapi_unregister_io: Unregistering object no 0 [n_objects = 1] grdedit: gmtapi_unregister_io: Unregistering object no 1 [n_objects = 0] grdedit (gmtlib_free_tmp_arrays): tried to free unallocated memory
#6
Updated by Joaquim 12 months ago
- Assignee deleted (
Remko) - % Done changed from 100 to 0
- Estimated time deleted (
1.00)
Ok, here is what is currently going on, despite the printing debug messages
In gmtnc_grd_info, line
if (!strcmp (header→name,"=")) return (GMT_GRDIO_NC_NO_PIPE);
the header→name still holds the input file name and hence it's this file that sees the header updated, so this is the source of the bug ... BUT
in api_export_grid() that code was called inside the branch
if (mode & GMT_GRID_HEADER_ONLY) { /* Update header structure only */
so in fact only the header was updated and no new file was created (again despite the printed messages).
A corollary of this is, it it wasn't the bug we would end up with a new grid with ... only the header.
This only reinforces my point that -G should be removed.
#11
Updated by Joaquim 12 months ago
Two things:
- I'm using debug builds. Sometimes it makes a difference
- I know you will smile on this but I've been there really many times (Paul can testify) the fact is that compilers on Mac are too permissive to small memory errors. I lost count to cases where VS detected a problem (often by crashing) that clang did let go. We have one of those with grdimage and MEX/Julia that we have not been able to solve.
#13
Updated by Paul 12 months ago
Joaquim was testing things like gmt grdedit JP.nc -Jm0.1i -Glixo.grd which definitively crashes since grdedit did not actually read the grid data (only the header) but then tries to write the entire grid to the new file. I fixed this and added some general precautions in the API against that sort of problem for grids and images. In r16865.