Home

M3D Python script



#! /usr/bin/env python 
""" syntax: python m3d.py m3d.in """

Initialize python and run syntax. Please keep them.
Reference: docs.python.org/tut, docs.python.org/lib, docs.python.org/ref.

import os
import re
import sys
import string

All the modules we need right now. Make them global for code simplicity.

#set up selectors
pcoment=re.compile('^(\s)*#.*')
pnewline=re.compile('^(\s)*\n$')
pstar=re.compile('^(\*)\w')
pnlist=re.compile('^&')

peel of comment lines, such as a line start with # sign: #This is modified on xx-xx-xxxx;
peel of unnecessary blank lines;
find the item checked by *, such as a line: seaborg *jaguar #I am choosing jaguar this time;
count the number of namelist in wxy file.

 
#IDs for all the fields given in m3d.input file
pmkfile=re.compile('^__makefile__', re.IGNORECASE)
pexec=re.compile('^__executable__', re.IGNORECASE)
pcomputer=re.compile('^__name_of_computer__', re.IGNORECASE)
pquenue=re.compile('^__name_of_quenue__', re.IGNORECASE)
presource=re.compile('^__resource__', re.IGNORECASE)
pjobname=re.compile('^__runtime_job_name__', re.IGNORECASE)
pmode=re.compile('^__runtime_mode__', re.IGNORECASE)
pequilibrium=re.compile('^__equilibrium__', re.IGNORECASE)
pchk=re.compile('^__checkpoint__', re.IGNORECASE)
pothers=re.compile('^__others__', re.IGNORECASE)
pconf=re.compile('^__configuration__', re.IGNORECASE)
pwxy=re.compile('^__wxy__', re.IGNORECASE)
pend=re.compile('^__', re.IGNORECASE)

IDs for all the fields listed in m3d.input and their names are self-explained.
The order of the field in m3d.input can be arbituary up to your convenience
except the following two:
__START__
__END__
They have to be in the begining and the end of the m3d.input, respectively.
They are picked up by ID "pend".
Up to this point, makefile generator is not available yet.
re.IGNORECASE means both lower case and upper case letters are acceptable.

 
#computer
pseaborg=re.compile('seaborg', re.IGNORECASE) 
pjacquard=re.compile('jacquard', re.IGNORECASE) 
pjaguar=re.compile('jaguar', re.IGNORECASE) 
pbgl=re.compile('bgl', re.IGNORECASE) 

A list of all the computers M3D are running now. More can be added in future.

 
#quenue
pinteractive=re.compile('interactive', re.IGNORECASE) 
pdebug=re.compile('debug', re.IGNORECASE) 
pregular=re.compile('regular', re.IGNORECASE) 
ppremium=re.compile('premiun', re.IGNORECASE) 
pbatch=re.compile('batch', re.IGNORECASE) 

A list of all the quenue available for users. More can be added in future.
Actually "interactive" can be deleted since it is only used on Seaborg and
its turn-around time is the same as "debug" quenue.

 
#convenient definitions
bn = ' '
nline = '\n'

"bn" represent one space; "nline" represents a new line.
These are given for code simplicity. Also anyone can add his/hers.

 
#default variables
name_of_exe='m3dp.x'
name_of_computer='seaborg'
name_of_quenue = 'debug'
num_of_proc=1
num_of_proc_total=1
wtime='00:30:00'
name_of_job='m3dp'
name_of_mode='vn'
name_of_equilibrium='vmec4.dat'
name_of_checkpoint=''
name_of_config='config.dat'
memory='4GB'

The name of all the global variables and their default values.

 
#__________________________fun1 generate wxy file__________________________
def construct_wxy_file(wxy):
   """driver for m3d dec-21-2006 by Jin Chen"""

   new_wxy=[]
   nlist_in_wxy=[]

   for item in wxy:
        if(pcoment.match(item)):                   #get rid of comment lines
                pass
        elif(pnewline.match(item)):                #get rid of blank lines
                pass
        else:
		new_wxy.append(string.strip(item)) #get rid of \n
   #print new_wxy

   #f=open('wxy', 'w')                             
   for item in new_wxy:                            #item is a string, wxy is a list
	#f.write(item)
        first=string.strip(item)
        second= re.sub(r"(\s)+=", "=", item)       #get rid of space before =
        third= re.sub(r"=(\s)+", "=", second)      #get rid of the space after =
        fourth= re.sub(r"(\s)+", " ", third)       #keep only one space bettwen the fields
        fifth= re.split(r"\s", fourth)             #fifth is a list
        for field in fifth:
		#sys.stdout.write(field+nline)     
                #f.write(field+nline)              #write a new look of wxy file
                if(pnlist.match(field)):           #count the number of namelist found for wxy file
                        #print '        is', wxy.index(' '+field+'\n'), 'th position in wxy'
                        nlist_in_wxy.append(field)
   #f.close()

   num_nlist=len(nlist_in_wxy)
   print num_nlist, 'namelists are found for wxy :', nlist_in_wxy 
   print 

