Clean up use and implementation of accumulMod
- Dominant language
- Fortran
- Stars
- 352
- Forks
- 361
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
**Bill Sacks < sacks@ucar.edu > - 2014-08-05 15:32:30 -0600**
**Bugzilla Id:** [2023](http://bugz.cgd.ucar.edu/show_bug.cgi?id=2023)
**Bugzilla CC:** erik@ucar.edu, muszala@ucar.edu, mvertens@ucar.edu, rfisher@ucar.edu,
Currently, on Mariana's refactor branch, there is a lot of verbosity and repeated boilerplate code needed in the InitAccVars routines, which initialize variables associated with time-accumulated fields. For example:
```Fortran
begp = bounds%begp; endp = bounds%endp
! Allocate needed dynamic memory for single level pft field
allocate(rbufslp(begp:endp), stat=ier)
if (ier/=0) then
write(iulog,*)' in '
call endrun(msg=" allocation error for rbufslp"//&
errMsg(__FILE__, __LINE__))
endif
nstep = get_nstep()
call extract_accum_field ('AGDDTW', rbufslp, nstep)
this%agddtw_patch(begp:endp) = rbufslp(begp:endp)
call extract_accum_field ('AGDD', rbufslp, nstep)
this%agdd_patch(begp:endp) = rbufslp(begp:endp)
deallocate(rbufslp)
```
Could this be replaced by simply the following?:
```Fortran
call extract_accum_field('AGDDTW', this%agddtw_patch(bounds%begp:bounds%endp))
call extract_accum_field('AGDD', this%agdd_patch(begp:endp))
```
The two major changes here are:
(1) the extract_accum_field routine gets nstep, rather than requiring the caller to obtain and pass in this value.
(2) I avoid the use of rbufslp - which may be needed in some cases, but doesn't appear to be needed here.
Edit (2019-11-15): It looks like rbufslp and similar variables are used in order to pass in pointers with particular lower bounds. I think this isn't needed with the current setup of having these routines always called outside a clump loop. But even if this is needed (e.g., to allow calling these routines from inside a clump loop), I think we could avoid this with a mechanism like what's suggested in https://github.com/ESCOMP/CTSM/issues/30#issuecomment-554031145.
Contributor guide
Assessment
This issue has not been assessed yet.