3 // Copyright (C) INRIA - Masoud Najafi <masoud.najafi@inria.fr>
4 // Serge Steer <serge.steer@inria.fr> 1993
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 // See the file ../license.txt
24 function [x,y,typ]=CURVE_c(job,arg1,arg2)
25 //** 07/01/2008 : Adapted fot Scilab 5.0 by Simone Mannori
34 [x,y,typ]=standard_inputs(arg1);
36 case "getoutputs" then
37 [x,y,typ]=standard_outputs(arg1);
40 [x,y]=standard_origin(arg1);
46 graphics = arg1.graphics;
47 exprs = graphics.exprs;
53 [ok,Method,xx,yy,PeriodicOption,graf,exprs] = scicos_getvalue('Spline data',['Spline"+...
54 " Method (0..7)';'x';'y';'Periodic signal(y/n)?';'Launch"+...
55 " graphic window(y/n)?'],list('vec',1,'vec',-1, ...
56 'vec',-1,'str',1,'str',1),exprs)
59 if PeriodicOption=='y' | PeriodicOption=='Y' then
75 METHOD = getmethod(mtd);
79 [nx,mx] = size(xx); [ny,my]=size(yy);
80 if ~((nx==ny)&(mx==my)) then
81 messagebox("Incompatible size of [x] and [y]","modal","error");
86 if ~Ask_again then //+++++++++++++++++++++++++++++++++++++++
88 [xy] = cleandata(xy); // just for sorting to be able to compare data before and after poke_point(.)
90 exprs(5)='n';// exprs.graf='n'
92 if graf=='y' | graf=='Y' then //_______Graphic editor___________
96 if (winsid() == []) then
99 curwin = max(winsid())+1; //** prepare a brand new win
101 //** see below in this file; "poke_point" is very similar to "edit_curv"
102 [orpar,oipar,ok] = poke_point(xy,ipar,rpar); //** HERE WE ARE +++++++++++++++++++++++++++++++++++
103 if ~ok then break;end;// exit without save
105 // verifying the data change
106 N2=oipar(1);xy2=[orpar(1:N2),orpar(N2+1:2*N2)];
107 New_methhod=oipar(2);
109 METHOD=getmethod(New_methhod);
110 if or(xy(:,1)<>xy2(:,1)) then, DChange=%t;end
111 if or(xy(1:N-1,2)<>xy2(1:N2-1,2)) then, DChange=%t;end
112 if (xy(N,2)<>xy2(N2,2) & (METHOD<>'periodic')) then, DChange=%t;end
114 exprs(2)=strcat(sci2exp(xy2(:,1)))
115 exprs(3)=strcat(sci2exp(xy2(:,2)))
118 exprs(1)=sci2exp(New_methhod);
119 if oipar(3)==1 then,perop='y';else,perop='n';end
122 else//_____________________No graphics__________________________
123 [Xdummy,Ydummy,orpar]=Do_Spline(N,mtd,xy(:,1),xy(:,2));
124 if (METHOD=='periodic') then // periodic spline
127 if (METHOD=='order 2' | METHOD=='not_a_knot'|METHOD=='periodic' | METHOD=='monotone'| METHOD=='fast' | METHOD=='clamped') then
128 orpar=[xy(:,1);xy(:,2);orpar];
130 if (METHOD=='zero order'|METHOD=='linear')
131 orpar=[xy(:,1);xy(:,2);]
134 exprs(1)=sci2exp(mtd);// pour le cas methode>7 | method<0
137 end //___________________________________________________________
138 end //++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 xp=find(orpar(1:oipar(1))>=0);
143 model.firing=orpar(xp(1)); //first positive event
149 graphics.exprs=exprs;
157 xx=[0, 1, 2];yy=[10, 20, -30]; N=3; Method=3; PeriodicOption='y'; Graf='n'
158 model.sim=list('curve_c',4)
161 model.rpar=[xx(:);yy(:)]
162 model.ipar=[N;Method;1]
168 exprs=[sci2exp(Method);sci2exp(xx);sci2exp(yy);PeriodicOption;Graf]
170 gr_i=['rpar=arg1.model.rpar;n=model.ipar(1);order=model.ipar(2);';
171 'xx=rpar(1:n);yy=rpar(n+1:2*n);';
172 '[XX,YY,rpardummy]=Do_Spline(n,order,xx,yy)';
173 'xmx=max(XX);xmn=min(XX);';
174 'ymx=max(YY);ymn=min(YY);';
175 'dx=xmx-xmn;if dx==0 then dx=max(xmx/2,1);end';
176 'xmn=xmn-dx/20;xmx=xmx+dx/20;';
177 'dy=ymx-ymn;if dy==0 then dy=max(ymx/2,1);end;';
178 'ymn=ymn-dy/20;ymx=ymx+dy/20;';
179 'xx2=orig(1)+sz(1)*((XX-xmn)/(xmx-xmn));';
180 'yy2=orig(2)+sz(2)*((YY-ymn)/(ymx-ymn));';
182 'xpoly(xx2,yy2,''lines'');']
183 x=standard_define([2 2],model,exprs,gr_i)
188 function [rpar,ipar,ok] = poke_point(ixy,iparin,rparin)
192 //** get_click is already defined in "editi_curv"
193 //in line definition of get_click
194 deff('[btn,xc,yc,win,Cmenu]=get_click(flag)',[
195 'if ~or(winsid() == curwin) then Cmenu = ''Quit'';return,end,';
196 'if argn(2) == 1 then';
197 ' [btn, xc, yc, win, str] = xclick(flag);';
199 ' [btn, xc, yc, win, str] = xclick();';
201 'if btn == -1000 then';
202 ' if win == curwin then';
203 ' Cmenu = ''Quit'';';
205 ' Cmenu = ''Open/Set'';';
211 ' try ' // added to handle unwanted menu actions in french version
212 ' execstr(''Cmenu='' + part(str, 9:length(str) - 1));';
213 ' execstr(''Cmenu='' + Cmenu);';
222 if rhs==0 then ixy=[];end;
224 if size(xy,'c')<2 then
225 xinfo(" No [y] is provided");
229 [xy] = cleandata(ixy)
236 ipar = [N;NOrder;PeridicOption]
240 PeridicOption = iparin(3);
245 PeridicOption = iparin(3);
252 Amp=[]; wp=[]; phase=[]; offset=[]; np1=[];
253 Sin_exprs = list(string(Amp),string(wp), string(phase),string(offset),string(np1));
254 sAmp=[]; sTp=[]; sdelay=[];
255 Sawt1_exprs = list(string(sAmp),string(sTp),string(sdelay));
257 Sawt2_exprs = list(string(sAmp2),string(sTp2));
259 Amp3=[];Tp3=[];Pw3=[];Pd3=[];Bias3=[];
260 Pulse_exprs=list(string(Amp3), string(Tp3),string(Pw3),string(Pd3),string(Bias3))
262 mean4=[];var4=[];seed4=[];sample4=[];np4=[];
263 random_n_exprs=list(string(mean4),string(var4), string(seed4),string(sample4),string(np4))
265 min5=[];max5=[];seed5=[];sample5=[];np5=[];
266 random_u_exprs=list(string(min5), string(max5), string(seed5),string(sample5),string(np5))
268 // bornes initiales du graphique
269 xmx = max(xy(:,1));xmn=min(xy(:,1)),xmn=max(xmn,0);
270 ymx = max(xy(:,2));ymn=min(xy(:,2));
271 dx = xmx-xmn; dy = ymx-ymn
273 if dx==0 then dx=max(xmx/2,1),end;
276 if dy==0 then dy=max(ymx/2,1),end;
277 ymn = ymn-dy/50; ymx = ymx+dy/50;
279 rect = [xmn,ymn;xmx,ymx];
287 menu_o = ['zero order','linear','order 2','not_a_knot','periodic','monotone','fast','clamped']
288 menu_d = ['Clear','Data Bounds','Load from text file','Save to text file','Load from Excel','Periodic signal']
289 menu_t=['sine','sawtooth1','sawtooth2','pulse','random normal','random uniform']
290 menu_e=['Help','Exit without save','Save/Exit']
291 MENU=['Autoscale','Spline','Data','Standards','Exit'];
292 menus = list(MENU,menu_s,menu_o,menu_d,menu_t,menu_e);
295 w='menus(3)(';r=')';Orderm=w(ones(menu_o))+string(1:size(menu_o,'*'))+r(ones(menu_o))
296 w='menus(4)(';r=')';Datam=w(ones(menu_d))+string(1:size(menu_d,'*'))+r(ones(menu_d))
297 w='menus(5)(';r=')';Standm=w(ones(menu_t))+string(1:size(menu_t,'*'))+r(ones(menu_t))
298 w='menus(6)(';r=')';Exitm=w(ones(menu_e))+string(1:size(menu_e,'*'))+r(ones(menu_e))
300 execstr('Autoscale_'+string(curwin)+'=scam')
301 execstr('Spline_'+string(curwin)+'=Orderm')
302 execstr('Data_'+string(curwin)+'=Datam')
303 execstr('Standards_'+string(curwin)+'=Standm')
304 execstr('Exit_'+string(curwin)+'=Exitm')
306 addmenu(curwin,MENU(1))
307 addmenu(curwin,MENU(2),menu_o)
308 addmenu(curwin,MENU(3),menu_d)
309 addmenu(curwin,MENU(4),menu_t)
310 addmenu(curwin,MENU(5),menu_e)
311 //===================================================================
315 a.data_bounds = rect;
316 a.axes_visible = 'on';
318 xtitle( '', 'time', 'Output' ) ;
320 a.title.font_style=4;
321 a.title.foreground=2;
324 xpolys(xy(:,1),xy(:,2),[-1]); //children(2)
325 xpolys(xy(:,1),xy(:,2),[5]); //children(1)
326 splines = a.children(1).children
327 points = a.children(2).children
328 //---------------------------------------
329 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
331 // -- boucle principale
334 while %t then //=================================================
336 [btn,xc,yc,win,Cmenu] = get_click(); //** see
337 if ((win>0) & (win<>curwin)) then
338 Cmenu="Mouse click is Offside!";
340 if Cmenu==[] then Cmenu='edit',end
341 if (Cmenu=='Exit') |(Cmenu=='Quit' ) then, ipar=[];rpar=[];ok=%f;return; end
342 //-------------------------------------------------------------------
343 if ((Cmenu=='zero order') | (Cmenu=='linear') | (Cmenu=='order 2')| ...
344 (Cmenu=='not_a_knot')| (Cmenu=='periodic')| (Cmenu=='monotone')| ...
345 (Cmenu=='fast')| (Cmenu=='clamped')) then
348 case 'zero order' then
354 case 'not_a_knot' then
366 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
368 //-------------------------------------------------------------------
370 case 'Data Bounds' then
372 [mok, xmn1, xmx1, ymn1, ymx1] = scicos_getvalue('Enter new bounds',['xmin';'xmax'; 'ymin';'ymax'], ..
373 list('vec', 1,'vec', 1,'vec', 1,'vec', 1), string(rectx(:)))
376 if (xmn1 > xmx1 | ymn1 > ymx1) then
377 xinfo('Incorrect bounds')
381 xinfo('X should be positive')
385 a.data_bounds=[xmn1, ymn1; xmx1, ymx1];
388 //drawnow();//show_pixmap();
389 //-------------------------------------------------------------------
390 case 'Autoscale' then
391 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
392 //-------------------------------------------------------------------
393 case 'Periodic signal' then
394 if PeridicOption==1 then, ans0='y',else, ans0='n',end;
395 [mok,myans]=scicos_getvalue('Generating periodic signal',['y/n'],list('str',1),list(ans0));
396 if ((myans=='y')|(myans=='Y')) then,PeridicOption=1,else,PeridicOption=0;end;
397 ipar(3)=PeridicOption;
398 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
399 //-------------------------------------------------------------------
401 [mok,Amp,wp,phase,offset,np1,Sin_exprs2]=scicos_getvalue(' Sine parameters', ...
402 ['Amplitude';'Frequency(rad/sec)'; ...
403 'Phase(rad)';'Bias';'number of points'],list('vec',1,'vec',1,'vec',1, ...
404 'vec',1,'vec',1),Sin_exprs)
405 if np1< 2 then np1=2;end
409 phase=atan(tan(phase));
410 xt=linspace(0,%pi*2/wp,np1)';
411 yt=Amp*sin(wp*xt+phase)+offset;
413 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
416 //-------------------------------------------------------------------
417 case 'sawtooth1' then
418 [mok,sAmp,sTp,sdelay,Sawt1_exprs2]=scicos_getvalue('Sawtooth signal parameters', ...
419 ['Amplitude';'Period';'delay'], ...
420 list('vec',1,'vec',1,'vec',1),Sawt1_exprs)
432 [rpar,ipar]=AutoScale(a,xy,ipar,rpar);
433 Sawt1_exprs=Sawt1_exprs2
435 //-------------------------------------------------------------------
436 case 'sawtooth2' then
437 [mok,sAmp2,sTp2,Sawt2_exprs2]=scicos_getvalue('Sawtooth signal parameters', ...
438 ['Amplitude';'Period'],list('vec',1,'vec',1),Sawt2_exprs)
445 [rpar,ipar]=AutoScale(a,xy,ipar,rpar);
446 Sawt2_exprs=Sawt2_exprs2
448 //-------------------------------------------------------------------
450 [mok,Amp3,Tp3,Pw3,Pd3,Bias3,Pulse_exprs2] = scicos_getvalue('Square wave pulse signal', ...
451 ['Amplitude';'Period (sec)';'Pulse width(% o"+...
452 "f period)';'Phase delay (sec)';'Bias'],list('vec',1, ...
453 'vec',1,'vec',1,'vec',1,'vec',1),Pulse_exprs);
457 if (Pd3>0) then xt=0;yt=Bias3;else xt=[];yt=[]; end
458 //otherwise there would be double points at 0
461 xt=[xt;Pd3; Pw3*Tp3/100+Pd3;Tp3];
462 yt=[yt;Amp3+Bias3;Bias3;Bias3];
464 xt=[0;Tp3];yt=[Bias3;Bias3];
467 xt=[0;Tp3];yt=[Bias3;Bias3];
471 [rpar,ipar]=AutoScale(a,xy,ipar,rpar);
472 Pulse_exprs=Pulse_exprs2;
474 //-------------------------------------------------------------------
475 case 'random normal' then
476 [mok,mean4,var4,seed4,sample4,np4,random_n_exprs2]=scicos_getvalue('Normal (Gaussian) random signal', ...
477 ['Mean';'Variance';'Initial seed';'Sample time';'Number of points'],list('vec',1, ...
478 'vec',1,'vec',1,'vec', ...
479 1,'vec',1),random_n_exprs)
480 if mok & sample4>0 then
483 rand('normal'); rand('seed',seed4);
484 xt=0:sample4:sample4*(np4-1);xt=xt(:);
485 yt=mean4+sqrt(var4)*rand(np4,1);
487 [rpar,ipar]=AutoScale(a,xy,ipar,rpar);
488 random_n_exprs2=random_n_exprs;
490 //-------------------------------------------------------------------
491 case 'random uniform' then
492 [mok,min5,max5,seed5,sample5,np5,random_u_exprs2]=scicos_getvalue('Uniform random signal', ...
493 ['Minimum';'Maximum';'Initial seed';'Sample time';'Number of points'],list('vec',1, ...
494 'vec',1,'vec',1,'vec', ...
495 1,'vec',1),random_u_exprs)
496 if mok & sample5>0 then
499 rand('uniform'); rand('seed',seed5);
500 xt=0:sample5:sample5*(np5-1);xt=xt(:);
501 yt=min5+(max5-min5)*rand(np5,1);
503 [rpar,ipar]=AutoScale(a,xy,ipar,rpar);
504 random_u_exprs2=random_u_exprs;
507 //-------------------------------------------------------------------
508 case 'Save/Exit' then
510 PeridicOption=ipar(3);
512 METHOD=getmethod(NOrder);
513 if (METHOD=='periodic') then // periodic spline
517 if (METHOD=='order 2' | METHOD=='not_a_knot'|METHOD=='periodic' | METHOD=='monotone'| METHOD=='fast' | METHOD=='clamped') then
518 rpar=[xy(:,1);xy(:,2);rpar];
520 if (METHOD=='zero order'|METHOD=='linear')
521 rpar=[xy(:,1);xy(:,2);]
528 //-------------------------------------------------------------------
529 case 'Exit without save' then
535 //-------------------------------------------------------------------
540 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
541 //----------------------------------------------------------------
542 case 'Edit text data NOT IN USE' then
544 [mok,xt,yt]=scicos_getvalue('Enter x and y data',['x';'y'],list('vec',-1,'vec',-1),list(strcat(sci2exp(xy(:,1))),strcat(sci2exp(xy(:,2)))));
548 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
550 //---------------------------------------------------------------
552 t1='Mouse-left click: adding a new point'
553 t2='Mouse-right click: remove a point'
554 t3='Mouse-left double click: edit a point''s coordinates'
555 t4='Mouse-left button press/drag/release: move a point'
556 t5='Change the window size: ''Data'' menu -> ''Databounds'''
557 messagebox([t1;t2;t3;t4;t5],"modal","info");
558 //---------------------------------------------------------------
559 case 'Load from Excel' then
560 [tok,xytt]=ReadExcel()
565 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
567 //---------------------------------------------------------------
568 case 'Load from text file' then
569 [tok,xytt]=ReadFromFile()
574 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
576 //---------------------------------------------------------------
577 case 'Save to text file' then
579 //---------------------------------------------------------------
584 [rpar,ipar]=drawSplin(a,xy,ipar,rpar);
587 //----------------------------------------------------------
591 xt=xy(:,1);yt=xy(:,2);
592 dist=((xt-ones(N,1)*xc))^2+((yt-ones(N,1)*yc))^2
595 ex=abs(rectx(2,1)-rectx(1,1))/80;
596 ey=abs(rectx(2,2)-rectx(1,2))/80;
597 if (abs(xc-xt(k))<ex & abs(yc-yt(k))<ey) then
602 //_________________________
603 // if ~((NOrder==-1|NOrder==-2|NOrder==-3|NOrder==-4)) then
604 if (~HIT)&(btn==0 | btn==3) then // add point
611 [xtt,k2]=gsort(xy(:,1),'r','i');xy=xy(k2,:)
614 [rpar,ipar]=drawSplin(a,xy,ipar,rpar);
619 if (HIT)&(btn==2 | btn==5) then // remove point
620 if (xy(k,1)>0) |( xy(k,1)==0 & (size(find(xy(:,1)==0),'*')>1)) then
625 [rpar,ipar] = drawSplin(a,xy,ipar,rpar);
629 if (HIT)&(btn==0) then // move point
630 [xy,rpar,ipar] = movept(a,xy,ipar,rpar,k)
633 if (HIT)&(btn==10) then // change data:: double click
634 [mok,xt,yt]=scicos_getvalue("Enter new x and y",['x';'y'],...
635 list('vec',1,'vec',1),list(sci2exp(xy(k,1)),sci2exp(xy(k,2))));
641 [rpar,ipar]=AutoScale(a,xy,ipar,rpar)
647 //_________________________________
650 //----------------------------------------------------------
653 //========================================================================
654 function [orpar,oipar] = drawSplin(a,xy,iipar,irpar)
655 N=size(xy,'r');// new size of xy
656 x=xy(:,1); y=xy(:,2);
657 points=a.children(2).children
658 splines=a.children(1).children
660 periodicoption=iipar(3);
663 METHOD=getmethod(order);
665 if periodicoption==1 then PERIODIC='periodic, T='+string(x(N)-x(1));
666 else PERIODIC='aperiodic';end
667 a.title.text=[string(N)+' points, '+'Method: '+METHOD+', '+PERIODIC];
669 if (N==0) then, return; end
670 if (N==1) then, order=0; end
671 // NP=50;// number of intermediate points between two data points
672 [X,Y,orpar]=Do_Spline(N,order,x,y);
673 if (periodicoption==1) then
677 xmx=max(points.data(:,1)); xmn=min(points.data(:,1));
678 XMX=max(0,xmx); XMN=max(0,xmn);
679 xmx1=max(a.x_ticks.locations)
684 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
686 oipar=[N;iipar(2);periodicoption]
688 //=============================================================
689 function [xyt,orpar,oipar]=movept(a,xy,iipar,irpar,k)
690 //on bouge un point existant
691 points=a.children(2).children
692 splines=a.children(1).children
696 x=xy(:,1); y=xy(:,2);
710 while ~(btn==3 | btn==0| btn==10| btn==-5)
711 rep=xgetmouse([%t %t]); xc=rep(1);yc=rep(2);btn=rep(3);
725 [xt,k2]=gsort(xt,'r','i');yt=yt(k2)
730 [orpar,oipar]=drawSplin(a,xyt,oipar,orpar);
736 //==========================================================
737 function rectx = findrect(a)
738 splines=a.children(1).children
739 points=a.children(2).children
741 if (points.data==[]) then
747 ymx1=max(splines.data(:,2)); ymn1=min(splines.data(:,2))
749 xmx=max(points.data(:,1));xmn=min(points.data(:,1));
750 ymx=max(points.data(:,2));ymn=min(points.data(:,2));
753 XMX=max(0,xmx); XMN=max(0,xmn);
754 YMX=max(ymx,ymx1); YMN=min(ymn,ymn1);
756 dx=XMX-XMN;dy=YMX-YMN
757 if dx==0 then dx=max(XMX/2,1),end;
759 if dy==0 then dy=max(YMX/2,1),end;
760 YMN=YMN-dy/50;YMX=YMX+dy/50;
761 rectx=[XMN,YMN;XMX,YMX];
764 //============================================================
765 function [tok,xyo]=ReadExcel()
766 TA=['A';'B';'C';'D';'E';'F';'G';'H';'I';'J';'K';'L';'M';'N';'O';'P'; ...
767 'Q';'R';'S';'T';'U';'V';'W';'X';'Y';'Z';'a';'b';'c';'d';'e';'f'; ...
768 'g';'h';'i';'j';'k';'l';'m';'n';'o';'p';'q';'r';'s';'t';'u';'v'; ...
770 TN=['0','1','2','3','4','5','6','7','8','9'];
773 [zok,filen,sheetN,xa,ya]=scicos_getvalue('Excel data file ',['Filename';'Sheet #"+...
774 " ';'X[start:Stop]';'Y[start:stop]'],list('str',1, ...
777 list(['Classeur1.xls'],['1'],['C5:C25'],['D5:D25']));
778 if ~zok then break,end
781 [fd,SST,Sheetnames,Sheetpos] = xls_open(filen);
783 xinfo('Scicos canot find the excel file:'+filen);
787 N=size(Sheetnames,'*');
788 if ((sheetN<=N) &(sheetN>0)) then
789 [Value,TextInd] = xls_read(fd,Sheetpos(sheetN))
792 xa=strsubst(xa,' ',''); px=strindex(xa,':');
793 ya=strsubst(ya,' ',''); py=strindex(ya,':');
794 x1=part(xa,1:px-1); x2=part(xa,px+1:length(xa));
795 y1=part(ya,1:py-1); y2=part(ya,py+1:length(ya));
797 x1p=min(strindex(x1,TN));
798 if x1p==[] then, xinfo('Bad address in X:'+x1); break, end
799 x11=part(x1,1:x1p-1);x12=part(x1,x1p:length(x1));
801 x2p=min(strindex(x2,TN));
802 if x2p==[] then, xinfo('Bad address in X:'+x2); break, end
803 x21=part(x2,1:x2p-1);x22=part(x2,x2p:length(x2));
805 y1p=min(strindex(y1,TN));
806 if y1p==[] then, xinfo('Bad address in Y:'+y1); break, end
807 y11=part(y1,1:y1p-1);y12=part(y1,y1p:length(y1));
809 y2p=min(strindex(y2,TN));
810 if y2p==[] then, xinfo('Bad address in Y:'+y2); break, end
811 y21=part(y2,1:y2p-1);y22=part(y2,y2p:length(y2));
815 lx11=length(x11);lx21=length(x21);
816 ly11=length(y11);ly21=length(y21)
817 xstC=0;for i=1:lx11,xstC=xstC+modulo(find(TA==part(x11,lx11-i+1)),26)*26^(i-1);end
818 xenC=0;for i=1:lx21,xenC=xenC+modulo(find(TA==part(x21,lx21-i+1)),26)*26^(i-1);end
819 ystC=0;for i=1:ly11,ystC=ystC+modulo(find(TA==part(y11,ly11-i+1)),26)*26^(i-1);end
820 yenC=0;for i=1:ly11,yenC=yenC+modulo(find(TA==part(y21,ly21-i+1)),26)*26^(i-1);end
829 if ~(xstR<=mv & xstR>0 & xenR<=mv & xenR>0&ystR<=mv & ystR>0¥R<=mv¥R>0 ) then
830 xinfo('error in Row data addresses'); break
832 if ~(xstC<=nv & xstC>0 & xenC<=nv & xenC>0&ystC<=nv & ystC>0¥C<=nv¥C>0 ) then
833 xinfo('error in Column data addresses'); break
836 xo=Value(min(xstR,xenR):max(xstR,xenR),min(xstC,xenC):max(xstC,xenC));
837 yo=Value(min(ystR,yenR):max(ystR,yenR),min(ystC,yenC):max(ystC,yenC));
838 [nx,mx]=size(xo);// adjusting the x and y size
849 xinfo(' Scicos cannot read your Excel file, please verify"+...
856 //---------------------------------------------------------------
857 function [xyo]=cleandata(xye)
861 [nx,mx]=size(xe);// adjusting the x and y size
867 // checking for NULL data
869 if (xe(i)<>xe(i)) then
870 xinfo('x contains no data:x('+string(i)+')');
873 if (ye(i)<>ye(i)) then
874 xinfo('Y contains no data:y('+string(i)+')');
878 zz=find(xe<0);xe(zz)=[];ye(zz)=[]
879 if (find(xe==0)==[]) then // add zero point
884 [xo,k2]=gsort(xe,'r','i');
889 //---------------------------------------------------------------
890 function [orpar,oipar] = AutoScale(a,xy,inipar,inrpar)
894 points = a.children(2).children
895 splines = a.children(1).children
898 [orpar,oipar] = drawSplin(a,xy,oipar,orpar);
900 a.data_bounds = rectx;
903 //============================
904 function METHOD = getmethod(order)
906 case 0 then, METHOD='zero order'
907 case 1 then, METHOD='linear'
908 case 2 then, METHOD='order 2'
909 case 3 then, METHOD='not_a_knot'
910 case 4 then, METHOD='periodic'
911 case 5 then, METHOD='monotone'
912 case 6 then, METHOD='fast'
913 case 7 then, METHOD='clamped'
916 //=======================================
917 function [sok,xye] = ReadFromFile()
920 [sok,filen,Cformat,Cx,Cy]=scicos_getvalue('Text data file ',['Filename';'Reading [C] f"+...
921 "ormat';'Abscissa column';'Output"+...
922 " column'],list('str',1,'str',1,'vec',1,'vec',1), ...
923 list(['mydatafile.dat'],['%g %g'],['1'],['2']));
924 if ~sok then break,end
925 px=strindex(Cformat,'%');
927 if NC==[] then, xinfo("Bad format in reading data file");sok=%f;break;end
931 Lx=mfscanf(-1,fd,Cformat);
934 xinfo("Scicos canot open the data file: " + filen);
939 if ((mD==0) | (nD==0)) then, xinfo("No data read");sok=%f;break;end
940 if (mD<>NC) then, xinfo('Bad format');sok=%f;break;end
942 xe=Lx(:,Cx);ye=Lx(:,Cy);
948 //=======================================
949 function [sok]=SaveToFile(xye)
954 [sok,filen,Cformat]=scicos_getvalue('Text data file ',['Filename';'Writing [C] f"+...
955 "ormat'],list('str',1,'str',1), ...
956 list(['mydatafile.dat'],['%g %g']));
957 if ~sok then break,end
958 px=strindex(Cformat,'%');
960 if NC<>2 then, xinfo("Bad format in writing data file");sok=%f;break;end
962 Cformat=Cformat+'\n';
966 mfprintf(fd,Cformat,xe,ye);
969 xinfo('Scicos canot open the data file:'+filen);
976 //=========================================================
977 function [X,Y,orpar]=Do_Spline(N,order,x,y)
980 METHOD=getmethod(order);
982 if (METHOD=='zero order') then
985 X=[X;x(i);x(i+1);x(i+1)];
986 Y=[Y;y(i);y(i);y(i+1)];
990 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
991 if (METHOD=='linear') then
999 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1000 if (N<25) then NP=10;else
1001 if (N<50) then NP=5;else
1002 if (N<100) then NP=2;else
1003 if (N<200) then NP=1;else
1007 X=[X;linspace(x(i),x(i+1),NP+2)']; // pour tous sauf "linear" et "zero order"
1009 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1010 if (N>2) & (METHOD=='order 2') then
1018 if X(j)>=x(i) then,break;end
1020 Y(j)=A(i)*(X(j)-x(i))^2+B(i)*(X(j)-x(i))+C(i);
1022 orpar=matrix(Z,-1,1)
1024 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1025 if (METHOD=='not_a_knot') then
1027 d = splin(x, y, METHOD);
1028 Y = interp(X, x, y, d);
1031 xinfo('ERROR in SPLINE: '+METHOD)
1035 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1036 if (METHOD=='periodic') then
1041 d = splin(x, y,METHOD);
1042 Y = interp(X, x, y, d);
1045 xinfo('ERROR in SPLINE: '+METHOD)
1048 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1049 if (METHOD=='monotone' ) then
1051 d = splin(x, y, METHOD);
1052 Y = interp(X, x, y, d);
1055 xinfo('ERROR in SPLINE: '+METHOD)
1059 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1060 if (METHOD=='fast') then
1062 d = splin(x, y, METHOD);
1063 Y = interp(X, x, y, d);
1066 xinfo('ERROR in SPLINE: '+METHOD)
1069 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1070 if (METHOD=='clamped') then
1072 d = splin(x, y, METHOD,[0;0]);
1073 Y = interp(X, x, y, d);
1076 xinfo('ERROR in SPLINE: '+METHOD)
1081 //=================================================
1082 function [Z]=ORDER2(x,y)
1090 A(j+1,i)=(x(i+1)-x(i))^2;
1091 A(j+1,i+N)=x(i+1)-x(i);
1098 A(j+2,i)=2*(x(i+1)-x(i));
1105 Q(i,i)=4*(x(i+1)-x(i))^2
1106 Q(i,i+N)=2*(x(i+1)-x(i))
1107 Q(i+N,i)=2*(x(i+1)-x(i))
1111 At=[Q,A';A,zeros(3*N-1,3*N-1)]
1116 //===================================================