home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / tan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  8.5 KB  |  268 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.6 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/tan.c,v 1.6 1992/05/31 19:05:44 mfolk beta koziol $
  30.  
  31. $Log: tan.c,v $
  32.  * Revision 1.6  1992/05/31  19:05:44  mfolk
  33.  * Added int32 casts to line 127 for Convex.
  34.  *
  35.  * Revision 1.5  1992/05/29  19:19:08  mfolk
  36.  * Changed pal declaration from char to uint8 for Convex.
  37.  *
  38.  * Revision 1.4  1992/05/27  21:46:34  chouck
  39.  * Added a cast
  40.  *
  41.  * Revision 1.3  1992/03/23  16:38:33  mfolk
  42.  * fixed minor bug in reporting success/failure of a DFR8 routine.
  43.  *
  44.  * Revision 1.2  1992/02/28  15:22:47  mfolk
  45.  * *** empty log message ***
  46.  *
  47.  * Revision 1.1  1992/02/28  14:33:49  mfolk
  48.  * Initial revision
  49.  *
  50. */
  51. #include "hdf.h"
  52.  
  53. /***********************************************************
  54. *
  55. * Test program: Stores annotations in a file
  56. * Writes several SDSs and corresponding RISs to a file.
  57. * Writes labels and descriptions for all but the first three SDSs.
  58. * Writes labels and descriptions for all RISs.
  59. *
  60. *************************************************************/
  61.  
  62. #define TESTFILE "tdfan.hdf"
  63. #define RESULT(a) if (ret == FAIL) {                            \
  64.                       printf( "\t>>>%s FAILED: ret = %d<<<\n", a, ret); \
  65.                       number_failed++;                          \
  66.                   } else                                        \
  67.                       printf("%s SUCCESSFUL\n", (a)); 
  68.  
  69. int32 number_failed = 0;  /* global counter */
  70.  
  71. #define ISFIRST    (int)1
  72. #define NOTFIRST   (int)0
  73. #define MAXLEN_LAB     50
  74. #define MAXLEN_DESC  1000
  75. #define ROWS           10
  76. #define COLS           10
  77. #define REPS            2   /* number of data sets to write to file */
  78.  
  79. main()
  80. {
  81.     char labsds[MAXLEN_LAB], labris[MAXLEN_LAB],
  82.          descsds[MAXLEN_DESC], descris[MAXLEN_DESC];
  83.     uint8 pal[768];
  84.     uint8 *image, *newimage;
  85.     uint16 refnum;
  86.     int32 ret, rank;
  87.     int j, dimsizes[2];
  88.     float *data;
  89.  
  90. /* set up object labels and descriptions */
  91.  
  92.     strcpy(labsds, "Object label #1: sds");
  93.     strcpy(labris, "Object label #2: image");
  94.     strcpy(descsds,"Object Descr #1: 1  2  3  4  5  6  7  8  9 10 11 12 \n" );
  95.     strcat(descsds,"             13 14 15 16 17 18 19 20 **END SDS DESCR**\n");
  96.     strcpy(descris,"Object Descr #2: A B C D E F G H I J K L \n");
  97.     strcat(descris, "                M N O **END IMAGE DESCR **\n");
  98.  
  99. /***** generate float array and image *****/
  100.  
  101.     data = (float *) malloc(ROWS*COLS*sizeof(float));
  102.     image = (uint8 *) malloc(ROWS*COLS*sizeof(char));
  103.     newimage = (uint8 *) malloc(ROWS*COLS*sizeof(char));
  104.  
  105.     dimsizes[0]=ROWS; 
  106.     dimsizes[1]=COLS;
  107.  
  108.     gen2Dfloat(ROWS, COLS, data);
  109.     genimage(ROWS, COLS, data, image);
  110.  
  111.     ret = DFSDsetdims(2,dimsizes);
  112.     RESULT("DFSDsetdims");
  113.  
  114. /********  Write labels and descriptions *********/
  115.     printf("\n\n***  Writing labels and descriptions with SDS and RIS ***\n\n");
  116.     for (j=0; j<REPS; j++) {
  117.  
  118.         /* write out scientific data set */
  119.         ret = DFSDadddata(TESTFILE, (uint16)2,dimsizes, (void *)data);
  120.         RESULT("DFSDadddata");
  121.  
  122.         if ((j%3) != 0) {      /* write out annotations for 2 out of every 3 */
  123.             refnum = DFSDlastref();
  124.             ret = DFANputlabel(TESTFILE, DFTAG_SDG, refnum, labsds);
  125.             RESULT("DFANputlabel");
  126.             ret = DFANputdesc(TESTFILE, DFTAG_SDG, refnum, 
  127.                                                    descsds, strlen(descsds));
  128.             RESULT("DFANputdesc");
  129.         }
  130.  
  131.         ret = DFR8addimage(TESTFILE, (char *)image, COLS, ROWS, (int) NULL);
  132.         RESULT("DFR8addimage");
  133.         refnum = DFR8lastref();
  134.         ret = DFANputlabel(TESTFILE, DFTAG_RIG, refnum, labris);
  135.         RESULT("DFANputlabel");
  136.         ret = DFANputdesc(TESTFILE,DFTAG_RIG,refnum, descris, strlen(descris));
  137.         RESULT("DFANputdesc")
  138.     }
  139.  
  140.  
  141. /********  Read labels and descriptions *********/
  142.  
  143.     printf("\n\n*** Reading labels and descriptions for SDS and RIS ***\n\n");
  144.  
  145.     for (j=0; j<REPS; j++) {
  146.  
  147.         ret = DFSDgetdims(TESTFILE,&rank,dimsizes,3);
  148.         RESULT("DFSDgetdims")
  149.         refnum = DFSDlastref();
  150.  
  151.         if ((j%3) != 0)       /* read in annotations for 2 out of every 3 */
  152.             check_lab_desc(TESTFILE, DFTAG_SDG, refnum, labsds, descsds);
  153.  
  154.         ret = DFR8getimage(TESTFILE, newimage, (int32) COLS, (int32) ROWS, pal);
  155.         RESULT("DFR8getimage")
  156.         refnum = DFR8lastref();
  157.         check_lab_desc(TESTFILE, DFTAG_RIG, refnum, labris, descris);
  158.     }
  159.  
  160.     if ( number_failed == 0 )
  161.         printf("\n\n***** ALL TESTS SUCCESSFUL ***** \n\n");
  162.     else
  163.         printf("\n\n***** %d TESTS FAILED ***** \n\n", number_failed);
  164. }
  165.  
  166.  
  167. /****************************************************************
  168. **
  169. **  gen2Dfloat:  generate 2-D data array 
  170. **
  171. ****************************************************************/
  172.         int
  173. gen2Dfloat(height, width, data)
  174. int   height, width;
  175. float *data;
  176. {
  177.     int i, j;
  178.         float *pdata;
  179.  
  180.     /* store one value per row, increasing by one for each row */
  181.         pdata = data;
  182.     for (i=0; i< height; i++)
  183.        for (j=0; j< width; j++)
  184.            *pdata++ = (float) i+1;
  185.  
  186. }
  187.  
  188. /****************************************************************
  189. **
  190. **  genimage:  generate image from 2-D float array
  191. **
  192. ****************************************************************/
  193.         int
  194. genimage(height, width, data, image)
  195.     int   height, width;
  196.     float *data;
  197.     uint8 *image;
  198. {
  199.     int i, limit;
  200.     float *pdata, max, min, multiplier;
  201.     uint8  *pimage;
  202.  
  203.     limit = height*width;
  204.     pdata = data;
  205.     max = min = *pdata;
  206.     for (i=0; i<limit; i++, pdata++) {
  207.        max = (max > *pdata) ? max : *pdata;
  208.        min = (min < *pdata) ? min : *pdata;
  209.     }
  210.     /* store one value per row, increasing by one for each row */
  211.     pdata = data;
  212.     pimage = image;
  213.     multiplier = 255.0 /(max-min);
  214.     for (i=0; i< limit; i++)
  215.            *image++ = (uint8) ((*pdata++)-min)*multiplier; 
  216.  
  217. }
  218.  
  219.  
  220. /****************************************************************
  221. **
  222. **  check_lab_desc:  read and compare label and description
  223. **                   with expected ones
  224. **
  225. ****************************************************************/
  226.     int
  227. check_lab_desc(filename, tag, ref, label, desc)
  228.     char *filename, *label, *desc;
  229.     uint16 tag, ref;
  230. {
  231.     int inlablen, indesclen, ret; 
  232.     char inlabel[MAXLEN_LAB], *indesc;
  233.  
  234.     inlablen = ret = DFANgetlablen(TESTFILE, tag, ref);
  235.     RESULT("DFANgetlablen");
  236.     if (inlablen != strlen(label)) {
  237.         printf("\t>>>BAD LABEL LENGTH.\n\t       IS: %d\n\tSHOULD BE: %d<<<\n",
  238.                                                 inlablen, strlen(label) );
  239.         number_failed++;
  240.     }
  241.     ret = DFANgetlabel(TESTFILE, tag, ref, inlabel, MAXLEN_LAB);
  242.     RESULT("DFANgetlabel");
  243.     if (strcmp(inlabel, label)!=0) {
  244.         printf("\t>>>BAD LABEL. \n\t       IS: %s; \n\tSHOULD BE: %s<<<\n", 
  245.                                                             inlabel, label );
  246.         number_failed++;
  247.     }
  248.  
  249.     indesclen = ret = DFANgetdesclen(TESTFILE, tag, ref);
  250.     RESULT("DFANgetdesclen");
  251.     if (indesclen != strlen(desc)) {
  252.         printf("\t>>>BAD DESCRIPTION LENGTH. \n\t       IS: %d", indesclen);
  253.         printf("\n\tSHOULD BE: %d<<<\n", strlen(desc) );
  254.         number_failed++;
  255.     }
  256.     else {
  257.         indesc = (char *)malloc( indesclen+1);
  258.         ret = DFANgetdesc(TESTFILE, tag, ref, indesc, MAXLEN_DESC);
  259.         RESULT("DFANgetdesc");
  260.         indesc[indesclen] = '\0';
  261.         if (strcmp(indesc, desc)!=0) {
  262.             printf("\t>>>BAD DESCRIPTION.\n\t      IS: %s", indesc);
  263.             printf("\n\tSHOULD BE: %s<<<\n", desc);
  264.             number_failed++;
  265.         }
  266.     }
  267. }
  268.