MODFLOW 6  version 6.9.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 1273 of file MemoryManager.f90.

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

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

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

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

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

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

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

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