Index: /trunk/tools/CFvariables.dat
===================================================================
--- /trunk/tools/CFvariables.dat	(revision 1863)
+++ /trunk/tools/CFvariables.dat	(revision 1864)
@@ -1,10 +1,22 @@
 # File with the values of actions to be done for specific CF variables
-# [cfvarname] [action] [newdimension] [newvardim] [newvarvaluesdim]
+# [cfvarname] [action] [values]
 #   [action] ________
-#     new_z_dim: add a z dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
+#     new_z_dim: add a height dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
+#       # [cfvarname] new_z_dim [newdimension] [newvardim] [newvarvaluesdim]
+#     new_p_dim: add a pressure dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim]
+#       # [cfvarname] new_p_dim [newdimension] [newvardim] [newvarvaluesdim]
 #
+#   [newvarvaluesdim] _______
+#     [number]: direct value to use
+#     Fromfile,[varn]: value to be taken from variable [varn] present in file
 huss new_z_dim height height 2.
 tas new_z_dim height height 2.
 uas new_z_dim height height 10.
 vas new_z_dim height height 10.
+hus new_z_dim pressure pressure 'FROMfile,press'
+ta new_z_dim pressure pressure 'FROMfile,press'
+ua new_z_dim pressure pressure 'FROMfile,press'
+va new_z_dim pressure pressure 'FROMfile,press'
+wa new_z_dim pressure pressure 'FROMfile,press'
+zg new_z_dim pressure pressure 'FROMfile,press'
 
Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 1863)
+++ /trunk/tools/nc_var_tools.py	(revision 1864)
@@ -22866,5 +22866,5 @@
 #quit()
 
-def projection2D_information(PROJn, AXinf, projinf, dx, dy, onc):
+def projection2D_information(PROJn, AXinf, projinf, dx, dy, oncs):
     """ Function to get the basic information of the 2D-projection: new dimensions, variables, ...
       Reproducing: class Projection from wrfncxnj.py
@@ -22872,5 +22872,5 @@
         AXinf: dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T'
         projinf: dictionary with all the information of the projection
-        onc= netCDF object from which retrieve the information
+        oncs= netCDF objects from which retrieve the information
       Returns:
         newdim: dictionary new dimensions to be added {dimn1: dimlength1, ..., dimnN: dimlengthN} 
@@ -22981,11 +22981,18 @@
         newvar['rlon'] = ['grid_longitude', 'longitude in rotated pole grid',        \
           'degrees']
-        if not gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]):
+        found = Flase
+        fileNs = ''
+        for ionc in range(len(oncs)):
+            onc = oncs[ionc]
+            fileNs = fileNs + onc.filepath + ', '
+            if gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]):
+                oXvar = onc.variables[projinf['fileXvals'][0]]
+                break
+        if not found:
             print errormsg
-            print '  ' + fname + ": file does not have variable with X ref values '"+\
-              projinf['fileXrefvals'][0] + "' !!"
+            print '  ' + fname + ": files: " + fileNs + " do not have variable " +   \
+              "with X ref values '" + projinf['fileXrefvals'][0] + "' !!"
             print '    available ones:', onc.variables.keys()
             quit(-1)
-        oXvar = onc.variables[projinf['fileXvals'][0]]
         if len(oXvar.shape) == 3:
             newvarv['rlon'] = oXvar[0,0,:]
@@ -23091,8 +23098,9 @@
     return newdim, newvar, newvarv, nonCFattr
 
-def CFvars(cfvarn, vardims, varvalues, outnc):
+def CFvars(cfvarn, innc, vardims, varvalues, outnc):
     """ Function to adapt a given variable and file following CF-standards
       NOTE: reading information from 'CFvariables.dat'
         cfvarn= provided CF name of the variabale
+        innc= netCDF object with input
         vardims= dimensions of the variable
         varvalues= values of the variable
@@ -23125,9 +23133,69 @@
         action = CFactions[0]
 
-        # Adding z-dimension
-        if action == 'new_z_dim':
+        # Adding p-dimension
+        if action == 'new_p_dim':
             newdim = CFactions[1]
             newvdim = CFactions[2]
