Skip to content

Fix NetCDF coordinate reads in topo_module: use varid instead of dimid#695

Open
mandli wants to merge 6 commits intoclawpack:masterfrom
mandli:fix-nc-topo-dimid
Open

Fix NetCDF coordinate reads in topo_module: use varid instead of dimid#695
mandli wants to merge 6 commits intoclawpack:masterfrom
mandli:fix-nc-topo-dimid

Conversation

@mandli
Copy link
Member

@mandli mandli commented Feb 27, 2026

topo_module.f90 retrieves coordinate data using:

nf90_get_var(nc_file, x_dim_id, ...)

where x_dim_id/y_dim_id are dimension IDs and not variable IDs. The NetCDF Fortran API requires variable ID for nf90_get_var.

Because NetCDF IDs are integers, this sometimes silently works when a dimid numerically matches a varid, but fails for valid CF files (e.g., GEBCO NetCDF4) with:

NetCDF: Start+count exceeds dimension bound  (-57)

This PR simply switches to the proper variable query

nf90_inq_varid(nc_file, trim(x_dim_name), x_var_id)
nf90_inq_varid(nc_file, trim(y_dim_name), y_var_id)

and checks those coordinates.

Also adds a small fix for nearest-index searches with

minloc(abs(xlocs - xll), dim=1)

@mandli mandli marked this pull request as draft February 27, 2026 16:56
@mandli
Copy link
Member Author

mandli commented Feb 27, 2026

This now works for the GEBCO data I was testing on, but I want to change over all the NetCDF places I think this is happening while I am at it.

@mandli
Copy link
Member Author

mandli commented Feb 27, 2026

There are some changes to the util.wrap_coords function for topography that this was revealed by, but I think that will go into another PR to keep this cleaner.

@mandli mandli marked this pull request as ready for review February 27, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant