write and run a script that loads waves from files and rename them accordingly
LeChat
I have N data files data.igr (in Igor Text Data format) each of which is contained into a folder DATA_MAIN/run1 ... DATA_MAIN/runN.
What I actually do is that I copy-paste over and over the following script into my command window:
//initialisation (just run once)
•numrun=-1
•string strangle
//LOAD DATA MANUALLY ?
// to be copy-paste several times into the command line
•numrun+=1
•strangle=num2str(angle[numrun])
•strnom="_theta"+strangle
•strname="sz"+strnom
•duplicate/O sz $strname
•strname="sv"+strnom
•duplicate/O svx $strname
•FuncFit/X=1/H="001"/NTHR=0/TBOX=1023 MyFun W_coef svx/X=sz /D /F={0.950000, 4} // (I don't know how to use strings here, as there is the H="001" argument in this command)
•AA[numrun]=W_coef[0]
•BB[numrun]=W_coef[1]
•CC[numrun]=W_coef[2]
Do you know if there is another better way to do so?
In particular, how can I make a loop on loading the files? Also, is it possible to write and run a script? I tried using function, but I don't know how to properly code functions without putting all the waves I am working on, within the function's argument, which is a pain.
Thank you for your help
Menu "DoStuff"
"Run Test", /Q, Test()
end
Function Test()
// Allows the user to select a folder to load
NewPath/M="Load all waves in folder" /O/Q MainFolderPath
// Returns a semicolon separated string of all subfolders in MainFolderPath
String AllSubFolders=IndexedDir(MainFolderPath, -1, 1)
// Finds the number of subfolders
Variable NumberOfSubfolders=ItemsInList(AllSubFolders, ";")
// Counts through the subfolders
Variable i=0, ii=0, NumberOfFiles=0
String ActiveSubFolder="", AllFilesInFolder="", ActiveFileName=""
for (i=0; i<NumberOfSubFolders; i+=1)
// Finds the name of the next subfolder
ActiveSubFolder=StringFromList(i, AllSubFolders, ";")
// Creates a path to ActiveSubFolder
NewPath /O/Q SubFolderPath, ActiveSubFolder
// Returns a semicolon separated string of all .igr files in ActiveSubFolder
AllFilesInFolder=IndexedFile(SubFolderPath, -1, ".igr")
// Finds the number of files in ActiveSubFolder
NumberOfFiles=ItemsInList(AllFilesInFolder, ";")
// Counts through the files in ActiveSubFolder
for (ii=0; ii<NumberOfFiles; ii+=1)
// Finds the name of the next file
ActiveFileName=StringFromList(ii, AllFilesInFolder, ";")
// Loads the file as an Igor text file. You probably have to adjust this to work with your files.
LoadWave/O/P=SubFolderPath /Q/T ActiveFileName
endfor
endfor
end
February 24, 2017 at 07:13 am - Permalink
Also, search IgorExchange code snippets for examples: http://www.igorexchange.com/search/node/LoadWave+type%3Acode_snippet
February 24, 2017 at 09:48 am - Permalink
Also, search IgorExchange code snippets for examples: http://www.igorexchange.com/search/node/LoadWave+type%3Acode_snippet[/q…]
Great, thanks. I think I am getting closer to my goal.
But how to automatically fit using a changing name for the wave to be fit? The fit function argument H="001" with the quotes makes it impossible for me to create and changing string that I
execute
Thank you for your support
February 24, 2017 at 11:22 am - Permalink
Assuming you have for instance a semicolon separated list of waves like the one returned by WaveList you could do something like:
Wave MyWave=$StringFromList(i, ListOfWaves, ";")
FuncFit MyWave
endfor
To write an " in a string use \". That means to give a string the value: FuncFit H="001" you need to write String MyString="FuncFit H=\"001\""
February 24, 2017 at 11:42 am - Permalink
Execute this:
and this:
February 24, 2017 at 12:54 pm - Permalink
Thanks! now I've got it ;)
Here is my code:
variable muc,bbeta,flag_muc,flag_beta,flag_ell
wave NomRun,fitDi,Lrelax
wave NameRun = root:NameRun
wave ucenter = root:ucenter
wave centercell = root:centercell
wave mu = root:mu
Make/O/N=(numpnts(NomRun)) fitUc,fitbeta
string strfix
wave W_coef
strfix="010"+num2str(flag_muc)+"1"+num2str(flag_beta)+num2str(flag_ell)
display
variable i
for (i=0;i<numpnts(NomRun);i+=1)
variable pointeur
FindValue /S=0/T=1e-3 /V=(NomRun[i]) NameRun; pointeur=V_value;
W_coef={ucenter[pointeur],centercell[pointeur],fitDi[i],muc,mu[pointeur],bbeta,Lrelax[i]}// init Guess
string phrase
phrase="FuncFit/X=1/H=\""+strfix+"\"/NTHR=0/TBOX=1023 uNLsh W_coef cnvx"+num2str(NomRun[i])+" /X=cnsy"+num2str(NomRun[i])+" /D"// /F={0.950000, 4}"
print "------- Run "+num2str(NomRun[i])+" -------"
print W_coef
print phrase
execute phrase
// Plot
appendtograph $("cnvx"+num2str(NomRun[i])) vs $("cnsy"+num2str(NomRun[i]))
appendtograph $("fit_cnvx"+num2str(NomRun[i]))
string str=("ModifyGraph lsize(cnvx"+num2str(NomRun[i])+")=2,lstyle(fit_cnvx"+num2str(NomRun[i])+")=7,lsize(fit_cnvx"+num2str(NomRun[i])+")=3;DelayUpdate")
execute str
str="ModifyGraph rgb(fit_cnvx"+num2str(NomRun[i])+")=(16385,28398,65535)"
execute str
string boxstr="\\Z24run"+num2str(NomRun[i])
TextBox/C/N=text0/A=MC boxstr
DoUpdate
sleep/s 0.5
//Save data
fitUc[i]=W_coef[0]
fitDi[i]=W_coef[2]
fitbeta[i]=W_coef[5]
endfor
End
February 27, 2017 at 02:29 am - Permalink
execute str
with
You can do the same for the FuncFit line.
I assume you use DoUpdate and Sleep to turn the updates into an animation of sorts?
February 28, 2017 at 05:25 am - Permalink