MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
memorymanagermodule::mem_reallocate Interface Reference
Collaboration diagram for memorymanagermodule::mem_reallocate:
Collaboration graph

Private Member Functions

subroutine reallocate_logical1d (alog, nrow, name, mem_path)
 Reallocate a 1-dimensional logical array. More...
 
subroutine reallocate_int1d (aint, nrow, name, mem_path)
 Reallocate a 1-dimensional integer array. More...
 
subroutine reallocate_int2d (aint, ncol, nrow, name, mem_path)
 Reallocate a 2-dimensional integer array. More...
 
subroutine reallocate_dbl1d (adbl, nrow, name, mem_path)
 Reallocate a 1-dimensional real array. More...
 
subroutine reallocate_dbl2d (adbl, ncol, nrow, name, mem_path)
 Reallocate a 2-dimensional real array. More...
 
subroutine reallocate_str1d (astr, ilen, nrow, name, mem_path)
 Reallocate a 1-dimensional defined length string array. More...
 
subroutine reallocate_charstr1d (acharstr1d, ilen, nrow, name, mem_path)
 Reallocate a 1-dimensional deferred length string array. More...
 

Detailed Description

Definition at line 82 of file MemoryManager.f90.

Member Function/Subroutine Documentation

◆ reallocate_charstr1d()

subroutine memorymanagermodule::mem_reallocate::reallocate_charstr1d ( type(characterstringtype), dimension(:), intent(inout), pointer, contiguous  acharstr1d,
integer(i4b), intent(in)  ilen,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]acharstr1dthe reallocated charstring array
[in]ilenstring length
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1272 of file MemoryManager.f90.

1273  type(CharacterStringType), dimension(:), pointer, contiguous, &
1274  intent(inout) :: acharstr1d !< the reallocated charstring array
1275  integer(I4B), intent(in) :: ilen !< string length
1276  integer(I4B), intent(in) :: nrow !< number of rows
1277  character(len=*), intent(in) :: name !< variable name
1278  character(len=*), intent(in) :: mem_path !< path where variable is stored
1279  ! -- local
1280  type(MemoryType), pointer :: mt
1281  logical(LGP) :: found
1282  type(CharacterStringType), dimension(:), allocatable :: astrtemp
1283  character(len=ilen) :: string
1284  integer(I4B) :: istat
1285  integer(I4B) :: isize
1286  integer(I4B) :: isize_old
1287  integer(I4B) :: nrow_old
1288  integer(I4B) :: n
1289  !
1290  ! -- Initialize string
1291  string = ''
1292  !
1293  ! -- Find and assign mt
1294  call get_from_memorystore(name, mem_path, mt, found)
1295  !
1296  ! -- reallocate astr1d
1297  if (found) then
1298  isize_old = mt%isize
1299  if (isize_old > 0) then
1300  nrow_old = size(acharstr1d)
1301  else
1302  nrow_old = 0
1303  end if
1304  !
1305  ! -- calculate isize
1306  isize = nrow
1307  !
1308  ! -- allocate astrtemp
1309  allocate (astrtemp(nrow), stat=istat, errmsg=errmsg)
1310  if (istat /= 0) then
1311  call allocate_error(name, mem_path, istat, isize)
1312  end if
1313  !
1314  ! -- copy existing values (only up to the new size to handle shrinking)
1315  do n = 1, min(nrow_old, nrow)
1316  astrtemp(n) = acharstr1d(n)
1317  call acharstr1d(n)%destroy()
1318  end do
1319  !
1320  ! -- destroy remaining elements if shrinking
1321  do n = nrow + 1, nrow_old
1322  call acharstr1d(n)%destroy()
1323  end do
1324  !
1325  ! -- fill new values with missing values
1326  do n = nrow_old + 1, nrow
1327  astrtemp(n) = string
1328  end do
1329  !
1330  ! -- deallocate mt pointer, repoint, recalculate isize
1331  deallocate (acharstr1d)
1332  !
1333  ! -- allocate astr1d
1334  allocate (acharstr1d(nrow), stat=istat, errmsg=errmsg)
1335  if (istat /= 0) then
1336  call allocate_error(name, mem_path, istat, isize)
1337  end if
1338  !
1339  ! -- fill the reallocated character array
1340  do n = 1, nrow
1341  acharstr1d(n) = astrtemp(n)
1342  call astrtemp(n)%destroy()
1343  end do
1344  !
1345  ! -- deallocate temporary storage
1346  deallocate (astrtemp)
1347  !
1348  ! -- reset memory manager values
1349  mt%acharstr1d => acharstr1d
1350  mt%element_size = ilen
1351  mt%isize = isize
1352  mt%nrealloc = mt%nrealloc + 1
1353  mt%master = .true.
1354  nvalues_astr = nvalues_astr + isize - isize_old
1355  write (mt%memtype, "(a,' LEN=',i0,' (',i0,')')") 'STRING', ilen, nrow
1356  else
1357  errmsg = "Programming error, variable '"//trim(name)//"' from '"// &
1358  trim(mem_path)//"' is not defined in the memory manager. Use "// &
1359  "mem_allocate instead."
1360  call store_error(errmsg, terminate=.true.)
1361  end if
Here is the call graph for this function:

◆ reallocate_dbl1d()

subroutine memorymanagermodule::mem_reallocate::reallocate_dbl1d ( real(dp), dimension(:), intent(inout), pointer, contiguous  adbl,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]adblthe reallocated 1d real array
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1498 of file MemoryManager.f90.

1499  real(DP), dimension(:), pointer, contiguous, intent(inout) :: adbl !< the reallocated 1d real array
1500  integer(I4B), intent(in) :: nrow !< number of rows
1501  character(len=*), intent(in) :: name !< variable name
1502  character(len=*), intent(in) :: mem_path !< path where variable is stored
1503  ! -- local
1504  type(MemoryType), pointer :: mt
1505  integer(I4B) :: istat
1506  integer(I4B) :: isize
1507  integer(I4B) :: i
1508  integer(I4B) :: isizeold
1509  integer(I4B) :: ifill
1510  logical(LGP) :: found
1511  ! -- code
1512  !
1513  ! -- Find and assign mt
1514  call get_from_memorystore(name, mem_path, mt, found)
1515  !
1516  ! -- Allocate adbl and then refill
1517  isize = nrow
1518  isizeold = size(mt%adbl1d)
1519  ifill = min(isizeold, isize)
1520  allocate (adbl(nrow), stat=istat, errmsg=errmsg)
1521  if (istat /= 0) then
1522  call allocate_error(name, mem_path, istat, isize)
1523  end if
1524  do i = 1, ifill
1525  adbl(i) = mt%adbl1d(i)
1526  end do
1527  !
1528  ! -- deallocate mt pointer, repoint, recalculate isize
1529  deallocate (mt%adbl1d)
1530  mt%adbl1d => adbl
1531  mt%element_size = dp
1532  mt%isize = isize
1533  mt%nrealloc = mt%nrealloc + 1
1534  mt%master = .true.
1535  nvalues_adbl = nvalues_adbl + isize - isizeold
1536  write (mt%memtype, "(a,' (',i0,')')") 'DOUBLE', isize
Here is the call graph for this function:

◆ reallocate_dbl2d()

subroutine memorymanagermodule::mem_reallocate::reallocate_dbl2d ( real(dp), dimension(:, :), intent(inout), pointer, contiguous  adbl,
integer(i4b), intent(in)  ncol,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]adblthe reallocated 2d real array
[in]ncolnumber of columns
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1541 of file MemoryManager.f90.

