Index: /trunk/tools/generic_tools.py
===================================================================
--- /trunk/tools/generic_tools.py	(revision 761)
+++ /trunk/tools/generic_tools.py	(revision 762)
@@ -3327,134 +3327,4 @@
     return seasvals
 
-def seasmean(timename, filename, varn):
-    """ Function to compute the seasonal mean of a variable
-    timename= name of the variable time in the file
-    filename= netCDF file name
-    varn= name of the variable
-    """
-    fillValue=1.e20
-
-    ncf = NetCDFFile(filename,'a')
-    ofile = 'seasmean_' + varn + '.nc'
-
-    if not ncf.variables.has_key(varn):
-        print errormsg
-        print '    seasmean: File  "' + filename + '" does not have variable ' + varn + ' !!!!'
-        print errormsg
-        ncf.close()
-        quit(-1)
-
-    varobj = ncf.variables[varn]
-    varinf = variable_inf(varobj)
-    timeobj = ncf.variables[timename]
-    timeinf = cls_time_information(ncf, timename)
-
-    timevals=timeobj[:]
-    netcdftimes = netCDFdatetime_realdatetime(timeinf.units + ' since ' + timeinf.Urefdate, timeinf.calendar, timevals)
-    
-    timeseasons=times_4seasons(netcdftimes, True)
-
-    timeseasvals=seasonal_means(netcdftimes, timevals)
-    
-    ncfnew = NetCDFFile(ofile,'w')
-    ncfnew.createDimension('seastime', timeinf.dimt/4)
-    ncfnew.createDimension('seas', 4)
-
-    newvarobj = ncfnew.createVariable('seastime', 'f4', ('seastime', 'seas',), fill_value=fillValue)
-    newvarobj[:]=timeseasvals
-    attr = newvarobj.setncattr('calendar', timeinf.calendar)
-    attr = newvarobj.setncattr('units', timeinf.units)
-
-    newvarobj = ncfnew.createVariable('seasn', str, ('seas'))
-    attr = newvarobj.setncattr('standard_name', 'seasn')
-    attr = newvarobj.setncattr('long_name', 'name of the season')
-    attr = newvarobj.setncattr('units', '3-months')
-    newvarobj[0]='DJF'
-    newvarobj[1]='MAM'
-    newvarobj[2]='JJA'
-    newvarobj[3]='SON'
-
-    newdims=[]
-    idim = 0
-
-    for ndim in varinf.dimns:
-        if ndim == timename:
-            newdims.append(unicode('seastime'))
-            if not idim == 0:
-                print errormsg
-                print '  seasmean: File  "' + filename + '" does not have time dimension "' + timename + '" as the first one. It has it as # ', idim, ' !!!!'
-                print errormsg
-                ncf.close()
-                quit(-1)
-        else:
-            newdims.append(ndim)
-
-        if not ncfnew.dimensions.has_key(ndim):
-            ncfnew.sync()
-            ncfnew.close()
-            ncf.close()            
-
-            fdimadd(filename + ',' + ndim, ofile)
-            ncf = NetCDFFile(filename,'r')
-            ncfnew = NetCDFFile(ofile,'a')
-
-    print ncfnew.dimensions
-    namedims=tuple(newdims)
-    print namedims
-
-    varobj = ncf.variables[varn]
-    varinf = variable_inf(varobj)
-
-    newvarobj=ncfnew.createVariable(varn + '_seasmean', 'f4', namedims, fill_value=fillValue)
-    attr = newvarobj.setncattr('standard_name', varn + '_seasmean')
-    attr = newvarobj.setncattr('long_name', 'seasonal mean of ' + varn)
-    attr = newvarobj.setncattr('units', varinf.units)
-
-    newvar = np.ones(varinf.dims[0], dtype=varinf.dtype)
-    if varinf.Ndims == 1:
-        newvar = newvarobj[:]
-        newvarobj[:] = seasonal_means(netcdftimes, newvar)
-    if varinf.Ndims == 2:
-        for i in range(varinf.dims[1]):
-            newvar = newvarobj[:,i]
-            newvarobj[:,i] = seasonal_means(netcdftimes, newvar)
-    if varinf.Ndims == 3:
-        for i in range(varinf.dims[1]):
-            for j in range(varinf.dims[2]):
-                newvar = newvarobj[:,i,j]
-                newvarobj[:,i,j] = seasonal_means(netcdftimes, newvar)
-    if varinf.Ndims == 4:
-        for i in range(varinf.dims[1]):
-            for j in range(varinf.dims[2]):
-                for k in range(varinf.dims[3]):
-                    newvar = newvarobj[:,i,j,k]
-                    newvarobj[:,i,j,k] = seasonal_means(netcdftimes, newvar)
-    if varinf.Ndims == 5:
-        for i in range(varinf.dims[1]):
-            for j in range(varinf.dims[2]):
-                for k in range(varinf.dims[3]):
-                    for l in range(varinf.dims[4]):
-                        newvar = newvarobj[:,i,j,k,l]
-                        newvarobj[:,i,j,k,l] = seasonal_means(netcdftimes, newvar)
-    if varinf.Ndims == 6:
-        for i in range(varinf.dims[1]):
-            for j in range(varinf.dims[2]):
-                for k in range(varinf.dims[3]):
-                    for l in range(varinf.dims[4]):
-                        for m in range(varinf.dims[5]):
-                            newvar = newvarobj[:,i,j,k,l,m]
-                            newvarobj[:,i,j,k,l,m] = seasonal_means(netcdftimes, newvar)
-    else:
-        print errormsg
-        print '  seasmean: number of dimensions ', varinf.Ndims, ' not ready !!!!'
-        print errormsg
-        ncf.close()
-        quit(-1)
-
-    ncfnew.sync()
-    ncfnew.close()
-
-    print 'seasmean: Seasonal mean file "' + ofile + '" written!'
-
 def load_variable_lastdims(var, prevdims, Nlastdims):
     """ Function to load the last [Nlastdims] dimensions of a variable [var] at the other dimensions at [prevdims]
@@ -5278,320 +5148,4 @@
 
     return Nvals
-
-def get_namelist_vars(values, namelist):
-    """ Function to get namelist-like  values ([varname] = [value]) 
-    get_namelist_vars(namelist)
-      values= [sectionname],[kout]
-        [sectionname]: name of the section from which one want the values ('all', for all)
-        [kout]: kind of output
-          'tex3': printed output as LaTeX table of three columns \verb+namelist_name+ & value
-          'column': printed output as namelist_name value
-          'dict': as two python dictionary object (namelistname, value and namelistname, sectionname)
-      namelist= namelist_like file to retrieve values
-    >>> get_namelist_vars('geogrid,dic','/home/lluis/etudes/domains/medic950116/namelist.wps')
-    {'e_sn': '32, 97,', 'stand_lon': '0.', 'opt_geogrid_tbl_path': "'./'", 'geog_data_path': "'/home/lluis/DATA/WRF/geog'", 'pole_lat': '90.0', 'ref_lat': '35.0,', 'map_proj': "'lat-lon',", 'parent_id': '1, 1,', 'geog_data_res': "'2m','2m',", 'e_we': '32, 112,', 'dx': '0.35,', 'dy': '0.35,', 'parent_grid_ratio': '1, 3,', 'pole_lon': '0.0', 'ref_lon': '20,', 'j_parent_start': '1, 17,', 'i_parent_start': '1, 31,'}
-    """
-
-    fname = 'get_namelist_vars'
-
-# List of characters which split pairs name/value
-    valuessep = ['=']
-# List of characters which indicate a comment
-    commentchars = ['#']
-
-    if values == 'h':
-        print fname + '_____________________________________________________________'
-        print get_namelist_vars.__doc__
-        quit()
-
-    expectargs = '[sectionname],[kout]'
-    check_arguments(fname,values,expectargs,',')
-
-    secname = values.split(',')[0]
-    kout = values.split(',')[1]
-
-    if not os.path.isfile(namelist):
-        print errormsg
-        print '  ' + fname + ": namelist file '" + namelist + "' does not exist !!"
-        quit(-1)
-
-    ncml = open(namelist, 'r')
-
-    sections = {}
-    namelistvals = {}
-    namelistsecs = {}
-    sectionnames = []
-    namessec = []
-    allnames = []
-    namelistvalssec = {}
-    namelistsecssec = {}
-    nmlname = ''
-    sectionname = ''
-
-    for line in ncml:
-        linevals = reduce_spaces(line)
-        Nvals = len(linevals)
-
-        if Nvals >= 1 and linevals[0][0:1] == '&':
-            if len(sectionnames) > 1:
-                sections[sectionname] = namessec
-
-            sectionname = linevals[0][1:len(linevals[0])+1]
-#            print '    ' + fname + ": new section '" + sectionname + "' !!!"
-            sectionnames.append(sectionname)
-            namessec = []
-            nmlname = ''
-        elif Nvals >= 1 and not searchInlist(commentchars,linevals[0][0:1]):
-            if Nvals >= 3 and searchInlist(valuessep,linevals[1]):
-                nmlname = linevals[0]
-                nmlval = numVector_String(linevals[2:Nvals],' ')
-            elif Nvals == 1:
-                for valsep in valuessep:
-                    if linevals[0].find(valsep) != -1:
-                        nmlname = linevals[0].split(valsep)[0]
-                        nmlval = linevals[0].split(valsep)[1]
-                        break
-            elif Nvals == 2:
-                for valsep in valuessep:
-                    if linevals[0].find(valsep) != -1:
-                        nmlname = linevals[0].split(valsep)[0]
-                        nmlval = linevals[1]
-                        break
-                    elif linevals[1].find(valsep) != -1:
-                        nmlname = linevals[0]
-                        nmlval = linevals[1].split(valsep)[0]
-                        break
-            else:
-                print warnmsg
-                print '  ' + fname + ': wrong number of values', Nvals,              \
-                  'in the namelist line!'
-                print '    line: ',line
-                print '    line values:',linevals
-#                quit(-1)
-
-            namelistvals[nmlname] = nmlval
-            namelistsecs[nmlname] = sectionname
-
-            namessec.append(nmlname)
-            allnames.append(nmlname)
-
-    if len(sectionname) > 1:
-        sections[sectionname] = namessec
-
-    if secname != 'all':
-        if not searchInlist(sections.keys(),secname):
-            print errormsg
-            print '  ' + fname + ": section '" + values + "' does not exist !!"
-            print '    only found:',sectionnames
-            quit(-1)
-
-        namestouse = []
-        for nml in allnames:
-            for nnml in sections[secname]:
-                namelistvalssec[nnml] = namelistvals[nnml]
-                namelistsecssec[nnml] = secname
-                if nml == nnml: namestouse.append(nml)
-    else:
-        namestouse = allnames
-        namelistvalssec = namelistvals
-        namelistsecssec = namelistsecs
-
-    if kout == 'tex3':
-        ofile='get_namelist_vars_3col.tex'
-        fobj = open(ofile, 'w')
-
-        vals = namestouse
-        Nvals = len(vals)
-        Nvals3 = int(Nvals/3)
-        latextab = '\\begin{center}\n\\begin{tabular}{lclclc}\n'
-        for il in range(2):
-            latextab = latextab + '{\\bfseries{name}} & {\\bfseries{value}} & '
-        latextab= latextab+ '{\\bfseries{name}} & {\\bfseries{value}} \\\\ \\hline\n'
-
-        if np.mod(Nvals,3) != 0:
-            Nvals0 = Nvals - np.mod(Nvals,3)
-        else:
-            Nvals0 = Nvals
-
-        for ival in range(0,Nvals0,3):
-            line = ''
-            print '  ival:',ival
-            for il in range(2):
-                line = line + '\\verb+' + vals[ival+il] + '+ & ' +                   \
-                   namelistvalssec[vals[ival+il]].replace('_','\\_') +' & '
-            line = line + '\\verb+' + vals[ival+2] + '+ & ' +                       \
-               namelistvalssec[vals[ival+2]].replace('_','\\_') + ' \\\\\n'
-            latextab = latextab + line
-
-        latextab = latextab + '%not multiple of three!!!!\n'
-        print 'mod:', np.mod(Nvals,3),Nvals0,Nvals
-        if np.mod(Nvals,3) != 0:
-            ival = Nvals0
-            line = ''
-            for il in range(np.mod(Nvals,3)):
-                print 'ival:',ival + il
-                line = line + '\\verb+' + vals[ival+il] + '+ & ' +                   \
-                      namelistvalssec[vals[ival+il]].replace('_','\\_') + ' & '
-            for il in range(2-np.mod(Nvals,3)):
-                line = line + ' & & '
-            latextab = latextab + line + ' & \\\\\n'
-        latextab = latextab + '\\end{tabular}\n\\end{center}\n'
-
-#        print latextab
-        fobj.write(latextab)
- 
-        fobj.close()
-        print fname + ": successful writen '" + ofile + "' LaTeX tale file !!"
-
-        return 
-    elif kout == 'column':
-        for dictv in namestouse:
-            print dictv + ' = ' + namelistvalssec[dictv]
-        return
-    elif kout == 'dict':
-        return namelistvalssec, namelistsecssec
-    else:
-        print errormsg
-        print '  ' + fname + ": kind of output '" + kout + "' not ready!!!"
-        quit(-1)
-
-    return
-
-def WRF_d0Nref(values, geofold):
-    """ Function for the generation of an extra WRF domain from a given one 
-    field_stats(values, ncfile, varn)
-      [values]= [namelist],[minLON],[minLAT],[maxLON],[maxLAT],[Ndomref],[factor],[geogres]
-        [namelist]: namelist.wps to use
-        [minLON],[minLAT]: minimum longitude and latitude
-        [maxLON],[maxLAT]: maximum longitude and latitude
-        [Ndomref]: domain reference number
-        [factor]: resolution factor with respect d01
-        [geogres]: which topography resolution to use
-      [geofold]= folder where to found the geo_em.d0[N-1].nc file
-    """
-
-    fname='WRF_d0Nref'
-
-    if values == 'h':
-        print fname + '_____________________________________________________________'
-        print WRF_d0Nref.__doc__
-        quit()
-
-    expectargs = '[namelist],[minLON],[minLAT],[maxLON],[maxLAT],[Ndomref],[factor],'
-    expectargs = expectargs + '[geogres]'
- 
-    check_arguments(fname,values,expectargs,',')
-
-    namelist = values.split(',')[0]
-    minLON = np.float(values.split(',')[1])
-    minLAT = np.float(values.split(',')[2])
-    maxLON = np.float(values.split(',')[3])
-    maxLAT = np.float(values.split(',')[4])
-    Ndomref = int(values.split(',')[5])
-    factor = int(values.split(',')[6])
-    geogres = values.split(',')[7]
-
-    onml = 'namelist.wps_d0' + str(Ndomref+1)
-
-# Namelist variables to which new value is a copy of the last one
-    repeatvalue = ['start_date' ,'end_date']
-# Namelist variables to which value is increased by 1 (single value)
-    add1 = ['max_dom']
-# Namelist variables to which new value is an increase by 1 of the last one
-    add1value = ['parent_id']
-
-#    ncfile = geofold + '/geo_em.d' + zeros(Ndomref,2) + '.nc'
-    ncfile = geofold + '/geo_em.d0' + str(Ndomref) + '.nc'
-
-    if not os.path.isfile(ncfile):
-        print errormsg
-        print '  ' + fname + ': geo_em file "' + ncfile + '" does not exist !!'
-        quit(-1)    
-
-    ncobj = NetCDFFile(ncfile, 'r')
-
-    nlon='XLONG_M'
-    nlat='XLAT_M'
-
-    lonobj = ncobj.variables[nlon]
-    latobj = ncobj.variables[nlat]
-
-    lon = lonobj[0,:,:]
-    lat = latobj[0,:,:]
-
-    ncobj.close()
-
-    diffmin = np.sqrt((lon - minLON)**2. + (lat - minLAT)**2.)
-    diffmax = np.sqrt((lon - maxLON)**2. + (lat - maxLAT)**2.)
-
-    posdiffmin = index_mat(diffmin,np.min(diffmin))
-    posdiffmax = index_mat(diffmax,np.min(diffmax))
-#    print 'min vals. min:',np.min(diffmin),'max:',np.min(diffmax)
-
-#    print 'min:', minLON, ',', minLAT, ':', posdiffmin, '.', lon[tuple(posdiffmin)], \
-#      ',', lat[tuple(posdiffmin)]
-#    print 'max:', maxLON, ',', maxLAT, ':', posdiffmax, '.', lon[tuple(posdiffmax)], \
-#      ',', lat[tuple(posdiffmax)]
-
-    print '  ' + fname +': coordinates of the SW corner:', posdiffmin, ' NE corner:',\
-      posdiffmax
-
-    nmlobj = open(namelist, 'r')
-    onmlobj = open(onml, 'w')
-    for line in nmlobj:
-        listline = reduce_spaces(line)
-        nvals = len(listline)
-        if nvals > 0:
-            if searchInlist(add1,listline[0]):
-                nmlval = int(listline[nvals-1].replace(',','')) + 1
-                onmlobj.write(' ' + listline[0] + ' = ' + str(nmlval) + ',\n')
-            elif searchInlist(add1value,listline[0]):
-                if Ndomref == 1:
-                    nmlval = 1
-                else:
-                    nmlval = int(listline[nvals-1].replace(',','')) + 1   
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1], ' ') + ' ' +str(nmlval)+',\n')
-            elif searchInlist(repeatvalue,listline[0]):
-                nmlval = listline[nvals-1]
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+'\n')
-            elif listline[0] == 'parent_grid_ratio':
-                nmlval = factor
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            elif listline[0] == 'i_parent_start':
-                nmlval = posdiffmin[1] - 10
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            elif listline[0] == 'j_parent_start':
-                nmlval = posdiffmin[0] - 10
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            elif listline[0] == 'e_we':
-                nmlval = (posdiffmax[1] - posdiffmin[1] + 20)*factor
-                nmlval = nmlval + np.mod(nmlval,factor) + 1
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            elif listline[0] == 'e_sn':
-                nmlval = (posdiffmax[0] - posdiffmin[0] + 20)*factor
-                nmlval = nmlval + np.mod(nmlval,factor) + 1
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            elif listline[0] == 'geog_data_res':
-                nmlval = "'" + geogres + "'"
-                onmlobj.write(' ' + listline[0] + ' = ' +                            \
-                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
-            else:
-                onmlobj.write(line)
-        else:
-            onmlobj.write('\n')
-
-    nmlobj.close()
-    onmlobj.close()
-
-    print fname + ": successfully written new namelist '" + onml + "' !!"
-
-    return
 
 def coincident_CFtimes(tvalB, tunitA, tunitB):
Index: /trunk/tools/nc_var.py
===================================================================
--- /trunk/tools/nc_var.py	(revision 761)
+++ /trunk/tools/nc_var.py	(revision 762)
@@ -171,5 +171,5 @@
     ncvar.get_attribute(opts.values, opts.ncfile, opts.varname)
 elif oper == 'get_namelist_vars':
-    ncvar.get_namelist_vars(opts.values, opts.ncfile)
+    gen.get_namelist_vars(opts.values, opts.ncfile)
 elif oper == 'getvalues_lonlat':
     ncvar.getvalues_lonlat(opts.values, opts.ncfile)
Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 761)
+++ /trunk/tools/nc_var_tools.py	(revision 762)
@@ -824,5 +824,5 @@
   if not os.path.isfile(ncfile):
     print errormsg
-    print '    ' + fname +': File "' + ncfile + '" does not exist !!'
+    print '    ' + fname +": File '" + ncfile + "' does not exist !!"
     print errormsg
     quit(-1)    
@@ -1288,4 +1288,140 @@
   return
  
+def seasmean(timename, filename, varn):
+    """ Function to compute the seasonal mean of a variable
+    timename= name of the variable time in the file
+    filename= netCDF file name
+    varn= name of the variable
+    """
+    fillValue=1.e20
+
+    ncf = NetCDFFile(filename,'a')
+    ofile = 'seasmean_' + varn + '.nc'
+
+    if not ncf.variables.has_key(varn):
+        print errormsg
+        print '    seasmean: File  "' + filename + '" does not have variable ' + varn + ' !!!!'
+        print errormsg
+        ncf.close()
+        quit(-1)
+
+    varobj = ncf.variables[varn]
+    varinf = variable_inf(varobj)
+    timeobj = ncf.variables[timename]
+    timeinf = cls_time_information(ncf, timename)
+
+    timevals=timeobj[:]
+    netcdftimes = netCDFdatetime_realdatetime(timeinf.units + ' since ' +            \
+      timeinf.Urefdate, timeinf.calendar, timevals)
+    
+    timeseasons=times_4seasons(netcdftimes, True)
+
+    timeseasvals=seasonal_means(netcdftimes, timevals)
+    
+    ncfnew = NetCDFFile(ofile,'w')
+    ncfnew.createDimension('seastime', timeinf.dimt/4)
+    ncfnew.createDimension('seas', 4)
+
+    newvarobj = ncfnew.createVariable('seastime', 'f4', ('seastime', 'seas',),       \
+      fill_value=fillValue)
+    newvarobj[:]=timeseasvals
+    attr = newvarobj.setncattr('calendar', timeinf.calendar)
+    attr = newvarobj.setncattr('units', timeinf.units)
+
+    newvarobj = ncfnew.createVariable('seasn', str, ('seas'))
+    attr = newvarobj.setncattr('standard_name', 'seasn')
+    attr = newvarobj.setncattr('long_name', 'name of the season')
+    attr = newvarobj.setncattr('units', '3-months')
+    newvarobj[0]='DJF'
+    newvarobj[1]='MAM'
+    newvarobj[2]='JJA'
+    newvarobj[3]='SON'
+
+    newdims=[]
+    idim = 0
+
+    for ndim in varinf.dimns:
+        if ndim == timename:
+            newdims.append(unicode('seastime'))
+            if not idim == 0:
+                print errormsg
+                print '  ' + fname + ': File  "' + filename + '" does not have ' +   \
+                  'time dimension "' + timename + '" as the first one. It has it as #'\
+                  , idim, ' !!!!'
+                ncf.close()
+                quit(-1)
+        else:
+            newdims.append(ndim)
+
+        if not ncfnew.dimensions.has_key(ndim):
+            ncfnew.sync()
+            ncfnew.close()
+            ncf.close()            
+
+            fdimadd(filename + ',' + ndim, ofile)
+            ncf = NetCDFFile(filename,'r')
+            ncfnew = NetCDFFile(ofile,'a')
+
+    print ncfnew.dimensions
+    namedims=tuple(newdims)
+    print namedims
+
+    varobj = ncf.variables[varn]
+    varinf = variable_inf(varobj)
+
+    newvarobj=ncfnew.createVariable(varn + '_seasmean', 'f4', namedims,              \
+      fill_value=fillValue)
+    attr = newvarobj.setncattr('standard_name', varn + '_seasmean')
+    attr = newvarobj.setncattr('long_name', 'seasonal mean of ' + varn)
+    attr = newvarobj.setncattr('units', varinf.units)
+
+    newvar = np.ones(varinf.dims[0], dtype=varinf.dtype)
+    if varinf.Ndims == 1:
+        newvar = newvarobj[:]
+        newvarobj[:] = seasonal_means(netcdftimes, newvar)
+    if varinf.Ndims == 2:
+        for i in range(varinf.dims[1]):
+            newvar = newvarobj[:,i]
+            newvarobj[:,i] = seasonal_means(netcdftimes, newvar)
+    if varinf.Ndims == 3:
+        for i in range(varinf.dims[1]):
+            for j in range(varinf.dims[2]):
+                newvar = newvarobj[:,i,j]
+                newvarobj[:,i,j] = seasonal_means(netcdftimes, newvar)
+    if varinf.Ndims == 4:
+        for i in range(varinf.dims[1]):
+            for j in range(varinf.dims[2]):
+                for k in range(varinf.dims[3]):
+                    newvar = newvarobj[:,i,j,k]
+                    newvarobj[:,i,j,k] = seasonal_means(netcdftimes, newvar)
+    if varinf.Ndims == 5:
+        for i in range(varinf.dims[1]):
+            for j in range(varinf.dims[2]):
+                for k in range(varinf.dims[3]):
+                    for l in range(varinf.dims[4]):
+                        newvar = newvarobj[:,i,j,k,l]
+                        newvarobj[:,i,j,k,l] = seasonal_means(netcdftimes, newvar)
+    if varinf.Ndims == 6:
+        for i in range(varinf.dims[1]):
+            for j in range(varinf.dims[2]):
+                for k in range(varinf.dims[3]):
+                    for l in range(varinf.dims[4]):
+                        for m in range(varinf.dims[5]):
+                            newvar = newvarobj[:,i,j,k,l,m]
+                            newvarobj[:,i,j,k,l,m] = seasonal_means(netcdftimes, newvar)
+    else:
+        print errormsg
+        print '  seasmean: number of dimensions ', varinf.Ndims, ' not ready !!!!'
+        print errormsg
+        ncf.close()
+        quit(-1)
+
+    ncfnew.sync()
+    ncfnew.close()
+
+    print 'seasmean: Seasonal mean file "' + ofile + '" written!'
+
+    return
+
 def ivars(ncfile):
   """Give all the variable names of a file
@@ -3095,5 +3231,5 @@
 
     arguments = '[Nflipdim]:[flipdim]'
-    check_arguments(fname, values, arguments, ':')
+    gen.check_arguments(fname, values, arguments, ':')
 
     ncf = NetCDFFile(filename,'a')
@@ -3104,5 +3240,6 @@
     if not ncf.variables.has_key(varn):
         print errormsg
-        print '    flipdim: File  "' + filename + '" does not have variable ' + varn + ' !!!!'
+        print '    ' + fname + ': File  "' + filename + '" does not have variable ' +\
+          varn + ' !!!!'
         print errormsg
         ncf.close()
@@ -3114,11 +3251,12 @@
     if varinf.Ndims < Nflipdim:
         print errormsg
-        print '    flipdim: variable "' + varn + '" has less dimensions ', varinf.Ndims, 'than the required to flip "', Nflipdim, '!!!!'
-        print errormsg
+        print '    ' + fname + ': variable "' + varn + '" has less dimensions ',     \
+          varinf.Ndims, 'than the required to flip "', Nflipdim, '!!!!'
         quit(-1)
  
     if flipdim == 'yes':
         flipdimname = varinf.dimns[Nflipdim]
-        print '  flipdim: Flipping also associated dimension variable "' + flipdimname + '"'
+        print '  ' + fname + ': Flipping also associated dimension variable "' +     \
+          flipdimname + '"'
 
         flipdim = ncf.variables[flipdimname]
@@ -3138,6 +3276,6 @@
         else:
             print errormsg
-            print '    flipdim: dimension to flip has ', len(flipdim.shape), ' dimensions, not ready to be flipped !!!'
-            print errormsg
+            print '    ' + fname + ': dimension to flip has ', len(flipdim.shape),   \
+              ' dimensions, not ready to be flipped !!!'
             quit(-1) 
 
@@ -3234,6 +3372,6 @@
     else:
         print errormsg
-        print '    flipdim: Number of dimensions ', varinf.Ndims, ' not ready!!!!'
-        print errormsg
+        print '    ' + fname + ': Number of dimensions ', varinf.Ndims,              \
+          ' not ready!!!!'
         quit(-1)
 
@@ -4011,4 +4149,183 @@
     return
 
+def get_namelist_vars(values, namelist):
+    """ Function to get namelist-like  values ([varname] = [value]) 
+    get_namelist_vars(namelist)
+      values= [sectionname],[kout]
+        [sectionname]: name of the section from which one want the values ('all', for all)
+        [kout]: kind of output
+          'tex3': printed output as LaTeX table of three columns \verb+namelist_name+ & value
+          'column': printed output as namelist_name value
+          'dict': as two python dictionary object (namelistname, value and namelistname, sectionname)
+      namelist= namelist_like file to retrieve values
+    >>> get_namelist_vars('geogrid,dic','/home/lluis/etudes/domains/medic950116/namelist.wps')
+    {'e_sn': '32, 97,', 'stand_lon': '0.', 'opt_geogrid_tbl_path': "'./'", 'geog_data_path': "'/home/lluis/DATA/WRF/geog'", 'pole_lat': '90.0', 'ref_lat': '35.0,', 'map_proj': "'lat-lon',", 'parent_id': '1, 1,', 'geog_data_res': "'2m','2m',", 'e_we': '32, 112,', 'dx': '0.35,', 'dy': '0.35,', 'parent_grid_ratio': '1, 3,', 'pole_lon': '0.0', 'ref_lon': '20,', 'j_parent_start': '1, 17,', 'i_parent_start': '1, 31,'}
+    """
+
+    fname = 'get_namelist_vars'
+
+# List of characters which split pairs name/value
+    valuessep = ['=']
+# List of characters which indicate a comment
+    commentchars = ['#']
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print get_namelist_vars.__doc__
+        quit()
+
+    expectargs = '[sectionname],[kout]'
+    check_arguments(fname,values,expectargs,',')
+
+    secname = values.split(',')[0]
+    kout = values.split(',')[1]
+
+    if not os.path.isfile(namelist):
+        print errormsg
+        print '  ' + fname + ": namelist file '" + namelist + "' does not exist !!"
+        quit(-1)
+
+    ncml = open(namelist, 'r')
+
+    sections = {}
+    namelistvals = {}
+    namelistsecs = {}
+    sectionnames = []
+    namessec = []
+    allnames = []
+    namelistvalssec = {}
+    namelistsecssec = {}
+    nmlname = ''
+    sectionname = ''
+
+    for line in ncml:
+        linevals = reduce_spaces(line)
+        Nvals = len(linevals)
+
+        if Nvals >= 1 and linevals[0][0:1] == '&':
+            if len(sectionnames) > 1:
+                sections[sectionname] = namessec
+
+            sectionname = linevals[0][1:len(linevals[0])+1]
+#            print '    ' + fname + ": new section '" + sectionname + "' !!!"
+            sectionnames.append(sectionname)
+            namessec = []
+            nmlname = ''
+        elif Nvals >= 1 and not searchInlist(commentchars,linevals[0][0:1]):
+            if Nvals >= 3 and searchInlist(valuessep,linevals[1]):
+                nmlname = linevals[0]
+                nmlval = numVector_String(linevals[2:Nvals],' ')
+            elif Nvals == 1:
+                for valsep in valuessep:
+                    if linevals[0].find(valsep) != -1:
+                        nmlname = linevals[0].split(valsep)[0]
+                        nmlval = linevals[0].split(valsep)[1]
+                        break
+            elif Nvals == 2:
+                for valsep in valuessep:
+                    if linevals[0].find(valsep) != -1:
+                        nmlname = linevals[0].split(valsep)[0]
+                        nmlval = linevals[1]
+                        break
+                    elif linevals[1].find(valsep) != -1:
+                        nmlname = linevals[0]
+                        nmlval = linevals[1].split(valsep)[0]
+                        break
+            else:
+                print warnmsg
+                print '  ' + fname + ': wrong number of values', Nvals,              \
+                  'in the namelist line!'
+                print '    line: ',line
+                print '    line values:',linevals
+#                quit(-1)
+
+            namelistvals[nmlname] = nmlval
+            namelistsecs[nmlname] = sectionname
+
+            namessec.append(nmlname)
+            allnames.append(nmlname)
+
+    if len(sectionname) > 1:
+        sections[sectionname] = namessec
+
+    if secname != 'all':
+        if not searchInlist(sections.keys(),secname):
+            print errormsg
+            print '  ' + fname + ": section '" + values + "' does not exist !!"
+            print '    only found:',sectionnames
+            quit(-1)
+
+        namestouse = []
+        for nml in allnames:
+            for nnml in sections[secname]:
+                namelistvalssec[nnml] = namelistvals[nnml]
+                namelistsecssec[nnml] = secname
+                if nml == nnml: namestouse.append(nml)
+    else:
+        namestouse = allnames
+        namelistvalssec = namelistvals
+        namelistsecssec = namelistsecs
+
+    if kout == 'tex3':
+        ofile='get_namelist_vars_3col.tex'
+        fobj = open(ofile, 'w')
+
+        vals = namestouse
+        Nvals = len(vals)
+        Nvals3 = int(Nvals/3)
+        latextab = '\\begin{center}\n\\begin{tabular}{lclclc}\n'
+        for il in range(2):
+            latextab = latextab + '{\\bfseries{name}} & {\\bfseries{value}} & '
+        latextab= latextab+ '{\\bfseries{name}} & {\\bfseries{value}} \\\\ \\hline\n'
+
+        if np.mod(Nvals,3) != 0:
+            Nvals0 = Nvals - np.mod(Nvals,3)
+        else:
+            Nvals0 = Nvals
+
+        for ival in range(0,Nvals0,3):
+            line = ''
+            print '  ival:',ival
+            for il in range(2):
+                line = line + '\\verb+' + vals[ival+il] + '+ & ' +                   \
+                   namelistvalssec[vals[ival+il]].replace('_','\\_') +' & '
+            line = line + '\\verb+' + vals[ival+2] + '+ & ' +                       \
+               namelistvalssec[vals[ival+2]].replace('_','\\_') + ' \\\\\n'
+            latextab = latextab + line
+
+        latextab = latextab + '%not multiple of three!!!!\n'
+        print 'mod:', np.mod(Nvals,3),Nvals0,Nvals
+        if np.mod(Nvals,3) != 0:
+            ival = Nvals0
+            line = ''
+            for il in range(np.mod(Nvals,3)):
+                print 'ival:',ival + il
+                line = line + '\\verb+' + vals[ival+il] + '+ & ' +                   \
+                      namelistvalssec[vals[ival+il]].replace('_','\\_') + ' & '
+            for il in range(2-np.mod(Nvals,3)):
+                line = line + ' & & '
+            latextab = latextab + line + ' & \\\\\n'
+        latextab = latextab + '\\end{tabular}\n\\end{center}\n'
+
+#        print latextab
+        fobj.write(latextab)
+ 
+        fobj.close()
+        print fname + ": successful writen '" + ofile + "' LaTeX tale file !!"
+
+        return 
+    elif kout == 'column':
+        for dictv in namestouse:
+            print dictv + ' = ' + namelistvalssec[dictv]
+        return
+    elif kout == 'dict':
+        return namelistvalssec, namelistsecssec
+    else:
+        print errormsg
+        print '  ' + fname + ": kind of output '" + kout + "' not ready!!!"
+        quit(-1)
+
+    return
+
 def check_times_file(values, filename, timen):
     """ Function to check time-steps of a given file
@@ -4136,4 +4453,5 @@
     Lchar = length of the string in the netCDF file
     """
