Index: trunk/tools/nc_var.py
===================================================================
--- trunk/tools/nc_var.py	(revision 385)
+++ trunk/tools/nc_var.py	(revision 386)
@@ -21,5 +21,6 @@
   'compute_opervaralltime', 'compute_opervartimes', 'compute_tevolboxtraj',          \
   'DataSetSection', 'DataSetSection_multidims', 'dimVar_creation', 'fattradd',       \
-  'fdimadd', 'fgaddattr', 'field_stats', 'file_oper_alongdims', 'filter_2dim',       \
+  'fdimadd', 'fgaddattr', 'field_stats', 'file_creation', 'file_oper_alongdims',     \
+  'filter_2dim',                                                                     \
   'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_namelist_vars', 'grattr',      \
   'grmattr', 'igattrs', 'isgattrs', 'isvattrs', 'ivars', 'ivattrs', 'maskvar',       \
@@ -77,5 +78,5 @@
 
 # Operations which file name is not a real file
-NotCheckingFile = ['list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation']
+NotCheckingFile = ['file_creation', 'list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation']
 
 ####### ###### ##### #### ### ## #
@@ -127,4 +128,6 @@
 elif oper == 'fgaddattr':
     ncvar.fgaddattr(opts.values, opts.ncfile)
+elif oper == 'file_creation':
+    ncvar.file_creation(opts.values, opts.ncfile, opts.varname)
 elif oper == 'file_oper_alongdims':
     ncvar.file_oper_alongdims(opts.values, opts.ncfile, opts.varname)
Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 385)
+++ trunk/tools/nc_var_tools.py	(revision 386)
@@ -13745,4 +13745,90 @@
 #ncstepdiff('Time,Times', '/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00.tests', 'Q2,T2')
 
+def file_creation(values, ncfile, varn):
+    """ Operation to create a file with one variable 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 = 'file_creation'
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print file_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, 'w')
+
+# 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)
+
+        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()
+
+# Global attributes
+    newattr = set_attribute(onc, 'description', "file creation using " + fname )
+    onc.sync()
+    onc.close()
+
+#file_creation('time_counter:12,sizes:24|time@time@seconds since 1949-12-01 00:00:00|f8', 'test.nc', 't_instant')
+
 #quit()
 
