################################################################################
##                                                                            ##
##                                                                            ##
##  file:         procnaif                                                    ##
##  description:  merge the newest Galileo SSI camera/platform                ##
##                kernels with the type 3 merged ck.                          ##
##  author:       Janet Barrett                                               ##
##  history:      2001 Dec 13  JBB - Flagstaff AZ - original version          ##
##                2002 May 16  K Teal Thompson - add documentation            ##
##                	and automate soft linking $ISISGALDATA/ck*.plt        ##
##                	files and listing into the plt.lst file for rest      ##
##                	of script                                             ##
##                2003 Jun  3  Debbie A. Cook - Made the following            ##
##                	revisions to the procedure:                           ##
##                 	  1) Attempt to delete processing files from previous ##
##			     run 					      ##
##                 	  2) Split the list of all Galileo ck into a type 1   ##
##			     list  					      ##
##                    	     and a type 3 list (type1.lst and type3.lst).     ##
##                 	  3) First concatenate only the type 1 ck into single ##
##                    	     daf (type1.plt)                                  ##
##                 	  4) ckmerge only the type 1 ck (type1.plt) into a    ##
##			     type 3 ck with a tolerance of 200000	      ##
##			     (type1merged.plt)      			      ##
##                 	  5) Concatenate (dafcat) the list of type3 ck and    ##
##			     the newly converted type1merged.plt into a	      ##
##			     single file CKmerge.plt                          ## 
##                 	  6) Create a comment file and add comments to	      ##
##			     CKmerge.plt                                      ##
##		  2007 Nov 02 - Jac Shinaman - Made the following revisions   ##
##			to the procedure:                                     ##
##			  1) the output of the script is now CKmerge_type3.plt##
##			     instead of CKmerge.plt.			      ##
##			  2) "ckspanit" and "dafcat" are no longer availble   ##
##                           in the NAIF release, therefore you must download ##
##			     these programs from the appropriate platform     ##
##			     specific directory on the NAIF public ftp site   ##
##			     (naif.jpl.nasa.gov/pub/naif/utilities) and put   ##
##			     them in your working directory.  The script has  ##
##			     been modified to look for the programs there.    ##
##			  3) "commnt" has a bug in it that prevents it from   ##
##			     being run in command line mode.  Therefore, it   ##
##			     is now necessary to run it manually at the end   ##
##			     of this script run.  Use the cmt.txt and	      ##
##			     CKmerge_type3.plt files as input to the program. ##
##_$Id: procnaif,v 1.2 2007/11/02 23:33:13 jshinama Exp $
################################################################################
#                                                                              #
# 1]  Create and/or move to an empty directory on each operating system needed,#
#     for your work area.  Move this script and the NAIF programs "ckspanit"   #
#     and "dafcat" to this work area.  This step and step 2 need to be done by #
#     the user prior to running this script.                                   #
#                                                                              #
# 2]  Copy the new Galileo SSI camera/platform kernels into $ISISGALDATA.      #
#     Kernels no longer need to be binary versions for the operating system on #
#     which you are working.  The script performs the remaining steps.         #  
#                                                                              #
# 3]  Link current Galileo SSI camera/platform kernels from ISIS system into   #
#     this directory and remove any old merged kernels.			       #
#                                                                              #
ln -s $ISISGALDATA/ck*.plt .
echo
echo " Removing any existing .plt and .lst files from previous runs ..."
echo
/bin/rm CKmerge_type3.plt plt.lst type1.lst type3.lst type1.plt
/bin/rm type1totype3.plt all3.lst cmt.txt temp.txt
#                                                                              #
# 4]  Create a list of all Galileo SSI ck/platform kernels                     #
#                                                                              #
unalias ls
ls ck*.plt > plt.lst
#                                                                              #
# 5]  Split the list of all Galileo ck/platform kernels into a type 1 list     #
#     and a type 3 list (type1.lst and type3.lst). 
#                                                                              #
splitcklist  plt.lst type1.lst type3.lst
#                                                                              #
# 6]  Concatenate only the type 1 ck into single daf file (type1.plt)          #
#                                                                              #
./dafcat type1.plt < type1.lst                                 
#                                                                              #
# 7]  Convert only the type 1 ck (type1.plt) into a type 3 ck with a           #
#     tolerance of 200000 (type1totype3.plt) for the interpolations.           #
#                                                                              #
./ckspanit -in type1.plt -out type1totype3.plt -tol 200000
#                                                                              #
# 8]  Add the new type 3 file, type1totype3.plt, to type3.lst and              # 
#     concatenate (dafcat) the entire set of type 3 ck into a single file      #
#     CKmerge_type3.plt                                                        # 
#                                                                              #
ls -1 type1totype3.plt | cat - type3.lst > all3.lst                            #
./dafcat CKmerge_type3.plt < all3.lst
#                                                                              #
# 9]  Create a comment describing the contents of the new file,                #
#     CKmerge_type3.plt, and write it to the file                              #
#                                                                              #
echo "tolerance of 200000" | cat - type1.lst > temp.txt
echo "with datcat, and converted to type3 with ckspanit, with a" | cat - temp.txt > cmt.txt
/bin/rm temp.txt
echo "CONTENTS:  This file contains the following type 1 ck concatenated" | cat - cmt.txt > temp.txt
/bin/rm cmt.txt
date | cat - temp.txt > cmt.txt
/bin/rm temp.txt
echo "FILE_CREATION_DATE:  \c" | cat - cmt.txt > temp.txt
/bin/rm cmt.txt
echo "FILE_NAME:  CKmerge.plt" | cat - temp.txt > cmt.txt
/bin/rm temp.txt
cat cmt.txt type1.lst > temp.txt
/bin/rm cmt.txt
echo "        In addition the following type 3 ck were concatenated" | cat temp.txt - > cmt.txt
/bin/rm temp.txt
echo "        with dafcat." | cat cmt.txt - > temp.txt
/bin/rm cmt.txt
cat temp.txt type3.lst > cmt.txt
/bin/rm temp.txt ck*.plt type* all3.lst plt.lst
echo
echo " CKmerge_type3.plt and cmt.txt are now ready to be run through commnt"
echo 
#                                                                              #
# 10] The new file, CKmerge_type3.plt, is ready for the ISISGALDATA area       #
#_END                                                                          #
################################################################################











