Skip to content

Commit f9183b7

Browse files
committed
Add datDsame - checks if two objects use same data representation
An easier fix to the problem of getting kappa:native working than implementing datDrep.
1 parent fb9472e commit f9183b7

9 files changed

+201
-2
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ datClone.c \
6565
datCopy.c \
6666
datCoerc.c \
6767
datDrep.c \
68+
datDsame.c \
6869
datErase.c \
6970
datErmsg.c \
7071
datExportFloc.c \

component.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- component.xml. Generated from component.xml.in by configure. -->
44

55
<component id="hds-v5" support="S">
6-
<version>1.0-1</version>
6+
<version>1.0-2</version>
77
<path>libext/hds-v5</path>
88
<description>Hierarchical Data System layered on HDF5</description>
99
<abstract>

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script
22
AC_REVISION($Revision$)
33

44
dnl Initialisation: package name and version number
5-
AC_INIT([hds-v5],[1.0-1],[starlink@jiscmail.ac.uk])
5+
AC_INIT([hds-v5],[1.0-2],[starlink@jiscmail.ac.uk])
66
AC_CONFIG_AUX_DIR([build-aux])
77

88
dnl Require autoconf-2.50 at least

datDsame.c

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
}

dat_err.msg

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ FILFM <File not in the expected format>
5858
THREAD <Object not locked by current thread>
5959
MUTEX <Failed to initialise mutex>
6060
NOTIM <Not implemented>
61+
NOTPR <Object is not primitive>
6162
.END

fortran_interface.c

+30
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,36 @@ F77_SUBROUTINE(dat_drep)( CHARACTER(locator),
366366
}
367367
}
368368

369+
F77_SUBROUTINE(dat_dsame)( CHARACTER(loc1),
370+
CHARACTER(loc2),
371+
LOGICAL(same),
372+
INTEGER(status )
373+
TRAIL(loc1)
374+
TRAIL(loc2) )
375+
{
376+
377+
/*=============================================================*/
378+
/* DAT_DSAME - Are two primitive data representations the same?*/
379+
/*=============================================================*/
380+
381+
/* Local variables. */
382+
HDSLoc *loc1_c = NULL;
383+
HDSLoc *loc2_c = NULL;
384+
hdsbool_t same_c;
385+
386+
/* Import the locator strings */
387+
datImportFloc( loc1, loc1_length, &loc1_c, status);
388+
datImportFloc( loc2, loc2_length, &loc2_c, status);
389+
390+
/* Call pure C routine */
391+
datDsame( loc1_c, loc2_c, &same_c, status);
392+
393+
if( same_c )
394+
*same = F77_TRUE;
395+
else
396+
*same = F77_FALSE;
397+
}
398+
369399
F77_SUBROUTINE(dat_erase)( CHARACTER(locator),
370400
CHARACTER(name),
371401
F77_INTEGER_TYPE *status

hds.h

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ datCopy(const HDSLoc *locator1, const HDSLoc *locator2, const char *name_c, int
101101
int
102102
datDrep(const HDSLoc *locator, char **format_str, char **order_str, int *status);
103103

104+
/*=============================================================*/
105+
/* datDsame - Are two primitive data representations the same? */
106+
/*=============================================================*/
107+
int
108+
datDsame(const HDSLoc *loc1, const HDSLoc *loc2, hdsbool_t *same, int *status);
109+
104110
/*========================================*/
105111
/* datErase - Erase object */
106112
/*========================================*/

hds_v5.h

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ datCopy_v5(const HDSLoc *locator1, const HDSLoc *locator2, const char *name_c, i
9797
int
9898
datDrep_v5(const HDSLoc *locator, char **format_str, char **order_str, int *status);
9999

100+
/*=============================================================*/
101+
/* datDsame - Are two primitive data representations the same? */
102+
/*=============================================================*/
103+
int
104+
datDsame_v5(const HDSLoc *loc1, const HDSLoc *loc2, hdsbool_t *same, int *status);
105+
100106
/*========================================*/
101107
/* datErase - Erase object */
102108
/*========================================*/

hds_v5_map.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define datCoerc datCoerc_v5
1111
#define datCopy datCopy_v5
1212
#define datDrep datDrep_v5
13+
#define datDsame datDsame_v5
1314
#define datErase datErase_v5
1415
#define datErmsg datErmsg_v5
1516
#define datFind datFind_v5

0 commit comments

Comments
 (0)