Refactor Idea using XML for histFldsMod.F90

The idea is that the code in histFldsMod (all the calls to hist_addfld) is very long and hard to manage/maintain. Another aspect of it is that I use a post-processing script to read in the file (as well as the at least one other file that has addfld calls) to put together an XML file that lists all of the history fields. This makes a nice table in the CLM User's Guide.

CLM UG History Fields Table

So the histFldsMod.F90 is the source and the XML is a file generated from it. The idea is to reverse that order. So the XML becomes the source and the bulk of what's in histFldsMod gets generated automatically from that XML file. I think it would be easier to maintain the XML rather than the code. The one part of the code that I don't see a way around are assigning the pointers for each item to the clm_type array that they resolve to.

Example history XML file:

This file is created anyway for the CLM UG. So it's already something that is managed.

<history_fields>

<field name='A10TMIN' units='K'
 long_name='10-day running mean of min 2-m temperature'
/>

<field name='A5TMIN' units='K'
 long_name='5-day running mean of min 2-m temperature'
/>
.
.
.

Example histFldsMod calls:

The calls to histAddFlds should really be moved to the modules that actually use the data that are saved. But, the calls become very simple only giving a name and a pointer with all other options in the XML file. So the options for units and long_name are all moved into the XML file. This would remove several thousand lines from histFldsMod (3k or so). I don't see

call hist_addfld1d (fname='FH2OSFC', ptr_col=cps%frac_h2osfc)

Example read of XML in CLM:

The reads of the XML file use XML reading already part of csm_share used for reading streams files which are simple XML files.

  • No labels