<p><b>duda</b> 2011-11-23 13:15:33 -0700 (Wed, 23 Nov 2011)</p><p>BRANCH COMMIT<br>
<br>
Commit initial code to auto-generate PIO calls for output through the registry.<br>
<br>
Still to be done:<br>
 - support for scalar fields with or without a Time dimension; e.g., xtime, cf1<br>
 - support for super-arrays<br>
 - support for fields of type logical and character (currently only integer and<br>
   real are handled)<br>
<br>
<br>
M    src/registry/gen_inc.c<br>
M    src/framework/mpas_io_output.F<br>
</p><hr noshade><pre><font color="gray">Modified: branches/pio/src/framework/mpas_io_output.F
===================================================================
--- branches/pio/src/framework/mpas_io_output.F        2011-11-22 17:50:14 UTC (rev 1209)
+++ branches/pio/src/framework/mpas_io_output.F        2011-11-23 20:15:33 UTC (rev 1210)
@@ -17,8 +17,7 @@
       ! For PIO
       type (iosystem_desc_t) :: pio_iosystem
       type (file_desc_t) :: pio_file
-!MGD-REGISTRY will need to generate an io_desc_t for each combination of dimensions
-      type (io_desc_t) :: iodesc_nVertLevels_nCells
+#include &quot;pio_output_io_desc.inc&quot;
 
       integer :: wr_ncid
       character (len=1024) :: filename
@@ -30,17 +29,9 @@
       integer :: wrDimIDStrLen
 #include &quot;io_output_obj_decls.inc&quot;
 
-!MGD-REGISTRY will need to generate dimensions
-      ! MGD currently hard-wired for testing
       integer :: pioDimIDTime
-      integer :: pioDimIDnCells
-      integer :: pioDimIDnVertLevels
+#include &quot;pio_output_io_dims_vars.inc&quot;
 
-!MGD-REGISTRY will need to generate variables
-      ! MGD currently hard-wired for testing
-      type (var_desc_t) :: pioVarIDtheta
-      type (var_desc_t) :: pioVarIDrho
-
       logical :: validExchangeLists
       type (exchange_list), pointer :: sendCellsList, recvCellsList
       type (exchange_list), pointer :: sendEdgesList, recvEdgesList
@@ -95,7 +86,7 @@
                     domain % dminfo % comm,       &amp;     ! comp_comm
                     4,                            &amp;     ! num_iotasks
                     0,                            &amp;     ! num_aggregator
-                    32,                           &amp;     ! stride
+                    16,                           &amp;     ! stride
                     PIO_rearr_box,                &amp;     ! rearr
                     output_obj % pio_iosystem)          ! iosystem
 !                    domain % dminfo % nprocs,     &amp;     ! num_iotasks
@@ -186,12 +177,10 @@
       integer :: nVerticesGlobal
       integer :: nVertLevelsGlobal
 
-!MGD-REGISTRY will need to generate compdof info for each combination of dimensions
-!MGD hard-wired for initial PIO testing
       integer(kind=PIO_Offset) :: pio_time
       integer, dimension(:), pointer :: compdof
-      integer, dimension(2) :: dimids2
-      integer, dimension(3) :: dimids3
+      integer, dimension(7) :: dimids
+      integer :: indx
 
       integer, dimension(:), pointer :: neededCellList
       integer, dimension(:), pointer :: neededEdgeList
@@ -328,26 +317,9 @@
 
       if (.not. output_obj % validExchangeLists) then
 
-!MGD-REGISTRY will need to generate compdof info for each combination of dimensions
 write(0,*) 'MGD PIO_initdecomp'
-         
-         allocate(compdof(domain % blocklist % mesh % nVertLevelsSolve * domain % blocklist % mesh % nCellsSolve))
-         do i=1,domain % blocklist % mesh % nCellsSolve
-         do j=1,domain % blocklist % mesh % nVertLevelsSolve
-            compdof((i-1)*domain % blocklist % mesh % nVertLevels + j) = &amp;
-                    (domain % blocklist % mesh % indexToCellID % array(i)-1) * &amp;
-                    domain % blocklist % mesh % nVertLevels + j
-         end do
-         end do
+#include &quot;pio_init_decomp.inc&quot;
 
