#!/bin/bash
#
# dist.sh - script to look for rocking curve files in "latest" directory
#           and create parallel directories named according to the scan
#           name convention, copying the associated scan files to their
#           corresponding directory using hard links.
#
# author: richard.t.jones at uconn.edu
# version: february 24, 2015

for study in `find latest -type f -name "*_*" | grep -v tiff`; do
    studybase=`basename $study`
    if [[ ! -d $studybase ]]; then
        mkdir $studybase
    fi
    ln $study $studybase/
    for tiff in `find latest | grep ${studybase}_scan'.*'.tiff`; do
        cp -l $tiff $studybase/
    done
done
