Example #1
0
def nchange (fini, s, n, repl_str):

# 
# Search for the occurence of string "s" in file "fini".
# Replace the "n"-th word (n=0,1,2...) of the string with 
# a different string "repl_str". This function is invoked 
# frequently by other functions in this module.
#

  nl   = (file.string_find(fini,s))[0]     # find the line number
  line = (file.read_lines(fini,nl,nl))[0]  # read the whole line
  scrh = string.split(line)                # split the words into a list
  scrh[n] = repl_str                       # replace the n-th word
  scrh = string.join(scrh,'   ')           # join words, add space
  scrh = scrh+"\n"                         # add newline
  file.replace_line(fini,scrh,nl)          # overwrite
Example #2
0
def makefile(work_dir, pluto_path, pluto_dir, additional_files,
             additional_flags, makefile_template, AUTO_UPDATE):

    mkfl_name = work_dir + '/makefile'
    mkfl_exist = os.path.exists(mkfl_name)

    # is Chombo required ?

    WITH_CHOMBO = 0
    for x in sys.argv:
        if (x == "--with-chombo" or x == "--with-chombo:"):
            WITH_CHOMBO = 1

# try to get "ARCH" from makefile

    if (mkfl_exist):
        scrh = file.string_list(mkfl_name, 'ARCH')

# Create a new makefile under the following conditions:

    if (AUTO_UPDATE == 0) or (not mkfl_exist) or (len(scrh) == 0):

        # define architecture

        entries = os.listdir(pluto_dir + '/Config')

        entries.sort()
        menu.SetTitle("Change makefile")
        arch = menu.Browse(entries)  # call menu to select config. file
        arch_string = 'ARCH         = ' + arch + '\n'
    else:  # try to update makefile automatically
        arch_string = scrh[0]
        arch = (string.split(arch_string))[2]

# Starting print here

    row = 1
    menu.Print("> Generating makefile... [" + arch + "]", row=row, sleep=1)

    # if CHOMBO is required, change dir to Lib/Chombo/lib, make vars to generate
    # a list of all the variables needed by CHOMBO makefile and copy the list to
    # make.vars in local working directory.
    # This file will be used later by PLUTO makefile.

    if (WITH_CHOMBO):

        # get the number of DIMENSIONS from definitions.h

        scrh = file.string_list(work_dir + "/definitions.h", "DIMENSIONS")
        scrh = string.split(scrh[0])

        # build chombo configuration string

        chombo_config_string = 'DIM=' + scrh[2]
        for x in sys.argv:
            if (x == '--with-chombo:'):
                i = sys.argv.index(x) + 1
                for y in sys.argv[i:]:
                    chombo_config_string += ' ' + y

        row = row + 1
        menu.Print("  - Chombo config string: " + chombo_config_string,
                   row=row)
        row = row + 1
        menu.Print("  - creating make.vars...", row=row, sleep=0)
        os.chdir(pluto_dir + "/Lib/Chombo-3.1/lib")
        os.system("make " + chombo_config_string + " vars > make.vars\n")
        os.system("cp make.vars " + work_dir + "\n")
        os.chdir(work_dir)

# copy template

    shutil.copy(pluto_dir + makefile_template[0], mkfl_name)

    # write main PLUTO dir

    scrh = file.word_find(mkfl_name, 'PLUTO_DIR')
    ipos = scrh[0]
    file.replace_line(mkfl_name, 'PLUTO_DIR    = ' + pluto_dir + '\n', ipos)

    #  write architecture

    scrh = file.word_find(mkfl_name, 'ARCH')
    ipos = scrh[0]
    file.replace_line(mkfl_name, arch_string, ipos)

    #  Write additional objects to makefile

    scrh = file.word_find(mkfl_name, 'Additional_object_files_here')
    ipos = scrh[0] + 3

    for x in additional_files:
        file.insert(mkfl_name, 'OBJ += ' + x + '\n', ipos)
        ipos = ipos + 1

# add included makefile; useful for header dependences

    for x in pluto_path:
        file.insert(mkfl_name, 'include $(SRC)/' + x + 'makefile' + '\n', ipos)
        ipos = ipos + 1

#  Write additional flags for C compiler

    for x in additional_flags:
        file.insert(mkfl_name, 'CFLAGS += ' + x + '\n', ipos)
        ipos = ipos + 1

# Check for libpng

# if (WITH_CHOMBO == 0):
#   if (os.path.exists("sysconf.out")):
#     scrh = file.string_find ("sysconf.out", "LIBPNG")
#     line = file.read_lines("sysconf.out", scrh[0], scrh[0]+1)
#     line_list = string.split(line[0])
#     if (line_list[2] == 'YES'):
#       file.insert(this_makefile, 'LDFLAGS += -lpng\n', ipos)
#       ipos = ipos + 1
#       file.insert(this_makefile, 'CFLAGS += -DHAVE_LIBPNG\n', ipos)

    return
Example #3
0
def replace_obsoletes(work_dir):

    # replace potential occurences of "INCLUDE_ROTATION" --> "ROTATING_FRAME"
    try:
        scrh = file.string_list(work_dir + '/definitions.h',
                                'INCLUDE_ROTATION')
        tmp = string.split(scrh[0])
        newline = "#define    ROTATING_FRAME        " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'INCLUDE_ROTATION')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "INCLUDE_BODY_FORCE" --> "BODY_FORCE"
    try:
        scrh = file.string_list(work_dir + '/definitions.h',
                                'INCLUDE_BODY_FORCE')
        tmp = string.split(scrh[0])
        newline = "#define    BODY_FORCE        " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'INCLUDE_BODY_FORCE')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "INCLUDE_COOLING" --> "COOLING"
    try:
        scrh = file.string_list(work_dir + '/definitions.h', 'INCLUDE_COOLING')
        tmp = string.split(scrh[0])
        newline = "#define    COOLING        " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'INCLUDE_COOLING')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "INCLUDE_BACKGROUND_FIELD" --> "BACKGROUND_FIELD"
    try:
        scrh = file.string_list(work_dir + '/definitions.h',
                                'INCLUDE_BACKGROUND_FIELD')
        tmp = string.split(scrh[0])
        newline = "#define    BACKGROUND_FIELD        " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h',
                             'INCLUDE_BACKGROUND_FIELD')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "TIME_EVOLUTION" --> "TIME_STEPPING"
    try:
        scrh = file.string_list(work_dir + '/definitions.h', 'TIME_EVOLUTION')
        tmp = string.split(scrh[0])
        newline = "#define    TIME_STEPPING    " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'TIME_EVOLUTION')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "FLUX_CT" --> "CONSTRAINED_TRANSPORT"
    try:
        scrh = file.string_find(work_dir + '/definitions.h', 'FLUX_CT')
        file.replace_line(
            work_dir + '/definitions.h',
            "#define    MHD_FORMULATION    CONSTRAINED_TRANSPORT\n", scrh[0])
    except:
        pass

    # replace potential occurences of "RAYMOND" --> "SNEq"
    try:
        scrh = file.string_find(work_dir + '/definitions.h', 'RAYMOND')
        file.replace_line(work_dir + '/definitions.h',
                          "#define    COOLING   SNEq\n", scrh[0])
    except:
        pass

    # replace potential occurences of "NEQ" --> "MINEq"
    try:
        scrh = file.string_find(work_dir + '/definitions.h', 'NEQ')
        file.replace_line(work_dir + '/definitions.h',
                          "#define    COOLING   MINEq\n", scrh[0])
    except:
        pass

    # replace potential occurences of "CT_VEC_POT_INIT" --> "USE_VECTOR_POTENTIAL"
    try:
        scrh = file.string_list(work_dir + '/definitions.h', 'CT_VEC_POT_INIT')
        tmp = string.split(scrh[0])
        newline = "#define  USE_VECTOR_POTENTIAL  " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'CT_VEC_POT_INIT')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "USE_VECTOR_POTENTIAL" -->
    #                                 "ASSIGN_VECTOR_POTENTIAL"
    try:
        scrh = file.string_list(work_dir + '/definitions.h',
                                'USE_VECTOR_POTENTIAL')
        tmp = string.split(scrh[0])

        newline = "#define  ASSIGN_VECTOR_POTENTIAL  " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h',
                             'USE_VECTOR_POTENTIAL')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    # replace potential occurences of "SAVE_VEC_POT" -->
    #                                 "UPDATE_VECTOR_POTENTIAL"
    try:
        scrh = file.string_list(work_dir + '/definitions.h', 'SAVE_VEC_POT')
        tmp = string.split(scrh[0])
        newline = "#define  UPDATE_VECTOR_POTENTIAL  " + tmp[2] + "\n"
        n = file.string_find(work_dir + '/definitions.h', 'SAVE_VEC_POT')
        n = n[0]
        file.replace_line(work_dir + '/definitions.h', newline, n)
    except:
        pass

    return
