#/!bin/bash
##===========================================================================
## Copyright (C) 2021 Max-Planck-Institut für Radioastronomie, Bonn, Germany
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see .
##===========================================================================
if [ $# -ne 2 ];
then
echo "Usage: fplot2png <1-letter station code|'all'>"
echo ""
echo "Creates a series of PNG images of all scans containing the given one-letter station code"
echo "If you want to process all stations specify: all"
exit
fi
arg1=$1
arg2=$2
function processScandir () {
path=$1
station=$2
base=$(dirname $path)
pushd $path > /dev/null
regex="(.)(.)\.[a-zA-Z]\.(.*)\."
for file in ??.*.*.*; do
if [[ $file =~ $regex ]]
then
bl1="${BASH_REMATCH[1]}"
bl2="${BASH_REMATCH[2]}"
num="${BASH_REMATCH[3]}"
if (( [ $station == "all" ] ) || ( [ $bl1 == $station ] || [ $bl2 == $station ] ))
then
scan=$(basename $file)
echo "processing $path baseline $bl1-$bl2"
out="${path}-${bl1}${bl2}_${num}"
GS_OPTIONS=-sOutputFile="../$out.png" GS_DEVICE=png16m fplot $file < /dev/urandom > /dev/null 2>&1
fi
fi
done
popd > /dev/null
}
cd $arg1
for scandir in `find * -type d`; do
processScandir $scandir $arg2
done