def SelectPreexistingNamelists(): files = os.listdir(NamelistsPath()) template_name = "Standard template" wrffiles = [template_name] wpsfiles = [template_name] for f in files: if f.startswith("namelist.input"): wrffiles.append(f) elif f.startswith("namelist.wps"): wpsfiles.append(f) # If the namelist container is given a None for the file, it will load the standard template print( "Select the namelist files to use. If there is a discrepancy in the domain, the WPS file" ) print("takes precedence.") wrffile = UI.UserInputList("Choose the WRF namelist: ", wrffiles) if wrffile == template_name: wrffile = wrf_namelist_template_file elif wrffile is not None: wrffile = os.path.join(NamelistsPath(), wrffile) wpsfile = UI.UserInputList("Choose the WPS namelist: ", wpsfiles) if wpsfile == template_name: wpsfile = wps_namelist_template_file elif wpsfile is not None: wpsfile = os.path.join(NamelistsPath(), wpsfile) return wrffile, wpsfile
def SaveMenu(nlc): # Decide how to save the namelists. Pass it the namelist container opts = ["Write namelist regularly (namelist files and pickle)", "Write just the namelist files (not pickle - i.e. temporary namelists)", "Save namelists to NAMELISTS folder for later", "Do not save"] sel = UI.UserInputList("Save the namelists?", opts, returntype="index") my_dir = os.path.dirname(__file__) if sel == 0: nlc.WriteNamelists(dir=my_dir) nlc.SavePickle() elif sel == 1: nlc.WriteNamelists(dir=my_dir) elif sel == 2: while True: suffix = UI.UserInputValue("suffix",noempty=True) if os.path.isfile(os.path.join(NamelistsPath(),"namelist.input.{0}".format(suffix))) or os.path.isfile(os.path.join(NamelistsPath(),"namelist.wps.{0}".format(suffix))): if UI.UserInputYN("{0} is already used. Overwrite?".format(suffix), default="n"): break else: break nlc.WriteNamelists(dir=NamelistsPath(), suffix=suffix) userans = raw_input("Do you also write to make these the current namelist? y/[n]: ") if userans.lower() == "y": print("Writing out namelists.") nlc.WriteNamelists(dir=my_dir) nlc.SavePickle() else: print("Not writing out namelists.") elif sel == 3: pass
def StartMenu(): opts = ["Create or modify namelists", "Show help", "Quit"] while True: sel = UI.UserInputList("What would you like to do?",opts,returntype="index", emptycancel=False) if sel == 0: return LoadMenu() elif sel == 1: PrintHelp("HELP") elif sel == 2: exit(0)
def LoadMenu(): opts = ["Load standard templates", "Load existing namelists", "Modify the current namelists", "Quit"] loadmethod = UI.UserInputList("What namelist would you like to load?", opts, returntype="index") if loadmethod == 0: return WRF.NamelistContainer(wrffile=wrf_namelist_template_file, wpsfile=wps_namelist_template_file) elif loadmethod == 1: wrffile, wpsfile = SelectPreexistingNamelists() if wrffile is not None and wpsfile is not None: nlc = WRF.NamelistContainer(wrffile=wrffile, wpsfile=wpsfile) nlc.UserSetMet() return nlc else: return None elif loadmethod == 2: return WRF.NamelistContainer.LoadPickle() elif loadmethod == 3: return None