#!/bin/sh

###############################################################
#  Script and program for CHIMERE input data                  #
#  and output results plots                                   #
#                                                             #
#  SOFTWARE REQUIRED: g77, gawk, gmt, xmgr                    #
#                                                             #
#  LAST REVISION : January 2003                               #
#                                                             #
#  AUTHORS: L. MENUT    [LISA]   menut@lisa.univ-p[aris12.fr  #
#           R. VAUTARD  [IPSL]   vautard@lmd.polytechnique.fr #
#           C. HONORE   [INERIS] Cecile.Honore@ineris.fr      #
############################################################### 

# Here you must use exactly the same directory names
# that the ones used for the chimere run
# To view the whole set of results, the flag clean must be NO in the
# chimere script

#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#                         users parameters
#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
dom=MED2
sim=IOP2rams
year=2001
month=06
day=19
hour=00
nhours=210

simuldir=/d2/save/chimere/RUN_${dom}${sim} 
domnsdir=/d2/save/chimere/DOMAINS
emissdir=/d2/save/chimere/emiMED2-200211 

# names of coordinates files
fichr=C2f_StationsHR.data
ficlr=C2f_StationsLR.data
fictopo=NOAAngdctopo.txt

# topography (yes=1 no=0)
inewtopo=1
#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#                       End of users parameters
#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

tmpdir=${simuldir}
sd0=${year}${month}${day}${hour}
init=0
iopbounlat=1
iopbountop=1

clear
echo " "
echo "         ---  CHIM2FIG for chimere 200211I ---"
echo " "

echo "chim2fig : reconstruction of INFOS file"
# Re-Construction of INFOS file

cat << EOD > $tmpdir/INFOS.sed-commands
s,_SIM_,${sim},
s,_NHOURS_,${nhours},
s,_INITDATE_,${sd0},
s,_INIT_,${init},
s,_SIMULDIR_,${simuldir},
s,_TMPDIR_,$tmpdir,
s/_IOPBOUNLAT_/${iopbounlat}/
s/_IOPBOUNTOP_/${iopbountop}/
EOD
sed -f $tmpdir/INFOS.sed-commands data/INFOS.sed > $simuldir/save.$sim/INFOS

#--------------------------------------------------------
echo "chim2fig : cleaning archive"
\rm chim2fig.a *.o

#--------------------------------------------------------
echo "chim2fig : compile"

   export simuldir
   export CURRENTDIR=`pwd`
   
echo "       -> making directory for figures named "$simuldir/fig.${sim}
   mkdir $simuldir/fig.${sim}   
echo "       -> compiling chim2fig in " $tmpdir
   cd $tmpdir
   
   rm -f *.a *.o
   cp $CURRENTDIR/srcfig/C2f*.f .
   cp $CURRENTDIR/srcfig/chim2fig.* .
   g77 -O -c B*.f C2f*.f
   ar r chim2fig.a B*.o C2f*.o
   rm *.o
   g77 -O chim2fig.f chim2fig.a -o chim2fig.e
   
echo "chim2fig : copy of chim2fig data files (names and topo)"
   cp $CURRENTDIR/datafig/* .

   echo "$fichr"                                  >  chim2fig.p
   echo "$ficlr"                                 >>  chim2fig.p
   echo "$inewtopo"                              >>  chim2fig.p
   echo "$fictopo"                               >>  chim2fig.p
   echo "$dom"                                   >>  chim2fig.p
   echo "$simuldir/fig.$sim/"                     >>  chim2fig.p
  
  
#--------------------------------------------------------
echo "chim2fig : run"
chim2fig.e