-         dimids2(1) = nVertLevelsGlobal
-         dimids2(2) = nCellsGlobal
-
-         call PIO_initdecomp(output_obj % pio_iosystem, PIO_DOUBLE, &amp;
-                             dimids2, compdof, output_obj % iodesc_nVertLevels_nCells)
-         deallocate(compdof)
-!MGD end PIO_initdecomp call
-
          call mpas_dmpar_get_owner_list(domain % dminfo, &amp;
                                    domain % blocklist % mesh % nCellsSolve, size(neededCellList), &amp;
                                    domain % blocklist % mesh % indexToCellID % array, neededCellList, &amp;
@@ -396,20 +368,12 @@
 !include &quot;io_output_fields.inc&quot;
 
       pio_time = output_obj % time
-write(0,*) 'MGD PIO_setframe ', pio_time
-      call PIO_setframe(output_obj % pioVarIDtheta, pio_time)
-      call PIO_setframe(output_obj % pioVarIDrho, pio_time)
 
-!MGD-REGISTRY will need to generate write calls for each field
+write(0,*) 'MGD PIO_setframe ', pio_time
 write(0,*) 'MGD PIO_write_darray'
-call mpas_timer_start(&quot;pio theta&quot;)
-      call PIO_write_darray(output_obj % pio_file, output_obj % pioVarIDtheta, output_obj % iodesc_nVertLevels_nCells, &amp;
-           domain % blocklist % diag % theta % array(:,1:domain%blocklist%mesh%nCellsSolve), i1)
-call mpas_timer_stop(&quot;pio theta&quot;)
-call mpas_timer_start(&quot;pio rho&quot;)
-      call PIO_write_darray(output_obj % pio_file, output_obj % pioVarIDrho, output_obj % iodesc_nVertLevels_nCells, &amp;
-           domain % blocklist % diag % rho % array(:,1:domain%blocklist%mesh%nCellsSolve), i1)
-call mpas_timer_stop(&quot;pio rho&quot;)
+call mpas_timer_start(&quot;pio write&quot;)
+#include &quot;pio_output_fields.inc&quot;
+call mpas_timer_stop(&quot;pio write&quot;)
 
 
       domain % blocklist % mesh % cellsOnCell % array =&gt; cellsOnCell_save
@@ -498,17 +462,18 @@
 
 !MGD-REGISTRY will need to generate definitions for each dimension
 write(0,*) 'MGD PIO_def_dim'
-      nferr = PIO_def_dim(output_obj % pio_file, 'Time', PIO_UNLIMITED, output_obj % pioDimIDTime)
-      nferr = PIO_def_dim(output_obj % pio_file, 'nCells', nCells, output_obj % pioDimIDnCells)
-      nferr = PIO_def_dim(output_obj % pio_file, 'nVertLevels', nVertLevels, output_obj % pioDimIDnVertLevels)
+!      nferr = PIO_def_dim(output_obj % pio_file, 'Time', PIO_UNLIMITED, output_obj % pioDimIDTime)
+!      nferr = PIO_def_dim(output_obj % pio_file, 'nCells', nCells, output_obj % pioDimIDnCells)
+!      nferr = PIO_def_dim(output_obj % pio_file, 'nVertLevels', nVertLevels, output_obj % pioDimIDnVertLevels)
 
 !MGD-REGISTRY will need to generate definitions for each field
 write(0,*) 'MGD PIO_def_var'
-      dimlist(1) = output_obj % pioDimIDnVertLevels
-      dimlist(2) = output_obj % pioDimIDnCells
-      dimlist(3) = output_obj % pioDimIDTime
-      nferr = PIO_def_var(output_obj % pio_file, 'theta', PIO_DOUBLE, dimlist(1:3), output_obj % pioVarIDtheta)
-      nferr = PIO_def_var(output_obj % pio_file, 'rho', PIO_DOUBLE, dimlist(1:3), output_obj % pioVarIDrho)
+!      dimlist(1) = output_obj % pioDimIDnVertLevels
+!      dimlist(2) = output_obj % pioDimIDnCells
+!      dimlist(3) = output_obj % pioDimIDTime
+!      nferr = PIO_def_var(output_obj % pio_file, 'theta', PIO_DOUBLE, dimlist(1:3), output_obj % pioVarIDtheta)
+!      nferr = PIO_def_var(output_obj % pio_file, 'rho', PIO_DOUBLE, dimlist(1:3), output_obj % pioVarIDrho)
+#include &quot;pio_def_dims_vars.inc&quot;
 
 
 write(0,*) 'MGD PIO_enddef'
@@ -972,9 +937,8 @@
 write(0,*) 'MGD PIO_closefile'
       call PIO_closefile(output_obj % pio_file)
 
-!MGD-REGISTRY will need to generate calls to free up each io_desc_t
 write(0,*) 'MGD PIO_freedecomp'
-      call PIO_freedecomp(output_obj % pio_iosystem, output_obj % iodesc_nVertLevels_nCells)
+#include &quot;pio_output_free_decomp.inc&quot;
 
 write(0,*) 'MGD PIO_finalize'
       call PIO_finalize(output_obj % pio_iosystem, nferr)

Modified: branches/pio/src/registry/gen_inc.c
===================================================================
--- branches/pio/src/registry/gen_inc.c        2011-11-22 17:50:14 UTC (rev 1209)
+++ branches/pio/src/registry/gen_inc.c        2011-11-23 20:15:33 UTC (rev 1210)
@@ -1662,9 +1662,10 @@
    struct group_list * group_ptr;
    struct dtable * dictionary;
    struct namelist * nl;
-   FILE * fd;
+   FILE * fd, * fd2;
    char vtype[5];
    char fname[32];
+   char temp[128];
    char struct_deref[1024];
    char * cp1, * cp2;
    int i, j;
@@ -2186,5 +2187,412 @@
    
       fclose(fd);
    }
+
+
+/*
+!MGD-REGISTRY will need to generate an io_desc_t for each combination of dimensions
+      type (io_desc_t) :: iodesc_nVertLevels_nCells
+*/
+/*
+!MGD-REGISTRY will need to generate calls to free up each io_desc_t
+write(0,*) 'MGD PIO_freedecomp'
+      call PIO_freedecomp(output_obj % pio_iosystem, output_obj % iodesc_nVertLevels_nCells)
+*/
+   /*
+    *  PIO code:
+    *  Generate definitions of io_desc_t for each combination of dimensions
+    */
+   fd = fopen(&quot;pio_output_io_desc.inc&quot;, &quot;w&quot;);
+   fd2 = fopen(&quot;pio_output_free_decomp.inc&quot;, &quot;w&quot;);
+   dict_alloc(&amp;dictionary);
+
+   var_ptr = vars;
+   while (var_ptr) {
+      sprintf(temp, &quot;&quot;);
+      dimlist_ptr = var_ptr-&gt;dimlist;
+
+      /* Avoid the case where we only have a time dimension */
+      if (var_ptr-&gt;ndims != 0) {
+         while(dimlist_ptr) {
+            sprintf(temp, &quot;%s_%s&quot;, temp, dimlist_ptr-&gt;dim-&gt;name_in_file);
+            dimlist_ptr = dimlist_ptr-&gt;next;
+         }
+         if (!dict_search(dictionary, temp)) {
+/* MGD NEED TO ADD IODESC TYPES FOR EACH FIELD TYPE */
+            fortprintf(fd, &quot;      type (io_desc_t) :: iodesc%s_Dbl</font>
<font color="blue">&quot;, temp);
+            fortprintf(fd, &quot;      type (io_desc_t) :: iodesc%s_Int</font>
<font color="blue">&quot;, temp);
+            fortprintf(fd2, &quot;      call PIO_freedecomp(output_obj %% pio_iosystem, output_obj %% iodesc%s_Dbl)</font>
<font color="blue">&quot;, temp);
+            fortprintf(fd2, &quot;      call PIO_freedecomp(output_obj %% pio_iosystem, output_obj %% iodesc%s_Int)</font>
<font color="blue">&quot;, temp);
+            dict_insert(dictionary, temp);
+         }
+      }
+      var_ptr = var_ptr-&gt;next;
+   }
+
+   dict_free(&amp;dictionary);
+   fclose(fd);
+   fclose(fd2);
+
+
+/*
+!MGD-REGISTRY will need to generate dimensions
+      ! MGD currently hard-wired for testing
+      integer :: pioDimIDTime
+      integer :: pioDimIDnCells
+      integer :: pioDimIDnVertLevels
+
+!MGD-REGISTRY will need to generate variables
+      ! MGD currently hard-wired for testing
+      type (var_desc_t) :: pioVarIDtheta
+      type (var_desc_t) :: pioVarIDrho
+*/
+   /*
+    *  PIO code:
+    *  Generate dimension IDs and var_desc_t for each dimension and variable
+    */
+   fd = fopen(&quot;pio_output_io_dims_vars.inc&quot;, &quot;w&quot;);
+
+   dim_ptr = dims;
+   while (dim_ptr) {
+      fortprintf(fd, &quot;      integer :: pioDimID%s</font>
<font color="blue">&quot;, dim_ptr-&gt;name_in_file);
+      dim_ptr = dim_ptr-&gt;next;
+   }
+
+   var_ptr = vars;
+   while (var_ptr) {
+      fortprintf(fd, &quot;      type (var_desc_t) :: pioVarID%s</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file);
+      var_ptr = var_ptr-&gt;next;
+   }
+
+   fclose(fd);
+
+
+/*
+      call PIO_setframe(output_obj % pioVarIDtheta, pio_time)
+      call PIO_write_darray(output_obj % pio_file, output_obj % pioVarIDtheta, output_obj % iodesc_nVertLevels_nCells, &amp;
+           domain % blocklist % diag % theta % array(:,1:domain%blocklist%mesh%nCellsSolve), i1)
+      call PIO_setframe(output_obj % pioVarIDrho, pio_time)
+      call PIO_write_darray(output_obj % pio_file, output_obj % pioVarIDrho, output_obj % iodesc_nVertLevels_nCells, &amp;
+           domain % blocklist % diag % rho % array(:,1:domain%blocklist%mesh%nCellsSolve), i1)
+*/
+   /*
+    *  PIO code:
+    *  Generate calls to write fields using PIO
+    */
+   fd = fopen(&quot;pio_output_fields.inc&quot;, &quot;w&quot;);
+
+   group_ptr = groups;
+   while (group_ptr) {
+      var_list_ptr = group_ptr-&gt;vlist;
+      while (var_list_ptr) {
+         var_ptr = var_list_ptr-&gt;var;
+
+/* MGD FOR NOW, NO SCALAR FIELDS OR SUPER-ARRAYS */
+if (var_ptr-&gt;ndims &gt; 0 &amp;&amp; strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) == 0) {
+         if (group_ptr-&gt;vlist-&gt;var-&gt;ntime_levs &gt; 1)
+            snprintf(struct_deref, 1024, &quot;domain %% blocklist %% %s %% time_levs(1) %% %s&quot;, group_ptr-&gt;name, group_ptr-&gt;name);
+         else
+            snprintf(struct_deref, 1024, &quot;domain %% blocklist %% %s&quot;, group_ptr-&gt;name);
+         
+         i = 1;
+         dimlist_ptr = var_ptr-&gt;dimlist;
+         if (var_ptr-&gt;vtype == INTEGER) sprintf(vtype, &quot;int&quot;); 
+         else if (var_ptr-&gt;vtype == REAL) sprintf(vtype, &quot;real&quot;); 
+         else if (var_ptr-&gt;vtype == CHARACTER) sprintf(vtype, &quot;char&quot;); 
    
+         if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+/* MGD SUPER-ARRAYS FOR NOW? */
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;super_array);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;super_array);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% sfc .and. output_obj %% stream == SFC)) then</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;super_array);
+         }
+         else {
+            fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% output .and. output_obj %% stream == OUTPUT) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. output_obj %% stream == RESTART) .or. &amp;</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code);
+            fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% sfc .and. output_obj %% stream == SFC)) then</font>
<font color="blue">&quot;, struct_deref, var_ptr-&gt;name_in_code);
+         }
+
+         /******/
+         sprintf(temp, &quot;&quot;);
+         dimlist_ptr = var_ptr-&gt;dimlist;
+
+         /* Avoid the case where we only have a time dimension */
+         if (var_ptr-&gt;ndims != 0) {
+            while(dimlist_ptr) {
+               sprintf(temp, &quot;%s_%s&quot;, temp, dimlist_ptr-&gt;dim-&gt;name_in_file);
+               dimlist_ptr = dimlist_ptr-&gt;next;
+            }
+         }
+         if (var_ptr-&gt;timedim) fortprintf(fd, &quot;         call PIO_setframe(output_obj %% pioVarID%s, pio_time)</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file);
+         fortprintf(fd, &quot;         call PIO_write_darray(output_obj %% pio_file, output_obj %% pioVarID%s, &quot;, var_ptr-&gt;name_in_file);
+/* Handle scalars */
+         if (var_ptr-&gt;ndims != 0) {
+/* MGD NEED TO USE CORRECT IODESC FOR THE TYPE OF THIS VARIABLE */
+            if (var_ptr-&gt;vtype == REAL)
+               fortprintf(fd, &quot;output_obj %% iodesc%s_Dbl, %s %% %s %% array(&quot;, temp, struct_deref, var_ptr-&gt;name_in_code);
+            else
+               fortprintf(fd, &quot;output_obj %% iodesc%s_Int, %s %% %s %% array(&quot;, temp, struct_deref, var_ptr-&gt;name_in_code);
+            dimlist_ptr = var_ptr-&gt;dimlist;
+            i = 1;
+            while(dimlist_ptr) {
+               if (i == var_ptr-&gt;ndims)
+                  if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
+                      !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
+                      !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
+                     fortprintf(fd, &quot;1:domain%%blocklist%%mesh%%%sSolve&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+                  else
+                     fortprintf(fd, &quot;:&quot;);
+               else
+                  fortprintf(fd, &quot;:,&quot;);
+               i++;
+               dimlist_ptr = dimlist_ptr-&gt;next;
+            }
+            fortprintf(fd, &quot;), i1)</font>
<font color="blue">&quot;);
+         }
+         /******/
+   
+         fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="blue">&quot;);
 }
