home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------
- //
- // printsys
- //
- // Syntax: printsys(a,b,c,d,ulabels,ylabels,xlabels)
- //
- // This routine prints state space systems with labels above the matrices
- // and to the left of the matrix. It can also print a transfer function
- // model by printing the ratio of the polynomials.
- //
- // If it is called as printsys(a,b,c,d,ulabels,ylabels,xlabels) then the
- // state-space model given by a,b,c,d is printed with input, output, and
- // state labels contained in ulabels,ylabels,xlabels respectively. Note:
- // the labels are vectors of strings, such as:
- //
- // ylabels[1]="phi"
- // ylabels[2]="theta"
- // ylabels[3]="psi"
- //
- // If it is called as printsys(a,b,c,d) then the system is written with
- // numerical labels for the matrices.
- //
- // If it is called for transfer functions such as printsys(num,den,"s")
- // then the transfer function is printed as a ration of two polynomials
- // in the transform variables "s"
- //
- // Copyright (C), by Jeffrey B. Layton, 1994
- // Version JBL 940513
- //----------------------------------------------------------------------------
-
- rfile tfchk
- rfile abcdchk
- // rfile printmat
- rfile poly2str
-
- printsys = function(a,b,c,d,ulab,ylab,xlab)
- {
- local(A,tvar,msg,estr,B,s,dlen,t,nlen,itop,len,sdum,...
- stmp,i,j,narg,num,nc,mn,nn,den,ulab,ylab,xlab)
-
- len = 12; // Label parameter. Should match parameter in PRINTMAT.
-
- // Count the number of input arguments
- narg=0;
- if (exist(a)) {narg=narg+1;}
- if (exist(b)) {narg=narg+1;}
- if (exist(c)) {narg=narg+1;}
- if (exist(d)) {narg=narg+1;}
- if (exist(ulab)) {narg=narg+1;}
- if (exist(ylab)) {narg=narg+1;}
- if (exist(xlab)) {narg=narg+1;}
-
- // --- Determine which syntax is being used ---
- if (narg == 2) {
- A=tfchk(a,b);
- num=A.numc;
- den=A.denc;
- tvar="s";
- else if (narg == 3) {
- A=tfchk(a,b);
- num=A.numc;
- den=A.denc;
- if ( c.class != "string") {
- error("printsys: Transfrom variable must be a string.");
- }
- tvar=c;
- else if (narg == 4) {
- msg="";
- msg=abcdchk(a,b,c,d);
- if ( msg != "" ) {
- estr="printsys: "+msg;
- error(estr);
- }
- if (a.nr > 0) {
- nc=c.nc;
- else
- }
-
- for (i in 1:a.nr) {
- sprintf(sdum,"%3.0f",i);
- xlab[i]="x"+sdum;
- }
- printmat(a,"a",xlab,xlab);
- for (i in 1:b.nc) {
- sprintf(sdum,"%3.0f",i);
- ylab[i]="y"+sdum;
- }
- printmat(b,"b",xlab,ulab);
- for (i in 1:c.nr) {
- sprintf(sdum,"%3.0f",i);
- ulab[i]="u"+sdum;
- }
- printmat(c,"c",ylab,xlab);
- printmat(c,"d",ylab,ulab);
- else if ( (narg == 5) || (narg == 6) ) {
- error("printsys: Wrong number of arguments.");
- else
- msg="";
- msg=abcdchk(a,b,c,d);
- if (msg != "") {
- estr="printsys: "+msg;
- error(estr);
- }
- if ( ulab.class != "string" ) {
- error("printsys: ULAB must be a string.");
- }
- if ( ylab.class != "string" ) {
- error("printsys: YLAB must be a string.");
- }
- if ( xlab.class != "string" ) {
- error("printsys: XLAB must be a string.");
- }
-
- // Put labels into format for PRINTMAT
- printmat(a,"a",xlab,xlab);
- printmat(b,"b",xlab,ulab);
- printmat(c,"c",ylab,xlab);
- printmat(d,"d",ylab,ulab);
- }}}}
-
- if ( (narg == 2) || (narg == 3) ) {
- nn=num.nr;
- mn=num.nc;
- B=poly2str(den,tvar);
- s=B.s;
- dlen=B.len;
-
- for (i in 1:nn) {
- B=poly2str(num[i;],tvar);
- t=B.s;
- nlen=B.len;
-
- // Now print the polynomials
- len=max([dlen,nlen])-3;
- printf("%s"," \n");
- if (nn == 1) {
- printf("%s"," num/den = \n");
- else
- stmp="";
- stmp="num("+int2str(i)+"(/den = \n";
- printf("%s",stmp);
- }
- printf("%s"," \n");
- if (length(t) < len+3) {
- stmp="";
- itop=(len+4-length(t))/2;
- for (j in 1:itop) {
- stmp=stmp+" ";
- }
- stmp=stmp+t;
- stmp=stmp+"\n";
- printf("%s",stmp);
- else
- t=t+"\n";
- printf("%s",t);
- }
- stmp=" ";
- for (j in 1:len) {
- stmp=stmp+"-";
- }
- stmp=stmp+"\n";
- printf("%s",stmp);
- if (length(s) < len+3) {
- itop=(len+4-length(s))/2;
- for (j in 1:itop) {
- stmp=stmp+" ";
- }
- stmp=stmp+s;
- stmp=stmp+"\n";
- printf("%s",stmp);
- else
- printf("%s",s);
- printf("%s"," \n");
- }
- }
- }
-
- printf("%s"," \n");
-
- return 0;
- };
-