def create_transfer_functions(self): """ define for each block the 3 functions TF and the three TF width """ def create_optional_variable(text, blockname, variable, list_var=[]): """ replace all #1,#2 by fortran name """ output = '' Pattern = re.compile(r'''#(\d*)''') prov = Pattern.split(text) i = 0 while i < len(prov) - 1: output += prov[i] i += 1 if not ('tf_' + blockname + "_" + variable + "_" + prov[i] in list_var): list_var.append('tf_' + blockname + "_" + variable + "_" + prov[i]) output += 'tf_' + blockname + "_" + variable + "_" + prov[ i] + "(curr_tf)" i += 1 output += prov[-1] return output, list_var template = mod_file.Mod_file(rule_file='./input/mod_generic') list_var = [ ] #list all variable needed to defined in order to be set in the transfer card text = '$B$ TF_HEADER $E$' text = mod_file.mod_text(text, template.dico) for block in self.block.values(): for variable in ['E', 'THETA', 'PHI']: tf_var = 'tf_' + variable + '_' + block.name new_text = '$B$ GENERIC_TF $E$' width_var = 'width_' + variable + '_' + block.name new_text += '$B$ GENERIC_WIDTH $E$' new_text = mod_file.mod_text(new_text, template.dico) #extend generic new_rule = {'tf_var': tf_var, 'width_var': width_var} new_rule['tf_definition'] = block[variable].tf_code new_rule['width_definition'] = block[variable].width_code new_rule['tf_include'] = block[variable].includetext new_text = mod_file.mod_text( new_text, new_rule) #change default variable in real one new_text, list_var = create_optional_variable( new_text, block.name, variable, list_var) new_text = MW_fct.put_in_fortran_format(new_text) text += new_text text = MW_fct.put_in_fortran_format(text) ff = open('./transfer_function.f', 'w') ff.writelines(text) return list_var
def create_param_inc(list_var): out=open("TF_param.inc",'w') file_in=open("./input/TF_param_generic.inc",'r') out.writelines(file_in.read()) file_in.close() if list_var==[]: print "TF_param created (no input)" return common_text='' for name in list_var: name = name.replace('(curr_tf)','') line=" double precision "+name+"(nb_tf)\n" out.writelines(line) common_text+=name+',' common_text=common_text[:-1] #suppress last coma line=" Common/to_TF_param/"+common_text line=MW_fct.put_in_fortran_format(line) out.writelines(line) out.close() return
def create_transfer_functions(self): """ define for each block the 3 functions TF and the three TF width """ def create_optional_variable(text,blockname,variable,list_var=[]): """ replace all #1,#2 by fortran name """ output='' Pattern=re.compile(r'''#(\d*)''') prov=Pattern.split(text) i=0 while i<len(prov)-1: output+=prov[i] i+=1 if not('tf_'+blockname+"_"+variable+"_"+prov[i] in list_var): list_var.append('tf_'+blockname+"_"+variable+"_"+prov[i]) output+='tf_'+blockname+"_"+variable+"_"+prov[i]+"(curr_tf)" i+=1 output+=prov[-1] return output,list_var template = mod_file.Mod_file(rule_file='./input/mod_generic') list_var=[] #list all variable needed to defined in order to be set in the transfer card text='$B$ TF_HEADER $E$' text=mod_file.mod_text(text,template.dico) for block in self.block.values(): for variable in ['E','THETA','PHI']: tf_var='tf_'+variable+'_'+block.name new_text='$B$ GENERIC_TF $E$' width_var='width_'+variable+'_'+block.name new_text+='$B$ GENERIC_WIDTH $E$' new_text=mod_file.mod_text(new_text,template.dico) #extend generic new_rule={'tf_var':tf_var,'width_var':width_var} new_rule['tf_definition']=block[variable].tf_code new_rule['width_definition']=block[variable].width_code new_rule['tf_include']=block[variable].includetext new_text=mod_file.mod_text(new_text,new_rule) #change default variable in real one new_text,list_var=create_optional_variable(new_text,block.name,variable,list_var) new_text=MW_fct.put_in_fortran_format(new_text) text+=new_text text=MW_fct.put_in_fortran_format(text) ff=open('./transfer_function.f','w') ff.writelines(text) return list_var
def write_transfer_function_file(self): """ write transfer_function.f file for the specific subprocesses """ text='$B$ TF_HEADER $E$\n' text+=self.text_get_central_point()+'\n' text+=self.text_transfer_fct()+'\n' text+=self.text_tf_E_for_part()+'\n' template = mod_file.Mod_file(rule_file='./Source/MadWeight/transfer_function/input/mod_generic') text=mod_file.mod_text(text,template.dico) text=MW_fct.put_in_fortran_format(text) ff=open(self.dir+'/call_TF.f','w') ff.writelines(text) ff.close()