<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(&quot;netcdf_def_dims_vars.inc&quot;, &quot;w&quot;);
 
@@ -1270,6 +1271,29 @@
       var_ptr = var_ptr-&gt;next;
    }
 
+   nl = namelists;
+   while (nl) {
+      if (nl-&gt;vtype == INTEGER)
+         fortprintf(fd, &quot;      nferr = nf_put_att_int(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_INT, 1, %s)</font>
<font color="blue">&quot;, nl-&gt;name, nl-&gt;name);
+      else if (nl-&gt;vtype == REAL) {
+         fortprintf(fd, &quot;      if (RKIND == 8) then</font>
<font color="blue">&quot;, nl-&gt;name);
+         fortprintf(fd, &quot;         nferr = nf_put_att_double(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_DOUBLE, 1, %s)</font>
<font color="blue">&quot;, nl-&gt;name, nl-&gt;name);
+         fortprintf(fd, &quot;      else if (RKIND == 4) then</font>
<font color="blue">&quot;, nl-&gt;name);
+         fortprintf(fd, &quot;         nferr = nf_put_att_real(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', NF_FLOAT, 1, %s)</font>
<font color="blue">&quot;, nl-&gt;name, nl-&gt;name);
+         fortprintf(fd, &quot;      end if</font>
<font color="blue">&quot;);
+      }
+      else if (nl-&gt;vtype == CHARACTER)
+         fortprintf(fd, &quot;      nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', len_trim(%s), trim(%s))</font>
<font color="blue">&quot;, nl-&gt;name, nl-&gt;name, nl-&gt;name);
+      else if (nl-&gt;vtype == LOGICAL) {
+         fortprintf(fd, &quot;      if (%s) then</font>
<font color="blue">&quot;, nl-&gt;name);
+         fortprintf(fd, &quot;         nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', 1, \'T\')</font>
<font color="blue">&quot;, nl-&gt;name);
+         fortprintf(fd, &quot;      else</font>
<font color="blue">&quot;);
+         fortprintf(fd, &quot;         nferr = nf_put_att_text(output_obj %% wr_ncid, NF_GLOBAL, \'%s\', 1, \'F\')</font>
<font color="blue">&quot;, nl-&gt;name);
+         fortprintf(fd, &quot;      end if</font>
<font color="gray">&quot;);
+      }
+      nl = nl-&gt;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>