Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 1887)
+++ trunk/tools/nc_var_tools.py	(revision 1888)
@@ -23302,95 +23302,109 @@
         # Adding p-dimension
         if action == 'new_p_dim':
-            newdim = CFactions[1]
-            newvdim = CFactions[2]
-            if CFactions[3].find('FROMfile') == -1:
-                newvvar = np.float(CFactions[3])
+            # Only doing it if variables does not have already dimension 'pres'
+            if gen.searchInlist(vardims,'pres'):
+                print infmsg
+                print '      ' + fname + ": variable already has 'pres' dimension " +\
+                  "doing nothing !!"
+                return None, None
             else:
-                vn = CFactions[3].split(',')[1]
-                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)
+                newdim = CFactions[1]
+                newvdim = CFactions[2]
+                if CFactions[3].find('FROMfile') == -1:
+                    newvvar = np.float(CFactions[3])
                 else:
-                    newvdn.append(vdn)
-                    newvshape.append(varvalues.shape[idim])
-                idim = idim + 1
-            newvarvalues = np.zeros(tuple(newvshape), dtype=np.float)
-            newvarvalues[:,0,:,:] = varvalues
+                    vn = CFactions[3].split(',')[1]
+                    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])
+            # Only doing it if variables does not have already dimension 'pres'
+            if gen.searchInlist(vardims,'pres'):
+                print infmsg
+                print '      ' + fname + ": variable already has 'pres' dimension " +\
+                  "doing nothing !!"
+                return None, None
             else:
-                vn = CFactions[3].split(',')[1]
-                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)
+                newdim = CFactions[1]
+                newvdim = CFactions[2]
+                if CFactions[3].find('FROMfile') == -1:
+                    newvvar = np.float(CFactions[3])
                 else:
-                    newvdn.append(vdn)
-                    newvshape.append(varvalues.shape[idim])
-                idim = idim + 1
-            newvarvalues = np.zeros(tuple(newvshape), dtype=np.float)
-            newvarvalues[:,0,:,:] = varvalues
+                    vn = CFactions[3].split(',')[1]
+                    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
         else:
             print errormsg
