Index: palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3727)
+++ palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3729)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! Bugfix: - initialize return values to ensure they are set before returning
+!           (routine define_geo_coordinates)
+!         - change order of dimensions for some variables
+! 
+! 3727 2019-02-08 14:52:10Z gronemeier
 ! make several routines publicly available
 ! 
@@ -511,10 +516,10 @@
                     id_var_zw_xy, id_var_zw_xz, id_var_zw_yz, id_var_zw_3d
 
-    INTEGER(iwp), DIMENSION(0:1,0:2) ::  id_var_eutm_3d, id_var_nutm_3d, &
+    INTEGER(iwp), DIMENSION(0:2,0:1) ::  id_var_eutm_3d, id_var_nutm_3d, &
                                          id_var_eutm_xy, id_var_nutm_xy, &
                                          id_var_eutm_xz, id_var_nutm_xz, &
                                          id_var_eutm_yz, id_var_nutm_yz
 
-    INTEGER(iwp), DIMENSION(0:1,0:2) ::  id_var_lat_3d, id_var_lon_3d, &
+    INTEGER(iwp), DIMENSION(0:2,0:1) ::  id_var_lat_3d, id_var_lon_3d, &
                                          id_var_lat_xy, id_var_lon_xy, &
                                          id_var_lat_xz, id_var_lon_xz, &
@@ -564,8 +569,8 @@
                    id_var_zusi_mask, id_var_zwwi_mask
 
-    INTEGER(iwp), DIMENSION(1:max_masks,0:1,0:2) ::  id_var_eutm_mask, &
+    INTEGER(iwp), DIMENSION(0:2,1:max_masks,0:1) ::  id_var_eutm_mask, &
                                                      id_var_nutm_mask
 
-    INTEGER(iwp), DIMENSION(1:max_masks,0:1,0:2) ::  id_var_lat_mask, &
+    INTEGER(iwp), DIMENSION(0:2,1:max_masks,0:1) ::  id_var_lat_mask, &
                                                      id_var_lon_mask
 
@@ -1029,6 +1034,6 @@
                   (/ id_dim_x_mask(mid,av), id_dim_xu_mask(mid,av) /),    &
                   (/ id_dim_y_mask(mid,av), id_dim_yv_mask(mid,av) /),    &
-                  id_var_eutm_mask(mid,av,:), id_var_nutm_mask(mid,av,:), &
-                  id_var_lat_mask(mid,av,:), id_var_lon_mask(mid,av,:)    )
+                  id_var_eutm_mask(:,mid,av), id_var_nutm_mask(:,mid,av), &
+                  id_var_lat_mask(:,mid,av), id_var_lon_mask(:,mid,av)    )
 !
 !--       Define coordinate-reference system
@@ -1303,5 +1308,5 @@
 
                 nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), &
-                                        id_var_eutm_mask(mid,av,k), &
+                                        id_var_eutm_mask(k,mid,av), &
                                         netcdf_data, start = (/ 1 /), &
                                         count = (/ mask_size(mid,1) /) )
@@ -1332,5 +1337,5 @@
 
                 nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), &
-                                        id_var_nutm_mask(mid,av,k), &
+                                        id_var_nutm_mask(k,mid,av), &
                                         netcdf_data, start = (/ 1 /), &
                                         count = (/ mask_size(mid,2) /) )
@@ -1371,5 +1376,5 @@
 
                nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), &
-                                       id_var_eutm_mask(mid,av,k), &
+                                       id_var_eutm_mask(k,mid,av), &
                                        netcdf_data_2d, start = (/ 1, 1 /), &
                                        count = (/ mask_size(mid,1), &
@@ -1386,5 +1391,5 @@
              
                nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), &
