# The line above is intentionally blank #+ # Name: # gif2ndf # Purpose: # Converts a GIF-format file into an NDF # Type of Module: # Bourne shell script # Description: # This Bourne-shell script converts a Graphics Interchange Format # (GIF) file into an unsigned-byte (256 grey-level) NDF format file. # It handles one- or two-dimensional images. The script uses # various PBMPLUS utilities to produce a FITS file, flipped top # to bottom, and then FITS2NDF to produce the final NDF. Error # messages are converted into Starlink style (preceded by !). # Usage: # gif2ndf in [out] # Parameters: # IN = FILENAME (Read) # The name of the GIF file to be converted (without the .gif extension # which is assumed). # OUT = NDF (Write) # The name of the NDF to be generated (without the .sdf extension). # If the OUT parameter is omitted, the value of the IN parameter # is used. # Examples: # gif2ndf old new # This converts the GIF file old.gif into an NDF called new # (in file new.sdf). # gif2ndf horse # This converts the GIF file horse.gif into an NDF called horse # (in file horse.sdf). # Related Applications: # CONVERT: NDF2GIF # Notes: # This initial version of the script generates images with at most # 256 grey levels. It does not use the image colour lookup table. # # Input image filenames must have the extension .gif. # # The PBMPLUS utilities giftopnm, ppmtopgm and pgmtofits # must be available on your PATH. # Authors: # MJC: Malcolm J. Currie (STARLINK) # GJP: G.J.Privett (Starlink - UWCC) # AJC: A.J.Chipperfield (Starlink - RAL) # {enter_new_authors_here} # History: # 28-NOV-1995 (AJC): # Original version, based on work by MJC and GJP. # 1997 August 1 (MJC): # Removed KAPPA dependencies. Reworded and reordered the # description. Added some comments. # 1997 October 3 (MJC): # Improved the parameter handling to allow for no arguments, and # to remove any .gif that may be present in the first argument. # {note_further_changes_here} # Bugs: # {note_any_bugs_here} #- # Check that a file name was given. if [ "$#" -eq 0 ] then echo "!! GIF2NDF: no GIF name supplied" echo "! Usage: gif2ndf in [out]" exit fi # Remove any .gif file extension. root=`echo $1 | sed 's#.gif##'` # Find the filename less any path. name=`basename $root` # Set required output file name. Defaults to the input name. out=${2:-$name} # Convert the image removing temporary files at each stage. The PMBPLUS # utilities giftopnm, ppmtopgm and pgmtofits must be available on your # path. # # Convert image from GIF format to FITS, flipping it from top to bottom. # The error output is written to temporary files. Make the error look # as if it came from MSG. giftoppm ${root}.gif 2> convert_err1_$name.lis | \ ppmtopgm 2> convert_err2_$name.lis | \ pnmflip -topbottom 2> convert_err3_$name.lis | \ pgmtofits 2> convert_err4_$name.lis > convert_temp_$name.fit || \ { sed 's/^/! GIF2NDF:/' convert_err?_$name.lis 1>&2 rm -f convert_err?_$name.lis convert_temp_$name.fit exit 1 } rm -f convert_err?_$name.lis # Convert the image to an NDF of data type _UBYTE. Make the error look # as if it came from MSG, so as this is a secondary error report, # replace the !! prefix with !. $CONVERT_DIR/fits2ndf in=convert_temp_$name.fit out=$out fmtcnv=t \ &1 | \ sed 's/^\!\!/\! /' | \ awk \ 'BEGIN{err=0}\ /^\!/{if(err==0){err=1;print "!! GIF2NDF: Error reports from FITS2NDF"}};\ {print}\ END{if(err==1){exit 1}}' || \ (rm -f convert_temp_$name.fit echo "! GIF2NDF: Abandoned at FITS2NDF" exit 1 ) || exit 1 rm -f convert_temp_$name.fit