source: CDB_driver/trunk/lib/concatenate_models.sh @ 36

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CDB_driver/trunk/lib/concatenate_models.sh@36
Revision 36, 1.7 KB checked in by lalibert, 9 years ago (diff)

Initial import. This splits the driver from the diagnostics.

Line 
1#!/bin/bash
2#
3while getopts :h: opt; do
4  case $opt in
5    h)
6      echo "Help"
7      echo "Usage: concatenate_models.sh DEST_NC_FILE INPUT_NC_FILE_LIST"
8      echo ""
9      echo "This script uses ncecat to outputs from several models. The output must have been"
10      echo "converted to the same horizontal and vertical grids. ncecat creates a new \'record\'"
11      echo "attribute. This script creates ordered lists \'model_list\' and \'rip_list\' as global"
12      echo "attributes. These can be used to match \'record\' with model name and realization."
13      echo ""
14      echo "F. Laliberte and P. J. Kushner, University of Toronto, 2012"
15      exit
16    ;;
17    \?)
18      echo "Unknown option -$OPTARG use -h for help"
19    ;;
20  esac
21done
22shift $((OPTIND-1))
23
24#First input is output file
25CDB_CAT_FILE=$1
26
27#All other inputs will be concatenated
28shift
29CDB_FILE_LIST="$@"
30
31#Create model and rip list
32MODEL_ID_LIST=""
33RIP_ID_LIST=""
34for CDB_FILE in ${CDB_FILE_LIST}; do
35   MODEL_ID=$(ncks -M ${CDB_FILE} | grep model_id) 
36   MODEL_ID=$(echo $MODEL_ID | awk -F'=' '{print $3}')
37   MODEL_ID_LIST="${MODEL_ID_LIST},${MODEL_ID# }"
38
39   RIP_ID=$(ncks -M ${CDB_FILE} | grep parent_experiment_rip) 
40   RIP_ID=$(echo $RIP_ID | awk -F'=' '{print $3}')
41   RIP_ID_LIST="${RIP_ID_LIST},${RIP_ID# }"
42done
43
44#Cat files:
45ncecat -h ${CDB_FILE_LIST} ${CDB_CAT_FILE}
46
47#Create model_list and rip_list global attributes:
48ncatted -h -a model_list,global,c,c,"${MODEL_ID_LIST:1}" ${CDB_CAT_FILE}
49ncatted -h -a rip_list,global,c,c,"${RIP_ID_LIST:1}" ${CDB_CAT_FILE}
50
51#Permute dimensions so that time becomes a netCDF record dimension once again
52ncpdq -h -a time,record ${CDB_CAT_FILE} ${CDB_CAT_FILE}_perm
53mv ${CDB_CAT_FILE}_perm ${CDB_CAT_FILE}
Note: See TracBrowser for help on using the repository browser.