1 #pragma rtGlobals=1 // Use modern global access method.
\r
2 #pragma IgorVersion = 4.0
\r
3 #pragma version = 0.4
\r
6 // ExportMFP1D.ipf - A procedure to export force curves from MFP1D to 'hooke'
\r
8 // Copyright (c) 2009 Rolf Schmidt, Montreal
\r
9 // rschmidt@alcor.concordia.ca
\r
11 // This procedure is released under the GNU General Public License version 2
\r
16 // the wave note is now correctly and fully exported in Igor 4
\r
18 // split functionality into ExportMFP1DFolder and ExportMFP1DWaves
\r
19 // ExportMFP1DFolder: export individual Igor binary waves file from a folder
\r
20 // ExportMFP1DWaves: export all currently open waves to a folder
\r
21 // 2009 06 26: v0.2.1
\r
22 // added the IgorVersion pragma
\r
24 // changed the filename finding algorithm to work with Igor 4 and up
\r
25 // Igor 5 users can use the code marked 'the following only works in Igor 5 and up' instead
\r
26 // the procedure now catches 'Cancel' on NewPath
\r
27 // added version information
\r
29 // changed the procedure so that it runs in Igor as well as in MFP (ie Igor with MFP plug-in)
\r
31 // How to use ExportMFP1D()
\r
32 // - save all current waves of interest (ExportMFP1D() kills all open waves before exporting files)
\r
33 // - execute ExportMFP1D() from the command line
\r
34 // - browse to a folder containing force curves (a 'force curve' consists of two files: one 'deflection' and one 'LVDT' file
\r
35 // - ExportMFP1D() will now iterate through all the waves in the folder, extract the header information and create four columns:
\r
36 // 1: approach (x) 2: approach (y) 3: retraction (x) 4; retraction (y)
\r
37 // - the resulting files are saved in the same folder and the same base name as the original files (ie without 'deflection' and 'LVDT')
\r
38 // CAUTION: existing files will be overwritten!
\r
39 // - these files can then be analyzed with 'hooke'
\r
41 Function ExportMFP1DFolder()
\r
46 // set the path (used for opening the waves and saving the output files later)
\r
47 NewPath /O /Q /M="Choose the folder that contains the waves" PathExport1D
\r
52 // get a list of all Igor binary waves in the folder
\r
53 sList=IndexedFile(PathExport1D,-1,".ibw")
\r
55 for(iCount=0; iCount<ItemsInList(sList); iCount+=1)
\r
56 LoadWave /P=PathExport1D /Q StringFromList(iCount, sList)
\r
60 // kill the export path
\r
61 KillPath /Z PathExport1D
\r
64 Function ExportMFP1DWaves()
\r
71 String sWaveCombined
\r
72 String sWaveDeflection
\r
83 // set the path (used for saving the output files later)
\r
84 NewPath /O /Q /M="Choose the folder to save the waves" PathExport1D
\r
86 // get a list of all LVDT waves (could be deflection as well, they always come in a pair)
\r
87 sList=WaveList("*LVDT*", ";", "")
\r
89 // iterate through all the LVDT waves
\r
90 for(iCount=0; iCount<ItemsInList(sList); iCount+=1)
\r
91 // create the wave names as string
\r
92 // the following only works in Igor 5 and up
\r
93 // sWaveLVDT=ReplaceString(".ibw",StringFromList(iCount, sList), "")
\r
94 // sWaveDeflection=ReplaceString("LVDT",sWaveLVDT, "deflection")
\r
95 // sWaveCombined=ReplaceString("LVDT",sWaveLVDT, "_")
\r
96 // END: the following only works in Igor 5 and up
\r
98 // the following works in Igor 4 and up
\r
99 // treat the filename as a key-value list with '.' as a separator
\r
100 // use the first entry (ie 0) as the filename without extension
\r
101 sWaveLVDT=StringFromList(0, StringFromList(iCount, sList), ".")
\r
103 // treat the filename as a key-value list with 'LVDT' as a separator
\r
104 // use the first entry (ie 0) as the first part of the filename
\r
105 sFileName1=StringFromList(0, sWaveLVDT, "LVDT")
\r
106 // getting the second part of the filename is a bit trickier
\r
107 // first, we 'remove' the first part of the filename by treating it as a key
\r
108 // using 'LVDT' as a separator
\r
109 sFileName2=StringByKey(sFileName1, sWaveLVDT, "LVDT")
\r
110 // unfortunately, StringByKey only removes the first character of the separator
\r
111 // to get the second part of the filename, we use VD as the key and 'T' as the separator
\r
112 sFileName2=StringByKey("VD", sFileName2, "T")
\r
113 // then we create the wave names as follows:
\r
114 sWaveDeflection=sFileName1+"deflection"+sFileName2
\r
116 sWaveCombined=sFileName1+"_"+sFileName2
\r
118 // END: the following works in Igor 4 and up
\r
120 // create the waves we need
\r
121 Wave wLVDT=$sWaveLVDT
\r
122 Wave wDeflection=$sWaveDeflection
\r
124 // open the output text file, add extension
\r
125 Open /P=PathExport1D iRefNum as sWaveCombined+".txt"
\r
127 // create the header
\r
128 fprintf iRefNum, "Wave:"+sWaveCombined+"\r"
\r
129 fprintf iRefNum, "WaveLVDT:"+sWaveLVDT+"\r"
\r
130 fprintf iRefNum, "WaveDeflection:"+sWaveDeflection+"\r"
\r
132 // the number of points (use WaveStats to get them) are identical for LVDT and Deflection
\r
135 fprintf iRefNum, "Rows:"+num2str(iPoints)+"\r"
\r
137 // add the note to the file
\r
138 // the notes are identical for LVDT and Deflection
\r
139 // the following only works in Igor 5 and up
\r
140 // fprintf iRefNum, note(wDeflection)
\r
141 // END: the following only works in Igor 5 and up
\r
143 // in order to get the correct number of lines in the note, we have to specify the EOF as \r\n
\r
144 for(iLine=0; iLine<ItemsInList(sNote, "\r\n");iLine+=1)
\r
145 // print every line to the output file
\r
146 fprintf iRefNum, StringFromList(iLine, sNote, "\r\n")
\r
147 // add a CR/LF for every but the last line
\r
148 if(iLine<ItemsInList(sNote, "\r\n")-1)
\r
149 fprintf iRefNum, "\r\n"
\r
153 // separate the approach from the retraction
\r
154 // by simply taking the first half of the points to be the approach
\r
155 // and the second half to be the retraction
\r
156 // this probably has to be changed for dual pulls
\r
157 Duplicate /O /R=[0, iPoints] wLVDT, wApproachX
\r
158 Duplicate /O /R=[0, iPoints] wDeflection, wApproachY
\r
159 Duplicate /O /R=[iPoints+1] wLVDT, wRetractionX
\r
160 Duplicate /O /R=[iPoints+1] wDeflection, wRetractionY
\r
162 // create four columns line by line
\r
163 // 1: approach x 2: approach y 3: retraction x 4: retraction y
\r
164 for(iLine=0; iLine<iPoints; iLine+=1)
\r
165 sLine=num2str(wApproachX[iLine])+"\t"+num2str(wApproachY[iLine])
\r
166 sLine=sLine+"\t"+num2str(wRetractionX[iLine])+"\t"+num2str(wRetractionY[iLine])
\r
167 // add the line to the file
\r
168 fprintf iRefNum, "\r"+sLine
\r
171 // save the text file to disk
\r
172 print "Exporting "+sWaveCombined
\r
177 print "Export completed ("+num2str(ItemsInList(sList))+" files)"
\r
179 // kill the temporary waves used
\r
180 // given the names, it is unlikely that this function will interfere with data
\r
181 KillWaves /Z wApproachX
\r
182 KillWaves /Z wApproachY
\r
183 KillWaves /Z wRetractionX
\r
184 KillWaves /Z wRetractionY
\r