Load .rtf files with spaces instead of TAB or comma

Hello everyone,

I would like to automatically load some data from .rtf files. These are exported from an instrument software and I cannot do anything to change the way they are exported.
I need the information at the beginning of the file (so I thought of loading the file as text/strings first), and also the data themselves (as 3 more separate waves). So 1 file --> 4 waves.
Afterwards other procedures perform the analysis of these files, 1 by 1, and give me an output pdf.

I tried to use the codes that other users have kindly posted here and nothing seems to work.
Now it's getting kind of strange: I cannot upload .rtf files to this forum so I opened one and saved it as .txt, to be able to upload it. I tried the normal procedures for loading ( loadwave/G etc) on this .txt (formerly .rtf) file and... it works perfect, 3 waves for 3 columns of data!

Is anything going funny with Igor, when loading something that has a .rtf extension?

I am really lost here, thanks in advance for any suggestion and help!
Example_rtf.txt (334.5 KB)
The RTF formated file includes codes that direct the formatting; the file contains more text than the values that you want to load. I've attached a screen image from a hex editor to show this. The table on the top is from the text file while that on the bottom is from the same file encoded with rich text. As you can see, the RTF format still appears to be all ASCII characters, but you will have to devise a filtering scheme to remove them.
RTF_TXT Hex.PNG (79.22 KB)
You may have some success if you load the rtf document as a notebook in igor and then extract the text from that.
Hope this helps,
Kurt
Quote:
I would like to automatically load some data from .rtf files.


LoadWave can not load RTF files. The issue is not the extension but the contents of the file. To see this open it in Igor as a notebook (File->Open-Notebook). Igor will ask if you want to convert from RTF. Say no - Igor will open it as an unformatted notebook and you will see the original RTF code. Then open it as a notebook again and say yes - you will see what it looks like when converted to an Igor formatted notebook.

In order to load the data using LoadWave you will need to convert the file to text. If you want to automate this in Igor you can use OpenNotebook and SaveNotebook. But first get the loading part right working on the file that you manually converted to text.

Use LoadWave/G (Load General Text) to load the numeric columns. Among other attributes it handles space-delimited text easily.

If you want to control the wave names created by LoadWave use the /B flag.

Quote:
I need the information at the beginning of the file


You will need to use Open/FReadLine/Close to read the header information. For an example see http://www.igorexchange.com/node/908.

Quote:
These are exported from an instrument software and I cannot do anything to change the way they are exported.

RTF is an awful way to export scientific data. Double-check that there is no other export format. If so contact the instrument manufacturer and ask them to export as plain text.

Great as usual!
Thanks Jtigor, I did not know that .rtf was so nasty.
And thanks Kurt too, I was playing around with notebooks when the next suggestions came. I never needed before to use notebooks, it was a good suggestion.
And finally thanks Hrodstein, it was the final kick to solve my problem.

I pasted the code I am using. It nicely loads these cursed .rtf files (I agree it is an awful way to export data...) as notebooks, exports them as plain text and kills the window.
It works just nice. Afterwards I will keep going as usual, with the text files. Loading them as strings/text for the header, and as normal waves for math.

I am so happy about this solution. Only one question more, everything will be totally perfect if you could help me on these two:
with the code I wrote, it asks me everytime if I want to convert the file to plain text: is there a way to avoid it, i.e. convert quietly?
it also asks for confirmation when saving the file as .txt. Also this one, can it somehow be silenced too?
That way, I would only need to point the folder and I will find all the texts there - ready to be used by the other procedures.

Thanks again!

function convert_em_all()
variable i=0
    getfilefolderinfo/D
    newpath/O rtf
    string filelist= indexedfile(rtf,-1,".rtf")
    do
        OpenNotebook/K=1/P=rtf/V=1/Z/N=ThisNotebook stringfromlist(i,filelist)
        Savenotebook/P=rtf/S=6 ThisNotebook
        KillWindow ThisNotebook
        i += 1  
    while(i<itemsinlist(filelist))
    variable/g No=i
    print No
end
Quote:
it asks me everytime if I want to convert the file to plain text: is there a way to avoid it, i.e. convert quietly?


Unfortunately no. RTF is so little used that there has never been a need for this.

Quote:
it also asks for confirmation when saving the file as .txt.


You need to specify the name of the file to save like this
SaveNotebook /P=rtf /S=6 /O ThisNotebook as "ThisNotebook.txt"

Note the /O for overwrite.
Thanks Hrodstein! Problem solved, as much as possible at least!
I think the avoiding confirmation to convert to plain .txt should go to the wishlist for next Igor versions ;)
It is quite disturbing but... whatever... I will get a coffee and drink it while clicking "yes" "yes" "yes" without thinking.

So here is the final version of the code:

function convert_em_all()
variable i=0
    getfilefolderinfo/D
    newpath/O rtf
    string filelist= indexedfile(rtf,-1,".rtf")
    do
        OpenNotebook/K=1/P=rtf/V=1/Z/N=ThisNotebook stringfromlist(i,filelist)
        String TheName="RTF"+num2str(i)+".txt"
        Savenotebook/P=rtf/S=6 ThisNotebook as TheName
        KillWindow ThisNotebook
        i += 1  
    while(i<itemsinlist(filelist))
    variable/g No=i
    print No
end
FWIW, a search on "convert rtf to text" might give you other options (with batch methods too) rather than Igor.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville