ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
read_write_entire_textfile.m
Go to the documentation of this file.
1
%READ_WRITE_ENTIRE_TEXTFILE Read or write a whole text file to/from memory
2
%
3
% Read or write an entire text file to/from memory, without leaving the
4
% file open
if
an error occurs.
5
%
6
% Reading:
7
% fstrm =
read_write_entire_textfile
(fname)
8
% Writing:
9
%
read_write_entire_textfile
(fname, fstrm)
10
%
11
%IN:
12
% fname - Pathname of text file to be read in.
13
% fstrm - String to be written to the file, including carriage returns.
14
%
15
%OUT:
16
% fstrm - String read from the file. If an fstrm input is given the
17
% output is the same as that input.
18
19
function fstrm =
read_write_entire_textfile
(fname, fstrm)
20
modes = {
'rt'
,
'wt'
};
21
writing = nargin > 1;
22
fh = fopen(fname, modes{1+writing});
23
if
fh == -1
24
error(
'Unable to open file %s.'
, fname);
25
end
26
try
27
if
writing
28
fwrite(fh, fstrm,
'char*1'
);
29
else
30
fstrm = fread(fh,
'*char'
)
';
31
end
32
catch ex
33
fclose(fh);
34
rethrow(ex);
35
end
36
fclose(fh);
37
end
read_write_entire_textfile
function read_write_entire_textfile(in fname, in fstrm)
src
matlab
main
+pm
+vis
+figure
private
read_write_entire_textfile.m
Generated on Mon Dec 2 2024 10:04:18 for ParaMonte MATLAB 3.0.0 by
1.9.3