#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This script combines and formates the temperature, dew point and pressure  
# fields to build the forcing temperature and humidity fields afterwards. 
# output_step12_0h.nc and output_step12_12h.nc as described in README should 
# be in the working directory 
#
# History : Virginie Guemas - Initial version                         - 2012 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#                                Arguments
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
year='2013'
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ncap2 -O -s "d2m=double(d2m)" output_step0.nc output_step0.nc
ncap2 -O -s "t2m=double(t2m)" output_step0.nc output_step0.nc
ncap2 -O -s "sp=double(sp)" output_step0.nc output_step0.nc
ncatted -O -a add_offset,d2m,d,d, output_step0.nc output_step0.nc
ncatted -O -a add_offset,t2m,d,d, output_step0.nc output_step0.nc
ncatted -O -a add_offset,sp,d,d, output_step0.nc output_step0.nc
ncatted -O -a scale_factor,d2m,d,d, output_step0.nc output_step0.nc
ncatted -O -a scale_factor,t2m,d,d, output_step0.nc output_step0.nc
ncatted -O -a scale_factor,sp,d,d, output_step0.nc output_step0.nc
ncks -v t2m output_step0.nc t2m_eraint_${year}.nc
ncrename -v t2m,t2 t2m_eraint_${year}.nc t2_eraint_${year}.nc
ncks -v d2m output_step0.nc d2m_eraint_${year}.nc
ncks -v sp output_step0.nc sp_eraint_${year}.nc
