~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/iolibs/export_v4.py

  • Committer: Johan Alwall
  • Date: 2011-07-14 19:18:57 UTC
  • mfrom: (152.1.16 new_make_files)
  • Revision ID: johan@alwall.net-20110714191857-9s0c3y5vns4wghui
Merged up to v. 1.3.5: Updated makefile structure and fixed error messages if compilation fails during MadEvent run

Show diffs side-by-side

added added

removed removed

Lines of Context:
678
678
 
679
679
        return res_str + '*'
680
680
 
 
681
    def set_compiler(self, default_compiler):
 
682
        """Set compiler based on what's available on the system"""
 
683
        
 
684
        # Check for compiler
 
685
        if misc.which('g77'):
 
686
            compiler = 'g77'
 
687
        elif misc.which('gfortran'):
 
688
            compiler = 'gfortran'
 
689
        elif misc.which('f77'):
 
690
            compiler = 'f77'
 
691
        else:
 
692
            # Use g77 as default
 
693
            compiler = 'g77'
 
694
        logger.info('Use Fortran compiler ' + compiler)
 
695
        self.replace_make_opt_compiler(compiler)
 
696
        # Replace also for Template
 
697
        self.replace_make_opt_compiler(compiler, os.path.join(MG5DIR, 'Template'))
 
698
 
 
699
    def replace_make_opt_compiler(self, compiler, root_dir = ""):
 
700
        """Set FC=compiler in Source/make_opts"""
 
701
 
 
702
        if not root_dir:
 
703
            root_dir = self.dir_path
 
704
        make_opts = os.path.join(root_dir, 'Source', 'make_opts')
 
705
        lines = open(make_opts).read().split('\n')
 
706
        FC_re = re.compile('^(\s*)FC\s*=\s*.+\s*$')
 
707
        for iline, line in enumerate(lines):
 
708
            FC_result = FC_re.match(line)
 
709
            if FC_result:
 
710
                lines[iline] = FC_result.group(1) + "FC=" + compiler
 
711
        outfile = open(make_opts, 'w')
 
712
        outfile.write('\n'.join(lines))
 
713
 
681
714
#===============================================================================
682
715
# ProcessExporterFortranSA
683
716
#===============================================================================
710
743
 
711
744
        source_dir = os.path.join(self.dir_path, "Source")
712
745
        logger.info("Running make for Helas")
713
 
        misc.compile(arg=['../lib/libdhelas3.a'], cwd=source_dir, mode='fortran')
 
746
        misc.compile(arg=['../lib/libdhelas.a'], cwd=source_dir, mode='fortran')
714
747
        logger.info("Running make for Model")
715
748
        misc.compile(arg=['../lib/libmodel.a'], cwd=source_dir, mode='fortran')
716
749
 
721
754
                              online = False):
722
755
        """Finalize Standalone MG4 directory by generation proc_card_mg5.dat"""
723
756
 
724
 
        if not misc.which('g77'):
725
 
            logger.info('Change makefiles to use gfortran')
726
 
            subprocess.call(['python','./bin/Passto_gfortran.py'], cwd=self.dir_path, \
727
 
                            stdout = open(os.devnull, 'w')) 
728
 
 
 
757
        self.set_compiler('g77')
729
758
        self.make()
730
759
 
731
760
        # Write command history as proc_card_mg5
1112
1141
        # Touch "done" file
1113
1142
        os.system('touch %s/done' % os.path.join(self.dir_path,'SubProcesses'))
1114
1143
 
1115
 
        if not misc.which('g77'):
1116
 
            logger.info('Change makefiles to use gfortran')
1117
 
            subprocess.call(['python','./bin/Passto_gfortran.py'], cwd=self.dir_path, \
1118
 
                            stdout = open(os.devnull, 'w')) 
 
1144
        # Check for compiler
 
1145
        self.set_compiler('g77')
1119
1146
 
1120
1147
        old_pos = os.getcwd()
1121
1148
        os.chdir(os.path.join(self.dir_path, 'SubProcesses'))