Skip to content

Commit

Permalink
Merge pull request #2 from ckoven/rgknox-tools-pftindexswapper
Browse files Browse the repository at this point in the history
added execution permission on pftindexswapper and added silent mode on modify_paramfile.
  • Loading branch information
rgknox authored Jan 19, 2018
2 parents 7ad065c + ffa4956 commit 6683715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tools/FatesPFTIndexSwapper.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# =======================================================================================
#
# This python script will open an input FATES parameter file, and given a list of PFT
Expand Down
9 changes: 8 additions & 1 deletion tools/modify_fates_paramfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
####


Expand Down Expand Up @@ -34,14 +35,16 @@ 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)
#
# 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)
Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit 6683715

Please sign in to comment.