-                                       id_var_nutm_mask(mid,av,k), &
+                                       id_var_nutm_mask(k,mid,av), &
                                        netcdf_data_2d, start = (/ 1, 1 /), &
                                        count = (/ mask_size(mid,1), &
@@ -1433,5 +1438,5 @@
 
              nc_stat = NF90_PUT_VAR( id_set_mask(mid,av),           &
-                                     id_var_lon_mask(mid,av,k),     &
+                                     id_var_lon_mask(k,mid,av),     &
                                      lon, start = (/ 1, 1 /),       &
                                      count = (/ mask_size(mid,1),   &
@@ -1440,5 +1445,5 @@
 
              nc_stat = NF90_PUT_VAR( id_set_mask(mid,av),           &
-                                     id_var_lat_mask(mid,av,k),     &
+                                     id_var_lat_mask(k,mid,av),     &
                                      lat, start = (/ 1, 1 /),       &
                                      count = (/ mask_size(mid,1),   &
@@ -1778,6 +1783,6 @@
                   (/ id_dim_x_3d(av), id_dim_xu_3d(av) /),    &
                   (/ id_dim_y_3d(av), id_dim_yv_3d(av) /),    &
-                  id_var_eutm_3d(av,:), id_var_nutm_3d(av,:), &
-                  id_var_lat_3d(av,:), id_var_lon_3d(av,:)    )
+                  id_var_eutm_3d(:,av), id_var_nutm_3d(:,av), &
+                  id_var_lat_3d(:,av), id_var_lon_3d(:,av)    )
 !
 !--       Define coordinate-reference system
@@ -2098,5 +2103,5 @@
                    ENDDO
                 
-                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_eutm_3d(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_eutm_3d(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ nx+1 /) )
@@ -2128,5 +2133,5 @@
                    ENDDO
 
-                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_nutm_3d(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_nutm_3d(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ ny+1 /) )
@@ -2166,5 +2171,5 @@
                   ENDDO
                 
-                  nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_eutm_3d(av,k),  &
+                  nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_eutm_3d(k,av),  &
                                           netcdf_data_2d, start = (/ 1, 1 /),   &
                                           count = (/ nx+1, ny+1 /) )
@@ -2179,5 +2184,5 @@
                   ENDDO
                 
-                  nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_nutm_3d(av,k),  &
+                  nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_nutm_3d(k,av),  &
                                           netcdf_data_2d, start = (/ 1, 1 /),   &
                                           count = (/ nx+1, ny+1 /) )
@@ -2249,10 +2254,10 @@
                 ENDDO
 
-                nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_lon_3d(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_lon_3d(k,av), &
                                      lon, start = (/ nxl+1, nys+1 /),       &
                                      count = (/ nxr-nxl+1, nyn-nys+1 /) )
                 CALL netcdf_handle_error( 'netcdf_define_header', 556 )
 
-                nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_lat_3d(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_lat_3d(k,av), &
                                      lat, start = (/ nxl+1, nys+1 /),       &
                                      count = (/ nxr-nxl+1, nyn-nys+1 /) )
@@ -2760,6 +2765,6 @@
                   (/ id_dim_x_xy(av), id_dim_xu_xy(av) /),    &
                   (/ id_dim_y_xy(av), id_dim_yv_xy(av) /),    &
-                  id_var_eutm_xy(av,:), id_var_nutm_xy(av,:), &
-                  id_var_lat_xy(av,:), id_var_lon_xy(av,:)    )
+                  id_var_eutm_xy(:,av), id_var_nutm_xy(:,av), &
+                  id_var_lat_xy(:,av), id_var_lon_xy(:,av)    )
 !
 !--       Define coordinate-reference system
@@ -3154,5 +3159,5 @@
                    ENDDO
                 
-                   nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_eutm_xy(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_eutm_xy(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ nx+1 /) )
@@ -3184,5 +3189,5 @@
                    ENDDO
 
-                   nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_nutm_xy(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_nutm_xy(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ ny+1 /) )
@@ -3222,5 +3227,5 @@
                   ENDDO
                 
-                  nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_eutm_xy(av,k),  &
+                  nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_eutm_xy(k,av),  &
                                           netcdf_data_2d, start = (/ 1, 1 /),   &
                                           count = (/ nx+1, ny+1 /) )
@@ -3235,5 +3240,5 @@
                   ENDDO
                 
-                  nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_nutm_xy(av,k),  &
+                  nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_nutm_xy(k,av),  &
                                           netcdf_data_2d, start = (/ 1, 1 /),   &
                                           count = (/ nx+1, ny+1 /) )
@@ -3284,10 +3289,10 @@
                 ENDDO
 
-                nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_lon_xy(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_lon_xy(k,av), &
                                      lon, start = (/ nxl+1, nys+1 /),       &
                                      count = (/ nxr-nxl+1, nyn-nys+1 /) )
                 CALL netcdf_handle_error( 'netcdf_define_header', 556 )
 
-                nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_lat_xy(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_lat_xy(k,av), &
                                      lat, start = (/ nxl+1, nys+1 /),       &
                                      count = (/ nxr-nxl+1, nyn-nys+1 /) )
