Write a new variable to history file

Status
Not open for further replies.

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
 
Status
Not open for further replies.
Back
Top