#! /usr/bin/bash
#---------------------------------------------------------------------------------------------------
# This script concatenates the 4 seperate files containing CMIP7 N-deposition fields (dry and wet
# deposition of NHx and NOy) into one file for easier reading by NorESM
#
# Currently this is done for climatological 1850 files and for historical. CMIP7 scenarios 
# will be added when available
#----------------------------------------------------------------------------------------------------


ndepvar=("drynhx" "drynoy" "wetnhx" "wetnoy")

#-----------------------------------------------
# pre-industrial
#-----------------------------------------------
basename=input4MIPs_surfaceFluxes_CMIP_FZJ-CMIP-nitrogen-1-2_gn_185001-185012-clim.nc
outfile=ndep_$basename
rm $outfile

cp ${ndepvar[0]}_${basename} $outfile

ncks  -A -C -v ${ndepvar[1]} ${ndepvar[1]}_$basename $outfile
ncks  -A -C -v ${ndepvar[2]} ${ndepvar[2]}_$basename $outfile
ncks  -A -C -v ${ndepvar[3]} ${ndepvar[3]}_$basename $outfile

#-----------------------------------------------
# historical
#-----------------------------------------------
basename=input4MIPs_surfaceFluxes_CMIP_FZJ-CMIP-nitrogen-1-2_gn_185001-202212.nc
outfile=ndep_$basename
rm $outfile

cp ${ndepvar[0]}_${basename} $outfile

ncks  -A -C -v ${ndepvar[1]} ${ndepvar[1]}_$basename $outfile
ncks  -A -C -v ${ndepvar[2]} ${ndepvar[2]}_$basename $outfile
ncks  -A -C -v ${ndepvar[3]} ${ndepvar[3]}_$basename $outfile

