This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Lee,
I can duplicate what you are seeing. It looks like a bug.
If I use
character (len = 5) :: ch = "abcde"
...
call check(nf90_put_var(ncid, varid2, ch))
it works fine:
ncdump CharTest.nc
...
CH = "abcde" ;
but the F90 library seems to be treating
character (len = 1), dimension (5) :: ch = (/'a', 'b', 'c', 'd', 'e' /)
...
call check(nf90_put_var(ncid, varid2, ch))
as if it's a 2D array, becasue it ends up calling
nf90_put_var_1d_text
which calls
nf_put_vars_text(ncid, varid, localStart, localCount, localStride, values(1))
with
localstart(1:2) =
(1) 1
(2) 1
localcount(1:2) =
(1) 1
(2) 5
localstride(1:2) =
(1) 1
(2) 1
as if it were an array of 5 strings, each of length 1, rather than an array
of 5 characters. I didin't write this and don't know enough about F90 to be
sure of how to fix it without breaking how text strings are handled. Is it
possible to do what you want with bytes, using the ichar() and char()
Fortran intrinsic functions?
Maybe Ed can see how to fix it when he gets back. Or you could look at the
function nf90_put_var_1D_text() in f90/netcdf_text_variables.f90 and see if
you can suggest a fix. The original author of the Fortran 90 interface,
Robert Pincus, may still work with the NOAA CIRES Climate Diagnostic Center
(or whatever it's called now). We may try to get him to help with this if
we can't figure it out.
--Russ
--Russ
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
Ticket Details
===================
Ticket ID: YEC-124697
Department: Support netCDF
Priority: Normal
Status: Closed