#!/bin/csh 
#########################################################################
# COPYRIGHT (C) 2003         EDF R&D              WWW.CODE-ASTER.ORG    #
#                                                                       #
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR         #
# MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS        #
# PUBLISHED BY THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE    #
# LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.                       #
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,       #
# BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF        #
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU      #
# GENERAL PUBLIC LICENSE FOR MORE DETAILS.                              #
#                                                                       #
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE     #
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO : EDF R&D CODE_ASTER,       #
#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.        #
#########################################################################
#
# $Id: as_rex_prof 3261 2008-04-11 11:29:44Z courtois $
#
# as_rex_prof : recopie les fichiers d'un profil d'étude associés à une 
#               fiche REX sur le serveur de reference 
#
if ($#argv != 2) then
  echo usage : as_rex_prof fichier_profil nra
  exit(101)
else
  set prof=$1
  set nra=$2
endif
if ( $?USER ) then
   set who=$USER
else
   if ( $?LOGNAME ) then
      set who=$LOGNAME
   else
      set who=`whoami`
   endif
endif
#
set REPCONF=$ASTER_ROOT/etc/codeaster
if ( -d $REPCONF ) then
  set REPAGLA=`egrep "rep_agla[ ]+:"             $REPCONF/agla  | awk '{print $3}'` 
  set REPTMP=`egrep "rep_tmp[ ]+:"               $REPCONF/asrun | awk '{print $3}'` 
  set REPFLASH=$HOME/flasheur
  set REPREX=`egrep "rep_rex[ ]+:"               $REPCONF/agla  | awk '{print $3}'`
  set IPSERVER=`egrep "devel_server_ip[ ]+:"     $REPCONF/asrun | awk '{print $3}'`
else
  echo repertoire $REPCONF inaccessible 
  exit(102)
endif
#
set rep=$REPTMP/astk_`whoami`
mkdir -p $rep
chmod 755 $rep
#
set ficpret=$rep/`basename $prof`

cd $rep
mkdir $nra.D
chmod 755 $nra.D
set newprof=$nra.D/$nra.export
#
# préparation du fichier .export modifié (prêt à être importé dans astk)
# - paramètres et arguments
egrep '^[P|A]+' $ficpret >  $newprof
# - fichiers/répertoires (on ajoute user@aster.cla.edfgdf.fr: pour forcer "distant")
egrep '^[F|R]+' $ficpret | awk -v chem=user@"$IPSERVER":$REPREX/emise/$nra '{gsub(".*/","",$3); printf("%s %s %s/%s %s %s\n",$1,$2,chem,$3,$4,$5);}' >> $newprof
#
# copie des fichiers de résultats et des répertoires (flag D et/ou R)
#
set lficdr=`egrep '^[F|R]+' $ficpret | awk '{print $3}'`
#
foreach ficd ($lficdr)
  rcp -r $ficd $nra.D
end
#
chmod -R a+rx $nra.D
mv $nra.D $nra
$REPAGLA/mkdir_uid $REPREX/emise/$nra
$REPAGLA/cp_uid $nra $REPREX/emise/$nra

exit 0
