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

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CDB_driver/trunk/lib/compare_grid.sh@36
Revision 36, 1.4 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: compare_grid.sh target_nc_file nc_file_to_conform"
8      echo ""
9      echo "This script takes two netCDF files as input. Both files must have one and only one"
10      echo "horizontal grid as perceived by cdo. This script compares the grids using the"
11      echo "cdo griddes2 operator. If the two grids are identical, then this script does nothing."
12      echo "If, on the other hand, the two grids are different, the script echos a filename that"
13      echo "contains the first file's, \'target_nc_file\', grid description. This grid description"
14      echo "can then be used with the cdo remap{con,bil,dis,nn,...} onto \'nc_file_to_conform\'"
15      echo ""
16      echo "F. Laliberte and P. J. Kushner, University of Toronto, 2012"
17      exit
18    ;;
19    \?)
20      echo "Unknown option -$OPTARG use -h for help"
21    ;;
22  esac
23done
24shift $((OPTIND-1))
25
26#Recover the grid description
27cdo griddes2 $1 > ${CDB_TEMP_DIR}/griddes.pid${$}.1
28cdo griddes2 $2 > ${CDB_TEMP_DIR}/griddes.pid${$}.2
29
30#Use diff to compare
31DIFFERENCE=$(diff ${CDB_TEMP_DIR}/griddes.pid${$}.1 ${CDB_TEMP_DIR}/griddes.pid${$}.2 | wc -l)
32
33rm ${CDB_TEMP_DIR}/griddes.pid${$}.2
34
35#Check if they differ
36if [ "$DIFFERENCE" -gt "0" ]; then
37    echo "${CDB_TEMP_DIR}/griddes.pid${$}.1"
38else
39    rm ${CDB_TEMP_DIR}/griddes.pid${$}.1
40fi
Note: See TracBrowser for help on using the repository browser.