Index: /trunk/tools/generic_tools.py
===================================================================
--- /trunk/tools/generic_tools.py	(revision 1836)
+++ /trunk/tools/generic_tools.py	(revision 1837)
@@ -1483,5 +1483,6 @@
          got an extra dependency...
     >>> variables_values('WRFght')
-    ['z', 'geopotential_height', 0.0, 80000.0, 'geopotential|height', 'm2s-2', 'rainbow', ]
+    ['z', 'geopotential_height', 0.0, 80000.0, 'geopotential|height', 'm2s-2', 
+      'rainbow', '$z$', 'z']
     """
     import subprocess as sub
Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 1836)
+++ /trunk/tools/nc_var_tools.py	(revision 1837)
@@ -22492,5 +22492,4 @@
     return
 
-
 def compute_WRFtime_bnds(timewrfv, period, kindWRFt='begperiod',                    \
   refdate='19491201000000', tunitsval='minutes'):
@@ -22671,3 +22670,153 @@
 
 #onc.close()
+
+def CFmorzization(values, ncfile, variable):
+    """ Function to provide a CF-compilation version of a variable within a file
+      See further details at:
+        - Christensen, Gutowski, Nikulin, and Legutke; 2013. CORDEX Archive Design 
+          (http://cordex.org/publications/report-and-document-archives/)
+        - Taylor, K., and C. Doutriaux, 2011. âCMIP5 Model Output Requirements: File 
+          Contents and Format, Data Structure and Meta Dataâ 
+          (http://cmip-pcmdi.llnl.gov/cmip5/output_req.html#metadata)
+
+        values=[dimvarns]:[globattrfile]
+          [dimvarns]: ',' separated list for identification of axes, dimensions and 
+            variable-dimensions as '[AXIS]|[dimn]|[vardimn]'
+              [AXIS]: axis of the file: 'X', 'Y', 'Z', or 'T'
+              [dimn]: name of the current name of the dimension of the given axis
+              [vardimn]: name of the current name of the variable-dimension of the 
+                given axis
+          [globattrfilen]: name of ASCII file with the given metadata to be added as global attributes
+            with a line per attribute [attrname] [value] it has to have at least (underparenthesis for description)
+            use '#' for comments:
+              institute_id [value, use '!' for spaces] (CV)
+              institution  [value]
+              model_id [value] (CORDEX starts with <institute_id>-)
+              experiment_id	[value] (same CV as CMIP5 with "evaluation" in addition)
+              experiment [value] (long version of "experiment_id")
+              contact [value] ([Name], [email] of contact person)
+              product	[value] (single value: "output")
+              Conventions [value] (later than CF1.4 if present / single value: "CF-1.4")
+              creation_date	[YYYY-MM-DDTHH:MM:SSZ] (format according to UNIDATA conventions, same in CMIP5 & CORDEX)
+              frequency	[value] (same CV as CMIP5 with "sem" in addition; 3hr highest freq. in CORDEX; no "yr")
+              driving_model_id [value] (CMIP5 institute_id, <CMIP5 institute_id>-<member in CMIP5 CV list of model_id>)
+              driving_model_ensemble_member [value] (CMIP5 CV, e.g. "r1i1p1")
+              driving_experiment_name [value] ("evaluation" or <member in CMIP5 CV list of experiment_id >)
+              driving_experiment [value] ("<driving_model_id>,<driving_experiment_name>,<driving_model_ensemble_member>", 
+                members of the CMIP5 list of forcing agents are not necessarily forcing agents of RCM (besides implicitly
+                in driving_experimnt)
+              rcm_version_ID [value] (<free text string>; valid characters only	indicates model modifs during the project
+                e.g.: parameterizations, small upgrades)
+              project_id [value] (single value)
+              CORDEX_domain	[value]	((e.g.: "AFR-44", "AFR-44i", includes resolution acronym)
+              tracking_id [value] (not required or explained in ADD; it is, however, strongly recommended to include it 
+                as prescribed CMIP5.)
+              basetime	[value] (reference time "1949-12-01T00:00:00Z" formatted acording to UNIDATA conventions)
+              calendar	[value] (CF conventions	as in driving model)
+              grid [value] (according to CF conventions
+        ncfile= netCDF file to use
+        variable= ',' list of variables to CF transform ('all' for all variables). A separated file will be created
+          for each variable
+          NOTE: CF values will be taken from 'variables_values.dat'
+    """
+    fname = 'CFmorzization'
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print CFmorzizarion.__doc__
+        quit()
+
+    expectargs = '[dimvarns]:[globattrfilen]'
+    gen.check_arguments(fname, values, expectargs, ':')
+
+    dimvarns = values.split(':')[0].split(',')
+    globalattrfilen = values.split(':')[1]
+
+    # CF Mandatory global attributes
+    mangattr = ['institute_id', 'institution', 'model_id', 'experiment_id',          \
+      'experiment', 'contact', 'product', 'Conventions', 'creation_date','frequency',\
+      'driving_model_id', 'driving_model_ensemble_member', 'driving_experiment_name',\
+      'driving_experiment', 'rcm_version_ID', 'project_id', 'CORDEX_domain',         \
+      'tracking_id', 'basetime', 'calendar', 'grid']
+
+    # Getting axes information
+    axisinf = {}
+    for dvn in dimvarns:
+        axis = dvn.split('|')[0]
+        dimn = dvn.split('|')[1]
+        dimvn = dvn.split('|')[2]
+        axisinf[axis] = [dimn, dimvn]
+ 
+    # Getting global attributes
+    if not os.path.isfile(globalattrfilen):
+        print errormsg
+        print '  '+fname+ "': ASCII file with global attributes '" + globalattrfilen \
+          + "' does not exist !!"
+        quit(-1)
+
+    gattr = {}
+    ogatrf = open(globalattrfilen, 'r')
+    for line in ogatrf:
+        if line[0:1] != '#' and len(line) > 1:
+            linevals = line.replace('\n','').replace('\t','').split(' ')
+            gattr[linevals[0]] = linevals[1].replace('!',' ')
+    ogatrf.close()
+    # Checking for presence of mandatory attributes
+    for mgattr in mangattr:
+        if not gattr.has_key(mgattr):
+            print errormsg
+            print '  '+fname+ "': ASCII file with global attributes does not " +     \
+              "contain attribute '" + mgattr + "' !!"
+            quit(-1)
+
+    # Getting variables to process
+    onc = NetCDFFile(ncfile,'r')
+    if variable == 'all':
+        Varns = onc.variables
+        # Removing axis variables
+        for axis in axisinf.keys:
+            dimvn = axis[axis][1]
+            if gen.searchInlist(Varns, dimvn): Varns.remove(dimvn)
+    else:
+        Varns = gen.str_list(variable, ',')
+
+    # Creation of new file name
+    # This will done following CORDEX rules (getting information from the ASCII 
+    #   global attributes and variable):
+    # Institution: institude_id
+    # VariableName: from `variables_values.dat'
+    # Domain: CORDEX_domain
+    # GCMModelName:	driving_model_id
+    # CMIP5ExperimentName: driving_experiment_name
+    # CMIP5EnsembleMember: driving_model_ensemble_member
+    # RCMModelName: model_id
+    # RCMVersionID: rcm_version_id
+    # Frequency: frequency
+    # StartTime-EndTime: (not allowed if <frequency>=fx)
+    # filen = Institution_VariableName_Domain_GCMModelName_CMIP5ExperimentName_
+    #   CMIP5EnsembleMember_RCMModelName_RCMVersionID_Frequency_StartTime-EndTime.nc
+
+    for vn in varns:
+        # getting CF information
+        varinf = gen.variables_values(vn)
+        cfvarn = varinf[0]
+        stdvarn = varinf[1]
+        longvarn = varinf[4].replace('|', ' ')
+
+        if not onc.variables.has_key(vn):
+            print errormsg
+            print '  '+fname+ "': netcdf file '" + ncfile + "' does not contain " +  \
+              "variable '" + vn + "' !!"
+            onc.close()
+            quit(-1)
+
+        filen = gattr['institude_id'] + '_' + cfvarn + '_' + gattr['CORDEX_domain'] +\
+          '_' + gattr['driving_model_id'] + '_' + gattr['driving_experiment_name'] + \
+          '_' + gattr['driving_model_ensemble_member'] + '_' + gattr['model_id'] +   \
+          '_' + gattr['rcm_version_id'] + '_' + Sfrequency + '_' StartTime-EndTime + \
+          '.nc'
+
+    onc.close()
+    return 
+
 #quit()
