Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 868)
+++ /trunk/tools/nc_var_tools.py	(revision 869)
@@ -56,4 +56,5 @@
 # grattr: Function to read a global atribute
 # grmattr: Removing a global attribute
+# idims: Give all the dimensions names of a file
 # igattrs: Give all the global attributes of a file
 # increaseDimvar: Function to increase with 1 dimension an existing variable within a netcdf file. Values of the variable will be repeated along the new dimension
@@ -656,5 +657,5 @@
     return
 
-def chdimname(values, ncfile, varn):
+def chdimname(values, ncfile):
   """ Changing the name of the dimension
   values = [olddimname]:[newdimname]
@@ -662,7 +663,5 @@
     [newdimname]: new name of the dimension
   ncfile = netCDF file name
-  varn = variable name
   """
-
   fname = 'chdimname'
 
@@ -674,6 +673,5 @@
   if not os.path.isfile(ncfile):
     print errormsg
-    print '    chdimname: File "' + ncfile + '" does not exist !!'
-    print errormsg
+    print '  ' + fname + ": File '" + ncfile + "' does not exist !!"
     quit(-1)    
 
@@ -685,7 +683,8 @@
   if not ncf.dimensions.has_key(olddimname):
     print warnmsg
-    print '    chdimname: File "' + ncfile + '" does not have dimension "' + olddimname + '" !!!!'
+    print '  ' + fname + ": File '" + ncfile + "' does not have dimension '" +       \
+      olddimname + "' !!"
     ncf.close()
-    quit()
+    quit(-1)
 
   if not olddimname == newdimname and not ncf.dimensions.has_key(newdimname):
@@ -695,6 +694,8 @@
   else:
       print warnmsg
-      print '    chdimname: File "' + ncfile + '" already has dimension name "' + newdimname + '" '
-      print '    chdimname: modifying all the variables which use the old dimension'
+      print '  ' + fname + ": File '" + ncfile + "' already has dimension name '" +  \
+        newdimname + '" '
+      print '  ' + fname + ": modifying all variables which use the old '" +         \
+        olddimname + "' dimension..."
       filevars = ncf.variables
       for fvarn in filevars:
@@ -702,6 +703,6 @@
               fvar = ncf.variables[fvarn]
               fvardims = fvar.dimensions
-              if searchInlist(fvardims, olddimname):
-                  print '    variable "' + fvarn + '" uses dimension "' + olddimname + '" '
+              if gen.searchInlist(fvardims, olddimname):
+#                  print '    variable "' + fvarn + '" uses dimension "' + olddimname + '" '
                   varinf = variable_inf(fvar)
 
@@ -710,5 +711,6 @@
 # From http://stackoverflow.com/questions/9067043/python-replace-list-values-using-a-tuple
                   newdims = tuple([ change.get(x,x) for x in fvardims ])
-                  newvar = ncf.createVariable(fvarn + 'tmpdname', varinf.dtype, newdims, fill_value=varinf.FillValue)
+                  newvar = ncf.createVariable(fvarn + 'tmpdname', varinf.dtype,      \
+                    newdims, fill_value=varinf.FillValue)
                   varv = fvar[:]
                   newvar[:] = varv
@@ -1569,4 +1571,27 @@
 
   print '  # allvars= ' + allvars
+  ncf.close()
+
+  return
+
+def idims(ncfile):
+  """Give all the dimensions names of a file
+    ncfile= netCDFfile name from which all variables will be given
+  """
+  fname = 'idims'
+
+  if not os.path.isfile(ncfile):
+    print errormsg
+    print '    ' + fname + ': File "' + ncfile + '" does not exist !!'
+    quit(-1)    
+
+  ncf = NetCDFFile(ncfile,'r')
+  ncdims = ncf.dimensions
+  alldims=''
+  for dim in ncdims:
+      print vdim
+      alldims=alldims + ':' + dim
+
+  print '  # alldims= ' + alldims
   ncf.close()
 
@@ -9239,12 +9264,18 @@
     tunits = tunitsval + ' since ' + refdateS
 
+# Create dimension
+    if not wrfnc.dimensions.has_key('time'):
+        newdim = wrfnc.createDimension('time', None)
+
     if wrfnc.variables.has_key(varn):
         newvar = wrfnc.variables[varn]
     else:
-        newvar = wrfnc.createVariable('time','f4',('Time'))
+        newvar = wrfnc.createVariable('time','f8',('time'))
 
     newattr = basicvardef(newvar, 'time','time',tunits)
     newvar[:] = cftimes
     newattr = set_attribute(newvar, 'calendar', 'standard')
+    newattr = set_attribute(newvar, 'axis', 'T')
+    newattr = set_attribute(newvar, '_CoordinateAxisType', 'Time')
 
     wrfnc.sync()
@@ -9508,12 +9539,18 @@
         cflats = np.zeros((latv.shape[1],latv.shape[2]), dtype=np.float)
         cflats = latv[0,:,:]
+        dimx = lonv.shape[2]
+        dimy = lonv.shape[1]
     elif len(lonv.shape) == 2:
         cflons = np.zeros((lonv.shape), dtype=np.float)
         cflons = np.where(lonv < 0., lonv + 360., lonv)
         cflats = latv
+        dimx = lonv.shape[1]
+        dimy = lonv.shape[0]
     elif len(lonv.shape) == 1:
         cflons = np.zeros((lonv.shape), dtype=np.float)
         cflons = np.where(lonv < 0., lonv + 360., lonv)
         cflats = latv
+        dimx = lonv.shape[0]
+        dimy = latv.shape[0]
     else:
         print errormsg
@@ -9528,4 +9565,10 @@
 #        for ix in range(lonv.shape[1]):
 #            print ix, lonv[10,ix], cflons[10,ix]
+
+    # Creation of CF-dimensions
+    if not wrfnc.dimensions.has_key('lon'):
+        newdim = wrfnc.createDimension('lon', dimx)
+    if not wrfnc.dimensions.has_key('lat'):
+        newdim = wrfnc.createDimension('lat', dimy)
 
     if wrfnc.variables.has_key(cflonn):
@@ -9536,7 +9579,9 @@
         newvar = wrfnc.variables[cflonn]
     else:
-        newvar = wrfnc.createVariable(cflonn,'f4',('south_north','west_east'))
-    newattr = basicvardef(newvar, 'longitude','longitude','degrees East')
+        newvar = wrfnc.createVariable(cflonn,'f8',('lat','lon'))
+    newattr = basicvardef(newvar, 'longitude','Longitude','degrees_East')
     newvar[:] = cflons
+    newattr = set_attribute(newvar, 'axis', 'X')
+    newattr = set_attribute(newvar, '_CoordinateAxisType', 'Lon')
 
     if wrfnc.variables.has_key(cflatn):
@@ -9547,7 +9592,9 @@
         newvar = wrfnc.variables[cflatn]
     else:
-        newvar = wrfnc.createVariable(cflatn,'f4',('south_north','west_east'))
-    newattr = basicvardef(newvar, 'latitude','latitude','degrees North')
+        newvar = wrfnc.createVariable(cflatn,'f8',('lat','lon'))
+    newattr = basicvardef(newvar, 'latitude','Latitude','degrees_North')
     newvar[:] = cflats
+    newattr = set_attribute(newvar, 'axis', 'Y')
+    newattr = set_attribute(newvar, '_CoordinateAxisType', 'Lat')
 
     wrfnc.sync()
