📄 readwrite.pas
字号:
{
@abstract(EBK&NVS Library for Turbo Pascal: I/O routines for Test LinAlg)
@author(Nikolai V. Shokhirev <nikolai@shokhirev.com> <nikolai@u.arizona.edu>)
@created(09.09.2002)
@lastmod(10.10.2002)
㎞ikolai V. Shokhirev, 2002
}
unit ReadWrite;
interface
uses
MathTypes, classes;
procedure ReadMatrix(const m: matrix; n1, n2: intType; const FileName: string);
procedure WriteMatrix(const m: matrix; n1, n2: intType; const FileName: string);
procedure ReadVector(var v: vector; n: intType; const FileName: string);
procedure WriteVector(const v: vector; n: intType; const FileName: string);
procedure ReadTVector(var v: vector; n: intType; const FileName: string);
procedure WriteTVector(const v: vector; n: intType; const FileName: string);
procedure MatrixToHTML(const m: matrix; n1, n2: intType;
const SL: TStringList; const S: String);
procedure VectorToHTML(const v: vector; n: intType; const SL: TStringList;
const S: String);
procedure TVectorToHTML(const v: vector; n: intType; const SL: TStringList;
const S: String);
implementation
uses
Sysutils;
procedure ReadMatrix(const m: matrix; n1, n2: intType; const FileName: string);
var
i, j: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
reset(tf);
for i := 1 to n1 do
begin
for j := 1 to n2 do
begin
read(tf,x);
m[i]^[j] := x;
end;
readln(tf);
end;
finally
closeFile(tf);
end;
end;
procedure WriteMatrix(const m: matrix; n1, n2: intType; const FileName: string);
var
r, c: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
rewrite(tf);
for r := 1 to n1 do
begin
for c := 1 to n2 do
begin
x := m[r]^[c];
Write(tf,' ',x);
end;
Writeln(tf);
end;
finally
closeFile(tf);
end;
end;
procedure ReadVector(var v: vector; n: intType; const FileName: string);
var
i: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
reset(tf);
for i := 1 to n do
begin
readln(tf,x);
v[i] := x;
end;
finally
closeFile(tf);
end;
end;
procedure ReadTVector(var v: vector; n: intType; const FileName: string);
var
i: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
reset(tf);
for i := 1 to n do
begin
read(tf,x);
v[i] := x;
end;
finally
closeFile(tf);
end;
end;
procedure WriteVector(const v: vector; n: intType; const FileName: string);
var
i: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
rewrite(tf);
for i := 1 to n do
begin
x := v[i];
WriteLn(tf,x);
end;
finally
closeFile(tf);
end;
end;
procedure WriteTVector(const v: vector; n: intType; const FileName: string);
var
i: IntType;
tf: TextFile;
x: RealType;
begin
try
AssignFile(tf,FileName);
rewrite(tf);
for i := 1 to n do
begin
x := v[i];
Write(tf,x);
end;
WriteLn(tf);
finally
closeFile(tf);
end;
end;
procedure MatrixToHTML(const m: matrix; n1, n2: intType; const SL: TStringList;
const S: String);
var
r, c: IntType;
x: RealType;
begin
SL.Add(S);
SL.Add('<table border="1">');
for r := 1 to n1 do
begin
SL.Add('<tr>');
for c := 1 to n2 do
begin
x := m[r]^[c];
SL.Add('<td>'+FloatToStr(x)+'</td>');
end;
SL.Add('</tr>');
end;
SL.Add('</table><br>');
end;
procedure VectorToHTML(const v: vector; n: intType; const SL: TStringList;
const S: String);
var
i: IntType;
x: RealType;
begin
SL.Add(S);
SL.Add('<table border="1">');
for i := 1 to n do
begin
x := v[i];
SL.Add('<tr><td>'+FloatToStr(x)+'</td></tr>');
end;
SL.Add('</table><br>');
end;
procedure TVectorToHTML(const v: vector; n: intType; const SL: TStringList;
const S: String);
var
i: IntType;
x: RealType;
begin
SL.Add(S);
SL.Add('<table border="1"><tr>');
for i := 1 to n do
begin
x := v[i];
SL.Add('<td>'+FloatToStr(x)+'</td>');
end;
SL.Add('</tr></table><br>');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -