Skip to content

Commit

Permalink
Merge branch 'jonbob/mpas-framework/add-attributes' into next (PR #5183)
Browse files Browse the repository at this point in the history
Add mpas-framework support for several other attributes

Adds parsing support to the mpas-framework for the following attributes:
* bounds
* cell_measures
* cell_method
* coordinates
* standard_name
See additional discussion in E3SM-Ocean-Discussion PR #28

[BFB]
  • Loading branch information
jonbob committed Sep 20, 2022
2 parents 7de5ed1 + 5b99512 commit 11f9186
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
254 changes: 254 additions & 0 deletions components/mpas-framework/src/tools/registry/gen_inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
const char *const_core;
const char *nmlrecname, *nmlrecindef, *nmlrecinsub;
const char *nmloptname, *nmlopttype, *nmloptval, *nmloptunits, *nmloptdesc, *nmloptposvals, *nmloptindef;
const char *nmloptbounds, *nmloptcellmeasures, *nmloptcellmethod, *nmloptcoords, *nmloptstdname;

char pool_name[1024];
char core_string[1024];
Expand Down Expand Up @@ -608,6 +609,11 @@ int parse_namelist_records_from_registry(ezxml_t registry)/*{{{*/
nmlopttype = ezxml_attr(nmlopt_xml, "type");
nmloptval = ezxml_attr(nmlopt_xml, "default_value");
nmloptunits = ezxml_attr(nmlopt_xml, "units");
nmloptbounds = ezxml_attr(nmlopt_xml, "bounds");
nmloptcellmeasures = ezxml_attr(nmlopt_xml, "cell_measures");
nmloptcellmethod = ezxml_attr(nmlopt_xml, "cell_method");
nmloptcoords = ezxml_attr(nmlopt_xml, "coordinates");
nmloptstdname = ezxml_attr(nmlopt_xml, "standard_name");
nmloptdesc = ezxml_attr(nmlopt_xml, "description");
nmloptposvals = ezxml_attr(nmlopt_xml, "possible_values");
nmloptindef = ezxml_attr(nmlopt_xml, "in_defaults");
Expand Down Expand Up @@ -1014,7 +1020,9 @@ int parse_var_array(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t var
const char *structname, *structlevs, *structpackages;
const char *substructname;
const char *vararrname, *vararrtype, *vararrdims, *vararrpersistence, *vararrdefaultval, *vararrpackages, *vararrmissingval, *vararrmissing_value_mask;
const char *vararrbounds, *vararrcellmeasures, *vararrcellmethod, *vararrcoords, *vararrstdname;
const char *varname, *varpersistence, *vartype, *vardims, *varunits, *vardesc, *vararrgroup, *varstreams, *vardefaultval, *varpackages;
const char *varbounds, *varcellmeasures, *varcellmethod, *varcoords, *varstdname;
const char *varname2, *vararrgroup2, *vararrname_in_code;
const char *varname_in_code;
const char *varname_in_output;
Expand Down Expand Up @@ -1056,6 +1064,11 @@ int parse_var_array(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t var
vararrtimelevs = ezxml_attr(var_arr_xml, "time_levs");
vararrname_in_code = ezxml_attr(var_arr_xml, "name_in_code");
vararrmissing_value_mask= ezxml_attr(var_arr_xml, "missing_value_mask");
vararrbounds = ezxml_attr(var_arr_xml, "bounds");
vararrcellmeasures = ezxml_attr(var_arr_xml, "cell_measures");
vararrcellmethod = ezxml_attr(var_arr_xml, "cell_method");
vararrcoords = ezxml_attr(var_arr_xml, "coordinates");
vararrstdname = ezxml_attr(var_arr_xml, "standard_name");

package_list[0] = '\0';
no_packages = build_struct_package_lists(varArray, package_list);
Expand Down Expand Up @@ -1378,6 +1391,11 @@ int parse_var_array(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t var
varname_in_code = ezxml_attr(var_xml, "name_in_code");
vardesc = ezxml_attr(var_xml, "description");
varunits = ezxml_attr(var_xml, "units");
varbounds = ezxml_attr(var_xml, "bounds");
varcellmeasures = ezxml_attr(var_xml, "cell_measures");
varcellmethod = ezxml_attr(var_xml, "cell_method");
varcoords = ezxml_attr(var_xml, "coordinates");
varstdname = ezxml_attr(var_xml, "standard_name");

if(!varname_in_code){
varname_in_code = ezxml_attr(var_xml, "name");
Expand Down Expand Up @@ -1437,6 +1455,156 @@ int parse_var_array(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t var
fortprintf(fd, " %s %% maskName = 'none'\n", pointer_name_arr , temp_str);
}

if ( varbounds != NULL ) {
string = strdup(varbounds);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'bounds', '%s')\n", pointer_name_arr, temp_str);
} else if ( vararrbounds != NULL ) {
string = strdup(vararrbounds);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'bounds', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcellmeasures != NULL ) {
string = strdup(varcellmeasures);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'cell_measures', '%s')\n", pointer_name_arr, temp_str);
} else if ( vararrcellmeasures != NULL ) {
string = strdup(vararrcellmeasures);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'cell_measures', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcellmethod != NULL ) {
string = strdup(varcellmethod);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'cell_method', '%s')\n", pointer_name_arr, temp_str);
} else if ( vararrcellmethod != NULL ) {
string = strdup(vararrcellmethod);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'cell_method', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcoords != NULL ) {
string = strdup(varcoords);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'coordinates', '%s')\n", pointer_name_arr, temp_str);
} else if ( vararrcoords != NULL ) {
string = strdup(vararrcoords);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'coordinates', '%s')\n", pointer_name_arr, temp_str);
}

