-
Notifications
You must be signed in to change notification settings - Fork 1
/
dat1DumpLoc.c
286 lines (232 loc) · 8.1 KB
/
dat1DumpLoc.c
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
/*
*+
* Name:
* dat1DumpLoc
* Purpose:
* Dump useful information about a locator
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* dat1DumpLoc( const HDSLoc * locator, int * status );
* Arguments:
* locator = const HDSLoc * (Given)
* Locator to be summarized.
* status = int* (Given and Returned)
* Pointer to global status.
* Description:
* Write to standard output information about the state of a locator.
* Authors:
* TIMJ: Tim Jenness (Cornell)
* {enter_new_authors_here}
* History:
* 2014-08-26 (TIMJ):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2014 Cornell University
* All Rights Reserved.
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* Bugs:
* {note_any_bugs_here}
*-
*/
#include <stdio.h>
#include "hdf5.h"
#include "star/one.h"
#include "ems.h"
#include "hds1.h"
#include "dat1.h"
#include "hds.h"
#include "dat_err.h"
#include "sae_par.h"
static void dump_dataspace_info( hid_t dataspace_id, const char * label, int *status);
static void dump_handle( const HDSLoc *loc, int *status );
static void dump_hdsFile( const HDSLoc *loc, int *status );
void dat1DumpLoc( const char *text, const HDSLoc* locator, int * status ) {
char * name_str = NULL;
char * file_str = NULL;
ssize_t ll;
hid_t objid = 0;
hid_t dspace_id = 0;
if (*status != SAI__OK) return;
objid = dat1RetrieveIdentifier( locator, status );
if (objid > 0) {
name_str = dat1GetFullName( objid, 0, &ll, status );
file_str = dat1GetFullName( objid, 1, &ll, status );
} else if (locator->file_id > 0) {
file_str = dat1GetFullName( locator->file_id, 1, &ll, status );
}
if( text ) printf("%s\n", text );
printf("Dump of locator %p at %s (%s)\n", locator,
(name_str ? name_str : "none"),
(file_str ? file_str : "no file"));
printf("- File: %d; Group %d; Dataspace: %d; Dataset: %d; Data Type: %d\n",
locator->file_id, locator->group_id, locator->dataspace_id,
locator->dataset_id, locator->dtype);
printf("- Vectorized: %zu; Bytes mapped: %zu, Array mapped: %p (%s)\n",
locator->vectorized, locator->bytesmapped, locator->regpntr,
(locator->uses_true_mmap ? "file" : "memory"));
printf("- Is sliced: %d; Primary: %s; Group name: '%s'\n", locator->isslice,
(locator->isprimary ? "yes" : "no"), locator->grpname);
printf("- Is a discontiguous slice: %s\n", (locator->isdiscont ? "yes" : "no") );
if (locator->dataspace_id > 0) {
dump_dataspace_info( locator->dataspace_id, "Locator associated", status);
dspace_id = H5Dget_space( locator->dataset_id );
dump_dataspace_info( dspace_id, "Dataset associated", status );
H5Sclose( dspace_id );
}
dump_handle( locator, status );
dump_hdsFile( locator, status );
if (file_str) MEM_FREE(file_str);
if (name_str) MEM_FREE(name_str);
if( locator->next ) {
objid = dat1RetrieveIdentifier( locator->next, status );
if (objid > 0) {
name_str = dat1GetFullName( objid, 0, &ll, status );
file_str = dat1GetFullName( objid, 1, &ll, status );
} else if (locator->next->file_id > 0) {
file_str = dat1GetFullName( locator->next->file_id, 1, &ll, status );
}
printf("- Next locator %p at %s (%s)\n", locator->next,
(name_str ? name_str : "none"),
(file_str ? file_str : "no file"));
if (file_str) MEM_FREE(file_str);
if (name_str) MEM_FREE(name_str);
} else {
printf("- Next locator: none\n");
}
if( locator->prev ) {
objid = dat1RetrieveIdentifier( locator->prev, status );
if (objid > 0) {
name_str = dat1GetFullName( objid, 0, &ll, status );
file_str = dat1GetFullName( objid, 1, &ll, status );
} else if (locator->prev->file_id > 0) {
file_str = dat1GetFullName( locator->prev->file_id, 1, &ll, status );
}
printf("- Previous locator %p at %s (%s)\n", locator->prev,
(name_str ? name_str : "none"),
(file_str ? file_str : "no file"));
if (file_str) MEM_FREE(file_str);
if (name_str) MEM_FREE(name_str);
} else {
printf("- Previous locator: none\n");
}
return;
}
static void dump_dataspace_info( hid_t dataspace_id, const char * label, int *status) {
hsize_t * blockbuf = NULL;
if (dataspace_id > 0) {
hsize_t h5dims[DAT__MXDIM];
hssize_t nblocks = 0;
int i;
int rank;
hsize_t nelem = 1;
CALLHDFE( int,
rank,
H5Sget_simple_extent_dims( dataspace_id, h5dims, NULL ),
DAT__DIMIN,
emsRep("datshape_1", "datShape: Error obtaining shape of object",
status)
);
nblocks = H5Sget_select_hyper_nblocks( dataspace_id );
if (nblocks < 0) nblocks = 0; /* easier to understand */
printf("- %s dataspace has rank: %d and %d hyperslab%s\n", label, rank, (int)nblocks,
(nblocks == 1 ? "" : "s") );
printf(" Dataspace dimensions (HDF5 order): ");
for (i=0; i<rank; i++) {
printf(" %zu", (size_t)h5dims[i]);
nelem *= h5dims[i];
}
printf(" (%zu element%s)\n",(size_t)nelem, (nelem == 1 ? "" : "s"));
if (nblocks > 0) {
hssize_t n = 0;
herr_t h5err = 0;
hsize_t nelem = 1;
blockbuf = MEM_MALLOC( nblocks * rank * 2 * sizeof(*blockbuf) );
CALLHDF( h5err,
H5Sget_select_hyper_blocklist( dataspace_id, 0, nblocks, blockbuf ),
DAT__DIMIN,
emsRep("dat1DumpLoc_2", "dat1DumpLoc: Error obtaining shape of slice", status )
);
for (n=0; n<nblocks; n++) {
/* The buffer is returned in form:
ndim start coordinates, then ndim opposite corner coordinates
and repeats for each block
*/
nelem = 1;
printf(" Hyperslab #%d (0-based):", (int)n);
for (i = 0; i<rank; i++) {
hsize_t start;
hsize_t opposite;
size_t offset = 2 * n * rank;
start = blockbuf[offset+i];
opposite = blockbuf[offset+i+rank];
/* So update the shape to account for the slice: HDS is 1-based */
printf(" %zu:%zu", (size_t)start, (size_t)opposite);
nelem *= (opposite-start+1);
}
printf(" (%zu element%s)\n",(size_t)nelem, (nelem == 1 ? "" : "s"));
}
}
}
CLEANUP:
if (blockbuf) MEM_FREE(blockbuf);
return;
}
static void dump_handle( const HDSLoc *loc, int *status ){
Handle *handle;
const char *name;
if( *status != SAI__OK || !loc ) return;
printf("- Handle: ");
handle = loc->handle;
while( handle ) {
name = handle->name ? handle->name : "<>";
if( handle->erase ) {
printf("%s(%p,erase on close)", name, handle );
} else {
printf("%s(%p)", name, handle );
}
handle = handle->parent;
if( handle ) printf("." );
}
printf("\n" );
}
static void dump_hdsFile( const HDSLoc *loc, int *status ){
HdsFile *hdsFile;
int np, ns;
if( *status != SAI__OK || !loc ) return;
hdsFile = loc->hdsFile;
if( hdsFile ){
np = 0;
loc = hdsFile->primhead;
while( loc ) {
np++;
loc = loc->prev;
}
ns = 0;
loc = hdsFile->sechead;
while( loc ) {
ns++;
loc = loc->prev;
}
printf("- HdsFile: nprim: %d nsec: %d %s\n", np, ns, hdsFile->path );
} else {
printf("- HdsFile: <null>\n");
}
}