Exemple #1
0
    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
Exemple #2
0
 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('_',3)
         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]+"(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
Exemple #4
0
 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()