home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / mesch12a.zip / iotort.c < prev    next >
C/C++ Source or Header  |  1994-01-14  |  4KB  |  142 lines

  1.  
  2. /**************************************************************************
  3. **
  4. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5. **
  6. **                 Meschach Library
  7. ** 
  8. ** This Meschach Library is provided "as is" without any express 
  9. ** or implied warranty of any kind with respect to this software. 
  10. ** In particular the authors shall not be liable for any direct, 
  11. ** indirect, special, incidental or consequential damages arising 
  12. ** in any way from use of the software.
  13. ** 
  14. ** Everyone is granted permission to copy, modify and redistribute this
  15. ** Meschach Library, provided:
  16. **  1.  All copies contain this copyright notice.
  17. **  2.  All modified copies shall carry a notice stating who
  18. **      made the last modification and the date of such modification.
  19. **  3.  No charge is made for this software or works derived from it.  
  20. **      This clause shall not be construed as constraining other software
  21. **      distributed on the same medium as this software, nor is a
  22. **      distribution fee considered a charge.
  23. **
  24. ***************************************************************************/
  25.  
  26. /* iotort.c  10/11/93 */
  27. /* test of I/O functions */
  28.  
  29.  
  30. static char rcsid[] = "$Id: $";
  31.  
  32. #include "sparse.h"
  33. #include "zmatrix.h"
  34.  
  35.  
  36. #define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  37. #define notice(mesg)    printf("# Testing %s...\n",mesg);
  38.  
  39.  
  40. void main()
  41. {
  42.    VEC *x;
  43.    MAT *A;
  44.    PERM *pivot;
  45.    IVEC *ix;
  46.    SPMAT *spA;
  47.    ZVEC *zx;
  48.    ZMAT *ZA;
  49.    char yes;
  50.    int i;
  51.    FILE *fp;
  52.  
  53.    mem_info_on(TRUE);
  54.  
  55.    if ((fp = fopen("iotort.dat","w")) == NULL) {
  56.       printf(" !!! Cannot open file %s for writing\n\n","iotort.dat");
  57.       exit(1);
  58.    }
  59.      
  60.    x = v_get(10);
  61.    A = m_get(3,3);
  62.    zx = zv_get(10);
  63.    ZA = zm_get(3,3);
  64.    pivot = px_get(10);
  65.    ix = iv_get(10);
  66.    spA = sp_get(3,3,2);
  67.  
  68.    v_rand(x);
  69.    m_rand(A);
  70.    zv_rand(zx);
  71.    zm_rand(ZA);
  72.    px_ident(pivot);
  73.    for (i=0; i < 10; i++)
  74.      ix->ive[i] = i+1;
  75.    for (i=0; i < spA->m; i++) {
  76.       sp_set_val(spA,i,i,1.0);
  77.       if (i > 0) sp_set_val(spA,i-1,i,-1.0);
  78.    }
  79.  
  80.    notice(" VEC output");
  81.    v_foutput(fp,x);
  82.    notice(" MAT output");
  83.    m_foutput(fp,A);
  84.    notice(" ZVEC output");
  85.    zv_foutput(fp,zx);
  86.    notice(" ZMAT output");
  87.    zm_foutput(fp,ZA);
  88.    notice(" PERM output");
  89.    px_foutput(fp,pivot);
  90.    notice(" IVEC output");
  91.    iv_foutput(fp,ix);
  92.    notice(" SPMAT output");
  93.    sp_foutput(fp,spA);
  94.    fprintf(fp,"Y");
  95.    fclose(fp);
  96.  
  97.    printf("\nENTER SOME VALUES:\n\n");
  98.  
  99.    if ((fp = fopen("iotort.dat","r")) == NULL) {
  100.       printf(" !!! Cannot open file %s for reading\n\n","iotort.dat");
  101.       exit(1);
  102.    }
  103.  
  104.    notice(" VEC input/output");
  105.    x = v_finput(fp,x);
  106.    v_output(x);
  107.  
  108.    notice(" MAT input/output");
  109.    A = m_finput(fp,A);
  110.    m_output(A);
  111.  
  112.    notice(" ZVEC input/output");
  113.    zx = zv_finput(fp,zx);
  114.    zv_output(zx);
  115.  
  116.    notice(" ZMAT input/output");
  117.    ZA = zm_finput(fp,ZA);
  118.    zm_output(ZA);
  119.  
  120.    notice(" PERM input/output");
  121.    pivot = px_finput(fp,pivot);
  122.    px_output(pivot);
  123.  
  124.    notice(" IVEC input/output");
  125.    ix = iv_finput(fp,ix);
  126.    iv_output(ix);
  127.  
  128.    notice(" SPMAT input/output");
  129.    SP_FREE(spA);
  130.    spA = sp_finput(fp);
  131.    sp_output(spA);
  132.  
  133.    notice(" general input");
  134.    finput(fp," finish the test?  ","%c",&yes);
  135.    if (yes == 'y' || yes == 'Y' )
  136.      printf(" YES\n");
  137.    else printf(" NO\n");
  138.    fclose(fp);
  139.  
  140.    mem_info();
  141. }
  142.