@@ -3687,6 +3692,6 @@
                   (/ id_dim_x_xz(av), id_dim_xu_xz(av) /),    &
                   (/ id_dim_y_xz(av), id_dim_yv_xz(av) /),    &
-                  id_var_eutm_xz(av,:), id_var_nutm_xz(av,:), &
-                  id_var_lat_xz(av,:), id_var_lon_xz(av,:)    )
+                  id_var_eutm_xz(:,av), id_var_nutm_xz(:,av), &
+                  id_var_lat_xz(:,av), id_var_lon_xz(:,av)    )
 !
 !--       Define coordinate-reference system
@@ -4035,5 +4040,5 @@
                    ENDDO
                 
-                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_eutm_xz(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_eutm_xz(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ nx+1 /) )
@@ -4069,5 +4074,5 @@
                    ENDDO
 
-                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_nutm_xz(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_nutm_xz(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ ns /) )
@@ -4111,5 +4116,5 @@
                    ENDDO
                    
-                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_eutm_xz(av,k),  &
+                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_eutm_xz(k,av),  &
                                            netcdf_data_2d, start = (/ 1, 1 /),   &
                                            count = (/ nx+1, ns /) )
@@ -4128,5 +4133,5 @@
                    ENDDO
                    
-                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_nutm_xz(av,k),  &
+                   nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_nutm_xz(k,av),  &
                                            netcdf_data_2d, start = (/ 1, 1 /),   &
                                            count = (/ nx+1, ns /) )
@@ -4178,10 +4183,10 @@
                 ENDDO
 
-                nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_lon_xz(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_lon_xz(k,av), &
                                      lon, start = (/ 1, 1 /),       &
                                      count = (/ nx+1, ns /) )
                 CALL netcdf_handle_error( 'netcdf_define_header', 556 )
 
-                nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_lat_xz(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_lat_xz(k,av), &
                                      lat, start = (/ 1, 1 /),       &
                                      count = (/ nx+1, ns /) )
@@ -4546,6 +4551,6 @@
                   (/ id_dim_x_yz(av), id_dim_xu_yz(av) /),    &
                   (/ id_dim_y_yz(av), id_dim_yv_yz(av) /),    &
-                  id_var_eutm_yz(av,:), id_var_nutm_yz(av,:), &
-                  id_var_lat_yz(av,:), id_var_lon_yz(av,:)    )
+                  id_var_eutm_yz(:,av), id_var_nutm_yz(:,av), &
+                  id_var_lat_yz(:,av), id_var_lon_yz(:,av)    )
 !
 !--       Define coordinate-reference system
@@ -4884,5 +4889,5 @@
                    ENDDO
                 
-                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_eutm_yz(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_eutm_yz(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ ns /) )
@@ -4914,5 +4919,5 @@
                    ENDDO
 
-                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_nutm_yz(av,k),&
+                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_nutm_yz(k,av),&
                                            netcdf_data, start = (/ 1 /),   &
                                            count = (/ ny+1 /) )
@@ -4956,5 +4961,5 @@
                    ENDDO
                    
-                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_eutm_yz(av,k),  &
+                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_eutm_yz(k,av),  &
                                            netcdf_data_2d, start = (/ 1, 1 /),   &
                                            count = (/ ns, ny+1 /) )
@@ -4973,5 +4978,5 @@
                    ENDDO
 
-                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_nutm_yz(av,k),  &
+                   nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_nutm_yz(k,av),  &
                                            netcdf_data_2d, start = (/ 1, 1 /),   &
                                            count = (/ ns, ny+1 /) )
@@ -5023,10 +5028,10 @@
                 ENDDO
 
-                nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_lon_yz(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_lon_yz(k,av), &
                                      lon, start = (/ 1, 1 /),       &
                                      count = (/ ns, ny+1 /) )
                 CALL netcdf_handle_error( 'netcdf_define_header', 556 )
 
-                nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_lat_yz(av,k), &
+                nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_lat_yz(k,av), &
                                      lat, start = (/ 1, 1 /),       &
                                      count = (/ ns, ny+1 /) )
@@ -7234,6 +7239,12 @@
     INTEGER(iwp), DIMENSION(0:2), INTENT(OUT) ::  id_var_nutm  !< variable id for N_UTM coordinates
 
+!
+!-- Initialize return values
+    id_var_lat  = -1
+    id_var_lon  = -1
+    id_var_eutm = -1
+    id_var_nutm = -1
+
 #if defined( __netcdf )
-
 !
 !-- Define UTM coordinates
