iotort.c 3.3 KB

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