Skip to content
Snippets Groups Projects
Commit 189ccba1 authored by WAUTELET Philippe's avatar WAUTELET Philippe
Browse files

Philippe 14/10/2021: dynamically allocate tfieldlist (+ reallocate if necessary)

parent 754627f2
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
! P. Wautelet 10/11/2020: new data structures for netCDF dimensions ! P. Wautelet 10/11/2020: new data structures for netCDF dimensions
! P. Wautelet 24/09/2021: add Fill_tfielddata and use it as a custom constructor for tfielddata type ! P. Wautelet 24/09/2021: add Fill_tfielddata and use it as a custom constructor for tfielddata type
! P. Wautelet 08/10/2021: add 2 new dimensions: LW_bands (NMNHDIM_NLWB) and SW_bands (NMNHDIM_NSWB) ! P. Wautelet 08/10/2021: add 2 new dimensions: LW_bands (NMNHDIM_NLWB) and SW_bands (NMNHDIM_NSWB)
! P. Wautelet 14/10/2021: dynamically allocate tfieldlist (+ reallocate if necessary)
!----------------------------------------------------------------- !-----------------------------------------------------------------
module modd_field module modd_field
...@@ -26,9 +27,11 @@ use NETCDF, only: NF90_FILL_INT, NF90_FILL_REAL ...@@ -26,9 +27,11 @@ use NETCDF, only: NF90_FILL_INT, NF90_FILL_REAL
implicit none implicit none
integer, parameter :: NMNHMAXDIMS = 6 ! Cannot be less than 6 integer, parameter :: NMNHMAXDIMS = 6 ! Cannot be less than 6
INTEGER,PARAMETER :: MAXFIELDS = 250
INTEGER,PARAMETER :: TYPEUNDEF = -1, TYPEINT = 1, TYPELOG = 2, TYPEREAL = 3, TYPECHAR = 4, TYPEDATE = 5 INTEGER,PARAMETER :: TYPEUNDEF = -1, TYPEINT = 1, TYPELOG = 2, TYPEREAL = 3, TYPECHAR = 4, TYPEDATE = 5
! !
INTEGER, PARAMETER :: NMAXFIELDINIT = 200 !Initial maximum number of fields in tfieldlist
INTEGER, PARAMETER :: NMAXFIELDSTEP = 50 !Number of fields to add each time tfieldlist is too small
integer, parameter :: NMNHDIM_UNKNOWN = -2 integer, parameter :: NMNHDIM_UNKNOWN = -2
!For efficient use of memory, it is better that all values for real dimensions be contiguous !For efficient use of memory, it is better that all values for real dimensions be contiguous
...@@ -115,6 +118,8 @@ integer, dimension(0:8,3), parameter :: NMNHDIM_ARAKAWA = reshape( [ & ...@@ -115,6 +118,8 @@ integer, dimension(0:8,3), parameter :: NMNHDIM_ARAKAWA = reshape( [ &
NMNHDIM_NI_U, NMNHDIM_NJ_V, NMNHDIM_LEVEL_W] & ! fw point (=uvw point) NMNHDIM_NI_U, NMNHDIM_NJ_V, NMNHDIM_LEVEL_W] & ! fw point (=uvw point)
, shape = [ 9, 3 ], order = [ 2, 1 ] ) , shape = [ 9, 3 ], order = [ 2, 1 ] )
INTEGER, SAVE :: NMAXFIELDS !Maximum number of fields in tfieldlist (value is automatically increased if too small)
TYPE TFIELDPTR_C0D TYPE TFIELDPTR_C0D
CHARACTER(LEN=:), POINTER :: DATA => NULL() CHARACTER(LEN=:), POINTER :: DATA => NULL()
END TYPE TFIELDPTR_C0D END TYPE TFIELDPTR_C0D
...@@ -216,7 +221,7 @@ TYPE, extends( tfield_metadata_base ) :: TFIELDDATA ...@@ -216,7 +221,7 @@ TYPE, extends( tfield_metadata_base ) :: TFIELDDATA
CHARACTER(LEN=4) :: CLBTYPE = 'NONE' !Type of the lateral boundary (LBX,LBY,LBXU,LBYV) CHARACTER(LEN=4) :: CLBTYPE = 'NONE' !Type of the lateral boundary (LBX,LBY,LBXU,LBYV)
LOGICAL :: LTIMEDEP = .FALSE. !Is the field time-dependent? LOGICAL :: LTIMEDEP = .FALSE. !Is the field time-dependent?
! !
INTEGER :: NMODELMAX = -1 !Number of models for which the field has been allocated INTEGER :: NMODELMAX = -1 !Number of models for which the field has been allocated (default value must be negative)
! !
TYPE(TFIELDPTR_C0D),DIMENSION(:),ALLOCATABLE :: TFIELD_C0D !Pointer to the character string fields (one per nested mesh) TYPE(TFIELDPTR_C0D),DIMENSION(:),ALLOCATABLE :: TFIELD_C0D !Pointer to the character string fields (one per nested mesh)
TYPE(TFIELDPTR_C1D),DIMENSION(:),ALLOCATABLE :: TFIELD_C1D !Pointer to the character string 1D fields (one per nested mesh) TYPE(TFIELDPTR_C1D),DIMENSION(:),ALLOCATABLE :: TFIELD_C1D !Pointer to the character string 1D fields (one per nested mesh)
...@@ -243,7 +248,7 @@ END TYPE TFIELDDATA ...@@ -243,7 +248,7 @@ END TYPE TFIELDDATA
! !
integer, save :: NFIELDS_USED = 0 integer, save :: NFIELDS_USED = 0
LOGICAL, SAVE :: LFIELDLIST_ISINIT = .FALSE. LOGICAL, SAVE :: LFIELDLIST_ISINIT = .FALSE.
TYPE(TFIELDDATA),DIMENSION(MAXFIELDS),SAVE :: TFIELDLIST TYPE(TFIELDDATA), ALLOCATABLE, DIMENSION(:), SAVE :: TFIELDLIST
interface TFIELDDATA interface TFIELDDATA
module procedure :: Fill_tfielddata module procedure :: Fill_tfielddata
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
! P. Wautelet 23/01/2020: split in modd_field.f90 and mode_field.f90 ! P. Wautelet 23/01/2020: split in modd_field.f90 and mode_field.f90
! JL Redelsperger 03/2021: add variables for Ocean LES and auto-coupled version ! JL Redelsperger 03/2021: add variables for Ocean LES and auto-coupled version
! P. Wautelet 08/10/2021: add Goto_model_1field + Add_field2list procedures + remove Fieldlist_nmodel_resize ! P. Wautelet 08/10/2021: add Goto_model_1field + Add_field2list procedures + remove Fieldlist_nmodel_resize
! P. Wautelet 14/10/2021: dynamically allocate tfieldlist (+ reallocate if necessary)
!----------------------------------------------------------------- !-----------------------------------------------------------------
module mode_field module mode_field
...@@ -70,17 +71,14 @@ INTEGER,INTENT(IN),OPTIONAL :: KMODEL ...@@ -70,17 +71,14 @@ INTEGER,INTENT(IN),OPTIONAL :: KMODEL
INTEGER :: IMODEL INTEGER :: IMODEL
CHARACTER(LEN=42) :: YMSG CHARACTER(LEN=42) :: YMSG
! !
!F90/95: TFIELDLIST(1) = TFIELDDATA('UT','x_wind','m s-1','XY','X_Y_Z_U component of wind',2)
!F2003:
!TFIELDLIST(1) = TFIELDDATA(CMNHNAME='UT',CSTDNAME='x_wind',CUNITS='m s-1',CDIR='XY',&
! CCOMMENT='X_Y_Z_U component of wind',NGRID=2)
!
CALL PRINT_MSG(NVERB_DEBUG,'GEN','INI_FIELD_LIST','called') CALL PRINT_MSG(NVERB_DEBUG,'GEN','INI_FIELD_LIST','called')
IF (LFIELDLIST_ISINIT) THEN IF (LFIELDLIST_ISINIT) THEN
CALL PRINT_MSG(NVERB_ERROR,'GEN','INI_FIELD_LIST','already called') CALL PRINT_MSG(NVERB_ERROR,'GEN','INI_FIELD_LIST','already called')
RETURN RETURN
END IF END IF
LFIELDLIST_ISINIT = .TRUE. LFIELDLIST_ISINIT = .TRUE.
Allocate( tfieldlist(NMAXFIELDINIT) )
NMAXFIELDS = NMAXFIELDINIT
! !
IF (PRESENT(KMODEL)) THEN IF (PRESENT(KMODEL)) THEN
IMODEL = KMODEL IMODEL = KMODEL
...@@ -3098,7 +3096,7 @@ call Add_field2list( TFIELDDATA( & ...@@ -3098,7 +3096,7 @@ call Add_field2list( TFIELDDATA( &
LTIMEDEP = .FALSE. ) ) LTIMEDEP = .FALSE. ) )
! !
! !
WRITE(YMSG,'("number of used fields=",I4," out of ",I4)') nfields_used-1,MAXFIELDS WRITE(YMSG,'("number of used fields=",I4," out of ",I4)') nfields_used-1,NMAXFIELDS
CALL PRINT_MSG(NVERB_INFO,'GEN','INI_FIELD_LIST',TRIM(YMSG)) CALL PRINT_MSG(NVERB_INFO,'GEN','INI_FIELD_LIST',TRIM(YMSG))
! !
#if 0 #if 0
...@@ -3749,11 +3747,17 @@ implicit none ...@@ -3749,11 +3747,17 @@ implicit none
type(tfielddata) :: tpfield type(tfielddata) :: tpfield
CHARACTER(LEN=42) :: YMSG character(len=64) :: ymsg
type(tfielddata), allocatable, dimension(:) :: tzfieldlistnew
if ( nfields_used >= MAXFIELDS ) then
WRITE(YMSG,'( "nfields_used>=MAXFIELDS (",I5,")" )') MAXFIELDS !Check if tfieldlist big enough and enlarge it if necessary
CALL PRINT_MSG(NVERB_FATAL,'GEN','INI_FIELD_LIST',TRIM(YMSG)) if ( nfields_used >= NMAXFIELDS ) then
Allocate( tzfieldlistnew(nmaxfields + nmaxfieldstep) )
tzfieldlistnew(1 : nmaxfields) = tfieldlist(1 : nmaxfields)
call Move_alloc( from = tzfieldlistnew, to = tfieldlist )
nmaxfields = nmaxfields + nmaxfieldstep
Write( ymsg, '( "nmaxfields increased from ", i5, " to ", i5 )') nmaxfields - nmaxfieldstep, nmaxfields
call Print_msg( NVERB_DEBUG, 'GEN', 'Add_field2list', Trim( ymsg ) )
end if end if
nfields_used = nfields_used + 1 nfields_used = nfields_used + 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment