iom.pas 2.9 KB

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