#!/bin/sh

#    Dec 04/06 - F.Majaess

#id nogo_asis - creates binary executable(s) from ".../source_asis/lspgm_asis"
#               source code.

#    AUTHOR  - F.Majaess

#hd  PURPOSE - "nogo_asis" invokes standard "nogo" script on targeted program
#hd            source code residing under $CCRNSRC/source_asis/lspgm_asis 
#hd            subdirectory.
#hd            Please refer to "nogo" documentation for the full list of 
#hd            switches (such as: lib,sublib,modver,list,nopack,
#hd                               openmp,float1,float2...)
#hd            allowed besides the ones described below.

#pr  PARAMETERS:
#pr 
#pr    POSITIONAL
#pr 
#pr        fil  = name of program(s) (".f" extension included) accessible from
#pr               $CCRNSRC/source_asis/lspgm_asis to generate executable for.
#pr               (=all; generate executable for every ".f" program source code
#pr                      residing under $CCRNSRC/source_asis/lspgm_asis 
#pr                      subdirectory).
#pr 

#ex  EXAMPLES:
#ex 
#ex   1) nogo_asis all
#ex 
#ex      The above example leads to generating the corresponding executable
#ex      (in the default mode) for each ".f" program entry found in 
#ex      $CCRNSRC/source_asis/lspgm_asis subdirectory.
#ex 
#ex   2) nogo_asis progx.f float2 list
#ex 
#ex      The above example generates "progx" executable in 64-bits real/integer
#ex      mode from "$CCRNSRC/source_asis/lspgm_asis/progx.f" program source code.
#ex 

Prog_list=" "
Nogo_dirctv=" "
unset Prog_list Nogo_dirctv
for arg in $@
do
  case $arg in
       all) if [ -n "$Prog_list" ] ; then
             echo "nogo_asis: the program list consisting of: "
             echo "           $Prog_list " 
             echo "           since the overriding keyword 'all' is specified"
            fi
            Prog_list='ALL' ;;
       *.f) if [ "$Prog_list" != 'ALL' ] ; then
             Prog_list="$Prog_list $arg" 
            else
             echo "nogo_asis: $arg is ignored since the overriding keyword 'all' is specified"
            fi;;
         *) Nogo_dirctv="$Nogo_dirctv $arg" ;;
  esac
done
if [ "$Prog_list" = 'ALL' ] ; then
 Cwd=`pwd`
 cd $CCRNSRC/source_asis/lspgm_asis
 Prog_list=`echo *.f`
 cd $Cwd
 echo "nogo_asis: 'all' keyword is specified; the list of programs consists of:"
 echo "           $Prog_list"
fi
Exit_code='0'
if [ -n "$Prog_list" -a "$Prog_list" != '*' ] ; then
  for prg in $Prog_list
  do
   if [ -s "$CCRNSRC/source_asis/lspgm_asis/$prg" ] ; then
    Abs=`echo $prg | sed -e 's/\.f$//g'`
    echo "nogo_asis: Attempting Generation of --> $Abs <-- executable from --> $prg <-- program source code" 
    nogo a=$Abs $Nogo_dirctv input=$CCRNSRC/source_asis/lspgm_asis/$prg && Exit_codex="$?" || Exit_codex="$?"
    if [ "$Exit_codex" != '0' ] ; then
     echo "nogo_asis: Problem detected in nogo in generating --> $Abs <-- executable from --> $prg <-- program source code"
     if [ "$Exit_code" = '0' ] ; then
      Exit_code="$Exit_codex"
     fi
    fi
   else
    echo "nogo_asis: Invalid --> $CCRNSRC/source_asis/lspgm_asis/$prg <-- target program source!"
    Exit_code='1'
   fi
  done
else
 echo "nogo_asis: Sorry, you must specify a valid list of '.f' program(s) target source code!"
 Exit_code='2'
fi
exit $Exit_code
