#!/bin/sh
#
# shell script to fix postscript files that were generated in IDL
# with landscape orientation to create epsi files that can be 
# imported into StarOffice
#
# Author: Martin Schultz, MPI, 04 Jan 2001
# The output file will be <filename>.eps unless otherwise specified


# check arguments

if [ .$1. == .. ] ; then
   echo Usage: psfix inputfile [outputfile]
   exit
else
   infile=$1
fi
echo Converting $infile

if [ ! -s $infile ] ; then
   echo Input file $infile not found!
   exit
fi

if [ .$2. == .. ] ; then
   outfile=`basename $infile .ps`.eps
else
   outfile=$2
fi
echo generating EPS file $outfile


# remove bounding box and orientation statements
sed 's/%%BoundingBox:.*//' $infile > tmp___001.ps
sed 's/%%PageOrientation: Landscape//' tmp___001.ps > tmp___002.ps
rm -f tmp___001.ps
sed 's/%%PageBoundingBox:.*//' tmp___002.ps > tmp___003.ps
rm -f tmp___002.ps

# remove rotate and translate statements
sed 's/[0-9 ]*translate//' tmp___003.ps > tmp___004.ps
rm -f tmp___003.ps
sed 's/[0-9 ]*rotate//' tmp___004.ps > tmp___005.ps
rm -f tmp___004.ps

# convert to epsi
ps2epsi tmp___005.ps
rm -f tmp___005.ps

# rename
mv tmp___005.epsi $outfile
rm -f tmp___005.epsi


