@@ -269,7 +269,8 @@ end subroutine load_models
269
269
subroutine load_exchanges (model_loadmask , iout )
270
270
! -- modules
271
271
use MemoryHelperModule, only: create_mem_path
272
- use MemoryManagerModule, only: mem_setptr, mem_allocate, mem_deallocate
272
+ use MemoryManagerModule, only: mem_setptr, mem_allocate, &
273
+ mem_deallocate, get_isize
273
274
use CharacterStringModule, only: CharacterStringType
274
275
use SimVariablesModule, only: idm_context, simfile
275
276
use SourceCommonModule, only: idm_subcomponent_type, ifind_charstr
@@ -301,7 +302,7 @@ subroutine load_exchanges(model_loadmask, iout)
301
302
character (len= LENCOMPONENTNAME) :: sc_type, sc_name, mtype
302
303
class(StaticPkgLoadBaseType), pointer :: static_loader
303
304
class(DynamicPkgLoadBaseType), pointer :: dynamic_loader
304
- integer (I4B) :: n, m1_idx, m2_idx, irem
305
+ integer (I4B) :: n, m1_idx, m2_idx, irem, isize
305
306
!
306
307
! -- set input memory path
307
308
input_mempath = create_mem_path(' SIM' , ' NAM' , idm_context)
@@ -360,8 +361,13 @@ subroutine load_exchanges(model_loadmask, iout)
360
361
mfname = mfnames(irem)
361
362
mname = mnames(irem)
362
363
mempath = create_mem_path(component= mname, context= idm_context)
363
- call mem_allocate(ncelldim, ' NCELLDIM' , mempath)
364
- ncelldim = remote_model_ndim(mtype, mfname)
364
+ call get_isize(' NCELLDIM' , mempath, isize)
365
+ if (isize < 0 ) then
366
+ call mem_allocate(ncelldim, ' NCELLDIM' , mempath)
367
+ ncelldim = remote_model_ndim(mtype, mfname)
368
+ else
369
+ call mem_setptr(ncelldim, ' NCELLDIM' , mempath)
370
+ end if
365
371
else
366
372
nullify (ncelldim)
367
373
end if
@@ -393,13 +399,23 @@ subroutine load_exchanges(model_loadmask, iout)
393
399
deallocate (static_loader)
394
400
end if
395
401
!
396
- ! -- deallocate ncelldim as all input has been loaded
397
- if (associated (ncelldim)) call mem_deallocate(ncelldim)
398
- !
399
402
end if
400
403
!
401
404
end do
402
405
!
406
+ ! -- clean up temporary NCELLDIM for remote models
407
+ do n = 1 , size (mnames)
408
+ if (model_loadmask(n) == 0 ) then
409
+ mname = mnames(n)
410
+ mempath = create_mem_path(component= mname, context= idm_context)
411
+ call get_isize(' NCELLDIM' , mempath, isize)
412
+ if (isize > 0 ) then
413
+ call mem_setptr(ncelldim, ' NCELLDIM' , mempath)
414
+ call mem_deallocate(ncelldim)
415
+ end if
416
+ end if
417
+ end do
418
+ !
403
419
! -- return
404
420
return
405
421
end subroutine load_exchanges
0 commit comments