Skip to content

Commit

Permalink
Updates to run-directory creation scripts
Browse files Browse the repository at this point in the history
In run/GCClassic/createRunDir.sh and run/GCHPctm/createRunDir.sh:

(1) Allow for tab completion (read -e) when reading the run directory
    path and run directory name

(2) In the run directory path, replace ~ with the user's home directory
    path using this safe algorithm:
    https://stackoverflow.com/questions/3963716/how-to-manually-expand-a-special-variable-ex-tilde-in-bash/27485157#27485157

(3) Print a note that the run directory will be created as a subfolder
    of the run directory path specfied above.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Nov 17, 2020
1 parent bc5c23a commit c304239
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
24 changes: 15 additions & 9 deletions run/GCClassic/createRunDir.sh
Expand Up @@ -425,28 +425,34 @@ while [ "${valid_lev}" -eq 0 ]; do
done

#-----------------------------------------------------------------
# Ask user to define path where directoy will be created
# Ask user to define path where directory will be created
#-----------------------------------------------------------------
printf "${thinline}Enter path where the run directory will be created:${thinline}"
valid_path=0
while [ "$valid_path" -eq 0 ]; do
read rundir_path
if [[ ${rundir_path} = "q" ]]; then
read -e rundir_path
if [[ "x${rundir_path}" == "xq" ]]; then
printf "\nExiting.\n"
exit 1
elif [[ ! -d ${rundir_path} ]]; then
fi
if [[ "${rundir_path}" =~ '~' ]]; then
rundir_path="${rundir_path/#\~/$HOME}"
echo "Expanding to: ${rundir_path}"
fi
if [[ ! -d ${rundir_path} ]]; then
printf "\nERROR: ${rundir_path} does not exist. Enter a new path or hit q to quit.\n"
else
valid_path=1
fi
done

#-----------------------------------------------------------------
# Ask user to define run directoy name if not passed as argument
# Ask user to define run directory name if not passed as argument
#-----------------------------------------------------------------
if [ -z "$1" ]; then
printf "${thinline}Enter run directory name, or press return to use default:${thinline}"
read rundir_name
printf "${thinline}Enter run directory name, or press return to use default:\n"
printf "(This will be a subfolder of the path you entered above.)${thinline}"
read -e rundir_name
if [[ -z "${rundir_name}" ]]; then
if [[ "${sim_extra_option}" = "none" ]]; then
rundir_name=gc_${grid_res}_${sim_name}
Expand Down Expand Up @@ -648,13 +654,13 @@ fi
if [[ "x${domain_name}" == "xAS" ]] || \
[[ "x${domain_name}" == "xEU" ]] || \
[[ "x${domain_name}" == "xNA" ]] || \
[[ "x${domain_name}" == "xcustom" ]]; then
[[ "x${domain_name}" == "xcustom" ]]; then
cmd='s|\[sec\]: 600|\[sec\]: 300|'
sed -i -e "$cmd" input.geos
cmd='s|\[sec\]: 1200|\[sec\]: 600|'
sed -i -e "$cmd" input.geos
fi

#--------------------------------------------------------------------
# Copy sample restart file to run directory
#--------------------------------------------------------------------
Expand Down
16 changes: 11 additions & 5 deletions run/GCHPctm/createRunDir.sh
Expand Up @@ -211,11 +211,16 @@ done
printf "${thinline}Enter path where the run directory will be created:${thinline}"
valid_path=0
while [ "$valid_path" -eq 0 ]; do
read rundir_path
if [[ ${rundir_path} = "q" ]]; then
read -e rundir_path
if [[ "x${rundir_path}" == "xq" ]]; then
printf "\nExiting.\n"
exit 1
elif [[ ! -d ${rundir_path} ]]; then
fi
if [[ "${rundir_path}" =~ '~' ]]; then
rundir_path="${rundir_path/#\~/$HOME}"
echo "Expanding to: ${rundir_path}"
fi
if [[ ! -d ${rundir_path} ]]; then
printf "\nERROR: ${rundir_path} does not exist. Enter a new path or hit q to quit.\n"
else
valid_path=1
Expand All @@ -226,8 +231,9 @@ done
# Ask user to define run directory name if not passed as argument
#-----------------------------------------------------------------
if [ -z "$1" ]; then
printf "${thinline}Enter run directory name, or press return to use default:${thinline}"
read rundir_name
printf "${thinline}Enter run directory name, or press return to use default:\n"
printf "(This will be a subfolder of the path you entered above.)${thinline}"
read -e rundir_name
if [[ -z "${rundir_name}" ]]; then
if [[ "${sim_extra_option}" = "none" ]]; then
rundir_name=gchp_${sim_name}
Expand Down

0 comments on commit c304239

Please sign in to comment.