<p><b>duda</b> 2010-10-01 17:48:22 -0600 (Fri, 01 Oct 2010)</p><p>BRANCH COMMIT<br>
<br>
Updates from repository trunk:<br>
<br>
   - Add changes to permit specification of non-decomposed dimensions<br>
   (nCells, nEdges, nVertices, nVertLevels) at runtime in the namelist.<br>
<br>
   - Remove EXPAND_LEVELS code, since the functionality it provided can<br>
   now be duplicated at runtime.<br>
<br>
   - Fix logic bug in code to generate super-array indices (e.g., index_qv)<br>
   in gen_inc.c around line 372 and with the addition of sort_group_vars<br>
   subroutine in parse.c).<br>
<br>
   - Convert hydrostatic model to use runtime specification of nVertLevels<br>
   in new &amp;dimensions namelist.<br>
<br>
Plus:<br>
<br>
   - Convert nonhydrostatic model to use runtime specification of nVertLevels<br>
   in new &amp;dimensions namelist<br>
<br>
<br>
M    namelist.input.nhyd_atmos_squall<br>
M    namelist.input.hyd_atmos<br>
M    src/core_hyd_atmos/Registry<br>
M    src/core_sw/module_test_cases.F<br>
M    src/registry/gen_inc.c<br>
M    src/registry/parse.c<br>
M    src/core_nhyd_atmos/Registry<br>
M    src/framework/module_io_input.F<br>
M    Makefile<br>
M    namelist.input.nhyd_atmos<br>
M    namelist.input.nhyd_atmos_jw<br>
M    namelist.input.nhyd_atmos_mtn_wave<br>
</p><hr noshade><pre><font color="gray">Modified: branches/atmos_nonhydrostatic/Makefile
===================================================================
--- branches/atmos_nonhydrostatic/Makefile        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/Makefile        2010-10-01 23:48:22 UTC (rev 518)
@@ -1,14 +1,6 @@
 #MODEL_FORMULATION = -DNCAR_FORMULATION
 MODEL_FORMULATION = -DLANL_FORMULATION
 
-ifeq ($(CORE),hyd_atmos)
-EXPAND_LEVELS = -DEXPAND_LEVELS=26
-endif
-
-ifeq ($(CORE),nhyd_atmos)
-EXPAND_LEVELS = -DEXPAND_LEVELS=26
-endif
-
 FILE_OFFSET = -DOFFSET64BIT
 
 #########################
