Newer
Older

WAUTELET Philippe
committed
if ( htype /= 'CART' ) call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //': gsplit=T not implemented for these dimensions and htype/=CART' )

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 2 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 2 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( Any( tpfields(1)%ndimlist(1) == [ NMNHDIM_NI, NMNHDIM_NI_U, NMNHDIM_NI_V, NMNHDIM_BUDGET_CART_NI, &
NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ] ) &
.and. Any( tpfields(1)%ndimlist(3) == [ NMNHDIM_LEVEL, NMNHDIM_LEVEL_W, &
NMNHDIM_BUDGET_CART_LEVEL, NMNHDIM_BUDGET_CART_LEVEL_W ] ) ) then

WAUTELET Philippe
committed
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata2d( size(pvar,1), size(pvar,3) ) )
zdata2d(:,:) = pvar(:, 1, :, 1, 1, 1)

WAUTELET Philippe
committed
if ( gsplit ) then
if ( htype /= 'CART' ) call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //': gsplit=T not implemented for these dimensions and htype/=CART' )

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 3 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 3 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( Any( tpfields(1)%ndimlist(2) == [ NMNHDIM_NJ, NMNHDIM_NJ_U, NMNHDIM_NJ_V, NMNHDIM_BUDGET_CART_NJ, &
NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ] ) &
.and. Any( tpfields(1)%ndimlist(3) == [ NMNHDIM_LEVEL, NMNHDIM_LEVEL_W, &
NMNHDIM_BUDGET_CART_LEVEL, NMNHDIM_BUDGET_CART_LEVEL_W ] ) ) then

WAUTELET Philippe
committed
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata2d( size(pvar,2), size(pvar,3) ) )
zdata2d(:,:) = pvar(1, :, :, 1, 1, 1)