Module construct_wxy_file. Rewrite the wxy file with each variable per line. For example,
if we uncomment the following 3 lines:
      #f=open('wxy', 'w')
                                #f.write(field+nline)
      #f.close()
wxy has a

look.

 
#__________________________fun2 generate conf file__________________________
def construct_con_file(con):
   """driver for m3d dec-21-2006 by Jin Chen"""

   new_con=[]

   for item in con:
	if(pcoment.match(item)):         #peel of comment lines
		pass
	elif(pnewline.match(item)):      #peel of blank lines
		pass
	else:
		#f_m3d = re.match(r"(.+[\.].+)#(.*)", item)    #peel of comments
		f_m3d = re.match(r"(.+[\.].+)(//)(.*)", item)  #find floats
		i_m3d = re.match(r"(\d+)\s+(.*)", item)        #find integers
		if(f_m3d):
			#print m_m3d.group(0)
			new_con.append(string.atof(f_m3d.group(1)))  #found a float number
		elif(i_m3d):
			#print n_m3d.group(0)
			new_con.append(string.atoi(i_m3d.group(1)))  #found an integer
		else:
			new_con.append(item)                   #if it's a string

   #f=open(name_of_config, 'w')        #write a new look of config file
   #for item in new_con:
	#sys.stdout.write(str(item)+nline) 
	#f.write(m3d[item])
   #f.close()

   #get the numbers to calculate the total number of processors needed for the job
   A= new_con[0]
   B= new_con[1]
   C= new_con[2]
   D= new_con[3]
   E= new_con[4]
   F= new_con[5]
   #global num_of_proc_total
   if(D==1):
	num_of_proc_total=B*F
   elif(D==2):
	num_of_proc_total=B*(F+1)
   print 'num_of_proc_total = ', num_of_proc_total 
   print 

   #return it since "num_of_proc_total" is a global variable
   return num_of_proc_total

Module construct_con_file. It will calculate the total number of processors
using the values given in configuration file.
If user prefers, she/he can rewrite the config file with each value per line. For example,
if the following 4 lines are uncommented:
     #f=open(name_of_config, 'w')
     #for item in new_con:
                #f.write(m3d[item])
     #f.close()
config.dat has a

