SOLPSxport_dr.py
def increment_run(rundir, gfile_loc, new_filename = 'b2.transport.inputfile_new',
                  profiles_fileloc = None, shotnum = None, ptime = None, prunid = None,
                  use_existing_last10 = False, reduce_Ti = True,
                  carbon = True, plotall = False, plot_xport_coeffs = True,
                  ntim_new = 100, dtim_new = '1.0e-6', Dn_min = 0.0005):
    """
    This routine runs the main calculation of transport coefficients, then saves
    the old b2.transport.inputfile and b2fstati files with the iteration number
    and updates the b2mn.dat file with short time steps in preparation for the new run

    Hide input files from this routine by using '_' in the filename after 'b2.transport.inputfile'
    """

    olddir = os.getcwd()
    os.chdir(rundir)
    
    xp = main_mdsplus(rundir = rundir, gfile_loc = gfile_loc, new_filename = new_filename,
                      profiles_fileloc = profiles_fileloc, shotnum = shotnum, ptime = ptime,
                      prunid = prunid, Dn_min = Dn_min, use_existing_last10 = use_existing_last10,
                      reduce_Ti = reduce_Ti, carbon = carbon, plotall = plotall,
                      plot_xport_coeffs = plot_xport_coeffs, verbose=False)
    
    allfiles = os.listdir('.')
    all_incs = [int(i[22:]) for i in allfiles if i[:22] == 'b2.transport.inputfile' and
                i[-1] != '~' and i[-1] != 'e' and i[22] != '_']

    if all_incs:
        inc_num = np.max(all_incs)
    else:
        inc_num = 0
    os.rename('b2fstati', 'b2fstati' + str(inc_num+1))
    os.rename('b2.transport.inputfile', 'b2.transport.inputfile' + str(inc_num+1))
    os.rename(new_filename, 'b2.transport.inputfile')
    # os.remove('run.log')  # Leave this in case there was a mistake or you want to make changes
    for filename in allfiles:
        if filename[-7:] == '.last10':
            os.remove(filename)
    # os.remove('*.last10')
    # os.system('rm *.last10')  Doesn't work (apparently the star doesn't translate)
    
    print('modifying b2mn.dat')

    with open('b2mn.dat', 'r') as f:
        lines = f.readlines()
        
    # os.rename('b2mn.dat','b2mn.dat_old')  (this looks good, so just overwrite it from now on)
    
    for i, line in enumerate(lines):
        if line[:13] == "'b2mndr_ntim'":
            lines[i] = lines[i][:35] + "'" + str(ntim_new) + "'\r\n"
            
        if line[:13] == "'b2mndr_dtim'":
            lines[i] = lines[i][:35] + "'" + str(dtim_new) + "'\r\n"
            break

    with open('b2mn.dat', 'w') as f:
        for i in range(len(lines)):
            f.write(lines[i])
            
    os.chdir(olddir)

    This routine runs the main calculation of transport coefficients, then saves
    the old b2.transport.inputfile and b2fstati files with the iteration number
    and updates the b2mn.dat file with short time steps in preparation for the new run

    Hide input files from this routine by using '_' in the filename after 'b2.transport.inputfile'
    
This routine runs the main calculation of transport coefficients, then saves
the old b2.transport.inputfile and b2fstati files with the iteration number
and updates the b2mn.dat file with short time steps in preparation for the new run

Hide input files from this routine by using '_' in the filename after 'b2.transport.inputfile'
This routine runs the main calculation of transport coefficients then saves the old b2 . transport . inputfile and b2fstati files with the iteration number and updates the b2mn . dat file with short time steps in preparation for the new run Hide input files from this routine by using ' _ ' in the filename after ' b2 . transport . inputfile '
def increment_run(rundir, gfile_loc, new_filename = 'b2.transport.inputfile_new',
                  profiles_fileloc = None, shotnum = None, ptime = None, prunid = None,
                  use_existing_last10 = False, reduce_Ti = True,
                  carbon = True, plotall = False, plot_xport_coeffs = True,
                  ntim_new = 100, dtim_new = '1.0e-6', Dn_min = 0.0005):
    olddir = os.getcwd()
    os.chdir(rundir)
    xp = main_mdsplus(rundir = rundir, gfile_loc = gfile_loc, new_filename = new_filename,
                      profiles_fileloc = profiles_fileloc, shotnum = shotnum, ptime = ptime,
                      prunid = prunid, Dn_min = Dn_min, use_existing_last10 = use_existing_last10,
                      reduce_Ti = reduce_Ti, carbon = carbon, plotall = plotall,
                      plot_xport_coeffs = plot_xport_coeffs, verbose=False)
    allfiles = os.listdir('.')
    all_incs = [int(i[22:]) for i in allfiles if i[:22] == 'b2.transport.inputfile' and
                i[-1] != '~' and i[-1] != 'e' and i[22] != '_']
    if all_incs:
        inc_num = np.max(all_incs)
    else:
        inc_num = 0
    os.rename('b2fstati', 'b2fstati' + str(inc_num+1))
    os.rename('b2.transport.inputfile', 'b2.transport.inputfile' + str(inc_num+1))
    os.rename(new_filename, 'b2.transport.inputfile')
    for filename in allfiles:
        if filename[-7:] == '.last10':
            os.remove(filename)
    print('modifying b2mn.dat')
    with open('b2mn.dat', 'r') as f:
        lines = f.readlines()
    for i, line in enumerate(lines):
        if line[:13] == "'b2mndr_ntim'":
            lines[i] = lines[i][:35] + "'" + str(ntim_new) + "'\r\n"
        if line[:13] == "'b2mndr_dtim'":
            lines[i] = lines[i][:35] + "'" + str(dtim_new) + "'\r\n"
            break
    with open('b2mn.dat', 'w') as f:
        for i in range(len(lines)):
            f.write(lines[i])
    os.chdir(olddir)