if ( varstdname != NULL ) {
string = strdup(varstdname);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'standard_name', '%s')\n", pointer_name_arr, temp_str);
} else if ( vararrstdname != NULL ) {
string = strdup(vararrstdname);
tofree = string;

token = strsep(&string, "'");
sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, 'standard_name', '%s')\n", pointer_name_arr, temp_str);
}

if ( vararrmissingval ) {
fortprintf(fd, " call mpas_add_att(%s %% attLists(const_index) %% attList, '_FillValue', %s)\n", pointer_name_arr, missing_value);
}
Expand Down Expand Up @@ -1496,6 +1664,7 @@ int parse_var(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t currentVa
const char *structname, *structlevs, *structpackages;
const char *substructname;
const char *varname, *varpersistence, *vartype, *vardims, *varunits, *vardesc, *vararrgroup, *varstreams, *vardefaultval, *varpackages, *varmissingval, *varmissing_value_mask;
const char *varbounds, *varcellmeasures, *varcellmethod, *varcoords, *varstdname;
const char *varname2, *vararrgroup2;
const char *varname_in_code;
const char *varname_in_output;
Expand Down Expand Up @@ -1532,6 +1701,11 @@ int parse_var(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t currentVa
vartimelevs = ezxml_attr(var_xml, "time_levs");
varname_in_code = ezxml_attr(var_xml, "name_in_code");
varunits = ezxml_attr(var_xml, "units");
varbounds = ezxml_attr(var_xml, "bounds");
varcellmeasures = ezxml_attr(var_xml, "cell_measures");
varcellmethod = ezxml_attr(var_xml, "cell_method");
varcoords = ezxml_attr(var_xml, "coordinates");
varstdname = ezxml_attr(var_xml, "standard_name");
vardesc = ezxml_attr(var_xml, "description");
varmissingval = ezxml_attr(var_xml, "missing_value");
varmissing_value_mask = ezxml_attr(var_xml, "missing_value_mask");
Expand Down Expand Up @@ -1656,6 +1830,86 @@ int parse_var(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t currentVa
fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'units', '%s')\n", pointer_name_arr, temp_str);
}

if ( varbounds != NULL ) {
string = strdup(varbounds);
tofree = string;
token = strsep(&string, "'");

sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'bounds', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcellmeasures != NULL ) {
string = strdup(varcellmeasures);
tofree = string;
token = strsep(&string, "'");

sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'cell_measures', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcellmethod != NULL ) {
string = strdup(varcellmethod);
tofree = string;
token = strsep(&string, "'");

sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'cell_method', '%s')\n", pointer_name_arr, temp_str);
}

if ( varcoords != NULL ) {
string = strdup(varcoords);
tofree = string;
token = strsep(&string, "'");

sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'coordinates', '%s')\n", pointer_name_arr, temp_str);
}

if ( varstdname != NULL ) {
string = strdup(varstdname);
tofree = string;
token = strsep(&string, "'");

sprintf(temp_str, "%s", token);

while ( ( token = strsep(&string, "'") ) != NULL ) {
sprintf(temp_str, "%s''%s", temp_str, token);
}

free(tofree);

fortprintf(fd, " call mpas_add_att(%s %% attLists(1) %% attList, 'standard_name', '%s')\n", pointer_name_arr, temp_str);
}

