Skip to content

Instantly share code, notes, and snippets.

@n7275
Last active October 23, 2022 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n7275/8cab7e348507ff4bce4749d09e2c3894 to your computer and use it in GitHub Desktop.
Save n7275/8cab7e348507ff4bce4749d09e2c3894 to your computer and use it in GitHub Desktop.
import re
import glob
import os
### THIS SCRIPT HAS NO UNDO BUTTON. IT UPDATES ALL. SCENERIOS IN THE CURRENT DIRECTORY ###
### BACK UP YOUR FILES. KNOW WHAT DIRECTORY THIS IS RUNNING IN.
### I WILL DO THE UPDATE FOR YOU, BUT I CAN'T FIX AN INCORRECTLY PERFORMED UPDATE THAT YOU DO
### PM ME ON ORBITER-FORUM.COM (@n72.75)
all_scn_files = glob.glob('./*.scn')
#all_scn_files = ["LEMSystems.cfg","SaturnSystems.cfg"]
SPECIFICC_GAS = [0.658, 10.183, 1.4108, 0.743, 0.6553, 3.625769, 0.48102, 4.6, 3.12]
SPECIFICC_LIQ = [1.1519, 9.668, 4.184, 1.040, 0.858, 3.691041, 1.0724, 1.5525, 5.193]
SPECIFICC_OLD = [1.669, 9.668, 4.184, 1.040, 0.858, 3.691041, 2.9056392, 1.270, 5.193]
substance_pattern = "\sCHM"
version_pattern = "\sNASSPVER"
def updatelines(scn_name):
scn_file = open(scn_name,'r')
scn_lines = scn_file.readlines()
line = 0
for scn_line in scn_lines:
if(re.search(version_pattern,scn_line)):
scn_line_split = scn_line.split()
version = substance = int(scn_line_split[1])
if(version >= 80001):
print(scn_filename + " Already Up To Date")
break
else:
new_version_line = scn_line.replace(scn_line_split[1],str(80001))
scn_lines[line] = new_version_line
if(re.search(substance_pattern,scn_line)):
scn_line_split = scn_line.split()
commented = 0
if(scn_line_split[0] == "#"):
commented = 1
substance = int(scn_line_split[1+commented])
mass = float(scn_line_split[2+commented])
vapor_mass = float(scn_line_split[3+commented])
internal_energy = float(scn_line_split[4+commented])
old_temp = 0.0
if(mass > 0.0):
old_temp = internal_energy/(mass*SPECIFICC_OLD[substance])
new_internal_energy = ((mass-vapor_mass)*SPECIFICC_LIQ[substance]+vapor_mass*SPECIFICC_GAS[substance])*old_temp
new_substance_line = scn_line.replace(scn_line_split[4+commented],str(new_internal_energy))
scn_lines[line] = new_substance_line
line += 1
with open(scn_name,'w') as new_file:
new_file.writelines(scn_lines)
# updatelines("SaturnSystems.cfg")
for scn_filename in all_scn_files:
print("Updated: " + scn_filename)
updatelines(scn_filename)
os.system("pause")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment