-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcmp_rundirs_ncfiles.sh
executable file
·100 lines (74 loc) · 2.41 KB
/
cmp_rundirs_ncfiles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh -l
module load nccmp
#
#-----------------------------------------------------------------------
#
# Define generic function to compare NetCDF files in two directories.
#
#-----------------------------------------------------------------------
#
function cmp_ncfiles_one_dir() {
local dir1="$1"
local dir2="$2"
local subdir="$3"
local fileext="$4"
local fn=""
local msg=""
cd $dir1/$subdir
for fn in *.$fileext; do
fn1="$fn"
if [ -f "$fn1" ] && [ ! -L "$fn1" ]; then # Check if regular file and not a symlink.
fn2="$dir2/$subdir/$fn"
if [ -e "$fn2" ]; then # Check if file exists.
if [ -f "$fn2" ] && [ ! -L "$fn2" ]; then # Check if regular file and not a symlink.
printf "\nComparing file \"$fn\" in subdirectory \"$subdir\" ...\n"
nccmp -d $fn1 $fn2
# nccmp -dS $fn1 $fn2
# nccmp -d -t 1e-3 $fn1 $fn2
# nccmp -d --precision='%g10.5' $fn1 $fn2
if [ $? = 0 ]; then
msg=$( printf "%s" "Files are identical." )
elif [ $? = 1 ]; then
msg=$( printf "%s" "===>>> FILES ARE DIFFERENT!!!" )
else
msg=$( printf "%s" "FATAL ERROR. Exiting script." )
exit 1
fi
printf "%s\n" "$msg"
else
printf "\n%s\n" "File \"$fn\" in \"$dir2/$subdir\" is a symbolic link. Skipping."
fi
else
printf "\n%s\n" "File \"$fn\" does not exist in \"$dir2/$subdir\"."
printf "\n%s\n" "Exiting script."
exit 1
fi
else
printf "\n%s\n" "File \"$fn\" in \"$dir1/$subdir\" is a symbolic link. Skipping."
fi
done
}
#
#-----------------------------------------------------------------------
#
# Get the two run directories to compare from command-line arguments.
# Then compare NetCDF files in the run directories as well as in their
# INPUT subdirectories.
#
#-----------------------------------------------------------------------
#
#set -x
rundir1="$( readlink -f $1 )"
rundir2="$( readlink -f $2 )"
printf "\n"
printf "%s\n" "rundir1 = \"$rundir1\""
printf "%s\n" "rundir2 = \"$rundir2\""
subdirs=("INPUT" ".")
for subdir in "${subdirs[@]}"; do
msg=$( printf "%s" "Comparing files in subdirectory \"$subdir\" ..." )
msglen=${#msg}
printf "\n%s\n" "$msg"
printf "%0.s=" $(seq 1 $msglen)
printf "\n"
cmp_ncfiles_one_dir "$rundir1" "$rundir2" "$subdir" "nc"
done