Closed dmr-dj closed 5 months ago
Yes, I see the test case would give an error because the dimension of the integer variable must be defined first with a call to nc_write_dim
, and then that dimension should be used with the nc_write
of the integer itself. For example, this would look something like this:
program test
use ncio
call nc_create("test.nc",overwrite=.true.,netcdf4=.true.)
call nc_write_dim("test.nc","point",x=1,units="-")
call nc_write("test.nc","int_var",1,dim1="point")
end program test
It does seem a bit like overkill to have to write a dimension for an integer variable of length 1, but this is required by NetCDF.
So, is the issue though, that a better error message should be provided in this case? Or do you think some functionality could be improved?
I am not sure that netCDF do need a dimension for this. If you look at what ncio does for the "crs" variable, it indeed writes a integer without an axis associated:
call nc_check( nf90_def_var(nc_id, trim(crs_name), NF90_INT, varid) )
I guess one option would be to add a special case when dims = 0
and process it in a similar fashion as above ... or am I missing something?
(or at least it defines a variable without an axis, more properly said)
Ok, I have made some changes within the code, and now it looks like your test works. I have also made a new test program from your code just to check:
make nodim
./test_nodim.x
I think it works as expected. Please let me know if you encounter any trouble, and thanks for the suggestion!
I was trying to write a plain integer (one value) into a netCDF file. Using nc_write. According to the API:
... the only thing to provide are the first three arguments.
Thus using the simplest test possible:
But this example compiles fine but do not run, error message is:
Within the module it should be caught by
nc_write_int_pt
that callsnc4_write_internal
, but I could not find the case wherendims=0
in the latter. I guess it defaults tondims=1
and then crashes since none exist/specified.