Loading general texts in series in a macro.

Hello!
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
Hi,

there was recently a similar question:

http://www.igorexchange.com/node/1225

My suggestion was:


Function FileImport()
   
    NewPath/O PathName  //prompt for folder in which the files are
       
    if (V_flag == -1)   //User cancelled dialog
        return -1
    endif
   
    string ListOfFiles = IndexedFile(PathName, -1, ".dat")  // Get list of *.dat files in folder
    String CurrentFile = ""
    variable i = 0
   
    do
        CurrentFile = StringFromList(i, ListOfFiles)           
        if(strlen(CurrentFile)==0)  // no more file to import
            break
        endif
       
        NewDataFolder/O/S $CurrentFile   //make new datafolder
       
        LoadWave/A/D/J/W/K=0/V={" "," $",0,0}/L={0,1,0,0,0} /P=PathName CurrentFile   //needs to be adjusted to your files
        SetDataFolder ::
        i+=1
    while(1)
end


Cheers
Christian
This is very good because it works. Thank you Christian, very helpful! Sorry to not look better for the answer in the forum.
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
First, you should use the /O flag on the duplicate command.
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
anna wrote:

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


Perhaps you need the missing WAVE declarations and WAVEClear command:
--Jim
Function FileImport()
 
    NewPath/O PathName  //prompt for folder in which the files are
 
    if (V_flag == -1)   //User cancelled dialog
        return -1
    endif
 
    string ListOfFiles = IndexedFile(PathName, -1, ".dat")  // Get list of *.dat files in folder
    String CurrentFile = ""
    variable i = 0
 
    do
        CurrentFile = StringFromList(i, ListOfFiles)           
        if(strlen(CurrentFile)==0)  // no more file to import
            break
        endif
 
        NewDataFolder/O/S $CurrentFile   //make new datafolder
 
        LoadWave/A/D/J/W/K=0/V={" "," $",0,0}/L={0,1,0,0,0} /P=PathName CurrentFile   //needs to be adjusted to your files
        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
        SetDataFolder ::
        i+=1
    while(1)
end
JimProuty wrote:
Perhaps you need the missing WAVE declarations and WAVEClear command:


Oh! WAVEClear is just what I also was needing some time ago. Thanks!

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
anna wrote:
Hello!
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


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.
JimProuty wrote:
anna wrote:

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


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


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!
anna wrote:

Secondly, Jim, the WAVEClear command does not exist (is it possible??) in my Igor


WaveClear was added in Igor Pro 6. It is equivalent to this:

Wave w = $"" // Make w refer to no wave

anna wrote:

Another thing. I don't have any Example Experiment in File. May that be due as well to me using Igor Pro 5.02?


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.