if ( vardesc != NULL ) {
string = strdup(vardesc);
tofree = string;
Expand Down
23 changes: 23 additions & 0 deletions components/mpas-framework/src/tools/registry/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ int validate_reg_xml(ezxml_t registry)/*{{{*/
const char *dimname, *dimunits, *dimdesc, *dimdef, *dimdecomp;
const char *nmlrecname, *nmlrecindef;
const char *nmloptname, *nmlopttype, *nmloptval, *nmloptunits, *nmloptdesc, *nmloptposvals, *nmloptindef;
const char *nmloptbounds, *nmloptcellmeasures, *nmloptcellmethod, *nmloptcoords, *nmloptstdname;
const char *structname, *structpackages, *structstreams;
const char *vararrname, *vararrtype, *vararrdims, *vararrpersistence, *vararrpackages, *vararrstreams;
const char *vararrbounds, *vararrcellmeasures, *vararrcellmethod, *vararrcoords, *vararrstdname;
const char *varname, *varpersistence, *vartype, *vardims, *varunits, *vardesc, *vararrgroup, *varstreams, *varpackages;
const char *varbounds, *varcellmeasures, *varcellmethod, *varcoords, *varstdname;
const char *varname_in_code, *varname_in_stream;
const char *const_model, *const_core, *const_version;
const char *streamname, *streamtype, *streamfilename, *streamrecords, *streaminterval_in, *streaminterval_out, *streampackages, *streamvarpackages;
Expand Down Expand Up @@ -125,6 +128,11 @@ int validate_reg_xml(ezxml_t registry)/*{{{*/
nmlopttype = ezxml_attr(nmlopt_xml, "type");
nmloptval = ezxml_attr(nmlopt_xml, "default_value");
nmloptunits = ezxml_attr(nmlopt_xml, "units");
nmloptbounds = ezxml_attr(nmlopt_xml, "bounds");
nmloptcellmeasures = ezxml_attr(nmlopt_xml, "cell_measures");
nmloptcellmethod = ezxml_attr(nmlopt_xml, "cell_method");
nmloptcoords = ezxml_attr(nmlopt_xml, "coordinates");
nmloptstdname = ezxml_attr(nmlopt_xml, "standard_name");
nmloptdesc = ezxml_attr(nmlopt_xml, "description");
nmloptposvals = ezxml_attr(nmlopt_xml, "possible_values");

Expand Down Expand Up @@ -250,6 +258,11 @@ int validate_reg_xml(ezxml_t registry)/*{{{*/
vararrtype = ezxml_attr(var_arr_xml, "type");
vararrdims = ezxml_attr(var_arr_xml, "dimensions");
vararrpersistence = ezxml_attr(var_arr_xml, "persistence");
vararrbounds = ezxml_attr(var_arr_xml, "bounds");
vararrcellmeasures = ezxml_attr(var_arr_xml, "cell_measures");
vararrcellmethod = ezxml_attr(var_arr_xml, "cell_method");
vararrcoords = ezxml_attr(var_arr_xml, "coordinates");
vararrstdname = ezxml_attr(var_arr_xml, "standard_name");
vararrpackages = ezxml_attr(var_arr_xml, "packages");
vararrstreams = ezxml_attr(var_arr_xml, "streams");
time_levs = ezxml_attr(var_arr_xml, "time_levs");
Expand Down Expand Up @@ -342,6 +355,11 @@ int validate_reg_xml(ezxml_t registry)/*{{{*/
for(var_xml = ezxml_child(var_arr_xml, "var"); var_xml; var_xml = var_xml->next){
varname = ezxml_attr(var_xml, "name");
varunits = ezxml_attr(var_xml, "units");
varbounds = ezxml_attr(var_xml, "bounds");
varcellmeasures = ezxml_attr(var_xml, "cell_measures");
varcellmethod = ezxml_attr(var_xml, "cell_method");
varcoords = ezxml_attr(var_xml, "coordinates");
varstdname = ezxml_attr(var_xml, "standard_name");
vardesc = ezxml_attr(var_xml, "description");
vararrgroup = ezxml_attr(var_xml, "array_group");
varname_in_code = ezxml_attr(var_xml, "name_in_code");
Expand Down Expand Up @@ -399,6 +417,11 @@ int validate_reg_xml(ezxml_t registry)/*{{{*/
vartype = ezxml_attr(var_xml, "type");
vardims = ezxml_attr(var_xml, "dimensions");
varunits = ezxml_attr(var_xml, "units");
varbounds = ezxml_attr(var_xml, "bounds");
varcellmeasures = ezxml_attr(var_xml, "cell_measures");
varcellmethod = ezxml_attr(var_xml, "cell_method");
varcoords = ezxml_attr(var_xml, "coordinates");
varstdname = ezxml_attr(var_xml, "standard_name");
vardesc = ezxml_attr(var_xml, "description");
varname_in_code = ezxml_attr(var_xml, "name_in_code");
varpackages = ezxml_attr(var_xml, "packages");
Expand Down

0 comments on commit 11f9186

Please sign in to comment.