#!/bin/csh
##
##

if !(-e fichier3d.data && -e fichier2d.data) then
   echo "ERREUR : Les fichiers de base fichier2d.data ou fichier3d.data sont manquants"
   exit 1
endif

##
## La syntaxe de la commande:
##

if ($# <9 | $# > 9 |"$1" == "-h" | "$1" == "-help") then
    echo ""
    echo "     usage: $0 p1 p2 p3 p4 p5 p6 p7 p8 nom_du_maillage_amdba"
    echo ""
    echo "p1 : nombre de sommets sur (0,0,0)-(0,11mm,0) et meme nombre sur (0,13mm,0)-(0,24mm,0)"
    echo "p2 : nombre de sommets sur (0,11mm,0)-(0,13mm,0)"
    echo "p3 : nombre de sommets sur (0,0,0)-(0,0,2mm)"
    echo "p4 : nombre de sommets sur (0,0,2.1mm)-(0,0,10.1mm)"
    echo "p5 : nombre de sommets sur (0,0,10.2mm)-(0,0,14.2mm)"
    echo 'p6 : nombre de sommets "colle en haut"'
    echo 'p7 : nombre de sommets "colle en bas"'
    echo "p8 : nombre de couches d'lments dans l'axe des x"
    echo "nom_du_maillage_amdba: ben... le nom..."
    exit 1
endif

if(-e $9) then
  echo "ERREUR : Le fichier existe deja, pas de destruction"
  exit 1
endif

rm -f mail2d.data mail3d.data run_apnoxx run_apn3xx run_interf run_trnoxx

echo "\!NP="$1 > mail2d.data
echo "\!NP1="$2 >> mail2d.data
echo "\!NP2="$3 >> mail2d.data
echo "\!NP3="$4 >> mail2d.data
echo "\!NP4="$5 >> mail2d.data
echo "\!NCH="$6 >> mail2d.data
echo "\!NCB="$7 >> mail2d.data
cat fichier2d.data >> mail2d.data
echo "e" > run_apnoxx
echo "mail2d.data" >> run_apnoxx
echo "F" >> run_apnoxx
./apnoxx < run_apnoxx > /dev/null
if(-e mail2d.nopo) then
  echo "\!NCOUCHES="$8 > mail3d.data
  cat fichier3d.data >> mail3d.data
  echo "e" > run_apn3xx
  echo "mail3d.data" >> run_apn3xx
  echo "F" >> run_apn3xx
  ./apn3xx < run_apn3xx > /dev/null
endif
if(-e mail3d.nopo) then
  echo "mail3d.nopo" > run_interf
  echo "2" >> run_interf
  echo "$9.amdba" >> run_interf
  interf < run_interf > /dev/null
  permute $9.amdba
  mv $9.amdba.permute $9
endif

if(-e mail2d.nopo) then
  echo "Conserver les nopo pour visualisation avec trnoxx? (o/n)"
  set REPONSE=$<
  if ( $REPONSE != "o" ) rm *.nopo
endif

rm mail2d.data mail3d.data run_apnoxx run_apn3xx run_interf $9.amdba

if( -e $9) then
   echo "Tout est OK fichier $9 cree"
else
   echo "ERREUR : Probleme lors de la creation de $9"
endif

