-
Notifications
You must be signed in to change notification settings - Fork 51
/
votParse.c
4016 lines (3286 loc) · 103 KB
/
votParse.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* VOTPARSE.C -- Public interface procedures for the libVOTable parser.
*
* @file votParse.c
* @author Mike Fitzpatrick and Eric Timmermann
* @date 8/03/09
*
* @brief Public interface procedures for the libVOTable parser.
*/
#include <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE
#include <string.h>
#include <expat.h>
#include <unistd.h>
#include <assert.h>
#include <ctype.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include "votParseP.h"
#include "votParse.h"
#ifdef HAVE_CFITSIO
#include "fitsio.h"
#endif
#define BUFSIZE 4096
extern char *strcasestr();
/* Private procedures
*/
static Element *vot_elementDup (handle_t element_h);
static handle_t vot_nodeCreate (int type);
static char *vot_deWS (char *in);
#ifdef USE_VALIDITY
static int vot_validParents (int type);
static int vot_validChildren (int type);
#endif
static void vot_attachToNode (handle_t parent, handle_t new);
static void vot_attachSibling (handle_t big_brother, handle_t new);
static void vot_dumpXML (Element *node, int level, int indent, FILE *fd);
static void vot_htmlHeader (FILE *fd, char *fname);
static void vot_htmlTableMeta (FILE *fd, handle_t res, char *ifname);
static void vot_htmlTableData (FILE *fd, handle_t res, char *ifname);
static void vot_htmlFooter (FILE *fd);
static int vot_simpleGetURL (char *url, char *ofname);
#ifdef USE_DEBUG
static void vot_printData (Element *tdata);
static void votBob (void);
#endif
/** *************************************************************************
* Public Interface
*
* vot = vot_openVOTABLE (filename|str|NULL)
* vot_closeVOTABLE (vot)
*
* res = vot_getRESOURCE (vot|res)
* tab = vot_getTABLE (res)
* field = vot_getFIELD (tab)
*
* data = vot_getDATA (tab)
*
* tdata = vot_getTABLEDATA (data) // data elements
* tr = vot_getTR (tdata)
* td = vot_getTD (tr)
* bin = vot_getBINARY (data)
* bin = vot_getBINARY2 (data)
* fits = vot_getFITS (data)
*
* group = vot_getGROUP (vot|res|tab|group)
* fldref = vot_getFIELDRef (group)
* parref = vot_getPARAMRef (group)
*
* desc = vot_getDESCRIPTION (handle)
* param = vot_getPARAM (handle)
* info = vot_getINFO (handle)
* stream = vot_getSTREAM (bin|fits)
*
* val = vot_getVALUES (field|param|info)
* min = vot_getMIN (val)
* max = vot_getMAX (val)
* opt = vot_getOPTION (val)
*
* link = vot_getLINK (res|info|param|field|table)
*
* sys = vot_getCOOSYS (vot) // Compatability
*
*
* h = vot_newRESOURCE (handle_t parent_h)
* h = vot_newTABLE (handle_t parent_h)
* h = vot_newFIELD (handle_t parent_h)
* h = vot_newDATA (handle_t parent_h)
* h = vot_newTABLEDATA (handle_t parent_h)
* h = vot_newTR (handle_t parent_h)
* h = vot_newTD (handle_t parent_h)
* h = vot_newBINARY (handle_t parent_h)
* h = vot_newBINARY2 (handle_t parent_h)
* h = vot_newFITS (handle_t parent_h)
* h = vot_newGROUP (handle_t parent_h)
* h = vot_newFIELDRef (handle_t parent_h)
* h = vot_newPARAMRef (handle_t parent_h)
* h = vot_newDESCRIPTION (handle_t parent_h)
* h = vot_newPARAM (handle_t parent_h)
* h = vot_newINFO (handle_t parent_h)
* h = vot_newSTREAM (handle_t parent_h)
* h = vot_newVALUES (handle_t parent_h)
* h = vot_newMIN (handle_t parent_h)
* h = vot_newMAX (handle_t parent_h)
* h = vot_newOPTION (handle_t parent_h)
* h = vot_newLINK (handle_t parent_h)
* h = vot_newCOOSYS (handle_t parent_h)
*
*
* handle = vot_newNode (parent, type)
* vot_freeNode (node)
* vot_deleteNode (node)
* vot_attachNode (parent, new)
* handle = vot_copyElement (handle_t source_h, handle_t parent_h)
*
*
* val = vot_getValue (handle)
* stat = vot_setValue (handle, value)
*
* attr = vot_getAttr (handle, attr)
* stat = vot_setAttr (handle, attr, value)
*
*
* type = vot_getDATAType (data) // Utilities
* typeStr = vot_getDATATypeString (data)
*
* nc = vot_getNCols (tdata_h)
* nr = vot_getNRows (tdata_h)
* val = vot_getTableCell (tdata_h, row, col)
* stat = vot_sortTable (tdata_h, col, string_sort, sort_order)
*
* len = vot_getLength (elem_h)
* N = vot_getNumberOf (elem_h, type)
*
* col = vot_colByName (tab_h, name, alt)
* col = vot_colByUCD (tab_h, name, alt)
* col = vot_colByID (tab_h, name, alt)
*
* handle = vot_findByAttr (parent, name, value)
* handle *vot_findInGroup (group, type)
* handle = vot_getNext (handle)
* handle = vot_getSibling (handle)
* handle = vot_getChild (handle)
* handle = vot_getParent (handle)
* handle = vot_getChildOfType (handle, int type)
*
* int = vot_valueOf (handle)
* type = vot_typeOf (handle)
* vot_setWarnings (value)
*
* vot_writeVOTable (handle, char *fname, int indent)
* vot_writeHTML (handle, char *fname)
* vot_writeSHTML (handle, char *fname)
* vot_writeFITS (handle, char *fname)
* vot_writeASV (handle, char *fname, int hdr)
* vot_writeBSV (handle, char *fname, int hdr)
* vot_writeCSV (handle, char *fname, int hdr)
* vot_writeTSV (handle, char *fname, int hdr)
* vot_writeDelimited (handle, char *fname, char delim, int hdr)
*
*
** *************************************************************************/
Stack *element_stack = NULL; /* This holds a stack of elements. Should be
* empty most of the time.
*/
Element *vot_struct = NULL; /* This will hold all the VOTs. The first
* Element in this structure is a ROOT Element.
*/
char *votELevel = ""; /* Error Message Level
*/
int votWarn = 0; /* Warn about parsing issues. Values:
* 0 No messages (lax parsing)
* 1 Warning messages
* 2 Strict parsing
*/
/**
* vot_openVOTABLE -- Parse a VOTable and return a handle to it
*
* @brief Parse a VOTable and return a handle to it
* @fn handle_t vot_openVOTABLE (char *arg)
*
* @param arg The source of the table
* @return The root node handle of the VOTable
*/
handle_t
vot_openVOTABLE (char *arg)
{
FILE *fd = (FILE *) NULL;
Element *my_element;
char buf[BUFSIZE], *ip, urlFname[BUFSIZE];
size_t len, nleft = 0, fsize = -1, nread = 0;
int done, ret_handle, nerrs;
XML_Parser parser;
struct stat st;
memset (buf, 0, BUFSIZE);
memset (urlFname, 0, BUFSIZE);
vot_newHandleTable (); /* initialize the handle table */
if (element_stack == NULL)
element_stack = vot_newStack ();
if (vot_struct == NULL)
vot_struct = vot_newElem (TY_ROOT);
votPush (element_stack, vot_struct);
if (arg == NULL) {
my_element = vot_newElem (TY_VOTABLE);
if (vot_struct->child)
vot_struct->last_child->next = my_element;
else
vot_struct->child = my_element;
vot_struct->last_child = my_element;
vot_clearStack (element_stack);
my_element->parent = vot_struct;
return (vot_setHandle (my_element));
} else if (strncmp (arg, "http://", 7) == 0) { /* input from URL */
extern int vot_getURL (char *url, char *fname, int *nbytes);
int tfd = 0;
/* Open a temp file for the downloaded URL.
*/
strcpy (urlFname, "/tmp/votXXXXXX");
if ((tfd = mkstemp (urlFname) < 0))
strcpy (urlFname, "/tmp/votquery");
close (tfd);
nerrs = vot_simpleGetURL (arg, urlFname);
if ( !(fd = fopen (urlFname, "r")) ) {
fprintf (stderr, "Unable to open url '%s'\n", arg);
return (0); /* cannot open file error */
}
fstat (fileno(fd), &st);
fsize = (size_t) st.st_size;
} else if (strcmp (arg, "-") == 0 || strncasecmp (arg, "stdin", 5) == 0) {
/* input from stdin */
fd = stdin;
fsize = -1;
} else if (strncmp (arg, "file://", 7) == 0) { /* input from URL */
len = strlen (&arg[7]);
if (!(fd = fopen (&arg[7], "r"))) {
fprintf (stderr, "Unable to open input file '%s'\n", &arg[7]);
return (0); /* cannot open file error */
}
fstat (fileno(fd), &st);
fsize = (size_t) st.st_size;
} else if (access (arg, R_OK) == 0) { /* input from file */
len = strlen (arg);
if (!(fd = fopen (arg, "r"))) {
fprintf (stderr, "Unable to open input file '%s'\n", arg);
return (0); /* cannot open file error */
}
fstat (fileno(fd), &st);
fsize = (size_t) st.st_size;
} else if (strcasestr (arg, "votable")) {
/* input argument is XML string */
ip = arg;
len = strlen (arg);
} else {
fprintf (stderr, "openVOTable(): Invalid input arg '%s'\n", arg);
return (-1);
}
/* Create the parser and set the input handlers.
*/
parser = XML_ParserCreate (NULL);
XML_SetElementHandler (parser, vot_startElement, vot_endElement);
XML_SetCdataSectionHandler (parser, vot_startCData, vot_endCData);
XML_SetCharacterDataHandler (parser, vot_charData);
ip = arg; /* initialize */
done = 0;
nleft = fsize;
nread = 0;
if (fd) {
do {
memset (buf, 0, BUFSIZE);
len = fread (buf, 1, sizeof(buf), fd);
if (nread == 0) {
/* Check that this actually is a VOTable.
*/
if (strcasestr (buf, "<votable") == (char *) NULL) {
if (fd != stdin) fclose (fd);
if (urlFname[0]) unlink (urlFname);
return (-1); /* not a votable */
}
}
nread += len;
if (fd != stdin) {
nleft -= len;
done = nread >= fsize;
} else
done = (len == 0 ? feof (stdin) : 0);
if (done && buf[len-1] == '\0') /* trim trailing null */
while (len && !buf[len-1])
len--;
if (done && buf[len-1] != '\n') /* no newline on file */
buf[len] = '\n';
if (!XML_Parse (parser, buf, len, done)) {
fprintf (stderr, "Error: %s at line %d\n",
XML_ErrorString (XML_GetErrorCode (parser)),
(int)XML_GetCurrentLineNumber (parser));
return (0); /* parse error */
}
} while (!done);
} else {
if (!XML_Parse (parser, ip, len, 1)) {
fprintf (stderr, "Error: %s at line %d\n",
XML_ErrorString (XML_GetErrorCode (parser)),
(int)XML_GetCurrentLineNumber (parser));
return (0); /* parse error */
}
}
XML_ParserFree (parser);
if (fd && fd != stdin)
fclose (fd);
if (urlFname[0])
unlink (urlFname);
vot_clearStack (element_stack);
ret_handle = vot_lookupHandle (vot_struct->last_child);
return (ret_handle);
}
/**
* vot_closeVOTABLE -- Destroy the root node and all of it's children.
*
* @brief Destroy the root node and all of it's children.
* @fn vot_closeVOTABLE (handle_t vot)
*
* @param vot A handle to the Element that you want deleted
* @return nothing
*
* @warning Destroys the node and all of it's children.
*/
void
vot_closeVOTABLE (handle_t vot)
{
Element *elem = vot_getElement (vot);
int my_type = vot_elemType (elem);
if ((my_type != TY_VOTABLE)) {
votEmsg ("closeVOTABLE() arg must be a VOTABLE tag\n");
return;
}
vot_deleteNode (vot);
}
/*****************************************************************************
* Routines to get nodes of a VOTable as a handle.
****************************************************************************/
/**
* vot_getRESOURCE -- Gets the RESOURCE node from the parent handle
*
* @brief Gets the RESOURCE node from the parent handle
* @fn handle_t vot_getRESOURCE (handle_t handle)
*
* @param handle Parent handle containing a RESOURCE
* @return A handle to the first RESOURCE node, or zero
*/
handle_t
vot_getRESOURCE (handle_t handle)
{
Element *elem, *child;
int my_type;
/* Get Element pointer for the element.
*/
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
/* Make sure it's a node that can have a RESOURCE.
*/
if ((my_type != TY_VOTABLE) && (my_type != TY_RESOURCE)) {
votEmsg ("RESOURCE must be child of a RESOURCE or VOTABLE tag\n");
return (0);
}
/* Go through children until a RESOURCE is found.
*/
for (child = elem->child; child; child = child->next)
if (child->type == TY_RESOURCE)
break;
/* If nothing found return 0, if found return handle to found Element.
*/
return (vot_lookupHandle (child));
}
/**
* vot_getTABLE -- Gets the TABLE node from the parent handle
*
* @brief Gets the TABLE node from the parent handle
* @fn handle_t vot_getTABLE (handle_t handle)
*
* @param handle Parent handle containing a TABLE
* @return A handle to the first TABLE node, or zero
*/
handle_t
vot_getTABLE (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_RESOURCE) {
votEmsg ("TABLE must be child of a RESOURCE tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_TABLE)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getFIELD -- Gets the FIELD node from the parent handle
*
* @brief Gets the FIELD node from the parent handle
* @fn handle_t vot_getFIELD (handle_t handle)
*
* @param handle Parent handle containing a FIELD
* @return A handle to the first FIELD node, or zero
*/
handle_t
vot_getFIELD (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_TABLE) {
votEmsg ("FIELD must be child of a TABLE tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_FIELD)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getDATA -- Gets the DATA node from the parent handle
*
* @brief Gets the DATA node from the parent handle
* @fn handle_t vot_getDATA (handle_t handle)
*
* @param handle Parent handle containing a DATA
* @return A handle to the first DATA node, or zero
*/
handle_t
vot_getDATA (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_TABLE) {
votEmsg ("DATA must be child of a TABLE tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_DATA)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getTABLEDATA -- Gets the TABLEDATA node from the parent handle
*
* @brief Gets the TABLEDATA node from the parent handle
* @fn handle_t vot_getTABLEDATA (handle_t handle)
*
* @param handle Parent handle containing a TABLEDATA
* @return A handle to the first TABLEDATA node, or zero
*/
handle_t
vot_getTABLEDATA (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_DATA) {
votEmsg ("TABLEDATA must be child of a DATA tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_TABLEDATA)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getTR -- Gets the TR node from the parent handle
*
* @brief Gets the TR node from the parent handle
* @fn handle_t vot_getTR (handle_t handle)
*
* @param handle Parent handle containing a TR
* @return A handle to the first TR node, or zero
*/
handle_t
vot_getTR (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_TABLEDATA) {
votEmsg ("TR must be child of a TABLEDATA tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_TR)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getTD -- Gets the TD node from the parent handle
*
* @brief Gets the TD node from the parent handle
* @fn handle_t vot_getTD (handle_t handle)
*
* @param handle Parent handle containing a TD
* @return A handle to the first TD node, or zero
*/
handle_t
vot_getTD (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_TR) {
votEmsg ("TD must be child of a TR tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_TD)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getBINARY -- Gets the BINARY node from the parent handle
*
* @brief Gets the BINARY node from the parent handle
* @fn handle_t vot_getBINARY (handle_t handle)
*
* @param handle Parent handle containing a BINARY
* @return A handle to the first BINARY node, or zero
*/
handle_t
vot_getBINARY (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_DATA) {
votEmsg ("BINARY must be child of a DATA tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_BINARY || child->type == TY_BINARY2)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getBINARY2 -- Gets the BINARY2 node from the parent handle
*
* @brief Gets the BINARY2 node from the parent handle
* @fn handle_t vot_getBINARY2 (handle_t handle)
*
* @param handle Parent handle containing a BINARY2
* @return A handle to the first BINARY2 node, or zero
*/
handle_t
vot_getBINARY2 (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_DATA) {
votEmsg ("BINARY2 must be child of a DATA tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_BINARY2)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getFITS -- Gets the FITS node from the parent handle
*
* @brief Gets the FITS node from the parent handle
* @fn handle_t vot_getFITS (handle_t handle)
*
* @param handle Parent handle containing a FITS
* @return A handle to the first FITS node, or zero
*/
handle_t
vot_getFITS (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_DATA) {
votEmsg ("FITS must be child of a DATA tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_FITS)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getGROUP -- Gets the GROUP node from the parent handle
*
* @brief Gets the GROUP node from the parent handle
* @fn handle_t vot_getGROUP (handle_t handle)
*
* @param handle Parent handle containing a GROUP
* @return A handle to the first GROUP node, or zero
*/
handle_t
vot_getGROUP (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if ((my_type != TY_VOTABLE) && (my_type != TY_RESOURCE) &&
(my_type != TY_TABLE) && (my_type != TY_GROUP)) {
votEmsg (
"GROUP must be child of a RESOURCE, TABLE, GROUP or VOTABLE\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_GROUP)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getFIELDref -- Gets the FIELDref node from the parent handle
*
* @brief Gets the FIELDref node from the parent handle
* @fn handle_t vot_getFIELDRef (handle_t handle)
*
* @param handle Parent handle containing a FIELDref
* @return A handle to the first FIELDref node, or zero
*/
handle_t
vot_getFIELDRef (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_GROUP) {
votEmsg ("FIELDref must be child of a GROUP tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_FIELDREF)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getPARAMRef -- Gets the PARAMref node from the parent handle
*
* @brief Gets the PARAMRef node from the parent handle
* @fn handle_t vot_getPARAMRef (handle_t handle)
*
* @param handle Parent handle containing a PARAMRef
* @return A handle to the first PARAMRef node, or zero
*/
handle_t
vot_getPARAMRef (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if (my_type != TY_GROUP) {
votEmsg ("PARAMref must be child of a GROUP tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_PARAMREF)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getDESCRIPTION -- Gets the DESCRIPTION node from the parent handle
*
* @brief Gets the DESCRIPTION node from the parent handle
* @fn handle_t vot_getDESCRIPTION (handle_t handle)
*
* @param handle Parent handle containing a DESCRIPTION
* @return A handle to the first DESCRIPTION node, or zero
*/
handle_t
vot_getDESCRIPTION (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
elem = vot_getElement (handle);
for (child = elem->child; child; child = child->next)
if (child->type == TY_DESCRIPTION)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getPARAM -- Gets the PARAM node from the parent handle
*
* @brief Gets the PARAM node from the parent handle
* @fn handle_t vot_getPARAM (handle_t handle)
*
* @param handle Parent handle containing a PARAM
* @return A handle to the first PARAM node, or zero
*/
handle_t
vot_getPARAM (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
elem = vot_getElement (handle);
for (child = elem->child; child; child = child->next)
if (child->type == TY_PARAM)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getINFO -- Gets the INFO node from the parent handle
*
* @brief Gets the INFO node from the parent handle
* @fn handle_t vot_getINFO (handle_t handle)
*
* @param handle Parent handle containing a INFO
* @return A handle to the first INFO node, or zero
*/
handle_t
vot_getINFO (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
elem = vot_getElement (handle);
for (child = elem->child; child; child = child->next)
if (child->type == TY_INFO)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getSTREAM -- Gets the STREAM node from the parent handle
*
* @brief Gets the STREAM node from the parent handle
* @fn handle_t vot_getSTREAM (handle_t handle)
*
* @param handle Parent handle containing a STREAM
* @return A handle to the first STREAM node, or zero
*/
handle_t
vot_getSTREAM (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if ((my_type != TY_BINARY) &&
(my_type != TY_BINARY2) &&
(my_type != TY_FITS)) {
votEmsg ("STREAM must be child of a BINARY(2) or FITS tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_STREAM)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getVALUES -- Gets the VALUES node from the parent handle
*
* @brief Gets the VALUES node from the parent handle
* @fn handle_t vot_getVALUES (handle_t handle)
*
* @param handle Parent handle containing a VALUES
* @return A handle to the first VALUES node, or zero
*/
handle_t
vot_getVALUES (handle_t handle)
{
/* Refer to vot_getRESOURCE for detailed comments on function workings. */
Element *elem, *child;
int my_type;
elem = vot_getElement (handle);
my_type = vot_elemType (elem);
if ((my_type != TY_FIELD) && (my_type != TY_PARAM) &&
(my_type != TY_INFO)) {
votEmsg ("VALUES must be child of a FIELD, PARAM or INFO tag\n");
return (0);
}
for (child = elem->child; child; child = child->next)
if (child->type == TY_VALUES)
break;
return (vot_lookupHandle (child));
}
/**
* vot_getMIN -- Gets the MIN node from the parent handle
*
* @brief Gets the MIN node from the parent handle
* @fn handle_t vot_getMIN (handle_t handle)
*
* @param handle Parent handle containing a MIN
* @return A handle to the first MIN node, or zero