def runGRETEL(gretel,file,geom,ncsize): # ~~ Run GRETEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ putFileContent('gretel_'+file+'.par',[geom,file,str(ncsize)]) failure = system(gretel+' < gretel_'+file+'.par >> gretel_'+file+'.log') if not failure: return True return False
def processPARALLEL(ncsize,wdir): # ~~ parallel case ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ncsize >= 0: putFileContent('PARAL',[str(ncsize),str(len(wdir)),wdir,'']) elif ncsize > 1: putFileContent('PARAL',[str(ncsize),str(len(wdir)),wdir,'']) return
def Exit(self) : if self.doneLines != []: self.outFileName = path.splitext(self.outFileName)[0]+'.noe' poolLines = self.doneLines for line in self.waitLines: print '>'+line[1][0]+line[1][1]+line[1][2] poolLines.append(line[1][0]+line[1][1]+line[1][2]) poolLines.extend(self.leftLines) print poolLines putFileContent(self.outFileName,poolLines) sys.exit()
def runGREDEL(gredel,file,geom,type,ncsize): # ~~ Change GRETEL into GREDEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pg = path.dirname(gredel) bg,eg = path.splitext(path.basename(gredel)) gredel = path.join(pg,'gredel' + type.lower() + '_autop' + eg) # ~~ Run GREDEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ putFileContent('gretel_'+file+'.par',[geom,file,str(ncsize)]) failure = system(gredel+' < gretel_'+file+'.par >> gretel_'+file+'.log') if not failure: return True return False return
def processLIT(cas,iFiles,TMPDir): # ~~ copy input files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for k in cas.keys(): if iFiles.has_key(k): cref = cas[k][0] if not path.isfile(cref): print '... file does not exist ',cref return False crun = path.join(TMPDir,iFiles[k].split(';')[1]) if iFiles[k].split(';')[3] == 'ASC': putFileContent(crun,getFileContent(cref)+['']) print ' copying: ', path.basename(cref) else: shutil.copy2(cref,crun) print ' copying: ', path.basename(cref) return True
def createExeFiles(ename,ecfg,eprog): # ~~ Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ExeDir = path.join(cfg['MODULES'][eprog.lower()]['path'],ecfg) chdir(ExeDir) # ~~ Removes existing executables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if 'homere' in ename: ExeFile = path.join(ExeDir,eprog + cfg['TELVER'] + cfg['SYSTEM']['SFX_EXE']) LibFile = path.join(ExeDir,eprog + cfg['TELVER'] + cfg['SYSTEM']['SFX_LIB']) ObjCmd = path.join(ExeDir,eprog + cfg['TELVER'] + '.cmdo') ExeCmd = path.join(ExeDir,eprog + cfg['TELVER'] + '.cmdx') else: ExeFile = path.join(ExeDir,ename + cfg['SYSTEM']['SFX_EXE']) LibFile = path.join(ExeDir,ename + cfg['SYSTEM']['SFX_LIB']) ObjCmd = path.join(ExeDir,ename + '.cmdo') ExeCmd = path.join(ExeDir,ename + '.cmdx') if cfg['COMPILER']['REBUILD'] > 0 and path.exists(ExeFile): remove(ExeFile) # ~~ Lists all libraries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LibFiles = '' for lib in HOMERES[ename.upper()]['deps'][1:]: # /!\ [1:] to create the exe from local objs. #ModDir = path.join(cfg['MODULES'][eprog.lower()]['path'],ecfg) LibFiles = LibFiles + path.join(ExeDir,lib.lower()+cfg['TELVER']+cfg['SYSTEM']['SFX_LIB']) + ' ' LibFiles = LibFiles + ' ' + cfg['MODULES'][eprog]['libs'] # parallel executable: adding MPI library # ~~ Lists local objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ObjFiles = '' for obj,lib in HOMERES[ename.upper()]['add'] : Root,Suffix = path.splitext(obj) if lib == eprog and obj.lower()+cfg['SYSTEM']['SFX_OBJ'] not in ObjFiles.split(): ObjFiles = ObjFiles + (Root.lower()+cfg['SYSTEM']['SFX_OBJ']+' ') if ObjFiles.strip() == '' and path.exists(ExeFile): return True for obj,lib in HOMERES[ename.upper()]['tag'] : if lib == eprog and obj.lower()+cfg['SYSTEM']['SFX_OBJ'] not in ObjFiles.split(): ObjFiles = ObjFiles + (obj.lower()+cfg['SYSTEM']['SFX_OBJ']+' ') # ~~ creation of the exe (according to makefile.wnt + systel.ini): # ~~ xilink.exe /stack:536870912 /out:postel3dV5P9.exe declarations_postel3d.obj coupeh.obj lecdon_postel3d.obj postel3d.obj coupev.obj lecr3d.obj pre2dh.obj pre2dv.obj ecrdeb.obj nomtra.obj homere_postel3d.obj point_postel3d.obj ..\..\..\bief\bief_V5P9\1\biefV5P9.lib ..\..\..\damocles\damo_V5P9\1\damoV5P9.lib ..\..\..\paravoid\paravoid_V5P9\1\paravoidV5P9.lib ..\..\..\special\special_V5P9\1\specialV5P9.lib cmd = cfg['COMPILER']['CMD_EXE'] cmd = cmd.replace('<libs>',LibFiles) cmd = cmd.replace('<objs>',ObjFiles) cmd = cmd.replace('<exename>',ExeFile).replace('<config>',ExeDir).replace('<root>',cfg['TELDIR']) xocmd = cfg['COMPILER']['CMD_OBJ'] xocmd = xocmd.replace('<incs>',cfg['MODULES'][eprog]['incs']) mods = '' for mod in HOMERES[ename.upper()]['deps']: mods = mods + path.join(cfg['MODULES'][eprog]['mods'].replace('<config>',cfg['MODULES'][mod]['path']),ecfg) + ' ' xocmd = xocmd.replace('<mods>',mods) # <f95name> ... still to be replaced xocmd = xocmd.replace('<config>',ExeDir).replace('<root>',cfg['TELDIR']) xecmd = cfg['COMPILER']['CMD_EXE'] xecmd = xecmd.replace('<libs>',LibFile + ' ' + LibFiles) # <exename> and <objs> ... still to be replaced xecmd = xecmd.replace('<config>',ExeDir).replace('<root>',cfg['TELDIR']) if debug : print cmd failure = system(cmd) if not failure: print ' - created ' + ExeFile putFileContent(ObjCmd,[xocmd]) putFileContent(ExeCmd,[xecmd]) return True else: if path.exists(ObjCmd): remove(ObjCmd) if path.exists(ExeCmd): remove(ExeCmd) return False
ilines = getFileContent(ifile) # ~~ Process Lines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ===================================================== found = False olines = [] for iline in ilines: oline = iline.rstrip() if oline != '': if iline[0].upper() == 'C': oline = '!' + oline[1:] found = True else: oline = '!' found = True proc = re.match(f77continu2,oline) if proc: oline = ' &'+oline[6:] olines.append(oline) if found: print ifile # ===================================================== # ~~ Renames the original source file as *.hrw rename(ifile,path.splitext(ifile)[0]+'.cl1') # ~~ Writes the content of the source file ~~~~~~~~~~ ofile = ifile putFileContent(ofile,olines) sys.exit()
def endOfFile(self): reply = QtGui.QMessageBox.question(self, 'File Completed', "Is this your final version ?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply != QtGui.QMessageBox.Yes: self.outFileName = path.splitext(self.outFileName)[0]+'.noe' putFileContent(self.outFileName,self.doneLines)
def translateCAS(cas,frgb): keyLines = [] casLines = getFileContent(cas) # ~~ split comments core = [] for i in range(len(casLines)): casLines[i] = casLines[i].replace('"""',"'''").replace('"',"'") proc = re.match(key_comment,casLines[i]+'/') head = proc.group('before').strip() tail = proc.group('after').rstrip('/') p = re.match(key_none,head+' ') if p: keyLines.insert(0,p.group('key')) head = '' # /!\ here you forget about proc.group('after') if head != '': core.append(head) keyLines.append(head) # /!\ here you forget about tail elif tail != '': keyLines.append(tail) casStream = ' '.join(core) ik = 0; frLines = []; gbLines = [] # ~~ clean values to keep only the keys while casStream != '': # ~~ key proc = re.match(key_equals,casStream) if not proc: print '... hmmm, did not see this one coming ...' break kw = proc.group('key').strip() casStream = proc.group('after') # still hold the separator while 1: p = re.match(re.compile(key_word%(kw),re.I),keyLines[ik]) if not p: frLines.append(keyLines[ik]) gbLines.append(keyLines[ik]) ik = ik + 1 else: keyLines[ik] = p.group('after') if kw in frgb['GB'].keys(): frline = frgb['GB'][kw] gbline = kw if kw in frgb['FR'].keys(): frline = kw gbline = frgb['FR'][kw] break # ~~ val proc = re.match(val_equals,casStream) if not proc: print 'no value to keyword ',kw sys.exit() val = [] while proc: val.append(proc.group('val')) #.replace("'",'')) casStream = proc.group('after') # still hold the separator while 1: p = re.match(re.compile(val_word%(proc.group('val')),re.I),keyLines[ik]) if not p: print '... could not get the values for ',kw sys.exit() keyLines[ik] = p.group('after') if keyLines[ik] == '': ik = ik + 1 break proc = re.match(val_equals,casStream) # in FRENCH for i in range(len(val)): if val[i] in ['YES','Y','TRUE']: val[i] = 'OUI' if val[i] in ['NO','N','FALSE']: val[i] = 'NON' # not more than 72 characters if len(' '+frline+' : '+';'.join(val)) < 73: frline = ' ' + frline + ' : ' + ';'.join(val) else: frline = ' ' + frline + ' :\n' if len(';'.join(val)) < 70: frline = frline + ' ' + ';'.join(val) else: frline = frline + ' ' + ';\n '.join(val) # in ENGLISH for i in range(len(val)): if val[i] in ['OUI','O','VRAI']: val[i] = 'TRUE' if val[i] in ['NON','N','FAUX']: val[i] = 'FALSE' # not more than 72 characters if len(' '+gbline+' : '+';'.join(val)) < 73: gbline = ' ' + gbline + ' : ' + ';'.join(val) else: gbline = ' ' + gbline + ' :\n' if len(';'.join(val)) < 70: gbline = gbline + ' ' + ';'.join(val) else: gbline = gbline + ' ' + ';\n '.join(val) # final append frLines.append(frline) gbLines.append(gbline) # ~~ print FR and GB versions of the CAS file putFileContent(cas+'.fr',frLines) putFileContent(cas+'.gb',gbLines) return
def runCAS(cfgName,cfg,codeName,casFile,options): # ~~~~ Read the DICO File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dicoFile = path.join(path.join(cfg['MODULES'][codeName]['path'],'lib'),codeName+cfg['TELVER']+'.dico') frgb,dico = scanDICO(dicoFile) iFS,oFS = getIOFilesSubmit(frgb,dico) # ~~ Read the principal CAS File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if not path.exists(casFile): print '... inexistent CAS file: ',casFile return None # /!\ should you stop or carry on ? cas,lang = processCAS(casFile,frgb) if not checkConsistency(cas,dico,frgb,cfg): print '... inconsistent CAS file: ',casFile print ' +> you may be using an inappropriate configuration:',cfgName print ' +> or may be wishing for scalar mode while using parallel' return None # /!\ should you stop or carry on ? # ~~ Handling Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CASDir = path.dirname(casFile) TMPDir = processTMP(casFile) # ~~ Read the included CAS File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cplages,defaut = getKeyWord('COUPLING WITH',cas,dico,frgb) #/!\ having done the loop this way it will not check for DELWAQ COUPLAGE = {} for cplage in cplages: for mod in cfg['MODULES'].keys(): if mod in cplage.lower(): # ~~~~ Extract the CAS File name ~~~~~~~~~~~~~~~~~~~~~~~ casFilePlage,defaut = getKeyWord(mod.upper()+' STEERING FILE',cas,dico,frgb) if casFilePlage == []: casFilePlage = defaut casFilePlage = path.join(CASDir,casFilePlage[0]) if not path.isfile(casFilePlage): print '... missing coupling CAS file for',mod,': ',casFilePlage return None # /!\ should you stop or carry on ? # ~~~~ Read the DICO File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dicoFilePlage = path.join(path.join(cfg['MODULES'][mod]['path'],'lib'),mod+cfg['TELVER']+'.dico') frgbPlage,dicoPlage = scanDICO(dicoFilePlage) iFSPlage,oFSPlage = getIOFilesSubmit(frgbPlage,dicoPlage) # ~~ Read the coupled CAS File ~~~~~~~~~~~~~~~~~~~~~~~~~ casPlage,lang = processCAS(casFilePlage,frgbPlage) if not checkConsistency(casPlage,dicoPlage,frgbPlage,cfg): print '... inconsistent CAS file: ',casFilePlage return None # /!\ should you stop or carry on ? COUPLAGE.update({mod:{}}) COUPLAGE[mod].update({'cas':casPlage,'frgb':frgbPlage,'iFS':iFSPlage,'oFS':oFSPlage,'dico':dicoPlage}) # ~~ Handling sortie file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sortiefile = None if options.sortieFile: # define the filename (basename) of the sortie file sortiefile = path.basename(TMPDir)+'.sortie' # ~~ Handling all input files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # >>> Placing yourself where the CAS File is chdir(CASDir) # >>> Copy INPUT files into TMPDir if not processLIT(cas,iFS,TMPDir): sys.exit() for mod in COUPLAGE.keys(): if not processLIT(COUPLAGE[mod]['cas'],COUPLAGE[mod]['iFS'],TMPDir): sys.exit() # >>> Placing yourself into the TMPDir chdir(TMPDir) # >>> Creating LNG file processCONFIG(lang) # ~~ Handling Executable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # >>> Names for the executable set #> names within TMPDir f90File = iFS['FICHIER FORTRAN'].split(';')[1] #> aggregation of PRINCI files for mod in COUPLAGE.keys(): f90FilePlage = COUPLAGE[mod]['iFS']['FICHIER FORTRAN'].split(';')[1] if path.isfile(f90FilePlage): putFileContent(f90File,getFileContent(f90File)+['']+getFileContent(f90FilePlage)) remove(f90FilePlage) objFile = path.splitext(f90File)[0] + cfg['SYSTEM']['SFX_OBJ'] #> default executable name exeFile = path.join(path.join(cfg['MODULES'][codeName]['path'],cfgName),codeName+cfg['TELVER']+cfg['SYSTEM']['SFX_EXE']) #> user defined executable name useFile = exeFile value,defaut = getKeyWord('FICHIER FORTRAN',cas,dico,frgb) if value != []: useFile = path.join(CASDir,path.splitext(value[0])[0]+cfg['SYSTEM']['SFX_EXE']) if path.exists(useFile) and cfg['REBUILD'] > 0: remove(useFile) #> default command line compilation and linkage if not path.exists(path.join(path.join(cfg['MODULES'][codeName]['path'],cfgName),codeName+cfg['TELVER']+'.cmdo')): print '\nNot able to find your OBJECT command line: ' + path.join(cfgName,codeName+cfg['TELVER']+'.cmdo') + '\n' print ' ... you have to compile this module at least: ' print ' +> ',codeName sys.exit() objCmd = getFileContent(path.join(path.join(cfg['MODULES'][codeName]['path'],cfgName),codeName+cfg['TELVER']+'.cmdo'))[0] if not path.exists(path.join(path.join(cfg['MODULES'][codeName]['path'],cfgName),codeName+cfg['TELVER']+'.cmdx')): print '\nNot able to find your OBJECT command line: ' + path.join(cfgName,codeName+cfg['TELVER']+'.cmdx') + '\n' print ' ... you have to compile this module at least: ' print ' +> ',codeName sys.exit() exeCmd = getFileContent(path.join(path.join(cfg['MODULES'][codeName]['path'],cfgName),codeName+cfg['TELVER']+'.cmdx'))[0] # >>> Compiling the executable if required if not processExecutable(useFile,objFile,f90File,objCmd,exeCmd,CASDir): sys.exit() # >>> Rename executable because of firewall issues ~~~~~~~~~~~~~~ runCmd = path.join(TMPDir,'out_'+path.basename(useFile)) shutil.move(path.basename(useFile),runCmd) if not options.compileonly: # ~~ Handling the parallelisation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ncsize = getNCSIZE(cas,dico,frgb) if ncsize > 1: # >>> MPI configuration # ~~> Executable /!\ you need one if ncsize > 1 mpiCmd = '' if cfg.has_key('MPI'): if cfg['MPI'].has_key('EXEC'): mpiCmd = cfg['MPI']['EXEC'] if mpiCmd == '': print '... I do not know how to run MPI, can you help ?' return None # /!\ should you stop or carry on ? # ~~> Assign the mpi_telemac.conf hosts = '' if cfg.has_key('MPI'): if cfg['MPI'].has_key('HOSTS'): hosts = cfg['MPI']['HOSTS'] # ~~> MPI Command line mpiCmd = mpiCmd.replace('<wdir>','-wdir '+TMPDir) # /!\ Make sure TMPDir works in UNC convention mpiCmd = mpiCmd.replace('<ncsize>','-n '+str(ncsize)) mpiCmd = mpiCmd.replace('<hosts>',hosts) mpiCmd = mpiCmd.replace('<exename>',runCmd) runCmd = mpiCmd # >>> Parallel tools # ~~> Default path PARDir = path.join(cfg['MODULES']['parallel']['path'],cfgName) # ~~> User path if cfg.has_key('PARALLEL'): if cfg['PARALLEL'].has_key('PATH'): PARDir = cfg['PARALLEL']['PATH'].replace('<root>',cfg['TELDIR']).replace('<config>',path.join(cfg['MODULES']['parallel']['path'],cfgName)) # ~~> Creating PARA file and the mpi_telemac.conf processPARALLEL(ncsize,TMPDir+sep) # /!\ Make sure TMPDir works in UNC convention # >>> Running the partionning if ncsize > 1: # ~~> PARTEL Executable exeCmd = path.join(PARDir,'partel'+cfg['SYSTEM']['SFX_EXE']) # ~~> Run PARTEL CONLIM = getCONLIM(cas,iFS) # no check on existence runPartition(exeCmd,cas,CONLIM,iFS,ncsize) for mod in COUPLAGE.keys(): CONLIM = getCONLIM(COUPLAGE[mod]['cas'],COUPLAGE[mod]['iFS']) runPartition(exeCmd,COUPLAGE[mod]['cas'],CONLIM,COUPLAGE[mod]['iFS'],ncsize) # >>> Running the Executable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ print runCmd if not runCode(runCmd,sortiefile): sys.exit() # >>> Handling the recollection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ncsize > 1: # ~~> GRETEL Executable exeCmd = path.join(PARDir,'gretel_autop'+cfg['SYSTEM']['SFX_EXE']) # ~~> Run GRETEL GLOGEO = getGLOGEO(cas,iFS) # no check on existence runRecollection(exeCmd,cas,GLOGEO,oFS,ncsize) for mod in COUPLAGE.keys(): GLOGEO = getGLOGEO(COUPLAGE[mod]['cas'],COUPLAGE[mod]['iFS']) runRecollection(exeCmd,COUPLAGE[mod]['cas'],GLOGEO,COUPLAGE[mod]['oFS'],ncsize) # ~~ Handling all output files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if not processECR(cas,oFS,CASDir,TMPDir,sortiefile,ncsize): sys.exit() for mod in COUPLAGE.keys(): if not processECR(COUPLAGE[mod]['cas'],COUPLAGE[mod]['oFS'],CASDir,TMPDir,'',ncsize): sys.exit() # ~~ Handling Directories ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ chdir(CASDir) if options.tmpdirectory or options.compileonly: removeDirectories(TMPDir) return sortiefile
def runPARTEL(partel,file,conlim,ncsize): putFileContent('partel_'+file+'.par',[file,conlim,str(ncsize),str(1),str(0),'']) # option 1, without sections 0 failure = system(partel+' < partel_'+file+'.par >> partel_'+file+'.log') if not failure: return True return False
def processCONFIG(lang): # ~~ create CONFIG ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ putFileContent('CONFIG',[str(lang),'6','']) return True