#!/bin/bash
#PURPOSE: Extracts the version numbers of the SAXS routines
#VERSION: 1.2
#
#saxsversion.mac [<rootdir>]
#
#SAXS_ROOT is default of <rootdir>.
#If rootdir contains the version files E*, P*, V* and R*,
#they are used, if not the files edfpack/E*, saxspack/V*, 
#rocapackR* and src/P* are used
#

#AUTHOR: P. Boesecke

  if [[ ($# -eq 1) ]]; then
    SROOT=$1
  else
    SROOT=${SAXS_ROOT}
  fi

  cd ${SROOT}
  SROOT=`pwd`

# The following expressions works on bash command line but not in this script
#  if [[ (-f `ls -1 ${SROOT}/E*([0-9]).[0-9][0-9][0-9]?([w]) 2>>/dev/null`) ]]; then
  if [[ (-f `ls -1 ${SROOT}/E*.* 2>>/dev/null`) ]]; then
    if [[ (-f `ls -1 R*`) ]]; then
      SVERSION="`ls -1 V*``ls -1 P*.*``ls -1 E*.*``ls -1 R*.*`"
    else
      SVERSION="`ls -1 V*``ls -1 P*.*``ls -1 E*`"
    fi
    SVERSION="${SROOT}_$SVERSION"
  else

    if [[ (-d "${SROOT}/saxspack") ]]; then
      cd  "${SROOT}/saxspack/"
      SVERSION="`ls -1 V*`"
    fi

    if [[ (-d "${SROOT}/src") ]]; then
      cd  "${SROOT}/src/"
      SVERSION="${SVERSION}`ls -1 P*`"
      cd ..
    fi

    if [[ (-d "${SROOT}/edfpack") ]]; then
      cd "${SROOT}/edfpack/"
      SVERSION="${SVERSION}`ls -1 E*`"
      cd ..
    fi

    if [[ (-d "${SROOT}/rocapack") ]]; then
      cd  "${SROOT}/rocapack/"
      SVERSION="${SVERSION}`ls -1 R*`"
      cd ..
    fi

    SVERSION="${SROOT}_$SVERSION"

  fi

echo ${SVERSION}