WAUTELET Philippe
committed
if ( gsplit ) then
if ( htype /= 'CART' ) call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //': gsplit=T not implemented for these dimensions and htype/=CART' )

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 2, 3 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 2, 3 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( Any( tpfields(1)%ndimlist(1) == [ NMNHDIM_BUDGET_CART_NI, NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ] ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
Allocate( zdata1d(Size( pvar, 1 )) )
do ji = 1, Size( pvar, 6 )
zdata1d(:) = pvar(:, 1, 1, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1 ], kbutimepos = 2 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata1d, [ Size(zdata1d,1), 1 ] ), &
koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata1d )
end if
end do
Deallocate( zdata1d )
else if ( Any( tpfields(1)%ndimlist(2) == [ NMNHDIM_BUDGET_CART_NJ, NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ] ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
Allocate( zdata1d(Size( pvar, 2 )) )
do ji = 1, Size( pvar, 6 )
zdata1d(:) = pvar(1, :, 1, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 2 ], kbutimepos = 2 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata1d, [ Size(zdata1d,1), 1 ] ), &
koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 2 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata1d )
end if
end do
Deallocate( zdata1d )
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
zdata2d(:,:) = pvar(1, 1, :, :, 1, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( Any( tpfields(1)%ndimlist(3) == [ NMNHDIM_BUDGET_CART_LEVEL, NMNHDIM_BUDGET_CART_LEVEL_W ] ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
tzfield%ndimlist(1) = tpfields(1)%ndimlist(3)
tzfield%ndimlist(2:) = NMNHDIM_UNUSED
allocate( zdata1d( size(pvar,3) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, Size( pvar, 6 )
zdata1d(:) = pvar(1, 1, :, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3 ], kbutimepos = 2 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, Reshape( zdata1d, [ Size(zdata1d,1), 1 ] ), &
koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata1d )
end if
end do
deallocate( zdata1d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_TIME .and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_MASK_NBUMASK ) then
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
Allocate( zdata2d(Size( pvar, 4 ), Size( pvar, 5 )) )
zdata2d(:,:) = pvar(1, 1, 1, :, :, 1)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 4, 5 ], kbutimepos = 1 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, zdata2d, koffset= [ ( nbutshift - 1 ) * nbusubwrite, 0 ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 4, 5 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
Deallocate( zdata2d )
else if ( ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &

WAUTELET Philippe
committed
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_LES_SV ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata2d( size(pvar,4), size(pvar,5) ) )
zdata2d(:,:) = pvar(1, 1, 1, :, :, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(4) == NMNHDIM_FLYER_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_FLYER_PROC ) then
!Correspond to FLYER_DIACHRO

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
!Create local time dimension
if ( isp == tzfile%nmaster_rank) then
istatus = NF90_DEF_DIM( igrpid, 'time_flyer', Size( pvar, 4), idimid )
if ( istatus /= NF90_NOERR ) &
call IO_Err_handle_nc4( istatus, 'Write_diachro_nc4', 'NF90_DEF_DIM', Trim( tpfields(1)%cmnhname ) )
end if
allocate( zdata1d( size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata1d(:) = pvar(1, 1, 1, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata1d )
end do
deallocate( zdata1d )
else if ( tpfields(1)%ndimlist(4) == NMNHDIM_STATION_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_STATION_PROC ) then
!Correspond to STATION_DIACHRO_n

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata1d( size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata1d(:) = pvar(1, 1, 1, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata1d )
end do
deallocate( zdata1d )
else if ( tpfields(1)%ndimlist(4) == NMNHDIM_SERIES_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_SERIES_PROC ) then
!Correspond to WRITE_SERIES_n

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata1d( size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata1d(:) = pvar(1, 1, 1, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata1d )
end do
deallocate( zdata1d )
else
call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'case not yet implemented (variable '//trim(tpfields(1)%cmnhname)//')' )

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
end if
case (3)

WAUTELET Philippe
committed
if ( Any( tpfields(1)%ndimlist(1) == [ NMNHDIM_NI, NMNHDIM_NI_U, NMNHDIM_NI_V, NMNHDIM_BUDGET_CART_NI, &
NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ] ) &
.and. Any( tpfields(1)%ndimlist(2) == [ NMNHDIM_NJ, NMNHDIM_NJ_U, NMNHDIM_NJ_V, NMNHDIM_BUDGET_CART_NJ, &
NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ] ) &
.and. Any( tpfields(1)%ndimlist(3) == [ NMNHDIM_LEVEL, NMNHDIM_LEVEL_W, &
NMNHDIM_BUDGET_CART_LEVEL, NMNHDIM_BUDGET_CART_LEVEL_W ] ) ) then
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata3d( size(pvar,1), size(pvar,2), size(pvar,3) ) )
zdata3d(:,:,:) = pvar(:, :, :, 1, 1, 1)

WAUTELET Philippe
committed
if ( gsplit ) then
if ( htype /= 'CART' ) call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //': gsplit=T not implemented for these dimensions and htype/=CART' )
if ( htype == 'CART' .and. .not. oicp .and. .not. ojcp ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 2, 3 ], kbutimepos = 4 )

WAUTELET Philippe
committed
!Data is distributed between all the processes
tzfield%cdir = 'XY'
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write_box( tzfile, tzfield, 'BUDGET', &
Reshape( zdata3d, [ Size(zdata3d,1), Size(zdata3d,2), Size(zdata3d,3), 1 ] ) , &
kil + jphext, kih + jphext, kjl + jphext, kjh + jphext, &
koffset= [ 0, 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if

WAUTELET Philippe
committed
if ( htype == 'CART' .and. .not. oicp .and. .not. ojcp ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 2, 3 ] )

WAUTELET Philippe
committed
!Data is distributed between all the processes
tzfield%cdir = 'XY'
call IO_Field_write_box( tzfile, tzfield, 'BUDGET', zdata3d, &
kil + jphext, kih + jphext, kjl + jphext, kjh + jphext )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 2, 3 ] )

WAUTELET Philippe
committed
!Data is already collected on the master process

WAUTELET Philippe
committed
!tzfield%cdir = '--'

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata3d )
end if
end if
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( Any(tpfields(1)%ndimlist(1) == [ NMNHDIM_BUDGET_CART_NI, NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ]) &
.and. Any(tpfields(1)%ndimlist(2) == [ NMNHDIM_BUDGET_CART_NJ, NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ]) &

WAUTELET Philippe
committed
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then

WAUTELET Philippe
committed
Allocate( zdata2d(Size( pvar, 1 ), Size( pvar, 2 )) )
! Loop on the processes
do ji = 1, Size( pvar, 6 )
zdata2d(:, :) = pvar(:, :, 1, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, &
Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
end do
Deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( Any ( tpfields(1)%ndimlist(1) == [ NMNHDIM_BUDGET_CART_NI, NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ] ) &

WAUTELET Philippe
committed
.and. tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_CART_LEVEL &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then

WAUTELET Philippe
committed
Allocate( zdata2d(Size( pvar, 1 ), Size( pvar, 3 )) )
! Loop on the processes
do ji = 1, Size( pvar, 6 )
zdata2d(:, :) = pvar(:, 1, :, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 3 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, &
Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 3 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
end do
Deallocate( zdata2d )
else if ( Any ( tpfields(1)%ndimlist(2) == [ NMNHDIM_BUDGET_CART_NJ, NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ] ) &

WAUTELET Philippe
committed
.and. tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_CART_LEVEL &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then

WAUTELET Philippe
committed
Allocate( zdata2d(Size( pvar, 2 ), Size( pvar, 3 )) )
! Loop on the processes
do ji = 1, Size( pvar, 6 )
zdata2d(:, :) = pvar(1, :, :, 1, 1, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 2, 3 ], kbutimepos = 3 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, &
Reshape( zdata2d, [ Size(zdata2d,1), Size(zdata2d,2), 1 ] ), &
koffset= [ 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 2, 3 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
end do
Deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_MASK_LEVEL &
.or. tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_MASK_LEVEL_W ) &
.and. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_TIME &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_MASK_NBUMASK ) then
!Correspond to Store_one_budget_rho (MASK)
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata3d( size(pvar,3), size(pvar,4), size(pvar,5) ) )
zdata3d(:,:,:) = pvar(1, 1, :, :, :, 1)

WAUTELET Philippe
committed
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 3, 4, 5 ], kbutimepos = 2 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, zdata3d(:,:,:), koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite, 0 ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 3, 4, 5 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata3d )
end if
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_LES_MASK ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( nles_masks /= Size( pvar, 6 ) ) &
call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'last dimension size of pvar is not equal to nles_masks (variable ' &
// Trim( tpfields(1)%cmnhname ) // ')' )
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
! Loop on the masks (1 written variable per mask)
do ji = 1, size(pvar,6)
zdata2d(:,:) = pvar(1, 1, :, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_TERM ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
! Loop on the masks (1 written variable per mask)
do ji = 1, size(pvar,6)
zdata2d(:,:) = pvar(1, 1, :, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_LES_SV ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
!Correspond to Les_diachro_sv_new
allocate( zdata3d( size(pvar,3), size(pvar,4), size(pvar,5) ) )
zdata3d(:,:,:) = pvar(1, 1, :, :, :, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 3, 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata3d )
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(1) == NMNHDIM_SPECTRA_2PTS_NI &
.and. tpfields(1)%ndimlist(3) == NMNHDIM_SPECTRA_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata3d( size(pvar,1), size(pvar,3), size(pvar,4) ) )
zdata3d(:,:,:) = pvar(:, 1, :, :, 1, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata3d )
deallocate( zdata3d )
else if ( tpfields(1)%ndimlist(2) == NMNHDIM_SPECTRA_2PTS_NJ &
.and. tpfields(1)%ndimlist(3) == NMNHDIM_SPECTRA_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata3d( size(pvar,2), size(pvar,3), size(pvar,4) ) )
zdata3d(:,:,:) = pvar(1, :, :, :, 1, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 2, 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata3d )
deallocate( zdata3d )
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_LEVEL &
.and. tpfields(1)%ndimlist(4) == NMNHDIM_FLYER_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_FLYER_PROC ) then
!Correspond to FLYER_DIACHRO

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
!Create local time dimension
if ( isp == tzfile%nmaster_rank) then
istatus = NF90_DEF_DIM( igrpid, 'time_flyer', Size( pvar, 4), idimid )
if ( istatus /= NF90_NOERR ) &
call IO_Err_handle_nc4( istatus, 'Write_diachro_nc4', 'NF90_DEF_DIM', Trim( tpfields(1)%cmnhname ) )
end if
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata2d(:, :) = pvar(1, 1, :, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_LEVEL &
.and. tpfields(1)%ndimlist(4) == NMNHDIM_PROFILER_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_PROFILER_PROC ) then
!Correspond to PROFILER_DIACHRO_n

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata2d(:, :) = pvar(1, 1, :, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( ( tpfields(1)%ndimlist(3) == NMNHDIM_SERIES_LEVEL .or. tpfields(1)%ndimlist(3) == NMNHDIM_SERIES_LEVEL_W ) &
.and. tpfields(1)%ndimlist(4) == NMNHDIM_SERIES_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_SERIES_PROC ) then
!Correspond to PROFILER_DIACHRO_n

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata2d( size(pvar,3), size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata2d(:, :) = pvar(1, 1, :, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )
else if ( ( tpfields(1)%ndimlist(1) == NMNHDIM_NI .or. tpfields(1)%ndimlist(1) == NMNHDIM_NI_U ) &
.and. tpfields(1)%ndimlist(4) == NMNHDIM_SERIES_TIME &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_SERIES_PROC ) then
!Correspond to PROFILER_DIACHRO_n

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata2d( size(pvar,1), size(pvar,4) ) )
! Loop on the processes (1 written variable per process)
do ji = 1, size(pvar,6)
zdata2d(:, :) = pvar(:, 1, 1, :, 1, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 4 ] )
CALL IO_Field_write( tzfile, tzfield, zdata2d )
end do
deallocate( zdata2d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_TIME &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_MASK_NBUMASK &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
Allocate( zdata2d(Size( pvar, 4 ), Size( pvar, 5 )) )
! Loop on the processes (1 written variable per process)
do ji = 1, Size( pvar, 6 )
zdata2d(:,:) = pvar(1, 1, 1, :, :, ji)
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 4, 5 ], kbutimepos = 1 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write( tzfile, tzfield, zdata2d, koffset= [ ( nbutshift - 1 ) * nbusubwrite, 0 ] )
else
call IO_Field_write( tzfile, tzfield, zdata2d )
end if
end do
Deallocate( zdata2d )
else
call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'case not yet implemented (variable '//trim(tpfields(1)%cmnhname)//')' )
end if
case (4)

WAUTELET Philippe
committed
if ( Any( tpfields(1)%ndimlist(1) == [ NMNHDIM_BUDGET_CART_NI, NMNHDIM_BUDGET_CART_NI_U, NMNHDIM_BUDGET_CART_NI_V ] ) &
.and. Any( tpfields(1)%ndimlist(2) == [ NMNHDIM_BUDGET_CART_NJ, NMNHDIM_BUDGET_CART_NJ_U, NMNHDIM_BUDGET_CART_NJ_V ] ) &
.and. Any( tpfields(1)%ndimlist(3) == [ NMNHDIM_BUDGET_CART_LEVEL,NMNHDIM_BUDGET_CART_LEVEL_W ] ) &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
!Correspond to Store_one_budget (CART)
allocate( zdata3d( size(pvar,1), size(pvar,2), size(pvar,3) ) )
! Loop on the processes
do ji = 1, size(pvar,6)
zdata3d(:,:,:) = pvar(:, :, :, 1, 1, ji)

WAUTELET Philippe
committed
if ( gsplit ) then
if ( htype /= 'CART' ) call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented for these dimensions and htype/=CART' )
if ( htype == 'CART' .and. .not. oicp .and. .not. ojcp ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2, 3 ], kbutimepos = 4 )

WAUTELET Philippe
committed
!Data is distributed between all the processes
tzfield%cdir = 'XY'
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
call IO_Field_write_box( tzfile, tzfield, 'BUDGET', &
Reshape( zdata3d, [ Size(zdata3d,1), Size(zdata3d,2), Size(zdata3d,3), 1 ] ) , &
kil + jphext, kih + jphext, kjl + jphext, kjh + jphext, &
koffset= [ 0, 0, 0, ( nbutshift - 1 ) * nbusubwrite ] )
else
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if

WAUTELET Philippe
committed
if ( htype == 'CART' .and. .not. oicp .and. .not. ojcp ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2, 3 ] )

WAUTELET Philippe
committed
!Data is distributed between all the processes
tzfield%cdir = 'XY'
call IO_Field_write_box( tzfile, tzfield, 'BUDGET', zdata3d, &
kil + jphext, kih + jphext, kjl + jphext, kjh + jphext )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2, 3 ] )

WAUTELET Philippe
committed
!Data is already collected on the master process

WAUTELET Philippe
committed
! tzfield%cdir = '--'

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata3d )
end if
end if
end do
deallocate( zdata3d )

WAUTELET Philippe
committed
elseif ( ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_MASK_LEVEL &
.or. tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_MASK_LEVEL_W ) &

WAUTELET Philippe
committed
.and. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_TIME &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_MASK_NBUMASK &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_NGROUPS ) then
!Correspond to Store_one_budget (MASK)
allocate( zdata3d( size(pvar,3), size(pvar,4), size(pvar,5) ) )
! Loop on the processes
do ji = 1, size(pvar,6)
zdata3d(:,:,:) = pvar(1, 1, :, :, :, ji)

