#!/bin/bash

## Just run code in recipes, use it carefully
## example: use cdo to make cache file. Since cdo is quicker than ncl.
#;DIAG_NORCPM; RUNTHESECODES: echo '    no codes run here.'

output='sst_ens_NINO3_ts.nc'
test -z "$output" && (echo 'ERROR, no output file, exit...')
test -f "$output" && echo "$output exist, skip" && exit 0
#not work?## test -f "$output" && test 'True' != 'False' && (echo "$output is exist, exit." ; exit 0)
files=$(ls sst_??_NINO3_ts.nc)
test -z "$files" && (echo 'ERROR, no input for pattern: sst_??_NINO3_ts.nc, exit...';exit 1)
newdim='member'
test -z "$newdim" && (echo 'ERROR, no new dim name, exit... ';exit 1)

echo "Concatenating to new dim: $newdim"
echo "Concatenating from files:"
echo "$files"
echo "Concatenating to file: $output"
## Theres warning message with libnetcdf 4.8.1, but still OK
##   ncecat: WARNING nc_cdc_lst_bld() reports nco_inq_filter_avail()
ncecat -O -u member $files $output |grep -v 'ncecat: WARNING nc_cdc_lst_bld()'
echo "Done"


