From ffa4956ac98bed6235aa7620df2747ede02d551d Mon Sep 17 00:00:00 2001 From: Charlie Koven Date: Fri, 19 Jan 2018 13:49:48 -0800 Subject: [PATCH] added execution permission on pftindexswapper and added silent mode on modify_paramfile. --- tools/FatesPFTIndexSwapper.py | 2 ++ tools/modify_fates_paramfile.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) mode change 100644 => 100755 tools/FatesPFTIndexSwapper.py diff --git a/tools/FatesPFTIndexSwapper.py b/tools/FatesPFTIndexSwapper.py old mode 100644 new mode 100755 index 72c891071e..af901b3d18 --- a/tools/FatesPFTIndexSwapper.py +++ b/tools/FatesPFTIndexSwapper.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + # ======================================================================================= # # This python script will open an input FATES parameter file, and given a list of PFT diff --git a/tools/modify_fates_paramfile.py b/tools/modify_fates_paramfile.py index c81a944b55..92ab14dab1 100755 --- a/tools/modify_fates_paramfile.py +++ b/tools/modify_fates_paramfile.py @@ -7,6 +7,7 @@ # --output or --fout: output filename. If missing, will assume its directly modifying the input file, and will prompt unless -O is specified # --O or --overwrite: overwrite output file without asking. # --value or --val: value to put in variable +# --s or --silent: don't write anything on successful execution. #### @@ -34,6 +35,7 @@ def main(): parser.add_argument('--fout','--output', dest='outputfname', type=str, help="Output filename. Required.", required=True) parser.add_argument('--val', '--value', dest='val', type=float, help="New value of PFT variable. Required.", required=True) parser.add_argument('--O','--overwrite', dest='overwrite', help="If present, automatically overwrite the output file.", action="store_true") + parser.add_argument('--silent', '--s', dest='silent', help="prevent writing of output.", action="store_true") # args = parser.parse_args() # print(args.varname, args.pftnum, args.inputfname, args.outputfname, args.val, args.overwrite) @@ -41,7 +43,8 @@ def main(): # check to see if output file exists if os.path.isfile(args.outputfname): if args.overwrite: - print('replacing file: '+args.outputfname) + if not args.silent: + print('replacing file: '+args.outputfname) os.remove(args.outputfname) else: raise ValueError('Output file already exists and overwrite flag not specified for filename: '+args.outputfname) @@ -75,8 +78,12 @@ def main(): if args.pftnum > npft_file: raise ValueError('PFT specified ('+str(args.pftnum)+') is larger than the number of PFTs in the file ('+str(npft_file)+').') if pftdim == 0: + if not args.silent: + print('replacing prior value of variable '+args.varname+', for PFT '+str(args.pftnum)+', which was '+str(var[args.pftnum-1])+', with new value of '+str(args.val)) var[args.pftnum-1] = args.val elif args.pftnum == None and not ispftvar: + if not args.silent: + print('replacing prior value of variable '+args.varname+', which was '+str(var[:])+', with new value of '+str(args.val)) var[:] = args.val else: raise ValueError('Nothing happened somehow.')