Load .rtf files with spaces instead of TAB or comma
DavideT
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!
September 25, 2013 at 05:47 am - Permalink
Hope this helps,
Kurt
September 25, 2013 at 07:52 am - Permalink
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.
You will need to use Open/FReadLine/Close to read the header information. For an example see http://www.igorexchange.com/node/908.
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.
September 25, 2013 at 09:29 am - Permalink
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!
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
September 25, 2013 at 10:31 am - Permalink
Unfortunately no. RTF is so little used that there has never been a need for this.
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.
September 25, 2013 at 10:57 am - Permalink
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:
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
September 25, 2013 at 11:07 am - Permalink
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
September 25, 2013 at 05:13 pm - Permalink