# QSUB -q uqbar 
# NECOPT -s /bin/csh                                                   
# NECOPT -eo    
# NECOPT -lM 300Mb # 750Mb maximum memory used per job (nx=2048, nz=1024)
# NECOPT -lT 1500      # maximum CPU time per job
# NECOPT -me
# NECOPT -r prepom0
# NECOPT -jo
# NECOPT -o listing

#_____________________________________________________
#!/usr/bin/csh
#
# 	DESCRIPTIF DU JOB 
#_____________________________________________________
#

date
cd $TMPDIR
unalias rm
set echo


#_____________________________________________________
#
# 	definition des variables :
#_____________________________________________________
#
set DATE        =       `date '+%Y%m%d'_'%H%M%S'`
set LISTING	=	listing
set HOMERHOD	=       $QSUB_WORKDIR 
set WORK_DIR    =       /workdir/rech/dyc/rdyc009
# test perfomrances of the code
set F_PROGINF   =       yes  
#


ftget -h rhodes $HOMERHOD/FICH_RUN FICH_RUN
set RUN_NAME    =       `more FICH_RUN`
set N           =       ${RUN_NAME}
set MFDIR       =       UQBAR_${RUN_NAME}

#_____________________________________________________
#
# Alea jacta est ...
#_____________________________________________________
#

# in $tmpdir create the right directories
cd $WORK_DIR
mkdir projects
cd projects
cd ..
mkdir output
cd output
mkdir 2D
mkdir 3D
mkdir 1D
mkdir 0D
cd ..


#create a directory on gaya
#rsh gaya -n mkdir $MFDIR


#_____________________________________________________
#
#	3D simulation:
#_____________________________________________________
#


### copy the executable and allows it to runs  
	
	ftget -h rhodes $HOMERHOD/flow_solve.x flow_solve.x
	chmod +x flow_solve.x
        pwd
	mpirun -np 1 flow_solve.x

exit

#_____________________________________________________
#
# tidying up ... :
#_____________________________________________________
#

ls -l
ftrace

# save outputs (reels ieee):
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cd output
 ls

#save energetics

mfput energetics $MFDIR/$N.energetics

# save 0D fields:

tar cvf 0D.tar 0D 
mfput  0D.tar $MFDIR/$N.0D.tar
rm 0D.tar

# save 1D fields:

tar cvf 1D.tar 1D 
mfput  1D.tar $MFDIR/$N.1D.tar
rm 1D.tar

# save 2D fields:

tar cvf 2D.tar 2D 
mfput  2D.tar $MFDIR/$N.2D.tar
rm 2D.tar

# save 3D fields:

tar cvf 3D.tar 3D 
mfput  3D.tar $MFDIR/$N.3D.tar
rm 3D.tar

# save forcing
#mfput forcing.txt $MFDIR/forcing.txt

# save listing
#mfput ../$LISTING $MFDIR/$LISTING

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd $TMPDIR
rm flow_solve.x 
rm core 

#### save listing
cd $WORK_DIR
mkdir $MFDIR
cd $MFDIR
ftget -h rhodes $HOMERHOD/sub_rapatrie sub_rapatrie
echo $HOMERHOD > fichier_directory
qsub sub_rapatrie

#_____________________________________________________
#
# 	that's all, folks !
#_____________________________________________________
#

exit

