#!/bin/bash
#
#  This bash script will writes analog data from xdphys data files into
#  a separate binary .ana file.
#
#  This is useful if, for instance, you want to analyze analog data using
#  MATLAB for Windows, where xdview is unavailable, or if you simply want
#  a CD full of analog data files.
#
#  It specifically does the following: 
#
# 		if <file> is an xdphys data file, 
#			xdview -ana all <file> > <file>.ana
#			rm <file>
#		fi
#   

for dir in $(ls | grep "^J")
do
	echo $dir;
	echo -----------;
	cd /home/ICx/$dir;
	for xfile in $(ls [46]* | grep -v "\(ana\|gen\)")
	do
		echo -n "$xfile: "
		if test $(echo $xfile | grep "gz$") 
		then
			echo -n "gunzipping ... ";
			gunzip $xfile;
			xfile=$(echo $xfile | sed 's/\.gz$//g');
		fi
		anafile="$xfile.ana";
		echo -n "creating ana file ... ";
		xdview -ana all $xfile > $anafile;
		rm $xfile;
		echo "done.";
	done
done



