#!/bin/bash
#-------------------------------------------------------------
# FLUO_PROCESS: A shell script for post-processing sQuid experimental data
#
# IN:		folder: (a4...ec) GFP camera data: GFPimages.tif
#			folder: (a4...37) IR camera data: IRimages.tif
#
# OUT:		folder: GFP images all.tif
#			folder: IR bkgd images.tif
#			file:   sequence.txt
#			file:   IR movie.avi
#
# Author: 	Pavan Ramdya	
# Date:		March 29 2012
# Modified:	
#-------------------------------------------------------------

STRING="Revision March 29 2012 Pavan Ramdya"
echo $STRING

#-------------------------------------
# GET directory for processing
expdir=$1
cd $expdir

#-------------------------------------
# MAKE folder with GFP images from GFP camera images (a4...ec)
STRING="...Making GFP images folder from GFP camera (a4...ec) blue LED images"
echo $STRING

cd a47011109a1ec*		#Go to the directory named after GFP camera number (USER: change this for your camera)

mkdir "GFPimages"

cp -v *blue*.tif GFPimages

mv GFPimages ..

cd ..

#-------------------------------------
# MAKE folder with IR background images from IR camera images (a4...37)
STRING="...Making background folder with IR images"
echo $STRING

cd a470111098137*		#Go to the directory named after IR camera number (USER: change this for your camera)

mkdir "bkgd"

cp -v *_*-*-*-0*.tif bkgd

mv bkgd ..

cd ..

#-------------------------------------
# MAKE sequence.txt file from IR camera images (a4...37) 
STRING="...Making sequence file from IR images"
echo $STRING

cd a470111098137*		#Go to the directory named after IR camera number (USER: change this for your camera)

ls>sequence.txt

mv sequence.txt ..

cd ..

#-------------------------------------
# CHANGE IR (a4...37) .tif images to .jpeg
STRING="...Making IR.jpeg images from IR.tif"
echo $STRING

cd a470111098137*		#Go to the directory named after IR camera number (USER: change this for your camera)

for f in *tif ; do convert -quality 100 $f `basename $f tif`jpg; done 

cd ..

#-------------------------------------
# MAKE IR (a4...37) .jpg images to .avi movie
STRING="...Making video from IR jpegs"
echo $STRING

cd a470111098137*		#Go to the directory named after IR camera number (USER: change this for your camera)

mencoder "mf://*.jpg" -mf fps=20 -o movie.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

mv movie.avi ..

cd ..
#-------------------------------------
# REMOVE IR (a4...37) .tif images
STRING="...Removing IR.tif images"
echo $STRING

cd a470111098137*		#Go to the directory named after IR camera number (USER: change this for your camera)

rm *.tif

cd ..

#------------------------------------
# REMOVE GFP image (a4...ec) folder and images
STRING="...Removing GFP image folder with original GFP camera images"
echo $STRING

rm -r a47011109a1ec*	#Remove directory named after GFP camera number (USER: change this for your camera)

#------------------------------------
# REMOVE IR (a4...37) folder and images
STRING="...Removing IR image folder with original IR camera images"
echo $STRING

rm -r a470111098137*	#Remove directory named after IR camera number (USER: change this for your camera)

#-----------------------------------
STRING="...Done."
echo $STRING

