[Thread Prev][Thread Next][Index]
Re: small graphics in Ferret
Mario Germano wrote:
In reply to Billy Kessler, it is also possible (and more straightforward) to
use the -batch option, to produce a postscript file:
for instance:
> ferret -batch filename.ps
> yes? ....all your plot commands ....
> quit
Mario
Hi all,
I have attached a script called ps2gif to transfom ps to gif at a
specified size.
My favorite combinaison of commands is then:
ferret -server -batch file.ps -script file.jnl arg1 arg2
ps2gif -v -g 200xc file.ps
You have then produced a gif image of 200 pixels width and a height set
by the ratio you have decided when used the command yes?set
window/aspect=ratio
Note, that you will have to modify pageheight and pagewidth according to
the ratio set.
Hope that can help
Patrick
#!/bin/ksh
#
# Author: Patrick Brockmann
# Contact: Patrick.Brockmann@ipsl.jussieu.fr
# $Date: 2004/09/01 14:05:28 $
# $Name: FAST_570_1_0 $
# $Revision: 1.1.1.6 $
# History:
# Modification:
#
#---------------------------------------------
geometry_tocalculate='x'
geometry_size=800
rotate_command='none'
verbose=0
option_outputname=0
#---------------------------------------------
# pageheight and pagewidth values of the postscript file are obtained from following command:
# gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -sOutputFile=- file.ps | pnmcrop | pnmfile
# They reflect the ratio set by the command set window/aspect
# The following values reflect the A4 ratio ie 210/296 set by
# the scrip page_new whitch uses the line set window/aspect=`296/210`
pageheight=540
pagewidth=384
#---------------------------------------------
while [ $# -ne 0 ]
do
case $1 in
-h|--help|-help)
echo "----------------------------------------------------------------------------"
echo "Usage: ps2gif [-v] [-h] [-g {xsize}x{ysize}] [-o fileout.gif] filein.ps"
echo
echo "Description:"
echo " Convert a postscript file to a gif image file."
echo
echo " Here is a typical ferret script:"
echo " go page_new 1 1"
echo " set viewport 1"
echo " use levitus_climatology"
echo " shade temp[k=1]"
echo " exit"
echo " The postscript will be generated with:"
echo " ferret -server -batch ex.ps < ex.jnl"
echo " The gif image will be generated with:"
echo " ps2gif -o ex.gif ex.ps"
echo
echo " ps2gif is a shell script based on gs from http://www.cs.wisc.edu/~ghost,"
echo " pnmfile, pnmcrop, pnmflip from http://netpbm.sourceforge.net/ and"
echo " convert d'ImageMagick from http://www.imagemagick.org/."
echo
echo " The postscript is converted with gs to a pnmraw 24 bits image."
echo " Then, the pnmraw 24 bits image is converted to a 8 bits gif image"
echo " using convert (compiled with the --enable-lzw=yes option)."
echo
echo " ps ------> pnmraw -----------> pnmraw -----------> gif"
echo " (gs) (pnmcrop) (convert)"
echo " (pnmflip)"
echo
echo "Arguments:"
echo " filein.ps: Postscript file must have .ps in name."
echo
echo "Options:"
echo " -h, --help, -help"
echo " Print this manual."
echo
echo " -v, --verbose"
echo " Informations are printed on standard output."
echo
echo " -g, --geometry"
echo " Examples:"
echo " -g cx800 for a portrait postscript (go page_new ...)"
echo " defining a height of 800 pixels and"
echo " a width calculated following the A4 page size ratio."
echo " -g 800xc for a landscape postscript (go page_new -l ...)"
echo " defining a width of 800 pixels and"
echo " a height calculated following the A4 page size ratio."
echo " Default is -g cx800"
echo
echo " -o, --output fileout.gif"
echo " The name of the output gif file"
echo " Default name is built by replacing .ps extension by .gif"
echo " from the input ps file"
echo
echo "----------------------------------------------------------------------------"
exit ;;
-g|--geometry)
geometry_xsize=`echo $2 | cut -dx -f1`
geometry_ysize=`echo $2 | cut -dx -f2`
if [ $geometry_xsize = 'c' ] ; then
geometry_tocalculate='x'
geometry_size=$geometry_ysize
rotate_command='none'
elif [ $geometry_ysize = 'c' ] ; then
geometry_tocalculate='y'
geometry_size=$geometry_xsize
rotate_command='pnmflip -r270'
fi
shift 2 ;;
-o|--output)
option_outputname=1
fileout=$2
shift 2 ;;
-v|--verbose)
verbose=1
shift ;;
-*)
ps2gif -h
exit ;;
*)
break ;;
esac
done
if [ $# -ne 1 ] ; then
ps2gif -h
exit
fi
if [ $option_outputname -eq 0 ] ; then
fileout=`basename $1 .ps`.gif
fi
#---------------------------------------------
function PRINT {
if [ $verbose -eq 1 ] ; then
echo "$1"
fi;
}
#---------------------------------------------
filein=$1
PRINT "*********************************"
PRINT "ps2gif informations"
case $geometry_tocalculate in
'x')
PRINT "y geometry set; x geometry calculated"
ysize=${geometry_size}
xsize=`echo "${ysize} ${pagewidth} ${pageheight}" | awk '{printf("%.0f\n", $1*$2/$3)}'`
xresol=`echo "${xsize} ${pagewidth}" | awk '{printf("%.3f\n", 72*$1/$2)}'`
yresol=`echo "${ysize} ${pageheight}" | awk '{printf("%.3f\n", 72*$1/$2)}'`
PRINT "xsize=${xsize} ysize=${ysize}"
PRINT "xresol=${xresol} yresol=${yresol}" ;;
'y')
PRINT "x geometry set; y geometry calculated"
xsize=${geometry_size}
ysize=`echo "${xsize} ${pagewidth} ${pageheight}" | awk '{printf("%.0f\n", $1*$2/$3)}'`
xresol=`echo "${xsize} ${pageheight}" | awk '{printf("%.3f\n", 72*$1/$2)}'`
yresol=`echo "${ysize} ${pagewidth}" | awk '{printf("%.3f\n", 72*$1/$2)}'`
PRINT "xsize=${xsize} ysize=${ysize}"
PRINT "xresol=${xresol} yresol=${yresol}" ;;
esac
if [ "$rotate_command" != 'none' ] ; then
PRINT "gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -r${xresol}x${yresol} -sOutputFile=- $filein | pnmcrop | $rotate_command | convert - $fileout"
(gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -r${xresol}x${yresol} -sOutputFile=- $filein | pnmcrop | $rotate_command | convert - $fileout) > /dev/null 2>&1
else
PRINT "gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -r${xresol}x${yresol} -sOutputFile=- $filein | pnmcrop | convert - $fileout"
(gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -r${xresol}x${yresol} -sOutputFile=- $filein | pnmcrop | convert - $fileout) > /dev/null 2>&1
fi
PRINT "*********************************"
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement