Loading general texts in series in a macro.
I'm quite new at using Igor and I have a question. I am writing a macro. I have a lot of different waves called 1.dat, 2.dat, 3.dat... and so on (like 100 of them). Each wave contains like 13 columns. What I would like to do a macro to open them in series - I mean creating a new folder in root for each file (which is easy) and then loading each wave in a different folder.
So far I wrote:
function shift (ini,final)
variable ini, final, cont
string file
for(cont=ini;cont
file=num2istr(cont)
newdatafolder f_file
setdatafolder root:f_file
loadwave /g /a=w_file_ "C:\\blabla\\file.dat"
setdatafolder root:
endfor
end
I would like to know which commands to use to load 1.dat, 2.dat and so on, because obviously if I write loadwave /g "C:\\blabla\\file.dat" Igor looks for file.dat, even though I defined (or tried to...) a string called file. I want him to understand that he has to load as a general text all the files in order. So I called a string 'file' and then a variable 'cont' in order to use numbers in the string: how do I tell him that 'file.dat' in loadwave is a string and not the name of the file?
Well obviously it doesn't work.
Also (but I think it's the same kind of problem), when I call the newdatafolder Igor calls it f_file, while I want him to call it f_1 if I'm opening 1.dat, f_2 if I'm calling 2.dat and so on. Otherwise the macro doesn't work because after he loaded 1.dat in the folder f_file Igor says that a folder called f_file already exists. How can you blame him!
I hope I could explain correctly my problem, otherwise please let me know. And thank you very much for your time!
Anna
there was recently a similar question:
http://www.igorexchange.com/node/1225
My suggestion was:
Cheers
Christian
November 20, 2009 at 12:56 am - Permalink
Now, problem number 2....
I load the waves in different folders called 1.dat, 2.dat and so on... Inside each folder (which thanks to you contains one wave) I have to do a simple operation which is:
duplicate H Hcorr
duplicate K Knorm
Hcorr += Knorm*tan(30*Pi/180)
where H and K are two columns of the waves. I have to do it for each H and K in each folder. BUT! If I put the command before the SetDataFolder :: that goes back to root it writes the operation in the 1.dat folder and then stops because it doesn't go to the next folder to do the same operation.
Well, I hope that someone cand help me!
Ciao,
Anna
November 20, 2009 at 02:41 am - Permalink
Second, duplicate needs some special attention in loops; execute the following on the command line:
DisplayHelpTopic "duplicate"
this should work:
Duplicate/O H, $"Hcorr"
Duplicate/O K, $"Knorm"
Cheers
Christian
November 20, 2009 at 04:56 am - Permalink
I load the waves in different folders called 1.dat, 2.dat and so on... Inside each folder (which thanks to you contains one wave) I have to do a simple operation which is:
duplicate H Hcorr
duplicate K Knorm
Hcorr += Knorm*tan(30*Pi/180)
where H and K are two columns of the waves. I have to do it for each H and K in each folder. BUT! If I put the command before the SetDataFolder :: that goes back to root it writes the operation in the 1.dat folder and then stops because it doesn't go to the next folder to do the same operation.
Ciao,
Anna[/quote]
Perhaps you need the missing WAVE declarations and WAVEClear command:
--Jim
November 20, 2009 at 09:06 am - Permalink
Oh! WAVEClear is just what I also was needing some time ago. Thanks!
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
November 20, 2009 at 10:44 am - Permalink
I'm quite new at using Igor and I have a question. I am writing a macro. I have a lot of different waves called 1.dat, 2.dat, 3.dat... and so on (like 100 of them). Each wave contains like 13 columns. What I would like to do a macro to open them in series - I mean creating a new folder in root for each file (which is easy) and then loading each wave in a different folder.
Anna[/quote]
Study the "Data Folder Tutorial". You can open it by choosing File->Example Experiments->Tutorials->Data Folder Tutorial.
This shows how to load sets of waves from a series of files into separate data folders - one data folder per file.
November 20, 2009 at 09:15 pm - Permalink
I load the waves in different folders called 1.dat, 2.dat and so on... Inside each folder (which thanks to you contains one wave) I have to do a simple operation which is:
duplicate H Hcorr
duplicate K Knorm
Hcorr += Knorm*tan(30*Pi/180)
where H and K are two columns of the waves. I have to do it for each H and K in each folder. BUT! If I put the command before the SetDataFolder :: that goes back to root it writes the operation in the 1.dat folder and then stops because it doesn't go to the next folder to do the same operation.
Ciao,
Anna[/quote]
Perhaps you need the missing WAVE declarations and WAVEClear command:
--Jim
WAVE H, K // Presumably your column/Wave names are H and K
Duplicate/O H Hcorr
Duplicate/O K Knorm // I'm not sure why you need to use Knorm instead of just K, but okay...
Hcorr += Knorm*tan(30*Pi/180)
WAVEClear H, K, Hcorr, Knorm // Next time through the loop the WAVE References aren't set already
[/quote]
Hello! First of all, thank you to everybody, Christian, Jim and Hrodstein. Very helpful! Sorry to reply so late but it was the weekend. And now back to work :-(
Secondly, Jim, the WAVEClear command does not exist (is it possible??) in my Igor... I mean it simply doesn't turn blue, it gives me an error and also it doesn't exist in the manual. I have Igor Pro 5.02... may that be the reason?
So, since in the manual says that this command is equivalent to WAVE /Z I tried to use that by writing:
WAVE /Z H, K, Hcorr
and it does the job! So, great.
Another thing. I don't have any Example Experiment in File. May that be due as well to me using Igor Pro 5.02?
Byebye!
November 23, 2009 at 02:28 am - Permalink
Secondly, Jim, the WAVEClear command does not exist (is it possible??) in my Igor
[/quote]
WaveClear was added in Igor Pro 6. It is equivalent to this:
Wave w = $"" // Make w refer to no wave
[quote=anna]
Another thing. I don't have any Example Experiment in File. May that be due as well to me using Igor Pro 5.02?
[/quote]
This would be because your Igor Pro installation is fouled up. I would uninstall and reinstall from CD. Then update to the latest in the 5.0x line (5.05A I think).
Or you could uninstall and install Igor Pro 6.1 which you can download here:
htpp://www.wavemetrics.net
In this case you will have 30 days in fully-functional demo mode during which you can purchase an upgrade to 6.1 to convert to licensed mode.
November 25, 2009 at 07:38 pm - Permalink