diff --git a/AOloopControl/scripts/cacao-calib-apply b/AOloopControl/scripts/cacao-calib-apply index 15d68d93..3af7ddd7 100755 --- a/AOloopControl/scripts/cacao-calib-apply +++ b/AOloopControl/scripts/cacao-calib-apply @@ -1,5 +1,44 @@ #!/usr/bin/env bash +####################################################################################### +# Script to apply a CACAO loop calibration previously saved with cacao-calib-archive. +# +# Usage: cacao-calib-apply cal_name +# +# This script must be run in `loop-name-rootdir`. Here cal_name corresponds to a directory +# in `../loop-name-calibs`. Note this is not the whole path, just the directory name including +# the timestamp appended by cacao-calib-archive. +# +# The following steps are performed: +# 1. The loop is turned off +# 2. The loop processes are shutdown, in each case both run and conf: +# mvalC2dm +# mfilt +# wfs2cmodeval +# acquWFS +# 3. The script `./scripts/pre-calib-apply` is run, if it exists. This is a user script +# that can be used for any other desired pre-apply actions on your system. The calib name +# and path (relative to rootdir) are passed as arguments. +# 4. The calibration is loaded into shared memory. This means the files: +# CMmodesDM/CMmodesDM.fits +# CMmodesWFS/CMmodesWFS.fits +# RMmodesWFS/zrespM-H.fits +# wfsref.fits +# wfsmask.fits +# dmmask.fits +# 5. The loop processes, conf and run, are started in the correct order to be initialized: +# acquWFS +# wfs2cmodeval +# mfilt +# mvalC2dm +# 6. The script `./scripts/post-calib-apply` is run, if it exists. This is a user script +# that can be used for any other desired post-apply actions on your system (e.g. zero all gains). +# The calib name and path (relative to rootdir) are passed as arguments. +# 7. The following files are created: +# $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt [contains the directory to calibration files] +# $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_loaded.txt [contains the time calibration was loaded] +# 8. A log entry is made. +############################################################################################################ MSdescr="Apply AO calibration" @@ -39,23 +78,73 @@ echo "Loop ${CACAO_LOOPNUMBER}: Loading calibration from ${ARCHDIR}" if [[ -d "${ARCHDIR}" ]]; then -# Load CM to shared memory -milk-FITS2shm "${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits" aol${CACAO_LOOPNUMBER}_modesWFS -milk-FITS2shm "${ARCHDIR}/CMmodesDM/CMmodesDM.fits" aol${CACAO_LOOPNUMBER}_DMmodes +#open the loop +echo "setval mfilt-${CACAO_LOOPNUMBER}.loopON OFF" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo + +#Shutdown processes +echo "runstop mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +echo "confstop mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +echo "runstop mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +echo "confstop mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsref -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsrefc.fits" aol${CACAO_LOOPNUMBER}_wfsrefc +echo "runstop wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +echo "confstop wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsmask.fits" aol${CACAO_LOOPNUMBER}_wfsmask -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_wfsmap.fits" aol${CACAO_LOOPNUMBER}_wfsmap +echo "runstop acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +echo "confstop acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_dmmask.fits" aol${CACAO_LOOPNUMBER}_dmmask -milk-FITS2shm "${ARCHDIR}/shmim.aol${CACAO_LOOPNUMBER}_dmmap.fits" aol${CACAO_LOOPNUMBER}_dmmap +#run pre-apply script if it exists. +if [ -d "scripts" ]; then + cd scripts + if [ -f "pre-calib-apply" ]; then + echo "running pre-calib-apply" + ./pre-calib-apply ${calib} ${ARCHDIR} + fi + cd .. +fi +# Load CM to shared memory +milk-FITS2shm "${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits" aol${CACAO_LOOPNUMBER}_CMmodesWFS +milk-FITS2shm "${ARCHDIR}/CMmodesDM/CMmodesDM.fits" aol${CACAO_LOOPNUMBER}_CMmodesDM + +milk-FITS2shm "${ARCHDIR}/RMmodesWFS/zrespM-H.fits" aol${CACAO_LOOPNUMBER}_zrespM + +milk-FITS2shm "${ARCHDIR}wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsref +milk-FITS2shm "${ARCHDIR}wfsref.fits" aol${CACAO_LOOPNUMBER}_wfsrefc + +milk-FITS2shm "${ARCHDIR}wfsmask.fits" aol${CACAO_LOOPNUMBER}_wfsmask + +milk-FITS2shm "${ARCHDIR}dmmask.fits" aol${CACAO_LOOPNUMBER}_dmmask + +#Startup processes +echo "confstart acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "runstart acquWFS-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "confstart wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "runstart wfs2cmodeval-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "confstart mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "runstart mfilt-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "confstart mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo +sleep 1 +echo "runstart mvalC2dm-${CACAO_LOOPNUMBER}" >> /milk/shm/${CACAO_LOOPNAME}_fpsCTRL.fifo + +if [ -d "scripts" ]; then + cd scripts + if [ -f "post-calib-apply" ]; then + echo "running post-calib-apply" + ./post-calib-apply ${calib} ${ARCHDIR} + fi + cd .. +fi # record this calib as applied -echo $(pwd)/../${ARCHDIR} > $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt +echo $(pwd)/${ARCHDIR} > $MILK_SHM_DIR/aol${CACAO_LOOPNUMBER}_calib_source.txt DATESTRING="$(date -u --iso-8601=seconds)" diff --git a/AOloopControl/scripts/cacao-calib-archive b/AOloopControl/scripts/cacao-calib-archive index 5fe0b075..be70f017 100755 --- a/AOloopControl/scripts/cacao-calib-archive +++ b/AOloopControl/scripts/cacao-calib-archive @@ -1,5 +1,34 @@ #!/usr/bin/env bash +####################################################################################### +# Script to archive a CACAO loop calibration. +# +# Usage: cacao-calib-arhchive cal_name +# +# This script must be run in `loop-name-rootdir`. Here cal_name corresponds to a descriptive name +# of the calibration. A timestamp will be apended to it, and the result is used to create a directory +# in ``../loop-name-calibs`. +# +# The time stamp appendage can be suppressed with -u for update. +# +# The following files are copied to the cal directory. +# conf/CMmodesDM/CMmodesDM.fits +# conf/CMmodesWFS/CMmodesWFS.fits +# conf/RMmodesWFS/zrespM-H.fits +# conf/wfsref.fits +# conf/wfsmap.fits +# conf/wfsmask.fits +# conf/dmmap.fits +# conf/dmmask.fits +# LOOPNAME +# +# Additionally a file named calib_dir.txt is created which holds the directory path (useful for +# dereferencing symlinks). +# +# The file calib_archived.txt is updated with the current time, and a log entry is made. +# +########################################################################################################## + MSdescr="Archive AO calibration" MSextdescr="Copy current filesystem calibration to ../CACAO_LOOPNAME-AOcalibs// directory @@ -16,8 +45,6 @@ RequiredFiles=() RequiredDirs=(conf) - - MSarg+=( "calibname:string:calibration name" ) MSopt+=( "u:update:setupdate::update existing, do not append timestamp" ) @@ -62,6 +89,10 @@ ARCHDIR="${BASEARCHDIR}${calib}/" mkdir -p ${ARCHDIR} +mkdir -p ${ARCHDIR}/RMmodesDM +mkdir -p ${ARCHDIR}/RMmodesWFS +mkdir -p ${ARCHDIR}/CMmodesDM +mkdir -p ${ARCHDIR}/CMmodesWFS echo "Saving to DIRECTORY ${ARCHDIR}" @@ -69,30 +100,23 @@ echo "Saving to DIRECTORY ${ARCHDIR}" CONFDIR="conf" -for f in $CONFDIR -do - if [ -d "$f" ] - then - for ff in $f/* - do - #if this is a broken symlink, ignore it - if [ -L $ff ] && [ ! -e $ff ] - then - continue - fi - - cp -L -r $ff ${ARCHDIR}"$(basename $ff)" - done - else - cp -L -r $ff ${ARCHDIR} - fi -done +cp ${CONFDIR}/RMmodesWFS/zrespM-H.fits ${ARCHDIR}/RMmodesWFS/zrespM-H.fits +cp ${CONFDIR}/CMmodesDM/CMmodesDM.fits ${ARCHDIR}/CMmodesDM/CMmodesDM.fits +cp ${CONFDIR}/CMmodesWFS/CMmodesWFS.fits ${ARCHDIR}/CMmodesWFS/CMmodesWFS.fits +cp ${CONFDIR}/RMmodesDM/RMmodesDM.fits ${ARCHDIR}/RMmodesDM/RMmodesDM.fits +cp ${CONFDIR}/RMmodesWFS/RMmodesWFS.fits ${ARCHDIR}/RMmodesWFS/RMmodesWFS.fits +cp ${CONFDIR}/wfsref.fits ${ARCHDIR}/wfsref.fits +cp ${CONFDIR}/wfsmask.fits ${ARCHDIR}/wfsmask.fits +cp ${CONFDIR}/wfsmap.fits ${ARCHDIR}/wfsmap.fits +cp ${CONFDIR}/dmmask.fits ${ARCHDIR}/dmmask.fits +cp ${CONFDIR}/dmmap.fits ${ARCHDIR}/dmmap.fits +cp LOOPNAME ${ARCHDIR}/LOOPNAME # write out complete path so someone following a symlink can easily track where we are -echo $(pwd)/${ARCHDIR} > ${ARCHDIR}/aol${CACAO_LOOPNUMBER}_calib_dir.txt +echo $(pwd)/${ARCHDIR} > ${ARCHDIR}/calib_dir.txt # append timestamp -echo ${DATESTRING} >> ${ARCHDIR}/aol${CACAO_LOOPNUMBER}_calib_archived.txt +echo ${DATESTRING} >> ${ARCHDIR}/calib_archived.txt echo "${DATESTRING} ARCHIVED ${calib}" >> ${BASEARCHDIR}/aol${CACAO_LOOPNUMBER}_archive-log.txt