Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

How to declare a new variable in .f90 file and write the new variable to history file?

liyongkang

liyongkang
New Member
I want to declare a variable to storage cumulative NPP and write it to history file. The cumulative NPP refers to total NPP from Jan. 1 to current run time. If the model is run to the next year, it is accumulated from the new year.
I guess the cumulative NPP variable needs to be declared in the CNVegCarbonFluxType.F90. Such as:

type, public :: cnveg_carbonflux_type
......
real(r8), pointer :: sumnpp_patch (:) ! (gC/m2/s) cumulative NPP
......

then, I need to give an initial value of nan:

subroutine InitAllocate(this, bounds, carbon_type)
......
allocate(this%sumnpp_patch (begp:endp)) ; this%sumnpp_patch (:) = nan
......
end subroutine InitAllocate

then, I need to call the hist_addfld1d function to output it to the history file:

this%sumnpp_patch(begp:endp) = spval
call hist_addfld1d (fname='SUMNPP', units='gC/m^2/s', &
avgflag='A', long_name='cumulative NPP', &
ptr_patch=this%sumnpp_patch)

then, set carbon state fluxes in subroutine SetValues: this%sumnpp_patch(i) = value_patch

Finally, I don't know how to compute the npp of the last time node in " subroutine Summary_carbonflux() " and summed with the cumulative npp of the last time node.
I would be grateful if you could help me out.
 
Top