#!/bin/sh
set -e
# add two files then convert the sum, which is a global average 
# expressed per cm^2 per second, to a global integral per year 
# by multiplying by the surface area of the Earth (cm^2) and 
# the length of a year (sec) and then converting to moles by 
# dividing by Avogadro's number
#
#  with R_earth = 6.37122E+08 cm
#  with year = 3.1536E7 sec
#  factor = 5.100997E+18*3.1536E7/6.0221413E+23

if [ $# -ne 4 ] ; then
  echo "Error in $0: invalid number of arguments $#"
  exit 1
fi

pfx=$1
inp1=$2
inp2=$3
out=$4

release inp1 inp2
access  inp1 ${pfx}_${inp1}
access  inp2 ${pfx}_${inp2}

add inp1 inp2 temp1
echo "          267.122662" | ccc xlin temp1 ${pfx}_${out}
rm -f temp1
release inp1 inp2
