MPAS-Dev / MPAS-Model

Repository for MPAS models and shared framework releases.
238 stars 317 forks source link

Add arbitrary registry attributes #1101

Closed dimomatt closed 1 year ago

dimomatt commented 1 year ago

This PR allows the addition of arbitrary attributes to variables defined in Registry.xml.

In pursuit of CF compliance, certain attributes will need to be added to variables. To make this easier, this pull request allows for the addition of arbitrary attributes by looping over all attributes in a variable, as opposed to hardcoding them in. Some support functions were also created to filter out attributes that aren't used in output files and to allow for the modification of attribute names if they have a different name in the code (namely, description vs. long_name).

dimomatt commented 1 year ago

Testing has been done to compare output in structs_and_variables.inc on develop vs this branch. Changes appear to be limited to the replacement of single quotes with double quotes, and the addition of attributes that were not hard coded to be included on develop.

mgduda commented 1 year ago

Testing has been done to compare output in structs_and_variables.inc on develop vs this branch. Changes appear to be limited to the replacement of single quotes with double quotes, and the addition of attributes that were not hard coded to be included on develop.

Which additional attributes are being included? We can add those to the list of ignored attributes. I think we should aim to get identical (with the exception of quotes v. apostrophes) generated code.

mgduda commented 1 year ago

I think there's just one final issue. If we add the missing_value attribute to both a var_array and one of its constituent vars, e.g.,

<var_array name="arrTest" type="real" dimensions="nCells" missing_value="FILLVAL">
        <var name="test1" units="units1" description="Test var 1 in a var_array" array_group="arrTest" missing_value="-1.0"/>
        <var name="test2" units="units2" description="Test var 2 in a var_array" array_group="arrTest"/>             
</var_array>

the current develop branch generates the following in structs_and_variables.inc:

         call mpas_add_att(r2Ptr % attLists(const_index) % attList, 'long_name', 'Test var 1 in a var_array')
         call mpas_add_att(r2Ptr % attLists(const_index) % attList, 'units', 'units1')
         call mpas_add_att(r2Ptr % attLists(const_index) % attList, '_FillValue', MPAS_REAL_FILLVAL)

So, the missing_value attribute on constituents is ignored, and a missing_value can only be applied to an entire var_array.

However, with the changes in this PR, the following code is generated in structs_and_variables.inc:

      call mpas_add_att(r2Ptr % attLists(const_index) % attList, "units", "units1")
      call mpas_add_att(r2Ptr % attLists(const_index) % attList, "long_name", "Test var 1 in a var_array")
      call mpas_add_att(r2Ptr % attLists(const_index) % attList, "_FillValue", MPAS_REAL_FILLVAL)
      call mpas_add_att(r2Ptr % attLists(const_index) % attList, "_FillValue", MPAS_REAL_FILLVAL)