def create_transfer_card(self,list_var): """ create the generic transfer_card linked to this transfer_functions """ in_card=open("./input/transfer_card_generic.dat",'r') text=in_card.read() in_card.close() text += '$b$ S-COMMENT_# $b$\n' text+='To change the transfer function run ./bin/change_tf.py \n' text+='Current parametrization :'+self.tf_name+'\n' text += '$e$ S-COMMENT_# $e$' current_block='' current_var='' for fortran_var in list_var: tag,block,var,number=fortran_var.split('_') if block != current_block: current_block=block current_var='' text += '$b$ S-COMMENT_# $b$' text += self.block[block].info() text += '$e$ S-COMMENT_#$e$' if var!=current_var: current_var=var text+='BLOCK TF_'+block+'_'+var+'\n' text+='\t'+number+'\t 1d0 \t #\n' text=mod_file.mod_text(text,{}) #only S-COMMENT mod out=open("transfer_card.dat",'w') out.writelines(text) out.close()
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] 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_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=put_in_fortran_format(new_text) text+=new_text text=put_in_fortran_format(text) ff=open('./transfer_function.f','w') ff.writelines(text) return list_var
def close_d_choices_file(self, template): """write the end of the D block related files """ #ending f file text = '\n return \n end\n' text = put_in_fortran_format(text) self.D_f_text += text #endind .inc file (add common) text = '\n$B$ S-COMMENT_C $B$\n Definition of the common\n$E$ S-COMMENT_C $E$\n' if self.d_block: text += '\n common/to_d_block/' + ','.join(self.d_block) + '\n' text = put_in_fortran_format(text) self.D_inc_text += text #write text in file self.D_f_text = put_in_fortran_format(self.D_f_text) self.D_inc_text = put_in_fortran_format(self.D_inc_text) mod_file.mod_text(self.D_inc_text, template.dico, self.directory + '/d_choices.inc') mod_file.mod_text(self.D_f_text, template.dico, self.directory + '/d_choices.f')
def write_code(self, template): """ write the data_file and the main_code file """ write_main = template.dico['INTRO_FOR_MAIN'] write_main += template.dico['START_ROUTINE'] write_data = template.dico['INTRO_FOR_DATA'] write_data += self.write_f77_parameter() write_data += template.dico['COMMON_DEF'] for i in range(0, len(self.code)): write_main += self.code[i][0] write_data += self.code[i][1] write_main += ' endif\n' write_main += ' return\n' write_main += ' end\n' mod_file.mod_text(write_main, template.dico, self.directory + '/main_code.f') mod_file.mod_text(write_data, template.dico, self.directory + '/data.inc')
def write_code(self, template): """ write the data_file and the main_code file """ self.close_d_choices_file(template) self.check_redondant_peak(self.unaligned, self.unaligned_in_sol) write_main=template.dico['INTRO_FOR_MAIN'] write_main += template.dico['START_ROUTINE'] write_data=template.dico['INTRO_FOR_DATA'] write_data += self.write_f77_parameter() write_data += template.dico['COMMON_DEF'] write_mchannel=template.dico['INTRO_FOR_MULTICHANNEL'] write_mchannel+=self.def_text_for_channel_weight(self.unaligned) for i in range(0, len(self.code)): write_main += self.code[i][0] write_data += self.code[i][1] write_mchannel += self.create_multi_channel_weight(i,self.sol_nb[i]) write_main += ' endif\n' write_main += ' return\n' write_main += ' end\n' # write_mchannel += template.dico['SECONDPART_FOR_MULTICHANNEL'] #contains endif,return+start of following routine # self.unaligned_correct_for_identical_solution() # write_mchannel += self.write_channel_weight(self.unaligned,'+') write_mchannel += template.dico['END_FOR_MULTICHANNEL'] write_mchannel= put_in_fortran_format(write_mchannel) mod_file.mod_text(write_main, template.dico, self.directory + '/main_code.f') mod_file.mod_text(write_data, template.dico, self.directory + '/data.inc') mod_file.mod_text(write_mchannel, template.dico, self.directory + '/multi_channel.f')
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=put_in_fortran_format(text) ff=open(self.dir+'/call_TF.f','w') ff.writelines(text) ff.close()
def write_code(self, template): """ write the data_file and the main_code file """ self.close_d_choices_file(template) self.check_redondant_peak(self.unaligned, self.unaligned_in_sol) write_main = template.dico['INTRO_FOR_MAIN'] write_main += template.dico['START_ROUTINE'] write_data = template.dico['INTRO_FOR_DATA'] write_data += self.write_f77_parameter() write_data += template.dico['COMMON_DEF'] write_mchannel = template.dico['INTRO_FOR_MULTICHANNEL'] write_mchannel += self.def_text_for_channel_weight(self.unaligned) for i in range(0, len(self.code)): write_main += self.code[i][0] write_data += self.code[i][1] write_mchannel += self.create_multi_channel_weight( i, self.sol_nb[i]) write_main += ' endif\n' write_main += ' return\n' write_main += ' end\n' # write_mchannel += template.dico['SECONDPART_FOR_MULTICHANNEL'] #contains endif,return+start of following routine # self.unaligned_correct_for_identical_solution() # write_mchannel += self.write_channel_weight(self.unaligned,'+') write_mchannel += template.dico['END_FOR_MULTICHANNEL'] write_mchannel = put_in_fortran_format(write_mchannel) mod_file.mod_text(write_main, template.dico, self.directory + '/main_code.f') mod_file.mod_text(write_data, template.dico, self.directory + '/data.inc') mod_file.mod_text(write_mchannel, template.dico, self.directory + '/multi_channel.f') # create permutations.inc file self.write_permutations_file()