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

Write a new variable to history file

nick

Herold
Member
Hi, I want to write a 2D variable to a history file. I'm in PhotosynthesisMod.F90 and have looked at GSSUN for an example of how to do this. Does the following look correct:

In the InitHistory subroutine I add the following, to simply write out data stored in the already existing mbb_patch variable:
this%mbb_patch(begp:endp) = spval call hist_addfld1d (fname='my_var', units='my units', & avgflag='A', long_name='my long name', & ptr_patch=this%mbb_patch)

Not sure if the first line assigning missing val is necessary but I'm copying the convention I see.

If I wanted to create and write out a completely new variable it looks like I'd have to add that new variable to the photosyns_type structure near the top of the file, e.g. real(r8), pointer, private :: my_new_var. Then fill my_new_var at the right place. Does this sound right?

Thanks.
 

oleson

Keith Oleson
CSEG and Liaisons
Staff member
The explanation for the first line assigning spval is (from the CLM Tutorial exercise):

"This is needed for history fields that remain uninitialized (NaN) for some points; to be safe, we do this for all history fields. NaN values cannot be output, so we instead ensure that any unused points are set to spval (“special value”) for fields that are output to history files. spval is a constant that signals to the history averager that that point should be excluded from averaging."

Your first example for mbb_patch looks correct (but the compiler and the history output will obviously tell you if you've done this correctly).

A completely new variable must also be allocated memory and initialized, e.g., this is done in subroutine InitAllocate for mbb_patch:

allocate(this%mbb_patch (begp:endp)) ; this%mbb_patch (:) = nan
 
Top