<p><b>duda</b> 2010-03-04 11:04:46 -0700 (Thu, 04 Mar 2010)</p><p>Write namelist variables as global attributes in output and restart files.<br>
<br>
M Registry/gen_inc.c<br>
M Registry/gen_inc.h<br>
M Registry/parse.c<br>
</p><hr noshade><pre><font color="gray">Modified: trunk/swmodel/Registry/gen_inc.c
===================================================================
--- trunk/swmodel/Registry/gen_inc.c        2010-03-03 22:07:29 UTC (rev 123)
+++ trunk/swmodel/Registry/gen_inc.c        2010-03-04 18:04:46 UTC (rev 124)
@@ -1150,12 +1150,13 @@
}
-void gen_writes(struct variable * vars, struct dimension * dims)
+void gen_writes(struct variable * vars, struct dimension * dims, struct namelist * namelists)
{
struct variable * var_ptr;
struct dimension * dim_ptr;
struct dimension_list * dimlist_ptr, * lastdim;
struct dtable * dictionary;
+ struct namelist * nl;
FILE * fd;
char vtype[5];
char fname[32];
@@ -1235,7 +1236,7 @@
/*
- * Generate NetCDF calls to define dimensions and variables
+ * Generate NetCDF calls to define dimensions, variables, and global attributes
*/
fd = fopen("netcdf_def_dims_vars.inc", "w");
@@ -1270,6 +1271,29 @@
var_ptr = var_ptr->next;
}
+ nl = namelists;
+ while (nl) {
+ if (nl->vtype == INTEGER)
+ fortprintf(fd, " nferr = nf_put_att_int(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_INT, 1, %s)</font>
<font color="blue">", nl->name, nl->name);
+ else if (nl->vtype == REAL) {
+ fortprintf(fd, " if (RKIND == 8) then</font>
<font color="blue">", nl->name);
+ fortprintf(fd, " nferr = nf_put_att_double(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_DOUBLE, 1, %s)</font>
<font color="blue">", nl->name, nl->name);
+ fortprintf(fd, " else if (RKIND == 4) then</font>
<font color="blue">", nl->name);
+ fortprintf(fd, " nferr = nf_put_att_real(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_FLOAT, 1, %s)</font>
<font color="blue">", nl->name, nl->name);
+ fortprintf(fd, " end if</font>
<font color="blue">");
+ }
+ else if (nl->vtype == CHARACTER)
+ fortprintf(fd, " nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', len_trim(%s), trim(%s))</font>
<font color="blue">", nl->name, nl->name, nl->name);
+ else if (nl->vtype == LOGICAL) {
+ fortprintf(fd, " if (%s) then</font>
<font color="blue">", nl->name);
+ fortprintf(fd, " nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', 1, \'T\')</font>
<font color="blue">", nl->name);
+ fortprintf(fd, " else</font>
<font color="blue">");
+ fortprintf(fd, " nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', 1, \'F\')</font>
<font color="blue">", nl->name);
+ fortprintf(fd, " end if</font>
<font color="gray">");
+ }
+ nl = nl->next;
+ }
+
fclose(fd);
Modified: trunk/swmodel/Registry/gen_inc.h
===================================================================
--- trunk/swmodel/Registry/gen_inc.h        2010-03-03 22:07:29 UTC (rev 123)
+++ trunk/swmodel/Registry/gen_inc.h        2010-03-04 18:04:46 UTC (rev 124)
@@ -1,4 +1,4 @@
void gen_namelists(struct namelist *);
void gen_field_defs(struct variable *, struct dimension *);
void gen_reads(struct variable *, struct dimension *);
-void gen_writes(struct variable *, struct dimension *);
+void gen_writes(struct variable *, struct dimension *, struct namelist *);
Modified: trunk/swmodel/Registry/parse.c
===================================================================
--- trunk/swmodel/Registry/parse.c        2010-03-03 22:07:29 UTC (rev 123)
+++ trunk/swmodel/Registry/parse.c        2010-03-04 18:04:46 UTC (rev 124)
@@ -39,7 +39,7 @@
gen_namelists(nls);
gen_field_defs(vars, dims);
gen_reads(vars, dims);
- gen_writes(vars, dims);
+ gen_writes(vars, dims, nls);
return 0;
}
</font>
</pre>