-            newvvar = np.float(CFactions[3])
+            if CFactions[3].find('FROMfile') == -1:
+                newvvar = np.float(CFactions[3])
+            else:
+                vn = CFactinos[3].split[0]
+                if not innc.variables.has_key(vn):
+                    print errormsg
+                    print '  ' + fname + ": input file does not have variable '" + vn\
+                      + "' !!"
+                    print '    available ones:', innc.variables.keys()
+                    quit(-1)
+                ovar = innc.variables[vn]
+                # Assuming all the same value!
+                var1D = ovar.flatten()
+                newvvar = var1D[0]
+            outnc.createDimension(newdim, 1)
+            dimvals = gen.CFcorValues(newdim)
+            if not gen.searchInlist(outnc.dimensions, newdim):
+                newdim = outnc.createDimension(newdim, 1)
+            if not outnc.variables.has_key(newvdim):
+                newvar = outnc.createVariable(newvdim, 'f8', (newdim))
+                basicvardef(newvar, dimvals['stdn'], dimvals['longname'],            \
+                  dimvals['units'])
+                newvar[:] = newvvar
+                for ivn in dimvals.keys():
+                    if ivn != 'dimn' and ivn != 'stdn' and ivn != 'longname' and \
+                      ivn != 'units' and ivn != 'maxrank' and ivn != 'length':
+                        set_attribute(newvar,ivn,dimvals[ivn])
+            newvdn = []
+            newvshape = []
+            idim = 0
+            for vdn in vardims:
+                if vdn == 'time':
+                    newvdn.append(vdn)
+                    newvshape.append(varvalues.shape[idim])
+                    newvdn.append(newdim)
+                    newvshape.append(1)
+                else:
+                    newvdn.append(vdn)
+                    newvshape.append(varvalues.shape[idim])
+                idim = idim + 1
+            newvarvalues = np.zeros(tuple(newvshape), dtype=np.float)
+            newvarvalues[:,0,:,:] = varvalues
+
+        # Adding z-dimension
+        elif action == 'new_z_dim':
+            newdim = CFactions[1]
+            newvdim = CFactions[2]
+            if CFactions[3].find('FROMfile') == -1:
+                newvvar = np.float(CFactions[3])
+            else:
+                vn = CFactinos[3].split[0]
+                if not innc.variables.has_key(vn):
+                    print errormsg
+                    print '  ' + fname + ": input file does not have variable '" + vn\
+                      + "' !!"
+                    print '    available ones:', innc.variables.keys()
+                    quit(-1)
+                ovar = innc.variables[vn]
+                # Assuming all the same value!
+                var1D = ovar.flatten()
+                newvvar = var1D[0]
             outnc.createDimension(newdim, 1)
             dimvals = gen.CFcorValues(newdim)
@@ -23175,5 +23243,5 @@
           (http://cmip-pcmdi.llnl.gov/cmip5/output_req.html#metadata)
 
-        values=[dimvarns]:[globattrfile]:[projectfile]
+        values=[dimvarns]:[globattrfile]:[projectfile]:[extrafiles]
           [dimvarns]: ',' separated list for identification of axes, dimensions and 
             variable-dimensions as '[AXIS]|[dimn]|[vardimn]'
@@ -23220,9 +23288,10 @@
                y_resoltuion [value] (resolution along y-axis)
                proj_units [value] (units of the resoltion of the projection)
+          [extrafiles]: ',' list of netCDF files to be used if any additional variable is needed (use 'None' for any)
         ncfile= netCDF file to use
         variable= ',' list of [varfn]@[method]@[Tbnds] to CF transform. A separated file will be 
           created for each variable
           use [varfn]@instantaneous@None for instantaneous values
-          NOTE: CF values will be taken from 'variables_values.dat'
+          NOTE: CF values will be taken from 'variables_values.dat' and 'CFvariables.dat' for fine tunning
             [varfn]: name of the variable inside the file
             [method]: cell_method of the variable ('!' for spaces) uing, standard CF description: 
@@ -23247,5 +23316,5 @@
         quit()
 
-    expectargs = '[dimvarns]:[globattrfilen]:[projectfile]'
+    expectargs = '[dimvarns]:[globattrfilen]:[projectfile]:[extrafiles]'
     gen.check_arguments(fname, values, expectargs, ':')
 
@@ -23253,4 +23322,15 @@
     globalattrfilen = values.split(':')[1]
     projfilen = values.split(':')[2]
+    extrafiles = values.split(':')[3].split(',')
+
+    exonc = []
+    if extrafiles[0] != 'None':
+        for fln in extrafiles:
+            if not os.path.isfile(fln):
+                print errormsg
+                print '  '+fname+"': netCDF extra file '" +fln+ "' does not exist !!"
+                quit(-1)
+            else:
+                exonc.append(NetCDFFile(fln,'r'))
 
     # CF Mandatory global attributes
@@ -23496,5 +23576,6 @@
     if len(filedimvals['X'].shape) == 2 or len(filedimvals['Y'].shape) == 2:
         newDim, newVar, newVARv, nonCFproj = projection2D_information(gattr['grid'], \
-          CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0], onc)
+          CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0],    \
+          exonc + [onc])
 
     if len(newDim.keys()) > 0:
@@ -23645,5 +23726,5 @@
                 elif cdn == 'time': print ' '
                 else: coorv.append(cdn)
-            newVdims, newVvalues = CFvars(cfvarn, CFvardims, ovar[:], onewnc)
+            newVdims, newVvalues = CFvars(cfvarn, onc, CFvardims, ovar[:], onewnc)
             if newVdims is None:
                 newvar=onewnc.createVariable(cfvarn, 'f4', tuple(CFvardims),         \
