1 | #!/bin/bash |
---|
2 | #set -xv |
---|
3 | |
---|
4 | # This script is used to compares two netcdf files when there are some more variables in one or |
---|
5 | # the other of the files. The script will: |
---|
6 | # 1) Compare using ncdump the variables in both files and ask the user to remove if wanted. |
---|
7 | # Temporary files are created with less variables. |
---|
8 | # 2) use cdo diffv on the temporary files |
---|
9 | |
---|
10 | file1=$1 |
---|
11 | file2=$2 |
---|
12 | |
---|
13 | rm -f dump1 dump2 file1tmp.nc file2tmp.nc |
---|
14 | |
---|
15 | ncdump -h $file1 > dump1 |
---|
16 | ncdump -h $file2 > dump2 |
---|
17 | |
---|
18 | echo "Diff with grep float:" |
---|
19 | diff dump1 dump2 |grep float |
---|
20 | echo "Type variable list to be removed from input files before comparison" |
---|
21 | echo "or press enter if the list is empty to search for variables in double pression" |
---|
22 | echo "" |
---|
23 | echo "Type varlist1:" |
---|
24 | echo "Syntax: var1,var2,var3" |
---|
25 | read varlist1 |
---|
26 | echo "Type varlist2:" |
---|
27 | read varlist2 |
---|
28 | |
---|
29 | echo varlist1=$varlist1 varlist2=$varlist2 |
---|
30 | |
---|
31 | if [ X$varlist1 == X ] && [ X$varlist2 == X ] ; then |
---|
32 | echo "Search for variables in double precision" |
---|
33 | diff dump1 dump2 |grep double |
---|
34 | echo "Type variable list to be removed from input files before comparison" |
---|
35 | echo "" |
---|
36 | echo "Type varlist1:" |
---|
37 | echo "Syntax: var1,var2,var3" |
---|
38 | read varlist1 |
---|
39 | echo "Type varlist2:" |
---|
40 | read varlist2 |
---|
41 | |
---|
42 | echo varlist1=$varlist1 varlist2=$varlist2 |
---|
43 | fi |
---|
44 | |
---|
45 | if [ X$varlist1 == X ] ; then |
---|
46 | # only copy the file |
---|
47 | ncks $file1 -o file1tmp.nc |
---|
48 | else |
---|
49 | # extract variables |
---|
50 | ncks -x -v $varlist1 $file1 -o file1tmp.nc |
---|
51 | fi |
---|
52 | |
---|
53 | if [ X$varlist2 == X ] ; then |
---|
54 | ncks $file2 -o file2tmp.nc |
---|
55 | else |
---|
56 | ncks -x -v $varlist2 $file2 -o file2tmp.nc |
---|
57 | fi |
---|
58 | |
---|
59 | cdo diffv file1tmp.nc file2tmp.nc |
---|
60 | |
---|