Register
It is currently Wed Dec 13, 2017 12:52 pm

Prewritten script: How do I get it started?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Feb 16, 2017 11:39 am   

Joined: Thu Feb 16, 2017 11:23 am
Posts: 1
Hello,
I have to do some calculations with cdftools, but there are always some issues when I try to start the script. Can someone help me to get started with it?
Thank you, Sebastian

Script:
#!/bin/bash
# compute the transport through sections, defined by ${sectionfile}
# June 17, 2011 xhu
# Dec 30, 2011 xhu
# Sep 12, 2012 xhu: should work for any frequency output
# Jul 5, 2015 xhu: modified for ANHA simulation
# Jan 28, 2016 xhu: added the data folder for CREG025-EAHlim2
# usage:
# GetSectionOceanFlux_ANHA.sh CaseTag YearStart MonStart YearEnd MonEnd section-file
# e.g.,
# GetSectionOceanFlux_ANHA.sh ANHA4-EXH001 2002 1 2010 12 section_extra.dat

if [ $# -eq 5 ]; then
[ ! -e section.dat ] && echo "using default section file: section.dat but NOT found in current folder" && exit
sectionfile="section.dat" && echo "using default section file: section.dat"
elif [ $# -eq 6 ]; then
sectionfile=$6
else
sed -n '7,10p' `which GetSectionOceanFlux_ANHA.sh`
exit
fi

CaseTag
YearS=2002; MonS=1
YearE=2015; MonE=12
cPWD=`pwd`
saveFolder="${cPWD}/trpIASP"
isSectionTrpSave=1
isCLIP=1 # use clipped version cdftransportiz (cdftransportizClip)
# to save memory
isDebug=0

# check cdftool command
cdfP="/mnt/storage1/xhu/PROGRAM/CDFTOOLS/"
if [ $isCLIP -eq 1 ]; then
[ ! -e ${cdfP}/cdftransportizClip ] && echo "cdftransportizFinalSP is not found in ${cdfP}" && exit
else
[ ! -e ${cdfP}/cdftransportizFinalSP ] && echo "cdftransportizFinalSP is not found in ${cdfP}" && exit
fi
# set the mask/mesh files and data folder
maskfile="/mnt/storage1/xhu/ANHA4-I/ANHA4_mask.nc"
meshzgr="/mnt/storage1/xhu/ANHA4-I/ANHA4_mesh_zgr.nc"
meshhgr="/mnt/storage1/xhu/ANHA4-I/ANHA4_mesh_hgr.nc"
if [ ${CaseTag} == "ANHA4-EXH005" ]; then
dataSRC="/mnt/storage0/xhu/NEMO/ANHA4-EXH005"
elif [ ${CaseTag} == "ANHA4-ETestR" ]; then
dataSRC="/mnt/storage1/clark/ANHA4-ETestR"
elif [ ${CaseTag} == "ANHA4-EAHlim2" -o ${CaseTag} == "CREG025-EAHlim2" ]; then
dataSRC="/mnt/storage1/amber/ANHA4/ANHA4-EAHlim2/links"
CaseTag="CREG025-EAHlim2"
echo "CaseTag changed to CREG025-EAHlim2"
elif [ ${CaseTag} == "ANHA12-EXH003" ]; then
dataSRC="/mnt/storage1/xhu/NEMO/ANHA12-EXH003"
maskfile="/mnt/storage1/xhu/ANHA12-I/ANHA12_mask.nc"
meshzgr="/mnt/storage1/xhu/ANHA12-I/ANHA12_mesh_zgr.nc"
meshhgr="/mnt/storage1/xhu/ANHA12-I/ANHA12_mesh_hgr.nc"
else
dataSRC="/mnt/storage1/xhu/NEMO/${CaseTag}"
[ ! -d ${dataSRC} ] && echo "${dataSRC} does not exist" && exit
fi

# temporary work folder
mytmpfolder="mytmp_`date +%Y%m%d%H%M%S`"
[ ! -d ${mytmpfolder} ] && mkdir ${mytmpfolder}
cd ${mytmpfolder}
# link the mask/mesh files
ln -fs ${maskfile} mask.nc
ln -fs ${meshzgr} mesh_zgr.nc
ln -fs ${meshhgr} mesh_hgr.nc
if [ ! -e ../${sectionfile} ]; then
echo "${sectionfile} cannot be found!!!"
exit
else
ln -s ../${sectionfile} .
fi

# check the path to save the output files
[ ! -d ${saveFolder} ] && mkdir -p ${saveFolder} && echo "results are saved to ${saveFolder}"

# start the time loop
for myyear in `seq ${YearS} ${YearE}`
do
if [ ${YearS} -eq ${YearE} ]; then
nm1=${MonS}
nm2=${MonE}
else
if [ $myyear -eq ${YearS} ]; then
nm1=${MonS}
nm2=12
elif [ $myyear -eq ${YearE} ]; then
nm1=1
nm2=${MonE}
else
nm1=1
nm2=12
fi
fi
yearstr=`echo ${myyear} | awk '{printf "%04d",$1}'`
echo " year: $myyear nm1=$nm1 nm2=$nm2"
for nmon in `seq ${nm1} ${nm2}`
do
monstr=`echo ${nmon} | awk '{printf "%02d",$1}'`
eval "timeTag=( `ls ${dataSRC}/${CaseTag}_y${yearstr}m${monstr}d*_gridT.nc 2>/dev/null | awk -F\/ '{print $NF}' | awk -F\_ '{print $2}'`)"
if [ ${#timeTag} -eq 3 ]; then
timeTag=`echo ${timeTag} | sed -e 's/\(//g' -e 's/\)//g' -e 's/\ //g' 2>/dev/null`
fi

if [ ${#timeTag} -gt 0 ]; then
for yymmdd in ${timeTag[*]}
do
mytfile="${dataSRC}/${CaseTag}_${yymmdd}_gridT.nc"
myvfile="${dataSRC}/${CaseTag}_${yymmdd}_gridV.nc"
myufile="${dataSRC}/${CaseTag}_${yymmdd}_gridU.nc"
if [ ! -e $mytfile ]; then
echo "$mytfile cannot be found!!!"
exit
fi
if [ ! -e $myufile ]; then
echo "$myufile cannot be found!!!"
exit
fi
if [ ! -e $myvfile ]; then
echo "$myvfile cannot be found!!!"
exit
fi
if [ ${isDebug} -eq 1 ]; then
if [ $isCLIP -eq 1 ]; then
echo "${cdfP}/cdftransportizClip -short ${dataSRC}/${CaseTag}_${yymmdd} -Quiet < ${sectionfile}"
else
echo "${cdfP}/cdftransportizFinalSP -short ${dataSRC}/${CaseTag}_${yymmdd} -Quiet < ${sectionfile}"
fi
exit
else
if [ $isCLIP -eq 1 ]; then
${cdfP}/cdftransportizClip -short ${dataSRC}/${CaseTag}_${yymmdd} -Quiet < ${sectionfile}
else
${cdfP}/cdftransportizFinalSP -short ${dataSRC}/${CaseTag}_${yymmdd} -Quiet < ${sectionfile}
fi
mv htrp.txt ${saveFolder}/${CaseTag}_${yymmdd}_h_trp.txt
mv strp.txt ${saveFolder}/${CaseTag}_${yymmdd}_s_trp.txt
mv vtrp.txt ${saveFolder}/${CaseTag}_${yymmdd}_v_trp.txt
if [ ${isSectionTrpSave} -eq 1 ]; then
mv section_trp.dat ${saveFolder}/${CaseTag}_${yymmdd}_section_trp.dat
else
rm -f section_trp.dat
fi
fi
done
fi
done # done loop of month
done # done loop of year

# remove temporary folder
if [ ${isDebug} -eq 0 ]; then
[ -e mask.nc ] && unlink mask.nc
[ -e mesh_zgr.nc ] && unlink mesh_zgr.nc
[ -e mesh_hgr.nc ] && unlink mesh_hgr.nc
[ -e ${sectionfile} ] && unlink ${sectionfile}
cd .. && rmdir ${mytmpfolder}
fi







Error:
which: no GetSectionOceanFlux_ANHA.sh in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xxx/.local/bin:/home/xxx/bin)


Top
 Profile  
 PostPosted: Thu Feb 16, 2017 7:36 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
I do not read code presented like this.

Use proper indenting by applying code tags. Press "Full Editor".

And the error messages states clearly, that it is missing a file callen GetSectionOceanFlux_ANHA.sh
which it tried to find in some directories.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP