summaryrefslogtreecommitdiffstats
path: root/tools/testh5toh4
blob: ba8a3a30255211f19ddec2421edb4e0cb0f2d678 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/sh

h5toh4=./h5toh4		# a relative name
cmp='cmp -s'
diff='diff -c'

RM='rm -f'
SED='sed '
H4DUMP='hdp'

# The build (current) directory might be different than the source directory.
if test "X$srcdir" = X; then
    srcdir=.
fi
mkdir testfiles >/dev/null 2>&1

INDIR="$srcdir/testfiles"
OUTDIR="./testfiles"

nerrors=0
verbose=yes

# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
TESTING()
{
    SPACES="                                                               "
    echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\n'
}

# Run a test and print PASS or *FAIL*.  If a test fails then increment
# the `nerrors' global variable and (if $verbose is set) display the
# difference between the actual output and the expected output. The
# expected output is given by adding a `.dmp' extension to the root of
# the first argument to this function and the actual output file is
# calculated by replacing the `.dmp' with `.tmp'.  The actual output
# is not removed if $HDF5_NOCLEANUP has a value.
CONVERT()
{
    # Run h5toh4 convert.
    TESTING $h5toh4 $@
    (
        case "$1" in

        "-m")
   	    if [ $# -eq 2 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $OUTDIR
		    set - $1 $OUTDIR/$2
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2
		fi
	    elif [ $# -eq 3 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3
		fi
	    elif [ $# -eq 4 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4
		fi
	    elif [ $# -eq 5 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4 $OUTDIR/$5
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4 $5
		fi
	    elif [ $# -eq 6 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4 $OUTDIR/$5 $OUTDIR/$6
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4 $5 $6
		fi
	    elif [ $# -eq 7 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4 $OUTDIR/$5 $OUTDIR/$6 $OUTDIR/$7
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4 $5 $6 $7
		fi
	    elif [ $# -eq 8 ]
	    then
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7 $INDIR/$8
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7 $INDIR/$8 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4 $OUTDIR/$5 $OUTDIR/$6 $OUTDIR/$7 $OUTDIR/$8
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4 $5 $6 $7 $8
		fi
	    else
		if test "$INDIR" = "$OUTDIR"; then
		    set - $1 $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7 $INDIR/$8 $INDIR/$9
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$2 $INDIR/$3 $INDIR/$4 $INDIR/$5 $INDIR/$6 $INDIR/$7 $INDIR/$8 $INDIR/$9 $OUTDIR
		    set - $1 $OUTDIR/$2 $OUTDIR/$3 $OUTDIR/$4 $OUTDIR/$5 $OUTDIR/$6 $OUTDIR/$7 $OUTDIR/$8 $OUTDIR/$9
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $2 $3 $4 $5 $6 $7 $8 $9
		fi
	    fi
            ;;
	* )
   	    if [ $# -eq 1 ]
	    then 
		if test "$INDIR" = "$OUTDIR"; then
		    set - $INDIR/$1
        	    $h5toh4 "$@" 2>/dev/null
		else
		    cp $INDIR/$1 $OUTDIR
		    set - $OUTDIR/$1
        	    $h5toh4 "$@" 2>/dev/null
		    $RM $1
		fi
	    else
 		set - $INDIR/$1 $OUTDIR/$2
        	$h5toh4 "$@" 2>/dev/null
	    fi
            ;;
        esac
    )

    case "$1" in

    "-m")

	multirun=passed
	shift
	for i in $@
	do
		h4file=`echo $i | $SED -e s/\.h5/.hdf/g`

	    	actual=`echo $h4file | $SED -e s/\.hdf/.tmp/`
	    	expect=`echo $h4file | $SED -e s/\.hdf/.dmp/`

		if test "tloop.hdf" = "$h4file"; then
			($H4DUMP dumpvg "$OUTDIR/$h4file" |head -50 >"$OUTDIR/$actual") 2>/dev/null
		else
			$H4DUMP dumpvg "$OUTDIR/$h4file" > "$OUTDIR/$actual"
		fi
		$H4DUMP dumpvd "$OUTDIR/$h4file" >> "$OUTDIR/$actual"
		$H4DUMP dumpsds "$OUTDIR/$h4file" >> "$OUTDIR/$actual"

    		# Results. We normalize the result to account for different output 
    		# widths.  That is, the test should succeed if the only
    		# differences are in white space. We have to do this the hard way
    		# because diff isn't always smart enough.
		tr '\n' ' ' <"$OUTDIR/$actual" |tr -s ' \t' |fold >"$OUTDIR/$actual-norm"
		tr '\n' ' ' <"$INDIR/$expect" |tr -s ' \t' |fold >"$OUTDIR/$expect-norm"

    		if $cmp "$OUTDIR/$expect-norm" "$OUTDIR/$actual-norm"; then
			set unrelated
		else
			if test "passed" = "$multirun"; then
				echo "*FAILED*"
				echo "    Actual result (*.tmp) differs from expected result (*.dmp)"
				nerrors="`expr $nerrors + 1`"
				multirun=failed
			fi
			test yes = "$verbose" && $diff "$INDIR/$expect" "$OUTDIR/$actual" |sed 's/^/    /'
    		fi

    		# Clean up output file
    		$RM "$OUTDIR/$expect-norm" "$OUTDIR/$actual-norm"
    		if [ X = ${HDF5_NOCLEANUP:-X} ]; then
			$RM "$OUTDIR/$actual"
			$RM "$OUTDIR/$h4file"
    		fi
	done
	if test "passed" = "$multirun"; then
		echo " PASSED"
	fi

	;;


    * )

   	if [ $# -eq 1 ]
	then 
		h4file=`echo $1 | $SED -e s/\.h5/.hdf/`
	else
		h4file=$2
	fi

	actual=`echo $h4file | $SED -e s/\.hdf/.tmp/`
	expect=`echo $h4file | $SED -e s/\.hdf/.dmp/`

	if test "tloop.hdf" = "$h4file"; then
		($H4DUMP dumpvg "$OUTDIR/$h4file" |head -50 >"$OUTDIR/$actual") 2>/dev/null
	else
		$H4DUMP dumpvg "$OUTDIR/$h4file" > "$OUTDIR/$actual"
	fi
	$H4DUMP dumpvd "$OUTDIR/$h4file" >> "$OUTDIR/$actual"
	$H4DUMP dumpsds "$OUTDIR/$h4file" >> "$OUTDIR/$actual"


	# Results. We normalize the result to account for different output 
	# widths.  That is, the test should succeed if the only
	# differences are in white space. We have to do this the hard way
	# because diff isn't always smart enough.
	tr '\n' ' ' <"$OUTDIR/$actual" |tr -s ' \t' |fold >"$OUTDIR/$actual-norm"
	tr '\n' ' ' <"$INDIR/$expect" |tr -s ' \t' |fold >"$OUTDIR/$expect-norm"

	if $cmp "$OUTDIR/$expect-norm" "$OUTDIR/$actual-norm"; then
		echo " PASSED"
	else
		echo "*FAILED*"
		echo "    Actual result (*.tmp) differs from expected result (*.dmp)"
		nerrors="`expr $nerrors + 1`"
		test yes = "$verbose" && $diff "$INDIR/$expect" "$OUTDIR/$actual" |sed 's/^/    /'
	fi

	# Clean up output file
	$RM "$OUTDIR/$expect-norm" "$OUTDIR/$actual-norm"
	if [ X = ${HDF5_NOCLEANUP:-X} ]; then
		$RM "$OUTDIR/$actual"
		$RM "$OUTDIR/$h4file"
	fi
	;;

    esac

}



##############################################################################
##############################################################################
###			  T H E   T E S T S                                ###
##############################################################################
##############################################################################

$RM $OUTDIR/*.hdf $OUTDIR/*.tmp

#
# The HDF4 filenames are created based upon the HDF5 filenames
# without the extension.
#

# test for converting H5 groups to H4 Vgroups.
CONVERT tgroup.h5

# test for converting H5 datasets to H4 SDS's.
CONVERT tdset.h5

# test for converting H5 attributes to H4 attributes.
CONVERT tattr.h5

# test for converting H5 soft links.
CONVERT tslink.h5

# test for converting H5 hard links.
CONVERT thlink.h5

# test for converting H5 compound data type to H4 Vdata.
CONVERT tcompound.h5

# test for converting all H5 objects at in same file.
CONVERT tall.h5

# tests for converting H5 objects with loops.
CONVERT tloop.h5

# test for converting extendable H5 datasets to H4 SDS's.
CONVERT tdset2.h5

# test for converting extendable H5 datasets with compound data type to H4 Vdata.
CONVERT tcompound2.h5

# tests for converting H5 objects from many different pathways.
CONVERT tmany.h5

# tests for converting H5 string objects.
CONVERT tstr.h5

# tests for converting more H5 string objects.
CONVERT tstr2.h5

#
# The test for conversion are the same as above with the only difference
# being that the HDF4 filenames are given explicitly.
#

$RM $OUTDIR/*.tmp
CONVERT tgroup.h5 tgroup.hdf
CONVERT tdset.h5 tdset.hdf
CONVERT tattr.h5 tattr.hdf
CONVERT tslink.h5 tslink.hdf
CONVERT thlink.h5 thlink.hdf
CONVERT tcompound.h5 tcompound.hdf
CONVERT tall.h5 tall.hdf
CONVERT tloop.h5 tloop.hdf
CONVERT tdset2.h5 tdset2.hdf
CONVERT tcompound2.h5 tcompound2.hdf
CONVERT tmany.h5 tmany.hdf
CONVERT tstr.h5 tstr.hdf
CONVERT tstr2.h5 tstr2.hdf

#
# Again, the test for conversion are the same as the first set of test.
# Here, multiple conversion are done on HDF5 files at one time.
#

$RM $OUTDIR/*.hdf $OUTDIR/*.tmp
CONVERT -m tgroup.h5 tdset.h5 tattr.h5 tslink.h5 thlink.h5
CONVERT -m tcompound.h5 tall.h5 tloop.h5
CONVERT -m tdset2.h5 tcompound2.h5 tmany.h5
CONVERT -m tstr.h5 tstr2.h5

if test $nerrors -eq 0 ; then
	echo "All h5toh4 tests passed."
fi

exit $nerrors