home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / tstubsf.f < prev    next >
Encoding:
Text File  |  1992-10-29  |  12.6 KB  |  473 lines

  1. C***************************************************************************
  2. C
  3. C
  4. C                         NCSA HDF version 3.2r2
  5. C                            October 30, 1992
  6. C
  7. C NCSA HDF Version 3.2 source code and documentation are in the public
  8. C domain.  Specifically, we give to the public domain all rights for future
  9. C licensing of the source code, all resale rights, and all publishing rights.
  10. C
  11. C We ask, but do not require, that the following message be included in all
  12. C derived works:
  13. C
  14. C Portions developed at the National Center for Supercomputing Applications at
  15. C the University of Illinois at Urbana-Champaign, in collaboration with the
  16. C Information Technology Institute of Singapore.
  17. C
  18. C THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. C SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. C WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. C
  22. C***************************************************************************
  23.  
  24. C
  25. C $Header: /hdf/hdf/v3.2r2/test/RCS/tstubsf.f,v 1.6 1992/06/16 15:39:42 chouck beta koziol $
  26. C
  27. C $Log: tstubsf.f,v $
  28. c Revision 1.6  1992/06/16  15:39:42  chouck
  29. c HP is really picky about things not extending into column 72
  30. c
  31. c Revision 1.5  1992/06/02  16:04:38  dilg
  32. c Added more thorough test of dffind() and fixed error in expected return code
  33. c from dfput().
  34. c
  35. c Revision 1.4  1992/05/07  16:37:55  dilg
  36. c Fixed problem with "Hit <return> to continue"
  37. c Changed output file name from "o2" to "tstubsF.hdf"
  38. c
  39. c Revision 1.3  1992/04/29  17:00:06  dilg
  40. c Changed VAX FORTRAN initialization statements to standard FORTRAN 'data'
  41. c statements.
  42. c
  43. c Revision 1.2  1992/04/28  19:36:55  dilg
  44. c Some minor cosmetic changes.
  45. c
  46. c Revision 1.1  1992/03/26  21:51:22  dilg
  47. c Initial revision
  48. c
  49. C
  50.       program tstubsF
  51.  
  52.       character ar0*10
  53.       character ar1*9
  54.       character ar2*30
  55.       character ar3*8
  56.  
  57.       data ar0 /'Testing...'/
  58.       data ar1 /'...one...'/
  59.       data ar2 /'...two...'/
  60.       data ar3 /'...three'/
  61.  
  62.       character in*20
  63.  
  64.       integer nerrors
  65.       data nerrors /0/
  66.       integer dfile
  67.       integer dfinfo(16)
  68.       integer dlist(128)
  69.       integer a0size, a1size, a2size, a3size
  70.       integer ret, err, i, nd, dfenum, tag, ref, length
  71.  
  72.       integer t255
  73.       integer t127
  74.       integer r1
  75.       integer r3
  76.       integer r7
  77.  
  78.       data t255 /255/
  79.       data t127 /127/
  80.       data r1   /1/
  81.       data r3   /3/
  82.       data r7   /7/
  83.  
  84.       integer dfaccess, dfopen, dfclose, dfdesc, dfdup, dfdel, dfread,
  85.      +        dfwrite, dfupdate, dfget, dfput, dfsfind, dffind, 
  86.      +          dferrno, dfishdf, dfnewref, dfnumber, dfstat
  87.  
  88.       a0size = len(ar0)
  89.       a1size = len(ar1)
  90.       a2size = len(ar2)
  91.       a3size = len(ar3)
  92.  
  93.       print *, 'This program will test the DF emulation layer'
  94.       print *, 'of HDF 3.2 and beyond (FORTRAN version).  Many'
  95.       print *, 'routines will be tested individually.  Each test'
  96.       print *, 'will report its name and results.  If all goes'
  97.       print *, 'well, all of the results will begin with "Success".'
  98.       print *, 'If a test fails, the results line will begin with'
  99.       print *, '">>>Failure".  An error count is kept and printed'
  100.       print *, 'out at the end.'
  101.       print *, ' '
  102.       print *, 'Hit <return> to continue.'
  103.       read(5,100) in
  104.  100  format(a)
  105.       in(1:20) = '                    '
  106.  
  107.       print *, ' '
  108.       print *, 'Testing dferrno...'
  109.       ret = dferrno()
  110.       if (ret .ne. 0) then
  111.     print *, '>>>Failure:  Returned ', ret, ' rather than 0.'
  112.     nerrors = nerrors + 1
  113.       else
  114.     print *, 'Success!'
  115.       endif
  116.  
  117.       print *, ' '
  118.       print *, 'Testing dfishdf... (should fail)'
  119.       ret = dfishdf('tstubsF.hdf')
  120.       dfenum = dferrno()
  121.       if (ret .eq. -1) then
  122.         print *, 'Success:  dfishdf failed with DFerror = ', dfenum
  123.       else
  124.     print *, '>>>Failure:  Non-existent file looks like HDF file.'
  125.     print *, '   Maybe was a pre-existing file named "tstubsF.hdf"'
  126.     print *, '   DFerror = ', dfenum
  127.     nerrors = nerrors + 1
  128.       endif
  129.  
  130.       print *, ' '
  131.       print *, 'Testing dfopen... (new file)'
  132.       dfile = dfopen('tstubsF.hdf', 6, 0)
  133.       dfenum = dferrno()
  134.       if (dfile .eq. 0) then
  135.     print *, '>>>Failure:  Error ', dfenum, ' opening file.'
  136.     print *, '   Quiting.'
  137.     stop
  138.       else
  139.     print *, 'Success!'
  140.       endif
  141.  
  142.       print *, ' '
  143.       print *, 'Testing dfclose...'
  144.       ret = dfclose(dfile)
  145.       dfenum = dferrno()
  146.       if (ret .eq. -1) then
  147.     print *, '>>>Failure:  could not close file.'
  148.     print *, '   DFerror = ', dfenum
  149.     nerrors = nerrors + 1
  150.       else
  151.     print *, 'Success!'
  152.       endif
  153.  
  154.       print *, ' '
  155.       print *, 'Testing dfclose... (invalid file; should fail)'
  156.       ret = dfclose(dfile)
  157.       dfenum = dferrno()
  158.       if (ret .eq. -1) then
  159.     print *, 'Success: dfclose failed with DFerror = ', dfenum
  160.       else
  161.     print *, '>>>Failure:  Close allowed on unopened file.'
  162.     nerrors = nerrors + 1
  163.       endif
  164.  
  165.       print *, ' '
  166.       print *, 'Testing dfopen... (existing file)'
  167.       dfile = dfopen('tstubsF.hdf', 2, 0)
  168.       dfenum = dferrno()
  169.       if (dfile .eq. 0) then
  170.     print *, '>>>Failure:  Error ', dfenum, ' opening file.'
  171.     print *, '   Quiting.'
  172.     stop
  173.       else
  174.     print *, 'Success!'
  175.       endif
  176.  
  177.       print *, ' '
  178.       print *, 'Testing dfput...'
  179.       ret = dfput(dfile, t255, r1, ar0, a0size)
  180.       dfenum = dferrno()
  181.       if (ret .ne. a0size) then
  182.     print *, '>>>Failure:  DFerror = ', dfenum
  183.     nerrors = nerrors + 1
  184.       else
  185.     print *, 'Success!'
  186.       endif
  187.  
  188.       print *, ' '
  189.       print *, 'Testing dfget...'
  190.       ret = dfget(dfile, t255, r1, in)
  191.       dfenum = dferrno()
  192.       if (ret .ne. a0size) then
  193.     print *, '>>>Failure:  read ', ret, ' of ', a0size, ' bytes.'
  194.     print *, '   String read:  ', in
  195.     print *, '   DFerror = ', dfenum
  196.     nerrors = nerrors + 1
  197.       else
  198.     err = 0
  199.     do 10 i=1, a0size
  200.         if (in(i:i) .ne. ar0(i:i)) err = 1
  201.  10    continue
  202.     if (err .eq. 1) then
  203.       print *, '>>>Failure:  strings differ.'
  204.       print *, '   String written:  ', ar0
  205.       print *, '   String read:     ', in
  206.       nerrors = nerrors + 1
  207.     else
  208.       print *, 'Success:  string read is the same as written.'
  209.         endif
  210.       endif
  211.  
  212.       in(1:20) = '                    '
  213.  
  214.       print *, ' '
  215.       print *, 'Testing dfaccess (write)...'
  216.       ret = dfaccess(dfile, t255, r3, 'w')
  217.       dfenum = dferrno()
  218.       if (ret .eq. -1) then
  219.     print *, '>>>Failure:'
  220.     print *, '   DFerror = ', dfenum
  221.     nerrors = nerrors + 1
  222.       else
  223.     print *, 'Success!'
  224.       endif
  225.  
  226.       print *, ' '
  227.       print *, 'Testing dfread... (should fail)'
  228.       ret = dfread(dfile, in, 5)
  229.       dfenum = dferrno()
  230.       if (ret .eq. -1) then
  231.     print *, 'Success:  dfread failed with DFerror = ', dfenum
  232.       else
  233.     print *, '>>>Failure:  Read allowed on write element.'
  234.     nerrors = nerrors + 1
  235.       endif
  236.       in(1:20) = '                    '
  237.  
  238.       print *, ' '
  239.       print *, 'Testing dfwrite...'
  240.       ret = dfwrite(dfile, ar1, a1size)
  241.       dfenum = dferrno()
  242.       if (ret .ne. a1size) then
  243.     print *, '>>>Failure:  wrote ', ret, ' of ', a1size, ' bytes.'
  244.     print *, '   DFerror = ', dfenum
  245.     nerrors = nerrors + 1
  246.       else
  247.     print *, 'Success!'
  248.       endif
  249.  
  250.       print *, ' '
  251.       print *, 'Testing dfaccess (read)...'
  252.       ret = dfaccess(dfile, t255, r3, 'r')
  253.       dfenum = dferrno()
  254.       if (ret .eq. -1) then
  255.     print *, '>>>Failure:'
  256.     print *, '   DFerror = ', dfenum
  257.     nerrors = nerrors + 1
  258.       else
  259.     print *, 'Success!'
  260.       endif
  261.  
  262.       print *, ' '
  263.       print *, 'Testing dfwrite... (should fail)'
  264.       ret = dfwrite(dfile, in, 5)
  265.       dfenum = dferrno()
  266.       if (ret .eq. -1) then
  267.     print *, 'Success:  dfwrite failed with DFerror = ', dfenum
  268.       else
  269.     print *, '>>>Failure:  write allowed on read element.'
  270.     nerrors = nerrors + 1
  271.       endif
  272.  
  273.       print *, ' '
  274.       print *, 'Testing dfread...'
  275.       ret = dfread(dfile, in, a1size)
  276.       dfenum = dferrno()
  277.       if (ret .ne. a1size) then
  278.     print *, '>>>Failure:  read ', ret, ' of ', a1size, ' bytes.'
  279.     print *, '   String read:  ', in
  280.     print *, '   DFerror = ', dfenum
  281.     nerrors = nerrors + 1
  282.       else
  283.     err = 0
  284.     do 40 i=1, a1size
  285.       if (in(i:i) .ne. ar1(i:i)) err = 1
  286.  40    continue
  287.     if (err .eq. 1) then
  288.       print *, '>>>Failure:  strings differ.'
  289.       print *, '   String written:  ', ar1
  290.       print *, '   String read:     ', in
  291.       nerrors = nerrors + 1
  292.     else
  293.       print *, 'Success:  string read is the same as written.'
  294.         endif
  295.       endif
  296.       in(1:20) = '                    '
  297.  
  298.       print *, ' '
  299.       print *, 'Testing dfnumber...'
  300.       nd = dfnumber(dfile, t255)
  301.       dfenum = dferrno()
  302.       if (nd .ne. 2) then
  303.     print *, '>>>Failure:'
  304.     print *, '   Saw ', nd, ' occurrances of tag 255 not than 2.'
  305.     print *, '   DFerror = ', dfenum
  306.     nerrors = nerrors + 1
  307.       else
  308.     print *, 'Success!'
  309.       endif
  310.     
  311.       print *, ' '
  312.       print *, 'Testing dfdesc...'
  313.       ret = dfdesc(dfile, dlist, 0, 5)
  314.       dfenum = dferrno()
  315. C
  316. C  add one for version tag
  317. C
  318.       if (ret .ne. (nd + 1)) then
  319.     print *, '>>>Failure:  Returned ', ret, ' rather than ', nd+1
  320.     print *, '   DFerror = ', dfenum
  321.     nerrors = nerrors + 1
  322.       else
  323.     print *, 'Success!'
  324.       endif
  325.  
  326.       print *, ' '
  327.       print *, 'Testing dfupdate'
  328.       ret = dfupdate(dfile)
  329.       dfenum = dferrno()
  330.       if (ret .ne. 0) then
  331.     print *, '>>>Failure:'
  332.     print *, '   DFerror = ', dfenum
  333.     nerrors = nerrors + 1
  334.       else
  335.     print *, 'Success!'
  336.       endif
  337.  
  338.       print *, ' '
  339.       print *, 'Testing dfstat'
  340.       ret = dfstat(dfile, dfinfo)
  341.       dfenum = dferrno()
  342.       if (ret .ne. 0) then
  343.     print *, '>>>Failure:'
  344.     print *, '   DFerror = ', dfenum
  345.     nerrors = nerrors + 1
  346.       else
  347.     print *, 'Success!'
  348.       endif
  349.     
  350.       print *, ' '
  351.       print *, 'Testing dfnewref...'
  352.       ret = dfnewref(dfile)
  353.       dfenum = dferrno()
  354.       if (ret .ne. 4) then
  355.     print *, '>>>Failure:  Returned ref. ', ret, ' instead of 4'
  356.     print *, '   DFerror = ', dfenum
  357.     nerrors = nerrors + 1
  358.       else
  359.     print *, 'Success!'
  360.       endif
  361.  
  362.       print *, ' '
  363.       print *, 'Testing dfdup...'
  364.       ret = dfdup(dfile, 127, r7, t255, r3)
  365.       dfenum = dferrno()
  366.       if (ret .eq. -1) then
  367.     print *, '>>>Failure:'
  368.     print *, '   DFerror = ', dfenum
  369.     nerrors = nerrors + 1
  370.       else
  371.     ret = dfnumber(dfile, t127)
  372.       dfenum = dferrno()
  373.     if (ret .ne. 1) then
  374.       print *, '>>>Failure:  duplicated tag not found.'
  375.       print *, '   DFerror = ', dfenum
  376.       nerrors = nerrors + 1
  377.     else
  378.       print *, 'Success!'
  379.         endif
  380.       endif
  381.  
  382.       print *, ' '
  383.       print *, 'Testing dfdel...'
  384.       ret = dfdel(dfile, t127, r7)
  385.       dfenum = dferrno()
  386.       if (ret .eq. -1) then
  387.     print *, '>>>Failure:'
  388.     print *, '   DFerror = ', dfenum
  389.     nerrors = nerrors + 1
  390.       else
  391.     ret = dfnumber(dfile, t127)
  392.       dfenum = dferrno()
  393.     if (ret .ne. 0) then
  394.       print *, '>>>Failure:  found ', ret, ' deleted tags.'
  395.       print *, '   DFerror = ', dfenum
  396.       nerrors = nerrors + 1
  397.     else
  398.       print *, 'Success!'
  399.         endif
  400.       endif
  401.  
  402.       print *, ' '
  403.       print *, 'Testing dfsfind...'
  404.       ret = dfsfind(dfile, 254, 0)
  405.       dfenum = dferrno()
  406.       if (ret .eq. -1) then
  407.     print *, '>>>Failure:'
  408.     print *, '   DFerror = ', dfenum
  409.     nerrors = nerrors + 1
  410.       else
  411.     print *, 'Success!'
  412.       endif
  413.  
  414.       print *, ' '
  415.       print *, 'Testing dffind...'
  416.       ret = dfdup(dfile, 254, 4, 255, 3)
  417.       if (ret .ne. 0) then
  418.         print *, '>>>DFdup 1 failed.'
  419.       endif
  420.       ret = dfdup(dfile, 254, 5, 255, 3)
  421.       if (ret .ne. 0) then
  422.         print *, '>>>DFdup 2 failed.'
  423.       endif
  424.       ret = dfdup(dfile, 254, 6, 255, 3)
  425.       if (ret .ne. 0) then
  426.         print *, '>>>DFdup 3 failed.'
  427.       endif
  428.       do 200 i=4,6
  429.       ret = dffind(dfile, tag, ref, length)
  430.       dfenum = dferrno()
  431.       if (ret .eq. -1) then
  432.         print *, '>>>Failure:'
  433.         print *, '   DFerror = ', dfenum
  434.     nerrors = nerrors + 1
  435.       else
  436.     if ((tag .ne. 254) .or. (ref .ne. i) .or. 
  437.      +                                  (length .ne. a1size)) then
  438.       print *, '>>>Failure:  tag/ref found is not correct.'
  439.       print *, '   Looking for:'
  440.       print *, '      tag:      254'
  441.       print *, '      ref:    ', i
  442.       print *, '      length: ', a1size
  443.       print *, '   Found:'
  444.       print *, '      tag:    ', tag
  445.       print *, '      ref:    ', ref
  446.       print *, '      length: ', length
  447.       nerrors = nerrors + 1
  448.     else
  449.           print *, 'Success!'
  450.     endif
  451.       endif
  452.  200  continue
  453.  
  454.       ret = dfclose(dfile)
  455.       dfenum = dferrno()
  456.       if (ret .ne. 0) then
  457.     print *, '>>>Failure:  dfclose failed (probably from open aid)'
  458.         print *, '   DFerror = ', dfenum
  459.     nerrors = nerrors + 1
  460.       endif
  461.  
  462.  
  463.       print *, ' '
  464.       print *, ' '
  465.       print *, 'Test Summary:'
  466.       print *, '   ', nerrors, ' errors were encountered.'
  467.       if (nerrors .ne. 0) then
  468.     print *, '   Please check program output carefully.'
  469.       endif
  470.  
  471.       stop
  472.       end
  473.