summaryrefslogtreecommitdiffstats
path: root/tools/h5dump.c
blob: f65f9e230fed46eaae03518d2a9553bfab684cbc (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
#include "h5dump.h"
#include <stdio.h>
#include "H5private.h"

static int indent = 0;
static int display_data = 1;
static int status = 0;

static void dump_group (hid_t , const char* );
static void dump_dataset (hid_t, const  char*);
static void dump_data (hid_t, int);
static void dump_named_datatype (hid_t , const char *);

/*-------------------------------------------------------------------------
 * Function:    usage
 *
 * Purpose:     Print the usage message about dumper
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
usage(void)
{
fprintf(stderr, 
"\nUsage of HDF5 Dumper:\n\n  \
h5dump [-h] [-bb] [-header] [-a <names>] [-d <names>] [-g <names>]\n  \
       [-l <names>] <file>\n\n\
  -h            Print information on this command.\n\
  -bb           Display the conent of boot block. The default is not to display.\n\
  -header       Display header only; that is, no data displayed.\n\
  -a <names>    Display the specified attribute(s).\n\
  -d <names>    Display the specified dataset(s).\n\
  -g <names>    Display all the objects within the specified group(s).\n\
  -l <names>    Display the specified link value(s).\n\n"); 

}


/*-------------------------------------------------------------------------
 * Function:    indentation
 *
 * Purpose:     Print spaces for indentation
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void indentation(int x) {

  while (x>0) {
         printf(" "); 
         x--;
  }

}


/*-------------------------------------------------------------------------
 * Function:    datatype_name
 *
 * Purpose:     Prints the name of data type. 
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
datatype_name(hid_t type) {

    switch (H5Tget_class(type)) {

    case H5T_INTEGER:

        if (H5Tequal(type, H5T_STD_I8BE))
            printf( "H5T_STD_I8BE");
        else if (H5Tequal(type, H5T_STD_I8LE))
            printf( "H5T_STD_I8LE");
        else if (H5Tequal(type, H5T_STD_I16BE))
            printf( "H5T_STD_I16BE");
        else if (H5Tequal(type, H5T_STD_I16LE))
            printf( "H5T_STD_I16LE");
        else if (H5Tequal(type, H5T_STD_I32BE))
            printf( "H5T_STD_I32BE");
        else if (H5Tequal(type, H5T_STD_I32LE))
            printf( "H5T_STD_I32LE");
        else if (H5Tequal(type, H5T_STD_I64BE))
            printf( "H5T_STD_I64BE");
        else if (H5Tequal(type, H5T_STD_I64LE))
            printf( "H5T_STD_I64LE");
        else if (H5Tequal(type, H5T_STD_U8BE))
            printf( "H5T_STD_U8BE");
        else if (H5Tequal(type, H5T_STD_U8LE))
            printf( "H5T_STD_U8LE");
        else if (H5Tequal(type, H5T_STD_U16BE))
            printf( "H5T_STD_U16BE");
        else if (H5Tequal(type, H5T_STD_U16LE))
            printf( "H5T_STD_U16LE");
        else if (H5Tequal(type, H5T_STD_U32BE))
            printf( "H5T_STD_U32BE");
        else if (H5Tequal(type, H5T_STD_U32LE))
            printf( "H5T_STD_U32LE");
        else if (H5Tequal(type, H5T_STD_U64BE))
            printf( "H5T_STD_U64BE");
        else if (H5Tequal(type, H5T_STD_U64LE))
            printf( "H5T_STD_U64LE");
        else if (H5Tequal(type, H5T_NATIVE_CHAR)) 
            printf( "H5T_NATIVE_CHAR");
        else if (H5Tequal(type, H5T_NATIVE_UCHAR))
            printf( "H5T_NATIVE_UCHAR");
        else if (H5Tequal(type, H5T_NATIVE_SHORT))
            printf( "H5T_NATIVE_SHORT");
        else if (H5Tequal(type, H5T_NATIVE_USHORT))
            printf( "H5T_NATIVE_USHORT");
        else if (H5Tequal(type, H5T_NATIVE_INT))
            printf( "H5T_NATIVE_INT");
        else if (H5Tequal(type, H5T_NATIVE_UINT))
            printf( "H5T_NATIVE_UINT");
        else if (H5Tequal(type, H5T_NATIVE_LONG))
            printf( "H5T_NATIVE_LONG");
        else if (H5Tequal(type, H5T_NATIVE_ULONG))
            printf( "H5T_NATIVE_ULONG");
        else if (H5Tequal(type, H5T_NATIVE_LLONG))
            printf( "H5T_NATIVE_LLONG");
        else if (H5Tequal(type, H5T_NATIVE_ULLONG))
            printf( "H5T_NATIVE_ULLONG");
        else printf( "unknown integer");
        break;

    case H5T_FLOAT: 
        if (H5Tequal(type, H5T_IEEE_F32BE))
            printf( "H5T_IEEE_F32BE");
        else if (H5Tequal(type, H5T_IEEE_F32LE))
            printf( "H5T_IEEE_F32LE");
        else if (H5Tequal(type, H5T_IEEE_F64BE))
            printf( "H5T_IEEE_F64BE");
        else if (H5Tequal(type, H5T_IEEE_F64LE))
            printf( "H5T_IEEE_F64LE");
        else if (H5Tequal(type, H5T_NATIVE_FLOAT))
            printf( "H5T_NATIVE_FLOAT");
        else if (H5Tequal(type, H5T_NATIVE_DOUBLE))
            printf( "H5T_NATIVE_DOUBLE");
        else if (H5Tequal(type, H5T_NATIVE_LDOUBLE))
            printf( "H5T_NATIVE_LDOUBLE");
        else printf( "unknown float");
        break;

    case H5T_TIME: 
        printf( "time: not yet implemented");

    case H5T_STRING: 

        if (H5Tequal(type,H5T_C_S1))
            printf( "H5T_C_S1");
        else if (H5Tequal(type,H5T_FORTRAN_S1))
            printf( "H5T_FORTRAN_S1");
        else printf( "unknown string");
        break;

    case H5T_BITFIELD: 

        if (H5Tequal(type, H5T_STD_B8BE))
            printf( "H5T_STD_B8BE");
        else if (H5Tequal(type, H5T_STD_B8LE))
            printf( "H5T_STD_B8LE");
        else if (H5Tequal(type, H5T_STD_B16BE))
            printf( "H5T_STD_B16BE");
        else if (H5Tequal(type, H5T_STD_B16LE))
            printf( "H5T_STD_B16LE");
        else if (H5Tequal(type, H5T_STD_B32BE))
            printf( "H5T_STD_B32BE");
        else if (H5Tequal(type, H5T_STD_B32LE))
            printf( "H5T_STD_B32LE");
        else if (H5Tequal(type, H5T_STD_B64BE))
            printf( "H5T_STD_B64BE");
        else if (H5Tequal(type, H5T_STD_B64LE))
            printf( "H5T_STD_B64LE");
        else printf( "unknown bitfield");
        break;

    case H5T_OPAQUE: 
        printf( "opaque: not yet implemented");
        break;

    case H5T_COMPOUND: 

        printf( "compound: not yet implemented");
        break;

    default:
        printf( "unknown data type");
        break;
    }

}


/*-------------------------------------------------------------------------
 * Function:    dump_bb
 *
 * Purpose:     Dump the boot block
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_bb(void) {

    printf ("%s %s boot block not yet implemented %s\n", BOOT_BLOCK, BEGIN, END);

}


/*-------------------------------------------------------------------------
 * Function:    dump_datatype
 *
 * Purpose:     Dump the data type. Data type can be HDF5 predefined
 *              atomic data type, named data type or compound data type. 
 *
 * Return:      void 
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_datatype (hid_t type) {

    indentation (indent+col);
    printf ("%s %s \"", DATATYPE, BEGIN);
    datatype_name(type);
    printf ("\" %s\n", END);
}


/*-------------------------------------------------------------------------
 * Function:    dump_dataspace
 *
 * Purpose:     Dump the data space. Data space can be named data space,
 *              array, or others.
 *
 * Return:      void    
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_dataspace (hid_t space)
{
    hsize_t size[64];
    hsize_t maxsize[64];  /* check max dims size */
    int ndims = H5Sget_simple_extent_dims(space, size, maxsize);
    int i;

    indentation (indent+col);

    printf("%s ", DATASPACE);

    if (H5Sis_simple(space)) {

        HDfprintf (stdout, "%s %s ( %Hu",BEGIN, ARRAY, size[0]);
        for (i = 1; i < ndims; i++) 
             HDfprintf (stdout, ", %Hu", size[i]);
        printf(" ) ");
           
        if (maxsize[0]==H5S_UNLIMITED)
            HDfprintf (stdout, "( %s", "H5S_UNLIMITED");
        else
            HDfprintf (stdout, "( %Hu", maxsize[0]);

        for (i = 1; i < ndims; i++) 
             if (maxsize[i]==H5S_UNLIMITED)
                 HDfprintf (stdout, ", %s", "H5S_UNLIMITED");
             else
                 HDfprintf (stdout, ", %Hu", maxsize[i]);

        printf(" ) %s\n", END);

    } else

        printf("%s not yet implemented %s\n", BEGIN, END);

}


/*-------------------------------------------------------------------------
 * Function:    dump_attr
 *
 * Purpose:     dump the attribute
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        FAIL
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static herr_t
dump_attr (hid_t attr, const char *attr_name, void __unused__ *op_data)
{
hid_t  attr_id, type, space;

    indentation(indent);
    begin_obj (ATTRIBUTE, attr_name); 

    if ((attr_id = H5Aopen_name (attr, attr_name))>= 0) {

        type = H5Aget_type(attr_id);
        space = H5Aget_space(attr_id);
        dump_datatype(type);
        dump_dataspace(space);
        if (display_data) dump_data(attr_id, ATTRIBUTE_DATA);
        H5Tclose(type);
        H5Sclose(space);
	H5Aclose (attr_id);
        indentation (indent);
        end_obj();

    } else {
        indentation (indent+col);
        printf("h5dump error: unable to open attribute.\n");
        indentation (indent);
        end_obj();
        status = 1;
        return FAIL;
    }


    return SUCCEED;

}

/*-------------------------------------------------------------------------
 * Function:    dump_selected_attr
 *
 * Purpose:     dump the selected attribute
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        FAIL
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static herr_t
dump_selected_attr (hid_t loc_id, char *name)
{
int j;
char *obj_name, *attr_name;
hid_t  oid, attr_id, type, space;
H5G_stat_t statbuf;



    j = strlen(name)-1;
    obj_name = malloc ((j+2) * sizeof(char));
    /* find the last / */
    while (name[j] != '/' && j >=0) j--;
    /* object name */
    if (j == -1) strcpy(obj_name, "/");
    else strncpy(obj_name, name, j+1);
 
    attr_name = name+j+1;

    begin_obj (ATTRIBUTE, name);

    H5Gget_objinfo(loc_id, obj_name, FALSE, &statbuf);
    switch (statbuf.type) {
    case H5G_GROUP:
         if ((oid = H5Gopen (loc_id, obj_name))<0) {
             indentation (col);
             fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
             end_obj();
             status = 1;
             return FAIL;
         }
         break;
    case H5G_DATASET:
         if ((oid = H5Dopen (loc_id, obj_name))<0) {
             indentation (col);
             fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
             end_obj();
             status = 1;
             return FAIL;
         }
         break;
    case H5G_TYPE:
         if ((oid =  H5Topen(loc_id, obj_name)) < 0 ) {
             indentation (col);
             fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
             end_obj();
             status = 1;
             return FAIL;
         } 
         break;
    default:
         indentation (col);
         fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
         end_obj();
         status = 1;
         return FAIL;
    }

    if ((attr_id = H5Aopen_name (oid, attr_name))>= 0) {

        type = H5Aget_type(attr_id);
        space = H5Aget_space(attr_id);
        dump_datatype(type);
        dump_dataspace(space);
        if (display_data) dump_data(attr_id, ATTRIBUTE_DATA);
        H5Tclose(type);
        H5Sclose(space);
	H5Aclose (attr_id);
        end_obj();

    } else {
        indentation (col);
        printf("h5dump error: unable to open attribute.\n");
        end_obj();
        status = 1;
        return FAIL;
    }

    switch (statbuf.type) {
    case H5G_GROUP:
         if (H5Gclose (oid) < 0) {
         status = 1;
         return FAIL;
         } 
         break;
          
    case H5G_DATASET:
         if (H5Dclose (oid) < 0 ) {
             status = 1;
             return FAIL;
         } 
         break;

    case H5G_TYPE:
         if (H5Tclose(oid) < 0 ) {
             status = 1;
             return FAIL;
         } 
         break;
    default:
         status = 1;
         return FAIL;
    }

    free(obj_name);
    return SUCCEED;
}

