#/bin/csh -f
#
# Shell script to compress product labeled with ${ts}.  The extent is removed, 
# gzip'd and then the time tag added back up
if( $#argv == 0 ) then
   echo "Usage: sh_gzip_ts <time tag>"
   echo "where <time tag> is PBO processing timetag.  The time tag is removed, file gzip'd and tag added back"
   echo "    Maps nmt17444.final_nam08.snx.20131029153227 to nmt17444.final_nam08.snx.gz.20131029153227"
   echo " "
   exit
endif
#
# See how many files
set ts = $1
set files = `ls *.${ts}`
# Loop over files
foreach f ( $files )
   set tarfile = `echo $f | grep tar | awk '{if ( NR > 0 ) {print "TAR"}}'`
   if( $tarfile != "TAR" ) then 
     set root = $f:r
     if( $f:r:e != 'gz' ) then   # Make sure not already compressed
         mv $f $root 
         gzip -f $root
         \mv ${root}.gz ${root}.gz.${ts}
     else
         echo "$f already gzipd"
     endif
   else
       echo "$f is a tar file: No gzip"
   endif
end
echo "$#files files tested with tag ${ts}"

    