+
+         var_list_ptr = var_list_ptr-&gt;next;
+      }
+      group_ptr = group_ptr-&gt;next;
+   }
+
+   fclose(fd);
+
+
+/*
+         allocate(compdof(domain % blocklist % mesh % nVertLevelsSolve * domain % blocklist % mesh % nCellsSolve))
+         do i=1,domain % blocklist % mesh % nCellsSolve
+         do j=1,domain % blocklist % mesh % nVertLevelsSolve
+            compdof((i-1)*domain % blocklist % mesh % nVertLevels + j) = &amp;
+                    (domain % blocklist % mesh % indexToCellID % array(i)-1) * &amp;
+                    domain % blocklist % mesh % nVertLevels + j
+         end do
+         end do
+
+         dimids2(1) = nVertLevelsGlobal
+         dimids2(2) = nCellsGlobal
+
+         call PIO_initdecomp(output_obj % pio_iosystem, PIO_DOUBLE, &amp;
+                             dimids2, compdof, output_obj % iodesc_nVertLevels_nCells)
+         deallocate(compdof)
+*/
+   /*
+    *  PIO code:
+    *  Create io decompositions for each combination of dimensions
+    */
+   fd = fopen(&quot;pio_init_decomp.inc&quot;, &quot;w&quot;);
+   dict_alloc(&amp;dictionary);
+
+   var_ptr = vars;
+   while (var_ptr) {
+
+      /* Avoid the case where we only have a time dimension */
+      if (var_ptr-&gt;ndims != 0) {
+         sprintf(temp, &quot;&quot;);
+         dimlist_ptr = var_ptr-&gt;dimlist;
+
+         i = 1;
+         j = 1;   /* Flag telling whether this is a decomposed field or not */
+         while(dimlist_ptr) {
+            sprintf(temp, &quot;%s_%s&quot;, temp, dimlist_ptr-&gt;dim-&gt;name_in_file);
+
+            /* If this is not a decomposed dimension, we want to only write it from one task */
+            if (i == var_ptr-&gt;ndims) {
+               if (strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) &amp;&amp;
+                   strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) &amp;&amp;
+                   strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
+                  j = 0;  /* Not a decomposed field */
+            }
+            i++;
+            dimlist_ptr = dimlist_ptr-&gt;next;
+         }
+         if (!dict_search(dictionary, temp)) {
+            fortprintf(fd, &quot;!!!!! %s</font>
<font color="blue">&quot;, temp);
+            dimlist_ptr = var_ptr-&gt;dimlist;
+            i = 1;
+            while(dimlist_ptr) {
+               if (j == 0)  /* If this is not a decomposed field */
+                  fortprintf(fd, &quot;      if (domain %% dminfo %% my_proc_id == 0) then</font>
<font color="blue">&quot;);
+
+               if (dimlist_ptr-&gt;dim-&gt;constant_value &gt; 0) 
+                  fortprintf(fd, &quot;         dimids(%i) = %i</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;constant_value);
+               else if (dimlist_ptr-&gt;dim-&gt;namelist_defined &gt; 0) 
+                  fortprintf(fd, &quot;         dimids(%i) = %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024) ||
+                        !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024) ||
+                        !strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
+                  fortprintf(fd, &quot;         dimids(%i) = domain %% blocklist %% mesh %% %sSolve</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else
+                  fortprintf(fd, &quot;         dimids(%i) = domain %% blocklist %% mesh %% %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+
+               if (j == 0) { /* not a decomposed field */
+                  fortprintf(fd, &quot;      else</font>
<font color="blue">&quot;);
+                  fortprintf(fd, &quot;         dimids(%i) = 0</font>
<font color="blue">&quot;, i);
+                  fortprintf(fd, &quot;      end if</font>
<font color="blue">&quot;);
+               }
+          
+               i++;
+               dimlist_ptr = dimlist_ptr-&gt;next;
+            }
+            
+            fortprintf(fd, &quot;         allocate(compdof(&quot;);
+            for(i=1; i&lt;var_ptr-&gt;ndims; i++)
+               fortprintf(fd, &quot;dimids(%i)*&quot;, i);
+            fortprintf(fd, &quot;dimids(%i)&quot;, i);
+            fortprintf(fd, &quot;))</font>
<font color="blue">&quot;);
+
+            fortprintf(fd, &quot;         indx = 1</font>
<font color="blue">&quot;);
+            for(i=var_ptr-&gt;ndims; i&gt;0; i--)
+               fortprintf(fd, &quot;         do i%i=1,dimids(%i)</font>
<font color="blue">&quot;, i, i);
+
+            fortprintf(fd, &quot;            compdof(indx) = &quot;);
+            dimlist_ptr = var_ptr-&gt;dimlist;
+            i = 1;
+            while(dimlist_ptr) {
+               if (i &gt; 1) fortprintf(fd, &quot;(&quot;);
+               if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nCells&quot;, 1024))
+                  fortprintf(fd, &quot;domain %% blocklist %% mesh %% indexToCellID %% array(i%i)&quot;, i);
+               else if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nEdges&quot;, 1024))
+                  fortprintf(fd, &quot;domain %% blocklist %% mesh %% indexToEdgeID %% array(i%i)&quot;, i);
+               else if (!strncmp(dimlist_ptr-&gt;dim-&gt;name_in_file, &quot;nVertices&quot;, 1024))
+                  fortprintf(fd, &quot;domain %% blocklist %% mesh %% indexToVertexID %% array(i%i)&quot;, i);
+               else
+                  fortprintf(fd, &quot;i%i&quot;, i);
+               for(j=i-1; j&gt;0; j--)
+                  if (j == i-1)
+                     fortprintf(fd, &quot;-1)*dimids(%i)&quot;, j);
+                  else
+                     fortprintf(fd, &quot;*dimids(%i)&quot;, j);
+               if (dimlist_ptr-&gt;next) fortprintf(fd, &quot; + &quot;);
+               i++;
+               dimlist_ptr = dimlist_ptr-&gt;next;
+            }
+            fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+
+            fortprintf(fd, &quot;            indx = indx + 1</font>
<font color="blue">&quot;);
+            for(i=1; i&lt;=var_ptr-&gt;ndims; i++)
+               fortprintf(fd, &quot;         end do</font>
<font color="blue">&quot;);
+
+            i = 1;
+            dimlist_ptr = var_ptr-&gt;dimlist;
+            while(dimlist_ptr) {
+               if (dimlist_ptr-&gt;dim-&gt;constant_value &gt; 0) 
+                  fortprintf(fd, &quot;         dimids(%i) = %i</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;constant_value);
+               else if (dimlist_ptr-&gt;dim-&gt;namelist_defined &gt; 0) 
+                  fortprintf(fd, &quot;         dimids(%i) = %s</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else
+                  fortprintf(fd, &quot;         dimids(%i) = %sGlobal</font>
<font color="blue">&quot;, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
+               i++;
+               dimlist_ptr = dimlist_ptr-&gt;next;
+            }
+
+/* MGD NEED TO ADD MORE CODE HERE TO CREATE DECOMPS FOR EACH TYPE */
+            fortprintf(fd, &quot;         call PIO_initdecomp(output_obj %% pio_iosystem, PIO_DOUBLE, dimids(1:%i), compdof, output_obj %% iodesc%s_Dbl)</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, temp);
+            fortprintf(fd, &quot;         call PIO_initdecomp(output_obj %% pio_iosystem, PIO_INT, dimids(1:%i), compdof, output_obj %% iodesc%s_Int)</font>
<font color="blue">&quot;, var_ptr-&gt;ndims, temp);
+
+            fortprintf(fd, &quot;         deallocate(compdof)</font>
<font color="blue">&quot;);
+            fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+            dict_insert(dictionary, temp);
+         }
+      }
+      var_ptr = var_ptr-&gt;next;
+   }
+
+   dict_free(&amp;dictionary);
+   fclose(fd);
+
+
+/*
+!MGD-REGISTRY will need to generate definitions for each dimension
+write(0,*) 'MGD PIO_def_dim'
+      nferr = PIO_def_dim(output_obj % pio_file, 'Time', PIO_UNLIMITED, output_obj % pioDimIDTime)
+      nferr = PIO_def_dim(output_obj % pio_file, 'nCells', nCells, output_obj % pioDimIDnCells)
+      nferr = PIO_def_dim(output_obj % pio_file, 'nVertLevels', nVertLevels, output_obj % pioDimIDnVertLevels)
+
+!MGD-REGISTRY will need to generate definitions for each field
+write(0,*) 'MGD PIO_def_var'
+      dimlist(1) = output_obj % pioDimIDnVertLevels
+      dimlist(2) = output_obj % pioDimIDnCells
+      dimlist(3) = output_obj % pioDimIDTime
+      nferr = PIO_def_var(output_obj % pio_file, 'theta', PIO_DOUBLE, dimlist(1:3), output_obj % pioVarIDtheta)
+      nferr = PIO_def_var(output_obj % pio_file, 'rho', PIO_DOUBLE, dimlist(1:3), output_obj % rioVarIDrho)
+*/
+   /*
+    *  Generate PIO calls to define dimensions, variables, and global attributes
+    */
+   fd = fopen(&quot;pio_def_dims_vars.inc&quot;, &quot;w&quot;);
+
+   fortprintf(fd, &quot;      nferr = PIO_def_dim(output_obj %% pio_file, \'Time\', PIO_UNLIMITED, output_obj %% pioDimIDTime)</font>
<font color="blue">&quot;);
+   dim_ptr = dims;
+   while (dim_ptr) {
+      fortprintf(fd, &quot;      nferr = PIO_def_dim(output_obj %% pio_file, \'%s\', %s, output_obj %% pioDimID%s)</font>
<font color="blue">&quot;, dim_ptr-&gt;name_in_file, dim_ptr-&gt;name_in_code, dim_ptr-&gt;name_in_file);
+      dim_ptr = dim_ptr-&gt;next;
+   }
+   fortprintf(fd, &quot;</font>
<font color="blue">&quot;);
+
+   var_ptr = vars;
+   while (var_ptr) {
+
+/* MGD FOR NOW, NO SCALAR FIELDS OR SUPER-ARRAYS */
+if (var_ptr-&gt;ndims &gt; 0 &amp;&amp; strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) == 0 &amp;&amp; (var_ptr-&gt;vtype == INTEGER || var_ptr-&gt;vtype == REAL)) {
+
+      fortprintf(fd, &quot;      if (.false. &amp;</font>
<font color="blue">&quot;);
+      if (var_ptr-&gt;iostreams &amp; RESTART0) fortprintf(fd, &quot;          .or. output_obj %% stream == RESTART &amp;</font>
<font color="blue">&quot;);
+      if (var_ptr-&gt;iostreams &amp; OUTPUT0)  fortprintf(fd, &quot;          .or. output_obj %% stream == OUTPUT &amp;</font>
<font color="blue">&quot;);
+      if (var_ptr-&gt;iostreams &amp; SFC0)     fortprintf(fd, &quot;          .or. output_obj %% stream == SFC &amp;</font>
<font color="blue">&quot;);
+      fortprintf(fd, &quot;      ) then</font>
<font color="blue">&quot;);
+      dimlist_ptr = var_ptr-&gt;dimlist;
+      fortprintf(fd, &quot;write(0,*) \'MGD defining %s\'</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file);
+      i = 1;
+      if (var_ptr-&gt;vtype == CHARACTER)
+         fortprintf(fd, &quot;      dimlist(%i) = output_obj %% pioDimIDStrLen</font>
<font color="blue">&quot;, i++);
+      while(dimlist_ptr) {
+         fortprintf(fd, &quot;      dimlist(%i) = output_obj %% pioDimID%s</font>
<font color="blue">&quot;, i++, dimlist_ptr-&gt;dim-&gt;name_in_file);
+         dimlist_ptr = dimlist_ptr-&gt;next;
+      }
+      if (var_ptr-&gt;timedim) fortprintf(fd, &quot;      dimlist(%i) = output_obj %% pioDimIDTime</font>
<font color="blue">&quot;, i++);
+      if (var_ptr-&gt;vtype == INTEGER)
+         fortprintf(fd, &quot;      nferr = PIO_def_var(output_obj %% pio_file, \'%s\', PIO_INT, dimlist(1:%i), output_obj %% pioVarID%s)</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file, var_ptr-&gt;ndims + var_ptr-&gt;timedim, var_ptr-&gt;name_in_file);
+      else if (var_ptr-&gt;vtype == REAL)
+         fortprintf(fd, &quot;      nferr = PIO_def_var(output_obj %% pio_file, \'%s\', PIO_DOUBLE, dimlist(1:%i), output_obj %% pioVarID%s)</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file, var_ptr-&gt;ndims + var_ptr-&gt;timedim, var_ptr-&gt;name_in_file);
+      else if (var_ptr-&gt;vtype == CHARACTER)
+         fortprintf(fd, &quot;      nferr = PIO_def_var(output_obj %% pio_file, \'%s\', PIO_CHAR, dimlist(1:%i), output_obj %% pioVarID%s)</font>
<font color="blue">&quot;, var_ptr-&gt;name_in_file, var_ptr-&gt;ndims + var_ptr-&gt;timedim + 1, var_ptr-&gt;name_in_file);
+
+      fortprintf(fd, &quot;      end if</font>
<font color="black"></font>
<font color="blue">&quot;);
+}
+
+      var_ptr = var_ptr-&gt;next;
+   }
+
+/* STILL TO DO 
+   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="blue">&quot;);
+      }
+      nl = nl-&gt;next;
+   }
+*/
+
+   fclose(fd);   
+
+   
+}

</font>
</pre>