#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Bootstrap script to create a new mesh based on the CORE 2 Resolution. Dr. Paul Gierz, Jan 2020 """ import cdo import yaml import os import shutil if __name__ == "__main__": print(80*"=") print("Starting generation of a mesh: {{cookiecutter.mesh_name}}.") print(40*"- ") print("Gathering input data:") if not os.path.exists("./raw_input_data"): os.makedirs("./raw_input_data") shutil.copyfile("{{cookiecutter.input_fpath}}", "./raw_input_data/{{cookiecutter.input_fname}}") shutil.copyfile("{{cookiecutter.input_fpath}}", "./raw_input_data/{{cookiecutter.input_fname}}_backup") gateway_fixes = None if os.path.exists("fixup_gateways.yaml"): with open("fixup_gateways.yaml", "r") as gateway_fixes_file: gateway_fixes = yaml.load(gateway_fixes_file) if gateway_fixes: CDO = cdo.Cdo() print("Fixup input data:") for gateway_name, fix_list in gateway_fixes.items(): print(gateway_name) print(fix_list) for fix_number, fix in enumerate(fix_list): print(f"* {fix_number}:") fix = [int(item) for item in fix.split(",")] x1 = fix[0] x2 = fix[1] y1 = fix[2] y2 = fix[3] value = fix[4] print("* Setting:") # FIXME: print(f"{y2} ------ {x2}") print(f" | |") print(f" | {value} |") print(f" | |") print(f"{x1} ------ {y1}") output = CDO.setcindexbox(f"{value},{x1},{x2},{y1},{y2}", input="./raw_input_data/{{cookiecutter.input_fname}}") os.rename(output, "./raw_input_data/{{cookiecutter.input_fname}}") print(40*"- ") print("* MATLAB Part:") os.system("module load matlab; matlab.x -nodisplay -r \"run('mg_topo_prep_triangle_input.m')\"") os.system("module load matlab; matlab.x -nodisplay -r \"run('mg_coastline.m')\"") os.rename("{{cookiecutter.mesh_name}}_cst.txt", "mesh_CORE2_{{cookiecutter.mesh_name}}/{{cookiecutter.mesh_name}}_cst.txt") # TODO: Get count from the other python script and write it somewhere # TODO: C reads count from the file just written... print(40*"- ") print("* Triangle Part:") os.system("sbatch -W run_triangle.sh") print("Finished!") print("You should now inspect your mesh!") print(80*"=")