@@ -38,7 +30,7 @@
         &quot;CFLAGS = -g&quot; \
         &quot;LDFLAGS = -g -C&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
  
 ftn:
         ( make all \
@@ -50,7 +42,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi:
         ( make all \
@@ -62,7 +54,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-llnl:
         ( make all \
@@ -74,7 +66,7 @@
         &quot;CFLAGS = -fast&quot; \
         &quot;LDFLAGS = &quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 pgi-serial:
         ( make all \
@@ -86,7 +78,7 @@
         &quot;CFLAGS = -O0 -g&quot; \
         &quot;LDFLAGS = -O0 -g -Mbounds -Mchkptr&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 ifort:
         ( make all \
@@ -98,7 +90,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 gfortran:
         ( make all \
@@ -110,7 +102,7 @@
         &quot;CFLAGS = -O3 -m64&quot; \
         &quot;LDFLAGS = -O3 -m64&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE -m64 $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95:
         ( make all \
@@ -122,7 +114,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -D_MPI -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 g95-serial:
         ( make all \
@@ -134,7 +126,7 @@
         &quot;CFLAGS = -O3&quot; \
         &quot;LDFLAGS = -O3&quot; \
         &quot;CORE = $(CORE)&quot; \
-        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) $(EXPAND_LEVELS) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
+        &quot;CPPFLAGS = -DRKIND=8 $(MODEL_FORMULATION) -DUNDERSCORE $(FILE_OFFSET) $(ZOLTAN_DEFINE)&quot; )
 
 
 CPPINCLUDES = -I../inc -I$(NETCDF)/include

Modified: branches/atmos_nonhydrostatic/namelist.input.hyd_atmos
===================================================================
--- branches/atmos_nonhydrostatic/namelist.input.hyd_atmos        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/namelist.input.hyd_atmos        2010-10-01 23:48:22 UTC (rev 518)
@@ -16,6 +16,10 @@
    config_mp_physics = 0
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'

Modified: branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos
===================================================================
--- branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos        2010-10-01 23:48:22 UTC (rev 518)
@@ -19,6 +19,10 @@
    config_smdiv = 0.1
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'

Modified: branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_jw
===================================================================
--- branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_jw        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_jw        2010-10-01 23:48:22 UTC (rev 518)
@@ -27,6 +27,10 @@
    config_smdiv = 0.1
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'

Modified: branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_mtn_wave
===================================================================
--- branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_mtn_wave        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_mtn_wave        2010-10-01 23:48:22 UTC (rev 518)
@@ -22,6 +22,10 @@
    config_epssm = 0.2
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'

Modified: branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_squall
===================================================================
--- branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_squall        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/namelist.input.nhyd_atmos_squall        2010-10-01 23:48:22 UTC (rev 518)
@@ -17,6 +17,10 @@
    config_monotonic = .false.
 /
 
+&amp;dimensions
+   config_nvertlevels = 26
+/
+
 &amp;io
    config_input_name = 'grid.nc'
    config_output_name = 'output.nc'

Modified: branches/atmos_nonhydrostatic/src/core_hyd_atmos/Registry
===================================================================
--- branches/atmos_nonhydrostatic/src/core_hyd_atmos/Registry        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/core_hyd_atmos/Registry        2010-10-01 23:48:22 UTC (rev 518)
@@ -18,6 +18,7 @@
 namelist logical   sw_model config_positive_definite    false
 namelist logical   sw_model config_monotonic            true
 namelist integer   sw_model config_mp_physics           0
+namelist integer   dimensions config_nvertlevels        26
 namelist character io       config_input_name           grid.nc
 namelist character io       config_output_name          output.nc
 namelist character io       config_restart_name         restart.nc
@@ -38,7 +39,8 @@
 dim FIFTEEN 15
 dim TWENTYONE 21
 dim R3 3
-dim nVertLevels nVertLevels
+#dim nVertLevels nVertLevels
+dim nVertLevels namelist:config_nvertlevels
 #dim nTracers nTracers
 dim nVertLevelsP1 nVertLevels+1
 

Modified: branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Registry
===================================================================
--- branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Registry        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/core_nhyd_atmos/Registry        2010-10-01 23:48:22 UTC (rev 518)
@@ -30,7 +30,7 @@
 namelist integer   nhyd_model config_mp_physics           0.
 namelist real      nhyd_model config_epssm                0.1
 namelist real      nhyd_model config_smdiv                0.1
-
+namelist integer   dimensions config_nvertlevels        26
 namelist character io       config_input_name           grid.nc
 namelist character io       config_output_name          output.nc
 namelist character io       config_restart_name         restart.nc
@@ -52,7 +52,8 @@
 dim FIFTEEN 15
 dim TWENTYONE 21
 dim R3 3
-dim nVertLevels nVertLevels
+#dim nVertLevels nVertLevels
+dim nVertLevels namelist:config_nvertlevels
 dim nVertLevelsP1 nVertLevels+1
 
 #

Modified: branches/atmos_nonhydrostatic/src/core_sw/module_test_cases.F
===================================================================
--- branches/atmos_nonhydrostatic/src/core_sw/module_test_cases.F        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/core_sw/module_test_cases.F        2010-10-01 23:48:22 UTC (rev 518)
@@ -148,9 +148,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -164,9 +161,6 @@
          else
             state % h % array(1,iCell) = 0.0
          end if
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_1
@@ -230,9 +224,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -262,9 +253,6 @@
                                              )**2.0 &amp;
                                       ) / &amp;
                                       gravity
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_2
@@ -330,9 +318,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -389,9 +374,6 @@
                                       ) / &amp;
                                       gravity
          state % h % array(1,iCell) = state % h % array(1,iCell) - grid % h_s % array(iCell)
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_5
@@ -453,9 +435,6 @@
                                                psiVertex(grid%verticesOnEdge%array(2,iEdge)) - &amp;
                                                psiVertex(grid%verticesOnEdge%array(1,iEdge)) &amp;
                                              ) / grid%dvEdge%array(iEdge)
-#ifdef EXPAND_LEVELS
-         state % u % array(2:EXPAND_LEVELS, iEdge) = state % u % array(1,iEdge)
-#endif
       end do
       deallocate(psiVertex)
 
@@ -467,9 +446,6 @@
                                                       a*a*BB(grid%latCell%array(iCell)) * cos(R*grid%lonCell%array(iCell)) + &amp;
                                                       a*a*CC(grid%latCell%array(iCell)) * cos(2.0*R*grid%lonCell%array(iCell)) &amp;
                                       ) / gravity
-#ifdef EXPAND_LEVELS
-         state % h % array(2:EXPAND_LEVELS, iCell) = state % h % array(1,iCell)
-#endif
       end do
 
    end subroutine sw_test_case_6

Modified: branches/atmos_nonhydrostatic/src/framework/module_io_input.F
===================================================================
--- branches/atmos_nonhydrostatic/src/framework/module_io_input.F        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/framework/module_io_input.F        2010-10-01 23:48:22 UTC (rev 518)
@@ -1093,13 +1093,6 @@
  
 #include &quot;netcdf_read_ids.inc&quot;
 
-#ifdef EXPAND_LEVELS
-      if (.not. config_do_restart) then
-         input_obj % rdLocalnVertLevels = EXPAND_LEVELS
-         write(0,*) 'Expanding nVertLevels to ',input_obj % rdLocalnVertLevels,' by duplicating the first level.'
-      end if
-#endif
-
    end subroutine io_input_init
 
   

Modified: branches/atmos_nonhydrostatic/src/registry/gen_inc.c
===================================================================
--- branches/atmos_nonhydrostatic/src/registry/gen_inc.c        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/registry/gen_inc.c        2010-10-01 23:48:22 UTC (rev 518)
@@ -363,16 +363,24 @@
          }
 
          var_list_ptr = group_ptr-&gt;vlist;
-         memcpy(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024);
-         memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
+         sprintf(super_array, &quot;-&quot;);
+         sprintf(array_class, &quot;-&quot;);
          class_start = 1;
          class_end = 1;
          i = 1;
+
          while (var_list_ptr) {
+
+            /* Is the current variable in a super array? */
             if (strncmp(var_list_ptr-&gt;var-&gt;super_array, &quot;-&quot;, 1024) != 0) {
+
+               /* Have we hit the beginning of a new super array? */
                if (strncmp(super_array, var_list_ptr-&gt;var-&gt;super_array, 1024) != 0) {
-                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="red">&quot;, array_class, class_end);
-                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="blue">&quot;, super_array, i);
+                  /* Finish off the previous super array? */
+                  if (strncmp(super_array, &quot;-&quot;, 1024) != 0) {
+                     fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="blue">&quot;, array_class, class_end);
+                     fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="gray">&quot;, super_array, i);
+                  }
                   class_start = 1;
                   class_end = 1;
                   i = 1;
@@ -380,6 +388,7 @@
                   memcpy(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024);
                   fortprintf(fd, &quot;      integer :: %s_start = %i</font>
<font color="blue">&quot;, array_class, class_start);
                }
+               /* Or have we hit the beginning of a new array class? */
                else if (strncmp(array_class, var_list_ptr-&gt;var-&gt;array_class, 1024) != 0) {
                   fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="gray">&quot;, array_class, class_end);
                   class_start = class_end+1;
@@ -392,8 +401,10 @@
                   class_end++;
                   i++;
                }
+
             }
             var_list_ptr = var_list_ptr-&gt;next;
+
          }
          if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: %s_end = %i</font>
