diff --git a/src/LIB/SURCOUCHE/src/mode_netcdf.f90 b/src/LIB/SURCOUCHE/src/mode_netcdf.f90 index a8b2293ed219268b73bf0cf66d26883b9877e3a6..1b63a2bf8b0fe58e7c7e77f12bbf253ebea79520 100644 --- a/src/LIB/SURCOUCHE/src/mode_netcdf.f90 +++ b/src/LIB/SURCOUCHE/src/mode_netcdf.f90 @@ -1923,7 +1923,8 @@ CHARACTER(LEN=30) :: YVARNAME INTEGER(KIND=IDCDF_KIND) :: IVARID INTEGER(KIND=IDCDF_KIND) :: ITYPE ! variable type INTEGER(KIND=IDCDF_KIND) :: IDIMS ! number of dimensions -INTEGER(KIND=IDCDF_KIND), DIMENSION(SIZE(SHAPE(PFIELD))) :: IVDIMS +!INTEGER(KIND=IDCDF_KIND), DIMENSION(SIZE(SHAPE(PFIELD))) :: IVDIMS +INTEGER(KIND=IDCDF_KIND), DIMENSION(3) :: IVDIMS INTEGER(KIND=IDCDF_KIND) :: ICOMLEN ! comment length INTEGER :: IVARSIZE INTEGER(KIND=IDCDF_KIND) :: IDIMLEN @@ -1944,9 +1945,22 @@ IF (STATUS /= NF90_NOERR) THEN CALL HANDLE_ERR(status,__LINE__,'NCREADX2[NF90_INQ_VARID] '//TRIM(YVARNAME),IRESP) GOTO 1000 END IF + STATUS = NF90_INQUIRE_VARIABLE(KNCID, IVARID, XTYPE=ITYPE, NDIMS=IDIMS, DIMIDS=IVDIMS) IF (STATUS /= NF90_NOERR) CALL HANDLE_ERR(STATUS,__LINE__,'NCREADX2[NF90_INQUIRE_VARIABLE] '//TRIM(YVARNAME)) +!Treat special case of a degenerated 3D array (3rd dimension size is 1) +IF (IDIMS==3) THEN + STATUS = NF90_INQUIRE_DIMENSION(KNCID, IVDIMS(3), LEN=IDIMLEN) + IF (STATUS /= NF90_NOERR) CALL HANDLE_ERR(status,__LINE__,'NCREADX2[NF90_INQUIRE_DIMENSION] '//TRIM(YVARNAME)) + IF (IDIMLEN==1) THEN + CALL PRINT_MSG(NVERB_INFO,'IO','NCREADX2','reading 3D array with degenerated third dimension in 2D array for '//TRIM(HVARNAME)) + IDIMS = 2 + ELSE + CALL PRINT_MSG(NVERB_FATAL,'IO','NCREADX2','wrong number of dimensions for '//TRIM(HVARNAME)) + END IF +END IF + IF (IDIMS == SIZE(SHAPE(PFIELD)) .AND. ITYPE == NF90_DOUBLE) THEN ! Check size of variable before reading IVARSIZE = 1