look.

 
#__________________________fun3 generate job script__________________________
def construct_job_file(other_option):
   """driver for m3d dec-21-2006 by Jin Chen"""

   pbs_sign = '#@'
   resource ='' 
   account_no = 'mp288'
   runtime_option = ''

   #computer
   nodes= num_of_proc_total / num_of_proc
   print 'num_of_nodes = ', nodes
   sys.stdout.write('generate job submit file and then submitt the job'+nline)

   #mpi command
   if (pseaborg.match(name_of_computer)):
	runtime_option = runtime_option + 'poe' +bn

   if (pjacquard.match(name_of_computer)):
	runtime_option = runtime_option + 'mpiexec' +bn
	pbs_sign = '#PBS'
	resource =''+ 'nodes=' + str(nodes) +':' + 'ppn=' + str(num_of_proc) + ',' + wtime

   if (pjaguar.match(name_of_computer)):
	runtime_option = runtime_option + 'yod' +bn
	pbs_sign = '#PBS'
	size = nodes
	sn = re.search("sn", name_of_mode)
	if(sn):
		size = num_of_proc_total
	resource =''+ wtime +','+ memory +','+ 'size=' + str(size)
	account_no = 'FUS013'  #FUS013dev and FUS013cem

   if (pbgl.match(name_of_computer)):
	runtime_option = runtime_option + 'cqsub' +bn+ ...
              '-q' +bn+ name_of_quenue +bn+ '-t' +bn+ str(wtime) +bn+ ...
              '-n' +bn+ str(num_of_proc*nodes) +bn+ '-'+name_of_mode +bn+ ...
              str(num_of_proc*nodes) +bn


   #m3d executable
   runtime_option = runtime_option + name_of_exe + bn

   if (pseaborg.match(name_of_computer)):
	if(pinteractive.match(name_of_quenue)):
		runtime_option = runtime_option +bn+ '-retry 20 -retrycount 100' +bn+ \
		'-nodes' +bn+ str(nodes) +bn+ \
		'-tasks_per_node' +bn+ str(num_of_proc) +bn
   elif (pjaguar.match(name_of_computer)):
	runtime_option = runtime_option + '-'+name_of_mode.upper() +bn

   runtime_option = runtime_option + '\\' + nline

   #physics
   vmec = re.search("vmec", name_of_equilibrium)
   equin = re.search("\.in", name_of_equilibrium)
   if(vmec) :
	runtime_option = runtime_option + '-vmecfile' +bn+ name_of_equilibrium +bn+'\\'+nline
   elif equin:
	runtime_option = runtime_option + '-vmecInput' +bn+ name_of_equilibrium +bn+'\\'+nline

   if(name_of_checkpoint):
	runtime_option = runtime_option + '-checkpoint' +bn+ name_of_checkpoint +bn+'\\'+nline

   if(name_of_config):
	runtime_option = runtime_option + '-configFile' +bn+ name_of_config +bn+'\\'+nline

   runtime_option = runtime_option +'\\'+nline

   #other options
   runtime_option = runtime_option + other_option +'\\'+nline
   runtime_option = runtime_option +'\\'+nline

   #solver options
   symm = re.search("m3dp_fsymm", name_of_exe)
   if not symm:
	runtime_option = runtime_option  + '-poisson_pc_type asm' +bn+'\\'+nline \
	                                 + '-poisson_pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-poisson_sub_pc_type ilu' +bn+'\\'+nline \
	                                 + '-poisson_sub_pc_ilu_levels 3' +bn+'\\'+nline \
	                                 + '-poisson_ksp_type gmres' +bn+'\\'+nline  \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-poissonN_pc_type asm' +bn+'\\'+nline \
	                                 + '-poissonN_pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-poissonN_sub_pc_type ilu' +bn+'\\'+nline \
	                                 + '-poissonN_sub_pc_ilu_levels 3' +bn+'\\'+nline \
	                                 + '-poissonN_ksp_type gmres' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-xflg_nullspace' +bn+'\\'+nline \
	                                 + '-xpoissonN_pc_type asm' +bn+'\\'+nline \
	                                 + '-xpoissonN_pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-xpoissonN_sub_pc_type icc' +bn+'\\'+nline \
	                                 + '-xpoissonN_sub_pc_factor_levels 3' +bn+'\\'+nline \
	                                 + '-xpoissonN_ksp_type cg' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-poissonH_pc_type asm' +bn+'\\'+nline \
	                                 + '-poissonH_pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-poissonH_sub_pc_type ilu' +bn+'\\'+nline \
	                                 + '-poissonH_sub_pc_ilu_levels 3' +bn+'\\'+nline \
	                                 + '-poissonH_ksp_type gmres' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-pc_type asm' +bn+'\\'+nline \
	                                 + '-pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-sub_pc_type ilu' +bn+'\\'+nline \
	                                 + '-sub_pc_ilu_levels 3' +bn+'\\'+nline \
	                                 + '-ksp_type gmres' +bn+'\\'+nline

	#runtime_option = runtime_option  + '-poisson_ksp_view -poisson_ksp_monitor \
                          -poissonN_ksp_view -poissonN_ksp_monitor \
                          -poissonH_ksp_view -poissonH_ksp_monitor \
                          -ksp_view -ksp_monitor'
   elif symm :
	runtime_option = runtime_option  + '-poisson_pc_type hypre' +bn+'\\'+nline \
	                                 + '-poisson_pc_hypre_type boomeramg' +bn+'\\'+nline \
	                                 + '-poisson_ksp_type cg' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-poissonN_pc_type hypre' +bn+'\\'+nline \
	                                 + '-poissonN_pc_hypre_type boomeramg' +bn+'\\'+nline \
	                                 + '-poissonN_ksp_type cg' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-xflg_nullspace' +bn+'\\'+nline \
	                                 + '-xpoissonN_pc_type asm' +bn+'\\'+nline \
	                                 + '-xpoissonN_pc_asm_overlap 1' +bn+'\\'+nline \
	                                 + '-xpoissonN_sub_pc_type icc' +bn+'\\'+nline \
	                                 + '-xpoissonN_sub_pc_factor_levels 3' +bn+'\\'+nline \
	                                 + '-xpoissonN_ksp_type cg' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-poissonH_pc_type hypre' +bn+'\\'+nline \
	                                 + '-poissonH_pc_hypre_type boomeramg' +bn+'\\'+nline \
	                                 + '-poissonH_ksp_type cg' +bn+'\\'+nline \
	                                 + '\\' + nline

	runtime_option = runtime_option  + '-pc_type jacobi' +bn+'\\'+nline \
	                                 + '-ksp_type cg' +bn+'\\'+nline

	#runtime_option = runtime_option  + '-poisson_ksp_view -poisson_ksp_monitor \
                          -poissonN_ksp_view -poissonN_ksp_monitor \
                          -poissonH_ksp_view -poissonH_ksp_monitor \
                          -ksp_view -ksp_monitor'
   print 
   #print 'runtime_option = %s'% runtime_option

   #generate job script
   if (pseaborg.match(name_of_computer)):
	   if(pinteractive.match(name_of_quenue)):
		f=open('rs.'+name_of_computer+'_'+name_of_job, 'w')
		f.write(runtime_option)
		f.close()
		sys.stderr.write('submit job: rs.'+name_of_computer+'_'+name_of_job)
		os.system('rs.'+name_of_computer+'_'+name_of_job)
	   else:
		f=open('bs.'+name_of_computer+'_'+name_of_job, 'w')
		f.write('#@ shell           = /usr/bin/csh\n')
		f.write('#@ name_of_job        = %s\n'%name_of_job)
		f.write('#@ output          = %s.out\n'%name_of_job)
		f.write('#@ error           = %s.err\n'%name_of_job)
		f.write('#@ account_no      = %s\n'%account_no)
		f.write('#@ job_type        = parallel\n')
		f.write('#@ class           = %s\n'%name_of_quenue)
		f.write('#@ tasks_per_node  = '+ str(num_of_proc) +'\n')
		f.write('#@ node            = '+ str(nodes) +'\n')
		f.write('#@ wall_clock_limit= %s\n'% wtime)
		f.write('#@ notification    = complete\n')
		f.write('#@ network.MPI     = csss,not_shared,us\n')
		f.write('#@ queue\n')
		f.write('\n')
		f.write(runtime_option)
		f.write('\n')
		f.write('\n')
		f.write('echo End of Execution `date`\n')
		f.write('\n')
		f.write('exit\n')
		f.close()
		sys.stderr.write('submit job: bs.'+name_of_computer+'_'+name_of_job)
		os.system('llsubmit bs.'+name_of_computer+'_'+name_of_job)
   elif (pbgl.match(name_of_computer)):
		f=open('rs.'+name_of_computer+'_'+name_of_job, 'w')
		f.write(runtime_option)
		f.close()
		sys.stderr.write('submit job: rs.'+name_of_computer+'_'+name_of_job)
		os.system('cqsub rs.'+name_of_computer+'_'+name_of_job)
   else:
		f=open('bs.'+name_of_computer+'_'+name_of_job, 'w')
		f.write('#!/bin/csh' + nline)
		f.write(pbs_sign +bn+ '-A' +bn+ '%s\n' % account_no)
		f.write(pbs_sign +bn+ '-N' +bn+ '%s\n' % name_of_job )
		f.write(pbs_sign +bn+ '-o' +bn+ '%s.out\n' % name_of_job)
		f.write(pbs_sign +bn+ '-e' +bn+ '%s.err\n' % name_of_job)
		f.write(pbs_sign +bn+ '-l' +bn+ '%s\n' % resource)
		f.write(pbs_sign +bn+ '-q' +bn+ '%s\n' % name_of_quenue)
		f.write(pbs_sign +bn+ '-m' +bn+ 'e\n')
		f.write(pbs_sign +bn+ '-V\n')
		f.write(nline)
		if (pjacquard.match(name_of_computer)):
			#path = os.getcwd()
			#pritnt path
			#f.write('cd'+bn+path)
			f.write('echo'+bn+'$PBS_NODEFILE'+nline)
			f.write('echo'+bn+'$PBS_O_WORKDIR'+nline)
			f.write(nline)
			f.write('cd'+bn+'$PBS_O_WORKDIR'+nline)
		f.write(nline)
		f.write(runtime_option)
		f.write(nline)
		f.write(nline)
		f.write('echo End of Execution `date`\n')
		f.write(nline)
		f.write('exit' + nline)
		f.close()
		sys.stderr.write('qsub job: bs.'+name_of_computer+'_'+name_of_job)
		os.system('qsub bs.'+name_of_computer+'_'+name_of_job)

