continuously monitoring of a text file - best practice

Discussion in 'MATLAB' started by Roland, Sep 25, 2010.

  1. Roland

    Roland Guest

    hello!

    i need to continuously monitor a text file and do some analysis on the text file data, if the file changed. In this case, another program from time to time writes data to the end of the text file. I do not have any kind of access to the source code of that program. I was wondering, what is the best programming practise for such a kind of problem.

    i solved this with a while loop, and a pause command, otherwise it would need all CPU resources. I cound not think of a condition to check, if the file changed. so i do all the analysis lets say every 10 seconds. but i feel there must be a better way to do so. can the change of a file trigger a matlab function?? how do other programs continuously monitor the state of files, variables, etc without eating up all the cpu.

    my solution is in pseudo code:

    cond=true;
    while cond
    fid=fopen(textfile)
    data=textscan(fid, some conditions)
    fclose(fid)

    do some data analysis

    plot data

    pause(10)
    end
     
    Roland, Sep 25, 2010
    #1
    1. Advertisements

  2. Could you tell which OS you are on?
    I am sure every OS has a way to monitor this efficiently. ( I wonder how
    'tail' works on *NIX).

    Maybe you could monitor for the time stamp on the file (DIR)
    intermittently using PAUSE. Only if the stamp changed, would you need to
    fire your analysis.
     
    Ashish Uthama, Sep 26, 2010
    #2
    1. Advertisements

  3. Roland

    per isakson Guest

    You could use the timer object. Search for "timer" in the help. Checking the time stamp is a good idea.

    / per
     
    per isakson, Sep 26, 2010
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.