WAUTELET Philippe
committed
if ( gsplit ) then

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4, 5 ], kbutimepos = 2 )

WAUTELET Philippe
committed
!Create the metadata of the field (has to be done only once)
if ( nbutshift == 1 ) call IO_Field_create( tzfile, tzfield )
! call IO_Field_partial_write( tzfile, tzfield, zdata3d(:,:,:), koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite, 0 ] )
call IO_Field_write( tzfile, tzfield, zdata3d(:,:,:), koffset= [ 0, ( nbutshift - 1 ) * nbusubwrite, 0 ] )
else

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4, 5 ] )

WAUTELET Philippe
committed
call IO_Field_write( tzfile, tzfield, zdata3d )
end if
end do
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_LES_SV &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_LES_MASK ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( nles_masks /= Size( pvar, 6 ) ) &
call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'last dimension size of pvar is not equal to nles_masks (variable ' &
// Trim( tpfields(1)%cmnhname ) // ')' )
allocate( zdata3d( size(pvar,3), size(pvar,4), size(pvar,5) ) )
! Loop on the masks (1 written variable per mask)
do ji = 1, size(pvar,6)
zdata3d(:,:,:) = pvar(1, 1, :, :, :, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata3d )
end do
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(3) == NMNHDIM_BUDGET_LES_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_BUDGET_LES_SV &
.and. tpfields(1)%ndimlist(6) == NMNHDIM_BUDGET_TERM ) then

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
allocate( zdata3d( size(pvar,3), size(pvar,4), size(pvar,5) ) )
! Loop on the masks (1 written variable per mask)
do ji = 1, size(pvar,6)
zdata3d(:,:,:) = pvar(1, 1, :, :, :, ji)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 3, 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata3d )
end do
deallocate( zdata3d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(1) == NMNHDIM_SPECTRA_SPEC_NI &
.and. tpfields(1)%ndimlist(3) == NMNHDIM_SPECTRA_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_COMPLEX ) then
!Correspond to LES_DIACHRO_SPEC

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata4d( size(pvar,1), size(pvar,3), size(pvar,4), size(pvar,5) ) )
zdata4d(:,:,:,:) = pvar(:, 1, :, :, :, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 1, 3, 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata4d )
deallocate( zdata4d )

