Loading
  1. import os
  2. from subprocess import Popen
  3.  
  4. main_nml = open('PART.nml', 'r')
  5.  
  6. output_nml = open('PART-x-combined.nml', 'w')
  7. output_nml.close() # clear the content of the file
  8. output_nml = open('PART-x-combined.nml', 'w')
  9.  
  10. prefix = '//#include '
  11. prefix_length = len(prefix)
  12. for line in main_nml:
  13.   if prefix in line:
  14.     output_nml.write(line)
  15.     filename_to_import = line[prefix_length:][:-1]
  16.     if os.path.isfile(filename_to_import):
  17.       with open(filename_to_import,'r') as file_to_import:
  18.         file_to_import = open(filename_to_import, 'r')
  19.         for l in file_to_import:
  20.           output_nml.write(l)
  21.     else:
  22.       print(filename_to_import, 'not found!!!')
  23.   else:
  24.     output_nml.write(line)
  25.  
  26.  
  27. main_nml.close()
  28. output_nml.close()
  29.  
  30. script_path = os.path.realpath(__file__)
  31. script_folder = os.path.dirname(script_path)
  32. compiling = Popen('compile.bat', cwd=script_folder, shell = True)
  33.  
  34. print('Success! NML combined.')

Comments