+    fname = 'writing_str_nc'
 
     Nvals = len(values)
@@ -4150,4 +4468,6 @@
             charvals[ich] = stringv[ich:ich+1]
 
+        print 'Lluis: ' + fname + 'stringv:', stringv, 'charvals:', charvals
+        quit()
         varo[iv,:] = charvals
 
@@ -8534,4 +8854,141 @@
 
 #file_oper_alongdims('time:-1|z:-1|x:-1|y:-1,time:y,mean,pressure:lat', '/home/lluis/etudes/WRF_LMDZ/WaquaL/WRF_LMDZ/AR40/vertical_interpolation_WRFp.nc', 'WRFt')
+
+def WRF_d0Nref(values, geofold):
+    """ Function for the generation of an extra WRF domain from a given one 
+    field_stats(values, ncfile, varn)
+      [values]= [namelist],[minLON],[minLAT],[maxLON],[maxLAT],[Ndomref],[factor],[geogres]
+        [namelist]: namelist.wps to use
+        [minLON],[minLAT]: minimum longitude and latitude
+        [maxLON],[maxLAT]: maximum longitude and latitude
+        [Ndomref]: domain reference number
+        [factor]: resolution factor with respect d01
+        [geogres]: which topography resolution to use
+      [geofold]= folder where to found the geo_em.d0[N-1].nc file
+    """
+
+    fname='WRF_d0Nref'
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print WRF_d0Nref.__doc__
+        quit()
+
+    expectargs = '[namelist],[minLON],[minLAT],[maxLON],[maxLAT],[Ndomref],[factor],'
+    expectargs = expectargs + '[geogres]'
+ 
+    check_arguments(fname,values,expectargs,',')
+
+    namelist = values.split(',')[0]
+    minLON = np.float(values.split(',')[1])
+    minLAT = np.float(values.split(',')[2])
+    maxLON = np.float(values.split(',')[3])
+    maxLAT = np.float(values.split(',')[4])
+    Ndomref = int(values.split(',')[5])
+    factor = int(values.split(',')[6])
+    geogres = values.split(',')[7]
+
+    onml = 'namelist.wps_d0' + str(Ndomref+1)
+
+# Namelist variables to which new value is a copy of the last one
+    repeatvalue = ['start_date' ,'end_date']
+# Namelist variables to which value is increased by 1 (single value)
+    add1 = ['max_dom']
+# Namelist variables to which new value is an increase by 1 of the last one
+    add1value = ['parent_id']
+
+#    ncfile = geofold + '/geo_em.d' + zeros(Ndomref,2) + '.nc'
+    ncfile = geofold + '/geo_em.d0' + str(Ndomref) + '.nc'
+
+    if not os.path.isfile(ncfile):
+        print errormsg
+        print '  ' + fname + ': geo_em file "' + ncfile + '" does not exist !!'
+        quit(-1)    
+
+    ncobj = NetCDFFile(ncfile, 'r')
+
+    nlon='XLONG_M'
+    nlat='XLAT_M'
+
+    lonobj = ncobj.variables[nlon]
+    latobj = ncobj.variables[nlat]
+
+    lon = lonobj[0,:,:]
+    lat = latobj[0,:,:]
+
+    ncobj.close()
+
+    diffmin = np.sqrt((lon - minLON)**2. + (lat - minLAT)**2.)
+    diffmax = np.sqrt((lon - maxLON)**2. + (lat - maxLAT)**2.)
+
+    posdiffmin = index_mat(diffmin,np.min(diffmin))
+    posdiffmax = index_mat(diffmax,np.min(diffmax))
+#    print 'min vals. min:',np.min(diffmin),'max:',np.min(diffmax)
+
+#    print 'min:', minLON, ',', minLAT, ':', posdiffmin, '.', lon[tuple(posdiffmin)], \
+#      ',', lat[tuple(posdiffmin)]
+#    print 'max:', maxLON, ',', maxLAT, ':', posdiffmax, '.', lon[tuple(posdiffmax)], \
+#      ',', lat[tuple(posdiffmax)]
+
+    print '  ' + fname +': coordinates of the SW corner:', posdiffmin, ' NE corner:',\
+      posdiffmax
+
+    nmlobj = open(namelist, 'r')
+    onmlobj = open(onml, 'w')
+    for line in nmlobj:
+        listline = reduce_spaces(line)
+        nvals = len(listline)
+        if nvals > 0:
+            if searchInlist(add1,listline[0]):
+                nmlval = int(listline[nvals-1].replace(',','')) + 1
+                onmlobj.write(' ' + listline[0] + ' = ' + str(nmlval) + ',\n')
+            elif searchInlist(add1value,listline[0]):
+                if Ndomref == 1:
+                    nmlval = 1
+                else:
+                    nmlval = int(listline[nvals-1].replace(',','')) + 1   
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1], ' ') + ' ' +str(nmlval)+',\n')
+            elif searchInlist(repeatvalue,listline[0]):
+                nmlval = listline[nvals-1]
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+'\n')
+            elif listline[0] == 'parent_grid_ratio':
+                nmlval = factor
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            elif listline[0] == 'i_parent_start':
+                nmlval = posdiffmin[1] - 10
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            elif listline[0] == 'j_parent_start':
+                nmlval = posdiffmin[0] - 10
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            elif listline[0] == 'e_we':
+                nmlval = (posdiffmax[1] - posdiffmin[1] + 20)*factor
+                nmlval = nmlval + np.mod(nmlval,factor) + 1
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            elif listline[0] == 'e_sn':
+                nmlval = (posdiffmax[0] - posdiffmin[0] + 20)*factor
+                nmlval = nmlval + np.mod(nmlval,factor) + 1
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            elif listline[0] == 'geog_data_res':
+                nmlval = "'" + geogres + "'"
+                onmlobj.write(' ' + listline[0] + ' = ' +                            \
+                  numVector_String(listline[2:nvals+1],' ') + ' ' + str(nmlval)+',\n')
+            else:
+                onmlobj.write(line)
+        else:
+            onmlobj.write('\n')
+
+    nmlobj.close()
+    onmlobj.close()
+
+    print fname + ": successfully written new namelist '" + onml + "' !!"
+
+    return
 
 def WRF_CFtime_creation(values, ncfile, varn):