Example #4
0
import os
import shutil
import sys
import string
import re
import time
import file
import ut
import menu

# Script to automatically change Checkpoint_interval in pluto.ini

if (len(sys.argv) == 1): fname = "pluto.ini"
else: fname = sys.argv[1]

for fname in sys.argv[1:]:
    print "doing " + fname
    try:
        scrh = file.string_find(fname, 'Checkpoint_interval')
        file.replace_line(fname, "Checkpoint_interval  -1.0  0\n", scrh[0])

        scrh = file.string_find(fname, 'Plot_interval')
        file.replace_line(fname, "Plot_interval         1.0  0\n", scrh[0])
    except:
        continue
Example #5
0
import re
import time
import file
import ut
import menu

# Script to automatically change pluto.ini from v. 2 to v. 3.


if (len(sys.argv) == 1): fname = "pluto.ini"
else:                    fname = sys.argv[1]

# change headers first

scrh = file.string_find (fname, 'DOMAIN')
file.replace_line (fname, "[Grid]\n\n", scrh[0])

scrh = file.string_find (fname, 'TIME')
file.replace_line (fname, "[Time]\n", scrh[0])

scrh = file.string_find (fname, 'SOLVER')
file.replace_line (fname, "[Solver]\n", scrh[0])

scrh = file.string_find (fname, 'BOUNDARIES')
file.replace_line (fname, "[Boundary]\n", scrh[0])

scrh = file.string_find (fname, 'OUTPUT')
file.replace_line (fname, "[Uniform Grid Output]\n", scrh[0])

scrh = file.string_find (fname, 'USER-DEF')
file.replace_line (fname, "[Parameters]\n", scrh[0])
Example #6
0
def interpolation(fdef,interp):
  scrh = file.string_find(fdef, 'INTERPOLATION')
  file.replace_line(fdef, '#define    INTERPOLATION    '+interp+'\n',scrh[0]);
Example #7
0
def dbl (fini, xf, nf, mode):
  scrh = file.string_find (fini, 'dbl')
  file.replace_line (fini, "dbl    "+str(xf)+"    "+str(nf)+"    "+mode+"\n", scrh[0])
Example #8
0
def makefile(work_dir, pluto_path, pluto_dir, additional_files, 
             additional_flags, makefile_template, AUTO_UPDATE):

 mkfl_name  = work_dir+'/makefile'
 mkfl_exist = os.path.exists(mkfl_name)

# is Chombo required ?

 WITH_CHOMBO = 0
 for x in sys.argv: 
   if (x == "--with-chombo" or x == "--with-chombo:"):      
     WITH_CHOMBO = 1
   
# try to get "ARCH" from makefile

 if (mkfl_exist): 
   scrh = file.string_list(mkfl_name,'ARCH')
     
# Create a new makefile under the following conditions:

 if (AUTO_UPDATE == 0) or (not mkfl_exist) or (len(scrh) == 0):

 # define architecture

   entries = os.listdir(pluto_dir + '/Config')

   entries.sort()
   menu.SetTitle("Change makefile")
   arch        = menu.Browse(entries)  # call menu to select config. file
   arch_string = 'ARCH         = '+ arch + '\n'
 else:                           # try to update makefile automatically
   arch_string = scrh[0]
   arch        = (string.split(arch_string))[2]

# Starting print here

 row = 1
 menu.Print ("> Generating makefile... ["+arch+"]", row=row,sleep=1)
 
# if CHOMBO is required, change dir to Lib/Chombo/lib, make vars to generate 
# a list of all the variables needed by CHOMBO makefile and copy the list to 
# make.vars in local working directory.
# This file will be used later by PLUTO makefile.

 if (WITH_CHOMBO):      

 # get the number of DIMENSIONS from definitions.h
   
   scrh = file.string_list (work_dir+"/definitions.h", "DIMENSIONS")
   scrh = string.split(scrh[0])

 # build chombo configuration string

   chombo_config_string = 'DIM='+scrh[2]
   for x in sys.argv: 
     if (x == '--with-chombo:'):
       i = sys.argv.index(x) + 1
       for y in sys.argv[i:]: chombo_config_string += ' '+y
     
   row = row + 1
   menu.Print("  - Chombo config string: "+chombo_config_string,row=row) 
   row = row+1
   menu.Print("  - creating make.vars...",row=row,sleep=0) 
   os.chdir(pluto_dir+"/Lib/Chombo-3.1/lib")
   os.system("make "+chombo_config_string+" vars > make.vars\n")
   os.system("cp make.vars "+work_dir+"\n")
   os.chdir(work_dir)

