home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 580a.lha / hdf_utilities / src.LZH / src / hdfls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-11  |  6.7 KB  |  201 lines

  1. /*****************************************************************************
  2. *              NCSA HDF version 3.10r3
  3. *                Dec 6, 1990
  4. *
  5. * NCSA HDF Version 3.10r3 source code and documentation are in the public
  6. * domain.  Specifically, we give to the public domain all rights for future
  7. * licensing of the source code, all resale rights, and all publishing rights.
  8. * We ask, but do not require, that the following message be included in all
  9. * derived works:
  10. * Portions developed at the National Center for Supercomputing Applications at
  11. * the University of Illinois at Urbana-Champaign.
  12. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  13. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  14. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  15. *****************************************************************************/
  16.  
  17. #ifdef RCSID
  18. static char RcsId[] = "@(#)$Revision: 3.2 $";
  19. #endif
  20. /*
  21. $Header: /pita/work/HDF/dev/RCS/src/hdfls.c,v 3.2 90/07/02 10:11:46 clow beta $
  22.  
  23. $Log:    hdfls.c,v $
  24.  * Revision 3.2  90/07/02  10:11:46  clow
  25.  * some cosmetic modifications
  26.  * 
  27. */
  28. #include <hdf/df.h>
  29.  
  30. #define MAXBUFF 2000
  31.  
  32. DFdesc desc[MAXBUFF];
  33.  
  34. int
  35.     debug=0,        /* Debugging is off by default */
  36.     xsort=1,         /* Sorting is on by default */
  37.     longout=0;      /* short output by default */
  38.  
  39. struct des {
  40.     int num;
  41.     char name[50];
  42. }   tagdes[]={
  43.         {DFTAG_NULL, "Empty               (Utility)   "},
  44.         {DFTAG_FID,  "File Identifier     (Utility)   "},
  45.         {DFTAG_FD,   "File Description    (Utility)   "},
  46.         {DFTAG_TID,  "Tag Identifier      (Utility)   "},
  47.         {DFTAG_TD,   "Tag Description     (Utility)   "},
  48.         {DFTAG_DIL,  "Data Id Label       (Utility)   "},
  49.         {DFTAG_DIA,  "Data Id Annotation  (Utility)   "},
  50.         {DFTAG_NT,   "Number type         (Utility)   "},
  51.         {DFTAG_MT,   "Machine type        (Utility)   "},
  52.         {DFTAG_ID8,  "Image Dimensions-8  (Raster-8)  "},
  53.         {DFTAG_IP8,  "Image Palette-8     (Raster-8)  "},
  54.         {DFTAG_RI8,  "Raster Image-8      (Raster-8)  "},
  55.         {DFTAG_CI8,  "Compressed Image-8  (Raster-8)  "},
  56.         {DFTAG_II8,  "Imcomp Image-8      (Raster-8)  "},
  57.         {DFTAG_ID,   "Image Dimensions    (Raster)    "},
  58.         {DFTAG_LUT,  "Image Palette       (Raster)    "},
  59.         {DFTAG_RI,   "Raster Image        (Raster)    "},
  60.         {DFTAG_CI,   "Compressed Image    (Raster)    "},
  61.         {DFTAG_RIG,  "Raster Image Group  (Raster)    "},
  62.         {DFTAG_LD,   "Palette Dimension   (Raster)    "},
  63.         {DFTAG_MD,   "Matte Dimension     (Raster)    "},
  64.         {DFTAG_MA,   "Matte Data          (Raster)    "},
  65.         {DFTAG_CCN,  "Color Correction    (Raster)    "},
  66.         {DFTAG_CFM,  "Color Format        (Raster)    "},
  67.         {DFTAG_AR,   "Aspect Ratio        (Raster)    "},
  68.         {DFTAG_DRAW, "Draw                (Composite) "},
  69.         {DFTAG_RUN,  "Run                 (Composite) "},
  70.         {DFTAG_XYP,  "X-Y position        (Composite) "},
  71.         {DFTAG_MTO,  "M/c-Type override   (Composite)"},
  72.         {DFTAG_T14,  "TEK 4014 Data       (Tektronix) "},
  73.         {DFTAG_T105, "TEK 4105 data       (Tektronix) "},
  74.         {DFTAG_RLE,  "Run Length Encoding (Raster)    "},
  75.         {DFTAG_IMC,  "IMCOMP Encoding     (Raster)    "},
  76.         {DFTAG_SDG,  "Scientific Data Group (SciData) "},
  77.         {DFTAG_SD,   "Scientific Data     (SciData)   "},
  78.         {DFTAG_SDD,  "SciData description (SciData)   "},
  79.         {DFTAG_SDL,  "SciData labels      (SciData)   "},
  80.         {DFTAG_SDU,  "SciData units       (SciData)   "},
  81.         {DFTAG_SDF,  "SciData formats     (SciData)   "},
  82.         {DFTAG_SDS,  "SciData scales      (SciData)   "},
  83.         {DFTAG_SDM,  "SciData max/min     (SciData)   "},
  84.         {DFTAG_SDC,  "SciData coordsys    (SciData)   "},
  85.         {-1,         "Unknown Tag                     "}
  86.     };
  87.  
  88. int compare( a,b)
  89. DFdesc *a,*b;
  90. {
  91.     if (a->tag>b->tag) return(1);
  92.     if (a->tag<b->tag) return(-1);
  93.     if (a->ref>b->ref) return(1);
  94.     if (a->ref<b->ref) return(-1);
  95.     return(0);
  96. }
  97.  
  98. main(argc, argv)
  99. int argc;
  100. char *argv[];
  101. {
  102.     DF *df;
  103.     int i=1, j, n;
  104.  
  105.     if (argc <2) {
  106.         printf("%s,  version: 1.0   date: December 1, 1988\n",argv[0]);
  107.         printf("hdfls [-o][-l] fn ....\n");
  108.         printf("        This program displays information about the");
  109.         printf(" data elements in\n");
  110.         printf("        HDF file.\n");
  111.         printf("    -o: Ordered - display in reference number order\n");
  112.         printf("    -l: Long format - display more information\n");
  113.         exit (1);
  114.         }
  115.     
  116.     if (argv[1][0]=='-') {
  117.         switch( argv[1][1]) {
  118.             case 'o':
  119.                 xsort=0;
  120.                 break;
  121.             case 'd':
  122.                 debug=1;
  123.                 break;
  124.             case 'l':
  125.                 longout = 1;
  126.                 break;
  127.             default:    
  128.                 printf("Unknown option :%c\n", argv[1][1]);
  129.                 break;
  130.             }
  131.         i++;
  132.         }
  133.     while (i<argc) {
  134.         df=DFopen( argv[i], DFACC_READ, -1);
  135.         printf( "%s:", argv[i]);
  136.         if (!df) {
  137.             if (DFerror==DFE_NOTDFFILE) 
  138.                     printf(" not an NCSA Format Data File.\n");
  139.             else printf(" Error opening file.\n");
  140.             i++;
  141.             continue;
  142.             }
  143.  
  144.         n = DFdescriptors(df, desc, 0, MAXBUFF);
  145.  
  146.         for (j=0; j<n; j++) {
  147.             if (debug) printf("%d) %d[%d]",j,desc[j].tag,desc[j].ref);
  148.             if (debug) printf(" off %d len %d\n",
  149.                     desc[j].offset,desc[j].length);
  150.             }
  151.  
  152.         if (xsort) qsort( (char *) desc, n, sizeof(DFdesc), compare);
  153.  
  154.         lprint(desc, n);
  155.  
  156.         if (DFclose(df)<0) printf("Error %d @ close\n", DFerror);
  157.         i++;
  158.         printf("\n");
  159.     }
  160.     return(0);              /* success */
  161. }
  162.  
  163. lprint( desc, num)
  164. DFdesc  *desc;
  165. int num;
  166. {
  167.     
  168.     int i=0,j=0;
  169.     int prev=0, empty=0;
  170.  
  171.     while (j <num) {
  172.         if (desc[j].tag==DFTAG_NULL) {
  173.             empty++;
  174.             j++;
  175.             continue;               /* don't print anything now */
  176.         }
  177.         i=0;
  178.         while (tagdes[i].num!=desc[j].tag  && tagdes[i].num>0) i++;
  179.         printf("\n%s:", tagdes[i].name);
  180.         printf(" (tag %d)\n",desc[j].tag);
  181.         if (!longout) printf("\tRef nos:");
  182.         prev=desc[j].tag;
  183.         while (desc[j].tag==prev && j<num) {
  184.             if (longout)
  185.                 printf("\t\tRef no %6d   %8d bytes\n", desc[j].ref,
  186.                                                             desc[j].length);
  187.             else {
  188.                 printf(" %d",desc[j].ref);
  189.             }
  190.             j++;
  191.         }
  192.     }
  193.     printf("\nEmpty (tag %d): %d slots\n",DFTAG_NULL, empty);
  194.     return(0);
  195. }
  196.