Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

added execution permission on pftindexswapper and added silent mode on modify_paramfile. #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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