#! /bin/bash -e ### Madrigal upload script ### Translated from csh Carl-Fredrik Enell 20190917 ## Tasks # (1) Prepare analyzed data (guisdap result files) for loading to madrigal. # (2) Transfer the prepared files to the central "madrigalstage" directory. ### Syntax: mad RESULT_DIRECTORY if [ $# != 1 ]; then echo "Usage: $0 RESULT_DIRECTORY"; exit 1; fi ### Create stage directory echo "Reading input from $1" TMPDIR=$(mktemp -d) GDIR=$(basename $1) MDIR="${TMPDIR}/${GDIR}-stage" mkdir ${MDIR} echo "Copying $1 to ${MDIR}" cp -rp $1 ${MDIR} ### Format for Madrigal: results and tarball of mat files echo "Formatting ${MDIR} for Madrigal" pushd ${MDIR} >& /dev/null # Move result files up one level [ ! -f ${GDIR}/*.eps ] || mv -f ${GDIR}/*.eps . [ ! -f ${GDIR}/*.png ] || mv -f ${GDIR}/*.png . [ ! -f ${GDIR}/*.pdf ] || mv -f ${GDIR}/*.pdf . [ ! -f ${GDIR}/NCAR*.asc ] || mv -f ${GDIR}/NCAR*.asc . [ ! -f ${GDIR}/NCAR*.bin ] || mv -f ${GDIR}/NCAR*.bin . [ ! -f ${GDIR}/NCAR*.hdf5 ] || mv -f ${GDIR}/NCAR*.hdf5 . [ ! -f ${GDIR}/*.txt ] || mv -f ${GDIR}/*.txt . # create tarball of $MDIR/$GDIR: now contains only .mat and gfd_setup.m files tar cf ${GDIR}.tar ${GDIR} rm -rf ${GDIR} # Replace @ signs in names ##for F in *\@*; do mv ${F} ${F/\@/_}; done # Compress any big files BIGFILES=(eps asc tar) for FTYP in ${BIGFILES[@]}; do if [ -f *.${FTYP} ]; then gzip -9 *.${FTYP} ; fi done ### Done formatting echo "${MDIR} now contains: " ls -l popd >& /dev/null ### Copy to HQ stage area and clean up echo "Transferring ${MDIR} to HQ madrigalstage directory" scp -rqp ${MDIR} kstdev@eiscathq.eiscat.se:~/madrigalstage/ echo "Deleting temporary directory ${MDIR}" rm -rf ${MDIR} echo "Moving $1 to madrigalstaged" [ -d ${HOME}/madrigalstaged ] || mkdir ${HOME}/madrigalstaged mv $1 ${HOME}/madrigalstaged echo "Done!" ### EOF