Guest User

Untitled

a guest
Apr 1st, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.29 KB | None | 0 0
  1. function fm_plot(flag)
  2. % FM_PLOT plot results of Continuation Power Flow,
  3. % Optimal Power Flow and Time Domain
  4. % Simulations.
  5. %
  6. % FM_PLOT(FLAG)
  7. % FLAG 0 -> create variable list
  8. % 1 -> plot selected variables
  9. % 2 -> save graph
  10. % 3 -> set layout
  11. %
  12. %Author: Federico Milano
  13. %Date: 11-Nov-2002
  14. %Update: 25-Feb-2003
  15. %Update: 26-Jan-2005
  16. %Version: 1.0.2
  17. %
  18. %E-mail: federico.milano@ucd.ie
  19. %Web-site: faraday1.ucd.ie/psat.html
  20. %
  21. % Copyright (C) 2002-2019 Federico Milano
  22.  
  23. global DAE Bus Syn Settings Fig Snapshot Hdl CPF Theme
  24. global Varout Varname Path File OPF Line Mass SSR Pmu
  25.  
  26. %hdls = get(Fig.plot, 'Children')
  27. %display(hdls)
  28.  
  29. hdlfig = findobj(Fig.plot, 'Tag','Axes1');
  30. hdlfig2 = findobj(Fig.plot, 'Tag','Axes2');
  31. Hdl_grid = findobj(Fig.plot,'Tag','Checkbox1');
  32. Hdl_legend = findobj(Fig.plot,'Tag','Checkbox2');
  33. Hdl_listvar = findobj(Fig.plot,'Tag','Listbox1');
  34. Hdl_listplot = findobj(Fig.plot,'Tag','Listbox2');
  35. Hdl_tipoplot = findobj(Fig.plot,'Tag','PopupMenu1');
  36. Hdl_angref = findobj(Fig.plot,'Tag','PopupMenu2');
  37. Hdl_snap = findobj(Fig.plot,'Tag','Radiobutton1');
  38. hdl_zoom1 = findobj(Fig.plot,'Tag','Pushbutton12');
  39. hdl_zoom2 = findobj(Fig.plot,'Tag','Pushbutton11');
  40. hdl_zoom3 = findobj(Fig.plot,'Tag','Pushbutton4');
  41. hdl_x = findobj(Fig.plot,'Tag','Pushbutton9');
  42. hdl_y = findobj(Fig.plot,'Tag','Pushbutton5');
  43. hdl_xy = findobj(Fig.plot,'Tag','Pushbutton10');
  44.  
  45. switch flag
  46. case 'exporttext', % output data as plain text file
  47. flag = 'plotvars';
  48. out_matlab = 0;
  49. out_mtv = 0;
  50. out_text = 1;
  51. case 'exportmtv', % output data as plain text file
  52. flag = 'plotvars';
  53. out_matlab = 0;
  54. out_mtv = 1;
  55. out_text = 0;
  56. case 'exportscript', % output data as plain text file
  57. flag = 'plotvars';
  58. out_matlab = 1;
  59. out_mtv = 0;
  60. out_text = 0;
  61. otherwise
  62. out_matlab = 0;
  63. out_mtv = 0;
  64. out_text = 0;
  65. end
  66.  
  67. switch flag
  68.  
  69. case 'initlist'
  70.  
  71. if ~strcmp(get(Fig.plot,'UserData'),File.modify)
  72. set(Hdl_listvar, ...
  73. 'String',enum(Varname.uvars(Varout.idx)), ...
  74. 'Value',1);
  75. if Settings.hostver < 8.04
  76. set(Fig.plot,'DefaultAxesColorOrder',Settings.color, ...
  77. 'DefaultAxesLineStyle','-');
  78. end
  79. end
  80. set(Fig.plot,'UserData',File.modify)
  81. Varname.pos = 1;
  82.  
  83. case 'initxlabel'
  84.  
  85. first = strrep(Settings.xlabel,'\','');
  86. hdl = findobj(Fig.plot,'Tag','Listbox1');
  87. stringa = get(hdl,'String');
  88. hdl = findobj(Fig.plot,'Tag','PopupMenu3');
  89. if ~isempty(stringa)
  90. set(hdl,'String',[{first}; stringa],'Enable','on','Value',1)
  91. end
  92.  
  93. case 'plotvars'
  94.  
  95. if isempty(Varout.t)
  96. fm_disp('Plotting Utilities: No data available for plotting.')
  97. return
  98. end
  99.  
  100. if isempty(Varname.pos)
  101. fm_disp('Plotting Utilities: Select variables to be plotted.')
  102. return
  103. end
  104.  
  105. nB = Bus.n;
  106. nD = DAE.n;
  107.  
  108. Value = get(Hdl_listvar,'Value');
  109. if isempty(Value), return, end
  110. hdlfig = findobj(Fig.plot, 'Tag', 'Axes1');
  111. AxesFont = get(hdlfig,'FontName');
  112. %AxesColor = get(hdlfig,'Color');
  113. %if ~length(AxesColor)
  114. AxesColor = [1, 1, 1];
  115. %end
  116. AxesWeight = get(hdlfig,'FontWeight');
  117. AxesAngle = get(hdlfig,'FontAngle');
  118. AxesSize = get(hdlfig,'FontSize');
  119. AxesUnits = get(hdlfig,'FontUnits');
  120.  
  121. plot_snap = get(Hdl_snap,'Value');
  122. snap_idx = zeros(length(Snapshot),1);
  123. if plot_snap && ~OPF.init
  124. for i = 1:length(Snapshot);
  125. a = find(Varout.t == Snapshot(i).time);
  126. if isempty(a)
  127. fm_disp('Plotting utilities: Snapshots do not match current simulation data',2)
  128. Hdl_rad1 = findobj(gcf,'Tag','Radiobutton1');
  129. set(Hdl_rad1,'Value',0);
  130. plot_snap = 0;
  131. break
  132. else
  133. snap_idx(i) = a;
  134. end
  135. end
  136. end
  137.  
  138. legenda = Varname.fvars(Varout.idx(Value(Varname.pos)));
  139. leg_value = get(Hdl_legend,'Value');
  140.  
  141. hdlab = findobj(Fig.plot,'Tag','PopupMenu3');
  142. AbValue = get(hdlab,'Value');
  143.  
  144. Y = Varout.vars(:,Value);
  145. if isempty(Y), return, end
  146.  
  147. % set angle unit
  148. if Settings.usedegree
  149. kdx = get_angle_idx(Value);
  150. Y(:,kdx) = 180*Y(:,kdx)/pi;
  151. end
  152.  
  153. % set rotor speed unit and values
  154. if Settings.usehertz || Settings.userelspeed
  155. kdx = get_rotor_idx(Value);
  156. if Settings.userelspeed
  157. Y(:,kdx) = Y(:,kdx)-1;
  158. end
  159. if Settings.usehertz
  160. Y(:,kdx) = Settings.freq*Y(:,kdx);
  161. end
  162. end
  163.  
  164. % set reference angle
  165. if ~OPF.init
  166. ang_idx = get(Hdl_angref,'Value')-1;
  167. if ~ang_idx
  168. angolo = zeros(length(Varout.t),1);
  169. else
  170. ref_idx = get(Hdl_angref,'UserData');
  171. ang_ref = ref_idx(ang_idx);
  172. angolo = Varout.vars(:,ang_ref);
  173. end
  174. for i = 1:length(Value)
  175. kk = Varout.idx(Value(i));
  176. if isdelta(Syn,kk) || isdelta(Mass,kk) || isdelta(SSR,kk) || isdelta(Pmu,kk)
  177. Y(:,i) = Y(:,i) - angolo;
  178. elseif kk >= nD+1 && kk <= nD+nB
  179. Y(:,i) = Y(:,i) - angolo;
  180. end
  181. end
  182. end
  183.  
  184. hdlnorm = findobj(Fig.plot,'Tag','NormSij');
  185. if strcmp(get(hdlnorm,'Checked'),'on')
  186. for i = 1:length(Value)
  187. kk = Varout.idx(Value(i));
  188. Y(:,i) = isflow(Line,Y(:,i),kk);
  189. end
  190. end
  191.  
  192. if AbValue == 1
  193. X = Varout.t;
  194. else
  195. X = Varout.vars(:,AbValue-1);
  196. % set angle unit
  197. check = get_angle_idx(AbValue-1);
  198. if Settings.usedegree && ~isempty(check)
  199. X = 180*X/pi;
  200. end
  201. % set rotor speed unit and values
  202. if Settings.usehertz || Settings.userelspeed
  203. check = get_rotor_idx(AbValue-1);
  204. if Settings.userelspeed && check
  205. X = X-1;
  206. end
  207. if Settings.usehertz && check
  208. X = Settings.freq*X;
  209. end
  210. end
  211. end
  212.  
  213. tipoplot = get(Hdl_tipoplot,'Value');
  214.  
  215. if out_text
  216. plainfile = fm_filenum('txt');
  217. fid = fopen([Path.data,plainfile,'.txt'],'wt');
  218. if fid == -1
  219. fm_disp('Cannot open file. Data not saved.')
  220. return
  221. end
  222. fprintf(fid,'C Legend:\n');
  223. fprintf(fid,'C %s, ',Settings.xlabel);
  224. for i = 1:size(Y,2)
  225. fprintf(fid,'%s, ',legenda{i});
  226. end
  227. fprintf(fid,'\nC Data:\n');
  228. fprintf(fid,[repmat('%8.5f ',1,1+size(Y,2)),'\n'],[X,Y]');
  229. fclose(fid);
  230. fm_disp(['Data exported to plain text file "',plainfile,'.txt"'])
  231. end
  232.  
  233. if out_mtv
  234. plainfile = fm_filenum('mtv');
  235. fid = fopen([Path.data,plainfile,'.mtv'],'wt');
  236. if fid == -1
  237. fm_disp('Cannot open file. Data not saved.')
  238. return
  239. end
  240. %fprintf(fid,'$ DATA=CURVE2D\n');
  241. fprintf(fid,'%% xlabel = "%s"\n',Settings.xlabel);
  242. if min(X) < max(X)
  243. fprintf(fid,'%% xmin = %8.5f\n',min(X));
  244. fprintf(fid,'%% xmax = %8.5f\n',max(X));
  245. end
  246. fprintf(fid,'\n');
  247. if tipoplot == 3 || tipoplot == 6
  248. fm_disp('MTV format does not support numbered plots.')
  249. end
  250.  
  251. for i = 1:size(Y,2)
  252. labelmtv = strrep(legenda{i},'{','');
  253. labelmtv = strrep(labelmtv,'}','');
  254. labelmtv = strrep(labelmtv,'_',' ');
  255. labelmtv = strrep(labelmtv,'\','');
  256. fprintf(fid,'%% linelabel="%s"\n',labelmtv);
  257. switch tipoplot
  258. case 2
  259. linetype = rem(i-1,10)+1;
  260. linecolor = 1;
  261. markertype = 0;
  262. markercolor = 1;
  263. case 4
  264. linetype = 1;
  265. linecolor = 1;
  266. markertype = rem(i-1,13)+1;
  267. markercolor = 1;
  268. case 5
  269. linetype = 1;
  270. linecolor = rem(i-1,10)+1;
  271. markertype = rem(i-1,13)+1;
  272. markercolor = linecolor;
  273. otherwise
  274. linetype = 1;
  275. linecolor = rem(i-1,10)+1;
  276. markertype = 0;
  277. markercolor = 1;
  278. end
  279. fprintf(fid,'%% linetype=%d linecolor=%d markertype=%d markercolor=%d\n', ...
  280. linetype,linecolor,markertype,markercolor);
  281. fprintf(fid,'%8.5f %8.5f\n',[X,Y(:,i)]');
  282. fprintf(fid,'\n');
  283. end
  284.  
  285. fclose(fid);
  286. fm_disp(['Data exported to MTV plot file "',plainfile,'.mtv"'])
  287. end
  288.  
  289. if out_matlab
  290. plainfile = fm_filenum('m');
  291. fid = fopen([Path.data,plainfile,'.m'],'wt');
  292. if fid == -1
  293. fm_disp('Cannot open file. Data not saved.')
  294. return
  295. end
  296. fprintf(fid,'x_label = ''%s'';\n',Settings.xlabel);
  297. fprintf(fid,'\nvar_legend = {');
  298. for i = 1:size(Y,2)-1
  299. fprintf(fid,'''%s'', ',legenda{i});
  300. end
  301. fprintf(fid,'''%s''};\n',legenda{end});
  302. fprintf(fid,'\noutput_data = [ ...\n');
  303. fprintf(fid,[repmat('%8.5f ',1,1+size(Y,2)),';\n'], ...
  304. [X(1:end-1),Y(1:end-1,:)]');
  305. fprintf(fid,[repmat('%8.5f ',1,1+size(Y,2)),'];\n'], ...
  306. [X(end),Y(end,:)]');
  307. fclose(fid);
  308. fm_disp(['Data exported to plain text file "',plainfile,'.m"'])
  309. end
  310.  
  311. set(Fig.plot,'CurrentAxes',hdlfig);
  312. plot(X,Y(:,Varname.pos));
  313. set(hdlfig, 'Tag', 'Axes1')
  314.  
  315. if AbValue == 1
  316. xlabel(Settings.xlabel);
  317. else
  318. xlabel(Varname.fvars{Varout.idx(AbValue-1)});
  319. end
  320. if min(X) < max(X)
  321. set(hdlfig,'XLim',[min(X),max(X)])
  322. end
  323.  
  324. %legend
  325. if leg_value == 1 || Settings.hostver >= 7
  326. if Settings.hostver >= 8.04
  327. hleg = legend(legenda, 'Location', 'northeast');
  328. else
  329. hleg = legend(legenda, 0);
  330. end
  331. Hdl.legend = hleg;
  332. set(hleg,'Color',AxesColor)
  333. hchild = get(hleg,'Child');
  334. if ishandle(hchild)
  335. set(hchild(end), ...
  336. 'FontName',AxesFont, ...
  337. 'FontWeight',AxesWeight, ...
  338. 'FontAngle',AxesAngle)
  339. end
  340. end
  341.  
  342. hdlfig = findobj(Fig.plot, 'Tag', 'Axes1');
  343. % display(hdlfig)
  344. % axes(hdlfig)
  345.  
  346. if tipoplot == 3 || tipoplot == 6
  347.  
  348. [quanti,tanti] = size(Y);
  349. colori = get(gcf,'DefaultAxesColorOrder');
  350.  
  351. for i = 1:tanti
  352. if plot_snap
  353. sequenza = snap_idx;
  354. else
  355. tmin = min(X);
  356. tmax = max(X);
  357. deltat = (tmax-tmin)/5;
  358. tmin = tmin + i*(tmax-tmin)/43;
  359. seqt = tmin:deltat:tmax;
  360. for j = 1:length(seqt),
  361. [valt, sequenza(j)] = min(abs(X-seqt(j)));
  362. end
  363. end
  364. hdl = text(X(sequenza),Y(sequenza,i),num2str(Varname.pos(i)));
  365. if tipoplot == 6,
  366. set(hdl,'Color',colori(rem(i-1,7)+1,:));
  367. end
  368. end
  369.  
  370. if leg_value == 1 || Settings.hostver >= 7
  371. hdl = findobj(Fig.plot,'Tag','legend');
  372. %get(hdl)
  373. oldh = gca;
  374. set(gca,'HandleVisibility','off')
  375. set(hdl,'Interruptible','on')
  376. h = findobj(hdl,'Type','line');
  377. %get(hdl)
  378. for i = 1:tanti
  379. j = i*2;
  380. xdata = get(h(j),'XData');
  381. ydata = get(h(j),'YData');
  382. htext = text((xdata(2)-xdata(1))/2,ydata(1), ...
  383. int2str(tanti-i+1));
  384. set(htext,'Color',get(h(j),'Color'));
  385. end
  386. set(oldh,'HandleVisibility','on')
  387. set(Fig.plot,'CurrentAxes',oldh);
  388. end
  389.  
  390. elseif tipoplot == 4 || tipoplot == 5
  391.  
  392. [quanti,tanti] = size(Y);
  393. hold on
  394. simboli = {'o';'s';'d';'v';'^';'<';'>';'x'};
  395. colori = get(Fig.plot,'DefaultAxesColorOrder');
  396.  
  397. for i = 1:tanti
  398. if plot_snap
  399. sequenza = snap_idx;
  400. if tanti == 1 && CPF.init
  401. y1 = get(hdlfig,'YLim');
  402. yoff = 0.05*(y1(2)-y1(1));
  403. for hh = 1:length(sequenza)
  404. text(X(sequenza(hh)), ...
  405. Y(sequenza(hh),Varname.pos(i))+yoff, ...
  406. Snapshot(hh).name)
  407. end
  408. end
  409. else
  410. tmin = min(X);
  411. tmax = max(X);
  412. deltat = (tmax-tmin)/5;
  413. tmin = tmin + i*(tmax-tmin)/43;
  414. seqt = tmin:deltat:tmax;
  415. for j = 1:length(seqt),
  416. [valt, sequenza(j)] = min(abs(X-seqt(j)));
  417. end
  418. end
  419. set(hdlfig,'LineStyle',simboli{rem(i-1,8)+1}, 'Tag', 'Axes1');
  420. hmarker = plot(X(sequenza),Y(sequenza,Varname.pos(i)));
  421. set(hmarker,'MarkerSize',7,'MarkerFaceColor',AxesColor);
  422. if tipoplot == 5,
  423. set(hmarker,'Color',colori(rem(i-1,7)+1,:));
  424. end
  425. end
  426. hold off;
  427.  
  428. if leg_value == 1 || Settings.hostver >= 7
  429. hdl = findobj(Fig.plot,'Tag','legend');
  430. set(Fig.plot,'CurrentAxes',hdl);
  431. h = findobj(hdl,'Type','line');
  432. for i = 1:tanti
  433. j = i*2;
  434. xdata = get(h(j),'XData');
  435. ydata = get(h(j),'YData');
  436. set(hdl,'LineStyle',simboli{rem(tanti-i,8)+1});
  437. if Settings.hostver >= 7
  438. hmarker = plot(hdl,(xdata(2)-xdata(1))/1.2,ydata(1));
  439. else
  440. hmarker = plot((xdata(2)-xdata(1))/1.2,ydata(1));
  441. end
  442. set(hmarker,'MarkerSize',7, ...
  443. 'Color',get(h(j),'Color'), ...
  444. 'MarkerFaceColor',AxesColor);
  445. end
  446. set(Fig.plot,'CurrentAxes',hdlfig);
  447. end
  448.  
  449. end
  450.  
  451. if get(Hdl_grid,'Value'); grid on; end
  452. if ~get(Hdl_legend,'Value') && Settings.hostver >= 7 && Settings.hostver < 8.04
  453. legend(findobj(Fig.plot,'Tag','Axes1'),'hide')
  454. end
  455. set(get(hdlfig,'XLabel'), ...
  456. 'FontName',AxesFont, ...
  457. 'FontWeight',AxesWeight, ...
  458. 'FontAngle',AxesAngle, ...
  459. 'FontSize',AxesSize, ...
  460. 'FontUnits',AxesUnits)
  461. set(hdlfig, ...
  462. 'FontName',AxesFont, ...
  463. 'Color',AxesColor, ...
  464. 'FontWeight',AxesWeight, ...
  465. 'FontAngle',AxesAngle, ...
  466. 'FontSize',AxesSize, ...
  467. 'FontUnits',AxesUnits, ...
  468. 'Tag','Axes1')
  469.  
  470. if ishandle(Fig.line), fm_plot('createlinelist'), end
  471. if get(hdl_x, 'Value'), fm_plot('axesx'), end
  472. if get(hdl_y, 'Value'), fm_plot('axesy'), end
  473. if get(hdl_xy,'Value'), fm_plot('axesxy'), end
  474. fm_plot plotvlims
  475. fm_plot plotslims
  476. set(hdlfig,'Position',[0.09 0.4050 0.4754 0.5000], 'Tag', 'Axes1')
  477.  
  478. %display('ciao')
  479. %display(hdlfig)
  480.  
  481. case 'export' % export the figure to file
  482.  
  483. tag = get(gcbo,'Tag');
  484. axs_pos = get(Hdl.axesplot,'Position');
  485. fig_pos = get(Fig.plot,'Position');
  486. pap_pos = get(Fig.plot,'PaperPosition');
  487. pap_siz = get(Fig.plot,'PaperSize');
  488.  
  489. leg_value = get(Hdl_legend,'Value');
  490. if leg_value
  491. pos_leg = get(Hdl.legend,'Position');
  492. end
  493.  
  494. shrink = 0.8; % axes scale factor
  495.  
  496. set(Hdl.axesplot,'Position',[0.13 0.11 0.855 0.875])
  497. set(Fig.plot,'Position',[fig_pos(1), fig_pos(2), ...
  498. fig_pos(3)*shrink, fig_pos(4)*shrink])
  499. if leg_value
  500. pos_leg2(1) = 0.13 + 0.855*(pos_leg(1) - axs_pos(1))/axs_pos(3);
  501. pos_leg2(2) = 0.11 + 0.875*(pos_leg(2) - axs_pos(2))/axs_pos(4);
  502. pos_leg2(3) = pos_leg(3)*0.855/axs_pos(3);
  503. pos_leg2(4) = pos_leg(4)*0.875/axs_pos(4);
  504. set(Hdl.legend,'Position',pos_leg2);
  505.  
  506. if pos_leg2(1)+pos_leg2(3) > 0.985
  507. Resize = (pos_leg2(1)+pos_leg2(3))/0.985;
  508. fig_pos2 = [0.13 0.11 0.855 0.875];
  509. fig_pos2(3) = fig_pos2(3)/Resize;
  510. fig_pos2(1) = fig_pos2(1)/Resize;
  511. pos_leg2(3) = pos_leg2(3)/Resize;
  512. pos_leg2(1) = pos_leg2(1)/Resize;
  513. set(Hdl.axesplot,'Position',fig_pos2)
  514. set(Hdl.legend,'Position',pos_leg2)
  515. end
  516. end
  517.  
  518. if Settings.hostver > 5.03,
  519. set(Fig.plot,'PaperSize',[pap_siz(1)*shrink, pap_siz(2)*shrink])
  520. end
  521. ppos(3) = pap_pos(3)*shrink;
  522. ppos(4) = pap_pos(4)*shrink;
  523. ppos(1) = (pap_siz(1)-ppos(3))/2;
  524. ppos(2) = (pap_siz(2)-ppos(4))/2;
  525. set(Fig.plot,'PaperPosition',ppos)
  526.  
  527. ax2_pos = get(Hdl.axeslogo,'Position');
  528. set(Hdl.axeslogo,'Position',[10 10 0.2 0.2]);
  529.  
  530. Hdl_all = get(Fig.plot,'Children');
  531. idx = find(Hdl_all==Hdl.axesplot);
  532. if idx, Hdl_all(idx) = []; end
  533. idx = find(Hdl_all==Hdl.axeslogo);
  534. if idx, Hdl_all(idx) = []; end
  535. if leg_value,
  536. idx = find(Hdl_all==Hdl.legend);
  537. if idx, Hdl_all(idx) = []; end
  538. end
  539.  
  540. set(Hdl_all,'Visible','off');
  541.  
  542. lastwarn('')
  543. switch tag
  544. case 'PushEPS'
  545. nomefile = fm_filenum('eps');
  546. print(Fig.plot,'-depsc',[Path.data,nomefile])
  547. set(hdlfig,'Position',axs_pos);
  548. set(hdlfig2,'Position',ax2_pos);
  549. set(Fig.plot,'Position',fig_pos)
  550. set(Fig.plot,'PaperPosition',pap_pos)
  551. if Settings.hostver > 5.03,
  552. set(Fig.plot,'PaperSize',pap_siz)
  553. end
  554. set(Hdl_all,'Visible','on');
  555. if leg_value
  556. set(Hdl.legend,'Position',pos_leg);
  557. end
  558. case 'PushMeta'
  559. print(Fig.plot,'-dmeta')
  560. set(hdlfig,'Position',axs_pos);
  561. set(hdlfig2,'Position',ax2_pos);
  562. set(Fig.plot,'Position',fig_pos)
  563. set(Fig.plot,'PaperPosition',pap_pos)
  564. if Settings.hostver > 5.03,
  565. set(Fig.plot,'PaperSize',pap_siz)
  566. end
  567. set(Hdl_all,'Visible','on');
  568. if leg_value
  569. set(Hdl.legend,'Position',pos_leg);
  570. end
  571. case 'PushFig'
  572. figplot = Fig.plot;
  573. Fig.plot = -1;
  574. try
  575. figpos = get(0,'factoryFigurePosition');
  576. axspos = get(0,'factoryAxesPosition');
  577. figunit = get(0,'factoryFigureUnits');
  578. axsunit = get(0,'factoryAxesUnits');
  579. catch
  580. figpos = [100 100 660 520];
  581. axspos = [0.1300 0.1100 0.7750 0.8150];
  582. figunit = 'pixels';
  583. axsunit = 'normalized';
  584. end
  585. set(figplot, ...
  586. 'Units',figunit, ...
  587. 'Position',figpos, ...
  588. 'Menubar','figure', ...
  589. 'Name','', ...
  590. 'NumberTitle','on', ...
  591. 'CreateFcn','', ...
  592. 'DeleteFcn','', ...
  593. 'UserData',[], ...
  594. 'FileName','')
  595. set(Hdl.axesplot,'Color',[1 1 1],'Units',axsunit,'Position',axspos)
  596. if leg_value
  597. set(Hdl.legend,'Color',[1 1 1])
  598. end
  599. delete(Hdl_all)
  600. delete(hdlfig2)
  601. fm_plotfig
  602. figure(figplot)
  603. end
  604. if ~isempty(lastwarn) && ~strcmp(lastwarn,'File not found or permission denied')
  605. fm_disp(lastwarn,2),
  606. end
  607.  
  608. case 'plottypes'
  609.  
  610. tipoplot = get(Hdl_tipoplot,'Value');
  611.  
  612. if Settings.hostver < 8.04
  613. switch tipoplot
  614. case 1,
  615. set(Fig.plot, ...
  616. 'DefaultAxesColorOrder',Settings.color, ...
  617. 'DefaultAxesLineStyleOrder','-');
  618. case 2,
  619. set(Fig.plot, ...
  620. 'DefaultAxesColorOrder',[ 0 0 0 ], ...
  621. 'DefaultAxesLineStyleOrder','-|-.|--|:');
  622. case 3,
  623. set(Fig.plot, ...
  624. 'DefaultAxesColorOrder',[ 0 0 0 ], ...
  625. 'DefaultAxesLineStyleOrder','-');
  626. case 4,
  627. set(Fig.plot, ...
  628. 'DefaultAxesColorOrder',[ 0 0 0 ], ...
  629. 'DefaultAxesLineStyleOrder','-');
  630. otherwise,
  631. set(Fig.plot, ...
  632. 'DefaultAxesColorOrder',Settings.color, ...
  633. 'DefaultAxesLineStyleOrder','-');
  634. end
  635. else
  636. switch tipoplot
  637. case 1,
  638. set(Fig.plot, ...
  639. 'DefaultAxesColorOrder',Settings.color, ...
  640. 'DefaultAxesLineStyleOrder','-');
  641. otherwise,
  642. set(Fig.plot, ...
  643. 'DefaultAxesColorOrder',[ 0 0 0 ], ...
  644. 'DefaultAxesLineStyleOrder','-|-.|--|:');
  645. end
  646. end
  647.  
  648. fm_plot('plotvars')
  649.  
  650. case 'editvarname'
  651.  
  652. value = get(Hdl_listplot,'Value');
  653. if ~isempty(get(Hdl_listplot,'String'))
  654. valori = get(Hdl_listvar,'Value');
  655. val = valori(Varname.pos(value));
  656. stringa = Varname.fvars(Varname.idx);
  657. nomeattuale = popupstr(Hdl_listplot);
  658. idx = findstr(nomeattuale,']');
  659. nomeattuale = nomeattuale(idx+2:end);
  660. nomenuovo = fm_input('Input Formatted Text:', ...
  661. 'Legend Name',1,{stringa{val}});
  662. if isempty(nomenuovo),
  663. return,
  664. end
  665. Varname.fvars{Varname.idx(val)} = nomenuovo{1};
  666. set(Fig.plot,'UserData',stringa);
  667. fm_disp(['Formatted text of variable "', ...
  668. nomeattuale,'" has been changed in "', ...
  669. nomenuovo{1},'"'])
  670. else
  671. fm_disp('No variable selected')
  672. end
  673.  
  674. case 'zoomy'
  675.  
  676. zoom yon
  677. set(Fig.plot,'WindowButtonMotionFcn','fm_plot motion');
  678. set(hdl_zoom1,'Value',0);
  679. set(hdl_zoom2,'Value',0);
  680. if get(hdl_zoom3,'Value')
  681. Settings.zoom = 'zoom yon';
  682. else
  683. Settings.zoom = '';
  684. zoom off
  685. end
  686.  
  687. case 'axesy'
  688.  
  689. if get(hdl_x,'Value')
  690. set(hdl_x,'Value',0)
  691. delete(findobj(allchild(hdlfig),'UserData','x axis'))
  692. end
  693. if get(hdl_xy,'Value')
  694. set(hdl_xy,'Value',0)
  695. delete(findobj(allchild(hdlfig),'UserData','x axis'))
  696. delete(findobj(allchild(hdlfig),'UserData','y axis'))
  697. end
  698.  
  699. value = get(gcbo,'Value');
  700. if value
  701. ylim = get(hdlfig,'YLim');
  702. hold on
  703. h = plot([0 0],[ylim(1), ylim(2)],'k:');
  704. set(h,'UserData','y axis')
  705. hold off
  706. else
  707. hdl_child = allchild(hdlfig);
  708. delete(findobj(hdl_child,'UserData','y axis'))
  709. end
  710. if ishandle(Fig.line), fm_plot('createlinelist'), end
  711.  
  712. case 'axescolor'
  713.  
  714. currentColor = get(hdlfig,'Color');
  715. c = uisetcolor(currentColor);
  716. if ~isequal(c,currentColor)
  717. set(hdlfig,'Color',c)
  718. hdl_line = findobj(allchild(hdlfig),'Type','line');
  719. set(hdl_line,'MarkerFaceColor',c)
  720. hlegend = findobj(Fig.plot,'Tag','legend');
  721. set(hlegend,'Color',c)
  722. end
  723.  
  724. case 'axesx'
  725.  
  726. if get(hdl_y,'Value')
  727. set(hdl_y,'Value',0)
  728. delete(findobj(allchild(hdlfig),'UserData','y axis'))
  729. end
  730. if get(hdl_xy,'Value')
  731. set(hdl_xy,'Value',0)
  732. delete(findobj(allchild(hdlfig),'UserData','y axis'))
  733. delete(findobj(allchild(hdlfig),'UserData','x axis'))
  734. end
  735.  
  736. value = get(gcbo,'Value');
  737. if value
  738. xlim = get(hdlfig,'XLim');
  739. hold on
  740. h = plot([xlim(1), xlim(2)], [0, 0],'k:');
  741. set(h,'UserData','x axis')
  742. hold off
  743. else
  744. hdl_child = allchild(hdlfig);
  745. delete(findobj(hdl_child,'UserData','x axis'))
  746. end
  747. if ishandle(Fig.line), fm_plot('createlinelist'), end
  748.  
  749. case 'axesxy'
  750.  
  751. if get(hdl_x,'Value')
  752. set(hdl_x,'Value',0)
  753. delete(findobj(allchild(hdlfig),'UserData','x axis'))
  754. end
  755. if get(hdl_y,'Value')
  756. set(hdl_y,'Value',0)
  757. delete(findobj(allchild(hdlfig),'UserData','y axis'))
  758. end
  759.  
  760. value = get(gcbo,'Value');
  761. if value
  762. xlim = get(hdlfig,'XLim');
  763. ylim = get(hdlfig,'YLim');
  764. hold on
  765. h = plot([xlim(1), xlim(2)], [0, 0],'k:');
  766. set(h,'UserData','x axis')
  767. h = plot([0, 0],[ylim(1), ylim(2)],'k:');
  768. set(h,'UserData','y axis')
  769. hold off
  770. else
  771. hdl_child = allchild(hdlfig);
  772. try
  773. delete(findobj(hdl_child,'UserData','x axis'))
  774. catch
  775. % nothing to do
  776. end
  777. try
  778. delete(findobj(hdl_child,'UserData','y axis'))
  779. catch
  780. % nothing to do
  781. end
  782. end
  783. if ishandle(Fig.line), fm_plot('createlinelist'), end
  784.  
  785. case 'zoomx'
  786.  
  787. zoom xon
  788. set(Fig.plot,'WindowButtonMotionFcn','fm_plot motion');
  789. set(hdl_zoom1,'Value',0);
  790. set(hdl_zoom3,'Value',0);
  791. if get(hdl_zoom2,'Value')
  792. Settings.zoom = 'zoom xon';
  793. else
  794. Settings.zoom = '';
  795. zoom off
  796. end
  797.  
  798. case 'zoomxy'
  799.  
  800. zoom on
  801. set(Fig.plot,'WindowButtonMotionFcn','fm_plot motion');
  802. set(hdl_zoom2,'Value',0);
  803. set(hdl_zoom3,'Value',0);
  804. if get(hdl_zoom1,'Value')
  805. Settings.zoom = 'zoom on';
  806. else
  807. Settings.zoom = '';
  808. zoom off
  809. end
  810.  
  811. case 'moveup'
  812.  
  813. value = get(Hdl_listplot,'Value');
  814. NameString = get(Hdl_listplot,'String');
  815. Value = 1:length(NameString);
  816.  
  817. if value > 1
  818. dummy = Varname.pos(value);
  819. Varname.pos(value) = Varname.pos(value-1);
  820. Varname.pos(value-1) = dummy;
  821. dummy = Value(value);
  822. Value(value) = Value(value-1);
  823. Value(value-1) = dummy;
  824. set(Hdl_listplot, ...
  825. 'String',NameString(Value), ...
  826. 'Value',value-1);
  827. end
  828.  
  829. case 'movedown'
  830.  
  831. value = get(Hdl_listplot,'Value');
  832. NameString = get(Hdl_listplot,'String');
  833. Value = 1:length(NameString);
  834.  
  835. if value < length(Varname.pos) && ~isempty(NameString)
  836. dummy = Varname.pos(value);
  837. Varname.pos(value) = Varname.pos(value+1);
  838. Varname.pos(value+1) = dummy;
  839. dummy = Value(value);
  840. Value(value) = Value(value+1);
  841. Value(value+1) = dummy;
  842. set(Hdl_listplot, ...
  843. 'String',NameString(Value), ...
  844. 'Value',value+1);
  845. end
  846.  
  847. case 'togglegrid'
  848.  
  849. if get(gcbo,'Value')
  850. grid on
  851. else
  852. grid off
  853. end
  854.  
  855. case 'togglelegend'
  856.  
  857. if Settings.hostver >= 8.04
  858. % axes(findobj(Fig.plot, 'Tag', 'Axes1'))
  859. legend toggle
  860. elseif Settings.hostver >= 7
  861. legend(findobj(Fig.plot,'Tag','Axes1'),'toggle')
  862. else
  863. onoff = {'off','on'};
  864. if strcmp(get(gcbo,'Tag'),'PushLegend')
  865. set(Hdl_legend,'Value',~get(Hdl_legend,'Value'))
  866. set(gcbo,'Checked',onoff{get(Hdl_legend,'Value')+1})
  867. value = get(Hdl_legend,'Value');
  868. else
  869. hdl = findobj(Fig.plot,'Tag','PushLegend');
  870. set(hdl,'Checked',onoff{get(gcbo,'Value')+1})
  871. value = get(gcbo,'Value');
  872. end
  873.  
  874. if value
  875. fm_plot('plotvars')
  876. else
  877. legend off
  878. end
  879. end
  880.  
  881. case 'listvars'
  882.  
  883. Value = get(Hdl_listvar,'Value');
  884. if isempty(Value), return, end
  885. NameString = get(Hdl_listvar,'String');
  886. if isempty(NameString), return, end
  887. set(Hdl_listplot,'String',NameString(Value));
  888. set(Hdl_listplot,'Value',1);
  889. Varname.pos = 1:length(Value);
  890. if strcmp(get(Fig.plot,'SelectionType'),'open'),
  891. fm_plot('plotvars')
  892. end
  893.  
  894. case 'listlines'
  895.  
  896. hdl = findobj(Fig.line,'Tag','Listbox1');
  897. Value = get(hdl,'Value');
  898. hdl_line = get(Fig.line,'UserData');
  899. hdl_line = hdl_line(end:-1:1);
  900. fm_linedlg(hdl_line(Value))
  901.  
  902. case 'createlinelist'
  903.  
  904. hdl_line = findobj(allchild(hdlfig),'Type','line');
  905. variabili = get(Hdl_listplot,'String');
  906. set(Fig.line,'UserData',hdl_line);
  907. hdl_list = findobj(Fig.line,'Tag','Listbox1');
  908. line_string = cell(length(hdl_line),1);
  909. hdl_line = hdl_line(end:-1:1);
  910. for i = 1:length(hdl_line)
  911. if strcmp(get(hdl_line(i),'UserData'),'x axis')
  912. line_string{i,1} = ['x axis ',fvar(i,4)];
  913. elseif strcmp(get(hdl_line(i),'UserData'),'y axis')
  914. line_string{i,1} = ['y axis ',fvar(i,4)];
  915. elseif i <= length(variabili)
  916. line_string{i,1} = ['line ',fvar(i,4),variabili{i}];
  917. else
  918. line_string{i,1} = ['symbol ',fvar(i,4), ...
  919. variabili{i-length(variabili)}];
  920. end
  921. end
  922. set(hdl_list,'String',line_string,'Value',1);
  923.  
  924. case 'axesprops'
  925.  
  926. fm_axesdlg(hdlfig)
  927.  
  928. case 'textprops'
  929.  
  930. TextProp = uisetfont;
  931. if isstruct(TextProp)
  932. set(hdlfig,TextProp)
  933. set(get(hdlfig,'XLabel'),TextProp)
  934. set(get(hdlfig,'YLabel'),TextProp)
  935. set(get(hdlfig,'Title'),TextProp)
  936. if get(Hdl_legend,'Value')
  937. hlegend = findobj(Fig.plot,'Tag','legend');
  938. hchild = get(hlegend,'Child');
  939. set(hchild(end), ...
  940. 'FontName',TextProp.FontName, ...
  941. 'FontWeight', TextProp.FontWeight, ...
  942. 'FontAngle',TextProp.FontAngle)
  943. end
  944. end
  945.  
  946. case 'setxlabel'
  947.  
  948. value = get(gcbo,'Value');
  949. set(gcbo,'Value',value(end))
  950. if strcmp(get(Fig.plot,'SelectionType'),'open')
  951. fm_plot('plotvars')
  952. end
  953.  
  954. case 'setangles'
  955.  
  956. [idx,kdx] = get_angle_idx;
  957. set(gcbo,'String',[{'None'}; Varname.uvars(idx)],'UserData',kdx)
  958.  
  959. case 'limits'
  960.  
  961. status = get(gcbo,'Checked');
  962. switch status
  963. case 'on'
  964. set(gcbo,'Checked','off')
  965. case 'off'
  966. set(gcbo,'Checked','on')
  967. end
  968. fm_plot plotvars
  969.  
  970. case 'usedegrees'
  971.  
  972. status = get(gcbo,'Checked');
  973. switch status
  974. case 'on'
  975. Settings.usedegree = 0;
  976. set(gcbo,'Checked','off')
  977. case 'off'
  978. Settings.usedegree = 1;
  979. set(gcbo,'Checked','on')
  980. end
  981. fm_plot plotvars
  982.  
  983. case 'usehertzs'
  984.  
  985. status = get(gcbo,'Checked');
  986. switch status
  987. case 'on'
  988. Settings.usehertz = 0;
  989. set(gcbo,'Checked','off')
  990. case 'off'
  991. Settings.usehertz = 1;
  992. set(gcbo,'Checked','on')
  993. end
  994. fm_plot plotvars
  995.  
  996. case 'userelspeeds'
  997.  
  998. status = get(gcbo,'Checked');
  999. switch status
  1000. case 'on'
  1001. Settings.userelspeed = 0;
  1002. set(gcbo,'Checked','off')
  1003. case 'off'
  1004. Settings.userelspeed = 1;
  1005. set(gcbo,'Checked','on')
  1006. end
  1007. fm_plot plotvars
  1008.  
  1009. case 'plotvlims'
  1010.  
  1011. hdl = findobj(Fig.plot,'Tag','PlotVLim');
  1012. value = get(hdl,'Checked');
  1013. if ~strcmp(value,'on'), return, end
  1014. xlimits = get(hdlfig,'XLim');
  1015. hold on
  1016. plot(hdlfig,[xlimits(1) xlimits(2)],[0.9 0.9],'k:')
  1017. plot(hdlfig,[xlimits(1) xlimits(2)],[1.1 1.1],'k:')
  1018. hold off
  1019.  
  1020. case 'plotslims'
  1021.  
  1022. hdl = findobj(Fig.plot,'Tag','NormSij');
  1023. value = get(hdl,'Checked');
  1024. if ~strcmp(value,'on'), return, end
  1025. xlimits = get(hdlfig,'XLim');
  1026. hold on
  1027. plot(hdlfig,[xlimits(1) xlimits(2)],[1.0 1.0],'k:')
  1028. hold off
  1029.  
  1030. case 'lowestv'
  1031.  
  1032. idx = find(Varname.idx > DAE.n+Bus.n && Varname.idx <= DAE.n+2*Bus.n);
  1033. if isempty(idx), return, end
  1034. out = Varout.vars(:,idx);
  1035. vals = min(out,[],1);
  1036. [y,jdx] = sort(vals);
  1037. if length(jdx) > 3, jdx = jdx(1:3); end
  1038. set(Hdl_listvar,'Value',idx(jdx));
  1039. fm_plot listvars
  1040. fm_plot plotvars
  1041.  
  1042. case 'highestv'
  1043.  
  1044. idx = find(Varname.idx > DAE.n+Bus.n && Varname.idx <= DAE.n+2*Bus.n);
  1045. if isempty(idx), return, end
  1046. out = Varout.vars(:,idx);
  1047. vals = max(out,[],1);
  1048. [y,jdx] = sort(vals,2,'descend');
  1049. if length(jdx) > 3, jdx = jdx(1:3); end
  1050. set(Hdl_listvar,'Value',idx(jdx));
  1051. fm_plot listvars
  1052. fm_plot plotvars
  1053.  
  1054. case 'highests'
  1055.  
  1056. values = highests(Line);
  1057. if isempty(values), return, end
  1058. set(Hdl_listvar,'Value',values);
  1059. fm_plot listvars
  1060. fm_plot plotvars
  1061.  
  1062. end
  1063.  
  1064. if ~isempty(Settings.zoom), eval(Settings.zoom), end
  1065.  
  1066. % ------------------------------------------------------------------------
  1067. % Some useful functions
  1068. % -----------------------------------------------------------------------
  1069.  
  1070. function stringa = enum(stringa)
  1071. for i = 1:length(stringa),
  1072. stringa{i} = ['[',int2str(i),'] ',stringa{i}];
  1073. end
  1074.  
  1075. function kdx = get_rotor_idx(idx)
  1076. global DAE Syn COI Cswt Dfig Ddsg Busfreq Mass SSR Tg
  1077. kdx = [];
  1078. for i = 1:length(idx)
  1079. kkk = idx(i);
  1080. if kkk > DAE.n+DAE.m
  1081. break
  1082. elseif kkk <= DAE.n
  1083. if isomega(Syn,kkk) || isomega(Cswt,kkk) || isomega(Dfig,kkk) ...
  1084. || isomega(Ddsg,kkk) || isomega(Mass,kkk) || isomega(SSR,kkk) ...
  1085. || isomega(Busfreq)
  1086. kdx = [kdx, i];
  1087. end
  1088. elseif isomega(COI,kkk) || isomega(Tg,kkk)
  1089. kdx = [kdx, i];
  1090. end
  1091. end
  1092.  
  1093. function varargout = get_angle_idx(varargin)
  1094. global Varout DAE Syn Bus COI Mass SSR Phs Svc Cswt Ddsg Dfig Pmu Hvdc
  1095. idx = [];
  1096. kdx = [];
  1097.  
  1098. if ~nargin
  1099. varidx = Varout.idx;
  1100. else
  1101. varidx = varargin{1};
  1102. end
  1103.  
  1104. for i = 1:length(varidx)
  1105. kkk = varidx(i);
  1106. if kkk > DAE.n+DAE.m
  1107. break
  1108. elseif kkk <= DAE.n
  1109. if isdelta(Syn,kkk) || isdelta(Mass,kkk) || isdelta(SSR,kkk) ...
  1110. || isdelta(Phs,kkk) || isdelta(Svc,kkk) || isdelta(Cswt,kkk) ...
  1111. || isdelta(Ddsg,kkk) || isdelta(Dfig,kkk) || isdelta(Pmu,kkk)
  1112. idx = [idx, kkk];
  1113. kdx = [kdx, i];
  1114. end
  1115. elseif kkk > DAE.n && kkk <= DAE.n+Bus.n
  1116. idx = [idx, kkk];
  1117. kdx = [kdx, i];
  1118. elseif isdelta(COI,kkk) || isdelta(Hvdc,kkk)
  1119. idx = [idx, kkk];
  1120. kdx = [kdx, i];
  1121. end
  1122. end
  1123.  
  1124. switch nargout
  1125. case 1
  1126. varargout{1} = kdx;
  1127. case 2
  1128. varargout{1} = idx;
  1129. varargout{2} = kdx;
  1130. end
  1131.  
Add Comment
Please, Sign In to add comment