netcdf-fortran
netcdf-fortran copied to clipboard
Unable to write data to enum variable
the version of the software with which you are encountering an issue
libnetcdff-dev 4.5.2+ds-1build2 from the official Ubuntu 20.04 repos
environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
- Ubuntu 20.04.4 LTS
- gfortran 9.4.0
a description of the issue with the steps needed to reproduce it
Trying to write data to an enum variable gives me error code -45 "Not a valid data type or _FillValue type mismatch". Here is a minimal example demonstrating the issue:
PROGRAM nc
USE netcdf
IMPLICIT NONE
INTEGER :: ncid, varid, typegauge, i
CHARACTER(LEN=2), DIMENSION(3) :: arr = [CHARACTER(LEN=2) :: 'aa', 'bb', 'cc']
CALL check(nf90_create(path='/tmp/test.nc', cmode=nf90_netcdf4, ncid=ncid))
CALL check(nf90_def_enum(ncid, nf90_int, 'gauge', typegauge))
DO i=1, 3
CALL check(nf90_insert_enum(ncid, typegauge, TRIM(arr(i)), i))
END DO
CALL check(nf90_def_var(ncid=ncid, name='gaugetype', xtype=typegauge, varid=varid))
CALL check(nf90_enddef(ncid))
CALL check(nf90_put_var(ncid, varid, 1))
CALL check( nf90_close(ncid) )
CONTAINS
SUBROUTINE check(stat)
INTEGER, INTENT(IN) :: stat
IF (stat /= nf90_noerr) THEN
PRINT *, TRIM(nf90_strerror(stat))
STOP stat
END IF
END SUBROUTINE check
END PROGRAM nc
I get no errors when using nf90_put_var
with builtin datatypes.
I could not find any examples online using enum types with the nf90-interface, so maybe I'm just doing something stupid.