Make Matlab to read an US-ASCII file

4 views (last 30 days)
cyberdyne
cyberdyne on 20 Sep 2012
Hi,
I software that I use creates an US-ASCII log-text-file (but without extension) while it works.
Is there a way to read by Matlab that file in realtime (while the external software updates it) and then to load log-file and updates?
Thanks.
  6 Comments
cyberdyne
cyberdyne on 23 Sep 2012
@Jan: I don't expect you solve my problem. I have some difficulties to find a right way to do it (what is often called pseudo-code) I don't want help to write the code but help to setting up the problem itself. I am sorry if it seemed I am waiting for an algorithm from users for me.
@Walter: Windows 7 64-bit. It allows me to set the output format of text (always without extension) like ISO 8859-1 , US-ASCII, UTF8/16. What there is in the log should not be changed.
I check some MATLAB-functions like textscan, fileread, fscan, and so on. I thought to use:
indx = find(strcmp(Vstr, 'wordtocheck')==1); %where Vstr is a vector with all strings in the textfile
Vstr = textscan(fid, '%s', length(text));
this to get index of Vstr with that word, but, as I wrote above, I have not idea how to setup a while loop or some of that to create an "realtime-updater" algorithm.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Sep 2012
The US-ASCII vs ISO 8859-1 and so on, is not going to be an appreciable problem for you.
Your problem is your operating system. The output file is going to be locked by MS Windows during the time the process has it open for writing, and unless you can take special precautions you are not going to be able to open it for reading until after it is closed.
I have not been able to find out what has to be done to allow reading of files as they are being written. MS Windows' normal IO functions do not document the fact that the locking will be done, making it difficult for me to track down how the locking is happening or how to turn it off.
The sort of locking that MS Windows is doing is known as "mandatory file locking", and it is not supposed to happen in POSIX compatible operating systems (which MS Windows XP SP2 and later claim to be) until you get to Trusted security level B1 or higher, which MS Windows definitely is not. (I'm not sure what level it is; I have seen claims that it is D4 but it might possibly have climbed to C2.) As it is not supposed to happen, the mechanisms to deal with it are not standardized.
Because of this locking difficulty, it is not useful for me to describe the mechanisms that would normally be used on POSIX-compatible operating systems that do not have this locking behavior.
  1 Comment
cyberdyne
cyberdyne on 24 Sep 2012
I did a test starting log-file generation and using fileread function together, and it reads the file during generation session. So, I think that the external program close the text file after every update, and I guess that it does that because the generation of log-text file is an options that I enabled (maybe it is not the "true log", but its copy); I hope I was clear.
Updating that I want to achieve may have some latency (just the closing time), there's no problem.
EDIT: I'ld try, as pseudo-code, measuring the text char length and if it changes looking for last change. What do you think?

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!