home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / src / vconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  11.2 KB  |  448 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. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.3 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/vconv.c,v 1.3 1992/10/23 00:14:11 koziol beta koziol $
  30.  
  31. $Log: vconv.c,v $
  32.  * Revision 1.3  1992/10/23  00:14:11  koziol
  33.  * Changed all DFIstr*() and DFImem*() calls to HDstr*() and HDmem*() calls
  34.  * #ifdef'd out the macros Jason defined for Hopen, Hclose, etc. for Vsets
  35.  * Replaced Vset VFREESPACE and VGETSPACE calls with actual calls to HDfreespace
  36.  * and HDgetspace
  37.  * Added a MS-Windows lower lower for file I/O (which may not be completely working
  38.  *
  39.  * Revision 1.2  1992/10/12  18:11:51  koziol
  40.  * Updated for v3.2r2 release
  41.  *
  42.  * Revision 1.1  1992/08/25  21:40:44  koziol
  43.  * Initial revision
  44.  *
  45. */
  46. /* obsolete code for HDF 3.2. 26/march/92 jason ng */
  47. /* except for the following routines: 
  48. *    vicheckcompat()
  49. *     movebytes ()
  50. *     oldunpackvg ()
  51. *     oldunpackvs ()
  52. */
  53.  
  54.  
  55. /*
  56. *
  57. * vconv.c
  58. * Part of the HDF Vset interface.
  59. */
  60.  
  61. #include "vg.h" 
  62.  
  63. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  64. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  65. /*                                                                    */ 
  66. /* routines for converting from vsets in v1.0 to v2.x                 */
  67. /*                                                                    */ 
  68. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  69. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  70.  
  71. #define INT16SIZE 2
  72. #define INT32SIZE 4
  73.  
  74. /* ------------------------------------------------------------------ */
  75.  
  76. /*
  77. *  this routine checks that the given OPENED file is compatible with
  78. *    version 2.0 or later of the HDF Vset library .
  79. *  RETURNS 1  if file already compatible with r2.
  80. *          0  if not compatible.
  81. *          -1 if error.
  82. */
  83. #ifdef PROTOTYPE
  84. int32 vicheckcompat(HFILEID f)
  85. #else
  86. int32 vicheckcompat(f)
  87. HFILEID f;
  88. #endif
  89. {
  90.  
  91.     int16        foundold, foundnew;
  92.     int32     aid;    
  93.  
  94.     foundold = 0;
  95.     foundnew = 0;
  96.     /* locate any OLD vgs */
  97.          aid = QQstartread (f, (uint16)OLD_VGDESCTAG,  DFREF_WILDCARD);
  98.          if (aid != FAIL) foundold++;
  99.          QQendaccess (aid);
  100.  
  101.     /* locate any OLD vdatas */
  102.         aid = QQstartread(f, (uint16)OLD_VSDESCTAG,  DFREF_WILDCARD);
  103.         if (aid != FAIL) foundold++;
  104.         QQendaccess (aid);
  105.  
  106.  
  107.    /* locate any NEW vgs */
  108.         aid = QQstartread(f, NEW_VGDESCTAG,  DFREF_WILDCARD);
  109.         if (aid != FAIL) foundnew++;
  110.         QQendaccess (aid);
  111.  
  112.     /* locate any NEW vdatas */
  113.         aid = QQstartread(f, NEW_VSDESCTAG,  DFREF_WILDCARD);
  114.         if (aid != FAIL) foundnew++;
  115.         QQendaccess (aid);
  116.  
  117.  
  118.     if ( foundold == 0 ) /* has no old vset elements */
  119.         return (1); /* just assume compatible */
  120.  
  121.     if ( foundnew > 0 ) 
  122.         return (1); /* file is already compatible */
  123.     else
  124.         return (0); /* file is not compatible */
  125. } /* vicheckcompat */
  126.  
  127. /* ------------------------------------------------------------------ */
  128. /*
  129. * This routine will modify a given OPENED file so that is becomes compatible
  130. * with version 2.0 or later of the HDF Vset library.
  131. * Note that the file is assumed to be not compatible to begin with.
  132. * This routine will not check to see if the file is already compatible,
  133. * but it is harmless to run an already-compatible file through again.
  134. *
  135. * However, be aware that each time, the file gets larger.
  136. * Also, file must be opened with DFACC_ALL access.
  137. *
  138. * returns  1 if successful. if error, returns 0
  139. */
  140.  
  141.  
  142. #ifdef PROTOTYPE
  143. int32 vimakecompat(HFILEID f)
  144. #else
  145. int32 vimakecompat(f)
  146. HFILEID f;
  147. #endif
  148. {
  149.  
  150.     VGROUP     tempvgroup;
  151.     VDATA        tempvdata;
  152.  
  153.     VGROUP    * vg = &tempvgroup;
  154.     VDATA        *vs = &tempvdata;
  155.     BYTE        buf[5000]; /* to store an old vdata or vgroup descriptor  */
  156.     int32     bsize, aid;
  157.     int32   stat;
  158.     uint16 u;
  159.     uint16    tag, ref;
  160.  
  161.     /* =============================================  */
  162.     /* --- read all vgs and convert each --- */
  163.  
  164.     stat = aid = QQstartread (f, (uint16)OLD_VGDESCTAG, DFREF_WILDCARD);
  165.     while (stat != FAIL) {
  166.         QQQuerytagref (aid, &tag, &ref);
  167.         QQQuerylength (aid, &bsize);
  168.        stat = QQgetelement (f, (uint16)OLD_VGDESCTAG, ref, (uint8*)buf);
  169.         if (stat == FAIL) {
  170.             sprintf(sjs,"getvgroup_old. getelement err. \n"); zj;
  171.             return (0);
  172.             }
  173.  
  174.         oldunpackvg (vg, buf, &bsize);
  175.         /* add new items */
  176.             vg->vgclass[0] = '\0';
  177.             vg->extag = 0;
  178.             vg->exref = 0;
  179.             vg->version = 2; /* version 2 */
  180.             vg->more = 0;
  181.         /* inside each vgroup, change the old tags to new */
  182.             for(u=0;u<vg->nvelt;u++)
  183.                 if (vg->tag[u] == OLD_VGDESCTAG) vg->tag[u] = NEW_VGDESCTAG;
  184.                 else if (vg->tag[u] == OLD_VSDESCTAG) vg->tag[u] = NEW_VSDESCTAG;
  185.                 else { sprintf(sjs,"vimakecompat: unknown tag %d] in vgroup!\n",
  186.                                 vg->tag[u]); zj;
  187.                         }
  188.         vpackvg (vg, buf, &bsize);
  189.  
  190.          stat = QQputelement (f, VGDESCTAG, ref, (uint8*)buf, bsize);
  191.         if (stat == FAIL) {
  192.             sprintf(sjs,"put vgroup desc error.\n"); zj;
  193.             return (0);
  194.             }
  195.  
  196.         stat = QQnextread (aid, (uint16)OLD_VGDESCTAG, DFREF_WILDCARD, DF_CURRENT);
  197.         } /* while */
  198.     QQendaccess (aid);
  199.  
  200.     /* =============================================  */
  201.     /* --- read all vdata descs  and convert each --- */
  202.     /* --- then dup a tag for each vdata data elt --- */
  203.  
  204.     stat = aid = QQstartread (f, (uint16)OLD_VSDESCTAG, DFREF_WILDCARD);
  205.     while (stat != FAIL) {
  206.  
  207.         QQQuerytagref (aid, &tag, &ref);
  208.         QQQuerylength (aid, &bsize);
  209.         stat = QQgetelement (f, tag, ref, (uint8*)buf);
  210.         if (stat == FAIL) {
  211.             sprintf(sjs,"getvdata_old. getelement err. \n"); zj;
  212.             return (0);
  213.             }
  214.  
  215.         oldunpackvs (vs, buf, &bsize);
  216.  
  217.         /* add new items */
  218.             vs->vsclass[0] = '\0';
  219.             vs->extag = 0;
  220.             vs->exref = 0;
  221.             vs->version = 2; /* version 2 */
  222.             vs->more = 0;
  223.         vpackvs (vs, buf, &bsize);
  224.  
  225.       stat = QQputelement (f, VSDESCTAG, ref, (uint8*)buf, bsize);
  226.         if (stat == FAIL) {
  227.             sprintf(sjs ,"put vdata desc error.\n"); zj;
  228.             return (0);
  229.             }
  230.  
  231.         /* duplicate a tag to point to vdata data */
  232.             stat = QQdupdd (f, NEW_VSDATATAG, ref, (uint16)OLD_VSDATATAG, ref);
  233.              if (stat == FAIL) {
  234.                      sprintf(sjs,"Hdupdd - cannot duplicate vdata.\n"); zj;
  235.                     return (0);
  236.                     }
  237.         stat = QQnextread (aid, (uint16)OLD_VSDESCTAG, DFREF_WILDCARD, DF_CURRENT);
  238.         } /* while */
  239.  
  240.     QQendaccess (aid);
  241.  
  242.     return(1);
  243.  
  244. } /* vimakecompat */
  245.  
  246.  
  247. /* ================================================================== */
  248. /*
  249. *  this routine checks that the given file is compatible with
  250. *    version 2.0 or later of the HDF Vset library .
  251. *
  252. *  All it does is to open the file, call vicheckcompat to do all the
  253. *  checking, and then closes it.
  254. *    See comments for vicheckcompat().
  255.  
  256. *  returns 1 if file already compatible with r2.
  257. *          0 if not compatible.
  258. *          -1 if error.
  259. */
  260.  
  261. #ifdef PROTOTYPE
  262. int32 vcheckcompat(char *fs)
  263. #else
  264. int32 vcheckcompat(fs)
  265. char * fs;
  266. #endif
  267. {
  268.  
  269.     HFILEID    f;
  270.     int32     stat;
  271.  
  272.     f = QQopen (fs,DFACC_ALL,0);
  273.     if (f == FAIL) {
  274.         sprintf(sjs,"vcheckcompat: cannot open %s\n",fs); zj;
  275.         return (-1);
  276.         }         
  277.     stat = vicheckcompat(f); 
  278.     QQclose (f);    
  279.  
  280.     return (stat);
  281. } /* vcheckcompat */
  282.  
  283. /* ================================================================== */
  284. /*
  285. * This routine will modify a given file so that is becomes compatible
  286. * with version 2.0 or later of the HDF Vset library.
  287. *
  288. * All this routine does is to open the file, call vimakecompat to
  289. * do all the conversion, and then to close the file.
  290. * See comments for vimakecompat().
  291. *
  292. * returns  1 if successful. if error, returns 0
  293. */
  294.  
  295. #ifdef PROTOTYPE
  296. int32 vmakecompat(char * fs) 
  297. #else
  298.  
  299. int32 vmakecompat(fs) 
  300.     char * fs; 
  301.  
  302. #endif
  303.  
  304. {
  305.     HFILEID     f;
  306.     int32     stat;
  307.  
  308.     f = QQopen (fs,DFACC_ALL,0);
  309.    if (f == FAIL) { 
  310.         sprintf(sjs,"vmakecompat: cannot open %s\n",fs); zj;
  311.         return (0);
  312.         }         
  313.     stat = vimakecompat(f);
  314.     QQclose (f);
  315.     return (stat);
  316.  
  317. } /* vmakecompat */
  318.  
  319. /* ==================================================================== */
  320.  
  321. #ifdef PROTOTYPE
  322. void oldunpackvg (VGROUP *vg,BYTE  buf[], int32 *size)   
  323. #else
  324.  
  325. void oldunpackvg (vg, buf, size)   
  326.  
  327.     VGROUP*        vg;        /* vgroup to be loaded with file data */
  328.     BYTE            buf[];     /* must contain a VGDESCTAG data object from file */
  329.     int32*         size;      /* ignored, but included to look like packvg() */
  330.  
  331. #endif
  332.  
  333. {
  334.  
  335.     BYTE            *b, *bb;
  336.     uint32       i;
  337.     char * FUNC = "oldunpackvg";
  338.  
  339.     *size = *size; /* dummy, so that compiler thinks it is used  */
  340.  
  341.     bb = &buf[0];
  342.  
  343.     /* retrieve nvelt */
  344.     b = bb;
  345.     INT16DECODE(b,vg->nvelt);
  346.     bb+=INT16SIZE;
  347.  
  348.     /* retrieve the tags */
  349.     for (i=0;i<vg->nvelt;i++) {
  350.         b= bb;
  351.         INT16DECODE(b,vg->tag[i]);
  352.         bb +=INT16SIZE;
  353.     }
  354.  
  355.     /* retrieve the refs */
  356.     for (i=0;i<vg->nvelt;i++) {
  357.         b= bb;
  358.         INT16DECODE(b,vg->ref[i]);
  359.         bb +=INT16SIZE;
  360.     }
  361.  
  362.     /* retrieve vgname */
  363.     HDstrcpy(vg->vgname, (char*) bb);
  364.     bb += ( HDstrlen(vg->vgname)+1 );
  365.  
  366.     if (vjv) {
  367.         sprintf(sjs,"unpackvg: vgname is [%s]\n",vg->vgname);
  368.         zj;
  369.     }
  370.  
  371. } /* unpackvg */
  372.  
  373. /* ================================================================= */
  374.  
  375. #ifdef PROTOTYPE
  376. void oldunpackvs (VDATA *vs, BYTE buf[], int32 *size)       
  377. #else
  378. void oldunpackvs (vs, buf, size)       
  379.  
  380.     VDATA     *vs;
  381.     int32       *size;    /* UNUSED, but retained for compatibility with packvs */
  382.     BYTE        buf[];
  383.  
  384. #endif
  385.  
  386. {
  387.     BYTE        *b, *bb;
  388.     int16    i;
  389.     char * FUNC = "oldunpackvs";
  390.  
  391.     *size = *size; /* dummy */
  392.  
  393.     bb = &buf[0];
  394.  
  395.     b = bb;
  396.     INT16DECODE(b,vs->interlace);
  397.     bb += INT16SIZE;
  398.  
  399.     b = bb;
  400.     INT32DECODE(b,vs->nvertices);
  401.     bb += INT32SIZE;
  402.  
  403.     b = bb;
  404.     INT16DECODE(b,vs->wlist.ivsize);
  405.     bb += INT16SIZE;
  406.  
  407.     b = bb;
  408.     INT16DECODE(b,vs->wlist.n);
  409.     bb += INT16SIZE;
  410.  
  411.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the type */
  412.         b = bb;
  413.         INT16DECODE(b,vs->wlist.type[i]);
  414.         bb += INT16SIZE;
  415.     }
  416.  
  417.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the isize */
  418.         b = bb;
  419.         INT16DECODE(b,vs->wlist.isize[i]);
  420.         bb += INT16SIZE;
  421.     }
  422.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the off */
  423.         b = bb;
  424.         INT16DECODE(b,vs->wlist.off[i]);
  425.         bb += INT16SIZE;
  426.     }
  427.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the order */
  428.         b = bb;
  429.         INT16DECODE(b,vs->wlist.order[i]);
  430.         bb += INT16SIZE;
  431.     }
  432.     for (i=0;i<vs->wlist.n;i++) {
  433.         HDstrcpy(vs->wlist.name[i],  (char*) bb);
  434.         bb += ( HDstrlen(vs->wlist.name[i]) + 1 );
  435.     }
  436.  
  437.     HDstrcpy(vs->vsname, (char*) bb);
  438.     bb += ( HDstrlen(vs->vsname) + 1);
  439.  
  440.     /* **EXTRA**  fill in the machine-dependent size fields */
  441.     for (i=0;i<vs->wlist.n;i++) {
  442.         vs->wlist.esize[i] = vs->wlist.order[i] * SIZEOF(vs->wlist.type[i]);
  443.     }
  444.  
  445. } /* unpackvs */
  446.  
  447. /* ------------------------------------------------------------------ */
  448.