diff --git a/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 b/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 index 2e9a95b4a925d1c190c6bf021865b6aeee9e8af7..a395548def1a18c1fc8338d24d6a28c1e139933e 100644 --- a/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 +++ b/src/LIB/SURCOUCHE/src/mode_io_write_nc4.f90 @@ -88,15 +88,17 @@ integer(kind=CDFINT),parameter :: DEFLATE = 1 contains -subroutine IO_Field_header_split_write_nc4( tpfile, tpfield, knblocks ) +subroutine IO_Field_header_split_write_nc4( tpfile, tpfield, knblocks, kisize, kjsize ) use modd_field, only: TYPEREAL use modd_parameters, only: jphext use mode_tools_ll, only: Get_globaldims_ll -type(tfiledata), intent(in) :: tpfile -class(tfieldmetadata), intent(in) :: tpfield -integer, intent(in) :: knblocks +type(tfiledata), intent(in) :: tpfile +class(tfieldmetadata), intent(in) :: tpfield +integer, intent(in) :: knblocks +integer, optional, intent(in) :: kisize ! Size of the field in the first dimension +integer, optional, intent(in) :: kjsize ! Size of the field in the second dimension character(len=len(tpfield%cmnhname)) :: yvarname integer :: iimax, ijmax @@ -133,6 +135,7 @@ if ( istatus /= NF90_NOERR ) then trim( tpfile%cname )//': '//trim( yvarname )//': CDIR should be XY' ) call Get_globaldims_ll( iimax, ijmax ) + ! Use global dims and not kisize/kjsize (if provided) to set the correct 'coordinates' attribute ishape(1) = int( iimax + 2 * jphext, kind = CDFINT ) ishape(2) = int( ijmax + 2 * jphext, kind = CDFINT ) ishape(3) = knblocks @@ -164,6 +167,14 @@ if ( istatus /= NF90_NOERR ) then if ( istatus /= NF90_NOERR ) call IO_Err_handle_nc4( istatus, 'IO_Field_header_split_write_nc4', 'NF90_PUT_ATT', & 'ndims for '//trim( tpfield%cmnhname ) ) + ! Force ishape to the provided dimensions (if present) + if ( present( kisize ) ) then + ishape(1) = kisize + end if + if ( present( kjsize) ) then + ishape(2) = kjsize + end if + istatus = NF90_PUT_ATT( incid, ivarid,'dims', ishape ) if ( istatus /= NF90_NOERR ) call IO_Err_handle_nc4( istatus, 'IO_Field_header_split_write_nc4', 'NF90_PUT_ATT', & 'dims for '//trim( tpfield%cmnhname ) )