<font color="black">&quot;, array_class, class_end);
          if (strncmp(super_array, &quot;-&quot;, 1024) != 0) fortprintf(fd, &quot;      integer :: num_%s = %i</font>
<font color="gray">&quot;, super_array, i);
@@ -538,7 +549,8 @@
             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;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+               else fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
             else
                if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -547,7 +559,8 @@
                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;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
                   if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -581,7 +594,8 @@
                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;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;%s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                else
                   if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -590,7 +604,8 @@
                   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;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %s + 1&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
                      if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                      else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
@@ -758,7 +773,6 @@
    char * cp1, * cp2;
    int i, j;
    int ivtype;
-   int has_vert_dim, vert_dim;
 
 
    /*
@@ -820,29 +834,14 @@
             fortprintf(fd, &quot;      if ((%s %% %s %% ioinfo %% input .and. .not. config_do_restart) .or. &amp;</font>
<font color="black">&quot;, struct_deref, var_ptr-&gt;name_in_code);
             fortprintf(fd, &quot;          (%s %% %s %% ioinfo %% restart .and. config_do_restart)) then</font>
<font color="red">&quot;, struct_deref, var_ptr-&gt;name_in_code);
          }
-         vert_dim = 0;
          while (dimlist_ptr) {
                if (i &lt; var_ptr-&gt;ndims) {
-                  has_vert_dim = !strcmp( &quot;nVertLevels&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
                   fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-                  if (has_vert_dim) {
-                     vert_dim = i;
-                     fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-                     fortprintf(fd, &quot;      if (.not. config_do_restart) then</font>
<font color="red">&quot;);
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = 1</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i);
-                     fortprintf(fd, &quot;      else</font>
<font color="red">&quot;);
-                     fortprintf(fd, &quot;#endif</font>
<font color="red">&quot;);
-                  }
                   if (dimlist_ptr-&gt;dim-&gt;constant_value &lt; 0)
                      if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="black">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
                      else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = block %% mesh %% %s</font>
<font color="black">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
                      fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %s</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
-                  if (has_vert_dim) {
-                     fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-                     fortprintf(fd, &quot;      end if</font>
<font color="red">&quot;);
-                     fortprintf(fd, &quot;#endif</font>
<font color="gray">&quot;);
-                  }
                }
                else {
                   if (is_derived_dim(dimlist_ptr-&gt;dim-&gt;name_in_code)) {
@@ -853,8 +852,14 @@
                      free(cp2);
                   }
                   else {
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
-                     fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     if (dimlist_ptr-&gt;dim-&gt;namelist_defined) {
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                     }
+                     else {
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% start(%i) = read%sStart</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = read%sCount</font>
<font color="gray">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     }
                   }
                }
             dimlist_ptr = dimlist_ptr-&gt;next;
@@ -881,7 +886,8 @@
                   free(cp2);
                }
                else
-                  fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                  if (dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
+                  else fortprintf(fd, &quot;read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
             }
        
             dimlist_ptr = dimlist_ptr-&gt;next;
@@ -902,7 +908,8 @@
                      free(cp2);
                   }
                   else
-                     fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     else fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
                }
                dimlist_ptr = dimlist_ptr-&gt;next;
                i++;
@@ -919,7 +926,8 @@
                      if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
                      else fortprintf(fd, &quot;block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
-                     fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;%s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                }
                dimlist_ptr = dimlist_ptr-&gt;next;
                i++;
@@ -928,7 +936,9 @@
                      if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
                      else fortprintf(fd, &quot;, block %% mesh %% %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   else
-                     fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %s&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
+
                   dimlist_ptr = dimlist_ptr-&gt;next;
                   i++;
                }
@@ -942,26 +952,6 @@
          else
             fortprintf(fd, &quot;      call io_input_field(input_obj, %s%id)</font>
<font color="red">&quot;, vtype, var_ptr-&gt;ndims);
    
-         if (vert_dim &gt; 0) {
-            fortprintf(fd, &quot;#ifdef EXPAND_LEVELS</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;      if (.not. config_do_restart) then</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;         do k=2,EXPAND_LEVELS</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;            %s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
-            for (i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               if (i &gt; 1) fortprintf(fd, &quot;,&quot;);
-               fortprintf(fd, &quot;%s&quot;, i == vert_dim ? &quot;k&quot; : &quot;:&quot;);
-            }
-            fortprintf(fd, &quot;) = %s%id %% array(&quot;, vtype, var_ptr-&gt;ndims);
-            for (i=1; i&lt;=var_ptr-&gt;ndims; i++) {
-               if (i &gt; 1) fortprintf(fd, &quot;,&quot;);
-               fortprintf(fd, &quot;%s&quot;, i == vert_dim ? &quot;1&quot; : &quot;:&quot;);
-            }
-            fortprintf(fd, &quot;)</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;         end do</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;      end if</font>
<font color="red">&quot;);
-            fortprintf(fd, &quot;#endif</font>
<font color="red">&quot;);
-         }
-   
          if (var_ptr-&gt;ndims &gt; 0) {
             fortprintf(fd, &quot;      call dmpar_alltoall_field(dminfo, &amp;</font>
<font color="gray">&quot;);
             if (strncmp(var_ptr-&gt;super_array, &quot;-&quot;, 1024) != 0)
@@ -987,7 +977,8 @@
                   free(cp2);
                }
                else
-                  fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                  else fortprintf(fd, &quot;                                read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
             }
        
             dimlist_ptr = dimlist_ptr-&gt;next;
@@ -1008,18 +999,22 @@
                      free(cp2);
                   }
                   else
-                     fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code+1);
+                     else fortprintf(fd, &quot;, read%sCount&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file+1);
                }
                dimlist_ptr = dimlist_ptr-&gt;next;
                i++;
             }
-            fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code);
+            if (!lastdim-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code);
+            else fortprintf(fd, &quot;, block %% mesh %% %s, &amp;</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file);
       
-            if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) {
+            if (is_derived_dim(lastdim-&gt;dim-&gt;name_in_code)) 
                fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
-            }
             else
-               fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
+               if (lastdim-&gt;dim-&gt;namelist_defined) 
+                  fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
+               else
+                  fortprintf(fd, &quot;                                send%sList, recv%sList)</font>
<font color="gray">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
    
    
             /* Copy from super_ array to field */
