# The line above is intentionally blank #+ # Name: # ndf2gif # Purpose: # Converts an NDF into a GIF file. # Type of Module: # Bourne shell script # Usage: # ndf2gif in [out] # Description: # This Bourne shell script converts an NDF into a 256 grey-level # Graphics Interchange Format (GIF) file. One- or two-dimensional # images can be handled. The script uses the CONVERT utility # NDF2TIFF to produce a TIFF file and then various PBMPLUS utilities # to convert the TIFF file into a GIF file. # # Error messages are converted into Starlink style (preceded by !). # Parameters: # IN = NDF (Read) # The name of the input NDF (without the .sdf extension). # OUT = FILENAME (Write) # The name of the GIF file to be generated (without the .gif # extension which is appended). If this is omitted, the value of # the IN parameter is used. # Examples: # ndf2gif old new # This converts the NDF called old (in file old.sdf) # into a GIF file new.gif. # ndf2gif horse # This converts the NDF called horse (in file old.sdf) # into a GIF file horse.gif. # Notes: # - This initial version of the script handles only 256 grey # levels and does not use the image colour lookup table so # absolute data values may be lost. # # - The PBMPLUS utilities tifftopnm and ppmtogif must be available # on your PATH. # - At the time of writing, this utility uses a special Netpbm version # of tifftopnm on alpha OSF/1 due to a problem with tifftopnm in the # standard release of PBMPLUS. Netpbm is based on PBMPLUS but # contains many improvements and additions. # Related Applications: # CONVERT: GIF2NDF # Authors: # MJC: Malcolm J. Currie (STARLINK) # GJP: G.J. Privett (Starlink - UWCC) # AJC: A.J. Chipperfield (Starlink - RAL) # {enter_new_authors_here} # History: # 1995 March 2 (MJC): # Original conversion. # 1995 October 24 (GJP): # Added prologue and revised to avoid using KAPPA. # 1995 November 13 (AJC): # Added default output file, and error reporting and exit at each # stage. # 1997 July 15 (MJC): # Used a special tifftopnm for alpha_OSF1. # 1997 October 3 (MJC): # Improved the parameter handling to allow for no arguments, and # to remove any .sdf that may be present in the first argument. # Fixed bug that gave incorrect extraction of the base name. #- # Check that a file name was given. if [ "$#" -eq 0 ] then echo "!! NDF2GIF: no NDF name supplied" echo "! Usage: ndf2gif in [out]" exit fi # Remove any .sdf file extension. root=`echo $1 | sed 's#.sdf##'` # Find the filename less any path. name=`basename $root` # Set required output file name. Defaults to the input name. out=${2:-$name} # Determine whether the operating system is alpha_OSF1 or not. machine=`uname -m` opsys=`uname` # Use NDF2TIFF to create a TIFF file. Only the DATA component is # propagated. $CONVERT_DIR/ndf2tiff in=$root out=convert_temp_$name \ &1 | \ sed 's/^\!\!/\! /' | \ awk \ 'BEGIN{err=0}\ /^\!/{if(err==0){err=1;print "!! NDF2GIF: Error reports from NDF2TIFF"}};\ {print};\ END{if(err==1){exit 1}}' || \ (rm -f convert_temp_$name.tif echo "! NDF2GIF: Abandoned at NDF2TIFF" exit 1 ) || exit 1 # Use PBMPLUS tools to convert the TIFF file to a GIF image (except # use the Netpbm version of tifftopnm on alpha_OSF1 because of a bug # in the released PBMPLUS version). if test "$machine" = "alpha" -a "$opsys" = "OSF1" then $CONVERT_DIR/tifftopnm convert_temp_$name.tif 2> convert_err1_$name.lis | \ ppmtogif 2> convert_err2_$name.lis > ${out}.gif || \ { sed 's/^/! NDF2GIF:/' convert_err?_$name.lis 1>&2 rm -f convert_err?_$name.lis convert_temp_$name.tif exit 1 } else tifftopnm convert_temp_$name.tif 2> convert_err1_$name.lis | \ ppmtogif 2> convert_err2_$name.lis > ${out}.gif || \ { sed 's/^/! NDF2GIF:/' convert_err?_$name.lis 1>&2 rm -f convert_err?_$name.lis convert_temp_$name.tif exit 1 } fi rm -f convert_err?_$name.lis rm -f convert_temp_$name.tif