#!/bin/ksh
set -x
USAGE="usage: reducemap  INFILE  prntr ssnos"
VERS="${USHutil}/${member} 2005-12-07 13:05L"
set +x
#______________________________________________________________________________
# NAME     : reducemap
# Author   : Peter Henrichsen
# Purpose  : This script is called to convert a NMC 6-bit packed chart
#          : into HP printable format.
#          : It calls program graph_fxcompoz to decode the NMC 6-bit packed 
#          : chart into pure-raster format. 
#          : Then calls program graph_dispuras converts the pure-raster file
#          : into a pcl file.
#          : This pcl file is then sent to an 8X11 HP printer in the WWB!             
#
#          : 
# History  : 99-02-03 Peter Henrichsen
#          : 1999-12-01 Peter Henrichsen modify to run on ncosp
#          : 1999-12-14 Peter Henrichsen modify to call script print_pcl
#          : to send the compled pcl file to the printers via dbnet.
#          : 2000-01-28 Peter Henrichsen modify change "job" to lower case
#            fix errors in script.
#          : 2000-02-09 Peter Henrichsen modify script to remove "graph_"
#            from graph_fxcompoz and graph_dispuras
#          : 2005-12-07 Steve Lilly modify script to remove the call to script
#            print_pcl and to remove HPC precp chart from the stat file.
#
#
# Usage    : This script is run after a nmc6bit FAX file has been made
#
#
#               Arg1 is   Arg3 is     Arg2 is
# reducemap     nmc6bit   the printer subset
#               file name name        numbers    
#
#  AN EXAMPLE:
#
# reducemap  /tmp/foreign/fax/sixtenfax.${PDY} 3220 hplj-ad3
#       where:
#	      "/tmp/foreign/fax/sixtenfax.${PDY}" is the fax file full-path.
#
#             "3220" is the fax subset number.
#
#             "hplj-ad3" is the print name 
#            
#
#
#  Remarks : This script assumes that the following values have been exported
#            by the parent shell:
#            
#            jlogfile jobid pid pgmout
#            reqid utilities xc
#
#            DATA EXECforgn EXECgraph sutilities job   
#            
#                     
 
#_______________________________________________________________________________

#   check to see if $DATA is missing

   if [ -z "$DATA" ] ; then
   DATA=/tmp/fntest
    mkdir -m 755 -p $DATA >/dev/null 2>&1

    export DATA
   fi

cd $DATA
  RMDATA=NO 
 export RMDATA    
  print "$VERS"

echo Number of arguements passed in is $#

for arg in "$@"
do  
   echo $arg
done
integer   istat
integer   kstat
 
INFILE="$1"
subnums="$3"
export subnums INFILE    

NUMARG=$#

prntr="$2"
 
export prntr 
if [[ -a $INFILE ]]
then
#   ... NMC 6bit packed file exists ...
  print     "Given NMC6bitpacked = $INFILE "
 
# Start loop to print the small fax cuts!!!!
set -x
num=0
numsec=45
for subnn in $subnums 
do
 msgs="${member} getting nmc6bit map # $subnn from $filename!"
postmsg "$jlogfile" "$msgs" 
 
INFILEras=ras.$pid
INFILEcrd=crd.$pid
INFILEpcl=pcl.$subnn.$pid

parmsg="ssno="$subnn


pgm=fxcompoz
export pgm; prep_step

export XLFRTEOPTS="unit_vars=yes"

export XLFUNIT_66="$INFILEras"          # in cards
export XLFUNIT_67="$INFILEcrd"          # out card
export XLFUNIT_75="$DATA/fxcompoz.$subnn.msg.$pid" # the consol message file.

  startmsg
  
  $EXECutil/fxcompoz $INFILE \
       parm=$parmsg  2>> errfile
       istat=$?
        echo ${pgm}: Ended with return code = $istat
        if test "$istat" = 0
        then
         err=$?;export err; err_chk        
   

      print      " . . . . . . no errors."
      ls -l $INFILE
      ls -l $INFILEras
      ls -l $INFILEcrd


 pgm=dispuras
export pgm
export pgm; prep_step


len=`cut -c37-40 $INFILEcrd`

parmcut="lrecl=216,byskp=0,byshw=216,lands=1,lnskp=0,lnshw="$len",dotpi=200,swaby=0,nogrd=1"


export XLFRTEOPTS="unit_vars=yes"
export XLFUNIT_75="$DATA/dispuras.$subnn.msg.$pid"  # the consol message file.

startmsg
$EXECutil/dispuras $INFILEras $DATA/$INFILEpcl \
        parm=$parmcut  2> errfile
       
       kstat=$?
       echo ${pgm}: Ended with return code = $kstat
        if test "$kstat" = 0
        then
         err=$?;export err; err_chk        
         export prntr
          export member=print_pcl
     
          export ifid=`grep -i Faxmap $DATA/fxcompoz.$subnn.msg.$pid \
          | awk '{for(i=5;i<=NF;i++) printf("%s ", $i)}'`  
          sndpcl=0
          echo $sndpcl >$DATA/sndpcl
# copy the pcl file into pcom
     
          cp $INFILEpcl $pcom/pcl.$subnn.$job 

       fi
      fi
     done
  fi
