How to import a specific value from a plain text file in Igor Pro
I am working with a text file (attached) that contains various metadata and values written as plain text. I need to extract a few specific numeric values located at known line numbers and character positions from this file and import them into the Igor Pro data folder. From the attached text file, the specific values I need to extract are:
Value '64.60'(TC of reflectance, lower split) occurring at line 71 and column 94Value '.61'(OC/TC) occurring at line 96 and column 19Value '.39'(EC/TC) occurring at line 97 and column 96
Each value occurs at a fixed position in the file.
I have already tried importing the text file using standard text import methods. However, since this file is not delimited, I am unable to access the value using column or row indices in the usual way. I previously attempted to use LoadWave with line and column limits, for example: LoadWave/J/D/E=1/K=0/V={" "," $",0,1}/L={82,85,1,0,0}/W file_path
I would like to know if there is a way in Igor Pro to read a plain text file line by line and extract a value from a specific line and character position, or alternatively, to read the file as a string and extract the required value using string or substring operations. Any guidance, example code, or suggested functions for handling this kind of fixed-position text parsing would be greatly appreciated.
For this you can use Open / Close and FReadLine, which reads one line per call. Below is a very crude but hopefully simple-to-understand example to read these values. This code has almost no safety checks and uses a brute force approach, but you should get the idea. The same basic approach can be used to write a sophisticated parser for data headers from text files, as I have done many times. For example one could rewrite the code to search for a specific entry label instead of specifying line and column numbers ...
Run via, e.g., (note that fullPath must be a mac-compatible path, since I did not bother to parse windows paths here):
February 6, 2026 at 03:43 am - Permalink
Here is a version similar as above, which uses a keyword to find the line of interest, then "sscanf" to extract numeric values.
February 6, 2026 at 04:02 am - Permalink