@@ -1403,7 +1398,8 @@
                         free(cp2);
                      }
                      else
-                        fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                        if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="blue">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                        else fortprintf(fd, &quot;      %s%id %% ioinfo %% count(%i) = %sGlobal</font>
<font color="gray">&quot;, vtype, var_ptr-&gt;ndims, i, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   }
                dimlist_ptr = dimlist_ptr-&gt;next;
                i++;
@@ -1427,7 +1423,8 @@
                   free(cp2);
                }
                else
-                  fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                  else fortprintf(fd, &quot;%sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                lastdim = dimlist_ptr;
             }
             dimlist_ptr = dimlist_ptr-&gt;next;
@@ -1447,7 +1444,8 @@
                      free(cp2);
                   }
                   else
-                     fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     if (!dimlist_ptr-&gt;dim-&gt;namelist_defined) fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_code);
+                     else fortprintf(fd, &quot;, %sGlobal&quot;, dimlist_ptr-&gt;dim-&gt;name_in_file);
                   lastdim = dimlist_ptr;
                }
                dimlist_ptr = dimlist_ptr-&gt;next;
@@ -1545,8 +1543,14 @@
                free(cp2);
             }
             else {
-               fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="red">&quot;, lastdim-&gt;dim-&gt;name_in_code);
-               fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
+               if (!lastdim-&gt;dim-&gt;namelist_defined) {
+                  fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code);
+                  fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_code+1, lastdim-&gt;dim-&gt;name_in_code+1);
+               }
+               else {
+                  fortprintf(fd, &quot;, %sGlobal, &amp;</font>
<font color="blue">&quot;, lastdim-&gt;dim-&gt;name_in_file);
+                  fortprintf(fd, &quot;                                output_obj %% send%sList, output_obj %% recv%sList)</font>
<font color="gray">&quot;, lastdim-&gt;dim-&gt;name_in_file+1, lastdim-&gt;dim-&gt;name_in_file+1);
+               }
             }
          }
          else {

Modified: branches/atmos_nonhydrostatic/src/registry/parse.c
===================================================================
--- branches/atmos_nonhydrostatic/src/registry/parse.c        2010-10-01 22:55:04 UTC (rev 517)
+++ branches/atmos_nonhydrostatic/src/registry/parse.c        2010-10-01 23:48:22 UTC (rev 518)
@@ -8,6 +8,7 @@
 int getword(FILE *, char *);
 int is_integer_constant(char *);
 void sort_vars(struct variable *);
+void sort_group_vars(struct group_list *);
 
 int main(int argc, char ** argv)
 {
@@ -36,6 +37,7 @@
    }   
 
    sort_vars(vars);
+   sort_group_vars(groups);
 
    gen_namelists(nls);
    gen_field_defs(groups, vars, dims);
@@ -306,7 +308,7 @@
 
    var_ptr = vars;
 
-/*
+/* Attempt at sorting first on super-array, then on class in the same loop
    while (var_ptr) {
       memcpy(super_array, var_ptr-&gt;super_array, 1024);
       memcpy(array_class, var_ptr-&gt;array_class, 1024);
@@ -375,3 +377,68 @@
       var_ptr = var_ptr-&gt;next;
    }
 }
+
+
+void sort_group_vars(struct group_list * groups)
+{
+   struct variable_list * var_list;
+   struct variable_list * var_ptr;
+   struct variable_list * var_ptr2;
+   struct variable_list * var_ptr2_prev;
+   struct group_list * group_ptr;
+   char super_array[1024];
+   char array_class[1024];
+
+   group_ptr = groups;
+
+   while (group_ptr) {
+
+      var_ptr = group_ptr-&gt;vlist;
+   
+      while (var_ptr) {
+         memcpy(super_array, var_ptr-&gt;var-&gt;super_array, 1024);
+         var_ptr2_prev = var_ptr;
+         var_ptr2 = var_ptr-&gt;next;
+         if (var_ptr2 &amp;&amp; strncmp(super_array, var_ptr2-&gt;var-&gt;super_array, 1024) != 0) {
+            while (var_ptr2) {
+               if (strncmp(super_array, var_ptr2-&gt;var-&gt;super_array, 1024) == 0) {
+                  var_ptr2_prev-&gt;next = var_ptr2-&gt;next;
+                  var_ptr2-&gt;next = var_ptr-&gt;next;
+                  var_ptr-&gt;next = var_ptr2;
+                  var_ptr2 = var_ptr2_prev-&gt;next;
+               }
+               else {
+                  var_ptr2_prev = var_ptr2_prev-&gt;next;
+                  var_ptr2 = var_ptr2-&gt;next;
+               }
+            }
+         } 
+         var_ptr = var_ptr-&gt;next;
+      }
+   
+      var_ptr = group_ptr-&gt;vlist;
+   
+      while (var_ptr) {
+         memcpy(array_class, var_ptr-&gt;var-&gt;array_class, 1024);
+         var_ptr2_prev = var_ptr;
+         var_ptr2 = var_ptr-&gt;next;
+         if (var_ptr2 &amp;&amp; strncmp(array_class, var_ptr2-&gt;var-&gt;array_class, 1024) != 0) {
+            while (var_ptr2) {
+               if (strncmp(array_class, var_ptr2-&gt;var-&gt;array_class, 1024) == 0) {
+                  var_ptr2_prev-&gt;next = var_ptr2-&gt;next;
+                  var_ptr2-&gt;next = var_ptr-&gt;next;
+                  var_ptr-&gt;next = var_ptr2;
+                  var_ptr2 = var_ptr2_prev-&gt;next;
+               }
+               else {
+                  var_ptr2_prev = var_ptr2_prev-&gt;next;
+                  var_ptr2 = var_ptr2-&gt;next;
+               }
+            }
+         } 
+         var_ptr = var_ptr-&gt;next;
+      }
+
+      group_ptr = group_ptr-&gt;next;
+   }
+}

</font>
</pre>