package Jampack;
/**
Print prints numbers, matrices, and arrays. All floating-point
numbers are printed in e format with field width w and d figures
to the left of the right of the decimal point. For the defaults
see Parameters .
@version Pre-alpha
@author G. W. Stewart
*/
public class Print{
private static java.text.DecimalFormat fmt = new java.text.DecimalFormat();
/**
Prints an int in default format.
*/
public static void o(int k){
o(k, Parameters.OutputFieldWidth);
}
/**
Prints and int in a field of width w.
*/
public static void o(int k, int w){
System.out.print("\n");
String num = Integer.toString(k);
while (num.length() < w)
num = " " + num;
System.out.print(num);
System.out.print("\n");
}
/**
Prints an integer array in default format.
*/
public static void o(int ia[]){
o(ia, Parameters.OutputFieldWidth);
}
/**
Prints an integer array in fields of width w.
*/
public static void o(int ia[], int w){
int n = ia.length;
int ncp = Parameters.PageWidth/w;
int jl = 0;
while (jl < n){
int ju = Math.min(n, jl+ncp);
System.out.print("\n");
for (int j=jl; jZ in default e format.
*/
public static void o(Z[][] A){
o(A, Parameters.OutputFieldWidth, Parameters.OutputFracPlaces);
}
/**
Prints a 2-dimensional array of Z in w.d e format.
*/
public static void o(Z[][] A, int w, int d){
int nr = A.length;
int nc = A[0].length;
String temp = Integer.toString(nr-1);
int rfw = temp.length()+1;
int ww = w+d+10;
int ncp = (Parameters.PageWidth-rfw)/ww;
int jl = 0;
while (jl < nc){
int ju = Math.min(nc, jl+ncp);
System.out.print("\n");
String head = "";
while(head.length() < rfw)
head = head + " ";
System.out.print(head);
for (int j=jl; jZmat in default e format.
*/
public static void o(Zmat A){
o(A, Parameters.OutputFieldWidth, Parameters.OutputFracPlaces);
}
/**
Prints a Zmat in w.d e format. This method checks to
see if the Zmat is real, in which case it prints only the real part.
*/
public static void o(Zmat A, int w, int d){
int nr = A.nrow;
int nc = A.ncol;
A.getProperties();
/* Check to see if the matrix is real. */
boolean real = true;
real: for (int i=A.bx; i<=A.rx; i++){
for (int j=A.bx; j<=A.cx; j++){
if (A.im[i-A.bx][j-A.bx] != 0.){
real = false;
break real;
}
}
}
if (!real){
String temp = Integer.toString(nr+A.bx-1);
int rfw = temp.length()+1;
int ww = w+d+10;
int ncp = (Parameters.PageWidth-rfw)/ww;
int jl = 0;
while (jl < nc){
int ju = Math.min(nc, jl+ncp);
System.out.print("\n");
String head = "";
while(head.length() < rfw)
head = head + " ";
System.out.print(head);
for (int j=jl; j 10. - Math.pow(10., -d)){
frac = frac/10;
exp = exp + 1;
}
fmt.setMaximumFractionDigits(d);
fmt.setMinimumFractionDigits(d);
fmt.setGroupingUsed(false);
String sfrac = fmt.format(frac);
if (exp < 0){
minuse = true;
exp = -exp;
}
String sexp = Integer.toString(exp);
snum = sexp;
if (snum.length() < 2)
snum = "0" + snum;
if (minuse)
snum = "e-" + snum;
else
snum = "e+" + snum;
snum = sfrac + snum;
if (minusf)
snum = "-" + snum;
}
while (snum.length() < w)
snum = " " + snum;
return snum;
}
/**
Converts a Z to w.d e format.
*/
public static String ZtoEstring(Z num, int w, int d){
String snum = DoubletoEstring(num.re, w, d);
if (num.im < 0)
snum = snum + " - " +
DoubletoEstring(-num.im, d+6, d) + "i";
else
snum = snum + " + " +
DoubletoEstring(num.im, d+6, d) + "i";
return snum;
}
}