home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / tsdstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  4.3 KB  |  152 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/test/RCS/tsdstr.c,v 1.3 1992/08/11 15:35:38 chouck beta koziol $
  30.  
  31. $Log: tsdstr.c,v $
  32.  * Revision 1.3  1992/08/11  15:35:38  chouck
  33.  * Changed adddata() to putdata()
  34.  *
  35.  * Revision 1.2  1992/07/13  20:18:13  mfolk
  36.  * Added header to explain what it does.
  37.  *
  38.  * Revision 1.1  1992/07/08  22:07:42  sxu
  39.  * Initial revision
  40.  *
  41. */
  42. /***************************************************************
  43. **
  44. ** This program tests correctness of writing and read datastrings
  45. ** and dimension strings.
  46. ** To avoid the '\0' inserted by HDstrncpy, compare the first 14
  47. ** characters of output and input strings in subroutine compare()
  48. **
  49. ****************************************************************/
  50.  
  51.  
  52. #include "hdf.h"
  53. #include "dfsd.h"
  54.  
  55. int number_failed = 0;
  56.  
  57. int main()
  58. {
  59.     int i, j, err;
  60.     int32 rank;
  61.     int32 dims[2];
  62.     float32 f32[10][10], tf32[10][10];
  63.     char *datalabel, *dataunit, *datafmt, *coordsys;
  64.     char in_datalabel[256], in_dataunit[256], in_datafmt[256],
  65. in_coordsys[256];
  66.  
  67.     char *dimlabels[2], *dimunits[2], *dimfmts[2];
  68.     char in_dimlabels[2][256], in_dimunits[2][256], in_dimfmts[2][256];
  69.  
  70.     rank = 2;
  71.     dims[0] = 10;
  72.     dims[1] = 10;
  73.     datalabel  = "Datalabel";
  74.     dataunit   = "Dataunit";
  75.     datafmt    = "Datafmt";
  76.     coordsys   = "coordsys";
  77.  
  78.     dimlabels[0]  = "c_dim1_label_a";
  79.     dimunits[0]   = "c_dim1_unit_a";
  80.     dimfmts[0]    = "c_dim1_fmt_a";
  81.  
  82.     dimlabels[1]  = "c_dim2_label_b";
  83.     dimunits[1]   = "c_dim2_unit_b";
  84.     dimfmts[1]    = "c_dim2_fmt_b";
  85.  
  86.  
  87.     printf("Creating arrays...\n");
  88.  
  89.     for (i=0; i<10; i++) {
  90.         for (j=0; j<10; j++) {
  91.             f32[i][j] = (i * 10) + j;   /* range: 0 ~ 4-billion */
  92.         }
  93.     }
  94.  
  95.     DFSDsetdims(rank, dims);
  96.  
  97.     /* individual files */
  98.     printf("Testing arrays in individual files...\n");
  99.  
  100.     err = DFSDsetNT(DFNT_NFLOAT32);
  101.     err = DFSDsetdims(rank, dims);
  102.  
  103.     err = DFSDsetdatastrs(datalabel, dataunit, datafmt,coordsys);
  104.     err = DFSDsetdimstrs(1, dimlabels[0], dimunits[0], dimfmts[0]);
  105.     err = DFSDsetdimstrs(2, dimlabels[1], dimunits[1], dimfmts[1]);
  106.  
  107.     err = DFSDputdata("sdstrings.hdf", rank, dims, f32);
  108.  
  109.     err = DFSDgetdata("sdstrings.hdf", rank, dims, tf32);
  110.  
  111.     err = DFSDgetdatastrs(in_datalabel, in_dataunit, in_datafmt,
  112. in_coordsys);
  113.     err = DFSDgetdimstrs(1, in_dimlabels[0], in_dimunits[0],
  114. in_dimfmts[0]);
  115.     err = DFSDgetdimstrs(2, in_dimlabels[1], in_dimunits[1],
  116. in_dimfmts[1]);
  117.  
  118.     compare(datalabel, in_datalabel);
  119.     compare(dataunit, in_dataunit);
  120.     compare(datafmt, in_datafmt);
  121.     compare(coordsys, in_coordsys);
  122.  
  123.     compare(dimlabels[0], in_dimlabels[0]);
  124.     compare(dimunits[0], in_dimunits[0]);
  125.     compare(dimfmts[0], in_dimfmts[0]);
  126.  
  127.     compare(dimlabels[1], in_dimlabels[1]);
  128.     compare(dimunits[1], in_dimunits[1]);
  129.     compare(dimfmts[1], in_dimfmts[1]);
  130.  
  131.     if (number_failed > 0 ) {
  132.         printf("\n\t>>> %d TESTS FAILED <<<\n\n", number_failed);
  133.     }
  134.     else
  135.         printf("\n\t>>> ALL TESTS PASSED <<<\n\n");
  136.  
  137. }
  138.  
  139. int compare(outstring, instring)
  140. char *outstring, *instring;
  141. {
  142.     if (0 == strcmp(outstring, instring))
  143.         printf("Test passed for %s\n", outstring);
  144.     else {
  145.         printf(">>> Test failed for %s\n", outstring);
  146.         printf("    Input string =  %s\n", instring);
  147.         number_failed++;
  148.     }
  149. }
  150.  
  151.  
  152.