1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 #include "H5private.h"
15 #include "h5diff.h"
16 #include "h5diff_common.h"
17 #include "h5tools.h"
18 #include "h5tools_utils.h"
19 
20 
21 /*-------------------------------------------------------------------------
22  * Function: main
23  *
24  * Purpose: h5diff main program
25  *
26  * Return: An  exit status of 0 means no differences were found, 1 means some
27  *   differences were found.
28  *
29  * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
30  *
31  * Date: May 9, 2003
32  *
33  * Comments:
34  *
35  * Modifications: July 2004
36  *  Introduced the four modes:
37  *   Normal mode: print the number of differences found and where they occured
38  *   Report mode: print the above plus the differences
39  *   Verbose mode: print the above plus a list of objects and warnings
40  *   Quiet mode: do not print output
41  *
42  * November 2004: Leon Arber (larber@uiuc.edu)
43  *     Additions that allow h5diff to be run in parallel
44  *
45  * February 2005: Leon Arber (larber@uiuc.edu)
46  *   h5diff and ph5diff split into two files, one that is used
47  *   to build a serial h5diff and one used to build a parallel h5diff
48  *   Common functions have been moved to h5diff_common.c
49  *
50  * October 2005
51  *  Introduced a new field 'not_cmp' to 'diff_opt_t' that detects
52  *  if some objects are not comparable and prints the message
53  *  "Some objects are not comparable"
54  *
55  * February 2007
56  *  Added comparison for dataset regions.
57  *  Added support for reading and comparing by hyperslabs for large files.
58  *  Inclusion of a relative error formula to compare floating
59  *   point numbers in order to deal with floating point uncertainty.
60  *  Printing of dataset dimensions along with dataset name
61  *
62  *  November 19, 2007
63  *    adopted the syntax h5diff  [OPTIONS]  file1 file2  [obj1[obj2]]
64  *
65  *-------------------------------------------------------------------------
66  */
67 
68 
main(int argc,const char * argv[])69 int main(int argc, const char *argv[])
70 {
71     int        ret;
72     H5E_auto2_t         func;
73     H5E_auto2_t         tools_func;
74     void               *edata;
75     void               *tools_edata;
76     const char *fname1 = NULL;
77     const char *fname2 = NULL;
78     const char *objname1  = NULL;
79     const char *objname2  = NULL;
80     hsize_t    nfound=0;
81     diff_opt_t opts;
82 
83     h5tools_setprogname(PROGRAMNAME);
84     h5tools_setstatus(EXIT_SUCCESS);
85 
86     /* Disable error reporting */
87     H5Eget_auto2(H5E_DEFAULT, &func, &edata);
88     H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
89 
90     /* Initialize h5tools lib */
91     h5tools_init();
92 
93     /* Disable tools error reporting */
94     H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
95     H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
96 
97     /*-------------------------------------------------------------------------
98     * process the command-line
99     *-------------------------------------------------------------------------
100     */
101     parse_command_line(argc, argv, &fname1, &fname2, &objname1, &objname2, &opts);
102 
103     if (enable_error_stack > 0) {
104         H5Eset_auto2(H5E_DEFAULT, func, edata);
105         H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
106     }
107 
108     /*-------------------------------------------------------------------------
109     * do the diff
110     *-------------------------------------------------------------------------
111     */
112 
113     nfound = h5diff(fname1, fname2, objname1, objname2, &opts);
114 
115     print_info(&opts);
116 
117    /*-------------------------------------------------------------------------
118     * exit code
119     *   1 if differences, 0 if no differences, 2 if error
120     *-------------------------------------------------------------------------
121     */
122 
123     ret = (nfound == 0 ? 0 : 1);
124 
125     /* if graph difference return 1 for differences  */
126     if (opts.contents == 0)
127         ret = 1;
128 
129     /* and return 2 for error */
130     if (opts.err_stat)
131         ret = 2;
132 
133     h5diff_exit(ret);
134 }
135 
136 /*-------------------------------------------------------------------------
137  * Function: h5diff_exit
138  *
139  * Purpose: dismiss phdiff worker processes and exit
140  *
141  * Return: none
142  *
143  * Programmer: Albert Cheng
144  * Date: Feb 6, 2005
145  *
146  * Comments:
147  *
148  * Modifications:
149  *
150  *-------------------------------------------------------------------------
151  */
152 H5_ATTR_NORETURN void
h5diff_exit(int status)153 h5diff_exit(int status)
154 {
155     h5tools_close();
156 
157     HDexit(status);
158 }
159 
160