Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 1420)
+++ trunk/tools/nc_var_tools.py	(revision 1421)
@@ -90,4 +90,5 @@
 # ModelChar: Class object to determine major characterisitcs of a given model output
 # model_characteristics: Functino to provide major characterisitcs of a given model output
+# mthDYNAMICO_toCF: Function to pass a mthDYNAMICO original file to CF-conventions
 # ncreplace: Function to replace something from a netCDF file
 # ncstepdiff: Function to compute differencies between time-steps (deacumulate) a netCDF file
@@ -17764,5 +17765,4 @@
     return
 
-
 def DYNAMICO_toCF(values,ncfile):
     """ Function to pass a DYNAMICO original file to CF-conventions
@@ -17835,4 +17835,78 @@
 
     print fname + ": succesfull CFication of DYNAMICO file '" + ncfile + "' !!"
+
+    return
+
+
+def mthDYNAMICO_toCF(values,ncfile):
+    """ Function to pass a mthDYNAMICO original file to CF-conventions
+      values= [CFtimeUnits]
+        [CFtimeUnits]: [tunits] since [YYYYMMDDHHMISS], CF time-units to which variable time should be used ('!' for spaces)
+      ncfile= file to transform 
+    """
+    fname = 'mthDYNAMICO_toCF'
+
+    if ncfile == 'h':
+        print fname + '_____________________________________________________________'
+        print mthDYNAMICO_toCF.__doc__
+        quit()
+
+    CFT = values.replace('!',' ')
+
+    ofile = 'CF_mthDYNAMICO.nc'
+  
+    ncf = NetCDFFile(ncfile,'a')
+    ncdims = ncf.dimensions.keys()
+    ncvars = ncf.variables.keys()
+
+    # CFing variable 'pres'
+    if gen.searchInlist(ncvars,'pres'):
+        print warnmsg
+        print fname + ": renaming variable 'pres' as 'p' !!"
+        newname = ncf.renameVariable('pres','p')
+    ncf.sync()
+
+    # Re-aranging time-axis
+    tvaro = ncf.variables['time_centered']
+    tvals = tvaro[:]
+    tunits = tvaro.getncattr('units')
+
+    RefDate = CFT.split(' ')[2]
+    RefDateS = RefDate[0:4] + '-' + RefDate[4:6] + '-' + RefDate[6:8] + ' ' +        \
+      RefDate[8:10] + ':' + RefDate[10:12] + ':' + RefDate[12:14]
+    CFtimeUnits = ' '.join(CFT.split(' ')[0:2]) + ' '+ RefDateS
+
+    newtvals = gen.coincident_CFtimes(tvals, CFtimeUnits, tunits)
+    tvaro[:] = newtvals
+    newattr = set_attribute(tvaro, 'units', CFtimeUnits)
+    newattr = set_attribute(tvaro, 'time_origin', CFtimeUnits)
+
+    ncf.sync()
+
+    # CFing dimensions
+    CFdims = {'time_counter': 'time', 'presnivs': 'pres'}
+    for dimn in CFdims.keys():
+        if gen.searchInlist(ncdims,dimn):
+            # Making sure CF dimension is not in the file
+            if not gen.searchInlist(ncdims,CFdims[dimn]):
+                newname = ncf.renameDimension(dimn,CFdims[dimn])
+    ncf.sync()
+
+    ncvars = ncf.variables.keys()
+    # Re-arranging coordinates attribute for all the variables
+    for varn in ncvars:
+        varobj = ncf.variables[varn]
+        varattrs = varobj.ncattrs()
+        if gen.searchInlist(varattrs, unicode('coordinates')):
+            attrv = varobj.getncattr('coordinates')
+            newcoord = str(attrv)
+            for dimn in CFdims.keys():
+                newcoord = newcoord.replace(dimn, CFdims[dimn])
+            newattr = set_attribute(varobj, 'coordinates', newcoord)
+
+    ncf.sync()
+    ncf.close()
+
+    print fname + ": succesfull CFication of mthDYNAMICO file '" + ncfile + "' !!"
 
     return
