:
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


#* $Date:   22 Mar 1999 09:31:46  $
#* $Modtime:   22 Mar 1999 09:30:32  $

# ***********************************************
# $Workfile:   kxaltsort.sh  $ $Revision:   1.0  $
# ***********************************************

#*
#* $Log:   /home/prodsup/daved/unikix/warn6.0.0.0/unikixsrc/vsam/utilities/PVCS/kxaltsort.shv  $
#
#   Rev 1.0   22 Mar 1999 09:31:46   daved
#Initial 6.0
#
#   Rev 1.5   15 Mar 1999 13:26:08   giulio
#B3727
#force usage of $TMPDIR if defined for sortx temporary files. If not defined
#defaults to /tmp. For NT we always ask user for TMPDIR setting and eventually
#we default to c:/temp.
#
#   Rev 1.4   10 Feb 1999 14:37:38   daved
#Merge 1.2.1.0 and 1.3
#
#   Rev 1.3   26 Jan 1999 14:33:10   prabha
#D003432
#Changed the cobol sort version to SORTX version
#
#   Rev 1.2.1.0   05 Feb 1999 15:56:28   ald
#B003635
#Changed the cobol compile commands for kxalt008, etc. to specify the source
#program to compile. The kxalt008, etc. modules were being built incorrectly
#when the source wasn't specified (no executable code in them).
#
#   Rev 1.2   11/06/97 16:16:10   prabha
#B002524
#Fix to remove the load of kxalt modules from specific directory
#
#   Rev 1.1   06/17/97 14:51:48   rick
#B002161
#The COMMENTPREFIX in PVCS was wrong for this file. Caused an error
#( or apparent error ) when running the file as a shell script.
#  
#     Rev 1.0   05/22/97 17:32:50   unikix
#  Initial 5.1
#
#   Rev 1.2   10/21/96 15:39:52   daved
#Promote revision 1.0.1.1 to the main trunk and remove the revision 1.1
#changes.
#
#   Rev 1.0.1.1   10/21/96 15:37:48   daved
#D001747
#Set COBDIR and COBPATH to $UNIKIX/bin.
#
#   Rev 1.0.1.0   09/23/96 12:55:28   daved
#D001747
#Execute kxalt files directly instead of using cobrun.
#
#   Rev 1.0   04/19/96 14:42:44   unikix
#Initial revision.
#
#   Rev 1.0   12/28/94 15:35:06   unikix
#Initial revision (from V410ad)
#
#   Rev 1.3.1.1   12/05/94 10:20:38   rick
#B000525
#Case 525 - add code to put error out to unikixmain.err when a bad status is
#           returned from the COBOL SORT routines. The bad status is the 
#           MicroFocus runtime error returned by SORT and is displayed in the
#           message.
#
#   Rev 1.3.1.0   11/18/93 18:57:52   unikix
#UniKix 4.1 baseline (from V400m)
#
#   Rev 1.3   08/25/93 12:51:22   alan
#ACCEPT from pipe doesn't work with Micro Focus 3.0
#
#   Rev 1.2   07/13/93 11:25:20   alan
#Start first line with : to allow use with C shell
#
#   Rev 1.1   07/01/93 17:39:34   alan
#Set the Micro Focus sort size to 1M
#*


#-------------------------------------------------------------------------
# *    The following lines were for Cobol version of kxaltsort.
# *    The source programs are still available in $UNIKIX/src/record
#-------------------------------------------------------------------------
# kxaltsort
# call cobol program to perform a sort of the alternate key files
# params: key length, file name containing keys
# run the cobol sort program that matches the size of the alt key file.
#COBSW=-s1000000
#export COBSW
#ALTFILE=$3
#export ALTFILE
#kxalt$2
#-------------------------------------------------------------------------
if [ -z "$TMPDIR" ]
then
  TMPDIR=/tmp; export TMPDIR
fi

SRTFILE=$4.srt; export SRTFILE
sortx -i $4 -o $SRTFILE -t FS -s $2 -m $3M -w $TMPDIR -S stdin <<!
RECORD:
	KEYS=(1 $2)
ENDSORT:
!
returncd=$?
if [ $returncd -ne 0 ]
then 
  echo `date '+%D %H:%M:%S'` 'kxaltsort   :Shell script kxaltsort encountered error during sortx sort, runtime status = ' $returncd >> $KIXSYS/unikixmain.err
  rm -f $SRTFILE
else
  mv $SRTFILE $4
fi
exit $returncd
