0001 function [wavestruct_out,flag_Zp] = wave_optim_jd(dkepath,wavestruct,select)
0002
0003
0004
0005
0006
0007
0008 wavestruct_out = wavestruct;
0009
0010 ninputs(1) = abs(wavestruct.equil.ptBPHI(1,1));
0011 ninputs(2) = wavestruct.equil.Zp;
0012
0013 if isfield(wavestruct.launch,'angles'),
0014 opt_angles = true;
0015
0016 ninputs(3) = wavestruct.launch.angles.theta;
0017 ninputs(4) = wavestruct.launch.angles.phi;
0018 else
0019 opt_angles = false;
0020
0021 ninputs(3) = pi/2 - wavestruct.launch.ybeta_L;
0022 if wavestruct.launch.yalpha_L > 0,
0023 ninputs(4) = wavestruct.launch.yalpha_L - pi;
0024 else
0025 ninputs(4) = wavestruct.launch.yalpha_L + pi;
0026 end
0027 end
0028
0029 ntargets(1) = NaN;
0030 ntargets(2) = NaN;
0031 ntargets(3) = NaN;
0032
0033 wavestruct.waveparam.nd = 1;
0034 wavestruct.waveparam.nchi = 1;
0035
0036 set(select.busyhandle,'Visible','on');drawnow;
0037
0038 wavestruct.equil_fit = fitequil_yp(wavestruct.equil,wavestruct.fitparam.mode_equil,wavestruct.fitparam.method,wavestruct.fitparam.ngridresample,wavestruct.fitparam.nharm);
0039
0040 set(select.busyhandle,'Visible','off');drawnow;
0041
0042 if isfield(select,'style'),
0043 style = select.style;
0044 else
0045 style = struct;
0046 end
0047
0048 if isfield(select,'opt_gui'),
0049
0050 if ishandle(select.opt_gui),
0051
0052 panelposition = get(select.opt_gui,'Position');
0053
0054 columnwidth = (panelposition(3) - 4*style.panelsep - 2*style.buthsep - style.longbutwidth)/2;
0055 columnheight = 6*style.butvsep + 4*style.butheight;
0056
0057 info.position = [style.panelsep,2*style.panelsep + columnheight,panelposition(3) - 2*style.panelsep,panelposition(4) - columnheight - 3*style.panelsep];
0058
0059 inputs.position = [style.panelsep,style.panelsep,columnwidth,columnheight];
0060 targets.position = [2*style.panelsep + columnwidth,style.panelsep,columnwidth,columnheight];
0061 controls.position = [3*style.panelsep + 2*columnwidth,style.panelsep,2*style.buthsep + style.longbutwidth,columnheight];
0062
0063 infostr = {...
0064 ' --------------------------------------------------------',...
0065 ' ECRH optimization with C3PO ',...
0066 ' --------------------------------------------------------',...
0067 ' The magnetic field prescription is simulated by changing the wave frequency.',...
0068 ' Only the central ray is used for optimization. Do not pay attention to deposition width.',...
0069 ' Warning : if Zp is modified, all other wavestructs and waves will be deleted.',...
0070 ' - When all inputs are specified, you can press ''Run'' to calculate the deposition',...
0071 ' - Otherwise, press ''Optimize'' to calculate the missing parameters',...
0072 ' - The total number of specified (not empty) input and target parameters must always be 4',...
0073 ' - Press ''Return'' to return optimized parameters to C3PO console',...
0074 ' '};
0075
0076 infostr2 = {...
0077 ' ',...
0078 ' ',...
0079 ' ',...
0080 ' ',...
0081 ' ',...
0082 ' ',...
0083 ' - The total number of specified (not empty) input and target parameters must always be 4'};
0084
0085 infostr3 = {...
0086 ' ',...
0087 ' ',...
0088 ' ',...
0089 ' ',...
0090 ' ',...
0091 ' ',...
0092 ' - The wave did not enter the plasma. Modify input parameters'};
0093
0094 inputs.string = 'Input parameters';
0095 targets.string = 'Deposition target';
0096 controls.string = 'Controls';
0097
0098 inputs.bt.title.string = 'Bt [T] (on axis)';
0099 inputs.zp.title.string = 'Zp [m]';
0100 if opt_angles,
0101 inputs.theta.title.string = 'theta_L [deg]';
0102 inputs.phi.title.string = 'phi_L [deg]';
0103 else
0104 inputs.theta.title.string = 'pol. angle [deg]';
0105 inputs.phi.title.string = 'tor. angle [deg]';
0106 end
0107
0108 inputs.bt.clear.string = 'Clear';
0109 inputs.zp.clear.string = 'Clear';
0110 inputs.theta.clear.string = 'Clear';
0111 inputs.phi.clear.string ='Clear';
0112
0113 inputs.bt.reset.string = 'Reset';
0114 inputs.zp.reset.string = 'Reset';
0115 inputs.theta.reset.string = 'Reset';
0116 inputs.phi.reset.string ='Reset';
0117
0118
0119 targets.rho.title.string = 'r/a (psiP)';
0120 targets.theta.title.string = 'theta [deg]';
0121 targets.npar.title.string = 'n//';
0122
0123
0124 targets.rho.val.string = '';
0125 targets.theta.val.string = '';
0126 targets.npar.val.string = '';
0127
0128
0129 targets.rho.clear.string = 'Clear';
0130 targets.theta.clear.string = 'Clear';
0131 targets.npar.clear.string ='Clear';
0132
0133
0134 targets.rho.reset.string = 'Reset';
0135 targets.theta.reset.string = 'Reset';
0136 targets.npar.reset.string ='Reset';
0137
0138 run.string = 'Run';
0139
0140 optim.string = 'Optimize';
0141 finish.string = 'Return';
0142
0143 inputs.bt.title.position = [style.buthsep,4*style.butvsep + 3*style.butheight + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0144 inputs.bt.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,4*style.butvsep + 3*style.butheight,style.butwidth,style.butheight];
0145 inputs.bt.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,4*style.butvsep + 3*style.butheight,style.butwidth,style.butheight];
0146 inputs.bt.reset.position = [columnwidth - style.buthsep - style.butwidth,4*style.butvsep + 3*style.butheight,style.butwidth,style.butheight];
0147
0148 inputs.zp.title.position = [style.buthsep,3*style.butvsep + 2*style.butheight + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0149 inputs.zp.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0150 inputs.zp.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0151 inputs.zp.reset.position = [columnwidth - style.buthsep - style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0152
0153 inputs.theta.title.position = [style.buthsep,2*style.butvsep + style.butheight + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0154 inputs.theta.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0155 inputs.theta.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0156 inputs.theta.reset.position = [columnwidth - style.buthsep - style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0157
0158 inputs.phi.title.position = [style.buthsep,style.butvsep + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0159 inputs.phi.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,style.butvsep,style.butwidth,style.butheight];
0160 inputs.phi.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,style.butvsep,style.butwidth,style.butheight];
0161 inputs.phi.reset.position = [columnwidth - style.buthsep - style.butwidth,style.butvsep,style.butwidth,style.butheight];
0162
0163
0164
0165
0166
0167
0168
0169 targets.rho.title.position = [style.buthsep,3*style.butvsep + 2*style.butheight + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0170 targets.rho.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0171 targets.rho.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0172 targets.rho.reset.position = [columnwidth - style.buthsep - style.butwidth,3*style.butvsep + 2*style.butheight,style.butwidth,style.butheight];
0173
0174 targets.theta.title.position = [style.buthsep,2*style.butvsep + style.butheight + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0175 targets.theta.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0176 targets.theta.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0177 targets.theta.reset.position = [columnwidth - style.buthsep - style.butwidth,2*style.butvsep + style.butheight,style.butwidth,style.butheight];
0178
0179 targets.npar.title.position = [style.buthsep,style.butvsep + style.textheightcorr,columnwidth - 5*style.buthsep - 2*style.butwidth - style.butwidth,style.butheight];
0180 targets.npar.val.position = [columnwidth - 3*style.buthsep - 2*style.butwidth - style.butwidth,style.butvsep,style.butwidth,style.butheight];
0181 targets.npar.clear.position = [columnwidth - 2*style.buthsep - 2*style.butwidth,style.butvsep,style.butwidth,style.butheight];
0182 targets.npar.reset.position = [columnwidth - style.buthsep - style.butwidth,style.butvsep,style.butwidth,style.butheight];
0183
0184
0185 run.position = [style.buthsep,4*style.butvsep + 3*style.butheight,style.longbutwidth,style.butheight];
0186
0187
0188 optim.position = [style.buthsep,3*style.butvsep + 2*style.butheight,style.longbutwidth,style.butheight];
0189 finish.position = [style.buthsep,style.butvsep,style.longbutwidth,style.butheight];
0190
0191
0192
0193 inputs.handle = uipanel('Parent',select.opt_gui,'Title',inputs.string,'units','pixels','Position',inputs.position);
0194 targets.handle = uipanel('Parent',select.opt_gui,'Title',targets.string,'units','pixels','Position',targets.position);
0195 controls.handle = uipanel('Parent',select.opt_gui,'Title',controls.string,'units','pixels','Position',controls.position);
0196 info.handle = uicontrol(select.opt_gui,'Style','text','String',infostr,'Position',info.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0197
0198 inputs.bt.title.handle = uicontrol(inputs.handle,'Style','text','String',inputs.bt.title.string,'Position',inputs.bt.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0199 inputs.zp.title.handle = uicontrol(inputs.handle,'Style','text','String',inputs.zp.title.string,'Position',inputs.zp.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0200 inputs.theta.title.handle = uicontrol(inputs.handle,'Style','text','String',inputs.theta.title.string,'Position',inputs.theta.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0201 inputs.phi.title.handle = uicontrol(inputs.handle,'Style','text','String',inputs.phi.title.string,'Position',inputs.phi.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0202
0203 inputs.bt.val.handle = uicontrol(inputs.handle,'Style','edit','Position',inputs.bt.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0204 inputs.zp.val.handle = uicontrol(inputs.handle,'Style','edit','Position',inputs.zp.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0205 inputs.theta.val.handle = uicontrol(inputs.handle,'Style','edit','Position',inputs.theta.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0206 inputs.phi.val.handle = uicontrol(inputs.handle,'Style','edit','Position',inputs.phi.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0207
0208 inputs.bt.clear.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.bt.clear.string,'Position',inputs.bt.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0209 inputs.zp.clear.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.zp.clear.string,'Position',inputs.zp.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0210 inputs.theta.clear.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.theta.clear.string,'Position',inputs.theta.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0211 inputs.phi.clear.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.phi.clear.string,'Position',inputs.phi.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0212
0213 inputs.bt.reset.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.bt.reset.string,'Position',inputs.bt.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0214 inputs.zp.reset.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.zp.reset.string,'Position',inputs.zp.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0215 inputs.theta.reset.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.theta.reset.string,'Position',inputs.theta.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0216 inputs.phi.reset.handle = uicontrol(inputs.handle,'Style','pushbutton','String',inputs.phi.reset.string,'Position',inputs.phi.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0217
0218
0219 targets.rho.title.handle = uicontrol(targets.handle,'Style','text','String',targets.rho.title.string,'Position',targets.rho.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0220 targets.theta.title.handle = uicontrol(targets.handle,'Style','text','String',targets.theta.title.string,'Position',targets.theta.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0221 targets.npar.title.handle = uicontrol(targets.handle,'Style','text','String',targets.npar.title.string,'Position',targets.npar.title.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left');
0222
0223
0224 targets.rho.val.handle = uicontrol(targets.handle,'Style','edit','Position',targets.rho.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0225 targets.theta.val.handle = uicontrol(targets.handle,'Style','edit','Position',targets.theta.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0226 targets.npar.val.handle = uicontrol(targets.handle,'Style','edit','Position',targets.npar.val.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'HorizontalAlignment','left','Callback',@setval_cbf);
0227
0228
0229 targets.rho.clear.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.rho.clear.string,'Position',targets.rho.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0230 targets.theta.clear.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.theta.clear.string,'Position',targets.theta.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0231 targets.npar.clear.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.npar.clear.string,'Position',targets.npar.clear.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0232
0233
0234 targets.rho.reset.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.rho.reset.string,'Position',targets.rho.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0235 targets.theta.reset.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.theta.reset.string,'Position',targets.theta.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0236 targets.npar.reset.handle = uicontrol(targets.handle,'Style','pushbutton','String',targets.npar.reset.string,'Position',targets.npar.reset.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@setval_cbf);
0237
0238 run.handle = uicontrol(controls.handle,'Style','pushbutton','String',run.string,'Position',run.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@pushbutton_cbf);
0239
0240 optim.handle = uicontrol(controls.handle,'Style','pushbutton','String',optim.string,'Position',optim.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@pushbutton_cbf);
0241 finish.handle = uicontrol(controls.handle,'Style','pushbutton','String',finish.string,'Position',finish.position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Callback',@pushbutton_cbf);
0242
0243 inputs.handles = [inputs.bt.val.handle,inputs.zp.val.handle,inputs.theta.val.handle,inputs.phi.val.handle];
0244 targets.handles = [targets.rho.val.handle,targets.theta.val.handle,targets.npar.val.handle];
0245
0246 inputs.clearhandles = [inputs.bt.clear.handle,inputs.zp.clear.handle,inputs.theta.clear.handle,inputs.phi.clear.handle];
0247 inputs.resethandles = [inputs.bt.reset.handle,inputs.zp.reset.handle,inputs.theta.reset.handle,inputs.phi.reset.handle];
0248 targets.clearhandles = [targets.rho.clear.handle,targets.theta.clear.handle,targets.npar.clear.handle];
0249 targets.resethandles = [targets.rho.reset.handle,targets.theta.reset.handle,targets.npar.reset.handle];
0250
0251 opt_info = true;
0252
0253 else
0254 opt_gui = true;
0255 opt_info = false;
0256 end
0257 else
0258 opt_gui = false;
0259 opt_info = false;
0260 end
0261
0262 exit_loop = 0;
0263 optim_done = 0;
0264
0265 optim.tolfun = 1e-3;
0266 optim.tolx = 1e-3;
0267 optim.nitmax = 20;
0268
0269 inputs.resetval = cell(1,length(inputs.resethandles));
0270 targets.resetval = cell(1,length(targets.resethandles));
0271
0272 while exit_loop == 0,
0273
0274 if ~any(isnan(ninputs)),
0275
0276 ninputs_init = ninputs;
0277
0278 set(finish.handle,'Enable','on');
0279 set(run.handle,'Enable','on');
0280 if optim_done == 1,
0281 set(finish.handle,'BackgroundColor',[0 0.75 0]);
0282 set(run.handle,'BackgroundColor',[0.701961 0.701961 0.701961]);
0283 else
0284 set(finish.handle,'BackgroundColor',[0.701961 0.701961 0.701961]);
0285 set(run.handle,'BackgroundColor',[0 0.75 0]);
0286 end
0287 set(optim.handle,'Enable','off','BackgroundColor',[0.701961 0.701961 0.701961]);
0288 else
0289 set(finish.handle,'Enable','off','BackgroundColor',[0.701961 0.701961 0.701961]);
0290 set(run.handle,'Enable','off','BackgroundColor',[0.701961 0.701961 0.701961]);
0291
0292 if sum(isnan(ninputs)) + sum(isnan(ntargets)) == 3,
0293 set(optim.handle,'Enable','on','BackgroundColor',[0 0.75 0]);
0294
0295 set(info.handle,'String',infostr,'Fontweight','normal');
0296 else
0297 set(optim.handle,'Enable','off','BackgroundColor',[0.701961 0.701961 0.701961]);
0298
0299 set(info.handle,'String',infostr2,'Fontweight','bold');
0300 end
0301
0302 end
0303
0304 for ihandle = 1:length(inputs.handles),
0305 if isnan(ninputs(ihandle)),
0306 set(inputs.clearhandles(ihandle),'Enable','off');
0307 if ~isempty(inputs.resetval{ihandle}),
0308 set(inputs.resethandles(ihandle),'Enable','on');
0309 else
0310 set(inputs.resethandles(ihandle),'Enable','off');
0311 end
0312 else
0313 set(inputs.clearhandles(ihandle),'Enable','on');
0314 set(inputs.resethandles(ihandle),'Enable','off');
0315 end
0316 end
0317
0318 for ihandle = 1:length(targets.handles),
0319 if isnan(ntargets(ihandle)),
0320 set(targets.clearhandles(ihandle),'Enable','off');
0321 if ~isempty(targets.resetval{ihandle}),
0322 set(targets.resethandles(ihandle),'Enable','on');
0323 else
0324 set(targets.resethandles(ihandle),'Enable','off');
0325 end
0326 else
0327 set(targets.clearhandles(ihandle),'Enable','on');
0328 set(targets.resethandles(ihandle),'Enable','off');
0329 end
0330 end
0331
0332 set(inputs.bt.val.handle,'String',num2str(ninputs(1*find(~isnan(ninputs(1))))));
0333 set(inputs.zp.val.handle,'String',num2str(ninputs(2*find(~isnan(ninputs(2))))));
0334 set(inputs.theta.val.handle,'String',num2str(180/pi*ninputs(3*find(~isnan(ninputs(3))))));
0335 set(inputs.phi.val.handle,'String',num2str(180/pi*ninputs(4*find(~isnan(ninputs(4))))));
0336
0337 set(targets.rho.val.handle,'String',num2str(ntargets(1*find(~isnan(ntargets(1))))));
0338 set(targets.theta.val.handle,'String',num2str(180/pi*ntargets(2*find(~isnan(ntargets(2))))));
0339 set(targets.npar.val.handle,'String',num2str(ntargets(3*find(~isnan(ntargets(3))))));
0340
0341 uiwait;
0342
0343 end
0344
0345 if wavestruct_out.equil.Zp ~= ninputs(2),
0346 wavestruct_out.equil.Zp = ninputs(2);
0347 flag_Zp = true;
0348 else
0349 flag_Zp = false;
0350 end
0351
0352 if opt_angles,
0353 wavestruct_out.launch.angles.freq = wavestruct_out.launch.angles.freq*abs(wavestruct_out.equil.ptBPHI(1,1))/ninputs(1);
0354 wavestruct_out.launch.angles.theta = ninputs(3);
0355 wavestruct_out.launch.angles.phi = ninputs(4);
0356
0357 wavestruct_out.launch = imake_launch_angles_TCV_jd(wavestruct_out.launch.angles);
0358 else
0359 wavestruct_out.launch.omega_rf = wavestruct_out.launch.omega_rf*abs(wavestruct_out.equil.ptBPHI(1,1))/ninputs(1);
0360 wavestruct_out.launch.ybeta_L = pi/2 - ninputs(3);
0361 if ninputs(4) > 0,
0362 wavestruct_out.launch.yalpha_L = ninputs(4) - pi;
0363 else
0364 wavestruct_out.launch.yalpha_L = ninputs(4) + pi;
0365 end
0366 end
0367
0368 if opt_info,
0369 delete(inputs.handle);
0370 delete(targets.handle);
0371 delete(controls.handle);
0372 delete(info.handle);
0373
0374 delete(select.opt.axs(1))
0375 delete(select.opt.axs(2))
0376 delete(select.opt.axs(3))
0377 end
0378
0379 function setval_cbf(hObject,eventdata)
0380
0381 optim_done = 0;
0382
0383 if any(hObject == inputs.clearhandles),
0384 hObject = inputs.handles(hObject == inputs.clearhandles);
0385 inputs.resetval{hObject == inputs.handles} = get(hObject,'String');
0386 set(hObject,'String','');
0387 elseif any(hObject == targets.clearhandles),
0388 hObject = targets.handles(hObject == targets.clearhandles);
0389 targets.resetval{hObject == targets.handles} = get(hObject,'String');
0390 set(hObject,'String','');
0391 elseif any(hObject == inputs.resethandles),
0392 hObject = inputs.handles(hObject == inputs.resethandles);
0393 set(hObject,'String',inputs.resetval{hObject == inputs.handles});
0394 elseif any(hObject == targets.resethandles),
0395 hObject = targets.handles(hObject == targets.resethandles);
0396 set(hObject,'String',targets.resetval{hObject == targets.handles});
0397 end
0398
0399 if any(hObject == inputs.handles),
0400 if any(hObject == inputs.handles(3:4)),
0401 ninputs(hObject == inputs.handles) = pi/180*str2double(get(hObject,'String'));
0402 else
0403 ninputs(hObject == inputs.handles) = str2double(get(hObject,'String'));
0404 end
0405 elseif any(hObject == targets.handles),
0406 if hObject == targets.handles(2),
0407 ntargets(hObject == targets.handles) = pi/180*str2double(get(hObject,'String'));
0408 else
0409 ntargets(hObject == targets.handles) = str2double(get(hObject,'String'));
0410 end
0411 end
0412
0413 uiresume;
0414
0415 end
0416
0417 function pushbutton_cbf(hObject,eventdata)
0418
0419 set(info.handle,'String',infostr,'Fontweight','normal');
0420
0421 cla(select.opt.axs(1));
0422 cla(select.opt.axs(2));
0423 cla(select.opt.axs(3));
0424
0425 wave = [];
0426
0427 optim_done = 0;
0428
0429 if hObject == finish.handle,
0430
0431 exit_loop = 1;
0432
0433 elseif hObject == run.handle,
0434
0435 set(select.busyhandle,'Visible','on');drawnow;
0436
0437 [~,wave] = calc_delta_jd([],ninputs,[],dkepath,wavestruct,opt_angles);
0438
0439 set(select.busyhandle,'Visible','off');drawnow;
0440
0441 if isempty(wave),
0442 set(info.handle,'String',infostr3,'Fontweight','bold');
0443 end
0444
0445 elseif hObject == optim.handle,
0446
0447 ninputs_mask = isnan(ninputs);
0448
0449 set(select.busyhandle,'Visible','on');drawnow;
0450
0451 [Xopt,delta] = fminsearch(@(X) calc_delta_jd(X,ninputs,ntargets,dkepath,wavestruct,opt_angles),ninputs_init(ninputs_mask),...
0452 optimset('TolFun',optim.tolfun,'TolX',optim.tolx,'MaxIter',optim.nitmax));
0453
0454 set(select.busyhandle,'Visible','off');drawnow;
0455
0456 ninputs(ninputs_mask) = Xopt;
0457
0458 [~,wave] = calc_delta_jd([],ninputs,[],dkepath,wavestruct,opt_angles);
0459
0460 optim_done = 1;
0461
0462 end
0463
0464 if ~isempty(wave),
0465
0466
0467
0468
0469 [~,ntargets] = delta_wave_optim_jd(wave,wavestruct.equil_fit,[]);
0470
0471 graph_wave_jd(wavestruct.equil,{wave},select.opt.nr_dep,select.opt,select.opt.rho_disp,select.opt.ymask,select.opt.xvar);
0472
0473 end
0474
0475 uiresume;
0476
0477 end
0478
0479 end
0480
0481 function [delta,wave] = calc_delta_jd(X,ninputs,ntargets,dkepath,wavestruct,opt_angles)
0482
0483 ninputs_mask = isnan(ninputs);
0484
0485 ninputs(ninputs_mask) = X;
0486
0487 wavestruct.equil.Zp = ninputs(2);
0488 wavestruct.equil_fit.Zp = ninputs(2);
0489
0490 if opt_angles,
0491 wavestruct.launch.angles.freq = wavestruct.launch.angles.freq*abs(wavestruct.equil.ptBPHI(1,1))/ninputs(1);
0492 wavestruct.launch.angles.theta = ninputs(3);
0493 wavestruct.launch.angles.phi = ninputs(4);
0494
0495 wavestruct.launch = imake_launch_angles_TCV_jd(wavestruct.launch.angles);
0496 else
0497 wavestruct.launch.omega_rf = wavestruct.launch.omega_rf*abs(wavestruct.equil.ptBPHI(1,1))/ninputs(1);
0498 wavestruct.launch.ybeta_L = pi/2 - ninputs(3);
0499 if ninputs(4) > 0,
0500 wavestruct.launch.yalpha_L = ninputs(4) - pi;
0501 else
0502 wavestruct.launch.yalpha_L = ninputs(4) + pi;
0503 end
0504 end
0505
0506 wave = wave_solver_yp(dkepath,wavestruct,[]);
0507
0508 if isempty(wave.rays),
0509 wave = [];
0510 delta = 1;
0511 else
0512
0513 if ~isempty(ntargets),
0514 delta = delta_wave_optim_jd(wave,wavestruct.equil_fit,ntargets);
0515
0516 disp(' ');
0517 disp(['---> delta : ',num2str(delta),' ; norm(X) : ',num2str(norm(X))]);
0518
0519 else
0520 delta = [];
0521 end
0522 end
0523
0524 end
0525