# copy template
 
 shutil.copy(pluto_dir + makefile_template[0], mkfl_name)

# write main PLUTO dir

 scrh = file.word_find(mkfl_name,'PLUTO_DIR')
 ipos = scrh[0]
 file.replace_line (mkfl_name, 'PLUTO_DIR    = '+pluto_dir+'\n', ipos)

#  write architecture 

 scrh = file.word_find(mkfl_name,'ARCH')
 ipos = scrh[0]
 file.replace_line (mkfl_name, arch_string, ipos)

#  Write additional objects to makefile

 scrh = file.word_find(mkfl_name,'Additional_object_files_here')
 ipos = scrh[0] + 3

 for x in additional_files:
   file.insert(mkfl_name, 'OBJ += '+x + '\n', ipos)
   ipos = ipos + 1

# add included makefile; useful for header dependences

 for x in pluto_path:
   file.insert(mkfl_name, 'include $(SRC)/' + x + 'makefile' + '\n',ipos)
   ipos = ipos + 1

#  Write additional flags for C compiler

 for x in additional_flags:
   file.insert(mkfl_name, 'CFLAGS += '+x+'\n', ipos)
   ipos = ipos + 1

# Check for libpng

# if (WITH_CHOMBO == 0):
#   if (os.path.exists("sysconf.out")):
#     scrh = file.string_find ("sysconf.out", "LIBPNG")
#     line = file.read_lines("sysconf.out", scrh[0], scrh[0]+1)
#     line_list = string.split(line[0])
#     if (line_list[2] == 'YES'):
#       file.insert(this_makefile, 'LDFLAGS += -lpng\n', ipos)
#       ipos = ipos + 1
#       file.insert(this_makefile, 'CFLAGS += -DHAVE_LIBPNG\n', ipos)
  
 return
Example #9
0
def first_dt(fini, dt):
  scrh = file.string_find (fini, 'first_dt')
  file.replace_line (fini, "first_dt      "+str(dt)+"\n", scrh[0])
Example #10
0
def analysis (fini, xf,nf):
  scrh = file.string_find (fini, 'analysis')
  file.replace_line (fini, "analysis    "+str(xf)+"    "+str(nf)+"\n", scrh[0])
Example #11
0
def tstop (fini, t):
  scrh = file.string_find (fini, 'tstop')
  file.replace_line (fini, "tstop     "+str(t)+"\n", scrh[0])
Example #12
0
def CFL_max_var(fini, q):
  scrh = file.string_find (fini, 'CFL_max_var')
  file.replace_line (fini, "CFL_max_var     "+str(q)+"\n", scrh[0])
Example #13
0
def CFL (fini, cfl):
  scrh = file.string_find (fini, 'CFL')
  file.replace_line (fini, "CFL     "+str(cfl)+"\n", scrh[0])
Example #14
0
import sys
import string
import re
import time
import file
import ut
import menu

# Script to automatically change Checkpoint_interval in pluto.ini

if (len(sys.argv) == 1): fname = "pluto.ini"
else:                    fname = sys.argv[1]

for fname in sys.argv[1:]:
  print "doing "+fname
  try:
    scrh = file.string_find (fname, 'Checkpoint_interval')
    file.replace_line (fname, "Checkpoint_interval  -1.0  0\n", scrh[0])

    scrh = file.string_find (fname, 'Plot_interval')
    file.replace_line (fname, "Plot_interval         1.0  0\n", scrh[0])
  except:
    continue
  
  
  
  



Example #15
0
def flt (fini, xf, nf, mode):
  scrh = file.string_find (fini, 'flt')
  file.replace_line (fini, "flt    "+str(xf)+"    "+str(nf)+"    "+mode+"\n", scrh[0])
Example #16
0
import string
import re
import time
import file
import ut
import menu

# Script to automatically change pluto.ini from v. 2 to v. 3.

if (len(sys.argv) == 1): fname = "pluto.ini"
else: fname = sys.argv[1]

# change headers first

scrh = file.string_find(fname, 'DOMAIN')
file.replace_line(fname, "[Grid]\n\n", scrh[0])

scrh = file.string_find(fname, 'TIME')
file.replace_line(fname, "[Time]\n", scrh[0])

scrh = file.string_find(fname, 'SOLVER')
file.replace_line(fname, "[Solver]\n", scrh[0])

scrh = file.string_find(fname, 'BOUNDARIES')
file.replace_line(fname, "[Boundary]\n", scrh[0])

scrh = file.string_find(fname, 'OUTPUT')
file.replace_line(fname, "[Uniform Grid Output]\n", scrh[0])

scrh = file.string_find(fname, 'USER-DEF')
file.replace_line(fname, "[Parameters]\n", scrh[0])
Example #17
0
def replace_obsoletes(work_dir):

  # replace potential occurences of "INCLUDE_ROTATION" --> "ROTATING_FRAME"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','INCLUDE_ROTATION')
    tmp  = string.split(scrh[0])
    newline = "#define    ROTATING_FRAME        "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','INCLUDE_ROTATION')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "INCLUDE_BODY_FORCE" --> "BODY_FORCE"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','INCLUDE_BODY_FORCE')
    tmp  = string.split(scrh[0])
    newline = "#define    BODY_FORCE        "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','INCLUDE_BODY_FORCE')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "INCLUDE_COOLING" --> "COOLING"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','INCLUDE_COOLING')
    tmp  = string.split(scrh[0])
    newline = "#define    COOLING        "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','INCLUDE_COOLING')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "INCLUDE_BACKGROUND_FIELD" --> "BACKGROUND_FIELD"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','INCLUDE_BACKGROUND_FIELD')
    tmp  = string.split(scrh[0])
    newline = "#define    BACKGROUND_FIELD        "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','INCLUDE_BACKGROUND_FIELD')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "TIME_EVOLUTION" --> "TIME_STEPPING"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','TIME_EVOLUTION')
    tmp  = string.split(scrh[0])
    newline = "#define    TIME_STEPPING    "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','TIME_EVOLUTION')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "FLUX_CT" --> "CONSTRAINED_TRANSPORT"
  try:
    scrh = file.string_find(work_dir+'/definitions.h','FLUX_CT')
    file.replace_line(work_dir+'/definitions.h', 
                      "#define    MHD_FORMULATION    CONSTRAINED_TRANSPORT\n",scrh[0])
  except:
    pass


  # replace potential occurences of "RAYMOND" --> "SNEq"
  try:
    scrh = file.string_find(work_dir+'/definitions.h','RAYMOND')
    file.replace_line(work_dir+'/definitions.h', 
                      "#define    COOLING   SNEq\n",scrh[0])
  except:
    pass

  # replace potential occurences of "NEQ" --> "MINEq"
  try:
    scrh = file.string_find(work_dir+'/definitions.h','NEQ')
    file.replace_line(work_dir+'/definitions.h', 
                      "#define    COOLING   MINEq\n",scrh[0])
  except:
    pass


  # replace potential occurences of "CT_VEC_POT_INIT" --> "USE_VECTOR_POTENTIAL"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','CT_VEC_POT_INIT')
    tmp  = string.split(scrh[0])
    newline = "#define  USE_VECTOR_POTENTIAL  "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','CT_VEC_POT_INIT')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "USE_VECTOR_POTENTIAL" -->
  #                                 "ASSIGN_VECTOR_POTENTIAL"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','USE_VECTOR_POTENTIAL')
    tmp  = string.split(scrh[0])

    newline = "#define  ASSIGN_VECTOR_POTENTIAL  "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','USE_VECTOR_POTENTIAL')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  # replace potential occurences of "SAVE_VEC_POT" -->
  #                                 "UPDATE_VECTOR_POTENTIAL"
  try:
    scrh = file.string_list(work_dir+'/definitions.h','SAVE_VEC_POT')
    tmp  = string.split(scrh[0])
    newline = "#define  UPDATE_VECTOR_POTENTIAL  "+tmp[2]+"\n"
    n    = file.string_find(work_dir+'/definitions.h','SAVE_VEC_POT')
    n    = n[0]
    file.replace_line(work_dir+'/definitions.h', newline, n)
  except:
    pass

  return