Module construct_job_file.
It generates runtime script for each individual machine and submit the job in the end.

 
#__________________________main__________________________
if __name__ == "__main__":
   """driver for m3d dec-21-2006 by Jin Chen"""

   #all the lists and variables are defined here.
   resource=[]
   others=[]
   con=[]
   wxy=[]
   block=[]
   start_of_resource = 0
   start_of_others = 0
   start_of_conf = 0
   start_of_wxy = 0

   #read in the files
   name_m3d=sys.argv[1]
   fid_m3d=file(name_m3d, 'r')
   m3d=fid_m3d.readlines()            #m3d is a list
   fid_m3d.close()
   print 'm3d input is given in file %s'% name_m3d
   #for  item in m3d:
	#sys.stdout.write(item)
   print

   #seperate  each block into individual list
   for item in m3d:
	if(pmkfile.match(item)):
		block.append(m3d.index(item))
	elif(pexec.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
		                name_of_exe = item[1:]
		print 'name_of_executable:	%s'% name_of_exe
	elif(pcomputer.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
				name_of_computer=item[1:]
		print 'name_of_computer:	%s'% name_of_computer
	elif(pquenue.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
				name_of_quenue=item[1:]
		print 'name_of_quenue:	%s'% name_of_quenue
	elif(presource.match(item)):
		ind=m3d.index(item)
		block.append(ind)
		start_of_resource = len(block)-1
		#presource=m3d[ind+1].strip()
		#print 'wall_clock_time is:	%s'% wtime
	elif(pjobname.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
		                name_of_job=item[1:] 
		print 'runtime job name is:	%s'% name_of_job
	elif(pmode.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
				name_of_mode=item[1:]
		print 'name_of_mode:	%s'% name_of_mode
	elif(pequilibrium.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
				name_of_equilibrium=item[1:]
		print 'name_of_equilibrium:	%s'% name_of_equilibrium
	elif(pchk.match(item)):
		ind=m3d.index(item)
		block.append(ind)
                first = string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
		                name_of_checkpoint=item[1:] 
		print 'name_of_checkpoint:	%s'% name_of_checkpoint
	elif(pothers.match(item)):
		ind=m3d.index(item)
		block.append(ind)
		start_of_others = len(block)-1
		#num_of_proc=string.atoi(m3d[ind+1])
		#print 'num_of_proc:	%d'% num_of_proc
	elif(pconf.match(item)):
		ind=m3d.index(item)
		block.append(ind)
		start_of_conf = len(block)-1
		first= string.strip(m3d[ind+1])
                second = first.split()
		for item in second:
			if pstar.match(item):
		                name_of_config=item[1:] 
		print 'name_of_configuration:	%s'% name_of_config
	elif(pwxy.match(item)):
		block.append(m3d.index(item))
		start_of_wxy = len(block)-1
	elif(pend.match(item)):
		block.append(m3d.index(item))
   print 'We found %s blocks: resource start from %d; ...
          other options start from %d; ...
          conf start from %d; ...
          wxy start from %d'%...
          (len(block), start_of_resource, start_of_others, start_of_conf, start_of_wxy)
   print

   if (pseaborg.match(name_of_computer)):
	pass
   elif (pbgl.match(name_of_computer)):
	if (pdebug.match(name_of_quenue)):
		name_of_quenue='short'
	else:
		name_of_quenue='long'
   else:
	if (pdebug.match(name_of_quenue)):
		pass
	else:
		name_of_quenue='batch'

   #construct resouce list
   if(start_of_resource):
	for index in range( block[start_of_resource]+1, block[start_of_resource+1]):
		if(pcoment.match(m3d[index])):
			pass
		elif(pnewline.match(m3d[index])):
			pass
		else:
			resource.append(string.strip(m3d[index])) #get rid of \n
	print 'resource list = '#, resource
	for item in resource:             #item is a string, resource is a list
		first=string.strip(item)
		second= re.sub(r"(\s)+=", "=", item)     #get rid of space before =
		third= re.sub(r"=(\s)+", "=", second)     #get rid of the space after =
		fourth= re.sub(r"(\s)+", " ", third)      #keep only one space bettwen the fields
		fifth= re.split(r"\s", fourth)            #fifth is a list
		for field in fifth:
			#sys.stdout.write("\t"+field+nline) 
			c_m3d = re.match(r"(.+[\.].+)#(.*)", field)    #peel of comments
			i_m3d = re.match(r"(.+)(=)(\d+)", field)       #peel of integer
			s_m3d = re.match(r"(.+)(=)(.+)", field)        #peel of string
			pnp = re.search("num_proc_per_node", field)
			if(pnp):
				print i_m3d.group(0)
				num_of_proc = string.atoi((i_m3d.group(3)))
			wtim = re.search("walltime", field)
			if(wtim):
				print s_m3d.group(0)
				wtime= s_m3d.group(0)
			memo = re.search("mem", field)
			if(memo):
				print s_m3d.group(0)
				memory = s_m3d.group(0)
	print 

   #construct others list
   if(start_of_others):
	for index in range( block[start_of_others]+1, block[start_of_others+1]):
		if(pcoment.match(m3d[index])):
			pass
		elif(pnewline.match(m3d[index])):
			pass
		else:
			others.append(string.strip(m3d[index])) #get rid of \n
	other_option = ''
	print 'other options = '#, others
	for item in others:            #item is a string, others is a list
		first=string.strip(item)
		second= re.sub(r"(\s)+=", "=", item)     #get rid of space before =
		third= re.sub(r"=(\s)+", "=", second)     #get rid of the space after =
		fourth= re.sub(r"(\s)+", " ", third)      #keep only one space bettwen the fields
		fifth= re.split(r"\s", fourth)            #fifth is a list
		for field in fifth:
			#sys.stdout.write("\t"+field+nline) 
			c_m3d = re.match(r"(.+[\.].+)#(.*)", field)    #peel of comments
			i_m3d = re.match(r"(.+)(=)(\d+)", field)       #peel of integer
			s_m3d = re.match(r"(.+)(=)(.+)", field)        #peel of string
			f_m3d = re.match(r"(.+[\.].+)(//)(.*)", item)  #peel of float
			chkf = re.search("iwriteCheckPoint", field)
			if(chkf):
				print i_m3d.group(1), i_m3d.group(3)
				other_option = other_option + '-'+i_m3d.group(1) +bn+ i_m3d.group(3) +bn
			rescale = re.search("rescale", field)
			if(rescale):
				print i_m3d.group(1), i_m3d.group(3)
				if string.atoi(i_m3d.group(3)) > 0:
					other_option = other_option + '-'+i_m3d.group(1) +bn
			EB = re.search("EngUpBound", field)
			if(EB):
				print s_m3d.group(1), s_m3d.group(3)
				other_option = other_option + '-'+s_m3d.group(1) +bn+ s_m3d.group(3) +bn
			timestep = re.search("timestep", field)
			if(timestep):
				print s_m3d.group(1), s_m3d.group(3)
				other_option = other_option + '-'+s_m3d.group(1) +bn+ s_m3d.group(3) +bn
			NumRestart = re.search("NumRestart", field)
			if(NumRestart):
				print i_m3d.group(1), i_m3d.group(3)
				other_option = other_option + '-'+s_m3d.group(1) +bn+ s_m3d.group(3) +bn
			samplingT = re.search("samplingT", field)
			if(samplingT):
				print i_m3d.group(1), i_m3d.group(3)
				other_option = other_option + '-'+s_m3d.group(1) +bn+ s_m3d.group(3) +bn
			its = re.search("its", field)
			if(its):
				print i_m3d.group(1), i_m3d.group(3)
				other_option = other_option + '-'+s_m3d.group(1) +bn+ s_m3d.group(3) +bn
	print other_option
	print

   #construct configuration list
   if(start_of_conf):
	sys.stdout.write('generate configuration file'+nline)
	f=open(name_of_config, 'w') 
	#print '	range', ( block[start_of_conf]+1, block[start_of_conf+1])
	for index in range( block[start_of_conf]+2, block[start_of_conf+1]):
		con.append(m3d[index])
		f.write(m3d[index])
	f.close()

   #construct wxy list
   if(start_of_wxy):
	sys.stdout.write('generate wxy file'+nline)
	f=open('wxy', 'w') 
	#print '	range', ( block[start_of_wxy]+1, block[start_of_wxy+1])
	for index in range( block[start_of_wxy]+1, block[start_of_wxy+1]):
		#sys.stdout.write(m3d[index])
		wxy.append(m3d[index])
		f.write(m3d[index])
	f.close()

   #call modules construct_con_file, construct_wxy_file, construct_job_file
   sys.stdout.write(nline)
   num_of_proc_total = construct_con_file(con)
   construct_wxy_file(wxy)
   construct_job_file(other_option)

Python driver.