home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / vshow.c < prev   
Encoding:
C/C++ Source or Header  |  1992-10-28  |  8.2 KB  |  351 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. /*****************************************************************************
  26. *
  27. * vshow.c
  28. *
  29. *    HDF Vset utility.
  30. *
  31. *    vshow:     dumps out vsets in a hdf file.
  32. *
  33. *    Usage:  vshow [file] {+{n}}
  34. *        the '+' option indicates a full dump on all vdatas.
  35. *        '+n' means full dump only for the nth vdata.
  36. *
  37. ******************************************************************************/
  38.  
  39. #include "vg.h"
  40.  
  41. static int condensed;
  42.  
  43. #ifdef MAC
  44. int vsdumpfull(VDATA *);
  45. #endif
  46.  
  47. int32 vsdumpfull
  48.   PROTO((VDATA * vs)); 
  49.  
  50. main(ac,av) int ac; 
  51. char**av;
  52. {
  53.   VGROUP       *vg, *vgt;
  54.   VDATA          *vs;
  55.   HFILEID        f;
  56.   int32 vgid = -1;
  57.   int32 vsid = -1;
  58.   int32 vsno = 0;
  59.   int32    vstag;
  60.   
  61.   int32 i, t, nvg, n, ne, nv, interlace, vsize;
  62.   int32 * lonevs; /* array to store refs of all lone vdatas */
  63.   int32 nlone; /* total number of lone vdatas */
  64.   
  65.   char fields[50], vgname[50],vsname[50];
  66.   char  vgclass[50],vsclass[50], *name;
  67.   int32 fulldump = 0, start = 1;
  68.   
  69.   if (ac == 3) if(av[2][0]=='-'||av[2][0]=='+') {
  70.     sscanf(&(av[2][1]),"%d",&vsno);
  71.     if(vsno == 0) {
  72.       printf("FULL DUMP\n"); 
  73.     } else { 
  74.       printf("FULL DUMP on vs#%d\n",vsno); 
  75.     }
  76.     fulldump = 1;
  77.     if(av[2][0]=='+') condensed = 1; 
  78.     else condensed = 0;
  79.     start = 2;
  80.   }
  81.  
  82.   if(ac < 2) {
  83.     printf("%s: dumps HDF vsets info from hdf file\n",av[0]);
  84.     printf("usage: %s file {+n} \n", av[0]);
  85.     printf("\t +  gives full dump of all vdatas.\n"); 
  86.     printf("\t +n gives full dump of vdata with id n.\n"); 
  87.     exit(0);
  88.   }
  89.  
  90.   if((f=DFvsetopen(av[1],DFACC_READ,0))==FAIL) exit(0);
  91.   printf("\nFILE: %s\n",av[1]);
  92.   
  93.   nvg=0;
  94.   while( (vgid = Vgetid(f,vgid)) != -1) {
  95.     vg = (VGROUP*) Vattach(f,vgid,"r");
  96.     if(vg==NULL) {
  97.       printf("cannot open vg id=%d\n",vgid);
  98.     }
  99.     Vinquire(vg,&n, vgname);
  100.     Vgetclass(vg, vgclass); 
  101.     if (HDstrlen(vgname)==0)  strcat(vgname,"NoName");
  102.     printf("\nvg:%d <%d/%d> (%s {%s}) has %d entries:\n",
  103.            nvg, vg->otag, vg->oref, vgname, vgclass,n);
  104.     
  105.     for (t=0; t< Vntagrefs(vg); t++) {
  106.       Vgettagref(vg, t, &vstag, &vsid);
  107.       
  108.       /* ------ V D A T A ---------- */
  109.       if (vstag==VSDESCTAG)  {  
  110.         vs = (VDATA *) VSattach(f,vsid,"r");
  111.  
  112.         if(vs==NULL) {
  113.           printf("cannot open vs id=%d\n",vsid);
  114.           continue;
  115.         }
  116.  
  117.         VSinquire(vs, &nv,&interlace, fields, &vsize, vsname);
  118.         if (HDstrlen(vsname)==0)  strcat(vsname,"NoName");
  119.         VSgetclass(vs,vsclass); 
  120.         printf("  vs:%d <%d/%d> nv=%d i=%d fld [%s] vsize=%d (%s {%s})\n",
  121.                 t, vs->otag, vs->oref, nv, interlace, fields, vsize, vsname, vsclass);
  122.         
  123.         if(fulldump && vsno==0) vsdumpfull(vs);
  124.         else if(fulldump && vsno==vs->oref) vsdumpfull(vs);
  125.         
  126.         VSdetach(vs);
  127.       }
  128.       else 
  129.         if (vstag==VGDESCTAG)  {  
  130.           /* ------ V G R O U P ----- */
  131.           vgt = (VGROUP*) Vattach(f,vsid,"r");
  132.           
  133.           if(vgt==NULL) {
  134.             printf("cannot open vg id=%d\n",vsid);
  135.             continue;
  136.           }
  137.           
  138.           Vinquire(vgt, &ne, vgname);
  139.           if (HDstrlen(vgname)==0)  strcat(vgname,"NoName");
  140.           Vgetclass(vgt, vgclass);
  141.           printf("  vg:%d <%d/%d> ne=%d (%s {%s})\n",
  142.                  t, vgt->otag, vgt->oref, ne,  vgname, vgclass );
  143.           Vdetach(vgt);
  144.         }
  145.         else { 
  146.           name = HDgettagname(vstag);
  147.           if(!name) name = "Unknown Tag";
  148.           printf("  --:%d <%d/%d> %s\n", t, vstag, vsid, name);
  149.         }
  150.     } /* while */
  151.     
  152.     Vdetach(vg);
  153.     nvg++;
  154.  
  155.   } /* while */
  156.   
  157.   if(nvg==0) {
  158.     printf("No vgroups in this file\n");
  159.   }
  160.   
  161.   nlone = VSlone(f,NULL,0);
  162.   if(nlone > 0) {
  163.  
  164.     printf("Lone vdatas:\n");
  165.     if (NULL == (lonevs = (int32 *) HDgetspace (sizeof(int)*nlone))) {
  166.       printf("%s: File has %d lone vdatas but ",av[0],nlone ); 
  167.       printf("cannot alloc lonevs space. Quit.\n"); 
  168.       exit(0);
  169.     }
  170.  
  171.     VSlone(f,lonevs, nlone);
  172.     for(i=0; i<nlone;i++) {
  173.       vsid = lonevs[i];
  174.       if( NULL == ( vs = (VDATA *) VSattach(f,lonevs[i],"r"))) {
  175.         printf("cannot open vs id=%d\n",vsid);
  176.         continue;
  177.       }
  178.       VSinquire (vs, &nv,&interlace, fields, &vsize, vsname);
  179.       if (HDstrlen(vsname)==0)  strcat(vsname,"NoName");
  180.       VSgetclass (vs, vsclass);
  181.       printf("L vs:%d <%d/%d> nv=%d i=%d fld [%s] vsize=%d (%s {%s})\n",
  182.               vsid, vs->otag, vs->oref, nv, interlace, fields, vsize, vsname, vsclass);
  183.       if (fulldump && vsno==0) vsdumpfull(vs);
  184.       else if (fulldump && vsno==vs->oref) vsdumpfull(vs);
  185.       VSdetach(vs);
  186.     }
  187.     HDfreespace (lonevs);
  188.   }
  189.  
  190.   DFvsetclose(f);
  191.   
  192. } /* main */
  193.  
  194.  
  195. /* ------------------------------------------------ */
  196. /* printing functions used by vsdumpfull(). */
  197. static int32 cn = 0;
  198. int32 fmtbyte(x) unsigned char*x;  { cn += printf("%02x ",*x); return(1);  }
  199.  
  200. int32 fmtchar(x) char*x; 
  201.   cn++; putchar(*x); return(1);
  202. }
  203.  
  204. int32 fmtint(x) 
  205.      char* x;
  206. {    
  207.   int *i;
  208.   i = (int *) x;
  209.   cn += printf("%d", *i); 
  210.   return(1);  
  211. }
  212.  
  213. int32 fmtfloat(x) 
  214.      char* x;
  215. {
  216.   float *f;
  217.   f = (float *) x;
  218.   cn += printf("%f", *f); 
  219.   return(1);  
  220. }
  221.  
  222. int32 fmtlong(x) 
  223.      char* x;   
  224. {    
  225.   long *l;
  226.   l = (long *) x;
  227.   cn += printf("%ld", *l);
  228.   return(1);  
  229. }
  230.  
  231. int32 fmtshort(x) 
  232.      char* x;   
  233. {    
  234.   short *s;
  235.   s = (short *) x;
  236.   cn += printf("%d", *s);
  237.   return(1);  
  238. }
  239.  
  240. int32 fmtdouble(x) char*x;
  241. {    
  242.   double *d;
  243.   d = (double *) x;
  244.   cn += printf("%f", *d); 
  245.   return(1);  
  246. }
  247.  
  248. /* ------------------------------------------------ */
  249.  
  250. int32 vsdumpfull(vs) VDATA * vs; 
  251. {
  252.   char vsname[100], fields[100];
  253.   int32 j,i,t,interlace, nv, vsize;
  254.   BYTE *bb, *b;
  255.   VWRITELIST* w;
  256.   int32 (*fmtfn[60])();
  257.   int32 off[60];
  258.   int32 order[60];
  259.   
  260.   int32 nf;
  261.   
  262.   VSinquire(vs, &nv,&interlace, fields, &vsize, vsname);
  263.   bb = (BYTE *) HDgetspace (nv*vsize);
  264.   if(bb==NULL) { 
  265.     printf("vsdumpfull malloc error\n");
  266.     return(0); 
  267.   }
  268.  
  269.   VSsetfields(vs,fields);
  270.   VSread(vs,bb,nv,interlace);
  271.   
  272.   w = &(vs->wlist);
  273.   
  274.   nf = w->n;
  275.   for (i=0; i < w->n; i++) {
  276.     printf("%d: fld [%s], type=%d, order=%d\n", i, w->name[i], w->type[i], w->order[i]);
  277.  
  278.     order[i] = w->order[i];
  279.     off[i]   = DFKNTsize(w->type[i] | DFNT_NATIVE);
  280.     
  281.     switch(w->type[i]) {
  282.       
  283.     case DFNT_CHAR:
  284.       fmtfn[i] = fmtchar;
  285.       break;
  286.       
  287.     case DFNT_UINT8:
  288.     case DFNT_INT8:
  289.       fmtfn[i] = fmtbyte;
  290.       break;
  291.       
  292.     case DFNT_UINT16:
  293.     case DFNT_INT16:
  294.       fmtfn[i] = fmtshort;
  295.       break;
  296.       
  297.     case DFNT_UINT32:
  298.     case DFNT_INT32:
  299.       fmtfn[i] = fmtlong;
  300.       break;
  301.       
  302.     case DFNT_FLOAT32:
  303.       fmtfn[i] = fmtfloat;
  304.       break;
  305.       
  306.     case DFNT_FLOAT64:
  307.       fmtfn[i] = fmtdouble;
  308.       break;
  309.       
  310.     default: 
  311.       fprintf(stderr,"sorry, type [%s] not supported\n", w->type[i]); 
  312.       break;
  313.  
  314.     }
  315.   }
  316.   
  317.   b= bb;
  318.   cn=0;
  319.   
  320.   for(j = 0; j < nv; j++) {
  321.     for(i = 0; i < nf; i++) {
  322.       for(t=0; t < order[i]; t++) { 
  323.         (fmtfn[i]) (b); 
  324.         b += off[i]; 
  325.         putchar(' ');
  326.         cn++;
  327.       }
  328.       putchar(' ');
  329.       cn++;
  330.     }
  331.     
  332.     if (condensed) { 
  333.       if(cn > 65) { 
  334.         putchar('\n'); 
  335.         cn=0; 
  336.       } 
  337.     } 
  338.     else putchar('\n');
  339.   }
  340.   
  341.   /* ============================================ */
  342.   
  343.   HDfreespace (bb);
  344.   printf("\n\n");
  345.   
  346.   return(1);
  347.   
  348. } /* vsdumpfull */
  349. /* ------------------------------------- */
  350.