def increment_run ( rundir , gfile_loc , new_filename = 'b2.transport.inputfile_new' , profiles_fileloc = None , shotnum = None , ptime = None , prunid = None , use_existing_last10 = False , reduce_Ti = True , carbon = True , plotall = False , plot_xport_coeffs = True , ntim_new = 100 , dtim_new = '1.0e-6' , Dn_min = 0.0005 ) : olddir = os . getcwd ( ) os . chdir ( rundir ) xp = main_mdsplus ( rundir = rundir , gfile_loc = gfile_loc , new_filename = new_filename , profiles_fileloc = profiles_fileloc , shotnum = shotnum , ptime = ptime , prunid = prunid , Dn_min = Dn_min , use_existing_last10 = use_existing_last10 , reduce_Ti = reduce_Ti , carbon = carbon , plotall = plotall , plot_xport_coeffs = plot_xport_coeffs , verbose = False ) allfiles = os . listdir ( '.' ) all_incs = [ int ( i [ 22 : ] ) for i in allfiles if i [ : 22 ] == 'b2.transport.inputfile' and i [ - 1 ] != '~' and i [ - 1 ] != 'e' and i [ 22 ] != '_' ] if all_incs : inc_num = np . max ( all_incs ) else : inc_num = 0 os . rename ( 'b2fstati' , 'b2fstati' + str ( inc_num + 1 ) ) os . rename ( 'b2.transport.inputfile' , 'b2.transport.inputfile' + str ( inc_num + 1 ) ) os . rename ( new_filename , 'b2.transport.inputfile' ) for filename in allfiles : if filename [ - 7 : ] == '.last10' : os . remove ( filename ) print ( 'modifying b2mn.dat' ) with open ( 'b2mn.dat' , 'r' ) as f : lines = f . readlines ( ) for i , line in enumerate ( lines ) : if line [ : 13 ] == "'b2mndr_ntim'" : lines [ i ] = lines [ i ] [ : 35 ] + "'" + str ( ntim_new ) + "'\r\n" if line [ : 13 ] == "'b2mndr_dtim'" : lines [ i ] = lines [ i ] [ : 35 ] + "'" + str ( dtim_new ) + "'\r\n" break with open ( 'b2mn.dat' , 'w' ) as f : for i in range ( len ( lines ) ) : f . write ( lines [ i ] ) os . chdir ( olddir )
This routine runs the main calculation of transport coefficients, then saves
the old b2.transport.inputfile and b2fstati files with the iteration number
and updates the b2mn.dat file with short time steps in preparation for the new run
This routine runs the main calculation of transport coefficients then saves the old b2 . transport . inputfile and b2fstati files with the iteration number and updates the b2mn . dat file with short time steps in preparation for the new run
"""
    This routine runs the main calculation of transport coefficients, then saves
    the old b2.transport.inputfile and b2fstati files with the iteration number
    and updates the b2mn.dat file with short time steps in preparation for the new run

    Hide input files from this routine by using '_' in the filename after 'b2.transport.inputfile'
    """ # os.remove('run.log')  # Leave this in case there was a mistake or you want to make changes # os.remove('*.last10') # os.system('rm *.last10')  Doesn't work (apparently the star doesn't translate) # os.rename('b2mn.dat','b2mn.dat_old')  (this looks good, so just overwrite it from now on)
rundir
gfile_loc
new_filename
profiles_fileloc
shotnum
ptime
prunid
use_existing_last10
reduce_Ti
carbon
plotall
plot_xport_coeffs
ntim_new
dtim_new
Dn_min