append part of file name and information in .txt files as suffix to column and table name
MDV
I am trying to learn to program in Igor...baby steps... and I have figured out how to import data from a single text file and put it into a table with the Table and column names converted to my preferred Table and column names, but I need to open several hundreds of text files that have the same basic structure. I want to try to automate a procedure where I can open each file and add a suffix to the Column Name and Table Name that refers to
1) Part of the file name
2) a specific line within the original text file
I have tried googling and using the help browser to figure this out, but I'm having a hard time figuring it out.
This is the code I have put together so far:
Function LoadandEditContraDP (fileName, pathName)
String pathName // Name of path or "" to get dialog
String fileName // Name of file to load or "" to get dialog
//edit Table Name
Edit /N = ContraDP_ //I want to reference Subject Number and Run Number here, which can be found in the File Name
// Load the waves and set the local variables.
LoadWave/J/W/A/E=2/L={90,91,0,0,0}/D/O/P=$pathName fileName
if (V_flag==0) // No waves loaded. Perhaps user canceled.
return -1
endif
//edit Column Names:: I want to include (as a suffix) the Subject and Run Number which can be found in the file name, as well as multiple stimulus parameters that are found in the original .txt files (before line 90)
rename Block, Block_
rename Trial, Trial_
rename Time_s_, Times_
rename f1, L1_
rename f2, L2_
rename X2f1_f2, LDP_
rename N2f1_f2, LNF_
End
I am grateful for any help that you can provide!
Thanks,
MV
LoadWave sets a variable names S_fileName which contains the name of the loaded file. To get just the file name without the extension, use
To read a specific line from the file you need FReadLine. More on this below.
But first execute this in Igor and read the related help:
This usually means that you should load the data from each file into its own data folder. Each data folder will then contain waves with the same names so you can more easily write procedures that work on any given data folder. If you are not familiar with data folders, execute this in Igor:
Here is an example that shows how to access the file name and use it as a data folder name:
http://www.igorexchange.com/files/SPEC%20Loader.ipf
This also uses FReadLine to read header information.
You might be able to modify this example for your purposes. In this example, one file contains multiple sections from which waves are loaded. A data folder is created for each section in the file. In your case you have multiple files so a data folder should be created for each file.
Another example: http://www.igorexchange.com/project/NeuralynxLoader
For more examples:
http://www.igorexchange.com/search/node/LoadWave+type%3Acode_snippet
http://www.igorexchange.com/search/node/FReadLine+type%3Acode_snippet
http://www.igorexchange.com/search/node/IndexedFile+type%3Acode_snippet
March 24, 2013 at 03:35 pm - Permalink
Best,
MV
March 24, 2013 at 03:46 pm - Permalink