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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at *
* http://hdfgroup.org/products/hdf4/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "hdf.h"
#include "mfhdf.h"
#include "vg.h"
#include "hdiff.h"
/*-------------------------------------------------------------------------
* Function: gattr_diff
*
* Purpose: compare global SDS attributes
*
*-------------------------------------------------------------------------
*/
uint32 gattr_diff(int32 sdid1,
int32 sdid2,
diff_opt_t *opt)
{
int32 nvars1, nvars2; /* number of variables */
int32 ngatts1, ngatts2; /* number of global attributes */
struct ncatt att1, att2; /* attribute */
int ia, ib; /* attribute number */
int iret2;
uint32 nfound=0;
SDfileinfo(sdid1, &nvars1, &ngatts1);
/* get global attributes */
for (ia = 0; ia < ngatts1; ia++)
{
SDattrinfo(sdid1, ia, att1.name, &att1.type, &att1.len);
ib = SDfindattr(sdid2, att1.name);
if (ib == -1) /* attribute doesn't exist in file2 */
{
printf("\n---------------------------\n");
printf("< %s\n", att1.name);
printf("> '%s' does not exist in file2\n", att1.name);
nfound ++;
continue;
}
iret2 = SDattrinfo(sdid2, ib, att2.name, &att2.type, &att2.len);
att1.val = (void *) malloc((unsigned) (att1.len*DFKNTsize(att1.type | DFNT_NATIVE)));
if (!att1.val)
{
fprintf(stderr,"Out of memory!\n");
goto out;
}
att2.val = (void *) malloc((unsigned) (att2.len*DFKNTsize(att2.type | DFNT_NATIVE)));
if (!att2.val)
{
fprintf(stderr,"Out of memory!\n");
goto out;
}
SDreadattr(sdid1, ia, att1.val);
iret2 = SDreadattr(sdid2, ib, att2.val);
iret2 = 0;
if (att1.type != att2.type || att1.len != att2.len)
iret2 = 1;
if (iret2 == 0) /* compare the data */
iret2 = memcmp((void *) att1.val, att2.val,
att1.len*DFKNTsize(att1.type | DFNT_NATIVE));
if (iret2 != 0)
{
printf("\n---------------------------\n");
printf("Attr Name: %s\n", att1.name);
printf("< ");
pr_att_vals((nc_type)att1.type, att1.len, att1.val);
printf("\n> ");
pr_att_vals((nc_type)att2.type, att2.len, att2.val);
printf("\n");
nfound ++;
}
free ((char *) att1.val);
free ((char *) att2.val);
}
/* check any global attributes in file2 but not in file1 */
iret2 = SDfileinfo(sdid2, &nvars2, &ngatts2);
for (ib = 0; ib < ngatts2; ib++)
{
iret2 = SDattrinfo(sdid2, ib, att2.name, &att2.type, &att2.len);
ia = SDfindattr(sdid1, att2.name);
if (ia == -1) /* attribute doesn't exist in file2 */
{
printf("\n---------------------------\n");
printf("< '%s' does not exist in file1\n", att2.name);
printf("> %s\n", att2.name);
nfound ++;
}
}
return nfound;
out:
opt->err_stat = 1;
return 0;
}
|