iom.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {
  2. $Id$
  3. This file is part of the Numlib package.
  4. Copyright (c) 1986-2000 by
  5. Kees van Ginneken, Wil Kortsmit and Loek van Reij of the
  6. Computational centre of the Eindhoven University of Technology
  7. FPC port Code by Marco van de Voort ([email protected])
  8. documentation by Michael van Canneyt ([email protected])
  9. Basic In and output of matrix and vector types. Maybe too simple for
  10. your application, but still handy for logging and debugging.
  11. See the file COPYING.FPC, included in this distribution,
  12. for details about the copyright.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. **********************************************************************}
  17. unit iom;
  18. interface
  19. {$I direct.inc}
  20. uses typ;
  21. const
  22. npos : ArbInt = 78;
  23. {Read a n-dimensional vector v from textfile}
  24. procedure iomrev(var inp: text; var v: ArbFloat; n: ArbInt);
  25. {Read a m x n-dimensional matrix a from textfile}
  26. procedure iomrem(var inp: text; var a: ArbFloat; m, n, rwidth: ArbInt);
  27. {Write a n-dimensional vectorv v to textfile}
  28. procedure iomwrv(var out: text; var v: ArbFloat; n, form: ArbInt);
  29. {Write a m x n-dimensional matrix a to textfile}
  30. procedure iomwrm(var out: text; var a: ArbFloat; m, n, rwidth, form: ArbInt);
  31. implementation
  32. procedure iomrev(var inp: text; var v: ArbFloat; n: ArbInt);
  33. var pv : ^arfloat1;
  34. i : ArbInt;
  35. BEGIN
  36. pv:=@v; for i:=1 to n do read(inp, pv^[i])
  37. END {iomrev};
  38. procedure iomrem(var inp: text; var a: ArbFloat; m, n, rwidth: ArbInt);
  39. var pa : ^arfloat1;
  40. i, k : ArbInt;
  41. BEGIN
  42. pa:=@a; k:=1;
  43. for i:=1 to m do
  44. BEGIN
  45. iomrev(inp, pa^[k], n); Inc(k, rwidth)
  46. END
  47. END {iomrem};
  48. procedure iomwrv(var out: text; var v: ArbFloat; n, form: ArbInt);
  49. var pv : arfloat1 absolute v;
  50. i, i1 : ArbInt;
  51. BEGIN
  52. if form>maxform then form:=maxform else
  53. if form<minform then form:=minform;
  54. i1:=npos div (form+2);
  55. for i:=1 to n do
  56. if ((i mod i1)=0) or (i=n) then writeln(out, pv[i]:form)
  57. else write(out, pv[i]:form, '':2)
  58. END {iomwrv};
  59. procedure iomwrm(var out: text; var a: ArbFloat; m, n, rwidth, form: ArbInt);
  60. var pa : ^arfloat1;
  61. i, k, nb, i1, l, j, r, l1, kk : ArbInt;
  62. BEGIN
  63. if (n<1) or (m<1) then exit;
  64. pa:=@a;
  65. if form>maxform then form:=maxform else
  66. if form<minform then form:=minform;
  67. i1:=npos div (form+2); l1:=0;
  68. nb:=n div i1; r:=n mod i1;
  69. if r>0 then Inc(nb);
  70. for l:=1 to nb do
  71. BEGIN
  72. k:=l1+1; if (r>0) and (l=nb) then i1:=r;
  73. for i:=1 to m do
  74. BEGIN
  75. kk:=k;
  76. for j:=1 to i1-1 do
  77. BEGIN
  78. write(out, pa^[kk]:form, '':2); Inc(kk)
  79. END;
  80. writeln(out, pa^[kk]:form); Inc(k, rwidth)
  81. END;
  82. Inc(l1, i1); if l<nb then writeln(out)
  83. END;
  84. END {iomwrm};
  85. END.
  86. {
  87. $Log$
  88. Revision 1.1 2000-07-13 06:34:14 michael
  89. + Initial import
  90. Revision 1.2 2000/01/25 20:21:42 marco
  91. * small updates, crlf fix, and RTE 207 problem
  92. Revision 1.1 2000/01/24 22:08:58 marco
  93. * initial version
  94. }