#pragma TextEncoding = "UTF-8" #pragma version=5.10 #pragma rtGlobals=3 #pragma IgorVersion=9 //The procedure was developed by Dr. Gregor Germer within a research project of Prof. Dr. Eckart Rühl (Physical Chemistry, Freie Universität Berlin, Berlin, Germany) funded by the German Research Foundation (DFG), grant no: RU 420/12-1. // //It is required to cite the following reference when this procedure is used for scientific work and publications: G. Germer, T. Ohigashi, H. Yuzawa, N. Kosugi, R. Flesch, F. Rancan, A. Vogt, and E. Rühl, “Improved Skin Permeability after Topical Treatment with Serine Protease: Probing the Penetration of Rapamycin by Scanning Transmission X-Ray Microscopy”, ACS Omega 6, 12213-12222 (2021). doi.org/10.1021/acsomega.1c01058. // //Many thanks for the help from the wavemetrics forum, especially to the users tony, chozo, jjweimer, oleytken, KZarzana, KurtB, johnweeks (WM) and aclight (WM). Without their help this extended version wouldn’t achieve the current state. //Thanks to my students for beta testing // //changelog: //ggermer - 5.10: add support for 4-dim. wave-to-fit waves - Please be careful, I don't have a measured dataset to check, the check on a generated dataset seems to be ok. //ggermer - 5.07: saves the note of the to-be-fitted-wave in the information wave, shorter names for LCM results & name of to-be-fitted-wave saved as note in LCM_coef & LCM_sigma //ggermer - 5.06: LCM panel position is relative to the middle of the active screen / the screen where the mouse is (Macintosh) or Igors windows (Windows), Waves panel relative to LCM panel, fixedSize=1 for the LCMpanel, Panel position optimation using Windows //ggermer - 5.05: restart bug fixes, correction of start/end for x-shift pay attention to the initial value //ggermer - 5.04: MT optimization 1-dim. waves, uses version numbering compatible with the pragma version, mask_red restart bug fixed, change of units, bug fix 1-dim. fit_wave, waves w_coef & w_sigma & w_references now killed //ggermer - 5.03: save LCM configration files, bug fix for wave with names containing space (e.g. MPF results) //ggermer - 5.02: single energy fit for all reference waves together, restart LCM using information wave, restart LCM using old mask wave, deactivation of point-by-point-fits, bug fix restart LCM after aborted LCM (MT problem), generate fit wave after MT process //ggermer - 5.01: bug fix for hold function, bug fix LCM panel (green border), using of double float waves, bug fix for 3-dim. waves: (x,1,z) and (1,y,z) //ggermer - 5.00: completely rewritten version, now without the use quick and dirty methods, new layout for panel, drop-down menu for panel, help text for panel, new spectrums panel //ggermer - 4.xx: multiple energy shift for all reference waves, all-at-ones funcfit, results of 1 dim. waves saved as global variables, buttons for fast changing of initial guess & min & max, LCM funcfit uses /NWOK, bug fix all-at-ones funcfit //ggermer - 3.xx: average spectrum in panel, bug fix open LCM panel if panel already exists, save LCM results in a subfolder of the input, extract LCM results in multiple 2-dim. waves //ggermer - 0-2: new panel, mask regions as red region(s) in average spectrum, multiple bug fixes Menu "Analysis" submenu "Packages" submenu "Linear-combination modeling" "Start LCM (new dataset).", f_LCM_start() "Restart LCM (dataset of information wave from Data Browser, no mask wave).", f_LCM_restart(0) "Restart LCM (dataset of information wave from Data Browser, using mask wave).", f_LCM_restart(1) "Calculate relative sigma of LCM sigma wave from Data Browser.", f_sigma_to_sigma_rel() "Release ThreadGroup for aborted LCM using Igor Pro's beach ball.", f_ThreadGroupRelease_all() end end end //---------------------------------------------------------------------------- function f_LCM_beep() variable v_beep=0 //0 = no beep, 1 = beep return v_beep end function/S f_LCM_version() string s_version=num2str(ProcedureVersion("f_LCM_start")) return s_version end function f_LCM_start() if (WinType("LCMpanel")) //does an active LCM exists? DoWindow/F LCMpanel return 0 else //export folder generation f_ThreadGroupRelease_all() setDataFolder root: if (datafolderExists("root:Packages")==0) newdataFolder root:Packages endif if (datafolderExists("root:Packages:LCM")==0) newdataFolder root:Packages:LCM else //remove old files killdataFolder root:Packages:LCM newdatafolder root:Packages:LCM endif setDataFolder root:Packages:LCM string testfolder = "root:Packages:LCM" //transfer waves setdataFolder $testfolder make/D/O/WAVE/N=1 reference_waves make/D/O/WAVE/N=1 reference_waves_fit make/D/O/WAVE/N=1 data_wave make/D/O/N=10 lcm_variables //[0] = v_lcm_type: 1 = all-at-ones 2 = point-by-point , [1] = x_shift_done: 1 = no 2 = yes , [2] = quantity of waves, [3] = v_LCM_offset, [4] = v_LCM_delta, [5] = v_LCM_max , [6] = fitTol, [7] = start, [8] = end, [9] = dimensions of sample_wave //import of sample wave setdataFolder root: variable index,index2 variable v_num_of_waves=0 string s_nameofwave string s_wavepath string s_promptStr = "Choose the sample wave (1, 2 or 3 dimensions)" CreateBrowser prompt=s_promptStr, showWaves=1, showVars=0, showStrs=0 if (V_flag==0) print "LCM: Abort by user." killdataFolder/Z root:Packages:LCM return 0 endif s_wavepath=removeending(s_BrowserList,";") if (waveexists($s_wavepath)==0) print "LCM: No sample wave." killdataFolder/Z root:Packages:LCM return 0 endif wave w_sample=$s_wavepath variable v_rows=dimsize(w_sample,0) variable v_columns=dimsize(w_sample,1) variable v_layer=dimsize(w_sample,2) variable v_chunks=dimsize(w_sample,3) string s_exportname variable v_transformed_2_3D_loc=0 variable v_sampleoffset, v_sampledelta, v_rows_references variable v_layer_sample setdataFolder $testfolder if (v_chunks>1) v_sampleoffset = dimoffset(w_sample,3) v_sampledelta = dimdelta(w_sample,3) make/D/N=(v_chunks)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_chunks lcm_variables[9]=4 v_layer_sample=dimsize(w_sample,3) else if (v_layer>0) v_sampleoffset = dimoffset(w_sample,2) v_sampledelta = dimdelta(w_sample,2) make/D/N=(v_layer)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_layer lcm_variables[9]=3 v_layer_sample=dimsize(w_sample,2) else if (v_columns>0) v_sampleoffset = dimoffset(w_sample,1) v_sampledelta = dimdelta(w_sample,1) make/D/N=(v_columns)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_columns lcm_variables[9]=2 v_layer_sample=dimsize(w_sample,1) else v_sampleoffset = dimoffset(w_sample,0) v_sampledelta = dimdelta(w_sample,0) make/D/N=(v_rows)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_rows lcm_variables[9]=1 v_layer_sample=dimsize(w_sample,0) endif endif endif data_wave[0]=$s_wavepath //import of reference waves s_promptStr = "Choose all references (1 dimension) wave for linear combination." setdataFolder root: CreateBrowser executeMode=2, prompt=s_promptStr, showWaves=1, showVars=0, showStrs=0 if (V_flag==0) print "LCM: Abort by user." killdataFolder/Z root:Packages:LCM return 0 endif setdataFolder $testfolder variable index_max=itemsinList(S_BrowserList,";") variable v_position variable wave_index=0 variable v_dim_wave string s_test string s_order="" for (index=0;index0) insertPoints v_dim_wave,1,reference_waves insertPoints v_dim_wave,1,reference_waves_fit endif s_order+=s_test+";" s_nameofwave=testfolder+":reference"+num2str(wave_index) make/D/O w_inputwave killwaves w_inputwave wave w_inputwave=$s_test make/D/N=(v_rows_references)/O w_scaledwave for (index2=0;index21) make/N=(v_rows,(v_columns*v_layer),v_chunks)/FREE w_3dim variable ch_index for (r_index=0;r_index0) if (v_columns>1&&v_rows>1) make/D/O W_ISBeamAvg make/D/O W_ISBeamMax make/D/O W_ISBeamMin ImageStats/BEAM/Q w_sample setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),W_ISBeamAvg make/D/O root:Packages:LCM:w_example killwaves root:Packages:LCM:w_example duplicate W_ISBeamAvg root:Packages:LCM:w_example killwaves W_ISBeamAvg killwaves W_ISBeamMax killwaves W_ISBeamMin else if (v_columns==1&&v_rows==1) make/D/O/N=(v_layer) w_build matrixOP/O w_build=beam(w_sample,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build duplicate/O w_build root:Packages:LCM:w_example else if (v_rows>1) make/D/O/N=(v_layer) w_build matrixOP/O w_build=sumCols(w_sample) make/D/O/N=(v_layer) w_build2 matrixOP/O w_build2=beam(w_build,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build2 duplicate/O w_build2 root:Packages:LCM:w_example else make/D/O/N=(v_layer) w_build matrixOP/O w_build=sumRows(w_sample) make/D/O/N=(v_layer) w_build2 matrixOP/O w_build2=beam(w_build,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build2 duplicate/O w_build2 root:Packages:LCM:w_example endif endif endif else if (v_columns>0) make/D/O/N=(v_columns) w_build matrixOP/O w_build=sumCols(w_sample) make/D/O/N=(v_columns) w_build2 for (index=0;index=w_monitors[v_i-1][0])&&(v_left<=w_monitors[v_i-1][1])&&(v_top>=w_monitors[v_i-1][2])&&(v_top<=w_monitors[v_i-1][3])) v_active_screen=v_i endif endfor //print v_active_screen s_str = StringByKey("SCREEN"+num2str(v_active_screen), s_Igorinfo) sscanf s_str, "DEPTH=%*d,RECT=%d,%d,%d,%d", v_screen_left, v_screen_top, v_screen_right, v_screen_bottom //print v_screen_left, v_screen_right //print v_screen_top, v_screen_bottom v_sc1_width_mp=round((v_screen_right+v_screen_left)/2) //absolute position, negative values possible v_sc1_length_mp=round((v_screen_bottom+v_screen_top)/2) endif //print v_sc1_width_mp, v_sc1_length_mp //window for data input variable v_height=30*(wave_index) if (v_height < (75)) v_height=(75) endif variable v_panel_left=v_sc1_width_mp-483 //165 variable v_panel_rigth=v_sc1_width_mp+483 //(340+425+165+200+1) variable v_panel_top=v_sc1_length_mp-floor((v_height+110)/2) //140 variable v_panel_bottom=v_sc1_length_mp+ceil((v_height+110)/2) //(v_height+110+140) make/O/N=4 root:Packages:LCM:w_panel_resolution wave w_panel_resolution=root:Packages:LCM:w_panel_resolution //left,right,top,bottom w_panel_resolution[0]=v_panel_left w_panel_resolution[1]=v_panel_rigth w_panel_resolution[2]=v_panel_top w_panel_resolution[3]=v_panel_bottom NewPanel/K=2/W=(v_panel_left,v_panel_top,v_panel_rigth,v_panel_bottom)/N=LCMpanel as "linear-combination modeling input" // /W=(165,140,(425+165),(30*(quantity_waves)+110+140)) if (stringmatch(IgorInfo(2),"Macintosh")==1) MoveWindow v_panel_left,v_panel_top,-1,-1 //bug fix for negative positions on Macintosh endif ModifyPanel/W=LCMpanel fixedSize=1 DrawRect 422,-2,(422+200),(v_height+110+140+2) DrawText 10 ,25, "General settings" SetVariable V_FitTol ,pos={160 ,10} ,value=_NUM:0.0001, limits={1e-10,0.01,0}, help={"Accuracy of the fit - between 0.01 and 1e-10."} DrawText 125 ,25, "FitTol" SetVariable V_StartFit ,pos={270 ,10} ,value=_NUM:v_sampleoffset, limits={v_sampleoffset,(v_sampleoffset+v_sampledelta*(v_rows_references-1)),0}, help={"Start value (energy) for fit."} DrawText 240 ,25, "Start" SetVariable V_EndFit ,pos={365 ,10} ,value=_NUM:(v_sampleoffset+v_sampledelta*(v_rows_references-1)), limits={v_sampleoffset,(v_sampleoffset+v_sampledelta*(v_rows_references-1)),0}, help={"End value (energy) for fit."} DrawText 340,25, "End" string s_LCM_sample_global=nameofwave(w_sample) string s_LCM_sample_local=ReplaceString("'",s_LCM_sample_global,"") //if wave starts with bad character string s_samplename variable v_start=v_sampleoffset variable v_end=(v_sampleoffset+v_sampledelta*(v_rows_references-1)) if (strlen(s_LCM_sample_local)<38) //for long wavenames s_samplename="Reference waves for "+s_LCM_sample_local+"" else s_samplename="Reference waves for "+s_LCM_sample_local[0,5]+" ... "+s_LCM_sample_local[(strlen(s_LCM_sample_local)-33),(strlen(s_LCM_sample_local)-1)]+"" endif DrawText 10 ,45, s_samplename PopupMenu popup0 pos={430,5},size={50.00,14.00},value="All-at-ones Fit;Point-by-point-Fit",help={"The All-at-ones Fit is faster than the Point-by-point-Fit."},disable=2 PopupMenu popup1 pos={430,25},size={50.00,14.00},value="No x-shift analysis;Multiple x-shift analysis;Single x-shift analysis",help={"Better results for x-shift analysis if Initial Guess of waves >> 1e-6 (e. g. 0.5), ± = zero holds the initial value, Single x-shift analysis uses the initial x-shift of the first wave"} string s_start string s_min string s_max, s_x_start, s_x_var, s_x_hold string s_wavepos="" variable v_intemsinlist for (index=0;index6) w_initial_xshift[index-1]=str2num(w_information[index][5]) w_var_xshift[index-1]=str2num(w_information[index][6]) else w_initial_xshift[index-1]=0 w_var_xshift[index-1]=0 endif endif endfor for (index=0;index1) v_sampleoffset = dimoffset(w_sample,3) v_sampledelta = dimdelta(w_sample,3) make/D/N=(v_chunks)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_chunks lcm_variables[9]=4 v_layer_sample=dimsize(w_sample,3) else if (v_layer>0) v_sampleoffset = dimoffset(w_sample,2) v_sampledelta = dimdelta(w_sample,2) make/D/N=(v_layer)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_layer lcm_variables[9]=3 v_layer_sample=dimsize(w_sample,2) else if (v_columns>0) v_sampleoffset = dimoffset(w_sample,1) v_sampledelta = dimdelta(w_sample,1) make/D/N=(v_columns)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_columns lcm_variables[9]=2 v_layer_sample=dimsize(w_sample,1) else v_sampleoffset = dimoffset(w_sample,0) v_sampledelta = dimdelta(w_sample,0) make/D/N=(v_rows)/O energyscale=v_sampleoffset+x*v_sampledelta v_rows_references=v_rows lcm_variables[9]=1 v_layer_sample=dimsize(w_sample,0) endif endif endif data_wave[0]=$s_wavepath variable index_max=itemsinList(s_reference_waves,";") variable v_position variable wave_index=0 variable v_dim_wave string s_test string s_order="" for (index=0;index0) insertPoints v_dim_wave,1,reference_waves insertPoints v_dim_wave,1,reference_waves_fit endif s_order+=s_test+";" s_nameofwave=testfolder+":reference"+num2str(wave_index) make/D/O w_inputwave killwaves w_inputwave wave w_inputwave=$s_test make/D/N=(v_rows_references)/O w_scaledwave for (index2=0;index2v_max_position)) w_mask_newscale[index2]=1 else w_mask_newscale[index2]=w_mask_oldscale[v_position] endif endfor setscale/P x,v_sampleoffset,v_sampledelta,w_mask_newscale else v_use_mask=0 endif //generate MT fit wave make/D/O/N=(v_num_of_waves,v_layer_sample) w_references_MT for (index=0;index1) make/N=(v_rows,(v_columns*v_layer),v_chunks)/FREE w_3dim variable ch_index for (r_index=0;r_index0) if (v_columns>1&&v_rows>1) make/D/O W_ISBeamAvg make/D/O W_ISBeamMax make/D/O W_ISBeamMin ImageStats/BEAM/Q w_sample setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),W_ISBeamAvg make/D/O root:Packages:LCM:w_example killwaves root:Packages:LCM:w_example duplicate W_ISBeamAvg root:Packages:LCM:w_example killwaves W_ISBeamAvg killwaves W_ISBeamMax killwaves W_ISBeamMin else if (v_columns==1&&v_rows==1) make/D/O/N=(v_layer) w_build matrixOP/O w_build=beam(w_sample,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build duplicate/O w_build root:Packages:LCM:w_example else if (v_rows>1) make/D/O/N=(v_layer) w_build matrixOP/O w_build=sumCols(w_sample) make/D/O/N=(v_layer) w_build2 matrixOP/O w_build2=beam(w_build,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build2 duplicate/O w_build2 root:Packages:LCM:w_example else make/D/O/N=(v_layer) w_build matrixOP/O w_build=sumRows(w_sample) make/D/O/N=(v_layer) w_build2 matrixOP/O w_build2=beam(w_build,0,0) setscale/P x,dimoffset(w_sample,2),dimdelta(w_sample,2),w_build2 duplicate/O w_build2 root:Packages:LCM:w_example endif endif endif else if (v_columns>0) make/D/O/N=(v_columns) w_build matrixOP/O w_build=sumCols(w_sample) make/D/O/N=(v_columns) w_build2 for (index=0;index(v_sampleoffset+v_sampledelta*(v_rows_references-1))) v_start_restart=v_sampleoffset endif if (v_end_restart>(v_sampleoffset+v_sampledelta*(v_rows_references-1))) v_end_restart=(v_sampleoffset+v_sampledelta*(v_rows_references-1)) endif //generate panel //lcm_variables //[0] = v_lcm_type: 1 = all-at-ones 2 = point-by-point , [1] = x_shift_done: 1 = no 2 = yes , [2] = quantity of waves, [3] = v_LCM_offset, [4] = v_LCM_delta, [5] = v_LCM_max, [6] = fitTol, [7] = start, [8] = end, [9] = dimensions of sample_wave make/D/O/N=(v_rows_references) root:Packages:LCM:w_mask=1 make/D/O/N=(v_rows_references) root:Packages:LCM:w_mask_red=NaN wave w_mask=root:Packages:LCM:w_mask wave w_mask_red=root:Packages:LCM:w_mask_red if (v_use_mask>0) w_mask=w_mask_newscale for (index2=0;index2=w_monitors[v_i-1][0])&&(v_left<=w_monitors[v_i-1][1])&&(v_top>=w_monitors[v_i-1][2])&&(v_top<=w_monitors[v_i-1][3])) v_active_screen=v_i endif endfor //print v_active_screen s_str = StringByKey("SCREEN"+num2str(v_active_screen), s_Igorinfo) sscanf s_str, "DEPTH=%*d,RECT=%d,%d,%d,%d", v_screen_left, v_screen_top, v_screen_right, v_screen_bottom //%*d ignors this iput, only %d is used //print v_screen_left, v_screen_right //print v_screen_top, v_screen_bottom v_sc1_width_mp=round((v_screen_right+v_screen_left)/2) //absolute position, negative values possible v_sc1_length_mp=round((v_screen_bottom+v_screen_top)/2) endif //print v_sc1_width_mp, v_sc1_length_mp //window for data input variable v_height=30*(wave_index) if (v_height < (75)) v_height=(75) endif variable v_panel_left=v_sc1_width_mp-483 //165 variable v_panel_rigth=v_sc1_width_mp+483 //(340+425+165+200+1) variable v_panel_top=v_sc1_length_mp-floor((v_height+110)/2) //140 variable v_panel_bottom=v_sc1_length_mp+ceil((v_height+110)/2) //(v_height+110+140) make/O/N=4 root:Packages:LCM:w_panel_resolution wave w_panel_resolution=root:Packages:LCM:w_panel_resolution //left,right,top,bottom w_panel_resolution[0]=v_panel_left w_panel_resolution[1]=v_panel_rigth w_panel_resolution[2]=v_panel_top w_panel_resolution[3]=v_panel_bottom NewPanel/K=2/W=(v_panel_left,v_panel_top,v_panel_rigth,v_panel_bottom)/N=LCMpanel as "linear-combination modeling input" // /W=(165,140,(425+165),(30*(quantity_waves)+110+140)) if (stringmatch(IgorInfo(2),"Macintosh")==1) MoveWindow v_panel_left,v_panel_top,-1,-1 //bug fix for negative positions on Macintosh endif ModifyPanel/W=LCMpanel fixedSize=1 DrawRect 422,-2,(422+200),(v_height+110+140+2) DrawText 10 ,25, "General settings" SetVariable V_FitTol ,pos={160 ,10} ,value=_NUM:v_fittol_restart, limits={1e-10,0.01,0}, help={"Accuracy of the fit - between 0.01 and 1e-10."} DrawText 125 ,25, "FitTol" SetVariable V_StartFit ,pos={270 ,10} ,value=_NUM:v_start_restart, limits={v_sampleoffset,(v_sampleoffset+v_sampledelta*(v_rows_references-1)),0}, help={"Start value (energy) for fit."} DrawText 240 ,25, "Start" SetVariable V_EndFit ,pos={365 ,10} ,value=_NUM:v_end_restart, limits={v_sampleoffset,(v_sampleoffset+v_sampledelta*(v_rows_references-1)),0}, help={"End value (energy) for fit."} DrawText 340,25, "End" string s_LCM_sample_global=nameofwave(w_sample) string s_LCM_sample_local=ReplaceString("'",s_LCM_sample_global,"") //if wave starts with bad character string s_samplename variable v_start=v_sampleoffset variable v_end=(v_sampleoffset+v_sampledelta*(v_rows_references-1)) if (strlen(s_LCM_sample_local)<38) //for long wavenames s_samplename="Reference waves for "+s_LCM_sample_local+"" else s_samplename="Reference waves for "+s_LCM_sample_local[0,5]+" ... "+s_LCM_sample_local[(strlen(s_LCM_sample_local)-33),(strlen(s_LCM_sample_local)-1)]+"" endif DrawText 10 ,45, s_samplename //print v_allatones //print v_xshift_restart PopupMenu popup0 pos={430,5},size={50.00,14.00},value="All-at-ones Fit;Point-by-point-Fit",help={"The All-at-ones Fit is faster than the Point-by-point-Fit."},mode=v_allatones,disable=2 //,popmatch=s_allatones PopupMenu popup1 pos={430,25},size={50.00,14.00},value="No x-shift analysis;Multiple x-shift analysis;Single x-shift analysis",help={"Better results for x-shift analysis if Initial Guess of waves >> 1e-6 (e. g. 0.5), ± = zero holds the initial value, Single x-shift analysis uses the initial x-shift of the first wave"},mode=v_xshift_restart //popmatch=s_xshift_restart, string s_start string s_min string s_max, s_x_start, s_x_var, s_x_hold string s_wavepos="" variable v_intemsinlist for (index=0;indexv_end) b_index=v_start v_start=v_end v_end=b_index endif if (v_start<0) v_start=0 endif if (v_end<0) v_end=0 endif if (v_start>v_rows) v_start=v_rows endif if (v_end>v_rows) v_end=v_rows endif if (v_start==v_end) w_mask[v_start]=NaN w_mask_red[v_start]=1 else for (b_index=v_start;b_index<(v_end+1);b_index+=1) w_mask[b_index]=NaN w_mask_red[b_index]=1 endfor endif break case -1: // control being killed break endswitch return 0 End //Button to unmask an region Function f_Button_Mask_1_LCM(ba) : ButtonControl STRUCT WMButtonAction &ba wave w_mask=root:Packages:LCM:w_mask wave w_mask_red=root:Packages:LCM:w_mask_red variable v_rows=dimsize(w_mask,0)-1 variable v_start variable v_end variable b_index switch( ba.eventCode ) case 2: // mouse up ControlInfo/W=LCMpanel V_B_start v_start=ScaleToIndex(w_mask,V_value,0) ControlInfo/W=LCMpanel V_B_end v_end=ScaleToIndex(w_mask,V_value,0) if (v_start>v_end) b_index=v_start v_start=v_end v_end=b_index endif if (v_start<0) v_start=0 endif if (v_end<0) v_end=0 endif if (v_start>v_rows) v_start=v_rows endif if (v_end>v_rows) v_end=v_rows endif if (v_start==v_end) w_mask[v_start]=1 w_mask_red[v_start]=NaN else for (b_index=v_start;b_index<(v_end+1);b_index+=1) w_mask[b_index]=1 w_mask_red[b_index]=NaN endfor endif break case -1: // control being killed break endswitch return 0 End function f_LCM_save_config() variable v_num_of_waves=dimsize(root:Packages:LCM:reference_waves,0) variable v_information_rows if ((v_num_of_waves+3)>9) v_information_rows=v_num_of_waves+3 else v_information_rows=9 endif variable V_value ControlInfo/W=LCMpanel popup1 //1 = no x-shift, 2 = multiple x-shift, 3 = single x-shift variable x_shift_done=V_value switch (x_shift_done) case 1: make/FREE/T/O/N=((v_information_rows),5) w_config break case 2: make/FREE/T/O/N=((v_information_rows),7) w_config w_config[0][5]="Initial x-shift" w_config[0][6]="±" break case 3: make/FREE/T/O/N=((v_information_rows),7) w_config w_config[0][5]="Initial x-shift" w_config[0][6]="±" break endswitch wave/WAVE reference_waves=root:Packages:LCM:reference_waves variable v_fitTol, v_start, v_end, v_start_energy, v_end_energy, index string s_fit_type,s_ref_waves_names ControlInfo/W=LCMpanel popup0 //1 = all-at-ones, 2 = point-by-point switch (V_value) case 1: s_fit_type="All-at-ones Fit" break case 2: s_fit_type="Point-by-point Fit" //don't use, only for testing of new funcfit functions (Point-by-point forgives more mistakes) break endswitch ControlInfo/W=LCMpanel V_FitTol v_fitTol=V_value ControlInfo/W=LCMpanel V_StartFit v_start=V_value ControlInfo/W=LCMpanel V_EndFit v_end=V_value w_config[0][0]="0" w_config[0][0]=Secs2Date(DateTime,2) w_config[1][0]=Secs2Time(DateTime,2) w_config[2][0]="Saved configuration" w_config[6][0]="FitTol: "+num2str(v_fitTol) w_config[5][0]="Scale: "+num2str(v_start)+" to "+num2str(v_end) w_config[8][0]=s_fit_type w_config[0][1]="References" w_config[0][2]="Initial Guess" w_config[0][3]="Min" w_config[0][4]="Max" for (index=0;index<(v_num_of_waves);index++) w_config[index+1][1]=GetWavesDataFolder(reference_waves[index],2) s_ref_waves_names+=nameofwave(reference_waves[index])+";" endfor string s_transfer for (index=0;index<(v_num_of_waves);index++) //print index s_transfer="V_Start_"+num2str(index) //print s_transfer ControlInfo/W=LCMpanel $s_transfer w_config[index+1][2]=num2str(V_Value) s_transfer="V_Min_"+num2str(index) //print s_transfer ControlInfo/W=LCMpanel $s_transfer w_config[index+1][3]=num2str(V_Value) s_transfer="V_Max_"+num2str(index) //print s_transfer ControlInfo/W=LCMpanel $s_transfer w_config[index+1][4]=num2str(V_Value) if (x_shift_done>1) s_transfer="V_xStart_"+num2str(index) //print s_transfer ControlInfo/W=LCMpanel $s_transfer w_config[index+1][5]=num2str(V_Value) s_transfer="V_xVar_"+num2str(index) //print s_transfer ControlInfo/W=LCMpanel $s_transfer w_config[index+1][6]=num2str(V_Value) endif endfor //print index ControlInfo/W=LCMpanel V_Start_abs w_config[v_num_of_waves+1][2]=num2str(V_Value) ControlInfo/W=LCMpanel V_Min_abs w_config[v_num_of_waves+1][3]=num2str(V_Value) ControlInfo/W=LCMpanel V_Max_abs w_config[v_num_of_waves+1][4]=num2str(V_Value) w_config[v_num_of_waves+1][1]="absolute Offset" s_ref_waves_names+="abs;" switch (x_shift_done) case 1: break case 2: w_config[8][0]+=" + Multiple x-shift analysis" break case 3: w_config[8][0]+=" + Single x-shift analysis" break endswitch string s_export for (index=1;index 1-dim. does not need MT v_rows_max=dimsize(w_sample,0) //How many rows? v_columns_max=dimsize(w_sample,1) v_layers_max=dimsize(w_sample,2) v_row_per_thread=v_rows_max //How many rows for each thread -> 1-dim.: one thread does everything break case 2: //2D (spectra = rows, positions = columns) v_rows=dimsize(w_sample_input,0) v_columns=dimsize(w_sample_input,1) make/D/N=(v_rows,1,v_columns) w_sample=0 for (l_index=0;l_index-inf&&var_min!=var_max) s_constraint+="K"+num2str(index)+" > "+num2str(var_min)+"," var_test+=1 endif if (var_max-inf&&var_min!=var_max) s_constraint+="K"+num2str(v_num_of_waves+1+index)+" > "+num2str(var_min)+"," var_test+=1 endif if (var_max-inf&&var_min!=var_max) s_constraint+="K"+num2str(v_num_of_waves+1)+" > "+num2str(var_min)+"," var_test+=1 endif if (var_max0) //print s_constraint make/D/O M_FitConstraint make/D/O W_FitConstraint switch (x_shift_done) case 1: f_constr_txt_to_matrix_MT(s_constraint,(v_num_of_waves+1)) break case 2: f_constr_txt_to_matrix_MT(s_constraint,(2*v_num_of_waves+1)) break case 3: f_constr_txt_to_matrix_MT(s_constraint,(v_num_of_waves+2)) break endswitch endif //initial values variable var_coef switch (x_shift_done) case 1: //no x-shift analysis make/D/O/N=(v_num_of_waves+1) W_coef_input for (index=0;index<(v_num_of_waves+1);index+=1) var_coef=start_val[index] if (var_coef==0) var_coef=1e-6 endif W_coef_input[index]=var_coef endfor break case 2: //x-shift analysis multiple waves make/D/O/N=(2*v_num_of_waves+1) W_coef_input for (index=0;index<(v_num_of_waves+1);index+=1) var_coef=start_val[index] if (var_coef==0) var_coef=1e-6 endif W_coef_input[index]=var_coef endfor for (index=0;index<(v_num_of_waves);index+=1) var_coef=start_x_val[index] W_coef_input[(index+(v_num_of_waves+1))]=var_coef endfor break case 3: make/D/O/N=(v_num_of_waves+2) W_coef_input for (index=0;index<(v_num_of_waves+1);index+=1) var_coef=start_val[index] if (var_coef==0) var_coef=1e-6 endif W_coef_input[index]=var_coef endfor var_coef=start_x_val[0] W_coef_input[(v_num_of_waves+1)]=var_coef break endswitch //correction of start and end values for x-shift analysis variable v_start_korr, v_end_korr variable v_shift_max_pos,v_shift_max_neg switch (x_shift_done) case 1: break case 2: //idea: if the referece is shiftet to negative values, datapoint at the highest values of the wave-to-fit are missing -> fit must ignor these datapoints for (index=0;index<(v_num_of_waves);index+=1) if (((start_x_val[index])+abs(var_x_wave[index]))>v_shift_max_pos) v_shift_max_pos=((start_x_val[index])+abs(var_x_wave[index])) endif if (((start_x_val[index]-abs(var_x_wave[index]))) v_end_korr) v_end=v_end_korr endif break case 3: v_shift_max_pos=start_x_val[0]+abs(var_x_wave[0]) v_shift_max_neg=start_x_val[0]-abs(var_x_wave[0]) //print v_shift_max_pos,v_shift_max_neg v_start_korr=dimoffset(w_sample,2)+v_shift_max_pos+dimdelta(w_sample,2) v_end_korr=(dimoffset(w_sample,2)+dimdelta(w_sample,2)*(dimsize(w_sample,2)-1))+v_shift_max_neg-dimdelta(w_sample,2) //print v_start_korr,v_end_korr if (v_start< v_start_korr) v_start=v_start_korr endif if (v_end>v_end_korr) v_end=v_end_korr endif break endswitch variable v_start_energy=v_start variable v_end_energy=v_end v_start=scaletoindex(w_mask, v_start, 0) v_end=scaletoindex(w_mask, v_end, 0) //multi-threaded work variable fitted_waves switch (x_shift_done) case 1: fitted_waves=v_num_of_waves+1 break case 2: fitted_waves=2*v_num_of_waves+1 break case 3: fitted_waves=v_num_of_waves+2 break endswitch //print "fitted waves "+num2str(fitted_waves) Variable threadGroupID= ThreadGroupCreate(v_threads) Variable threadGroupStatus,dummy //print v_rows_max //print v_lcm_type //print "var_test" //print var_test //print "v_lcm_type" //print v_lcm_type //print v_rows_max,v_columns_max,v_layers_max,v_row_per_thread,t_index,v_start,v_end,fitted_waves,v_LCM_offset,v_LCM_delta, v_fitTol, v_lcm_type, s_hold_LCM, v_inputwave_dim if (var_test>0) //only 0 is without contraints switch (v_lcm_type) case 0: //point-by-point, no x-shift for(t_index=0; t_index10) v_information_rows=v_num_of_waves+2 else v_information_rows=10 endif switch (x_shift_done) case 1: make/D/T/O/N=(v_information_rows,5) w_information break case 2: make/D/T/O/N=(v_information_rows,7) w_information break case 3: make/D/T/O/N=(v_information_rows,7) w_information break endswitch w_information[0][0]=Secs2Date(DateTime,2) w_information[1][0]=Secs2Time(DateTime,2) w_information[2][0]=GetWavesDataFolder(w_sample_input,2) if (StringMatch(note(w_sample_input),"")==0) w_information[3][0]="Note: "+note(w_sample_input) endif w_information[6][0]="FitTol: "+num2str(v_fitTol) w_information[4][0]="Points: "+num2str(v_start)+" to "+num2str(v_end) w_information[5][0]="Scale: "+num2str(v_start_energy)+" to "+num2str(v_end_energy) w_information[7][0]="\H="+s_hold_LCM w_information[8][0]=s_fit_type w_information[9][0]="LCM version "+f_LCM_version() w_information[0][1]="References" w_information[0][2]="Initial Guess" w_information[0][3]="Min" w_information[0][4]="Max" for (index=0;index<(v_num_of_waves);index++) w_information[index+1][1]=GetWavesDataFolder(reference_waves[index],2) s_ref_waves_names+=nameofwave(reference_waves[index])+";" w_information[index+1][2]=num2str(start_val[index]) w_information[index+1][3]=num2str(min_wave[index]) w_information[index+1][4]=num2str(max_wave[index]) endfor w_information[v_num_of_waves+1][1]="absolute Offset" s_ref_waves_names+="offset;" w_information[v_num_of_waves+1][2]=num2str(start_val[v_num_of_waves]) w_information[v_num_of_waves+1][3]=num2str(min_wave[v_num_of_waves]) w_information[v_num_of_waves+1][4]=num2str(max_wave[v_num_of_waves]) for (index=0;index<(v_num_of_waves);index++) if ((index==0)&&(x_shift_done==3)) s_ref_waves_names+="Single_xshift;" else s_ref_waves_names+=nameofwave(reference_waves[index])+"_xshift;" endif endfor //print s_ref_waves_names switch (x_shift_done) case 2: w_information[0][5]="Initial x-shift" w_information[0][6]="±" w_information[8][0]+=" + Multiple x-shift analysis" for (index=0;indexv_shift_max)) for (l_index=0;l_indexv_shift_max)) for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max-1 endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //print "v_rowstart: "+num2str(v_rowstart) //print "v_rowend: "+num2str(v_rowend) //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_indexv_rows_max) v_rowend=v_rows_max endif if (v_rowstart>v_rows_max) v_rowstart=v_rows_max endif if (v_rowstart>v_rowend) v_rowstart=v_rowend-1 endif if (v_rowstart==v_rowend) v_rowstart-=1 endif if (v_rowstart<0) v_rowstart=0 endif //basic waves sleep/S t_index+1 make/O w_sample_duplicate killwaves w_sample_duplicate duplicate w_sample w_sample_duplicate make/O root:reference killwaves root:reference duplicate w_references_MT root:reference variable row_index,column_index, v_fit_index, v_num_index, index, l_index make/D/O/N=(v_num_of_waves) W_coef W_coef=W_coef_input make/D/O/N=(v_num_of_waves) W_sigma make/D/N=(v_layers_max)/O tempwave make/D/N=(v_layers_max)/O tempwave2 variable v_real_waves=dimsize(w_references_MT,0) make/WAVE/O/N=(v_real_waves) listwave string s_name_ref //unpack references for (index=0; index<(v_real_waves); index+=1) make/O/N=(v_layers_max) wave0 for (l_index=0;l_index*")==1) s_replace=num2str(temporary_wave[index])+" >" tempstring=replacestring(s_replace,tempstring,"") v_read=str2num(tempstring) M_FitConstraint[v_row][temporary_wave[index]]=-1 if (v_read==0) W_FitConstraint[v_row]=v_read else W_FitConstraint[v_row]=(-1)*v_read endif else s_replace=num2str(temporary_wave[index])+" <" tempstring=replacestring(s_replace,tempstring,"") v_read=str2num(tempstring) M_FitConstraint[v_row][temporary_wave[index]]=1 W_FitConstraint[v_row]=v_read endif v_row+=1 endfor killwaves temporary_wave end function f_change_LCM_start_values(variable v_input) //change all non-offset initial guesses string s_control=ControlNameList("LCMpanel", ";", "V_start_*") variable index for (index=0;index<(ItemsInList(s_control,";")-1);index+=1) SetVariable $(StringFromList(index,s_control,";")),win=LCMpanel ,value=_NUM:v_input endfor end function f_change_LCM_min_values(variable v_input) //change all non-offset initial guesses string s_control=ControlNameList("LCMpanel", ";", "V_Min*") variable index for (index=0;index<(ItemsInList(s_control,";")-1);index+=1) SetVariable $(StringFromList(index,s_control,";")),win=LCMpanel ,value=_NUM:v_input endfor end function f_change_LCM_min_values_all(variable v_input) //change all non-offset initial guesses string s_control=ControlNameList("LCMpanel", ";", "V_Min*") variable index for (index=0;index<(ItemsInList(s_control,";"));index+=1) SetVariable $(StringFromList(index,s_control,";")),win=LCMpanel ,value=_NUM:v_input endfor end function f_change_LCM_max_values(variable v_input) //change all non-offset initial guesses string s_control=ControlNameList("LCMpanel", ";", "V_Max*") variable index for (index=0;index<(ItemsInList(s_control,";"));index+=1) SetVariable $(StringFromList(index,s_control,";")),win=LCMpanel ,value=_NUM:v_input endfor end //the fit function //normal LCM Threadsafe function f_fitFunc_lc_MT(w,x) : FitFunc Wave w Variable x wave /WAVE list=root:listwave int index, imax variable v_return=0 imax = dimsize(list,0) for (index=0;index