-
Notifications
You must be signed in to change notification settings - Fork 1
/
datImportFloc.c
149 lines (124 loc) · 4.68 KB
/
datImportFloc.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
/*
*+
* Name:
* datImportFloc
* Purpose:
* Import a Fortran HDS locator buffer into C
* Invocation:
* datImportFloc( const char flocator[DAT__SZLOC], int loc_length, HDSLoc **clocator, int * status);
* Description:
* This function should be used to convert a Fortran HDS locator
* (implemented as a string buffer) to a C locator struct.
* This function is also available via the
* HDS_IMPORT_FLOCATOR macro defined in hds_fortran.h.
* Arguments
* flocator = const char [DAT__SZLOC] (Given)
* Fortran character string buffer. Should be at least DAT__SZLOC
* characters long.
* loc_length = int (Given)
* Size of Fortran character buffer. Sanity check. Should be DAT__SZLOC.
* clocator = HDSLoc ** (Returned)
* Assigned to the C version of the Fortran locator.
* Must be NULL on entry. Memory is not allocated by this routine
* and the locator must not be annulled whilst the Fortran
* locator is still being used.
* status = int * (Given and Returned)
* Inherited status. Attempts to excecute even if status is not SAI__OK
* on entry.
* Authors:
* Tim Jenness (Cornell)
* History:
* 2014-09-07 (TIMJ):
* Initial version
* Notes:
* - A NULL pointer is returned if the supplied locator is DAT__NOLOC.
* - Does check the contents of the locator for validity to avoid
* uncertainty when receiving uninitialized memory.
* - The expectation is that this routine is used solely for C
* interfaces to Fortran library routines.
* - The locator returned by this routine has not been allocated
* independently. It is the same locator tracked by the Fortran
* layer. Do not annul this locator if the Fortran layer is still
* tracking it.
* See Also:
* - datExportFloc
* Copyright:
Copyright (C) 2010 Science & Technology Facilities Council.
All Rights Reserved.
* Copyright (C) 2005-2006 Particle Physics and Astronomy Research Council.
* 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 2 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 <stdlib.h>
#include <string.h>
#include "ems.h"
#include "sae_par.h"
#include "hds1.h"
#include "dat1.h"
#include "dat_err.h"
#include "hds_fortran.h"
void datImportFloc ( const char flocator[DAT__SZLOC], int loc_length, HDSLoc ** clocator, int * status) {
int lstat;
/* Check that we have a null pointer for HDSLoc */
if ( *clocator != NULL ) {
if( *status == SAI__OK ) {
*status = DAT__WEIRD;
emsRep( "datImportFloc", "datImportFloc: Supplied C locator is non-NULL",
status);
}
return;
}
/* For these HDS/HDF5 locators that are either hex pointers or "<xxx_xxx>" strings
we can validate them immediately */
if (flocator[0] != '0' && flocator[0] != '<') {
if (*status == SAI__OK) {
char flocstr[DAT__SZLOC+1];
*status = DAT__WEIRD;
memmove( flocstr, flocator, DAT__SZLOC);
emsRepf( "datImportFloc_2",
"datImportFloc: Supplied Fortran locator looks to be corrupt: '%s'",
status, flocstr );
}
return;
}
/* Return the NULL pointer unchanged if the supplied locator is DAT__NOLOC. */
if( strncmp( DAT__NOLOC, flocator, loc_length ) ) {
/* Now import the Fortran locator - this will work even if status
is bad on entry but it is possible for this routine to set status
as well. We need to be able to determine whether the status was
set bad by this routine, since that will result in garbage in the
HDS locator. */
emsMark();
lstat = SAI__OK;
*clocator = dat1ImportFloc( flocator, loc_length, &lstat);
if (lstat != SAI__OK) {
/* Annul all this if status was already bad, since we do not
want the extra meaningless messages on the stack. If status
was good, we retain everything */
if (*status == SAI__OK) {
*status = lstat;
} else {
emsAnnul(&lstat);
}
}
emsRlse();
}
return;
}