WAUTELET Philippe
committed
else if ( tpfields(1)%ndimlist(2) == NMNHDIM_SPECTRA_SPEC_NJ &
.and. tpfields(1)%ndimlist(3) == NMNHDIM_SPECTRA_LEVEL &
.and. ( tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_TIME &
.or. tpfields(1)%ndimlist(4) == NMNHDIM_BUDGET_LES_AVG_TIME ) &
.and. tpfields(1)%ndimlist(5) == NMNHDIM_COMPLEX ) then
!Correspond to LES_DIACHRO_SPEC

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if
if ( Size( tpfields ) /= 1 ) call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'wrong size of tpfields (variable '//trim(tpfields(1)%cmnhname)//')' )
allocate( zdata4d( size(pvar,2), size(pvar,3), size(pvar,4), size(pvar,5) ) )
zdata4d(:,:,:,:) = pvar(1, :, :, :, :, 1)

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(1), tzfield, [ 2, 3, 4, 5 ] )
CALL IO_Field_write( tzfile, tzfield, zdata4d )
deallocate( zdata4d )
else
call Print_msg( NVERB_FATAL, 'IO', 'Write_diachro_nc4', &
'case not yet implemented (variable '//trim(tpfields(1)%cmnhname)//')' )
end if
! case (5)
! case (6)
case default

WAUTELET Philippe
committed
if ( gsplit ) then
call Print_msg( NVERB_ERROR, 'IO', 'Write_diachro_nc4', Trim( tzfile%cname ) // &
': group ' // Trim( hgroup ) //' gsplit=T not implemented' )
end if

WAUTELET Philippe
committed
! if ( All( tpfields(1)%ndimlist(:) /= NMNHDIM_UNKNOWN ) ) then
! tzfield%ndimlist(1) = tpfields(1)%ndimlist(1)
! tzfield%ndimlist(2) = tpfields(1)%ndimlist(2)
! tzfield%ndimlist(3) = tpfields(1)%ndimlist(3)
! tzfield%ndimlist(4) = tpfields(1)%ndimlist(4)
! tzfield%ndimlist(5) = tpfields(1)%ndimlist(5)
! tzfield%ndimlist(6:) = NMNHDIM_UNUSED
! end if
do ji = 1, Size( pvar, 6 )

WAUTELET Philippe
committed
call Prepare_diachro_write( tpfields(ji), tzfield, [ 1, 2, 3, 4, 5 ] )
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
CALL IO_Field_write( tzfile, tzfield, pvar(:, :, :, :, :, ji ) )
end do
end select
!Reset ndimlist (to prevent problems later)
tzfield%ndimlist(:) = NMNHDIM_UNKNOWN
TZFIELD%CMNHNAME = 'dates'
TZFIELD%CSTDNAME = ''
TZFIELD%CLONGNAME = 'dates'
TZFIELD%CUNITS = 'seconds since YYYY-MM-DD HH:MM:SS.S'
TZFIELD%CDIR = '--'
TZFIELD%CCOMMENT = 'Dates at the middle of the budget timesteps'
TZFIELD%NGRID = 0
TZFIELD%NTYPE = TYPEDATE
TZFIELD%NDIMS = 1
TZFIELD%LTIMEDEP = .FALSE.
if ( tpfields(1)%ndimlist(4) /= NMNHDIM_UNKNOWN .and. tpfields(1)%ndimlist(4) /= NMNHDIM_UNUSED) then
tzfield%ndimlist(1) = tpfields(1)%ndimlist(4)
tzfield%ndimlist(2:) = NMNHDIM_UNUSED
end if
CALL IO_Field_write( tzfile, tzfield, tpdates(:) )
!Reset ndimlist
tzfield%ndimlist(:) = NMNHDIM_UNKNOWN
!Restore id of the file root group ('/' group)
tzfile%nncid = isavencid

WAUTELET Philippe
committed
call Menu_diachro( tzfile, hgroup )
end subroutine Write_diachro_nc4

WAUTELET Philippe
committed
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
subroutine Prepare_diachro_write( tpfieldin, tpfieldout, kdims, kbutimepos )
use modd_field, only: NMNHDIM_BUDGET_TIME, NMNHDIM_UNUSED, NMNHMAXDIMS, tfielddata, tfield_metadata_base
class(tfield_metadata_base), intent(in) :: tpfieldin
type(tfielddata), intent(out) :: tpfieldout
integer, dimension(:), intent(in) :: kdims ! List of indices of dimensions to use
integer, optional, intent(in) :: kbutimepos
integer :: jdim
integer :: idims
print *,'PW: Prepare_diachro_write called for ',Trim( tpfieldin%cmnhname )
idims = Size( kdims )
if ( idims > NMNHMAXDIMS ) call Print_msg( NVERB_FATAL, 'IO', 'Prepare_diachro_write', &
'kdims is too big for ' //Trim( tpfieldin%cmnhname ) )
tpfieldout%cmnhname = tpfieldin%cmnhname
tpfieldout%cstdname = tpfieldin%cstdname
tpfieldout%clongname = tpfieldin%clongname
tpfieldout%cunits = tpfieldin%cunits
tpfieldout%cdir = '--'
tpfieldout%ccomment = tpfieldin%ccomment
tpfieldout%ngrid = tpfieldin%ngrid
tpfieldout%ntype = tpfieldin%ntype
tpfieldout%ltimedep = .false.
tpfieldout%ndims = idims
do jdim = 1, idims
tpfieldout%ndimlist(jdim) = tpfieldin%ndimlist(kdims(jdim))
end do
tpfieldout%ndimlist(idims + 1:) = NMNHDIM_UNUSED
!Add budget time dimension if required
if ( Present( kbutimepos ) ) then
! Note: if kbutimepos <= idims, the budget time dimension is assumed to be already present
! In that case, it is not necessary/useful to provide kbutimepos
if ( kbutimepos > idims ) then
if ( kbutimepos /= (idims + 1) ) call Print_msg( NVERB_FATAL, 'IO', 'Prepare_diachro_write', &
'unexpected value for kbutimepos for ' //Trim( tpfieldin%cmnhname ) )
tpfieldout%ndims = tpfieldout%ndims + 1
tpfieldout%ndimlist(kbutimepos) = NMNHDIM_BUDGET_TIME
end if
end if
end subroutine Prepare_diachro_write
end module mode_write_diachro