|
| 1 | +/* |
| 2 | +*+ |
| 3 | +* Name: |
| 4 | +* datDsame |
| 5 | +
|
| 6 | +* Purpose: |
| 7 | +* Check if two primitive objects use the same data representation. |
| 8 | +
|
| 9 | +* Language: |
| 10 | +* Starlink ANSI C |
| 11 | +
|
| 12 | +* Type of Module: |
| 13 | +* Library routine |
| 14 | +
|
| 15 | +* Invocation: |
| 16 | +* datDsame( const HDSLoc *loc1, const HDSLoc *loc2, hdsbool_t *same, |
| 17 | +* int *status); |
| 18 | +
|
| 19 | +* Arguments: |
| 20 | +* loc1 = const HDSLoc * (Given) |
| 21 | +* First primitive object locator. |
| 22 | +* loc2 = const HDSLoc * (Given) |
| 23 | +* Second primitive object locator. |
| 24 | +* same = hdsbool_t * (Returned) |
| 25 | +* Set to true if and only if the two supplied objects use |
| 26 | +* the same data representation. |
| 27 | +* status = int* (Given and Returned) |
| 28 | +* Pointer to global status. |
| 29 | +
|
| 30 | +* Description: |
| 31 | +* The routine returns a flag indicating if the two supplied primitive |
| 32 | +* objects use the same data representation. See also datDrep. |
| 33 | +
|
| 34 | +* Authors: |
| 35 | +* DSB: David S. Berry (EAO): |
| 36 | +* {enter_new_authors_here} |
| 37 | +
|
| 38 | +* History: |
| 39 | +* 2019-01-08 (DSB): |
| 40 | +* Initial version |
| 41 | +* {enter_further_changes_here} |
| 42 | +
|
| 43 | +* Copyright: |
| 44 | +* Copyright (C) 2019 East Asian Observatory |
| 45 | +* All Rights Reserved. |
| 46 | +
|
| 47 | +* Licence: |
| 48 | +* Redistribution and use in source and binary forms, with or |
| 49 | +* without modification, are permitted provided that the following |
| 50 | +* conditions are met: |
| 51 | +* |
| 52 | +* - Redistributions of source code must retain the above copyright |
| 53 | +* notice, this list of conditions and the following disclaimer. |
| 54 | +* |
| 55 | +* - Redistributions in binary form must reproduce the above |
| 56 | +* copyright notice, this list of conditions and the following |
| 57 | +* disclaimer in the documentation and/or other materials |
| 58 | +* provided with the distribution. |
| 59 | +* |
| 60 | +* - Neither the name of the {organization} nor the names of its |
| 61 | +* contributors may be used to endorse or promote products |
| 62 | +* derived from this software without specific prior written |
| 63 | +* permission. |
| 64 | +* |
| 65 | +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 66 | +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 67 | +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 68 | +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 69 | +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 70 | +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 71 | +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 72 | +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 73 | +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 74 | +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 75 | +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 76 | +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 77 | +* THE POSSIBILITY OF SUCH DAMAGE. |
| 78 | +
|
| 79 | +* Bugs: |
| 80 | +* {note_any_bugs_here} |
| 81 | +*- |
| 82 | +*/ |
| 83 | + |
| 84 | +#include "hdf5.h" |
| 85 | + |
| 86 | +#include "ems.h" |
| 87 | +#include "sae_par.h" |
| 88 | + |
| 89 | +#include "hds1.h" |
| 90 | +#include "dat1.h" |
| 91 | +#include "hds.h" |
| 92 | + |
| 93 | +#include "dat_err.h" |
| 94 | + |
| 95 | +int |
| 96 | +datDsame(const HDSLoc *loc1, const HDSLoc *loc2, hdsbool_t *same, int *status) { |
| 97 | + |
| 98 | +/* Local Variables: */ |
| 99 | + hdsbool_t prim; |
| 100 | + hid_t h5type1 = 0; |
| 101 | + hid_t h5type2 = 0; |
| 102 | + |
| 103 | +/* Initialise. */ |
| 104 | + *same = HDS_FALSE; |
| 105 | + |
| 106 | +/* Check inherited status */ |
| 107 | + if (*status != SAI__OK) return *status; |
| 108 | + |
| 109 | +/* Validate input locators. */ |
| 110 | + dat1ValidateLocator( "datDsame", 1, loc1, 1, status ); |
| 111 | + dat1ValidateLocator( "datDsame", 1, loc2, 1, status ); |
| 112 | + |
| 113 | +/* Check they are both primitive. */ |
| 114 | + datPrim( loc1, &prim, status ); |
| 115 | + if( !prim && *status == SAI__OK ) { |
| 116 | + *status = DAT__NOTPR; |
| 117 | + datMsg( "O", loc1 ); |
| 118 | + emsRepf( " ", "datDsame: The first supplied HDS object ('^O') is " |
| 119 | + "not primitive (programming error).", status ); |
| 120 | + } |
| 121 | + |
| 122 | + datPrim( loc2, &prim, status ); |
| 123 | + if( !prim && *status == SAI__OK ) { |
| 124 | + *status = DAT__NOTPR; |
| 125 | + datMsg( "O", loc2 ); |
| 126 | + emsRepf( " ", "datDsame: The second supplied HDS object ('^O') is " |
| 127 | + "not primitive (programming error).", status ); |
| 128 | + } |
| 129 | + |
| 130 | +/* Get the two HDF5 data type objects. */ |
| 131 | + CALLHDF( h5type1, |
| 132 | + H5Dget_type( loc1->dataset_id ), |
| 133 | + DAT__HDF5E, |
| 134 | + emsRep("datDsame_type", "datDsame: Error obtaining data type " |
| 135 | + "of first dataset", status) ); |
| 136 | + |
| 137 | + CALLHDF( h5type2, |
| 138 | + H5Dget_type( loc2->dataset_id ), |
| 139 | + DAT__HDF5E, |
| 140 | + emsRep("datDsame_type", "datDsame: Error obtaining data type " |
| 141 | + "of second dataset", status) ); |
| 142 | + |
| 143 | +/* See if they are the same. */ |
| 144 | + if( *status == SAI__OK && H5Tequal( h5type1, h5type2 ) ) { |
| 145 | + *same = HDS_TRUE; |
| 146 | + } |
| 147 | + |
| 148 | +/* Free resources */ |
| 149 | + H5Tclose( h5type1 ); |
| 150 | + H5Tclose( h5type2 ); |
| 151 | + |
| 152 | + CLEANUP: |
| 153 | + return *status; |
| 154 | +} |
0 commit comments