/*-------------------------------------------------------------------------
 * Function:    dump all
 *
 * Purpose:     Dump everything in the specified object
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        FAIL
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static herr_t
dump_all (hid_t group, const char *name, void __unused__ *op_data)
{
    hid_t obj;
    hid_t (*func)(void*);
    void *edata;
    char *buf;
    H5G_stat_t statbuf;

    /* Disable error reporting */
    H5Eget_auto (&func, &edata);
    H5Eset_auto (NULL, NULL);


    H5Gget_objinfo(group, name, FALSE, &statbuf);


    switch (statbuf.type) {
    case H5G_LINK:
        indentation (indent);

        buf = malloc (statbuf.linklen*sizeof(char));

        begin_obj(SOFTLINK, name);
        indentation (indent+col);
        if (H5Gget_linkval (group, name, statbuf.linklen, buf)>=0) 
            printf ("linktarget \"%s\"\n", buf);
        else {
            printf ("h5dump error: unable to get link value.\n");
            status = 1;
        }

        indentation (indent);
        end_obj();
        free (buf);
        break;

    case H5G_GROUP:
         if ((obj=H5Gopen (group, name))>=0) {
             dump_group (obj, name);
             H5Gclose (obj);
         } else {
             printf ("h5dump error: unable to dump group %s\n",name);
             status = 1;
         }

         break;

    case H5G_DATASET:

         if ((obj=H5Dopen (group, name))>=0) {              
             dump_dataset (obj, name);
             H5Dclose (obj);
         } else {
             printf ("h5dump error: unable to dump dataset %s\n",name);
             status = 1;
         }

         break;

    case H5G_TYPE:
         dump_named_datatype (obj, name);
         H5Tclose(obj);
         break;

    default:
         printf ("Unknown Object %s\n", name);
         status = 1; 
         H5Eset_auto (func, edata);
         return FAIL;
         break;

    }


    /* Restore error reporting */
    H5Eset_auto (func, edata);

    return SUCCEED;

}


/*-------------------------------------------------------------------------
 * Function:    dump_named_datatype
 *
 * Purpose:     Dump named data type
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications: Comments: not yet implemented.
 *
 *-----------------------------------------------------------------------*/
static void
dump_named_datatype (hid_t type_id, const char *name) {
hid_t id;
/*
char *fname ;
hid_t nmembers, mtype;
int i, ndims, perm[512];
*/

id = type_id; /*doesn't like warning message */

    indentation (indent);
    begin_obj(DATATYPE, name);

    indentation(indent+col);
    printf("named data type: not yet implemented.\n");

    indentation (indent);
    end_obj();

}


/*-------------------------------------------------------------------------
 * Function:    dump_group
 *
 * Purpose:     Dump everything within the specified group
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_group (hid_t gid, const char *name) {
H5G_stat_t statbuf;

    indentation (indent);
    begin_obj(GROUP, name);
    indent += col;

    /* hard link */
    H5Gget_objinfo(gid, ".", TRUE, &statbuf);
    if (statbuf.nlink > 1) { 
        indentation (indent);
        printf("%s %s (%s %u) (%s %lu %lu) (%s %lu %lu ) %s\n", 
               HARDLINK, BEGIN, NLINK, statbuf.nlink, FILENO, statbuf.fileno[0],
               statbuf.fileno[1], OBJNO, statbuf.objno[0], statbuf.objno[1], END); 
    }

    H5Aiterate (gid, NULL, dump_attr, NULL);
    H5Giterate (gid, ".", NULL, dump_all, NULL);
    indent -= col;
    indentation (indent);
    end_obj();

}


/*-------------------------------------------------------------------------
 * Function:    dump_dataset
 *
 * Purpose:     Dump the specified data set
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_dataset (hid_t did, const char *name) {
hid_t  type, space;
H5G_stat_t statbuf;

    indentation (indent);
    begin_obj(DATASET, name);

    /* hard link */
    H5Gget_objinfo(did, ".", TRUE, &statbuf);
    if (statbuf.nlink > 1) {
        indentation (indent+col);
        printf("%s %s (%s %u) (%s %lu %lu) (%s %lu %lu ) %s\n",
               HARDLINK, BEGIN, NLINK, statbuf.nlink, FILENO, statbuf.fileno[0],
               statbuf.fileno[1], OBJNO, statbuf.objno[0], statbuf.objno[1], END);
    }

    type = H5Dget_type (did);
    space = H5Dget_space (did);
    dump_datatype(type);
    dump_dataspace(space);

    if (display_data)
    switch (H5Tget_class(type)) {
    case H5T_INTEGER:
         dump_data(did, DATASET_DATA);
         break;
    case H5T_FLOAT:
         dump_data(did, DATASET_DATA);
         break;
    case H5T_TIME:
         indent += col;
         indentation (indent);
         indent -= col;
         printf("DATA{ not yet implemented.}\n");
         break;
    case H5T_STRING:
         indent += col;
         indentation (indent);
         indent -= col;
         printf("DATA{ not yet implemented.}\n");
         break;
    case H5T_BITFIELD:
         indent += col;
         indentation (indent);
         indent -= col;
         printf("DATA{ not yet implemented.}\n");
         break;
    case H5T_OPAQUE:
         indent += col;
         indentation (indent);
         indent -= col;
         printf("DATA{ not yet implemented.}\n");
         break;
    case H5T_COMPOUND:
         indent += col;
         indentation (indent);
         indent -= col;
         printf("DATA{ not yet implemented.}\n");
         break;
    default: break;
    }

    indent += col;
    H5Aiterate (did, NULL, dump_attr, NULL);
    indent -= col;

    H5Tclose(type);
    H5Sclose(space);
    indentation (indent);
    end_obj();
    
}


/*-------------------------------------------------------------------------
 * Function:    dump_data
 *
 * Purpose:     Dump attribute or dataset data
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
static void
dump_data (hid_t obj_id, int obj_data) {

    hid_t               f_type ;
    size_t              size ;
    h5dump_t            info;

    indent += col;
    indentation (indent);
    printf("%s %s", DATA, BEGIN);

    if (obj_data == DATASET_DATA)
        f_type = H5Dget_type(obj_id);
    else
        f_type = H5Aget_type(obj_id);

    size = H5Tget_size(f_type);

    /* Set to all default values and then override */
    memset(&info, 0, sizeof info);
    info.idx_fmt = "        (%s) ";
    info.line_ncols = 80;

    /*
     * If the dataset is a 1-byte integer type then format it as an ASCI
     * character string instead of integers.
     */
    if (1==size && H5T_INTEGER==H5Tget_class(f_type)) {
        info.elmt_suf1 = "";
        info.elmt_suf2 = "";
        info.idx_fmt = "        (%s) \"";
        info.line_suf = "\"";
        printf("\"");
    }

   
    /*
     * Print all the values.
     */

    if (h5dump1(stdout, &info, obj_id, -1, obj_data)<0) {
        printf("Unable to print data.");
    }

    if (1==size && H5T_INTEGER==H5Tget_class(f_type)) 
        printf("\"");

    printf("%s\n", END);
    indent -= col;

    H5Tclose(f_type);

}


/*-------------------------------------------------------------------------
 * Function:    
 *
 * Purpose:     HDF5 dumper
 *
 * Return:      Success:	0
 *              Failure:	1
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *
 *-----------------------------------------------------------------------*/