1542  real(DP), dimension(:, :), pointer, contiguous, intent(inout) :: adbl !< the reallocated 2d real array
1543  integer(I4B), intent(in) :: ncol !< number of columns
1544  integer(I4B), intent(in) :: nrow !< number of rows
1545  character(len=*), intent(in) :: name !< variable name
1546  character(len=*), intent(in) :: mem_path !< path where variable is stored
1547  ! -- local
1548  type(MemoryType), pointer :: mt
1549  logical(LGP) :: found
1550  integer(I4B) :: istat
1551  integer(I4B), dimension(2) :: ishape
1552  integer(I4B) :: i
1553  integer(I4B) :: j
1554  integer(I4B) :: isize
1555  integer(I4B) :: isizeold
1556  ! -- code
1557  !
1558  ! -- Find and assign mt
1559  call get_from_memorystore(name, mem_path, mt, found)
1560  !
1561  ! -- Allocate adbl and then refill
1562  ishape = shape(mt%adbl2d)
1563  isize = nrow * ncol
1564  isizeold = ishape(1) * ishape(2)
1565  allocate (adbl(ncol, nrow), stat=istat, errmsg=errmsg)
1566  if (istat /= 0) then
1567  call allocate_error(name, mem_path, istat, isize)
1568  end if
1569  ! Copy only what fits in the new array to handle shrinking
1570  do i = 1, min(ishape(2), nrow)
1571  do j = 1, min(ishape(1), ncol)
1572  adbl(j, i) = mt%adbl2d(j, i)
1573  end do
1574  end do
1575  !
1576  ! -- deallocate mt pointer, repoint, recalculate isize
1577  deallocate (mt%adbl2d)
1578  mt%adbl2d => adbl
1579  mt%element_size = dp
1580  mt%isize = isize
1581  mt%nrealloc = mt%nrealloc + 1
1582  mt%master = .true.
1583  nvalues_adbl = nvalues_adbl + isize - isizeold
1584  write (mt%memtype, "(a,' (',i0,',',i0,')')") 'DOUBLE', ncol, nrow
Here is the call graph for this function:

◆ reallocate_int1d()

subroutine memorymanagermodule::mem_reallocate::reallocate_int1d ( integer(i4b), dimension(:), intent(inout), pointer, contiguous  aint,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]aintthe reallocated integer array
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1408 of file MemoryManager.f90.

1409  integer(I4B), dimension(:), pointer, contiguous, intent(inout) :: aint !< the reallocated integer array
1410  integer(I4B), intent(in) :: nrow !< number of rows
1411  character(len=*), intent(in) :: name !< variable name
1412  character(len=*), intent(in) :: mem_path !< path where variable is stored
1413  ! -- local
1414  type(MemoryType), pointer :: mt
1415  logical(LGP) :: found
1416  integer(I4B) :: istat
1417  integer(I4B) :: isize
1418  integer(I4B) :: i
1419  integer(I4B) :: isizeold
1420  integer(I4B) :: ifill
1421  ! -- code
1422  !
1423  ! -- Find and assign mt
1424  call get_from_memorystore(name, mem_path, mt, found)
1425  !
1426  ! -- Allocate aint and then refill
1427  isize = nrow
1428  isizeold = size(mt%aint1d)
1429  ifill = min(isizeold, isize)
1430  allocate (aint(nrow), stat=istat, errmsg=errmsg)
1431  if (istat /= 0) then
1432  call allocate_error(name, mem_path, istat, isize)
1433  end if
1434  do i = 1, ifill
1435  aint(i) = mt%aint1d(i)
1436  end do
1437  !
1438  ! -- deallocate mt pointer, repoint, recalculate isize
1439  deallocate (mt%aint1d)
1440  mt%aint1d => aint
1441  mt%element_size = i4b
1442  mt%isize = isize
1443  mt%nrealloc = mt%nrealloc + 1
1444  mt%master = .true.
1445  nvalues_aint = nvalues_aint + isize - isizeold
Here is the call graph for this function:

◆ reallocate_int2d()

subroutine memorymanagermodule::mem_reallocate::reallocate_int2d ( integer(i4b), dimension(:, :), intent(inout), pointer, contiguous  aint,
integer(i4b), intent(in)  ncol,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]aintthe reallocated 2d integer array
[in]ncolnumber of columns
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1450 of file MemoryManager.f90.

