--- /dev/null
+#pragma rtGlobals=1 // Use modern global access method.\r
+#pragma IgorVersion = 4.0\r
+#pragma version = 0.3\r
+\r
+//\r
+// ExportMFP1D.ipf - A procedure to export force curves from MFP1D to 'hooke'\r
+//\r
+// Copyright (c) 2009 Rolf Schmidt, Montreal\r
+// rschmidt@alcor.concordia.ca\r
+// \r
+// This procedure is released under the GNU General Public License version 2\r
+//\r
+\r
+// History\r
+// 2009 06 29: v0.3\r
+// split functionality into ExportMFP1DFolder and ExportMFP1DWaves\r
+// ExportMFP1DFolder: export individual Igor binary waves file from a folder\r
+// ExportMFP1DWaves: export all currently open waves to a folder\r
+// 2009 06 26: v0.2.1\r
+// added the IgorVersion pragma\r
+// 2009 06 19: v0.2\r
+// changed the filename finding algorithm to work with Igor 4 and up\r
+// Igor 5 users can use the code marked 'the following only works in Igor 5 and up' instead\r
+// the procedure now catches 'Cancel' on NewPath\r
+// added version information\r
+// 2009 05 29: v0.1\r
+// changed the procedure so that it runs in Igor as well as in MFP (ie Igor with MFP plug-in)\r
+\r
+// How to use ExportMFP1D()\r
+// - save all current waves of interest (ExportMFP1D() kills all open waves before exporting files)\r
+// - execute ExportMFP1D() from the command line\r
+// - browse to a folder containing force curves (a 'force curve' consists of two files: one 'deflection' and one 'LVDT' file\r
+// - ExportMFP1D() will now iterate through all the waves in the folder, extract the header information and create four columns:\r
+// 1: approach (x) 2: approach (y) 3: retraction (x) 4; retraction (y)\r
+// - the resulting files are saved in the same folder and the same base name as the original files (ie without 'deflection' and 'LVDT')\r
+// CAUTION: existing files will be overwritten!\r
+// - these files can then be analyzed with 'hooke'\r
+\r
+Function ExportMFP1DFolder()\r
+\r
+ String sList\r
+ Variable iCount\r
+\r
+ // set the path (used for opening the waves and saving the output files later)\r
+ NewPath /O /Q /M="Choose the folder that contains the waves" PathExport1D\r
+\r
+ KillWaves /A /Z\r
+ \r
+ if(V_flag>=0)\r
+ // get a list of all Igor binary waves in the folder\r
+ sList=IndexedFile(PathExport1D,-1,".ibw")\r
+ // load all waves\r
+ for(iCount=0; iCount<ItemsInList(sList); iCount+=1)\r
+ LoadWave /P=PathExport1D /Q StringFromList(iCount, sList)\r
+ endfor\r
+ ExportMFP1DWaves()\r
+ endif\r
+ // kill the export path\r
+ KillPath /Z PathExport1D\r
+End\r
+\r
+Function ExportMFP1DWaves()\r
+\r
+ String sFileName1\r
+ String sFileName2\r
+ String sLine\r
+ String sList\r
+ String sWaveCombined\r
+ String sWaveDeflection\r
+ String sWaveLVDT\r
+ Variable iCount\r
+ Variable iLine\r
+ Variable iPoints\r
+ Variable iRefNum\r
+ Wave wApproachX\r
+ Wave wApproachY\r
+ Wave wRetractionX\r
+ Wave wRetractionY\r
+\r
+ // set the path (used for saving the output files later)\r
+ NewPath /O /Q /M="Choose the folder to save the waves" PathExport1D\r
+ \r
+ // get a list of all LVDT waves (could be deflection as well, they always come in a pair)\r
+ sList=WaveList("*LVDT*", ";", "")\r
+ // iterate through all the LVDT waves\r
+ for(iCount=0; iCount<ItemsInList(sList); iCount+=1)\r
+ // create the wave names as string\r
+// the following only works in Igor 5 and up\r
+// sWaveLVDT=ReplaceString(".ibw",StringFromList(iCount, sList), "")\r
+// sWaveDeflection=ReplaceString("LVDT",sWaveLVDT, "deflection")\r
+// sWaveCombined=ReplaceString("LVDT",sWaveLVDT, "_")\r
+// END: the following only works in Igor 5 and up\r
+\r
+// the following works in Igor 4 and up\r
+ // treat the filename as a key-value list with '.' as a separator\r
+ // use the first entry (ie 0) as the filename without extension\r
+ sWaveLVDT=StringFromList(0, StringFromList(iCount, sList), ".")\r
+\r
+ // treat the filename as a key-value list with 'LVDT' as a separator\r
+ // use the first entry (ie 0) as the first part of the filename\r
+ sFileName1=StringFromList(0, sWaveLVDT, "LVDT")\r
+ // getting the second part of the filename is a bit trickier\r
+ // first, we 'remove' the first part of the filename by treating it as a key\r
+ // using 'LVDT' as a separator \r
+ sFileName2=StringByKey(sFileName1, sWaveLVDT, "LVDT")\r
+ // unfortunately, StringByKey only removes the first character of the separator\r
+ // to get the second part of the filename, we use VD as the key and 'T' as the separator\r
+ sFileName2=StringByKey("VD", sFileName2, "T")\r
+ // then we create the wave names as follows:\r
+ sWaveDeflection=sFileName1+"deflection"+sFileName2\r
+ sWaveCombined=sFileName1+"_"+sFileName2\r
+// END: the following works in Igor 4 and up\r
+\r
+ // create the waves we need\r
+ Wave wLVDT=$sWaveLVDT\r
+ Wave wDeflection=$sWaveDeflection\r
+ \r
+ // open the output text file, add extension\r
+ Open /P=PathExport1D iRefNum as sWaveCombined+".txt"\r
+\r
+ // create the header\r
+ fprintf iRefNum, "Wave:"+sWaveCombined+"\r"\r
+ fprintf iRefNum, "WaveLVDT:"+sWaveLVDT+"\r"\r
+ fprintf iRefNum, "WaveDeflection:"+sWaveDeflection+"\r"\r
+\r
+ // the number of points (use WaveStats to get them) are identical for LVDT and Deflection\r
+ WaveStats /q wLVDT\r
+ iPoints=V_npnts/2\r
+ fprintf iRefNum, "Rows:"+num2str(iPoints)+"\r"\r
+\r
+ // add the note to the file\r
+ // the notes are identical for LVDT and Deflection\r
+ fprintf iRefNum, note(wLVDT)\r
+\r
+ // separate the approach from the retraction\r
+ // by simply taking the first half of the points to be the approach\r
+ // and the second half to be the retraction\r
+ // this probably has to be changed for dual pulls\r
+ Duplicate /O /R=[0, iPoints] wLVDT, wApproachX\r
+ Duplicate /O /R=[0, iPoints] wDeflection, wApproachY\r
+ Duplicate /O /R=[iPoints+1] wLVDT, wRetractionX\r
+ Duplicate /O /R=[iPoints+1] wDeflection, wRetractionY\r
+\r
+ // create four columns line by line\r
+ // 1: approach x 2: approach y 3: retraction x 4: retraction y\r
+ for(iLine=0; iLine<iPoints; iLine+=1)\r
+ sLine=num2str(wApproachX[iLine])+"\t"+num2str(wApproachY[iLine])\r
+ sLine=sLine+"\t"+num2str(wRetractionX[iLine])+"\t"+num2str(wRetractionY[iLine])\r
+ // add the line to the file\r
+ fprintf iRefNum, "\r"+sLine\r
+ endfor\r
+\r
+ // save the text file to disk\r
+ print "Exporting "+sWaveCombined\r
+ Close iRefNum\r
+ endfor\r
+\r
+ // print message\r
+ print "Export completed ("+num2str(ItemsInList(sList))+" files)"\r
+\r
+ // kill the temporary waves used\r
+ // given the names, it is unlikely that this function will interfere with data\r
+ KillWaves /Z wApproachX\r
+ KillWaves /Z wApproachY\r
+ KillWaves /Z wRetractionX\r
+ KillWaves /Z wRetractionY\r
+End\r