Index: trunk/tools/nc_var.py
===================================================================
--- trunk/tools/nc_var.py	(revision 386)
+++ trunk/tools/nc_var.py	(revision 387)
@@ -30,5 +30,6 @@
   'sorttimesmat', 'spacemean', 'statcompare_files', 'submns', 'subyrs', 'TimeInf',   \
   'timemean', 'valmod', 'valmod_dim','varaddattrk', 'varaddattr', 'varaddref',       \
-  'varout', 'varoutold', 'varrmattr', 'varrm', 'vrattr', 'WRF_d0Nref',               \
+  'var_creation', 'varout', 'varoutold', 'varrmattr', 'varrm', 'vrattr',             \
+  'WRF_d0Nref',                                                                      \
   'WRF_CFlonlat_creation', 'WRF_CFtime_creation', 'WRF_CFxtime_creation',            \
   'list_operations']
@@ -211,4 +212,6 @@
 elif oper == 'varaddref':
     ncvar.varaddref(opts.values, opts.ncfile, opts.varname)
+elif oper == 'var_creation':
+    ncvar.var_creation(opts.values, opts.ncfile, opts.varname)
 elif oper == 'varout':
     ncvar.varout(opts.values, opts.ncfile, opts.varname)
Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 386)
+++ trunk/tools/nc_var_tools.py	(revision 387)
@@ -13831,4 +13831,86 @@
 #file_creation('time_counter:12,sizes:24|time@time@seconds since 1949-12-01 00:00:00|f8', 'test.nc', 't_instant')
 
+def var_creation(values, ncfile, varn):
+    """ Operation to create a new variable in a file with a given set of dimensions
+      values= [dimensions]|[varattributes]|[kind]
+        [dimensions]: [dimn1]:[dsize1],...,[dimnN]:[dsizeN], ',' pairs of variable name [dimn] and [size]
+          if [dsize] = 'None', give a third value with the real size
+        [attributes]: [std_name]@[long_name]@[units], standard name, long name and units of the variable
+        [kind]: type of variable (standard netCDF4/C-like values, 'c', 'i', 'f', 'f8',...)
+      ncfile= name of the file
+      varn= name of the variables
+    """
+    fname = 'var_creation'
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print var_creation.__doc__
+        quit()
+
+    expectargs = '[dimensions]|[varattributes]|[kind]'
+ 
+    check_arguments(fname,len(expectargs.split('|')),values,'|',expectargs)
+
+    dimensions = values.split('|')[0].split(',')
+    attributes = values.split('|')[1]
+    kind = values.split('|')[2]
+
+    onc = NetCDFFile(ncfile, 'a')
+
+# Dimensions
+    dnames = []
+    dsize = []
+    for dim in dimensions:
+#        print "  Adding: '" + dim + "' ..."
+        dimn = dim.split(':')[0]
+        dimv = dim.split(':')[1]
+        if dimv == 'None':
+            if len(dim.split(':')) != 3:
+                print errormsg
+                print '  ' + fname + ": dimension '" + dimn + "' is None but the " + \
+                  'size is requried!!'
+                quit(-1)
+            else:
+                dv = None
+                dsize.append(int(dim.split(':')[2]))
+        else:
+            dv = int(dimv)
+            dsize.append(dv)
+
+        dnames.append(dimn)
+
+        if not searchInlist(onc.dimensions, dimn):
+            newdim = onc.createDimension(dimn, dv)
+
+    onc.sync()
+
+# Variable
+    if kind == 'c':
+        newvar = onc.createVariable(varn, 'c', tuple(dnames))
+#        newvar[:] = np.zeros(tuple(dsize), dtype=np.float)
+    if kind == 'f4':
+        newvar = onc.createVariable(varn, 'f4', tuple(dnames))
+        newvar[:] = np.zeros(tuple(dsize), dtype=np.float)
+    elif kind == 'f8':
+        newvar = onc.createVariable(varn, 'f8', tuple(dnames))
+        newvar[:] = np.zeros(tuple(dsize), dtype=np.float64)
+    elif kind == 'i':
+        newvar = onc.createVariable(varn, 'i', tuple(dnames))
+        newvar[:] = np.zeros(tuple(dsize), dtype=int)
+    else:
+        print errormsg
+        print '  ' + fname + ": variable kind '" + kind + "' not ready!!"
+        quit(-1)
+
+    sname = attributes.split('@')[0]
+    lname = attributes.split('@')[1]
+    u = attributes.split('@')[2]
+    
+    newattr = basicvardef(newvar, sname, lname, u)
+
+    onc.sync()
+    onc.close()
+
+#var_creation('dim1:12,sizes:24|time@time@seconds since 1949-12-01 00:00:00|f4', 'test.nc', 'var2')
 #quit()
 
