# The line above is intentionally blank #+ # Name: # tiff2ndf # Purpose: # Converts a TIFF file into an NDF. # Type of Module: # Bourne shell script # Usage: # tiff2ndf in [out] # Description: # This Bourne-shell script converts a 256 grey-level or # black-and-white dithered Tag Image File Format (TIFF) into an # unsigned-byte NDF 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 !). # Parameters: # IN = FILENAME (Read) # The name of the TIFF file to be converted (without the .tif # 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: # tiff2ndf old new # This converts the TIFF file old.tif into an NDF called old # (in file old.sdf). # tiff2ndf horse # This converts the TIFF file horse.tif into an NDF called horse # (in file horse.sdf). # Notes: # - This initial version of the script handles only greyscale # or b/w dithered images. You are responsible for conversion of # your images to this format prior to use, including the # conversion of RGB values to brightness values. # # - Input image file names must have the extension .tif. # # - The PBMPLUS utilities tifftopnm, ppmtopgm and pgmtofits must # be available on your PATH. # Related Applications: # CONVERT: NDF2TIFF # 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 3 (MJC): # Original version (GIFs). # 1995 November 2 (GJP): # Converted to TIFF requirements from GIF. # 1995 November 13 (AJC): # Added fileout parameter, and error reporting and exit at each # stage. Use long temporary filenames. # 1997 August 1 (MJC): # Removed KAPPA dependencies. Reworded and reordered the # description. Added some comments. Used a special tifftopnm # for alpha_OSF1. # 1997 October 3 (MJC): # Improved the parameter handling to allow for no arguments, and # to remove any .tif that may be present in the first argument. # Bugs: # {note_any_bugs_here} #- # Check that a file name was given. if [ "$#" -eq 0 ] then echo "!! TIFF2NDF: no TIFF name supplied" echo "! Usage: tiff2ndf in [out]" exit fi # Remove any .gif file extension. root=`echo $1 | sed 's#.tif##'` # 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` # Convert the image removing temporary files at each stage. # Convert image from TIFF format to FITS, flipping it from top to bottom. # Use the Netpbm version of tifftopnm on alpha_OSF1 because of a bug # in the released PBMPLUS version. The error output is written to # temporary files. Make the error look as if it came from MSG. if test "$machine" = "alpha" -a "$opsys" = "OSF1" then $CONVERT_DIR/tifftopnm ${root}.tif 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/^/! TIFF2NDF:/' convert_err?_$name.lis 1>&2 rm -f convert_err?_$name.lis convert_temp_$name.fit exit 1 } else tifftopnm ${root}.tif 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/^/! TIFF2NDF:/' convert_err?_$name.lis 1>&2 rm -f convert_err?_$name.lis convert_temp_$name.fit exit 1 } fi 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 "! TIFF2NDF: Abandoned at FITS2NDF" exit 1 ) || exit 1 rm -f convert_temp_$name.fit