home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / VSet2.0 / temp / vshow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-12  |  7.0 KB  |  281 lines  |  [TEXT/????]

  1. /*****************************************************************************
  2. *
  3. * vshow.c
  4. *
  5. *    HDF Vset utility.
  6. *
  7. *    vshow:     dumps out vsets in a hdf file.
  8. *
  9. *    Usage:  vshow [file] {+{n}}
  10. *        the '+' option indicates a full dump on all vdatas.
  11. *        '+n' means full dump only for the nth vdata.
  12. *
  13. *
  14. *****************************************************************************
  15. *              NCSA HDF Vset release 2.1
  16. *                    May 1991
  17. *                 Jason Ng May 1991 NCSA
  18. *
  19. * NCSA HDF Vset release 2.1 source code and documentation are in the public
  20. * domain.  Specifically, we give to the public domain all rights for future
  21. * licensing of the source code, all resale rights, and all publishing rights.
  22. * We ask, but do not require, that the following message be included in all
  23. * derived works:
  24. * Portions developed at the National Center for Supercomputing Applications at
  25. * the University of Illinois at Urbana-Champaign.
  26. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  27. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  28. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  29. ******************************************************************************/
  30.  
  31. #include "vg.h"
  32.  
  33. static int condensed;
  34. static char sbuf[80]; /* message buffer */
  35. #define PMSG     fprintf(stderr,"%s",sbuf)
  36.  
  37. #ifdef MAC
  38. int vsdumpfull(VDATA *);
  39. #endif
  40.  
  41. main(ac,av) int ac; 
  42. char**av;
  43. {
  44.     VGROUP       *vg, *vgt;
  45.     VDATA      *vs;
  46.     DF*                f;
  47.     int vgid = -1;
  48.     int vsid = -1;
  49.     int vsno = 0;
  50.     int    vstag;
  51.  
  52.     int i, t, nvg, n, ne, nv, interlace, vsize;
  53.     int * lonevs; /* array to store refs of all lone vdatas */
  54.     int nlone; /* total number of lone vdatas */
  55.  
  56.     char fields[50], vgname[50],vsname[50];
  57.     char  vgclass[50],vsclass[50];
  58.     int fulldump = 0;
  59.  
  60.     if (ac==3) if(av[2][0]=='-'||av[2][0]=='+') {
  61.         sscanf(&(av[2][1]),"%d",&vsno);
  62.         if(vsno == 0) {
  63.             sprintf(sbuf,"FULL DUMP\n"); 
  64.             PMSG; 
  65.         }
  66.         else { 
  67.             sprintf(sbuf,"FULL DUMP on vs#%d\n",vsno); 
  68.             PMSG; 
  69.         }
  70.         fulldump = 1;
  71.         if(av[2][0]=='+') condensed = 1; 
  72.         else condensed = 0;
  73.     }
  74.     if(ac<2) {
  75.         sprintf(sbuf,"%s: dumps HDF vsets info from hdf file\n",av[0]);
  76.         PMSG;
  77.         sprintf(sbuf,"usage: %s file {+n} \n", av[0]);
  78.         PMSG;
  79.         sprintf(sbuf,"\t +  gives full dump of all vdatas.\n"); 
  80.         PMSG;
  81.         sprintf(sbuf,"\t +n gives full dump of vdata with id n.\n"); 
  82.         PMSG;
  83.         exit(0);
  84.     }
  85.     if((f=DFopen(av[1],DFACC_READ,0))==NULL) exit(0);
  86.     sprintf(sbuf,"\nFILE: %s\n",av[1]);
  87.     PMSG;
  88.  
  89.     nvg=0;
  90.     while( (vgid = Vgetid(f,vgid)) != -1) {
  91.         vg = (VGROUP*) Vattach(f,vgid,"r");
  92.         if(vg==NULL) {
  93.             sprintf(sbuf,"cannot open vg id=%d\n",vgid);
  94.             PMSG;
  95.         }
  96.         Vinquire(vg,&n, vgname);
  97.         Vgetclass(vg, vgclass); 
  98.         if (strlen(vgname)==0)  strcat(vgname,"NoName");
  99.         sprintf(sbuf,"\nvg:%d <%d/%d> (%s.%s) has %d entries:\n",
  100.             nvg, vg->otag, vg->oref, vgname, vgclass,n);
  101.         PMSG;
  102.  
  103.         for (t=0; t< Vntagrefs(vg); t++) {
  104.             Vgettagref(vg, t, &vstag, &vsid);
  105.             
  106.             if (vstag==VSDESCTAG)  {  /* ------ V D A T A ---------- */
  107.                 vs = (VDATA *) VSattach(f,vsid,"r");
  108.                 if(vs==NULL) {
  109.                     sprintf(sbuf,"cannot open vs id=%d\n",vsid);
  110.                     PMSG;
  111.                 }
  112.                 VSinquire(vs, &nv,&interlace, fields, &vsize, vsname);
  113.                 if (strlen(vsname)==0)  strcat(vsname,"NoName");
  114.                 VSgetclass(vs,vsclass); 
  115.                 sprintf(sbuf,"  vs:%d <%d/%d> nv=%d i=%d fld [%s] vsize=%d (%s.%s)\n",
  116.                     t, vs->otag, vs->oref, nv, interlace, 
  117.                     fields, vsize, vsname, vsclass);
  118.                 PMSG;
  119.                 if(fulldump && vsno==0) vsdumpfull(vs);
  120.                 else if(fulldump && vsno==vs->oref) vsdumpfull(vs);
  121.  
  122.                 VSdetach(vs);
  123.             }
  124.             else if (vstag==VGDESCTAG)  {  /* ------ V G R O U P ----- */
  125.                 vgt = (VGROUP*) Vattach(f,vsid,"r");
  126.                 if(vgt==NULL) {
  127.                     sprintf(sbuf,"cannot open vg id=%d\n",vsid);
  128.                     PMSG;
  129.                 }
  130.                 Vinquire(vgt, &ne, vgname);
  131.                 if (strlen(vgname)==0)  strcat(vgname,"NoName");
  132.                 Vgetclass(vgt, vgclass);
  133.                 sprintf(sbuf,"  vg:%d <%d/%d> ne=%d (%s.%s)\n",
  134.                     t, vgt->otag, vgt->oref, ne,  vgname, vgclass );
  135.                 PMSG;
  136.                 Vdetach(vgt);
  137.             }
  138.             else {
  139.                 sprintf(sbuf,"  --:%d <%d/%d>  NON-VSET element\n", t,vstag,vsid);
  140.                 PMSG;
  141.             }
  142.         } /* while */
  143.         Vdetach(vg);
  144.         nvg++;
  145.     } /* while */
  146.  
  147.     if(nvg==0) {
  148.         sprintf(sbuf,"No vgroups in this file\n");
  149.         PMSG;
  150.         }
  151.  
  152.     nlone = VSlone(f,NULL,0);
  153.     if(nlone > 0) {
  154.         sprintf(sbuf,"Lone vdatas:\n"); PMSG;
  155.         if (NULL == (lonevs = (int*) DFIgetspace (sizeof(int)*nlone))) {
  156.             sprintf(sbuf,"%s: File has %d lone vdatas but ",av[0],nlone ); PMSG;
  157.            sprintf(sbuf,"cannot alloc lonevs space. Quit.\n"); PMSG; 
  158.               exit(0);
  159.                 }
  160.         VSlone(f,lonevs, nlone);
  161.         for(i=0; i<nlone;i++) {
  162.             vsid = lonevs[i];
  163.             if( NULL == ( vs = (VDATA *) VSattach(f,lonevs[i],"r"))) {
  164.                 sprintf(sbuf,"cannot open vs id=%d\n",vsid);
  165.                 PMSG;
  166.                 }
  167.             VSinquire (vs, &nv,&interlace, fields, &vsize, vsname);
  168.             if (strlen(vsname)==0)  strcat(vsname,"NoName");
  169.             VSgetclass (vs, vsclass);
  170.             sprintf(sbuf,"L vs:%d <%d/%d> nv=%d i=%d fld [%s] vsize=%d (%s.%s)\n",
  171.                          vsid, vs->otag, vs->oref, nv, interlace, fields,
  172.                              vsize, vsname, vsclass);
  173.             PMSG;
  174.             if (fulldump && vsno==0) vsdumpfull(vs);
  175.             else if (fulldump && vsno==vs->oref) vsdumpfull(vs);
  176.             VSdetach(vs);
  177.             }
  178.         DFIfreespace (lonevs);
  179.         }
  180.  
  181.     DFclose(f);
  182.  
  183. } /* main */
  184.  
  185.  
  186. /* ------------------------------------------------ */
  187. /* printing functions used by vsdumpfull(). */
  188. static int cn = 0;
  189. int fmtchar(x) char*x;       { cn++; putchar(*x); return(1); }
  190. int fmtint(x) int*x;           { cn += printf("%d ",*x); return(1);  }
  191. int fmtfloat(x) float*x;     { cn += printf("%f ",*x); return(1);  }
  192. int fmtlong(x) int*x;       { cn += printf("%ld ",*x); return(1);  }
  193. /* ------------------------------------------------ */
  194.  
  195. int vsdumpfull(vs) VDATA * vs; 
  196. {
  197.     char vsname[100], fields[100];
  198.     int i,t,interlace, nv, vsize;
  199.     char *bb, *b;
  200.     VWRITELIST* w;
  201.     int (*fmtfn[20])();
  202.     int off[20];
  203.  
  204.     int nf;
  205.  
  206.     VSinquire(vs, &nv,&interlace, fields, &vsize, vsname);
  207.     bb = (char*) DFIgetspace (nv*vsize);
  208.     if(bb==NULL) { 
  209.         sprintf(sbuf,"vsdumpfull malloc error\n");
  210.         PMSG; 
  211.         return(0); 
  212.     }
  213.  
  214.     VSsetfields(vs,fields);
  215.     VSread(vs,bb,nv,interlace);
  216.  
  217.     w = &(vs->wlist);
  218.     nf=0;
  219.  
  220.     for (i=0;i<w->n;i++) {
  221.         printf("%d: fld [%s], type=%d, order=%d\n",
  222.             i, w->name[i], w->type[i], w->order[i]);
  223.         switch(w->type[i]) {
  224.         case LOCAL_FLOATTYPE:
  225.             for(t=0;t<w->order[i];t++,nf++) {
  226.                 fmtfn[nf] = fmtfloat;
  227.                 off[nf] = sizeof(float);
  228.             }
  229.             break;
  230.         case LOCAL_INTTYPE:
  231.             for(t=0;t<w->order[i];t++,nf++) {
  232.                 fmtfn[nf] = fmtint;
  233.                 off[nf] = sizeof(int);
  234.             }
  235.             break;
  236.         case LOCAL_CHARTYPE:
  237.             for(t=0;t<w->order[i];t++,nf++) {
  238.                 fmtfn[nf] = fmtchar;
  239.                 off[nf] = sizeof(char);
  240.             }
  241.             break;
  242.         case LOCAL_LONGTYPE:
  243.             for(t=0;t<w->order[i];t++,nf++) {
  244.                 fmtfn[nf] = fmtlong;
  245.                 off[nf] = sizeof(long);
  246.             }
  247.             break;
  248.         }
  249.     }
  250.  
  251.     b= bb;
  252.     cn=0;
  253.     for(i=0;i<nv;i++) {
  254.         for(t=0;t<nf;t++) { 
  255.             (fmtfn[t]) (b); 
  256.             b+=off[t]; 
  257.         }
  258.         if (condensed)
  259.         { 
  260.             if( cn > 70) { putchar('\n'); cn=0; } 
  261.         }
  262.         else 
  263.             putchar('\n');
  264.     }
  265.  
  266.     /* ============================================ */
  267.  
  268.     DFIfreespace (bb);
  269.     putchar('\n'); 
  270.     putchar('\n');
  271.  
  272.     return(1);
  273.  
  274. } /* vsdumpfull */
  275. /* ------------------------------------- */
  276.