1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF.  The full HDF copyright notice, including       *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id$ */
15 
16 /*-----------------------------------------------------------------------------
17  * File:    dfanF.c
18  * Purpose: Fortran stubs for annotation routines
19  * Invokes: dfan.c dfkit.c
20  * Contents:
21  *
22  *  daiganl_     : get length of annotation of tag/ref
23  *  daigann_     : get annotation of tag/ref
24  *  daipann_     : put annotation of tag/ref
25  *  dailist_     : get list of refs and labels for a given tag
26  *  dalref_      : return last ref written or read
27  *  daclear_     : reset annotation internal structures
28  *  dfanlastref_ : return last ref written or read
29  *
30  *  dfanaddfds_    : add file description
31  *  dfangetfidlen_ : get length of file id
32  *  dfangetfdslen_ : get length of file description
33  *  dfangetfid_    : get file id
34  *  dfangetfds_    : get file description
35  *  daafds_        : get file description
36  *  dagfidl_       : get file id length
37  *  dagfdsl_       : get file description length
38  *  dagfid_        : get file id
39  *  dagfds_        : get file description
40  *
41  *  daiafid_       : add file id (intermediate routine)
42  *---------------------------------------------------------------------------*/
43 #include "dfan.h"
44 #include "df.h"
45 #include "hproto_fortran.h"
46 
47 /* conventions used in forming names of routines:
48    **
49    **    dfan: hdf annotation routine (<dfan>addfds)
50    **    add:  add item to file       dfan<add>fds
51    **    get:  get item from file     dfan<get>fds
52    **    f:    file                   dfanadd<f>ds
53    **    id:   id                     dfanaddf<id>
54    **    ds:   description            dfanaddf<ds>
55    **    len:  length                 dfanaddfid<len>
56    **    l:    length (short forms)   dagfid<l>
57    **    da:   dfan (short forms)     <da>gfid
58    **    a:    add (short forms)      da<a>fds
59    **    g:    get (short forms)      da<g>fds
60    **    i:    intermediate routine (not in user interface) da<i>afid
61    * */
62 
63 /*---------------------------------------------------------------------------
64 ** Routines for handling tag/ref (not file) annotations
65  *-------------------------------------------------------------------------*/
66 /*---------------------------------------------------------------------------
67  * Name:    daclear
68  * Purpose: Call DFANIclear to clear Lastref and DFANdir[i]
69  * Inputs:  none
70  * Returns: 0 on success, -1 on failure with DFerror set
71  * Users:   HDF Fortran programmers
72  * Invokes: DFSDIclear
73  *-------------------------------------------------------------------------*/
74 
75 FRETVAL(intf)
ndaclear(void)76 ndaclear(void)
77 {
78     return(DFANIclear());
79 }
80 
81 /*-----------------------------------------------------------------------------
82  * Name:    daiganl
83  * Purpose: get length of annotation of tag/ref
84  * Inputs:  filename: name of HDF file
85  *          tag, ref: tag/ref of item of which we want label
86  *          type: DFAN_LABEL if label, DFAN_DESC if description
87  *          fnlen: length of filename
88  * Returns: length of annotation on success, -1 on failure with DFerror set
89  * Users:   HDF HLL users, utilities, other routines
90  * Invokes: DFANIgetannlen, HDf2cstring, DFIfreespace
91  *---------------------------------------------------------------------------*/
92 
93 FRETVAL(intf)
ndaiganl(_fcd filename,intf * tag,intf * ref,intf * type,intf * fnlen)94 ndaiganl(_fcd filename, intf * tag, intf * ref, intf * type, intf * fnlen)
95 {
96     char       *fn;
97     intf        ret;
98 
99     fn = HDf2cstring(filename, (intn) *fnlen);
100     if (!fn)
101 	return(-1);
102     ret = DFANIgetannlen(fn, (uint16) *tag, (uint16) *ref, (intn) *type);
103     HDfree((VOIDP) fn);
104 
105     return (ret);
106 }
107 
108 /*-----------------------------------------------------------------------------
109  * Name:    daigann
110  * Purpose: get annotation of tag/ref
111  * Inputs:  filename: name of HDF file
112  *          tag, ref: tag/ref of item of which we want label
113  *          annotation: space to return label in
114  *          maxlen: size of space to return label in
115  *          type: DFAN_LABEL if label, DFAN_DESC if description
116  *          fnlen: length of filename
117  * Returns: 0 on success, -1 on failure with DFerror set
118  * Users:   HDF HLL users, utilities, other routines
119  * Invokes: DFANIgetann
120  *---------------------------------------------------------------------------*/
121 
122 FRETVAL(intf)
ndaigann(_fcd filename,intf * tag,intf * ref,_fcd annotation,intf * maxlen,intf * type,intf * fnlen)123 ndaigann(_fcd filename, intf * tag, intf * ref, _fcd annotation, intf * maxlen,
124          intf * type, intf * fnlen)
125 {
126     char       *fn;
127     intf        ret;
128 
129     fn = HDf2cstring(filename, (intn) *fnlen);
130     if (!fn)
131 	return(-1);
132     ret = DFANIgetann(fn, (uint16) *tag, (uint16) *ref,
133 		      (uint8 *) _fcdtocp(annotation), (int32) *maxlen, (intn) *type, 1);
134     HDfree((VOIDP) fn);
135 
136     return (ret);
137 }
138 
139 /*-----------------------------------------------------------------------------
140  * Name:    daipann
141  * Purpose: put annotation of tag/ref
142  * Inputs:  filename: name of HDF file
143  *          tag, ref: tag/ref of item of which we want label
144  *          annotation: space to return label in
145  *          annlen: length of annotation
146  *          type: DFAN_LABEL if label, DFAN_DESC if description
147  *          fnlen: length of filename
148  * Returns: 0 on success, -1 on failure with DFerror set
149  * Users:   HDF HLL users, utilities, other routines
150  * Invokes: DFANIgetann
151  *---------------------------------------------------------------------------*/
152 
153 FRETVAL(intf)
ndaipann(_fcd filename,intf * tag,intf * ref,_fcd annotation,intf * annlen,intf * type,intf * fnlen)154 ndaipann(_fcd filename, intf * tag, intf * ref, _fcd annotation,
155          intf * annlen, intf * type, intf * fnlen)
156 {
157     char       *fn;
158     intf        ret;
159 
160     fn = HDf2cstring(filename, (intn) *fnlen);
161     if (!fn)
162 	return(-1);
163     ret = DFANIputann(fn, (uint16) *tag, (uint16) *ref,
164              (uint8 *) _fcdtocp(annotation), (int32) *annlen, (intn) *type);
165     HDfree((VOIDP) fn);
166     return (ret);
167 }
168 
169 /*-----------------------------------------------------------------------------
170  * Name:    dailist
171  * Purpose: Return list of refs and labels for a given tag
172  * Inputs:  filename: name of HDF file
173  *          tag: tag to get list of refs and labels for
174  *          reflist: array to place refs in
175  *          labellist: array of strings to place labels in
176  *          listsize: size of ref and label lists
177  *          maxlen: maximum length allowed for label
178  *          startpos: beginning from the startpos'th entry, upto listsize
179  *              entries will be returned.
180  *          fnlen: length of filename
181  * Returns: number of entries on success, -1 on error with DFerror set
182  * Users:   HDF users, utilities, other routines
183  * Invokes: DFANIlablist
184  * Method:  call DFANIlablist
185  * Remarks: none
186  *---------------------------------------------------------------------------*/
187 
188 FRETVAL(intf)
ndailist(_fcd filename,intf * tag,intf reflist[],_fcd labellist,intf * listsize,intf * maxlen,intf * startpos,intf * fnlen)189 ndailist(_fcd filename, intf * tag, intf reflist[], _fcd labellist,
190          intf * listsize, intf * maxlen, intf * startpos, intf * fnlen)
191 {
192     char       *fn;
193     int         i;
194     intf        nrefs;
195     uint16     *tempreflist;
196 
197     fn = HDf2cstring(filename, (intn) *fnlen);
198     if (!fn)
199 	return(-1);
200 
201     /* create reflist with true uint16s to maintain compatibility
202        ** with machines that allocate more than 16 bits per uint16.
203      */
204     tempreflist = (uint16 *) HDmalloc((size_t) (*listsize) * sizeof(uint16));
205     /* 1 for isfortran */
206     nrefs = DFANIlablist(fn, (uint16) *tag, tempreflist,
207                          (uint8 *) _fcdtocp(labellist),
208                          (int) *listsize, (int) *maxlen, (int) *startpos, 1);
209     if (nrefs < 0)
210         return FAIL;
211 
212     /* move ref numbers into caller's reflist */
213     for (i = 0; i < *listsize; i++)
214         reflist[i] = (intf)tempreflist[i];
215 
216     HDfree((VOIDP) fn);
217     HDfree((VOIDP) tempreflist);
218 
219     return (nrefs);
220 }
221 
222 /*-----------------------------------------------------------------------------
223  * Name:    dalref
224  * Purpose: Return last ref written or read
225  * Inputs:  none
226  * Globals: Lastref
227  * Returns: ref on success, -1 on error with DFerror set
228  * Users:   HDF users, utilities, other routines
229  * Invokes: DFANlastref
230  * Remarks: none
231  *---------------------------------------------------------------------------*/
232 
233 FRETVAL(intf)
ndalref(void)234 ndalref(void)
235 {
236     return ((intf)DFANlastref());
237 }
238 
239 /*-----------------------------------------------------------------------------
240  * Name:    dfanlastref
241  * Purpose: Return last ref written or read
242  * Inputs:  none
243  * Globals: Lastref
244  * Returns: ref on success, -1 on error with DFerror set
245  * Users:   HDF users, utilities, other routines
246  * Invokes: DFANlastref
247  * Remarks: none
248  *---------------------------------------------------------------------------*/
249 
250 FRETVAL(intf)
ndfanlastref(void)251 ndfanlastref(void)
252 {
253     return ((intf)DFANlastref());
254 }
255 
256 /*---------------------------------------------------------------------------
257 ** Routines for handling file annotations
258  *-------------------------------------------------------------------------*/
259 
260 /*-----------------------------------------------------------------------------
261  * Name:    dfanaddfds
262  * Purpose: add file description (Fortran callable C version)
263  * Inputs:  dfile: pointer to HDF file
264  *          desc: description to write to file
265  *          desclen: length of description
266  * Returns: 0 on success, -1 on failure with DFerror set
267  * Users:   HDF HLL users, utilities, other routines
268  * Invokes: DFANaddfileann
269  *---------------------------------------------------------------------------*/
270 
271 FRETVAL(intf)
ndfanaddfds(intf * dfile,_fcd desc,intf * desclen)272 ndfanaddfds(intf * dfile, _fcd desc, intf * desclen)
273 {
274     return (DFANIaddfann(*dfile, _fcdtocp(desc), *desclen, DFAN_DESC));
275 }
276 
277 /*-----------------------------------------------------------------------------
278  * Name:    dfangetfidlen
279  * Purpose: get length of next file ID (Fortran callable C version)
280  * Inputs:  dfile: pointer to HDF file
281  *          isfirst: 1: start with first one; 0: get length of next one
282  * Returns: On success: length of next file ID; On failure: -1, with DFerror set
283  * Users:   HDF HLL users, utilities, other routines
284  * Invokes: DFANIgetfannlen
285  *---------------------------------------------------------------------------*/
286 
287 FRETVAL(intf)
ndfangetfidlen(intf * dfile,intf * isfirst)288 ndfangetfidlen(intf * dfile, intf * isfirst)
289 {
290     return (DFANIgetfannlen(*dfile, DFAN_LABEL, (intn) *isfirst));
291 }
292 
293 /*-----------------------------------------------------------------------------
294  * Name:    dfangetfdslen
295  * Purpose: get length of next file description (Fortran callable C version)
296  * Inputs:  dfile: pointer to HDF file
297  *          isfirst: 1: start with first one; 0: get length of next one
298  * Returns: On success: length of next file ID; On failure: -1, with DFerror set
299  * Users:   HDF HLL users, utilities, other routines
300  * Invokes: DFANIgetfannlen
301  *---------------------------------------------------------------------------*/
302 
303 FRETVAL(intf)
ndfangetfdslen(intf * dfile,intf * isfirst)304 ndfangetfdslen(intf * dfile, intf * isfirst)
305 {
306     return (DFANIgetfannlen(*dfile, DFAN_DESC, (intn) *isfirst));
307 }
308 
309 /*-----------------------------------------------------------------------------
310  * Name:    dfangetfid
311  * Purpose: get file ID (Fortran callable C version)
312  * Inputs:  dfile: pointer to HDF file
313  *          desc: description to write to file
314  *          desclen: length of description
315  * Returns: 0 on success, -1 on failure with DFerror set
316  * Users:   HDF HLL users, utilities, other routines
317  * Invokes: DFANgetfann
318  *---------------------------------------------------------------------------*/
319 
320 FRETVAL(intf)
ndfangetfid(intf * dfile,_fcd id,intf * maxlen,intf * isfirst)321 ndfangetfid(intf * dfile, _fcd id, intf * maxlen, intf * isfirst)
322 {
323     return (DFANIgetfann(*dfile, _fcdtocp(id), *maxlen,
324                          DFAN_LABEL, (intn) *isfirst));
325 }
326 
327 /*-----------------------------------------------------------------------------
328  * Name:    dfangetfds
329  * Purpose: get file description (Fortran callable C version)
330  * Inputs:  dfile: pointer to HDF file
331  *          desc: description to write to file
332  *          desclen: length of description
333  * Returns: 0 on success, -1 on failure with DFerror set
334  * Users:   HDF HLL users, utilities, other routines
335  * Invokes: DFANgetfann
336  *---------------------------------------------------------------------------*/
337 
338 FRETVAL(intf)
ndfangetfds(intf * dfile,_fcd id,intf * maxlen,intf * isfirst)339 ndfangetfds(intf * dfile, _fcd id, intf * maxlen, intf * isfirst)
340 {
341     return (DFANIgetfann(*dfile, _fcdtocp(id), *maxlen,
342                          DFAN_DESC, (intn) *isfirst));
343 }
344 
345 /*-----------------------------------------------------------------------------
346 ** Versions with short names
347 **---------------------------------------------------------------------------*/
348 
349 /*-----------------------------------------------------------------------------
350  * Name:    daafds
351  * Purpose: add file description (short form of DFANaddfds; Fortran callable)
352  * Inputs:  dfile: pointer to HDF file
353  *          desc: description to write to file
354  *          desclen: length of description
355  * Returns: 0 on success, -1 on failure with DFerror set
356  * Users:   HDF HLL users, utilities, other routines
357  * Invokes: DFANaddfileann
358  *---------------------------------------------------------------------------*/
359 
360 FRETVAL(intf)
ndaafds(intf * dfile,_fcd desc,intf * desclen)361 ndaafds(intf * dfile, _fcd desc, intf * desclen)
362 {
363     return (DFANIaddfann(*dfile, _fcdtocp(desc), *desclen, DFAN_DESC));
364 }
365 
366 /*-----------------------------------------------------------------------------
367  * Name:    dagfidl
368  * Purpose: get length of next file ID
369  * Inputs:  dfile: pointer to HDF file
370  *          isfirst: 1: start with first one; 0: get length of next one
371  * Returns: On success: length of next file ID; On failure: -1, with DFerror set
372  * Users:   HDF HLL users, utilities, other routines
373  * Invokes: DFANIgetfannlen
374  *---------------------------------------------------------------------------*/
375 
376 FRETVAL(intf)
ndagfidl(intf * dfile,intf * isfirst)377 ndagfidl(intf * dfile, intf * isfirst)
378 {
379     return (DFANIgetfannlen(*dfile, DFAN_LABEL, (intn) *isfirst));
380 }
381 
382 /*-----------------------------------------------------------------------------
383  * Name:    dagfdsl
384  * Purpose: get length of next file description (Fortran callable C version)
385  * Inputs:  dfile: pointer to HDF file
386  *          isfirst: 1: start with first one; 0: get length of next one
387  * Returns: On success: length of next file ID; On failure: -1, with DFerror set
388  * Users:   HDF HLL users, utilities, other routines
389  * Invokes: DFANIgetfannlen
390  *---------------------------------------------------------------------------*/
391 
392 FRETVAL(intf)
ndagfdsl(intf * dfile,intf * isfirst)393 ndagfdsl(intf * dfile, intf * isfirst)
394 {
395     return (DFANIgetfannlen(*dfile, DFAN_DESC, (intn) *isfirst));
396 }
397 
398 /*-----------------------------------------------------------------------------
399  * Name:    dagfid
400  * Purpose: get file ID (short form of DFANgetfid; Fortran callable version)
401  * Inputs:  dfile: pointer to HDF file
402  *          desc: description to write to file
403  *          desclen: length of description
404  * Returns: 0 on success, -1 on failure with DFerror set
405  * Users:   HDF HLL users, utilities, other routines
406  * Invokes: DFANIgetfann
407  *---------------------------------------------------------------------------*/
408 
409 FRETVAL(intf)
ndagfid(intf * dfile,_fcd id,intf * maxlen,intf * isfirst)410 ndagfid(intf * dfile, _fcd id, intf * maxlen, intf * isfirst)
411 {
412     return (DFANIgetfann(*dfile, _fcdtocp(id), *maxlen,
413                          DFAN_LABEL, (intn) *isfirst));
414 }
415 
416 /*-----------------------------------------------------------------------------
417  * Name:    dagfds
418  * Purpose: get file description
419  *          (short form of DFANgetfds; Fortran callable C version)
420  * Inputs:  dfile: pointer to HDF file
421  *          desc: description to write to file
422  *          desclen: length of description
423  * Returns: 0 on success, -1 on failure with DFerror set
424  * Users:   HDF HLL users, utilities, other routines
425  * Invokes: DFANgetfann
426  *---------------------------------------------------------------------------*/
427 
428 FRETVAL(intf)
ndagfds(intf * dfile,_fcd id,intf * maxlen,intf * isfirst)429 ndagfds(intf * dfile, _fcd id, intf * maxlen, intf * isfirst)
430 {
431     return (DFANIgetfann(*dfile, _fcdtocp(id), *maxlen,
432                          DFAN_DESC, (intn) *isfirst));
433 }
434 
435 /*-----------------------------------------------------------------------------
436 ** Intermediate routines called from user's fortran routines
437 **---------------------------------------------------------------------------*/
438 
439 /*-----------------------------------------------------------------------------
440  * Name:    daiafid
441  * Purpose: intermediate routine to add file ID (Fortran callable C version)
442  * Inputs:  dfile: pointer to HDF file
443  *          id: ID to write to file
444  *          idlen: length of ID string
445  * Returns: 0 on success, -1 on failure with DFerror set
446  * Users:   Fortran user routines DFANaddfid and daafid
447  * Invokes: DFANaddfann
448  *---------------------------------------------------------------------------*/
449 
450 FRETVAL(intf)
ndaiafid(intf * dfile,_fcd id,intf * idlen)451 ndaiafid(intf * dfile, _fcd id, intf * idlen)
452 {
453     return (DFANIaddfann(*dfile, _fcdtocp(id), *idlen, DFAN_LABEL));
454 }
455