Importing Single Value from File

Hi there,

I've been carrying out some DFT calculations on a molecule and I have data files for which I'd like to automate the data extraction process. I'm attaching 2 sample files. I've used IGOR to extract multiple columns and rows of data, but my approach does not seem to be working for this particular set of files.

The value I'm interested is the "Total Energy" found in row 565 in the c1_gnd.txt file or row 564 in the c2_gnd.txt files I've attached.

What I'd like to do, is be able to extract that value from the text file and append that value to a wave in Igor. Since I have multiple files containing this information, the next step would be to cycle through the various files and extract the value from each and sequentially append them to the same wave. The complication with this particular set of files is that the position of the row containing the "Total Energy" value, changes by a row or two sometimes because of the number of iterations required to complete the previous calculations.

Any ideas?

Thanks!
c1_gnd.txt c2_gnd.txt
I think you would be better off reading all the relevant entries from one file at one time. That will save you the trouble of opening and closing and setting your position in the file multiple times. Once you are done loading all the data from files you can rearrange it as necessary in Igor.

A.G.
WaveMetrics, Inc.
So I looked around and I found something that gets me closer to what I need. The only problem with this is that even though I can successfully print the value I need, I can't add that value directly to a wave yet.

Is there an easy way to accomplish this?

Here's the code:
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function ReadThisLine(pathName, filePath, whichLine, data)
    String pathName // Name of Igor symbolic path
    String filePath         // File name, partial path or full path
    Variable whichLine      // 0-based line number
    String& data            // Output
 
    data = " "
 
    Variable refNum
 
    Open /R /P=$pathName refNum as filePath
 
    Variable lineNumber = 0
    do
        String tmpData
        FReadLine refNum, tmpData
        if (strlen(tmpData) == 0)
            return -1           // Error - end of file
        endif
        if (lineNumber == whichLine)
            data = tmpData
            close refNum
            return 0            // Success
        endif
        lineNumber += 1
    while(1)
End
 
Function DemoReadThisLine()
    String data
    Variable err = ReadThisLine("DFTTotalEnergy" ,"c1_gnd.out", 564, data)
    Print err, data
End


Here's a link to the original thread where found it:
http://www.igorexchange.com/node/1903

Thanks!
Do I get it right that you want some sort of 'Minimal Energy vs Configuration' plot?
Input all the .txt files (yes you can select lots of them, see '/MULT' in open)) line by line , parse the lines for the 'Total Energy' keyword) and append (insertpoints) the result to the 'total energy wave'. Most likely do the same for the 'configuration', i.e. the filename, (text-)wave. The  stringmatch command might become handy and think of '*' as a wildcard -- or maybe stringbykey.
If you need several values, I would also recommend A.G.'s procedure to import all parameters one a file is open.

Have a look at the manual or the help file ;-) or ask here for further advice.
HJ