int
main(int argc, char *argv[]) {
hid_t fid, gid, dsetid;
hid_t plist=H5P_DEFAULT;
const char *fname = NULL;
int i, curr_arg, display_bb=0, display_all=1;
int nopts=0, *opts;
char *buf;
H5G_stat_t statbuf;
void __unused__ *op_data;

    if (argc < 2 ) {
        usage();
        exit(1);
    }

    opts = malloc((argc/2) * sizeof (int));
    opts[0] = -1;
    /* parse command line options */
    for (curr_arg = 1; curr_arg < argc; curr_arg++) 

         if (argv[curr_arg][0] == '-') {

             opts[nopts++] = curr_arg;

             if (!strcmp(argv[curr_arg],"-h")) {

                 usage();
                 exit(0);

             } else if (!strcmp(argv[curr_arg],"-bb"))

                 display_bb = 1;

             else if (!strcmp(argv[curr_arg],"-header")) 

                 display_data=0;

             else if (strcmp(argv[curr_arg],"-a") &&
                      strcmp(argv[curr_arg],"-d") &&
                      strcmp(argv[curr_arg],"-g") &&
                      strcmp(argv[curr_arg],"-l")) {

                 fprintf(stderr, "h5dump error: illegal option %s \n", 
                         argv[curr_arg]);
                 usage();
                 exit(1);
             } else display_all = 0;
         } 

    /* check names */
    if (argc == 2) {
        if (opts[0] == 1) { /* argv[1] is an option */
            fprintf(stderr, "h5dump error: no <names> or no <file>\n");
            usage();
            exit(1);
        }
    } else {
        for (i = 0; i < nopts-1; i++) {
             if (opts[i+1]-opts[i] == 1) {
                if (strcmp(argv[opts[i]], "-bb") &&
                    strcmp(argv[opts[i]], "-header") ) {
                    fprintf(stderr,"h5dump error: no <names> after option %s\n",
                            argv[opts[i]]);
                    usage();
                    exit(1);
                } 
             }
        }
        if (argc - opts[nopts-1] == 1) {
            fprintf(stderr,"h5dump error: no <file>\n");
            usage();
            exit(1);
        } 
        if (argc - opts[nopts-1] == 2) {
            if (strcmp(argv[opts[i]], "-bb") &&
                strcmp(argv[opts[i]], "-header") ) {
                fprintf (stderr, "h5dump error: no <file> or no <names> after option %s\n", argv[opts[i]]);
                usage();
                exit(1);
            }
        }
    } 


    if (argv[argc-1][0] == '\\') fname = &argv[argc-1][1];
    else fname = argv[argc-1];

    if ((fid = H5Fopen (fname, H5F_ACC_RDONLY, plist)) < 0) {
         fprintf (stderr, "h5dump error: unable to open file %s \n", fname);
         exit(1);
    }

    begin_obj("HDF5", fname);

    if (display_bb) dump_bb();
 
    if (display_all) {

        if ((gid = H5Gopen (fid, "/")) < 0 ) {
             fprintf(stdout, "h5dump error: unable to open root group\n");
             status = 1;
        } else
             dump_group(gid, "/");

        if (H5Gclose (gid) < 0) {
            fprintf(stdout, "h5dump error: unable to close root group\n");
            status = 1;
        }

    } else

      for (i = 0; i < nopts; i++) {
           if (!strcmp(argv[opts[i]],"-a")) { 

               for (curr_arg = opts[i]+1; 
                    curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]); 
                    curr_arg++) 

                    dump_selected_attr (fid, argv[curr_arg]);

           } else if (!strcmp(argv[opts[i]],"-d")) {
                for (curr_arg = opts[i]+1; 
                     curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]); 
                     curr_arg++) {

                     if ((dsetid = H5Dopen (fid, argv[curr_arg]))<0) {
                         begin_obj (DATASET, argv[curr_arg]); 
                         indentation (col);
                         fprintf (stdout, "h5dump error: unable to open %s\n", 
                                  argv[curr_arg]);
                         end_obj();
                         status = 1;
                     } else {
                         dump_dataset(dsetid, argv[curr_arg]);
                         if (H5Dclose(dsetid)<1) status = 1;
                     }
          
                }

           } else if (!strcmp(argv[opts[i]],"-g")) {

                for (curr_arg = opts[i]+1; 
                     curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]); 
                     curr_arg++) {
                     if ((gid = H5Gopen (fid, argv[curr_arg])) < 0) {
                         begin_obj (GROUP, argv[curr_arg]); 
                         indentation (col);
                         fprintf (stdout, "h5dump error: unable to open %s\n", 
                                  argv[curr_arg]);
                         end_obj();
                         status = 1;
                     } else {
                         dump_group(gid, argv[curr_arg]);
                         if (H5Gclose (gid) < 0) status = 1;
                     }
                }

           } else if (!strcmp(argv[opts[i]],"-l")) {

                for (curr_arg = opts[i]+1; 
                     curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]); 
                     curr_arg++) {


                     if (H5Gget_objinfo(fid, argv[curr_arg], FALSE, &statbuf) < 0) {
                         begin_obj(SOFTLINK, argv[curr_arg]);
                         indentation (col);
                         fprintf(stdout, "h5dump error: unable to get obj info from %s\n", argv[curr_arg]);
                         end_obj();
                         status = 1;

                     } else if (statbuf.type == H5G_LINK) {

                         buf = malloc(statbuf.linklen*sizeof(char));
                         begin_obj(SOFTLINK, argv[curr_arg]);
                         indentation (col);
                         if (H5Gget_linkval (fid, argv[curr_arg], statbuf.linklen, buf)>=0) 
                             printf ("linktarget \"%s\"\n", buf);
                         else {
                             fprintf (stdout, "h5dump error: unable to get link value\n");
                             status = 1;
                         }
                         end_obj();
                         free(buf);

                     } else {
                         begin_obj(SOFTLINK, argv[curr_arg]);
                         indentation (col);
                         fprintf(stdout, "h5dump error: %s is not a link\n", argv[curr_arg]);
                         end_obj();
                         status = 1;
                     }

                 }

           }
      }

    end_obj();

    free(opts);

    if (H5Fclose (fid) < 0) exit(1);

    return status;

}