#!/usr/bin/env bash
#
# $Id$
#
#
# modified to use the perl version to change back to the sed scripts
#
if [[ -z "${NWCHEM_TOP}" ]]; then
    DIRUTIL=`dirname "$0"`
    MYPWD=`pwd`
    NWCHEM_TOP=`echo ${MYPWD}/${DIRUTIL} | sed -e 's/\/src.*//' `
fi
  if [ -x /msrc/apps/bin/perl ]; then
      perlexe=/msrc/apps/bin/perl
  elif [ -x /usr/local/bin/perl ]; then
      perlexe=/usr/local/bin/perl
  elif [ -x /usr/local/gnu/bin/perl ]; then
      perlexe=/usr/local/gnu/bin/perl
  elif [ -x /usr/gnu/bin/perl ]; then
      perlexe=/usr/gnu/bin/perl
  else
# assume perl is in your path
      perlexe=perl
  fi
   perlscript=${NWCHEM_TOP}/src/config/64_to_32.pl


 JOB_LIMIT=6

 njob=0

for file in "$@"
do
if [ -f "$file" ]; then
   echo converting "$file" to 32-bit integers for BLAS/LAPACK
      ($perlexe $perlscript $file) &	

   let njob++
   if [ $njob -gt $JOB_LIMIT ]; then
     wait
     let njob=0
   fi
fi
done

if [ $njob -gt  0 ] ; then
    wait
fi