1451  integer(I4B), dimension(:, :), pointer, contiguous, intent(inout) :: aint !< the reallocated 2d integer array
1452  integer(I4B), intent(in) :: ncol !< number of columns
1453  integer(I4B), intent(in) :: nrow !< number of rows
1454  character(len=*), intent(in) :: name !< variable name
1455  character(len=*), intent(in) :: mem_path !< path where variable is stored
1456  ! -- local
1457  type(MemoryType), pointer :: mt
1458  logical(LGP) :: found
1459  integer(I4B) :: istat
1460  integer(I4B), dimension(2) :: ishape
1461  integer(I4B) :: i
1462  integer(I4B) :: j
1463  integer(I4B) :: isize
1464  integer(I4B) :: isizeold
1465  ! -- code
1466  !
1467  ! -- Find and assign mt
1468  call get_from_memorystore(name, mem_path, mt, found)
1469  !
1470  ! -- Allocate aint and then refill
1471  ishape = shape(mt%aint2d)
1472  isize = nrow * ncol
1473  isizeold = ishape(1) * ishape(2)
1474  allocate (aint(ncol, nrow), stat=istat, errmsg=errmsg)
1475  if (istat /= 0) then
1476  call allocate_error(name, mem_path, istat, isize)
1477  end if
1478  ! Copy only what fits in the new array to handle shrinking
1479  do i = 1, min(ishape(2), nrow)
1480  do j = 1, min(ishape(1), ncol)
1481  aint(j, i) = mt%aint2d(j, i)
1482  end do
1483  end do
1484  !
1485  ! -- deallocate mt pointer, repoint, recalculate isize
1486  deallocate (mt%aint2d)
1487  mt%aint2d => aint
1488  mt%element_size = i4b
1489  mt%isize = isize
1490  mt%nrealloc = mt%nrealloc + 1
1491  mt%master = .true.
1492  nvalues_aint = nvalues_aint + isize - isizeold
1493  write (mt%memtype, "(a,' (',i0,',',i0,')')") 'INTEGER', ncol, nrow
Here is the call graph for this function:

◆ reallocate_logical1d()

subroutine memorymanagermodule::mem_reallocate::reallocate_logical1d ( logical(lgp), dimension(:), intent(inout), pointer, contiguous  alog,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in,out]alogthe reallocated logical array
[in]nrownumber of rows
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1366 of file MemoryManager.f90.

1367  logical(LGP), dimension(:), pointer, contiguous, intent(inout) :: alog !< the reallocated logical array
1368  integer(I4B), intent(in) :: nrow !< number of rows
1369  character(len=*), intent(in) :: name !< variable name
1370  character(len=*), intent(in) :: mem_path !< path where variable is stored
1371  ! -- local
1372  type(MemoryType), pointer :: mt
1373  logical(LGP) :: found
1374  integer(I4B) :: istat
1375  integer(I4B) :: isize
1376  integer(I4B) :: i
1377  integer(I4B) :: isizeold
1378  integer(I4B) :: ifill
1379  ! -- code
1380  !
1381  ! -- Find and assign mt
1382  call get_from_memorystore(name, mem_path, mt, found)
1383  !
1384  ! -- Allocate aint and then refill
1385  isize = nrow
1386  isizeold = size(mt%alogical1d)
1387  ifill = min(isizeold, isize)
1388  allocate (alog(nrow), stat=istat, errmsg=errmsg)
1389  if (istat /= 0) then
1390  call allocate_error(name, mem_path, istat, isize)
1391  end if
1392  do i = 1, ifill
1393  alog(i) = mt%alogical1d(i)
1394  end do
1395  !
1396  ! -- deallocate mt pointer, repoint, recalculate isize
1397  deallocate (mt%alogical1d)
1398  mt%alogical1d => alog
1399  mt%element_size = lgp
1400  mt%isize = isize
1401  mt%nrealloc = mt%nrealloc + 1
1402  mt%master = .true.
1403  nvalues_alogical = nvalues_alogical + isize - isizeold
Here is the call graph for this function:

