#!/bin/sh function usage() { echo "" echo "Written up by Yufeng Tong 20070326, last updated 20070402" echo "Adopted from:" echo " http://structbio.vanderbilt.edu/~sheehan/diffracGallery.html" echo "Tailored for SGC Toronto data naming convention" echo "" echo "This script convert .osc diffraction pattern to jpeg images" echo "and makes a composite jpg file" echo "" echo "Requirement: " echo " ipmosflm -- Usually comes with CCP4" echo " ImageMagick -- Usually installed with your Linux distribution" echo "" echo "Usage: $0 [-combineonly|-convertonly|-h] [-img1] [-compact] [[-puck] puckname_jobid]" echo " -img1 Only process the first diffraction" echo " -compact Omit missing images in combination" echo "Example: $0 hv3_2" } function sanitycheck() { if `which $MOSFLM| grep -q 'which: no'`; then echo "Cannot find ${MOSFLM}. No conversion" CNVT=0 fi if `which montage| grep -q 'which: no'`; then echo "Cannot find 'montage' to combine images, No combination" CMBN=0 fi } function convertOSC() { oscfiles=`/bin/ls ${prefix}*/Images/*.osc` for ff in $oscfiles; do oscdir=`dirname $ff` # strip off "Images" to have a puck position for each image puckpos=`dirname $oscdir` cd $oscdir for I in $imageset; do imagename=${puckpos}-${I}.${exten02} if [ -f ${curdir}/${imagename} ]; then echo "skip $imagename..." continue fi $MOSFLM << EOF template ${prefix}_screen0###.osc image ${I} xgui on go CREATE_IMAGE BINARY TRUE FILENAME ${imagename} return exit exit EOF mv ${imagename} $curdir done cd $curdir done } function combineimages() { # combine the images echo "##############################" echo "# Now combining the images #" echo "##############################" for I in $imageset; do allimages="" for pp in $puckset; do jpgfile=${prefix}_${jobid}_$pp-$I.${exten02} if [ ! -f $jpgfile ]; then if [ $COMPACT == 0 ]; then jpgfile=null: # this is a ImageMagick name else jpgfile="" fi fi allimages="$allimages $jpgfile" #echo "allimages: $allimages" done montage -geometry 400x400 -label "%f" -tile 3x4 -quality 85 ${allimages} ${prefix}-combined-${I}.jpg done } if [ $# -lt 1 ]; then usage exit 1 fi CNVT=1 CMBN=1 curdir=`pwd` exten01="osc" exten02="jpg" MOSFLM=ipmosflm imageset="001 002" puckset="1 2 3 4 5 6 7 8 9 10 11 12" COMPACT=0 allimages="" while [ $1 ]; do case "$1" in -combineonly) CNVT=0 shift ;; -convertonly) CMBN=0 shift ;; -puck) shift PUCK=$1 shift ;; -img1) shift imageset="001" ;; -compact) shift COMPACT=1 ;; -help| -h) usage exit 1 ;; *) PUCK=$1 shift ;; esac done sanitycheck prefix=`echo $PUCK | sed -e "s/\(.*\)_\([0-9]\).*/\1/"` jobid=`echo $PUCK | sed -e "s/\(.*\)_\([0-9]\).*/\2/"` [ $CNVT <> 0 ] && convertOSC [ $CMBN <> 0 ] && combineimages