#include #include #include #include #include #include #include #include #include "kbd_keys.h" #include "ml.h" #define UNDEFINED (22222) #define MAXREAL (3.0E38) double lesspwr10(double x) { double y=1E15; int k; x=fabs(x); while( y > x ) y /= 10.0; k=x/y+0.001; if(k < 2) y /= 2.0; else if(k >= 6) y *= 2.0; return y; } int getvals(double min, double max, double *vals) { int i; double d,v; d=lesspwr10(max-min); for(v=0.0,i=0; v > min && i < 10; v -= d) vals[i++]=v; for(v=d; v < max && i < 10; v += d) vals[i++]=v; vals[i]=d; return i; } void real2str(double l, char *str) { sprintf(str,"%lf",l); } void int2str(long l, char *str) { sprintf(str,"%ld",l); } void traectoria(double*X, double*Y, int fromI, int toI, int ixmin, int iymin, int ixmax, int iymax, char *xname, char *yname, char *header) { int i,j,k,x,y,ix0,iy0,curx=0,cury=0,oldx=0,oldy=0,n; double vals[10]; double xmin,xmax,ymin,ymax,Rx,Ry; string str; init_graph("c:\\tc\\utilits"); setcolor(GREEN); xmin=0.0; xmax=0.000001; ymin=0.0; ymax=0.000001; for(i=fromI; i < toI; i++) { Rx = X[i]; if(xmin > Rx) xmin=Rx; else if(xmax < Rx) xmax=Rx; Ry = Y[i]; if(ymin > Ry) ymin=Ry; else if(ymax < Ry) ymax=Ry; } xmax *= 1.2; ymax *= 1.2; xmin *= 1.2; ymin *= 1.2; setlinestyle(SOLID_LINE,0,THICK_WIDTH); rectangle(ixmin,iymin,ixmax,iymax); setlinestyle(SOLID_LINE,0,NORM_WIDTH); ixmin+=30; ix0 = -xmin*(ixmax-ixmin)/(xmax-xmin)+ixmin; iy0 = ymax*(iymax-iymin)/(ymax-ymin)+iymin; line(ixmin,iy0,ixmax,iy0); outtextxy(ixmax-textwidth(xname)-5,iy0+15,xname); line(ix0,iymax,ix0,iymin); outtextxy(ix0-20,iymin+10,yname); /****** Y ******/ n=getvals(ymin,ymax,vals); for(i=0; i < n; i++){ y=-(vals[i]-ymin)/(ymax-ymin)*(iymax-iymin)+iymax; line(ix0-3,y,ix0+3,y); if(fabs(vals[n]) >= 100) { int2str(vals[i],str); for(k=strlen(str)-1; str[k] == ' '; ) str[k--]='\0'; } else { sprintf(str,"%f",vals[i]); for(k=strlen(str)-1; str[k] == '0'; ) str[k--]='\0'; if(str[k] == '.') str[k] = '\0'; } outtextxy(ix0-5-textwidth(str),y-10,str); } /****** X ******/ n=getvals(xmin,xmax,vals); for(i=0; i < n; i++){ x=(vals[i]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin; line(x,iy0-3,x,iy0+3); if(fabs(vals[n]) >= 100) { int2str(vals[i],str); for(k=strlen(str)-1; str[k] == ' '; ) str[k--]='\0'; } else { sprintf(str,"%f",vals[i]); for(k=strlen(str)-1; str[k] == '0'; ) str[k--]='\0'; if(str[k] == '.') str[k] = '\0'; } outtextxy((vals[i]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin,iy0+5,str); } for(j=fromI; j < toI; j++){ curx=(X[j]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin; cury=-(Y[j]-ymin)/(ymax-ymin)*(iymax-iymin)+iymax; if((j != fromI) && (Y[j-1] != UNDEFINED)) line(oldx,oldy,curx,cury); if(j == fromI+i+1) { sprintf(str,"%d",i+1); outtextxy(curx,cury,str); } oldx=curx; oldy=cury; circle(curx,cury,3); } } static int line_styles[]={ 0xFFFF, 0xAAAA, 0xF0F0, 0x6666, 0x0000 }; void traectories(double *X, double **Y, int fromI, int toI, int Ny, int ixmin, int iymin, int ixmax, int iymax, char *xname, char *yname, char *header) { int i,j,k,x,y,ix0,iy0,curx=0,cury=0,oldx=0,oldy=0,n; double vals[10]; double xmin,xmax,ymin,ymax,Rx,Ry; char str[256]; init_graph("c:\\tc\\utilits"); setcolor(GREEN); xmin=MAXREAL; xmax=-MAXREAL; ymin=MAXREAL; ymax=-MAXREAL; for(i=fromI; i < toI; i++) { Rx = X[i]; if(xmin > Rx) xmin=Rx; else if(xmax < Rx) xmax=Rx; for(j=0; j < Ny; j++){ Ry = Y[j][i]; if(ymin > Ry) ymin=Ry; else if(ymax < Ry) ymax=Ry; } } xmax *= 1.2; ymax *= 1.2; xmin *= 1.2; ymin *= 1.2; /* setlinestyle(SOLID_LINE,0,THICK_WIDTH); rectangle(ixmin,iymin,ixmax,iymax); */ setlinestyle(SOLID_LINE,0,NORM_WIDTH); ixmin+=30; ix0 = /* *** -xmin*(ixmax-ixmin)/(xmax-xmin)+ *** */ixmin; iy0 = ymax*(iymax-iymin)/(ymax-ymin)+iymin; line(ixmin,iy0,ixmax,iy0); outtextxy(ixmax-textwidth(xname)-5,iy0+15,xname); line(ix0,iymax,ix0,iymin); outtextxy(ix0-20,iymin+10,yname); /****** Y ******/ n=getvals(ymin,ymax,vals); for(i=0; i < n; i++){ y=-(vals[i]-ymin)/(ymax-ymin)*(iymax-iymin)+iymax; line(ix0-3,y,ix0+3,y); if(fabs(vals[n]) >= 100) { int2str(vals[i],str); for(k=strlen(str)-1; str[k] == ' '; ) str[k--]='\0'; } else { sprintf(str,"%f",vals[i]); for(k=strlen(str)-1; str[k] == '0'; ) str[k--]='\0'; if(str[k] == '.') str[k] = '\0'; } outtextxy(ix0-5-textwidth(str),y-10,str); } /****** X ******/ n=getvals(xmin,xmax,vals); for(i=0; i < n; i++){ x=(vals[i]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin; line(x,iy0-3,x,iy0+3); if(fabs(vals[n]) >= 100) { int2str(vals[i],str); for(k=strlen(str)-1; str[k] == ' '; ) str[k--]='\0'; } else { sprintf(str,"%f",vals[i]); for(k=strlen(str)-1; str[k] == '0'; ) str[k--]='\0'; if(str[k] == '.') str[k] = '\0'; } outtextxy((vals[i]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin,iy0+5,str); } for(j=0; j < Ny; j++){ setlinestyle(USERBIT_LINE,line_styles[j],NORM_WIDTH); for(i=fromI; i < toI; i++){ curx=(X[i]-xmin)/(xmax-xmin)*(ixmax-ixmin)+ixmin; cury=-(Y[j][i]-ymin)/(ymax-ymin)*(iymax-iymin)+iymax; if((i != fromI) && (Y[j][i-1] != UNDEFINED)) line(oldx,oldy,curx,cury); if(i == fromI+j+1) { sprintf(str,"%d",j+1); outtextxy(curx,cury,str); } oldx=curx; oldy=cury; circle(curx,cury,3); } } }