◆ reallocate_str1d()

subroutine memorymanagermodule::mem_reallocate::reallocate_str1d ( character(len=ilen), dimension(:), intent(inout), pointer, contiguous  astr,
integer(i4b), intent(in)  ilen,
integer(i4b), intent(in)  nrow,
character(len=*), intent(in)  name,
character(len=*), intent(in)  mem_path 
)
private
Parameters
[in]ilenstring length
[in]nrownumber of rows
[in,out]astrthe reallocated string array
[in]namevariable name
[in]mem_pathpath where variable is stored

Definition at line 1190 of file MemoryManager.f90.

1191  integer(I4B), intent(in) :: ilen !< string length
1192  integer(I4B), intent(in) :: nrow !< number of rows
1193  character(len=ilen), dimension(:), pointer, contiguous, intent(inout) :: astr !< the reallocated string array
1194  character(len=*), intent(in) :: name !< variable name
1195  character(len=*), intent(in) :: mem_path !< path where variable is stored
1196  ! -- local
1197  type(MemoryType), pointer :: mt
1198  logical(LGP) :: found
1199  character(len=ilen), dimension(:), allocatable :: astrtemp
1200  integer(I4B) :: istat
1201  integer(I4B) :: isize
1202  integer(I4B) :: isize_old
1203  integer(I4B) :: nrow_old
1204  integer(I4B) :: n
1205  !
1206  ! -- Find and assign mt
1207  call get_from_memorystore(name, mem_path, mt, found)
1208  !
1209  ! -- reallocate astr1d
1210  if (found) then
1211  isize_old = mt%isize
1212  if (isize_old > 0) then
1213  nrow_old = size(astr)
1214  else
1215  nrow_old = 0
1216  end if
1217  !
1218  ! -- calculate isize
1219  isize = nrow
1220  !
1221  ! -- allocate astrtemp
1222  allocate (astrtemp(nrow), stat=istat, errmsg=errmsg)
1223  if (istat /= 0) then
1224  call allocate_error(name, mem_path, istat, isize)
1225  end if
1226  !
1227  ! -- copy existing values (only up to the new size to handle shrinking)
1228  do n = 1, min(nrow_old, nrow)
1229  astrtemp(n) = astr(n)
1230  end do
1231  !
1232  ! -- fill new values with missing values
1233  do n = nrow_old + 1, nrow
1234  astrtemp(n) = ''
1235  end do
1236  !
1237  ! -- deallocate mt pointer, repoint, recalculate isize
1238  deallocate (astr)
1239  !
1240  ! -- allocate astr1d
1241  allocate (astr(nrow), stat=istat, errmsg=errmsg)
1242  if (istat /= 0) then
1243  call allocate_error(name, mem_path, istat, isize)
1244  end if
1245  !
1246  ! -- fill the reallocate character array
1247  do n = 1, nrow
1248  astr(n) = astrtemp(n)
1249  end do
1250  !
1251  ! -- deallocate temporary storage
1252  deallocate (astrtemp)
1253  !
1254  ! -- reset memory manager values
1255  mt%astr1d => astr
1256  mt%element_size = ilen
1257  mt%isize = isize
1258  mt%nrealloc = mt%nrealloc + 1
1259  mt%master = .true.
1260  nvalues_astr = nvalues_astr + isize - isize_old
1261  write (mt%memtype, "(a,' LEN=',i0,' (',i0,')')") 'STRING', ilen, nrow
1262  else
1263  errmsg = "Programming error, variable '"//trim(name)//"' from '"// &
1264  trim(mem_path)//"' is not defined in the memory manager. Use "// &
1265  "mem_allocate instead."
1266  call store_error(errmsg, terminate=.true.)
1267  end if
Here is the call graph for this function:

The documentation for this interface was generated from the following file: