#!/bin/csh -f
#
#	Script by CAO for converting a named PS files into PNG files
# 
echo " $#argv $argv[0] "
foreach FIGURE ($argv)
    echo "Figure to process is: ${FIGURE}"
    if ( !-e ${FIGURE} ) goto "skip"
    echo "Figure exists"
    if ( !-w ${FIGURE} ) goto skip
    echo "We have write permission" )
    If ( ${FIGURE}:e != "ps" )  goto skip
    echo "Figure is a PostScript file"
    set NEWFILE = ${FIGURE:r}.png
    echo ${NEWFILE}
    gs -q  -dNOPAUSE -sDEVICE=png256 -sOutputFile=${NEWFILE} -dBATCH ${FIGURE}
    if ( -e ${NEWFILE} ) then
        echo "PNG file successfully created: ${NEWFILE}"
        rm ${FIGURE}
    endif
    skip:
    "Continuing with next file"
end
