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 get compute the npp of the last time node in " subroutine Summary_carbonflux() " and summed with the cumulative npp of the last time node.(In fact, I just need to get the NPP of the last time node in gC/m^2. Since the CTSM runs at the same time interval, I just multiply the final cumulative amount by the time interval. For example, my run interval is days. Then I only need to multiply 60*60*24 at the end of the year.)
I would be grateful if you could help me out.
 

oleson

Keith Oleson
CSEG and Liaisons
Staff member
If I understand what you are trying to do it seems like it would be easier to just output NPP on an annual basis in a history file and then just multiply that NPP (in gC/m2/s) by the number of seconds in a year to get NPP in gC/m2 (per year).
 

liyongkang

liyongkang
New Member
If I understand what you are trying to do it seems like it would be easier to just output NPP on an annual basis in a history file and then just multiply that NPP (in gC/m2/s) by the number of seconds in a year to get NPP in gC/m2 (per year).
Thank you for your reply.
My ultimate goal is not to get an annual cumulative NPP. My goal is to get total NPP from Jan. 1 to current run time(such as,the cumulative NPP January 1 to May 31 and January 1 to September 30). Then, I can add my own modules to the CESM model based on this cumulative NPP variable.
 

oleson

Keith Oleson
CSEG and Liaisons
Staff member
I think you could make use of the accumulator functions:

src/main/accumulMod.F90

There are some examples of variables that use these functions in the code that are used to trigger other actions, for example, growing degree days in TemperatureType.F90
 

liyongkang

liyongkang
New Member
I think you could make use of the accumulator functions:

src/main/accumulMod.F90

There are some examples of variables that use these functions in the code that are used to trigger other actions, for example, growing degree days in TemperatureType.F90
Thanks a lot. I'll go check it out now.
 
Top