Skip to content

Commit

Permalink
Use pure sed instead of bash function
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiZhuang committed Dec 6, 2018
1 parent a6621f1 commit f5d9b5e
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions scripts/build_environment/GC-classic/deploy_GC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ git clone https://github.com/geoschem/geos-chem-unittest.git UT
cd UT
git checkout -b $UT_VERSION

# change UT configurations
modify_line () {
# convenient function to change one line in a text file
local key=$1 # unique pattern to locate a line
local newline=$2 # newline as the replacement
local file=$3
# use '#' as delimiter so the line can contain '/' and ':'
sed -i -e "s#.*${key}.*#${newline}#" $file
}
# Configure UT

modify_line 'CODE_DIR :=' ' CODE_DIR :=$(HOME)/tutorial/Code.$(VERSION)' runs/shared_inputs/Makefiles/Makefile
# Each sed command change one line in a text file
# This could be trivially done by text editors by we want full automation
# Use '#' as delimiter so the line can contain '/' and ':'
# Use .* to match the rest of the line

sed -i -e 's#CODE_DIR :=.*#CODE_DIR :=$(HOME)/tutorial/Code.$(VERSION)#' runs/shared_inputs/Makefiles/Makefile

cd perl
modify_line 'GCGRID_ROOT :' ' GCGRID_ROOT : /home/ubuntu' CopyRunDirs.input
modify_line 'DATA_ROOT :' ' DATA_ROOT : {GCGRIDROOT}/ExtData' CopyRunDirs.input
modify_line 'UNIT_TEST_ROOT :' ' UNIT_TEST_ROOT : {HOME}/tutorial/UT' CopyRunDirs.input
modify_line 'COPY_PATH :' ' COPY_PATH : {HOME}/tutorial' CopyRunDirs.input
sed -i -e 's#GCGRID_ROOT :.*#GCGRID_ROOT : /home/ubuntu#' CopyRunDirs.input
sed -i -e 's#DATA_ROOT :.*#DATA_ROOT : {GCGRIDROOT}/ExtData#' CopyRunDirs.input
sed -i -e 's#UNIT_TEST_ROOT :.*#UNIT_TEST_ROOT : {HOME}/tutorial/UT#' CopyRunDirs.input
sed -i -e 's#COPY_PATH :.*#COPY_PATH : {HOME}/tutorial#' CopyRunDirs.input

# show the modifications
git add -A
Expand All @@ -49,17 +46,20 @@ git status -v

# compile executable
cd ~/tutorial/geosfp_4x5_standard
mkdir OutputDir # to host output data
make -j4 mpbuild NC_DIAG=y BPCH_DIAG=n TIMERS=1

# change run-time configuration for tutorial purpose
modify_line 'End YYYYMMDD' 'End YYYYMMDD, hhmmss : 20160701 002000' input.geos

mkdir OutputDir
modify_line "EXPID: ./GEOSChem" "EXPID: ./OutputDir/GEOSChem" HISTORY.rc
sed -i -e 's#End YYYYMMDD.*#End YYYYMMDD, hhmmss : 20160701 002000#' input.geos
sed -i -e 's#EXPID: ./GEOSChem.*#EXPID: ./OutputDir/GEOSChem#' HISTORY.rc
sed -i -e "s/#'SpeciesConc',/'SpeciesConc',/" HISTORY.rc
modify_line "SpeciesConc'" " 'SpeciesConc'," HISTORY.rc # make sure this collection is uncommented

# reduce output size for tutorial purpose
modify_line "SpeciesConc.frequency" " SpeciesConc.frequency: 00000000 002000" HISTORY.rc
modify_line "SpeciesConc.duration" " SpeciesConc.duration: 00000000 002000" HISTORY.rc
modify_line "SpeciesConc.mode" " SpeciesConc.mode: 'instantaneous'" HISTORY.rc
modify_line "SpeciesConc.fields" " SpeciesConc.fields: 'SpeciesConc_NO ', 'GIGCchem',\n 'SpeciesConc_CO ', 'GIGCchem',\n 'SpeciesConc_O3 ', 'GIGCchem'," HISTORY.rc
sed -i -e 's#SpeciesConc.frequency.*#SpeciesConc.frequency: 00000000 002000#' HISTORY.rc
sed -i -e 's#SpeciesConc.duration.*#SpeciesConc.duration: 00000000 002000#' HISTORY.rc
sed -i -e "s#SpeciesConc.mode.*#SpeciesConc.mode: 'instantaneous'#" HISTORY.rc
sed -i -e "s#SpeciesConc.fields.*#SpeciesConc.fields: 'SpeciesConc_NO ', 'GIGCchem',\n 'SpeciesConc_CO ', 'GIGCchem',\n 'SpeciesConc_O3 ', 'GIGCchem',#" HISTORY.rc

# run the model
./geos.mp

0 comments on commit f5d9b5e

Please sign in to comment.