#!/bin/sh
# script to update the GOCCP GEWEX database
#
# Each type of files has its own program
# CA CAL CAM CAH use gewex.f90
# CALR CAMR CAHR use gewexr.f90
# CT CTL CTM CTH use gewexct2.f90
# CZ uses gewexcz.f90
#
# Compile the program first
# makefiles.sh gewex
#
# Then run the program with the input parameter file
# gewex.e < 2007gewex.p
# The parameter file contains the name of the variable and the year
# Another parameter file is used: the year file, named {year}file.p
#
# Don't forget to change the gewexdir

home=`pwd`
gewexdir='/bdd/CFMIP/CFMIP_OBS_LOCAL/Goccp_GEWEX/mensuel'


# compiling
$home/makefiles.sh gewex
$home/makefiles.sh gewexr
$home/makefiles.sh gewexct2
$home/makefiles.sh gewexcz

# creating yearly input files
for year in `seq 2007 2017`
do
rm -f ${year}file.p
for month in `seq -w 01 12`
do
echo $month $year$month >> ${year}file.p
done
done

# Running the programs
for year in  "2008" #`seq 2007 2017`
do
# Cloud Temperature
  for i in "CT" "CTH" "CTM" "CTL"; 
  do 
  echo $i > gewex.p; 
  echo ${year}file.p >> gewex.p; 
  gewexct2.e < gewex.p; 
  done
mv /bdd/CFMIP/GOCCP/temp/CT*${year}.nc  $gewexdir/$year

# Cloud Amount
  for i in "CA" "CAH" "CAM" "CAL"; 
  do 
  echo $i > gewex.p; 
  echo ${year}file.p >> gewex.p; 
  gewex.e < gewex.p; 
  done
mv /bdd/CFMIP/GOCCP/temp/CA*${year}.nc  $gewexdir/$year

# Cloud Amount RELATIF
  for i in "CAH" "CAM" "CAL";
  do
  echo $i > gewex.p;
  echo ${year}file.p >> gewex.p;   
  gewexr.e < gewex.p;  
  done
mv /bdd/CFMIP/GOCCP/temp/CA*${year}.nc  $gewexdir/$year

# Cloud Height
  for i in "CZ"
  do
  echo $i > gewex.p;
  echo ${year}file.p >> gewex.p;   
  gewexcz.e < gewex.p; 
  done
mv /bdd/CFMIP/GOCCP/temp/CZ*${year}.nc  $gewexdir/$year

done

