Open act-hydro opened 1 month ago
This is great process!!
One thing we can note here is that ameriflux_init_fields.C1152.CA-Cbo.2006-12-31_23-00-00.nc
does not exist because the year is incorrect. The initial condition file for CA-Cbo has a date of 2010-12-31. Here we simply use the mode start year (with variable name date
in the script above) minus 1 to calculate the year for initial condition file.
year_pre=$((date - 1)) f=ameriflux_init_fields.C1152.${site_id}.${year_pre}-12-31_23-00-00.nc
An example can be referred to #3
I am still having trouble with the cp part, even after following the directions:
for line in cat site_list.txt
; do
echo $line # print each line
echo # print a blank line
IFS="," # define the deliminator, split by comma
set -- $line
site_id=$1 # assign the first element in a line to variable "site_id"
model_run_year=$2 # assign the second element in a line to variable "model_run_year"
unset IFS # we need to unset the deliminator
echo "site name is:" $site_id
echo "model run year is:" $model_run_year
mkdir model_run
mkdir model_run/$1
################ mkdir model_run/$1/forcing mkdir model_run/$1/init mkdir model_run/$1/static
############### year_pre=$((date - 1)) cp /ameriflux_init_fields.C1152.CA-Cbo.2010-12-31_23-00-00.nc ..model_run/$1/init f=ameriflux_init_fields.C1152.$1.${year_pre}-12-31_23-00-00.nc
echo $f
d=../model_run/$1/init/
echo $d
cp $f $d
echo $1
pwd
done
This is how far I got but I am still having trouble with the cp. I keep getting the error that there is no such file in the directory
@KniyaD This is great progress!
Before we copy files, it is important to make sure that the path
of the file exist with respect to the bash script itself.
There are two ways to point to a file.
pwd
command. It output the full path to this file. In my case, the full path to initial condition file is /home/jovyan/data/assignment/assignment_2/hw2/gly606_hw2
. Then we define f="/home/jovyan/data/assignment/assignment_2/hw2/gly606_hw2/ameriflux_init_fields.C1152.$1.${year_pre}-12-31_23-00-00.nc"
gly606_hw2
folder, we will need to put the folder name in front of the file f="gly606_hw2/ameriflux_init_fields.C1152.$1.${year_pre}-12-31_23-00-00.nc"
If the bash script is within the gly606_hw2
folder, we can just directly point to the file
f="ameriflux_init_fields.C1152.$1.${year_pre}-12-31_23-00-00.nc"
Some comments about this line of code (I think you should probably delete it)
cp /ameriflux_init_fields.C1152.CA-Cbo.2010-12-31_23-00-00.nc ..model_run/$1/init
If your bash script is within the gly606_hw2
folder, you can refer to the initial condition file as above or ./ameriflux_init_fields.C1152.CA-Cbo.2010-12-31_23-00-00.nc
. It is important to add the .
in front of the /
, .
means the current folder.
Maybe add /
after the ..
if you want to point to the parent folder.
I hope this helps!
Ok I adopted the comments above but I am still running into no file in directory error
for line in cat site_list.txt
; do
echo $line # print each line
echo # print a blank line
IFS="," # define the deliminator, split by comma
set -- $line
site_id=$1 # assign the first element in a line to variable "site_id"
model_run_year=$2 # assign the second element in a line to variable "model_run_year"
unset IFS # we need to unset the deliminator
echo "site name is:" $site_id
echo "model run year is:" $model_run_year
mkdir model_run
mkdir model_run/$1
################ mkdir model_run/$1/forcing mkdir model_run/$1/init mkdir model_run/$1/static
############### year_pre=$((date - 1)) f=./ameriflux_init_fields.C1152.$1.${year_pre}-12-31_23-00-00.nc echo $f d=../model_run/$1/init/ echo $d cp $f $d echo $1 pwd done
Based on the code above, the variable name for the model year is model_run_year
. So when we calculate the previous year, we will need to refer to the model_run_year
, rather than date
year_pre=$((model_run_year - 1))
Please let me know if you have more questions!
How do I get the "cp" command to work? No matter what I do it says cp: cannot stat 'ameriflux_init_fields.C1152.CA-Cbo.2006-12-31_23-00-00.nc': No such file or directory
I can't figure out why it won't find the file and move it...