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 / Src / vconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-20  |  20.2 KB  |  870 lines  |  [TEXT/????]

  1. /*****************************************************************************
  2. *              NCSA HDF Vset release 2.1
  3. *                    May 1991
  4. *
  5. * NCSA HDF Vset release 2.1 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. * Likkai Ng NCSA May 91
  17. *
  18. * vconv.c
  19. * Part of the HDF Vset interface.
  20.  
  21.   conversion routines
  22.   -------------------
  23.  
  24.   Routines here convert an array of numbers to and from IEEE format.
  25.   Numbers do not have to be contiguous within array: specify the
  26.   step as the distance (in bytes) between consecutive numbers.
  27.  
  28. Description of arguments:
  29.  
  30.     machfp - pointer to buffer for machine data
  31.     ieeefp - pointer to data for IEEE data.
  32.     mstep  - distance betwn consecutive data in machine buffer.
  33.     istep  - distance betwn consecutive data in IEEE buffer.
  34.     n        - no of numbers to convert)
  35.  
  36. These routines always return 1.
  37.  
  38. ************************************************************************/
  39.  
  40.  
  41. #include "vg.h"
  42.  
  43. /* ============================================================== */
  44. /* ================== S T U B for unimplemented conversions ===== */
  45. /* ============================================================== */
  46. nolongfn()                            /*@@*/
  47. {
  48.   fprintf(stderr,"This long conversion fn not implemented\n");
  49. }
  50.  
  51.  
  52. /* ============================================================== */
  53. /* ================== U N T Y P E D ============================= */
  54. /* ============================================================== */
  55. /* 
  56.     the data is stored unconverted, ie stored in local machine 
  57.     represention. such files are NOT portable, and are of use
  58.     only to applications on the same machine.  Of course, sun-like
  59.     machines may be able to share such files among themselves if
  60.     they are lucky. No guarantees.  
  61.  
  62.    there are only 2 routines: DIRECTtoIEEE and DIRECTfromIEEE 
  63. */
  64.  
  65. int DIRECTtoIEEE (machfp, ieeefp, mstep, istep, n)        /*@@*/
  66.  
  67. unsigned char *machfp, *ieeefp;
  68. int mstep, istep, n;
  69. {
  70.     int ret;
  71.  
  72.     ret = istep;
  73.     if(vjv) {
  74.         sprintf(sjs,"#in DIRECTtoIEEE: which invokes bytetoIEEE\n");
  75.         zj;
  76.     }
  77.     ret = bytetoIEEE(machfp, ieeefp, mstep, mstep, n);
  78.  
  79.     return(ret);
  80.  
  81. } /* DIRECTtoIEEE */
  82.  
  83.  
  84. int DIRECTfromIEEE (ieeefp, machfp, istep, mstep, n)        /*@@*/
  85.  
  86. unsigned char *machfp, *ieeefp;
  87. int mstep, istep, n;
  88. {
  89.     int ret;
  90.  
  91.     if(vjv) {
  92.         sprintf(sjs,"#in DIRECTfromIEEE: which invokes bytefromIEEE\n");
  93.         zj;
  94.     }
  95.     ret = bytefromIEEE(ieeefp, machfp, istep, mstep, n);
  96.  
  97.     return(ret);
  98.  
  99. } /* DIRECTfromIEEE */
  100.  
  101.  
  102. /* ============================================================== */
  103. /* ==================== B Y T E S =============================== */
  104. /* ============================================================== */
  105.  
  106. /* there are only 2 routines: bytetoIEEE and bytefromIEEE  */
  107.  
  108. int bytetoIEEE (machfp, ieeefp, mstep, istep, n)        /*@@*/
  109.  
  110. unsigned char *machfp, *ieeefp;
  111. int mstep, istep, n;
  112. {
  113.     int j,t;
  114.     register unsigned char *mfp, *ifp, *i, *m;
  115.  
  116.     if(vjv) {
  117.         sprintf(sjs,"# in bytetoIEEE\n");
  118.         zj;
  119.     }
  120.  
  121.     mfp = machfp;
  122.     ifp = ieeefp;
  123.     for (j=0;j<n;j++) {
  124.         for (i=ifp, m=mfp, t=0;t<4;t++) *i++ = *m++;
  125.         mfp += mstep;
  126.         ifp += istep;
  127.     }
  128.  
  129.     return(1);
  130.  
  131. } /* bytetoIEEE */
  132.  
  133. int bytefromIEEE (ieeefp, machfp, istep, mstep, n)        /*@@*/
  134.  
  135. unsigned char *machfp, *ieeefp;
  136. int mstep, istep, n;
  137. {
  138.     int t,j;
  139.     register unsigned char *mfp, *ifp, *i, *m;
  140.  
  141.     if(vjv) {
  142.         sprintf(sjs,"# in bytefromIEEE\n");
  143.         zj;
  144.     }
  145.  
  146.     mfp = machfp;
  147.     ifp = ieeefp;
  148.     for (j=0;j<n;j++) {
  149.         for (i=ifp, m=mfp, t=0;t<4;t++) *m++ = *i++;
  150.         mfp += mstep;
  151.         ifp += istep;
  152.     }
  153.  
  154.     return(1);
  155.  
  156. } /* bytefromIEEE */
  157.  
  158.  
  159. /* ============================================================== */
  160. /* ================= I N T E G E R S ============================ */
  161. /* ============================================================== */
  162.  
  163.  
  164. /* src are on this machine , dst are IEEE */
  165.  
  166. int inttoIEEE (src,dst,sdelta,ddelta,n)            /*@@*/
  167.  
  168. unsigned char *src, *dst;
  169. int      n, sdelta, ddelta;
  170. {
  171.     int temp,i,j,sdel,ddel;
  172.     register unsigned char *s, *ss, *d, *dd;
  173.     register unsigned char *t;
  174.  
  175.     sdel = sdelta;
  176.     ddel = ddelta;
  177.     ss = src;
  178.     dd = dst;
  179.  
  180.     if(vjv){
  181.         sprintf(sjs,"#in inttoIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  182.         zj;
  183.     }
  184.  
  185.     for (i=0;i<n;i++) {
  186.         t = (unsigned char*) &temp;
  187.         s = ss;
  188.         for(j=0;j<sizeof(temp);j++) *t++ = *s++;
  189.  
  190.         d = dd;
  191.         INT16WRITE(d,temp);
  192.  
  193.         ss += sdel;
  194.         dd += ddel;
  195.     }
  196.  
  197.     return(1);
  198.  
  199. } /* inttoIEEE */
  200.  
  201. /* -------------------------------------------------------------- */
  202. /* src are IEEE , dst are on this machine */
  203.  
  204. int intfromIEEE (src,dst,sdelta,ddelta,n)            /*@@*/
  205.  
  206. unsigned char *src,*dst;
  207. int     n,sdelta,ddelta;
  208. {
  209.     register unsigned char *s, *ss, *d, *dd;
  210.     register unsigned char *t;
  211.     int                    temp,i,j,sdel,ddel;
  212.  
  213.     sdel = sdelta;
  214.     ddel = ddelta;
  215.     ss = src;
  216.     dd = dst;
  217.     if(vjv){
  218.         sprintf(sjs,"#in intfromIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  219.         zj;
  220.     }
  221.  
  222.     for(i=0;i<n;i++) {
  223.         s = ss;
  224.         INT16READ(s,temp);
  225.  
  226.         t = (unsigned char*) &temp;
  227.         d = dd;
  228.         for (j=0;j<sizeof(temp);j++) *d++ = *t++;
  229.  
  230.         ss += sdel;
  231.         dd += ddel;
  232.     }
  233.  
  234.     return(1);
  235.  
  236. } /* intfromIEEE */
  237.  
  238.  
  239. /* ============================================================== */
  240. /* ================= L O N G S ================================== */
  241. /* ============================================================== */
  242.  
  243. /* src are on this machine , dst are IEEE */
  244.  
  245. int longtoIEEE (src,dst,sdelta,ddelta,n)            /*@@*/
  246.  
  247. unsigned char *src, *dst;
  248. int      n, sdelta, ddelta;
  249. {
  250.     int temp,i,j,sdel,ddel;
  251.     register unsigned char *s, *ss, *d, *dd;
  252.     register unsigned char *t;
  253.  
  254.     sdel = sdelta;
  255.     ddel = ddelta;
  256.     ss = src;
  257.     dd = dst;
  258.  
  259.     if(vjv){
  260.         sprintf(sjs,"#in longtoIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  261.         zj;
  262.     }
  263.     printf("#in longtoIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  264.  
  265.     for (i=0;i<n;i++) {
  266.         t = (unsigned char*) &temp;
  267.         s = ss;
  268.         for(j=0;j<sizeof(temp);j++) *t++ = *s++;
  269.  
  270.         d = dd;
  271.         INT32WRITE(d,temp);
  272.  
  273.         ss += sdel;
  274.         dd += ddel;
  275.     }
  276.  
  277.     return(1);
  278.  
  279. } /* longtoIEEE */
  280.  
  281. /* -------------------------------------------------------------- */
  282. /* src are IEEE , dst are on this machine */
  283.  
  284. int longfromIEEE (src,dst,sdelta,ddelta,n)            /*@@*/
  285.  
  286. unsigned char *src,*dst;
  287. int     n,sdelta,ddelta;
  288. {
  289.     register unsigned char *s, *ss, *d, *dd;
  290.     register unsigned char *t;
  291.     int                    temp,i,j,sdel,ddel;
  292.  
  293.     sdel = sdelta;
  294.     ddel = ddelta;
  295.     ss = src;
  296.     dd = dst;
  297.     if(vjv){
  298.         sprintf(sjs,"#in intfromIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  299.         zj;
  300.     }
  301.     printf("#in longfromIEEE sdel=%d, ddel=%d, n=%d\n", sdel,ddel,n);
  302.  
  303.     for(i=0;i<n;i++) {
  304.         s = ss;
  305.         INT32READ(s,temp);
  306.  
  307.         t = (unsigned char*) &temp;
  308.         d = dd;
  309.         for (j=0;j<sizeof(temp);j++) *d++ = *t++;
  310.  
  311.         ss += sdel;
  312.         dd += ddel;
  313.     }
  314.  
  315.     return(1);
  316.  
  317. } /* longfromIEEE */
  318.  
  319. /* ============================================================== */
  320. /* ==================== F L O A T S ============================= */
  321. /* ============================================================== */
  322.  
  323. /* 
  324.     floats are very machine specific. 
  325.     There will always be  a set of 2 routines (XXXtoIEEE and XXXfromIEEE)
  326.     for each machine that is special.
  327.    So far, 2 sets are written specifically for the Cray and Vax.
  328.     A third set is written for all other supported machines. These 
  329.     machines use IEEE format (MAC, Sun, etc).
  330.     One set, written for IEEE machines, is used by all other machines 
  331.     (assumed to be IEEE) 
  332.     
  333. */
  334.  
  335. #ifdef CRAY
  336.  
  337. /* ------------------ C R A Y ------------------------------------------ */
  338.  
  339. #define MINEXP    0x3f81000000000000  /* min valid Cray masked exponent */
  340. #define MAXEXP    0x407e000000000000  /* max valid Cray masked exponent */
  341.  
  342. #define C_FMASK   0x00007fffff000000  /* Cray fraction mask (1st 23 bits)*/
  343. #define C_EMASK   0x7fff000000000000  /* Cray exponent mask */
  344. #define C_SMASK   0x8000000000000000  /* Cray sign mask */
  345. #define C_IMPLICIT 0x0000800000000000 /* Cray implicit bit */
  346.  
  347. #define I_FMASK   0x007fffff          /* IEEE fraction mask */
  348. #define I_EMASK   0x7f800000          /* IEEE exponent mask */
  349. #define I_SMASK   0x80000000          /* IEEE sign mask     */
  350.  
  351. #define IEEE_BIAS 0177
  352. #define CRAY_BIAS 040000
  353.  
  354.  
  355. /*
  356. convert from Cray2 floating point format to IEEE format
  357. */
  358.  
  359. int crayFtoIEEE (crayfp, ieeefp, cstep, istep, n)        /*@@*/
  360.  
  361. unsigned char *crayfp, *ieeefp;
  362. int cstep, istep, n;
  363. {
  364.     long tmp, C2I_diff;
  365.     long craylong;
  366.     register int i,j,c;
  367.  
  368.     if(vjv) {
  369.         sprintf(sjs,"#in crayFtoIEEE cstep=%d istep=%d n=%d\n",cstep,istep,n);
  370.         zj;
  371.     }
  372.  
  373.     c=0; 
  374.     i=0;
  375.     for (j=0;j<n;j++) {
  376.         movebytes ((unsigned char*) &crayfp[c],(unsigned char*) &craylong,sizeof(long));
  377.         /* ============================== */
  378.         if (craylong == 0)  {
  379.             tmp = 0;
  380.         }
  381.         else {
  382.             tmp = (C_EMASK & craylong);
  383.             if (tmp < MINEXP || tmp > MAXEXP)  return(-1);
  384.             C2I_diff = (IEEE_BIAS - CRAY_BIAS - 1) << 48;
  385.             tmp = (( tmp + C2I_diff ) << 7)
  386.                 | ( (craylong  & C_FMASK) << 8 )
  387.                 | ( (craylong  & C_SMASK));
  388.         }
  389.         /* ============================== */
  390.         movebytes(unsigned &tmp, unsigned &ieeefp[i], 4);
  391.         c += cstep; 
  392.         i += istep;
  393.     }
  394.     return(0);
  395.  
  396. } /* crayFtoIEEE */
  397.  
  398. /* -------------------------------------------------------------- */
  399.  
  400. /*
  401. Conversion from IEEE floating point format to Cray format 
  402. */
  403.  
  404. int crayFfromIEEE (ieeefp, crayfp, istep, cstep, n)        /*@@*/
  405.  
  406. unsigned char *crayfp, *ieeefp;
  407. int cstep, istep, n;
  408. {
  409.  
  410.     register int c,i,j;
  411.     long tmp;
  412.     long I2C_diff;
  413.     long craylong;
  414.  
  415.     if(vjv) {
  416.         sprintf(sjs,"#in crayFfromIEEE cstep=%d, istep=%d, n=%d\n", 
  417.             cstep,istep,n);
  418.         zj;
  419.     }
  420.  
  421.     c=0; 
  422.     i=0;
  423.     for (j=0;j<n;j++) {
  424.         tmp = 0;
  425.         movebytes (unsigned char*) &ieeefp[i],((unsigned char *) &tmp)+4, 4); /* right 4 bytes of tmp */
  426.  
  427.         /* ================================== */
  428.         craylong  = (tmp & I_EMASK);
  429.         if (craylong != 0) {
  430.             I2C_diff   = (CRAY_BIAS - IEEE_BIAS + 1) << 23;
  431.             craylong  += I2C_diff;
  432.             craylong   = (craylong<< 25)
  433.                 | ( (tmp & I_FMASK) << 24)
  434.                 | ( (tmp & I_SMASK) << 32)
  435.                 | C_IMPLICIT;
  436.         }
  437.         /* ================================== */
  438.  
  439.         movebytes ((unsigned char*) &craylong,(unsigned char*) &crayfp[c],sizeof(long));
  440.         c += cstep;
  441.         i += istep;
  442.     }
  443.     return (0);
  444. } /* crayFfromIEEE */
  445. #endif
  446.  
  447.  
  448. #ifdef VMS
  449. /* ------------------ V A X --------------------------------------------- */
  450.  
  451. /*
  452. Conversion from VAx format IEEE floating point format.
  453. */
  454.  
  455. int vaxFtoIEEE (vaxfp, ieeefp, vstep, istep, n)        /*@@*/
  456.  
  457. unsigned char *vaxfp, *ieeefp;
  458. int vstep, istep, n;
  459. {
  460.     { sprintf(sjs,"@%c vaxFtoIEEE unimplemeted yet\n",7);
  461.     zj; 
  462. }
  463.  
  464. } /* vaxFtoIEEE */
  465.  
  466. /*
  467. Conversion from IEEE floating point format to Vax format.
  468. */
  469.  
  470. int
  471. vaxFfromIEEE (ieeefp, vaxfp, istep, vstep, n)        /*@@*/
  472.  
  473. unsigned char *vaxfp, *ieeefp;
  474. int vstep, istep, n;
  475. {
  476.     { sprintf(sjs,"@%c vaxFfromIEEE unimplemeted yet\n",7);
  477.     zj; 
  478. }
  479.  
  480. } /* vaxFfromIEEE */
  481. #endif
  482.  
  483.  
  484. /* -------------------------------------------------------------- */
  485. /* ----------- A L L   O T H E R    M A C H I N E S ------------- */
  486. /* -------------------------------------------------------------- */
  487.  
  488. int floattoIEEE (machfp, ieeefp, mstep, istep, n)        /*@@*/
  489.  
  490. unsigned char *machfp, *ieeefp;
  491. int mstep, istep, n;
  492. {
  493.     int ret;
  494.     if(vjv)  {
  495.         sprintf(sjs,"#in floattoIEEE: which invokes bytetoIEEE\n");
  496.         zj;
  497.     }
  498.     ret = bytetoIEEE(machfp, ieeefp, mstep, istep, n);
  499.  
  500.     return(ret);
  501.  
  502. } /* floattoIEEE */
  503.  
  504.  
  505. int floatfromIEEE (ieeefp, machfp, istep, mstep, n)        /*@@*/
  506.  
  507. unsigned char *machfp, *ieeefp;
  508. int mstep, istep, n;
  509. {
  510.     int ret;
  511.     if(vjv)  {
  512.         sprintf(sjs,"#in floatfromIEEE: which invokes bytefromIEEE\n");
  513.         zj;
  514.     }
  515.     ret = bytefromIEEE(ieeefp, machfp, istep, mstep, n);
  516.     return(ret);
  517. } /* floatfromIEEE */
  518.  
  519. /* -------------------------------------------------------------- */
  520.  
  521. /* move n bytes of from ss to dd */
  522. int movebytes (ss,dd,n)        /*@@*/
  523.  
  524. unsigned char *ss, *dd;
  525. int n;
  526. {
  527.     register unsigned char *d,*s;
  528.     register int i;
  529.     for (d=dd,s=ss,i=0;i<n;i++) *d++ = *s++;
  530.  
  531.     return(1);
  532.  
  533. } /* movebytes */
  534. /* -------------------------------------------------------------- */
  535.  
  536.  
  537.  
  538. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  539. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  540. /*                                                                    */ 
  541. /* routines for converting from vsets in v1.0 to v2.x                 */
  542. /*                                                                    */ 
  543. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  544. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  545.  
  546. #define INT16SIZE 2
  547. #define INT32SIZE 4
  548.  
  549. /* ------------------------------------------------------------------ */
  550.  
  551. /*
  552. *  this routine checks that the given OPENED file is compatible with
  553. *    version 2.0 or later of the HDF Vset library .
  554. *  returns 1 if file already compatible with r2.
  555. *          0 if not compatible.
  556. *          -1 if error.
  557. */
  558.  
  559. int vicheckcompat(f) DF * f; {
  560.  
  561.     DFdesc    desc;
  562.     int         foundold, foundnew;
  563.  
  564.     foundold = 0;
  565.     foundnew = 0;
  566.  
  567.     /* locate any OLD vgs */
  568.         DFsetfind(f, OLD_VGDESCTAG, DFTAG_WILDCARD);
  569.         if ( DFfind(f, &desc)  == 0) foundold++; 
  570.                 
  571.     /* locate any OLD vdatas */
  572.         DFsetfind(f, OLD_VSDESCTAG, DFTAG_WILDCARD);
  573.         if ( DFfind(f, &desc)  == 0) foundold++; 
  574.                 
  575.     /* locate any NEW vgs */
  576.         DFsetfind(f, NEW_VGDESCTAG, DFTAG_WILDCARD);
  577.         if ( DFfind(f, &desc)  == 0) foundnew++; 
  578.                 
  579.     /* locate any NEW vdatas */
  580.         DFsetfind(f, NEW_VSDESCTAG, DFTAG_WILDCARD);
  581.         if ( DFfind(f, &desc)  == 0) foundnew++; 
  582.  
  583.     if ( foundold == 0 ) /* has no old vset elements */
  584.         return (1); /* just assume compatible */
  585.  
  586.     if ( foundnew > 0 ) 
  587.         return (1); /* file is already compatible */
  588.     else
  589.         return (0); /* file is not compatible */
  590. } /* vicheckcompat */
  591.  
  592. /* ------------------------------------------------------------------ */
  593. /*
  594. * This routine will modify a given OPENED file so that is becomes compatible
  595. * with version 2.0 or later of the HDF Vset library.
  596. * Note that the file is assumed to be not compatible to begin with.
  597. * This routine will not check to see if the file is already compatible,
  598. * but it is harmless to run an already-compatible file through again.
  599. *
  600. * However, be aware that each time, the file gets larger.
  601. * Also, file must be opened with DFACC_ALL access.
  602. *
  603. * returns  1 if successful. if error, returns 0
  604. */
  605.  
  606.  
  607. int vimakecompat(f)  DF *f; {
  608.  
  609.     VGROUP     tempvgroup;
  610.     VDATA        tempvdata;
  611.  
  612.     VGROUP    * vg = &tempvgroup;
  613.     VDATA        *vs = &tempvdata;
  614.     unsigned char buf[5000];
  615.     int         i, dum, bsize;
  616.     DFdesc    desc;
  617.  
  618.     /* =============================================  */
  619.     /* --- read all vgs and convert each --- */
  620.  
  621.     dum = 0;
  622.     DFsetfind (f, OLD_VGDESCTAG, DFTAG_WILDCARD);
  623.     while ( DFfind(f, &desc) == 0) {
  624.         if ( -1 == (bsize = DFgetelement (f, OLD_VGDESCTAG, desc.ref, buf)) ) {
  625.              fprintf(stderr,"getvgroup_old. getelement err. DFerror=%d\n",DFerror);
  626.             exit(0);
  627.             }
  628.  
  629.         oldunpackvg (vg, buf, &bsize);
  630.         /* add new items */
  631.             vg->vgclass[0] = '\0';
  632.             vg->extag = 0;
  633.             vg->exref = 0;
  634.             vg->version = 2; /* version 2 */
  635.             vg->more = 0;
  636.         /* inside each vgroup, change the old tags to new */
  637.             for(i=0;i<vg->nvelt;i++)
  638.                 if (vg->tag[i] == OLD_VGDESCTAG) vg->tag[i] = NEW_VGDESCTAG;
  639.                 else if (vg->tag[i] == OLD_VSDESCTAG) vg->tag[i] = NEW_VSDESCTAG;
  640.                 else { fprintf( stderr,"vimakecompat: unknown tag %d] in vgroup!\n",
  641.                                 vg->tag[i]);
  642.                         }
  643.         vpackvg (vg, buf, &bsize);
  644.  
  645.         if ( -1 == DFputelement (f, VGDESCTAG, desc.ref, buf, bsize)) {
  646.           fprintf(stderr,"put vgroup desc error. DFerror=%d\n",DFerror);
  647.             exit(0);
  648.             }    
  649.  
  650.         dum++;
  651.         }
  652.  
  653.     /* =============================================  */
  654.     /* --- read all vdata descs  and convert each --- */
  655.     /* --- then dup a tag for each vdata data elt --- */
  656.  
  657.     dum = 0;
  658.     DFsetfind (f, OLD_VSDESCTAG, DFTAG_WILDCARD);
  659.     while ( DFfind(f, &desc) == 0) {
  660.         if ( -1 == (bsize = DFgetelement (f, OLD_VSDESCTAG, desc.ref, buf)) ) {
  661.              fprintf(stderr,"getvdata_old. getelement err. DFerror=%d\n",DFerror);
  662.             exit(0);
  663.             }
  664.  
  665.         oldunpackvs (vs, buf, &bsize);
  666.         /* add new items */
  667.             vs->vsclass[0] = '\0';
  668.             vs->extag = 0;
  669.             vs->exref = 0;
  670.             vs->version = 2; /* version 2 */
  671.             vs->more = 0;
  672.         vpackvs (vs, buf, &bsize);
  673.  
  674.         if ( -1 == DFputelement (f, VSDESCTAG, desc.ref, buf, bsize)) {
  675.           fprintf(stderr,"put vdata desc error. DFerror=%d\n",DFerror);
  676.             exit(0);
  677.             }    
  678.  
  679.         /* duplicate a tag to point to vdata vdata */
  680.  
  681.             if ( DFdup(f, NEW_VSDATATAG, desc.ref, OLD_VSDATATAG, desc.ref) < 0) {
  682.                 fprintf(stderr,"DFdup - cannot duplicate. DFerror=%d\n",DFerror);
  683.                 exit(0);
  684.                 }
  685.  
  686.         dum++;
  687.         }
  688.  
  689.     return(1);
  690.  
  691. } /* vimakecompat */
  692.  
  693.  
  694. /* ================================================================== */
  695. /*
  696. *  this routine checks that the given file is compatible with
  697. *    version 2.0 or later of the HDF Vset library .
  698. *
  699. *  All it does is to open the file, call vicheckcompat to do all the
  700. *  checking, and then closes it.
  701. *    See comments for vicheckcompat().
  702.  
  703. *  returns 1 if file already compatible with r2.
  704. *          0 if not compatible.
  705. *          -1 if error.
  706. */
  707.  
  708. int vcheckcompat(fs) char * fs; {
  709.  
  710.     DF            * f;
  711.     int         stat;
  712.  
  713.    if (NULL==(f=DFopen(fs,DFACC_READ,0))) {
  714.         fprintf(stderr,"vcheckcompat: cannot open %s\n",fs);
  715.         return(-1);
  716.         }         
  717.     stat = vicheckcompat(f); 
  718.     DFclose (f);    
  719.  
  720.     return (stat);
  721. } /* vcheckcompat */
  722.  
  723. /* ================================================================== */
  724. /*
  725. * This routine will modify a given file so that is becomes compatible
  726. * with version 2.0 or later of the HDF Vset library.
  727. *
  728. * All this routine does is to open the file, call vimakecompat to
  729. * do all the conversion, and then to close the file.
  730. * See comments for vimakecompat().
  731. *
  732. * returns  1 if successful. if error, returns 0
  733. */
  734.  
  735. int vmakecompat(fs) char * fs; {
  736.     DF * f;
  737.     int stat;
  738.  
  739.    if (NULL==(f=DFopen(fs,DFACC_ALL,0))) {
  740.         fprintf(stderr,"vmakecompat: cannot open %s\n",fs);
  741.         return(0);
  742.         }         
  743.     stat = vimakecompat(f);
  744.     DFclose(f);
  745.  
  746. } /* vmakecompat */
  747.  
  748. /* ==================================================================== */
  749.  
  750. oldunpackvg (vg,buf,size)          /*@@*/
  751.  
  752. VGROUP*              vg;        /* vgroup to be loaded with file data */
  753. unsigned char     buf[];     /* must contain a VGDESCTAG data object from file */
  754.  
  755. int*              size;      /* ignored, but included to look like packvg() */
  756.  
  757. {
  758.  
  759.     unsigned char    *b, *bb;
  760.     int                 i;
  761.  
  762.     i = *size; /* dummy, so that compiler thinks it is used  */
  763.  
  764.     bb = &buf[0];
  765.  
  766.     /* retrieve nvelt */
  767.     b = bb;
  768.     INT16READ(b,vg->nvelt);
  769.     bb+=INT16SIZE;
  770.  
  771.     /* retrieve the tags */
  772.     for (i=0;i<vg->nvelt;i++) {
  773.         b= bb;
  774.         INT16READ(b,vg->tag[i]);
  775.         bb +=INT16SIZE;
  776.     }
  777.  
  778.     /* retrieve the refs */
  779.     for (i=0;i<vg->nvelt;i++) {
  780.         b= bb;
  781.         INT16READ(b,vg->ref[i]);
  782.         bb +=INT16SIZE;
  783.     }
  784.  
  785.     /* retrieve vgname */
  786.     strcpy(vg->vgname, (char*) bb);
  787.     bb += ( strlen(vg->vgname)+1 );
  788.  
  789.     if (vjv) {
  790.         sprintf(sjs,"unpackvg: vgname is [%s]\n",vg->vgname);
  791.         zj;
  792.     }
  793.  
  794. } /* unpackvg */
  795.  
  796. /* ================================================================= */
  797.  
  798.  
  799. oldunpackvs (vs,buf,size)       /*@@*/
  800.  
  801. VDATA *vs;
  802. int   *size;            /* UNUSED, but retained for compatibility with packvs */
  803. unsigned char buf[];
  804. {
  805.     unsigned char *b, *bb;
  806.     int            i;
  807.  
  808.     i = *size; /* dum */
  809.  
  810.     bb = &buf[0];
  811.  
  812.     b = bb;
  813.     INT16READ(b,vs->interlace);
  814.     bb += INT16SIZE;
  815.  
  816.     b = bb;
  817.     INT32READ(b,vs->nvertices);
  818.     bb += INT32SIZE;
  819.  
  820.     b = bb;
  821.     INT16READ(b,vs->wlist.ivsize);
  822.     bb += INT16SIZE;
  823.  
  824.     b = bb;
  825.     INT16READ(b,vs->wlist.n);
  826.     bb += INT16SIZE;
  827.  
  828.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the type */
  829.         b = bb;
  830.         INT16READ(b,vs->wlist.type[i]);
  831.         bb += INT16SIZE;
  832.     }
  833.  
  834.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the isize */
  835.         b = bb;
  836.         INT16READ(b,vs->wlist.isize[i]);
  837.         bb += INT16SIZE;
  838.     }
  839.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the off */
  840.         b = bb;
  841.         INT16READ(b,vs->wlist.off[i]);
  842.         bb += INT16SIZE;
  843.     }
  844.     for (i=0;i<vs->wlist.n;i++)  { /* retrieve the order */
  845.         b = bb;
  846.         INT16READ(b,vs->wlist.order[i]);
  847.         bb += INT16SIZE;
  848.     }
  849.     for (i=0;i<vs->wlist.n;i++) {
  850.         strcpy(vs->wlist.name[i],  (char*) bb);
  851.         bb += ( strlen(vs->wlist.name[i]) + 1 );
  852.     }
  853.  
  854.     strcpy(vs->vsname, (char*) bb);
  855.     bb += ( strlen(vs->vsname) + 1);
  856.  
  857.     /* **EXTRA**  fill in the machine-dependent size fields */
  858.     for (i=0;i<vs->wlist.n;i++) {
  859.         vs->wlist.esize[i] = vs->wlist.order[i] * SIZEOF(vs->wlist.type[i]);
  860.     }
  861.  
  862. } /* unpackvs */
  863.  
  864. /* ------------------------------------------------------------------ */
  865.