0001: /*
0002: * Created on Dec 4, 2004
0003: *
0004: */
0005: package org.jmatlab.toolbox;
0006:
0007: import java.io.FileWriter;
0008: import java.io.IOException;
0009: import java.io.PrintStream;
0010: import java.io.File;
0011: import java.util.ArrayList;
0012: import java.util.*;
0013: import org.jmatlab.linalg.IMatrix;
0014: import org.jmatlab.semantic.SemanticException;
0015:
0016: /**
0017: * @author Ali
0018: *
0019: */
0020: public class Plot {
0021:
0022: private static PrintStream out;
0023: private static String gnuplot = "c:\\jmatlab\\jmatlab\\InstallDir\\bin\\pgnuplot.exe";
0024: private static boolean isOnHold = false;
0025: private static boolean isGridOn = false;
0026: private static String lastFileName;
0027: private static List fileList = new ArrayList();
0028: private static String lastCommand;
0029: private static int lineNum = 1;
0030: private static List lastPlotCommands = new ArrayList();
0031: private static List lastRePlotCommands = new ArrayList();
0032:
0033: static {
0034: Process p = null;
0035: try {
0036: p = Runtime.getRuntime().exec(gnuplot);
0037: } catch (IOException e) {
0038: e.printStackTrace();
0039: }
0040: out = new PrintStream(p.getOutputStream());
0041: }
0042:
0043: private static void gplot(List cmds) {
0044: Iterator iter = cmds.iterator();
0045: while (iter.hasNext()) {
0046: out.println((String) iter.next());
0047: }
0048: out.flush();
0049: }
0050:
0051: private static void fplot(String s) {
0052: resetAllLabels();
0053: if (isOnHold) {
0054: String ps = "re" + s;
0055: lastRePlotCommands.add(ps);
0056: gplot(ps);
0057: } else {
0058: lastPlotCommands.add(s);
0059: gplot(s);
0060: }
0061: }
0062:
0063: public static void FPLOT(String s) {
0064: fplot("plot " + s);
0065: }
0066:
0067: public static void FPLOT(String s, String xrange) {
0068: fplot("plot " + xrange + " " + s);
0069: }
0070:
0071: public static void FPLOT(String s, String xrange, String yrange) {
0072: fplot("plot " + xrange + " " + yrange + " " + s);
0073: }
0074:
0075: public static void FPLOT(String s, String xrange, String yrange,
0076: String fmt) {
0077: fplot("plot " + xrange + " " + yrange + " " + s + " "
0078: + options(fmt));
0079: }
0080:
0081: private static void gplot(String s) {
0082: out.println(s);
0083: out.flush();
0084: }
0085:
0086: private static void resetToAutoScale() {
0087: gplot("set autoscale xyz");
0088: }
0089:
0090: private static void setXRange(double min, double max) {
0091: gplot("set xrange [" + min + ":" + max + "]");
0092: }
0093:
0094: private static void setYRange(double min, double max) {
0095: gplot("set yrange [" + min + ":" + max + "]");
0096: }
0097:
0098: private static void setZRange(double min, double max) {
0099: gplot("set zrange [" + min + ":" + max + "]");
0100: }
0101:
0102: public static void GRID(String s) {
0103: if ("ON".equalsIgnoreCase(s)) {
0104: isGridOn = true;
0105: gplot("set grid");
0106: } else if ("OFF".equalsIgnoreCase(s)) {
0107: isGridOn = false;
0108: gplot("unset grid");
0109: } else {
0110: throw new SemanticException("Correct usage: grid on/off");
0111: }
0112: refreshPlot();
0113: }
0114:
0115: public static void HOLD(String s) {
0116: if ("ON".equalsIgnoreCase(s)) {
0117: isOnHold = true;
0118: } else if ("OFF".equalsIgnoreCase(s)) {
0119: isOnHold = false;
0120: } else {
0121: throw new SemanticException("Correct usage: hold on/off");
0122: }
0123: }
0124:
0125: public static void AXIS(IMatrix m) {
0126: int size = m.getCols();
0127: if (size != 2 && size != 4 && size != 6) {
0128: throw new SemanticException(
0129: "Correct usage: axis([xmin, xmax, ymin, ymax, zmin, zmax])");
0130: }
0131: double[] d = m.getRealRow(1);
0132: if (size >= 2) {
0133: double xmin = d[0];
0134: double xmax = d[1];
0135: setXRange(xmin, xmax);
0136: }
0137: if (size >= 4) {
0138: double ymin = d[2];
0139: double ymax = d[3];
0140: setYRange(ymin, ymax);
0141: }
0142: if (size >= 6) {
0143: double zmin = d[4];
0144: double zmax = d[5];
0145: setZRange(zmin, zmax);
0146: }
0147: refreshPlot();
0148: }
0149:
0150: public static void AXIS(String s) {
0151: if ("NORMAL".equalsIgnoreCase(s) || "AUTO".equalsIgnoreCase(s)) {
0152: resetToAutoScale();
0153: } else {
0154: throw new SemanticException(
0155: "Correct usage: axis(\"normal\")");
0156: }
0157: refreshPlot();
0158: }
0159:
0160: public static void XLABEL(String s) {
0161: gplot("set xlabel '" + s + "'");
0162: refreshPlot();
0163: }
0164:
0165: public static void YLABEL(String s) {
0166: gplot("set ylabel '" + s + "'");
0167: refreshPlot();
0168: }
0169:
0170: public static void ZLABEL(String s) {
0171: gplot("set zlabel '" + s + "'");
0172: refreshPlot();
0173: }
0174:
0175: public static void TITLE(String s) {
0176: gplot("set title '" + s + "'");
0177: refreshPlot();
0178: }
0179:
0180: /**
0181: *
0182: */
0183: private static void refreshPlot() {
0184: if (isOnHold) {
0185: gplot(lastPlotCommands);
0186: gplot(lastRePlotCommands);
0187: } else {
0188: gplot(lastPlotCommands);
0189: }
0190: }
0191:
0192: private static void resetAllLabels() {
0193: gplot("set autoscale");
0194: gplot("unset xlabel");
0195: gplot("unset ylabel");
0196: gplot("unset zlabel");
0197: gplot("unset title");
0198: String unsetView = "unset view";
0199: gplot(unsetView);
0200: String setContour = "unset contour";
0201: gplot(setContour);
0202: String unsetSurface = "unset surface";
0203: gplot(unsetSurface);
0204: String unsetStyle = "unset style data";
0205: gplot(unsetStyle);
0206: String unsetHidden = "unset hidden3d";
0207: gplot(unsetHidden);
0208: String unsetGrid = "unset grid";
0209: gplot(unsetGrid);
0210: }
0211:
0212: private static void runLastCommand() {
0213: gplot(lastCommand);
0214: }
0215:
0216: private static void setLogScaleX() {
0217: gplot("set logscale x");
0218: }
0219:
0220: private static void setLogScaleY() {
0221: gplot("set logscale y");
0222: }
0223:
0224: private static void setLogScaleZ() {
0225: gplot("set logscale z");
0226: }
0227:
0228: private static void resetLogScale() {
0229: gplot("unset logscale xyz");
0230: }
0231:
0232: private static String save(double[] v) {
0233: File tempFile = null;
0234: try {
0235: tempFile = File.createTempFile("jmatlab_", ".dat");
0236: } catch (IOException e) {
0237: new SemanticException(
0238: "Failed to create temporary file 'jmatlab_*.dat'");
0239: }
0240: tempFile.deleteOnExit();
0241: String fileName = tempFile.getPath();
0242: lastFileName = fileName;
0243: fileList.add(0, fileName);
0244: FileWriter out = null;
0245: try {
0246: out = new FileWriter(tempFile);
0247: } catch (IOException e1) {
0248: new SemanticException("Failed to instantiate FileWriter.");
0249: }
0250: for (int i = 0; i < v.length; i++) {
0251: try {
0252: out.write("" + v[i] + '\t' + v[i] + '\n');
0253: } catch (IOException e2) {
0254: new SemanticException("Failed to write to file.");
0255: }
0256: }
0257: try {
0258: out.close();
0259: } catch (IOException e2) {
0260: new SemanticException("Failed to close File object");
0261: }
0262: return fileName;
0263: }
0264:
0265: private static String saveBarPoints(double[] v) {
0266: File tempFile = null;
0267: try {
0268: tempFile = File.createTempFile("jmatlab_", ".dat");
0269: } catch (IOException e) {
0270: new SemanticException(
0271: "Failed to create temporary file 'jmatlab_*.dat'");
0272: }
0273: tempFile.deleteOnExit();
0274: String fileName = tempFile.getPath();
0275: lastFileName = fileName;
0276: fileList.add(0, fileName);
0277: FileWriter out = null;
0278: try {
0279: out = new FileWriter(tempFile);
0280: } catch (IOException e1) {
0281: new SemanticException("Failed to instantiate FileWriter.");
0282: }
0283: for (int i = 1; i <= v.length; i++) {
0284: try {
0285: out.write("" + (i - 0.25) + '\t' + 0 + '\n');
0286: out.write("" + (i - 0.25) + '\t' + v[i - 1] + '\n');
0287: out.write("" + (i + 0.25) + '\t' + v[i - 1] + '\n');
0288: out.write("" + (i + 0.25) + '\t' + 0 + '\n');
0289: } catch (IOException e2) {
0290: new SemanticException("Failed to write to file.");
0291: }
0292: }
0293: try {
0294: out.close();
0295: } catch (IOException e2) {
0296: new SemanticException("Failed to close File object");
0297: }
0298: return fileName;
0299: }
0300:
0301: private static String saveBarPoints(double[] v, double[] w) {
0302: int size = v.length;
0303: double max = v[size - 1];
0304: double min = v[0];
0305: for (int i = 0; i < size; i++) {
0306: if (v[i] > max) {
0307: max = v[i];
0308: }
0309: if (v[i] < min) {
0310: min = v[i];
0311: }
0312: }
0313: double diff = max - min;
0314: double interval = diff / 20;
0315:
0316: File tempFile = null;
0317: try {
0318: tempFile = File.createTempFile("jmatlab_", ".dat");
0319: } catch (IOException e) {
0320: new SemanticException(
0321: "Failed to create temporary file 'jmatlab_*.dat'");
0322: }
0323: tempFile.deleteOnExit();
0324: String fileName = tempFile.getPath();
0325: lastFileName = fileName;
0326: fileList.add(0, fileName);
0327: FileWriter out = null;
0328: try {
0329: out = new FileWriter(tempFile);
0330: } catch (IOException e1) {
0331: new SemanticException("Failed to instantiate FileWriter.");
0332: }
0333: for (int i = 0; i < v.length; i++) {
0334: try {
0335: out.write("" + (v[i] - interval) + '\t' + 0 + '\n');
0336: out.write("" + (v[i] - interval) + '\t' + w[i] + '\n');
0337: out.write("" + (v[i] + interval) + '\t' + w[i] + '\n');
0338: out.write("" + (v[i] + interval) + '\t' + 0 + '\n');
0339: } catch (IOException e2) {
0340: new SemanticException("Failed to write to file.");
0341: }
0342: }
0343: try {
0344: out.close();
0345: } catch (IOException e2) {
0346: new SemanticException("Failed to close File object");
0347: }
0348: return fileName;
0349: }
0350:
0351: private static String saveStairPoints(double[] v) {
0352: File tempFile = null;
0353: try {
0354: tempFile = File.createTempFile("jmatlab_", ".dat");
0355: } catch (IOException e) {
0356: new SemanticException(
0357: "Failed to create temporary file 'jmatlab_*.dat'");
0358: }
0359: tempFile.deleteOnExit();
0360: String fileName = tempFile.getPath();
0361: lastFileName = fileName;
0362: fileList.add(0, fileName);
0363: FileWriter out = null;
0364: try {
0365: out = new FileWriter(tempFile);
0366: } catch (IOException e1) {
0367: new SemanticException("Failed to instantiate FileWriter.");
0368: }
0369: for (int i = 0; i < v.length - 1; i++) {
0370: try {
0371: out.write("" + i + '\t' + v[i] + '\n');
0372: out.write("" + (i + 1) + '\t' + v[i] + '\n');
0373: } catch (IOException e2) {
0374: new SemanticException("Failed to write to file.");
0375: }
0376: }
0377: try {
0378: out.close();
0379: } catch (IOException e2) {
0380: new SemanticException("Failed to close File object");
0381: }
0382: return fileName;
0383: }
0384:
0385: private static String saveStairPoints(double[] v, double[] w) {
0386: File tempFile = null;
0387: try {
0388: tempFile = File.createTempFile("jmatlab_", ".dat");
0389: } catch (IOException e) {
0390: new SemanticException(
0391: "Failed to create temporary file 'jmatlab_*.dat'");
0392: }
0393: tempFile.deleteOnExit();
0394: String fileName = tempFile.getPath();
0395: lastFileName = fileName;
0396: fileList.add(0, fileName);
0397: FileWriter out = null;
0398: try {
0399: out = new FileWriter(tempFile);
0400: } catch (IOException e1) {
0401: new SemanticException("Failed to instantiate FileWriter.");
0402: }
0403: for (int i = 0; i < v.length - 1; i++) {
0404: try {
0405: out.write("" + v[i] + '\t' + w[i] + '\n');
0406: out.write("" + (v[i + 1]) + '\t' + w[i] + '\n');
0407: } catch (IOException e2) {
0408: new SemanticException("Failed to write to file.");
0409: }
0410: }
0411: try {
0412: out.close();
0413: } catch (IOException e2) {
0414: new SemanticException("Failed to close File object");
0415: }
0416: return fileName;
0417: }
0418:
0419: private static double[] calculateHistPoints(double[] v) {
0420: int size = v.length;
0421: double max = v[size - 1];
0422: double min = v[0];
0423: for (int i = 0; i < size; i++) {
0424: if (v[i] > max) {
0425: max = v[i];
0426: }
0427: if (v[i] < min) {
0428: min = v[i];
0429: }
0430: }
0431: double diff = max - min;
0432: double interval = diff / 10;
0433: diff = max - min + 2 * interval;
0434: interval = diff / 10;
0435: double[] bins = new double[10];
0436: double start = min - interval;
0437: for (int i = 0; i < 10; i++) {
0438: bins[i] = 0.0;
0439: for (int j = 0; j < size; j++) {
0440: if (v[j] > start && v[j] <= start + interval) {
0441: bins[i] = bins[i] + 1.0;
0442: }
0443: }
0444: start = start + interval;
0445: }
0446: return bins;
0447: }
0448:
0449: private static double[] sort(double[] v) {
0450: int size = v.length;
0451: double[] rtn = new double[size];
0452: System.arraycopy(v, 0, rtn, 0, size);
0453: int length = (int) (Math.sqrt(size) + 1.0);
0454: for (int i = 0; i < length; i++) {
0455: for (int j = i; j < size; j++) {
0456: if (rtn[i] > rtn[j]) {
0457: double temp = rtn[i];
0458: rtn[i] = rtn[j];
0459: rtn[j] = temp;
0460: }
0461: }
0462: }
0463: return rtn;
0464: }
0465:
0466: private static String save(double[] v1, double[] v2) {
0467: File tempFile = null;
0468: try {
0469: tempFile = File.createTempFile("jmatlab_", ".dat");
0470: } catch (IOException e) {
0471: new SemanticException(
0472: "Failed to create temporary file 'jmatlab_*.dat'");
0473: }
0474: tempFile.deleteOnExit();
0475: String fileName = tempFile.getPath();
0476: lastFileName = fileName;
0477: fileList.add(0, fileName);
0478: FileWriter out = null;
0479: try {
0480: out = new FileWriter(tempFile);
0481: } catch (IOException e1) {
0482: new SemanticException("Failed to instantiate FileWriter.");
0483: }
0484: for (int i = 0; i < v1.length; i++) {
0485: try {
0486: out.write("" + v1[i] + '\t' + v2[i] + '\n');
0487: } catch (IOException e2) {
0488: new SemanticException("Failed to write to file.");
0489: }
0490: }
0491: try {
0492: out.close();
0493: } catch (IOException e2) {
0494: new SemanticException("Failed to close File object");
0495: }
0496: return fileName;
0497: }
0498:
0499: private static String save(double[] v1, double[] v2, double[] v3) {
0500: File tempFile = null;
0501: try {
0502: tempFile = File.createTempFile("jmatlab_", ".dat");
0503: } catch (IOException e) {
0504: new SemanticException(
0505: "Failed to create temporary file 'jmatlab_*.dat'");
0506: }
0507: tempFile.deleteOnExit();
0508: String fileName = tempFile.getPath();
0509: lastFileName = fileName;
0510: fileList.add(0, fileName);
0511: FileWriter out = null;
0512: try {
0513: out = new FileWriter(tempFile);
0514: } catch (IOException e1) {
0515: new SemanticException("Failed to instantiate FileWriter.");
0516: }
0517: for (int i = 0; i < v1.length; i++) {
0518: try {
0519: out
0520: .write("" + v1[i] + " " + v2[i] + " " + v3[i]
0521: + '\n');
0522: } catch (IOException e2) {
0523: new SemanticException("Failed to write to file.");
0524: }
0525: }
0526: try {
0527: out.close();
0528: } catch (IOException e2) {
0529: new SemanticException("Failed to close File object");
0530: }
0531: return fileName;
0532: }
0533:
0534: private static String saveMesh(double[] v1, double[] v2,
0535: double[][] v3) {
0536: File tempFile = null;
0537: try {
0538: tempFile = File.createTempFile("jmatlab_", ".dat");
0539: } catch (IOException e) {
0540: new SemanticException(
0541: "Failed to create temporary file 'jmatlab_*.dat'");
0542: }
0543: tempFile.deleteOnExit();
0544: String fileName = tempFile.getPath();
0545: lastFileName = fileName;
0546: fileList.add(0, fileName);
0547: FileWriter out = null;
0548: try {
0549: out = new FileWriter(tempFile);
0550: } catch (IOException e1) {
0551: new SemanticException("Failed to instantiate FileWriter.");
0552: }
0553: try {
0554: for (int i = 0; i < v1.length; i++) {
0555: for (int j = 0; j < v2.length; j++) {
0556: out.write("" + v1[i] + '\t' + v2[j] + '\t'
0557: + v3[i][j] + '\n');
0558: }
0559: }
0560: } catch (IOException e) {
0561: new SemanticException("Failed to write to file.");
0562: }
0563: try {
0564: out.close();
0565: } catch (IOException e2) {
0566: new SemanticException("Failed to close File object");
0567: }
0568: return fileName;
0569: }
0570:
0571: private static String saveContour(double[] v1, double[] v2,
0572: double[][] v3) {
0573: File tempFile = null;
0574: try {
0575: tempFile = File.createTempFile("jmatlab_", ".dat");
0576: } catch (IOException e) {
0577: new SemanticException(
0578: "Failed to create temporary file 'jmatlab_*.dat'");
0579: }
0580: tempFile.deleteOnExit();
0581: String fileName = tempFile.getPath();
0582: lastFileName = fileName;
0583: fileList.add(0, fileName);
0584: FileWriter out = null;
0585: try {
0586: out = new FileWriter(tempFile);
0587: } catch (IOException e1) {
0588: new SemanticException("Failed to instantiate FileWriter.");
0589: }
0590: try {
0591: for (int i = 0; i < v1.length; i++) {
0592: for (int j = 0; j < v2.length; j++) {
0593: out.write("" + v1[i] + '\t' + v2[j] + '\t'
0594: + v3[i][j] + '\n');
0595: }
0596: out.write("" + '\n');
0597: }
0598: } catch (IOException e) {
0599: new SemanticException("Failed to write to file.");
0600: }
0601: try {
0602: out.close();
0603: } catch (IOException e2) {
0604: new SemanticException("Failed to close File object");
0605: }
0606: return fileName;
0607: }
0608:
0609: private static String save(double[][] m) {
0610: File tempFile = null;
0611: try {
0612: tempFile = File.createTempFile("jmatlab_", ".dat");
0613: } catch (IOException e) {
0614: new SemanticException(
0615: "Failed to create temporary file 'jmatlab_*.dat'");
0616: }
0617: tempFile.deleteOnExit();
0618: String fileName = tempFile.getPath();
0619: lastFileName = fileName;
0620: fileList.add(0, fileName);
0621: FileWriter out = null;
0622: try {
0623: out = new FileWriter(tempFile);
0624: } catch (IOException e1) {
0625: new SemanticException("Failed to instantiate FileWriter.");
0626: }
0627: int rows = m.length;
0628: int cols = m[0].length;
0629: try {
0630: for (int i = 0; i < rows; i++) {
0631: for (int j = 0; j < cols; j++) {
0632: out.write("" + m[i][j]);
0633: if (j != cols - 1)
0634: out.write("" + '\t');
0635: }
0636: out.write("" + '\n');
0637: }
0638: } catch (IOException e) {
0639: new SemanticException("Failed to write to file.");
0640: }
0641: try {
0642: out.close();
0643: } catch (IOException e2) {
0644: new SemanticException("Failed to close File object");
0645: }
0646: return fileName;
0647: }
0648:
0649: private static void plot(double[] v) {
0650: if (isOnHold) {
0651: lineNum++;
0652: } else {
0653: lineNum = 1;
0654: }
0655: String fileName = null;
0656: fileName = save(v);
0657: String s = null;
0658: if (isOnHold) {
0659: String setStyle = "set style data lines";
0660: gplot(setStyle);
0661: if (lastPlotCommands.size() > 0
0662: || lastRePlotCommands.size() > 0) {
0663: s = "replot " + "\'" + fileName + "\' t \"line "
0664: + lineNum + "\"";
0665: } else {
0666: s = "plot " + "\'" + fileName + "\' t \"line "
0667: + lineNum + "\"";
0668: }
0669: gplot(s);
0670: String unsetStyle = "unset style data";
0671: gplot(unsetStyle);
0672: lastRePlotCommands.add(setStyle);
0673: lastRePlotCommands.add(s);
0674: lastRePlotCommands.add(unsetStyle);
0675: } else {
0676: resetAllLabels();
0677: String setStyle = "set style data lines";
0678: gplot(setStyle);
0679: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
0680: + "\"";
0681: gplot(s);
0682: lastCommand = s;
0683: String unsetStyle = "unset style data";
0684: gplot(unsetStyle);
0685: lastRePlotCommands.clear();
0686: lastPlotCommands.clear();
0687: lastPlotCommands.add(setStyle);
0688: lastPlotCommands.add(s);
0689: lastPlotCommands.add(unsetStyle);
0690: }
0691:
0692: }
0693:
0694: private static void plot(double[][] v) {
0695: int rows = v.length;
0696: int cols = v[0].length;
0697:
0698: String fileName = null;
0699:
0700: double[] domain = new double[rows];
0701: for (int i = 0; i < rows; i++) {
0702: domain[i] = i + 1;
0703: }
0704:
0705: List listOfFiles = new ArrayList();
0706: for (int i = 0; i < cols; i++) {
0707: double[] range = new double[rows];
0708: for (int j = 0; j < rows; j++) {
0709: range[j] = v[j][i];
0710: }
0711: listOfFiles.add(save(domain, range));
0712: }
0713:
0714: String s = null;
0715: if (isOnHold) {
0716: String setStyle = "set style data lines";
0717: gplot(setStyle);
0718: lastRePlotCommands.add(setStyle);
0719: Iterator iter = listOfFiles.iterator();
0720: int count = 0;
0721: while (iter.hasNext()) {
0722: fileName = (String) iter.next();
0723: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
0724: .size() > 0)
0725: && (count > 0)) {
0726: s = "replot " + "\'" + fileName + "\' t \"line "
0727: + lineNum++ + "\"";
0728: } else {
0729: s = "plot " + "\'" + fileName + "\' t \"line "
0730: + lineNum++ + "\"";
0731: }
0732: gplot(s);
0733: lastRePlotCommands.add(s);
0734: count++;
0735: }
0736: String unsetStyle = "unset style data";
0737: gplot(unsetStyle);
0738: lastRePlotCommands.add(unsetStyle);
0739: } else {
0740: resetAllLabels();
0741: lastRePlotCommands.clear();
0742: lastPlotCommands.clear();
0743: String setStyle = "set style data lines";
0744: gplot(setStyle);
0745: lastPlotCommands.add(setStyle);
0746: Iterator iter = listOfFiles.iterator();
0747: int count = 0;
0748: while (iter.hasNext()) {
0749: fileName = (String) iter.next();
0750: if (count > 0) {
0751: s = "replot " + "\'" + fileName + "\' t \"line "
0752: + lineNum++ + "\"";
0753: } else {
0754: s = "plot " + "\'" + fileName + "\' t \"line "
0755: + lineNum++ + "\"";
0756: }
0757: gplot(s);
0758: lastPlotCommands.add(s);
0759: count++;
0760: }
0761: lastCommand = s;
0762: String unsetStyle = "unset style data";
0763: gplot(unsetStyle);
0764: lastPlotCommands.add(unsetStyle);
0765: }
0766:
0767: }
0768:
0769: private static void plot(double[][] v, double[][] w) {
0770: int rows = v.length;
0771: int cols = v[0].length;
0772:
0773: String fileName = null;
0774:
0775: List listOfFiles = new ArrayList();
0776: for (int i = 0; i < cols; i++) {
0777: double[] domain = new double[rows];
0778: double[] range = new double[rows];
0779: for (int j = 0; j < rows; j++) {
0780: domain[j] = v[j][i];
0781: range[j] = w[j][i];
0782: }
0783: listOfFiles.add(save(domain, range));
0784: }
0785:
0786: String s = null;
0787: if (isOnHold) {
0788: String setStyle = "set style data lines";
0789: gplot(setStyle);
0790: lastRePlotCommands.add(setStyle);
0791: Iterator iter = listOfFiles.iterator();
0792: int count = 0;
0793: while (iter.hasNext()) {
0794: fileName = (String) iter.next();
0795: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
0796: .size() > 0)
0797: && (count > 0)) {
0798: s = "replot " + "\'" + fileName + "\' t \"line "
0799: + lineNum++ + "\"";
0800: } else {
0801: s = "plot " + "\'" + fileName + "\' t \"line "
0802: + lineNum++ + "\"";
0803: }
0804: gplot(s);
0805: lastRePlotCommands.add(s);
0806: count++;
0807: }
0808: String unsetStyle = "unset style data";
0809: gplot(unsetStyle);
0810: lastRePlotCommands.add(unsetStyle);
0811: } else {
0812: resetAllLabels();
0813: lastRePlotCommands.clear();
0814: lastPlotCommands.clear();
0815: String setStyle = "set style data lines";
0816: gplot(setStyle);
0817: lastPlotCommands.add(setStyle);
0818: Iterator iter = listOfFiles.iterator();
0819: int count = 0;
0820: while (iter.hasNext()) {
0821: fileName = (String) iter.next();
0822: if (count > 0) {
0823: s = "replot " + "\'" + fileName + "\' t \"line "
0824: + lineNum++ + "\"";
0825: } else {
0826: s = "plot " + "\'" + fileName + "\' t \"line "
0827: + lineNum++ + "\"";
0828: }
0829: gplot(s);
0830: lastPlotCommands.add(s);
0831: count++;
0832: }
0833: lastCommand = s;
0834: String unsetStyle = "unset style data";
0835: gplot(unsetStyle);
0836: lastPlotCommands.add(unsetStyle);
0837: }
0838:
0839: }
0840:
0841: private static void plot(double[][] v, double[][] w, String opt) {
0842: int rows = v.length;
0843: int cols = v[0].length;
0844:
0845: String fileName = null;
0846:
0847: List listOfFiles = new ArrayList();
0848: for (int i = 0; i < cols; i++) {
0849: double[] domain = new double[rows];
0850: double[] range = new double[rows];
0851: for (int j = 0; j < rows; j++) {
0852: domain[j] = v[j][i];
0853: range[j] = w[j][i];
0854: }
0855: listOfFiles.add(save(domain, range));
0856: }
0857:
0858: String s = null;
0859: String options = options(opt);
0860: if (isOnHold) {
0861: String setStyle = "set style data lines";
0862: gplot(setStyle);
0863: lastRePlotCommands.add(setStyle);
0864: Iterator iter = listOfFiles.iterator();
0865: int count = 0;
0866: while (iter.hasNext()) {
0867: fileName = (String) iter.next();
0868: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
0869: .size() > 0)
0870: && (count > 0)) {
0871: s = "replot " + "\'" + fileName + "\' t \"line "
0872: + lineNum++ + "\" " + options;
0873: } else {
0874: s = "plot " + "\'" + fileName + "\' t \"line "
0875: + lineNum++ + "\" " + options;
0876: }
0877: gplot(s);
0878: lastRePlotCommands.add(s);
0879: count++;
0880: }
0881: String unsetStyle = "unset style data";
0882: gplot(unsetStyle);
0883: lastRePlotCommands.add(unsetStyle);
0884: } else {
0885: resetAllLabels();
0886: lastRePlotCommands.clear();
0887: lastPlotCommands.clear();
0888: String setStyle = "set style data lines";
0889: gplot(setStyle);
0890: lastPlotCommands.add(setStyle);
0891: Iterator iter = listOfFiles.iterator();
0892: int count = 0;
0893: while (iter.hasNext()) {
0894: fileName = (String) iter.next();
0895: if (count > 0) {
0896: s = "replot " + "\'" + fileName + "\' t \"line "
0897: + lineNum++ + "\" " + options;
0898: } else {
0899: s = "plot " + "\'" + fileName + "\' t \"line "
0900: + lineNum++ + "\" " + options;
0901: }
0902: gplot(s);
0903: lastPlotCommands.add(s);
0904: count++;
0905: }
0906: lastCommand = s;
0907: String unsetStyle = "unset style data";
0908: gplot(unsetStyle);
0909: lastPlotCommands.add(unsetStyle);
0910: }
0911:
0912: }
0913:
0914: private static void semilogx(double[][] v) {
0915: int rows = v.length;
0916: int cols = v[0].length;
0917:
0918: String fileName = null;
0919:
0920: double[] domain = new double[rows];
0921: for (int i = 0; i < rows; i++) {
0922: domain[i] = i + 1;
0923: }
0924:
0925: List listOfFiles = new ArrayList();
0926: for (int i = 0; i < cols; i++) {
0927: double[] range = new double[rows];
0928: for (int j = 0; j < rows; j++) {
0929: range[j] = v[j][i];
0930: }
0931: listOfFiles.add(save(domain, range));
0932: }
0933:
0934: String s = null;
0935: if (isOnHold) {
0936: String setLogScale = "set logscale x";
0937: gplot(setLogScale);
0938: lastRePlotCommands.add(setLogScale);
0939: String setStyle = "set style data lines";
0940: gplot(setStyle);
0941: lastRePlotCommands.add(setStyle);
0942: Iterator iter = listOfFiles.iterator();
0943: int count = 0;
0944: while (iter.hasNext()) {
0945: fileName = (String) iter.next();
0946: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
0947: .size() > 0)
0948: && (count > 0)) {
0949: s = "replot " + "\'" + fileName + "\' t \"line "
0950: + lineNum++ + "\"";
0951: } else {
0952: s = "plot " + "\'" + fileName + "\' t \"line "
0953: + lineNum++ + "\"";
0954: }
0955: gplot(s);
0956: lastRePlotCommands.add(s);
0957: count++;
0958: }
0959: String unsetStyle = "unset style data";
0960: gplot(unsetStyle);
0961: lastRePlotCommands.add(unsetStyle);
0962: String unsetLogScale = "unset logscale x";
0963: gplot(unsetLogScale);
0964: lastRePlotCommands.add(unsetLogScale);
0965: } else {
0966: resetAllLabels();
0967: lastRePlotCommands.clear();
0968: lastPlotCommands.clear();
0969: String setLogScale = "set logscale x";
0970: gplot(setLogScale);
0971: lastPlotCommands.add(setLogScale);
0972: String setStyle = "set style data lines";
0973: gplot(setStyle);
0974: lastPlotCommands.add(setStyle);
0975: Iterator iter = listOfFiles.iterator();
0976: int count = 0;
0977: while (iter.hasNext()) {
0978: fileName = (String) iter.next();
0979: if (count > 0) {
0980: s = "replot " + "\'" + fileName + "\' t \"line "
0981: + lineNum++ + "\"";
0982: } else {
0983: s = "plot " + "\'" + fileName + "\' t \"line "
0984: + lineNum++ + "\"";
0985: }
0986: gplot(s);
0987: lastPlotCommands.add(s);
0988: count++;
0989: }
0990: lastCommand = s;
0991: String unsetStyle = "unset style data";
0992: gplot(unsetStyle);
0993: lastPlotCommands.add(unsetStyle);
0994: String unsetLogScale = "unset logscale x";
0995: gplot(unsetLogScale);
0996: lastPlotCommands.add(unsetLogScale);
0997: }
0998:
0999: }
1000:
1001: private static void semilogx(double[][] v, double[][] w) {
1002: int rows = v.length;
1003: int cols = v[0].length;
1004:
1005: String fileName = null;
1006:
1007: List listOfFiles = new ArrayList();
1008: for (int i = 0; i < cols; i++) {
1009: double[] range = new double[rows];
1010: double[] domain = new double[rows];
1011: for (int j = 0; j < rows; j++) {
1012: range[j] = v[j][i];
1013: domain[j] = w[j][i];
1014: }
1015: listOfFiles.add(save(domain, range));
1016: }
1017:
1018: String s = null;
1019: if (isOnHold) {
1020: String setLogScale = "set logscale x";
1021: gplot(setLogScale);
1022: lastRePlotCommands.add(setLogScale);
1023: String setStyle = "set style data lines";
1024: gplot(setStyle);
1025: lastRePlotCommands.add(setStyle);
1026: Iterator iter = listOfFiles.iterator();
1027: int count = 0;
1028: while (iter.hasNext()) {
1029: fileName = (String) iter.next();
1030: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1031: .size() > 0)
1032: && (count > 0)) {
1033: s = "replot " + "\'" + fileName + "\' t \"line "
1034: + lineNum++ + "\"";
1035: } else {
1036: s = "plot " + "\'" + fileName + "\' t \"line "
1037: + lineNum++ + "\"";
1038: }
1039: gplot(s);
1040: lastRePlotCommands.add(s);
1041: count++;
1042: }
1043: String unsetStyle = "unset style data";
1044: gplot(unsetStyle);
1045: lastRePlotCommands.add(unsetStyle);
1046: String unsetLogScale = "unset logscale x";
1047: gplot(unsetLogScale);
1048: lastRePlotCommands.add(unsetLogScale);
1049: } else {
1050: resetAllLabels();
1051: lastRePlotCommands.clear();
1052: lastPlotCommands.clear();
1053: String setLogScale = "set logscale x";
1054: gplot(setLogScale);
1055: lastPlotCommands.add(setLogScale);
1056: String setStyle = "set style data lines";
1057: gplot(setStyle);
1058: lastPlotCommands.add(setStyle);
1059: Iterator iter = listOfFiles.iterator();
1060: int count = 0;
1061: while (iter.hasNext()) {
1062: fileName = (String) iter.next();
1063: if (count > 0) {
1064: s = "replot " + "\'" + fileName + "\' t \"line "
1065: + lineNum++ + "\"";
1066: } else {
1067: s = "plot " + "\'" + fileName + "\' t \"line "
1068: + lineNum++ + "\"";
1069: }
1070: gplot(s);
1071: lastPlotCommands.add(s);
1072: count++;
1073: }
1074: lastCommand = s;
1075: String unsetStyle = "unset style data";
1076: gplot(unsetStyle);
1077: lastPlotCommands.add(unsetStyle);
1078: String unsetLogScale = "unset logscale x";
1079: gplot(unsetLogScale);
1080: lastPlotCommands.add(unsetLogScale);
1081: }
1082:
1083: }
1084:
1085: private static void semilogx(double[][] v, double[][] w, String opt) {
1086: int rows = v.length;
1087: int cols = v[0].length;
1088:
1089: String fileName = null;
1090:
1091: List listOfFiles = new ArrayList();
1092: for (int i = 0; i < cols; i++) {
1093: double[] range = new double[rows];
1094: double[] domain = new double[rows];
1095: for (int j = 0; j < rows; j++) {
1096: range[j] = v[j][i];
1097: domain[j] = w[j][i];
1098: }
1099: listOfFiles.add(save(domain, range));
1100: }
1101:
1102: String s = null;
1103: String options = options(opt);
1104: if (isOnHold) {
1105: String setLogScale = "set logscale x";
1106: gplot(setLogScale);
1107: lastRePlotCommands.add(setLogScale);
1108: String setStyle = "set style data lines";
1109: gplot(setStyle);
1110: lastRePlotCommands.add(setStyle);
1111: Iterator iter = listOfFiles.iterator();
1112: int count = 0;
1113: while (iter.hasNext()) {
1114: fileName = (String) iter.next();
1115: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1116: .size() > 0)
1117: && (count > 0)) {
1118: s = "replot " + "\'" + fileName + "\' t \"line "
1119: + lineNum++ + "\" " + options;
1120: } else {
1121: s = "plot " + "\'" + fileName + "\' t \"line "
1122: + lineNum++ + "\" " + options;
1123: }
1124: gplot(s);
1125: lastRePlotCommands.add(s);
1126: count++;
1127: }
1128: String unsetStyle = "unset style data";
1129: gplot(unsetStyle);
1130: lastRePlotCommands.add(unsetStyle);
1131: String unsetLogScale = "unset logscale x";
1132: gplot(unsetLogScale);
1133: lastRePlotCommands.add(unsetLogScale);
1134: } else {
1135: resetAllLabels();
1136: lastRePlotCommands.clear();
1137: lastPlotCommands.clear();
1138: String setLogScale = "set logscale x";
1139: gplot(setLogScale);
1140: lastPlotCommands.add(setLogScale);
1141: String setStyle = "set style data lines";
1142: gplot(setStyle);
1143: lastPlotCommands.add(setStyle);
1144: Iterator iter = listOfFiles.iterator();
1145: int count = 0;
1146: while (iter.hasNext()) {
1147: fileName = (String) iter.next();
1148: if (count > 0) {
1149: s = "replot " + "\'" + fileName + "\' t \"line "
1150: + lineNum++ + "\" " + options;
1151: } else {
1152: s = "plot " + "\'" + fileName + "\' t \"line "
1153: + lineNum++ + "\" " + options;
1154: }
1155: gplot(s);
1156: lastPlotCommands.add(s);
1157: count++;
1158: }
1159: lastCommand = s;
1160: String unsetStyle = "unset style data";
1161: gplot(unsetStyle);
1162: lastPlotCommands.add(unsetStyle);
1163: String unsetLogScale = "unset logscale x";
1164: gplot(unsetLogScale);
1165: lastPlotCommands.add(unsetLogScale);
1166: }
1167:
1168: }
1169:
1170: private static void semilogy(double[][] v) {
1171: int rows = v.length;
1172: int cols = v[0].length;
1173:
1174: String fileName = null;
1175:
1176: double[] domain = new double[rows];
1177: for (int i = 0; i < rows; i++) {
1178: domain[i] = i + 1;
1179: }
1180:
1181: List listOfFiles = new ArrayList();
1182: for (int i = 0; i < cols; i++) {
1183: double[] range = new double[rows];
1184: for (int j = 0; j < rows; j++) {
1185: range[j] = v[j][i];
1186: }
1187: listOfFiles.add(save(domain, range));
1188: }
1189:
1190: String s = null;
1191: if (isOnHold) {
1192: String setLogScale = "set logscale y";
1193: gplot(setLogScale);
1194: lastRePlotCommands.add(setLogScale);
1195: String setStyle = "set style data lines";
1196: gplot(setStyle);
1197: lastRePlotCommands.add(setStyle);
1198: Iterator iter = listOfFiles.iterator();
1199: int count = 0;
1200: while (iter.hasNext()) {
1201: fileName = (String) iter.next();
1202: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1203: .size() > 0)
1204: && (count > 0)) {
1205: s = "replot " + "\'" + fileName + "\' t \"line "
1206: + lineNum++ + "\"";
1207: } else {
1208: s = "plot " + "\'" + fileName + "\' t \"line "
1209: + lineNum++ + "\"";
1210: }
1211: gplot(s);
1212: lastRePlotCommands.add(s);
1213: count++;
1214: }
1215: String unsetStyle = "unset style data";
1216: gplot(unsetStyle);
1217: lastRePlotCommands.add(unsetStyle);
1218: String unsetLogScale = "unset logscale y";
1219: gplot(unsetLogScale);
1220: lastRePlotCommands.add(unsetLogScale);
1221: } else {
1222: resetAllLabels();
1223: lastRePlotCommands.clear();
1224: lastPlotCommands.clear();
1225: String setLogScale = "set logscale y";
1226: gplot(setLogScale);
1227: lastPlotCommands.add(setLogScale);
1228: String setStyle = "set style data lines";
1229: gplot(setStyle);
1230: lastPlotCommands.add(setStyle);
1231: Iterator iter = listOfFiles.iterator();
1232: int count = 0;
1233: while (iter.hasNext()) {
1234: fileName = (String) iter.next();
1235: if (count > 0) {
1236: s = "replot " + "\'" + fileName + "\' t \"line "
1237: + lineNum++ + "\"";
1238: } else {
1239: s = "plot " + "\'" + fileName + "\' t \"line "
1240: + lineNum++ + "\"";
1241: }
1242: gplot(s);
1243: lastPlotCommands.add(s);
1244: count++;
1245: }
1246: lastCommand = s;
1247: String unsetStyle = "unset style data";
1248: gplot(unsetStyle);
1249: lastPlotCommands.add(unsetStyle);
1250: String unsetLogScale = "unset logscale y";
1251: gplot(unsetLogScale);
1252: lastPlotCommands.add(unsetLogScale);
1253: }
1254:
1255: }
1256:
1257: private static void semilogy(double[][] v, double[][] w) {
1258: int rows = v.length;
1259: int cols = v[0].length;
1260:
1261: String fileName = null;
1262:
1263: List listOfFiles = new ArrayList();
1264: for (int i = 0; i < cols; i++) {
1265: double[] range = new double[rows];
1266: double[] domain = new double[rows];
1267: for (int j = 0; j < rows; j++) {
1268: range[j] = v[j][i];
1269: domain[j] = w[j][i];
1270: }
1271: listOfFiles.add(save(domain, range));
1272: }
1273:
1274: String s = null;
1275: if (isOnHold) {
1276: String setLogScale = "set logscale y";
1277: gplot(setLogScale);
1278: lastRePlotCommands.add(setLogScale);
1279: String setStyle = "set style data lines";
1280: gplot(setStyle);
1281: lastRePlotCommands.add(setStyle);
1282: Iterator iter = listOfFiles.iterator();
1283: int count = 0;
1284: while (iter.hasNext()) {
1285: fileName = (String) iter.next();
1286: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1287: .size() > 0)
1288: && (count > 0)) {
1289: s = "replot " + "\'" + fileName + "\' t \"line "
1290: + lineNum++ + "\"";
1291: } else {
1292: s = "plot " + "\'" + fileName + "\' t \"line "
1293: + lineNum++ + "\"";
1294: }
1295: gplot(s);
1296: lastRePlotCommands.add(s);
1297: count++;
1298: }
1299: String unsetStyle = "unset style data";
1300: gplot(unsetStyle);
1301: lastRePlotCommands.add(unsetStyle);
1302: String unsetLogScale = "unset logscale y";
1303: gplot(unsetLogScale);
1304: lastRePlotCommands.add(unsetLogScale);
1305: } else {
1306: resetAllLabels();
1307: lastRePlotCommands.clear();
1308: lastPlotCommands.clear();
1309: String setLogScale = "set logscale y";
1310: gplot(setLogScale);
1311: lastPlotCommands.add(setLogScale);
1312: String setStyle = "set style data lines";
1313: gplot(setStyle);
1314: lastPlotCommands.add(setStyle);
1315: Iterator iter = listOfFiles.iterator();
1316: int count = 0;
1317: while (iter.hasNext()) {
1318: fileName = (String) iter.next();
1319: if (count > 0) {
1320: s = "replot " + "\'" + fileName + "\' t \"line "
1321: + lineNum++ + "\"";
1322: } else {
1323: s = "plot " + "\'" + fileName + "\' t \"line "
1324: + lineNum++ + "\"";
1325: }
1326: gplot(s);
1327: lastPlotCommands.add(s);
1328: count++;
1329: }
1330: lastCommand = s;
1331: String unsetStyle = "unset style data";
1332: gplot(unsetStyle);
1333: lastPlotCommands.add(unsetStyle);
1334: String unsetLogScale = "unset logscale y";
1335: gplot(unsetLogScale);
1336: lastPlotCommands.add(unsetLogScale);
1337: }
1338:
1339: }
1340:
1341: private static void semilogy(double[][] v, double[][] w, String opt) {
1342: int rows = v.length;
1343: int cols = v[0].length;
1344:
1345: String fileName = null;
1346:
1347: List listOfFiles = new ArrayList();
1348: for (int i = 0; i < cols; i++) {
1349: double[] range = new double[rows];
1350: double[] domain = new double[rows];
1351: for (int j = 0; j < rows; j++) {
1352: range[j] = v[j][i];
1353: domain[j] = w[j][i];
1354: }
1355: listOfFiles.add(save(domain, range));
1356: }
1357:
1358: String s = null;
1359: String options = options(opt);
1360: if (isOnHold) {
1361: String setLogScale = "set logscale y";
1362: gplot(setLogScale);
1363: lastRePlotCommands.add(setLogScale);
1364: String setStyle = "set style data lines";
1365: gplot(setStyle);
1366: lastRePlotCommands.add(setStyle);
1367: Iterator iter = listOfFiles.iterator();
1368: int count = 0;
1369: while (iter.hasNext()) {
1370: fileName = (String) iter.next();
1371: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1372: .size() > 0)
1373: && (count > 0)) {
1374: s = "replot " + "\'" + fileName + "\' t \"line "
1375: + lineNum++ + "\" " + options;
1376: } else {
1377: s = "plot " + "\'" + fileName + "\' t \"line "
1378: + lineNum++ + "\" " + options;
1379: }
1380: gplot(s);
1381: lastRePlotCommands.add(s);
1382: count++;
1383: }
1384: String unsetStyle = "unset style data";
1385: gplot(unsetStyle);
1386: lastRePlotCommands.add(unsetStyle);
1387: String unsetLogScale = "unset logscale y";
1388: gplot(unsetLogScale);
1389: lastRePlotCommands.add(unsetLogScale);
1390: } else {
1391: resetAllLabels();
1392: lastRePlotCommands.clear();
1393: lastPlotCommands.clear();
1394: String setLogScale = "set logscale y";
1395: gplot(setLogScale);
1396: lastPlotCommands.add(setLogScale);
1397: String setStyle = "set style data lines";
1398: gplot(setStyle);
1399: lastPlotCommands.add(setStyle);
1400: Iterator iter = listOfFiles.iterator();
1401: int count = 0;
1402: while (iter.hasNext()) {
1403: fileName = (String) iter.next();
1404: if (count > 0) {
1405: s = "replot " + "\'" + fileName + "\' t \"line "
1406: + lineNum++ + "\" " + options;
1407: } else {
1408: s = "plot " + "\'" + fileName + "\' t \"line "
1409: + lineNum++ + "\" " + options;
1410: }
1411: gplot(s);
1412: lastPlotCommands.add(s);
1413: count++;
1414: }
1415: lastCommand = s;
1416: String unsetStyle = "unset style data";
1417: gplot(unsetStyle);
1418: lastPlotCommands.add(unsetStyle);
1419: String unsetLogScale = "unset logscale y";
1420: gplot(unsetLogScale);
1421: lastPlotCommands.add(unsetLogScale);
1422: }
1423:
1424: }
1425:
1426: private static void loglog(double[][] v) {
1427: String s = null;
1428: loglog(v, s);
1429: }
1430:
1431: private static void loglog(double[][] v, double[][] w) {
1432: loglog(v, w, null);
1433: }
1434:
1435: private static void loglog(double[][] v, double[][] w, String opt) {
1436: int rows = v.length;
1437: int cols = v[0].length;
1438:
1439: String fileName = null;
1440:
1441: List listOfFiles = new ArrayList();
1442: for (int i = 0; i < cols; i++) {
1443: double[] range = new double[rows];
1444: double[] domain = new double[rows];
1445: for (int j = 0; j < rows; j++) {
1446: range[j] = v[j][i];
1447: domain[j] = w[j][i];
1448: }
1449: listOfFiles.add(save(domain, range));
1450: }
1451:
1452: String s = null;
1453: String options = options(opt);
1454: if (isOnHold) {
1455: String setLogScale = "set logscale xy";
1456: gplot(setLogScale);
1457: lastRePlotCommands.add(setLogScale);
1458: String setStyle = "set style data lines";
1459: gplot(setStyle);
1460: lastRePlotCommands.add(setStyle);
1461: Iterator iter = listOfFiles.iterator();
1462: int count = 0;
1463: while (iter.hasNext()) {
1464: fileName = (String) iter.next();
1465: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1466: .size() > 0)
1467: && (count > 0)) {
1468: s = "replot " + "\'" + fileName + "\' t \"line "
1469: + lineNum++ + "\" " + options;
1470: } else {
1471: s = "plot " + "\'" + fileName + "\' t \"line "
1472: + lineNum++ + "\" " + options;
1473: }
1474: gplot(s);
1475: lastRePlotCommands.add(s);
1476: count++;
1477: }
1478: String unsetStyle = "unset style data";
1479: gplot(unsetStyle);
1480: lastRePlotCommands.add(unsetStyle);
1481: String unsetLogScale = "unset logscale xy";
1482: gplot(unsetLogScale);
1483: lastRePlotCommands.add(unsetLogScale);
1484: } else {
1485: resetAllLabels();
1486: lastRePlotCommands.clear();
1487: lastPlotCommands.clear();
1488: String setLogScale = "set logscale xy";
1489: gplot(setLogScale);
1490: lastPlotCommands.add(setLogScale);
1491: String setStyle = "set style data lines";
1492: gplot(setStyle);
1493: lastPlotCommands.add(setStyle);
1494: Iterator iter = listOfFiles.iterator();
1495: int count = 0;
1496: while (iter.hasNext()) {
1497: fileName = (String) iter.next();
1498: if (count > 0) {
1499: s = "replot " + "\'" + fileName + "\' t \"line "
1500: + lineNum++ + "\" " + options;
1501: } else {
1502: s = "plot " + "\'" + fileName + "\' t \"line "
1503: + lineNum++ + "\" " + options;
1504: }
1505: gplot(s);
1506: lastPlotCommands.add(s);
1507: count++;
1508: }
1509: lastCommand = s;
1510: String unsetStyle = "unset style data";
1511: gplot(unsetStyle);
1512: lastPlotCommands.add(unsetStyle);
1513: String unsetLogScale = "unset logscale xy";
1514: gplot(unsetLogScale);
1515: lastPlotCommands.add(unsetLogScale);
1516: }
1517:
1518: }
1519:
1520: private static void plot(double[][] v, String opt) {
1521: int rows = v.length;
1522: int cols = v[0].length;
1523:
1524: String fileName = null;
1525:
1526: double[] domain = new double[rows];
1527: for (int i = 0; i < rows; i++) {
1528: domain[i] = i + 1;
1529: }
1530:
1531: List listOfFiles = new ArrayList();
1532: for (int i = 0; i < cols; i++) {
1533: double[] range = new double[rows];
1534: for (int j = 0; j < rows; j++) {
1535: range[j] = v[j][i];
1536: }
1537: listOfFiles.add(save(domain, range));
1538: }
1539:
1540: String s = null;
1541: String options = options(opt);
1542: if (isOnHold) {
1543: String setStyle = "set style data lines";
1544: gplot(setStyle);
1545: lastRePlotCommands.add(setStyle);
1546: Iterator iter = listOfFiles.iterator();
1547: int count = 0;
1548: while (iter.hasNext()) {
1549: fileName = (String) iter.next();
1550: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
1551: .size() > 0)
1552: && (count > 0)) {
1553: s = "replot " + "\'" + fileName + "\' t \"line "
1554: + lineNum++ + "\" " + options;
1555: } else {
1556: s = "plot " + "\'" + fileName + "\' t \"line "
1557: + lineNum++ + "\" " + options;
1558: }
1559: gplot(s);
1560: lastRePlotCommands.add(s);
1561: count++;
1562: }
1563: String unsetStyle = "unset style data";
1564: gplot(unsetStyle);
1565: lastRePlotCommands.add(unsetStyle);
1566: } else {
1567: resetAllLabels();
1568: lastRePlotCommands.clear();
1569: lastPlotCommands.clear();
1570: String setStyle = "set style data lines";
1571: gplot(setStyle);
1572: lastPlotCommands.add(setStyle);
1573: Iterator iter = listOfFiles.iterator();
1574: int count = 0;
1575: while (iter.hasNext()) {
1576: fileName = (String) iter.next();
1577: if (count > 0) {
1578: s = "replot " + "\'" + fileName + "\' t \"line "
1579: + lineNum++ + "\" " + options;
1580: } else {
1581: s = "plot " + "\'" + fileName + "\' t \"line "
1582: + lineNum++ + "\" " + options;
1583: }
1584: gplot(s);
1585: lastPlotCommands.add(s);
1586: count++;
1587: }
1588: lastCommand = s;
1589: String unsetStyle = "unset style data";
1590: gplot(unsetStyle);
1591: lastPlotCommands.add(unsetStyle);
1592: }
1593:
1594: }
1595:
1596: private static void plot(double[] v, double[] w) {
1597: String s = null;
1598: plot(v, w, s);
1599: }
1600:
1601: private static void plot(double[] v, String opt) {
1602: if (isOnHold) {
1603: lineNum++;
1604: } else {
1605: lineNum = 1;
1606: }
1607: String fileName = null;
1608: fileName = save(v);
1609: String s = null;
1610: String options = options(opt);
1611: if (isOnHold) {
1612: String setStyle = "set style data lines";
1613: gplot(setStyle);
1614: if (lastPlotCommands.size() > 0
1615: || lastRePlotCommands.size() > 0) {
1616: s = "replot " + "\'" + fileName + "\' t \"line "
1617: + lineNum + "\"" + options;
1618: } else {
1619: s = "plot " + "\'" + fileName + "\' t \"line "
1620: + lineNum + "\"" + options;
1621: }
1622: gplot(s);
1623: String unsetStyle = "unset style data";
1624: gplot(unsetStyle);
1625: lastRePlotCommands.add(setStyle);
1626: lastRePlotCommands.add(s);
1627: lastRePlotCommands.add(unsetStyle);
1628: } else {
1629: resetAllLabels();
1630: String setStyle = "set style data lines";
1631: gplot(setStyle);
1632: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1633: + "\"" + options;
1634: gplot(s);
1635: lastCommand = s;
1636: String unsetStyle = "unset style data";
1637: gplot(unsetStyle);
1638: lastRePlotCommands.clear();
1639: lastPlotCommands.clear();
1640: lastPlotCommands.add(setStyle);
1641: lastPlotCommands.add(s);
1642: lastPlotCommands.add(unsetStyle);
1643: }
1644:
1645: }
1646:
1647: private static void plot(double[] v, double[] w, String opt) {
1648: if (isOnHold) {
1649: lineNum++;
1650: } else {
1651: lineNum = 1;
1652: }
1653: String fileName = null;
1654: fileName = save(v, w);
1655: String s = null;
1656: String options = options(opt);
1657: if (isOnHold) {
1658: String setStyle = "set style data lines";
1659: gplot(setStyle);
1660: if (lastPlotCommands.size() > 0
1661: || lastRePlotCommands.size() > 0) {
1662: s = "replot " + "\'" + fileName + "\' t \"line "
1663: + lineNum + "\" " + options;
1664: } else {
1665: s = "plot " + "\'" + fileName + "\' t \"line "
1666: + lineNum + "\" " + options;
1667: }
1668: gplot(s);
1669: String unsetStyle = "unset style data";
1670: gplot(unsetStyle);
1671: lastRePlotCommands.add(setStyle);
1672: lastRePlotCommands.add(s);
1673: lastRePlotCommands.add(unsetStyle);
1674: } else {
1675: resetAllLabels();
1676: String setStyle = "set style data lines";
1677: gplot(setStyle);
1678: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1679: + "\" " + options;
1680: gplot(s);
1681: lastCommand = s;
1682: String unsetStyle = "unset style data";
1683: gplot(unsetStyle);
1684: lastRePlotCommands.clear();
1685: lastPlotCommands.clear();
1686: lastPlotCommands.add(setStyle);
1687: lastPlotCommands.add(s);
1688: lastPlotCommands.add(unsetStyle);
1689: }
1690:
1691: }
1692:
1693: private static void semilogx(double[] v) {
1694: String s = null;
1695: semilogx(v, s);
1696: }
1697:
1698: private static void semilogx(double[] v, double[] w) {
1699: semilogx(v, w, null);
1700: }
1701:
1702: private static void semilogx(double[] v, double[] w, String opt) {
1703: if (isOnHold) {
1704: lineNum++;
1705: } else {
1706: lineNum = 1;
1707: }
1708: String fileName = null;
1709: fileName = save(v, w);
1710: String s = null;
1711: String options = options(opt);
1712: if (isOnHold) {
1713: String setLogScale = "set logscale x";
1714: gplot(setLogScale);
1715: String setStyle = "set style data lines";
1716: gplot(setStyle);
1717: if (lastRePlotCommands.size() > 0) {
1718: s = "replot " + "\'" + fileName + "\' t \"line "
1719: + lineNum + "\" " + options;
1720: } else {
1721: s = "plot " + "\'" + fileName + "\' t \"line "
1722: + lineNum + "\" " + options;
1723: }
1724: gplot(s);
1725: String unsetStyle = "unset style data lines";
1726: gplot(unsetStyle);
1727: String unsetLogScale = "unset logscale x";
1728: gplot(unsetLogScale);
1729: lastRePlotCommands.add(setLogScale);
1730: lastRePlotCommands.add(setStyle);
1731: lastRePlotCommands.add(s);
1732: lastRePlotCommands.add(unsetStyle);
1733: lastRePlotCommands.add(unsetLogScale);
1734: } else {
1735: resetAllLabels();
1736: String setLogScale = "set logscale x";
1737: gplot(setLogScale);
1738: String setStyle = "set style data lines";
1739: gplot(setStyle);
1740: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1741: + "\" " + options;
1742: gplot(s);
1743: lastCommand = s;
1744: String unsetStyle = "unset style data lines";
1745: gplot(unsetStyle);
1746: String unsetLogScale = "unset logscale x";
1747: gplot(unsetLogScale);
1748: lastRePlotCommands.clear();
1749: lastPlotCommands.clear();
1750: lastPlotCommands.add(setLogScale);
1751: lastPlotCommands.add(setStyle);
1752: lastPlotCommands.add(s);
1753: lastPlotCommands.add(unsetStyle);
1754: lastPlotCommands.add(unsetLogScale);
1755: }
1756:
1757: }
1758:
1759: private static void semilogy(double[] v) {
1760: String s = null;
1761: semilogy(v, s);
1762: }
1763:
1764: private static void semilogy(double[] v, double[] w) {
1765: semilogy(v, w, null);
1766: }
1767:
1768: private static void semilogy(double[] v, double[] w, String opt) {
1769: if (isOnHold) {
1770: lineNum++;
1771: } else {
1772: lineNum = 1;
1773: }
1774: String fileName = null;
1775: fileName = save(v, w);
1776: String s = null;
1777: String options = options(opt);
1778: if (isOnHold) {
1779: String setLogScale = "set logscale y";
1780: gplot(setLogScale);
1781: String setStyle = "set style data lines";
1782: gplot(setStyle);
1783: if (lastRePlotCommands.size() > 0) {
1784: s = "replot " + "\'" + fileName + "\' t \"line "
1785: + lineNum + "\" " + options;
1786: } else {
1787: s = "plot " + "\'" + fileName + "\' t \"line "
1788: + lineNum + "\" " + options;
1789: }
1790: gplot(s);
1791: String unsetStyle = "unset style data lines";
1792: gplot(unsetStyle);
1793: String unsetLogScale = "unset logscale y";
1794: gplot(unsetLogScale);
1795: lastRePlotCommands.add(setLogScale);
1796: lastRePlotCommands.add(setStyle);
1797: lastRePlotCommands.add(s);
1798: lastRePlotCommands.add(unsetStyle);
1799: lastRePlotCommands.add(unsetLogScale);
1800: } else {
1801: resetAllLabels();
1802: String setLogScale = "set logscale y";
1803: gplot(setLogScale);
1804: String setStyle = "set style data lines";
1805: gplot(setStyle);
1806: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1807: + "\" " + options;
1808: gplot(s);
1809: lastCommand = s;
1810: String unsetStyle = "unset style data lines";
1811: gplot(unsetStyle);
1812: String unsetLogScale = "unset logscale y";
1813: gplot(unsetLogScale);
1814: lastRePlotCommands.clear();
1815: lastPlotCommands.clear();
1816: lastPlotCommands.add(setLogScale);
1817: lastPlotCommands.add(setStyle);
1818: lastPlotCommands.add(s);
1819: lastPlotCommands.add(unsetStyle);
1820: lastPlotCommands.add(unsetLogScale);
1821: }
1822:
1823: }
1824:
1825: private static void loglog(double[] v) {
1826: String s = null;
1827: loglog(v, s);
1828: }
1829:
1830: private static void loglog(double[] v, double[] w) {
1831: String s = null;
1832: loglog(v, w, s);
1833: }
1834:
1835: private static void loglog(double[] v, double[] w, String opt) {
1836: if (isOnHold) {
1837: lineNum++;
1838: } else {
1839: lineNum = 1;
1840: }
1841: String fileName = null;
1842: fileName = save(v, w);
1843: String s = null;
1844: String options = options(opt);
1845: if (isOnHold) {
1846: String setLogScale = "set logscale xy";
1847: gplot(setLogScale);
1848: String setStyle = "set style data lines";
1849: gplot(setStyle);
1850: if (lastRePlotCommands.size() > 0) {
1851: s = "replot " + "\'" + fileName + "\' t \"line "
1852: + lineNum + "\" " + options;
1853: } else {
1854: s = "plot " + "\'" + fileName + "\' t \"line "
1855: + lineNum + "\" " + options;
1856: }
1857: gplot(s);
1858: String unsetStyle = "unset style data lines";
1859: gplot(unsetStyle);
1860: String unsetLogScale = "unset logscale xy";
1861: gplot(unsetLogScale);
1862: lastRePlotCommands.add(setLogScale);
1863: lastRePlotCommands.add(setStyle);
1864: lastRePlotCommands.add(s);
1865: lastRePlotCommands.add(unsetStyle);
1866: lastRePlotCommands.add(unsetLogScale);
1867: } else {
1868: resetAllLabels();
1869: String setLogScale = "set logscale xy";
1870: gplot(setLogScale);
1871: String setStyle = "set style data lines";
1872: gplot(setStyle);
1873: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1874: + "\" " + options;
1875: gplot(s);
1876: lastCommand = s;
1877: String unsetStyle = "unset style data lines";
1878: gplot(unsetStyle);
1879: String unsetLogScale = "unset logscale xy";
1880: gplot(unsetLogScale);
1881: lastRePlotCommands.clear();
1882: lastPlotCommands.clear();
1883: lastPlotCommands.add(setLogScale);
1884: lastPlotCommands.add(setStyle);
1885: lastPlotCommands.add(s);
1886: lastPlotCommands.add(unsetStyle);
1887: lastPlotCommands.add(unsetLogScale);
1888: }
1889:
1890: }
1891:
1892: private static void semilogx(double[] v, String opt) {
1893: if (isOnHold) {
1894: lineNum++;
1895: } else {
1896: lineNum = 1;
1897: }
1898: String fileName = null;
1899: fileName = save(v);
1900: String s = null;
1901: String options = options(opt);
1902: if (isOnHold) {
1903: String setLogScale = "set logscale x";
1904: gplot(setLogScale);
1905: String setStyle = "set style data lines";
1906: gplot(setStyle);
1907: if (lastRePlotCommands.size() > 0) {
1908: s = "replot " + "\'" + fileName + "\' t \"line "
1909: + lineNum + "\" " + options;
1910: } else {
1911: s = "plot " + "\'" + fileName + "\' t \"line "
1912: + lineNum + "\" " + options;
1913: }
1914: gplot(s);
1915: String unsetStyle = "unset style data lines";
1916: gplot(unsetStyle);
1917: String unsetLogScale = "unset logscale x";
1918: gplot(unsetLogScale);
1919: lastRePlotCommands.add(setLogScale);
1920: lastRePlotCommands.add(setStyle);
1921: lastRePlotCommands.add(s);
1922: lastRePlotCommands.add(unsetStyle);
1923: lastRePlotCommands.add(unsetLogScale);
1924: } else {
1925: resetAllLabels();
1926: String setLogScale = "set logscale x";
1927: gplot(setLogScale);
1928: String setStyle = "set style data lines";
1929: gplot(setStyle);
1930: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1931: + "\" " + options;
1932: gplot(s);
1933: lastCommand = s;
1934: String unsetStyle = "unset style data lines";
1935: gplot(unsetStyle);
1936: String unsetLogScale = "unset logscale x";
1937: gplot(unsetLogScale);
1938: lastRePlotCommands.clear();
1939: lastPlotCommands.clear();
1940: lastPlotCommands.add(setLogScale);
1941: lastPlotCommands.add(setStyle);
1942: lastPlotCommands.add(s);
1943: lastPlotCommands.add(unsetStyle);
1944: lastPlotCommands.add(unsetLogScale);
1945: }
1946:
1947: }
1948:
1949: private static void semilogy(double[] v, String opt) {
1950: if (isOnHold) {
1951: lineNum++;
1952: } else {
1953: lineNum = 1;
1954: }
1955: String fileName = null;
1956: fileName = save(v);
1957: String s = null;
1958: String options = options(opt);
1959: if (isOnHold) {
1960: String setLogScale = "set logscale y";
1961: gplot(setLogScale);
1962: String setStyle = "set style data lines";
1963: gplot(setStyle);
1964: if (lastRePlotCommands.size() > 0) {
1965: s = "replot " + "\'" + fileName + "\' t \"line "
1966: + lineNum + "\" " + options;
1967: } else {
1968: s = "plot " + "\'" + fileName + "\' t \"line "
1969: + lineNum + "\" " + options;
1970: }
1971: gplot(s);
1972: String unsetStyle = "unset style data lines";
1973: gplot(unsetStyle);
1974: String unsetLogScale = "unset logscale y";
1975: gplot(unsetLogScale);
1976: lastRePlotCommands.add(setLogScale);
1977: lastRePlotCommands.add(setStyle);
1978: lastRePlotCommands.add(s);
1979: lastRePlotCommands.add(unsetStyle);
1980: lastRePlotCommands.add(unsetLogScale);
1981: } else {
1982: resetAllLabels();
1983: String setLogScale = "set logscale y";
1984: gplot(setLogScale);
1985: String setStyle = "set style data lines";
1986: gplot(setStyle);
1987: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
1988: + "\" " + options;
1989: gplot(s);
1990: lastCommand = s;
1991: String unsetStyle = "unset style data lines";
1992: gplot(unsetStyle);
1993: String unsetLogScale = "unset logscale y";
1994: gplot(unsetLogScale);
1995: lastRePlotCommands.clear();
1996: lastPlotCommands.clear();
1997: lastPlotCommands.add(setLogScale);
1998: lastPlotCommands.add(setStyle);
1999: lastPlotCommands.add(s);
2000: lastPlotCommands.add(unsetStyle);
2001: lastPlotCommands.add(unsetLogScale);
2002: }
2003:
2004: }
2005:
2006: private static void loglog(double[] v, String opt) {
2007: if (isOnHold) {
2008: lineNum++;
2009: } else {
2010: lineNum = 1;
2011: }
2012: String fileName = null;
2013: fileName = save(v);
2014: String s = null;
2015: String options = options(opt);
2016: if (isOnHold) {
2017: String setLogScale = "set logscale xy";
2018: gplot(setLogScale);
2019: String setStyle = "set style data lines";
2020: gplot(setStyle);
2021: if (lastRePlotCommands.size() > 0) {
2022: s = "replot " + "\'" + fileName + "\' t \"line "
2023: + lineNum + "\" " + options;
2024: } else {
2025: s = "plot " + "\'" + fileName + "\' t \"line "
2026: + lineNum + "\" " + options;
2027: }
2028: gplot(s);
2029: String unsetStyle = "unset style data lines";
2030: gplot(unsetStyle);
2031: String unsetLogScale = "unset logscale xy";
2032: gplot(unsetLogScale);
2033: lastRePlotCommands.add(setLogScale);
2034: lastRePlotCommands.add(setStyle);
2035: lastRePlotCommands.add(s);
2036: lastRePlotCommands.add(unsetStyle);
2037: lastRePlotCommands.add(unsetLogScale);
2038: } else {
2039: resetAllLabels();
2040: String setLogScale = "set logscale xy";
2041: gplot(setLogScale);
2042: String setStyle = "set style data lines";
2043: gplot(setStyle);
2044: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
2045: + "\" " + options;
2046: gplot(s);
2047: lastCommand = s;
2048: String unsetStyle = "unset style data lines";
2049: gplot(unsetStyle);
2050: String unsetLogScale = "unset logscale xy";
2051: gplot(unsetLogScale);
2052: lastRePlotCommands.clear();
2053: lastPlotCommands.clear();
2054: lastPlotCommands.add(setLogScale);
2055: lastPlotCommands.add(setStyle);
2056: lastPlotCommands.add(s);
2057: lastPlotCommands.add(unsetStyle);
2058: lastPlotCommands.add(unsetLogScale);
2059: }
2060:
2061: }
2062:
2063: public static void PLOT(IMatrix m) {
2064: String s = null;
2065: PLOT(m, s);
2066: }
2067:
2068: public static void PLOT(IMatrix m, IMatrix n) {
2069: PLOT(m, n, null);
2070: }
2071:
2072: public static void PLOT(IMatrix m, IMatrix n, String opt) {
2073: int rows1 = m.getRows();
2074: int rows2 = n.getRows();
2075: int cols1 = m.getCols();
2076: int cols2 = n.getCols();
2077: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2078: double[] v = null;
2079: double[] w = null;
2080: if (rows1 == 1) {
2081: v = m.getRealRow(1);
2082: } else if (cols1 == 1) {
2083: v = m.getRealCol(1);
2084: } else {
2085:
2086: }
2087: if (rows2 == 1) {
2088: w = n.getRealRow(1);
2089: } else if (cols2 == 1) {
2090: w = n.getRealCol(1);
2091: } else {
2092:
2093: }
2094: plot(v, w, opt);
2095: }
2096:
2097: }
2098:
2099: public static void PLOT(IMatrix m, String opt) {
2100: int rows = m.getRows();
2101: int cols = m.getCols();
2102: if (m.isAllReal()) {
2103: if (rows == 1 || cols == 1) {
2104: if (rows == 1) {
2105: double[] v = m.getRealRow(1);
2106: plot(v, opt);
2107: } else {
2108: double[] v = m.getRealCol(1);
2109: plot(v, opt);
2110: }
2111: } else {
2112: double[][] v = m.getRealMatrix();
2113: plot(v, opt);
2114: }
2115: } else {
2116: if (rows == 1 || cols == 1) {
2117: if (rows == 1) {
2118: double[] v = m.getRealRow(1);
2119: double[] w = m.getImagRow(1);
2120: plot(v, w, opt);
2121: } else {
2122: double[] v = m.getRealCol(1);
2123: double[] w = m.getImagCol(1);
2124: plot(v, w, opt);
2125: }
2126: } else {
2127: double[][] v = m.getRealMatrix();
2128: double[][] w = m.getImagMatrix();
2129: plot(v, w, opt);
2130: }
2131: }
2132:
2133: }
2134:
2135: public static void SEMILOGX(IMatrix m) {
2136: String s = null;
2137: SEMILOGX(m, s);
2138: }
2139:
2140: public static void SEMILOGX(IMatrix m, IMatrix n) {
2141: SEMILOGX(m, n, null);
2142: }
2143:
2144: public static void SEMILOGX(IMatrix m, IMatrix n, String opt) {
2145: int rows1 = m.getRows();
2146: int rows2 = n.getRows();
2147: int cols1 = m.getCols();
2148: int cols2 = n.getCols();
2149: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2150: double[] v = null;
2151: double[] w = null;
2152: if (rows1 == 1) {
2153: v = m.getRealRow(1);
2154: } else if (cols1 == 1) {
2155: v = m.getRealCol(1);
2156: } else {
2157:
2158: }
2159: if (rows2 == 1) {
2160: w = n.getRealRow(1);
2161: } else if (cols2 == 1) {
2162: w = n.getRealCol(1);
2163: } else {
2164:
2165: }
2166: semilogx(v, w, opt);
2167: }
2168: }
2169:
2170: public static void SEMILOGY(IMatrix m) {
2171: String s = null;
2172: SEMILOGY(m, s);
2173: }
2174:
2175: public static void LOGLOG(IMatrix m) {
2176: String s = null;
2177: LOGLOG(m, s);
2178: }
2179:
2180: public static void SEMILOGX(IMatrix m, String opt) {
2181: int rows = m.getRows();
2182: int cols = m.getCols();
2183: if (m.isAllReal()) {
2184: if (rows == 1 || cols == 1) {
2185: if (rows == 1) {
2186: double[] v = m.getRealRow(1);
2187: semilogx(v, opt);
2188: } else {
2189: double[] v = m.getRealCol(1);
2190: semilogx(v, opt);
2191: }
2192: } else {
2193: double[][] v = m.getRealMatrix();
2194: semilogx(v, opt);
2195: }
2196: } else {
2197: if (rows == 1 || cols == 1) {
2198: if (rows == 1) {
2199: double[] v = m.getRealRow(1);
2200: double[] w = m.getImagRow(1);
2201: semilogx(v, w, opt);
2202: } else {
2203: double[] v = m.getRealCol(1);
2204: double[] w = m.getImagCol(1);
2205: semilogx(v, w, opt);
2206: }
2207: } else {
2208: double[][] v = m.getRealMatrix();
2209: double[][] w = m.getImagMatrix();
2210: semilogx(v, w, opt);
2211: }
2212: }
2213: }
2214:
2215: public static void SEMILOGY(IMatrix m, String opt) {
2216: int rows = m.getRows();
2217: int cols = m.getCols();
2218: if (m.isAllReal()) {
2219: if (rows == 1 || cols == 1) {
2220: if (rows == 1) {
2221: double[] v = m.getRealRow(1);
2222: semilogy(v, opt);
2223: } else {
2224: double[] v = m.getRealCol(1);
2225: semilogy(v, opt);
2226: }
2227: } else {
2228: double[][] v = m.getRealMatrix();
2229: semilogy(v, opt);
2230: }
2231: } else {
2232: if (rows == 1 || cols == 1) {
2233: if (rows == 1) {
2234: double[] v = m.getRealRow(1);
2235: double[] w = m.getImagRow(1);
2236: semilogy(v, w, opt);
2237: } else {
2238: double[] v = m.getRealCol(1);
2239: double[] w = m.getImagCol(1);
2240: semilogy(v, w, opt);
2241: }
2242: } else {
2243: double[][] v = m.getRealMatrix();
2244: double[][] w = m.getImagMatrix();
2245: semilogy(v, w, opt);
2246: }
2247: }
2248: }
2249:
2250: public static void SEMILOGY(IMatrix m, IMatrix n) {
2251: SEMILOGY(m, n, null);
2252: }
2253:
2254: public static void SEMILOGY(IMatrix m, IMatrix n, String opt) {
2255: int rows1 = m.getRows();
2256: int rows2 = n.getRows();
2257: int cols1 = m.getCols();
2258: int cols2 = n.getCols();
2259: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2260: double[] v = null;
2261: double[] w = null;
2262: if (rows1 == 1) {
2263: v = m.getRealRow(1);
2264: } else if (cols1 == 1) {
2265: v = m.getRealCol(1);
2266: } else {
2267:
2268: }
2269: if (rows2 == 1) {
2270: w = n.getRealRow(1);
2271: } else if (cols2 == 1) {
2272: w = n.getRealCol(1);
2273: } else {
2274:
2275: }
2276: semilogy(v, w, opt);
2277: }
2278: }
2279:
2280: public static void LOGLOG(IMatrix m, IMatrix n) {
2281: LOGLOG(m, n, null);
2282: }
2283:
2284: public static void LOGLOG(IMatrix m, IMatrix n, String opt) {
2285: int rows1 = m.getRows();
2286: int rows2 = n.getRows();
2287: int cols1 = m.getCols();
2288: int cols2 = n.getCols();
2289: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2290: double[] v = null;
2291: double[] w = null;
2292: if (rows1 == 1) {
2293: v = m.getRealRow(1);
2294: } else if (cols1 == 1) {
2295: v = m.getRealCol(1);
2296: } else {
2297:
2298: }
2299: if (rows2 == 1) {
2300: w = n.getRealRow(1);
2301: } else if (cols2 == 1) {
2302: w = n.getRealCol(1);
2303: } else {
2304:
2305: }
2306: loglog(v, w, opt);
2307: }
2308: }
2309:
2310: public static void LOGLOG(IMatrix m, String opt) {
2311: int rows = m.getRows();
2312: int cols = m.getCols();
2313: if (m.isAllReal()) {
2314: if (rows == 1 || cols == 1) {
2315: if (rows == 1) {
2316: double[] v = m.getRealRow(1);
2317: loglog(v, opt);
2318: } else {
2319: double[] v = m.getRealCol(1);
2320: loglog(v, opt);
2321: }
2322: } else {
2323: double[][] v = m.getRealMatrix();
2324: loglog(v, opt);
2325: }
2326: } else {
2327: if (rows == 1 || cols == 1) {
2328: if (rows == 1) {
2329: double[] v = m.getRealRow(1);
2330: double[] w = m.getImagRow(1);
2331: loglog(v, w, opt);
2332: } else {
2333: double[] v = m.getRealCol(1);
2334: double[] w = m.getImagCol(1);
2335: loglog(v, w, opt);
2336: }
2337: } else {
2338: double[][] v = m.getRealMatrix();
2339: double[][] w = m.getImagMatrix();
2340: loglog(v, w, opt);
2341: }
2342: }
2343: }
2344:
2345: public static void POLAR(IMatrix m, IMatrix n) {
2346: int rows1 = m.getRows();
2347: int rows2 = n.getRows();
2348: int cols1 = m.getCols();
2349: int cols2 = n.getCols();
2350: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2351: double[] v = null;
2352: double[] w = null;
2353: if (rows1 == 1) {
2354: v = m.getRealRow(1);
2355: } else if (cols1 == 1) {
2356: v = m.getRealCol(1);
2357: } else {
2358:
2359: }
2360: if (rows2 == 1) {
2361: w = n.getRealRow(1);
2362: } else if (cols2 == 1) {
2363: w = n.getRealCol(1);
2364: } else {
2365:
2366: }
2367: polar(v, w);
2368: }
2369:
2370: }
2371:
2372: public static void POLAR(IMatrix m, IMatrix n, String opt) {
2373: int rows1 = m.getRows();
2374: int rows2 = n.getRows();
2375: int cols1 = m.getCols();
2376: int cols2 = n.getCols();
2377: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
2378: double[] v = null;
2379: double[] w = null;
2380: if (rows1 == 1) {
2381: v = m.getRealRow(1);
2382: } else if (cols1 == 1) {
2383: v = m.getRealCol(1);
2384: } else {
2385:
2386: }
2387: if (rows2 == 1) {
2388: w = n.getRealRow(1);
2389: } else if (cols2 == 1) {
2390: w = n.getRealCol(1);
2391: } else {
2392:
2393: }
2394: polar(v, w, opt);
2395: }
2396:
2397: }
2398:
2399: private static String options(String opt) {
2400: if (opt == null) {
2401: return "";
2402: }
2403:
2404: boolean setColor = false;
2405: boolean setSymbol = false;
2406: boolean setLines = false;
2407: boolean setDots = false;
2408: boolean setPoints = false;
2409: boolean setImpulses = false;
2410: boolean setSteps = false;
2411: boolean setBoxes = false;
2412: boolean setYErrBars = false;
2413: boolean setXErrBars = false;
2414: char symbol = ' ';
2415: char color = ' ';
2416: String lineStyle = "solid";
2417: String keyTitle = "";
2418: String WITH = " w";
2419: String LINES = "l";
2420: String LINESPOINTS = "linesp";
2421: String BOXERRORBARS = "boxer";
2422: String BOXES = "boxes";
2423: String BOXXY = "boxxy";
2424: String POINTS = "p";
2425: String DOTS = "d";
2426: String IMPULSES = "i";
2427: String STEPS = "s";
2428: String YERRORBARS = "yerr";
2429: String XERRORBARS = "xerr";
2430: String XYERRORBARS = "xyerr";
2431: String TITLE = "title";
2432:
2433: StringBuffer sb = new StringBuffer();
2434: int len = opt.length();
2435: for (int i = 0; i < len; i++) {
2436: char ch = opt.charAt(i);
2437: if (ch == '-') {
2438: if (setLines) {
2439: lineStyle = "dash";
2440: } else {
2441: setLines = true;
2442: }
2443: } else if (ch == '.') {
2444: if (setLines) {
2445: lineStyle = "dashdot";
2446: } else {
2447: setDots = true;
2448: }
2449: } else if (ch == ':') {
2450: setLines = true;
2451: lineStyle = "dot";
2452: } else if (ch == '@') {
2453: setPoints = true;
2454: } else if (ch == '^') {
2455: setImpulses = true;
2456: } else if (ch == 'L') {
2457: setSteps = true;
2458: } else if (ch == '~') {
2459: setYErrBars = true;
2460: } else if (ch == '>') {
2461: setXErrBars = true;
2462: } else if (ch == '#') {
2463: setBoxes = true;
2464: } else if (ch >= '0' && ch <= '9') {
2465: if (setColor) {
2466: setPoints = true;
2467: symbol = ch;
2468: setSymbol = true;
2469: } else {
2470: color = ch;
2471: setColor = true;
2472: }
2473: } else if (ch == 'r') {
2474: setColor = true;
2475: color = '1';
2476: } else if (ch == 'g') {
2477: setColor = true;
2478: color = '2';
2479: } else if (ch == 'b') {
2480: setColor = true;
2481: color = '3';
2482: } else if (ch == 'm') {
2483: setColor = true;
2484: color = '4';
2485: } else if (ch == 'c') {
2486: setColor = true;
2487: color = '5';
2488: } else if (ch == 'w' || ch == 'k') {
2489: setColor = true;
2490: color = '6';
2491: } else if (ch == '*') {
2492: setPoints = true;
2493: setSymbol = true;
2494: symbol = '6';
2495: } else if (ch == '+') {
2496: setPoints = true;
2497: setSymbol = true;
2498: symbol = '2';
2499: } else if (ch == 'o') {
2500: setPoints = true;
2501: setSymbol = true;
2502: symbol = '1';
2503: } else if (ch == 'x') {
2504: setPoints = true;
2505: setSymbol = true;
2506: symbol = '4';
2507: }
2508: }
2509:
2510: sb.append(WITH);
2511: if (setLines) {
2512: if (setPoints) {
2513: sb.append(" ");
2514: sb.append(LINESPOINTS);
2515: } else {
2516: sb.append(" ");
2517: sb.append(LINES);
2518: }
2519: } else if (setBoxes) {
2520: if (setYErrBars && setXErrBars) {
2521: sb.append(" ");
2522: sb.append(BOXXY);
2523: } else if (setYErrBars) {
2524: sb.append(" ");
2525: sb.append(BOXERRORBARS);
2526: } else {
2527: sb.append(" ");
2528: sb.append(BOXES);
2529: }
2530: } else if (setPoints) {
2531: sb.append(" ");
2532: sb.append(POINTS);
2533: } else if (setDots) {
2534: sb.append(" ");
2535: sb.append(DOTS);
2536: } else if (setImpulses) {
2537: sb.append(" ");
2538: sb.append(IMPULSES);
2539: } else if (setSteps) {
2540: sb.append(" ");
2541: sb.append(STEPS);
2542: } else if (setYErrBars) {
2543: if (setXErrBars) {
2544: sb.append(" ");
2545: sb.append(XYERRORBARS);
2546: } else {
2547: sb.append(" ");
2548: sb.append(YERRORBARS);
2549: }
2550: } else if (setXErrBars) {
2551: sb.append(" ");
2552: sb.append(XERRORBARS);
2553: }
2554:
2555: if (sb.toString().equals(WITH)) {
2556: sb.append(" ");
2557: sb.append(LINES);
2558: }
2559:
2560: if (setColor) {
2561: sb.append(" ");
2562: sb.append(color);
2563: if (setSymbol) {
2564: sb.append(" ");
2565: sb.append(symbol);
2566: }
2567: } else if (setSymbol) {
2568: sb.append(" 1 ");
2569: sb.append(symbol);
2570: }
2571: return " " + sb.toString();
2572: }
2573:
2574: private static void semilogx(double[][] v, String opt) {
2575: int rows = v.length;
2576: int cols = v[0].length;
2577:
2578: String fileName = null;
2579:
2580: double[] domain = new double[rows];
2581: for (int i = 0; i < rows; i++) {
2582: domain[i] = i + 1;
2583: }
2584:
2585: List listOfFiles = new ArrayList();
2586: for (int i = 0; i < cols; i++) {
2587: double[] range = new double[rows];
2588: for (int j = 0; j < rows; j++) {
2589: range[j] = v[j][i];
2590: }
2591: listOfFiles.add(save(domain, range));
2592: }
2593:
2594: String s = null;
2595: String options = options(opt);
2596: if (isOnHold) {
2597: String setLogScale = "set logscale x";
2598: gplot(setLogScale);
2599: lastRePlotCommands.add(setLogScale);
2600: String setStyle = "set style data lines";
2601: gplot(setStyle);
2602: lastRePlotCommands.add(setStyle);
2603: Iterator iter = listOfFiles.iterator();
2604: int count = 0;
2605: while (iter.hasNext()) {
2606: fileName = (String) iter.next();
2607: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
2608: .size() > 0)
2609: && (count > 0)) {
2610: s = "replot " + "\'" + fileName + "\' t \"line "
2611: + lineNum++ + "\"" + options;
2612: } else {
2613: s = "plot " + "\'" + fileName + "\' t \"line "
2614: + lineNum++ + "\"" + options;
2615: }
2616: gplot(s);
2617: lastRePlotCommands.add(s);
2618: count++;
2619: }
2620: String unsetStyle = "unset style data";
2621: gplot(unsetStyle);
2622: lastRePlotCommands.add(unsetStyle);
2623: String unsetLogScale = "unset logscale x";
2624: gplot(unsetLogScale);
2625: lastRePlotCommands.add(unsetLogScale);
2626: } else {
2627: resetAllLabels();
2628: lastRePlotCommands.clear();
2629: lastPlotCommands.clear();
2630: String setLogScale = "set logscale x";
2631: gplot(setLogScale);
2632: lastPlotCommands.add(setLogScale);
2633: String setStyle = "set style data lines";
2634: gplot(setStyle);
2635: lastPlotCommands.add(setStyle);
2636: Iterator iter = listOfFiles.iterator();
2637: int count = 0;
2638: while (iter.hasNext()) {
2639: fileName = (String) iter.next();
2640: if (count > 0) {
2641: s = "replot " + "\'" + fileName + "\' t \"line "
2642: + lineNum++ + "\"" + options;
2643: } else {
2644: s = "plot " + "\'" + fileName + "\' t \"line "
2645: + lineNum++ + "\"" + options;
2646: }
2647: gplot(s);
2648: lastPlotCommands.add(s);
2649: count++;
2650: }
2651: lastCommand = s;
2652: String unsetStyle = "unset style data";
2653: gplot(unsetStyle);
2654: lastPlotCommands.add(unsetStyle);
2655: String unsetLogScale = "unset logscale x";
2656: gplot(unsetLogScale);
2657: lastPlotCommands.add(unsetLogScale);
2658: }
2659:
2660: }
2661:
2662: private static void semilogy(double[][] v, String opt) {
2663: int rows = v.length;
2664: int cols = v[0].length;
2665:
2666: String fileName = null;
2667:
2668: double[] domain = new double[rows];
2669: for (int i = 0; i < rows; i++) {
2670: domain[i] = i + 1;
2671: }
2672:
2673: List listOfFiles = new ArrayList();
2674: for (int i = 0; i < cols; i++) {
2675: double[] range = new double[rows];
2676: for (int j = 0; j < rows; j++) {
2677: range[j] = v[j][i];
2678: }
2679: listOfFiles.add(save(domain, range));
2680: }
2681:
2682: String s = null;
2683: String options = options(opt);
2684: if (isOnHold) {
2685: String setLogScale = "set logscale y";
2686: gplot(setLogScale);
2687: lastRePlotCommands.add(setLogScale);
2688: String setStyle = "set style data lines";
2689: gplot(setStyle);
2690: lastRePlotCommands.add(setStyle);
2691: Iterator iter = listOfFiles.iterator();
2692: int count = 0;
2693: while (iter.hasNext()) {
2694: fileName = (String) iter.next();
2695: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
2696: .size() > 0)
2697: && (count > 0)) {
2698: s = "replot " + "\'" + fileName + "\' t \"line "
2699: + lineNum++ + "\"" + options;
2700: } else {
2701: s = "plot " + "\'" + fileName + "\' t \"line "
2702: + lineNum++ + "\"" + options;
2703: }
2704: gplot(s);
2705: lastRePlotCommands.add(s);
2706: count++;
2707: }
2708: String unsetStyle = "unset style data";
2709: gplot(unsetStyle);
2710: lastRePlotCommands.add(unsetStyle);
2711: String unsetLogScale = "unset logscale y";
2712: gplot(unsetLogScale);
2713: lastRePlotCommands.add(unsetLogScale);
2714: } else {
2715: resetAllLabels();
2716: lastRePlotCommands.clear();
2717: lastPlotCommands.clear();
2718: String setLogScale = "set logscale y";
2719: gplot(setLogScale);
2720: lastPlotCommands.add(setLogScale);
2721: String setStyle = "set style data lines";
2722: gplot(setStyle);
2723: lastPlotCommands.add(setStyle);
2724: Iterator iter = listOfFiles.iterator();
2725: int count = 0;
2726: while (iter.hasNext()) {
2727: fileName = (String) iter.next();
2728: if (count > 0) {
2729: s = "replot " + "\'" + fileName + "\' t \"line "
2730: + lineNum++ + "\"" + options;
2731: } else {
2732: s = "plot " + "\'" + fileName + "\' t \"line "
2733: + lineNum++ + "\"" + options;
2734: }
2735: gplot(s);
2736: lastPlotCommands.add(s);
2737: count++;
2738: }
2739: lastCommand = s;
2740: String unsetStyle = "unset style data";
2741: gplot(unsetStyle);
2742: lastPlotCommands.add(unsetStyle);
2743: String unsetLogScale = "unset logscale y";
2744: gplot(unsetLogScale);
2745: lastPlotCommands.add(unsetLogScale);
2746: }
2747:
2748: }
2749:
2750: private static void loglog(double[][] v, String opt) {
2751: int rows = v.length;
2752: int cols = v[0].length;
2753:
2754: String fileName = null;
2755:
2756: double[] domain = new double[rows];
2757: for (int i = 0; i < rows; i++) {
2758: domain[i] = i + 1;
2759: }
2760:
2761: List listOfFiles = new ArrayList();
2762: for (int i = 0; i < cols; i++) {
2763: double[] range = new double[rows];
2764: for (int j = 0; j < rows; j++) {
2765: range[j] = v[j][i];
2766: }
2767: listOfFiles.add(save(domain, range));
2768: }
2769:
2770: String s = null;
2771: String options = options(opt);
2772: if (isOnHold) {
2773: String setLogScale = "set logscale xy";
2774: gplot(setLogScale);
2775: lastRePlotCommands.add(setLogScale);
2776: String setStyle = "set style data lines";
2777: gplot(setStyle);
2778: lastRePlotCommands.add(setStyle);
2779: Iterator iter = listOfFiles.iterator();
2780: int count = 0;
2781: while (iter.hasNext()) {
2782: fileName = (String) iter.next();
2783: if ((lastPlotCommands.size() > 0 || lastRePlotCommands
2784: .size() > 0)
2785: && (count > 0)) {
2786: s = "replot " + "\'" + fileName + "\' t \"line "
2787: + lineNum++ + "\"" + options;
2788: } else {
2789: s = "plot " + "\'" + fileName + "\' t \"line "
2790: + lineNum++ + "\"" + options;
2791: }
2792: gplot(s);
2793: lastRePlotCommands.add(s);
2794: count++;
2795: }
2796: String unsetStyle = "unset style data";
2797: gplot(unsetStyle);
2798: lastRePlotCommands.add(unsetStyle);
2799: String unsetLogScale = "unset logscale xy";
2800: gplot(unsetLogScale);
2801: lastRePlotCommands.add(unsetLogScale);
2802: } else {
2803: resetAllLabels();
2804: lastRePlotCommands.clear();
2805: lastPlotCommands.clear();
2806: String setLogScale = "set logscale xy";
2807: gplot(setLogScale);
2808: lastPlotCommands.add(setLogScale);
2809: String setStyle = "set style data lines";
2810: gplot(setStyle);
2811: lastPlotCommands.add(setStyle);
2812: Iterator iter = listOfFiles.iterator();
2813: int count = 0;
2814: while (iter.hasNext()) {
2815: fileName = (String) iter.next();
2816: if (count > 0) {
2817: s = "replot " + "\'" + fileName + "\' t \"line "
2818: + lineNum++ + "\"" + options;
2819: } else {
2820: s = "plot " + "\'" + fileName + "\' t \"line "
2821: + lineNum++ + "\"" + options;
2822: }
2823: gplot(s);
2824: lastPlotCommands.add(s);
2825: count++;
2826: }
2827: lastCommand = s;
2828: String unsetStyle = "unset style data";
2829: gplot(unsetStyle);
2830: lastPlotCommands.add(unsetStyle);
2831: String unsetLogScale = "unset logscale xy";
2832: gplot(unsetLogScale);
2833: lastPlotCommands.add(unsetLogScale);
2834: }
2835:
2836: }
2837:
2838: private static void polar(double[] v, double[] w) {
2839: if (isOnHold) {
2840: lineNum++;
2841: } else {
2842: lineNum = 1;
2843: }
2844: String fileName = null;
2845: fileName = save(v, w);
2846: String s = null;
2847: if (isOnHold) {
2848: String setPolar = "set polar";
2849: gplot(setPolar);
2850: lastPlotCommands.add(setPolar);
2851: String setPolarGrid = "set grid polar";
2852: gplot(setPolarGrid);
2853: lastPlotCommands.add(setPolarGrid);
2854: String setStyle = "set style data lines";
2855: gplot(setStyle);
2856: lastRePlotCommands.add(setStyle);
2857: if (lastPlotCommands.size() > 0
2858: || lastRePlotCommands.size() > 0) {
2859: s = "replot " + "\'" + fileName + "\' t \"line "
2860: + lineNum + "\"";
2861: } else {
2862: s = "plot " + "\'" + fileName + "\' t \"line "
2863: + lineNum + "\"";
2864: }
2865: gplot(s);
2866: lastRePlotCommands.add(s);
2867: String unsetStyle = "unset style data";
2868: gplot(unsetStyle);
2869: lastRePlotCommands.add(unsetStyle);
2870: String unsetPolarGrid = "unset grid polar";
2871: gplot(unsetPolarGrid);
2872: lastPlotCommands.add(unsetPolarGrid);
2873: String unsetPolar = "unset polar";
2874: gplot(unsetPolar);
2875: lastPlotCommands.add(unsetPolar);
2876: } else {
2877: resetAllLabels();
2878: lastRePlotCommands.clear();
2879: lastPlotCommands.clear();
2880: String setPolar = "set polar";
2881: gplot(setPolar);
2882: lastPlotCommands.add(setPolar);
2883: String setPolarGrid = "set grid polar";
2884: gplot(setPolarGrid);
2885: lastPlotCommands.add(setPolarGrid);
2886: String setStyle = "set style data lines";
2887: gplot(setStyle);
2888: lastPlotCommands.add(setStyle);
2889: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
2890: + "\"";
2891: gplot(s);
2892: lastPlotCommands.add(s);
2893: lastCommand = s;
2894: String unsetStyle = "unset style data";
2895: gplot(unsetStyle);
2896: lastPlotCommands.add(unsetStyle);
2897: String unsetPolarGrid = "unset grid polar";
2898: gplot(unsetPolarGrid);
2899: lastPlotCommands.add(unsetPolarGrid);
2900: String unsetPolar = "unset polar";
2901: gplot(unsetPolar);
2902: lastPlotCommands.add(unsetPolar);
2903: }
2904:
2905: }
2906:
2907: private static void polar(double[] v, double[] w, String opt) {
2908: if (isOnHold) {
2909: lineNum++;
2910: } else {
2911: lineNum = 1;
2912: }
2913: String fileName = null;
2914: fileName = save(v, w);
2915: String s = null;
2916: String options = options(opt);
2917: if (isOnHold) {
2918: String setPolar = "set polar";
2919: gplot(setPolar);
2920: lastPlotCommands.add(setPolar);
2921: String setPolarGrid = "set grid polar";
2922: gplot(setPolarGrid);
2923: lastPlotCommands.add(setPolarGrid);
2924: String setStyle = "set style data lines";
2925: gplot(setStyle);
2926: lastRePlotCommands.add(setStyle);
2927: if (lastPlotCommands.size() > 0
2928: || lastRePlotCommands.size() > 0) {
2929: s = "replot " + "\'" + fileName + "\' t \"line "
2930: + lineNum + "\"" + options;
2931: } else {
2932: s = "plot " + "\'" + fileName + "\' t \"line "
2933: + lineNum + "\"" + options;
2934: }
2935: gplot(s);
2936: lastRePlotCommands.add(s);
2937: String unsetStyle = "unset style data";
2938: gplot(unsetStyle);
2939: lastRePlotCommands.add(unsetStyle);
2940: String unsetPolarGrid = "unset grid polar";
2941: gplot(unsetPolarGrid);
2942: lastPlotCommands.add(unsetPolarGrid);
2943: String unsetPolar = "unset polar";
2944: gplot(unsetPolar);
2945: lastPlotCommands.add(unsetPolar);
2946: } else {
2947: resetAllLabels();
2948: lastRePlotCommands.clear();
2949: lastPlotCommands.clear();
2950: String setPolar = "set polar";
2951: gplot(setPolar);
2952: lastPlotCommands.add(setPolar);
2953: String setPolarGrid = "set grid polar";
2954: gplot(setPolarGrid);
2955: lastPlotCommands.add(setPolarGrid);
2956: String setStyle = "set style data lines";
2957: gplot(setStyle);
2958: lastPlotCommands.add(setStyle);
2959: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
2960: + "\"" + options;
2961: gplot(s);
2962: lastPlotCommands.add(s);
2963: lastCommand = s;
2964: String unsetStyle = "unset style data";
2965: gplot(unsetStyle);
2966: lastPlotCommands.add(unsetStyle);
2967: String unsetPolarGrid = "unset grid polar";
2968: gplot(unsetPolarGrid);
2969: lastPlotCommands.add(unsetPolarGrid);
2970: String unsetPolar = "unset polar";
2971: gplot(unsetPolar);
2972: lastPlotCommands.add(unsetPolar);
2973: }
2974:
2975: }
2976:
2977: public static void BAR(IMatrix m) {
2978: int rows = m.getRows();
2979: int cols = m.getCols();
2980: if (rows == 1 || cols == 1) {
2981: if (rows == 1) {
2982: double[] v = m.getRealRow(1);
2983: bar(v);
2984: } else {
2985: double[] v = m.getRealCol(1);
2986: bar(v);
2987: }
2988: } else {
2989: double[][] v = m.getRealMatrix();
2990: plot(v);
2991: }
2992: }
2993:
2994: public static void BAR(IMatrix m, IMatrix n) {
2995: int rows1 = m.getRows();
2996: int rows2 = n.getRows();
2997: int cols1 = m.getCols();
2998: int cols2 = n.getCols();
2999: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
3000: double[] v = null;
3001: double[] w = null;
3002: if (rows1 == 1) {
3003: v = m.getRealRow(1);
3004: } else if (cols1 == 1) {
3005: v = m.getRealCol(1);
3006: } else {
3007:
3008: }
3009: if (rows2 == 1) {
3010: w = n.getRealRow(1);
3011: } else if (cols2 == 1) {
3012: w = n.getRealCol(1);
3013: } else {
3014:
3015: }
3016: bar(v, w);
3017: }
3018:
3019: }
3020:
3021: private static void bar(double[] v) {
3022: if (isOnHold) {
3023: lineNum++;
3024: } else {
3025: lineNum = 1;
3026: }
3027: String fileName = null;
3028: fileName = saveBarPoints(v);
3029: String s = null;
3030: if (isOnHold) {
3031: String setStyle = "set style data lines";
3032: gplot(setStyle);
3033: lastRePlotCommands.add(setStyle);
3034: if (lastPlotCommands.size() > 0
3035: || lastRePlotCommands.size() > 0) {
3036: s = "replot " + "\'" + fileName + "\' t \"line "
3037: + lineNum + "\"";
3038: } else {
3039: s = "plot " + "\'" + fileName + "\' t \"line "
3040: + lineNum + "\"";
3041: }
3042: gplot(s);
3043: lastRePlotCommands.add(s);
3044: String unsetStyle = "unset style data";
3045: gplot(unsetStyle);
3046: lastRePlotCommands.add(unsetStyle);
3047: } else {
3048: resetAllLabels();
3049: lastRePlotCommands.clear();
3050: lastPlotCommands.clear();
3051: String setStyle = "set style data lines";
3052: gplot(setStyle);
3053: lastPlotCommands.add(setStyle);
3054: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
3055: + "\"";
3056: gplot(s);
3057: lastPlotCommands.add(s);
3058: lastCommand = s;
3059: String unsetStyle = "unset style data";
3060: gplot(unsetStyle);
3061: lastPlotCommands.add(unsetStyle);
3062: }
3063:
3064: }
3065:
3066: private static void bar(double[] v, double[] w) {
3067: if (isOnHold) {
3068: lineNum++;
3069: } else {
3070: lineNum = 1;
3071: }
3072: String fileName = null;
3073: fileName = saveBarPoints(v, w);
3074: String s = null;
3075: if (isOnHold) {
3076: String setStyle = "set style data lines";
3077: gplot(setStyle);
3078: lastRePlotCommands.add(setStyle);
3079: if (lastPlotCommands.size() > 0
3080: || lastRePlotCommands.size() > 0) {
3081: s = "replot " + "\'" + fileName + "\' t \"line "
3082: + lineNum + "\"";
3083: } else {
3084: s = "plot " + "\'" + fileName + "\' t \"line "
3085: + lineNum + "\"";
3086: }
3087: gplot(s);
3088: lastRePlotCommands.add(s);
3089: String unsetStyle = "unset style data";
3090: gplot(unsetStyle);
3091: lastRePlotCommands.add(unsetStyle);
3092: } else {
3093: resetAllLabels();
3094: lastRePlotCommands.clear();
3095: lastPlotCommands.clear();
3096: String setStyle = "set style data lines";
3097: gplot(setStyle);
3098: lastPlotCommands.add(setStyle);
3099: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
3100: + "\"";
3101: gplot(s);
3102: lastPlotCommands.add(s);
3103: lastCommand = s;
3104: String unsetStyle = "unset style data";
3105: gplot(unsetStyle);
3106: lastPlotCommands.add(unsetStyle);
3107: }
3108:
3109: }
3110:
3111: public static void STAIRS(IMatrix m) {
3112: int rows = m.getRows();
3113: int cols = m.getCols();
3114: if (rows == 1 || cols == 1) {
3115: if (rows == 1) {
3116: double[] v = m.getRealRow(1);
3117: stairs(v);
3118: } else {
3119: double[] v = m.getRealCol(1);
3120: stairs(v);
3121: }
3122: } else {
3123: double[][] v = m.getRealMatrix();
3124: // stairs(v);
3125: }
3126: }
3127:
3128: public static void STAIRS(IMatrix m, IMatrix n) {
3129: int rows1 = m.getRows();
3130: int rows2 = n.getRows();
3131: int cols1 = m.getCols();
3132: int cols2 = n.getCols();
3133: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)) {
3134: double[] v = null;
3135: double[] w = null;
3136: if (rows1 == 1) {
3137: v = m.getRealRow(1);
3138: } else if (cols1 == 1) {
3139: v = m.getRealCol(1);
3140: } else {
3141:
3142: }
3143: if (rows2 == 1) {
3144: w = n.getRealRow(1);
3145: } else if (cols2 == 1) {
3146: w = n.getRealCol(1);
3147: } else {
3148:
3149: }
3150: stairs(v, w);
3151: }
3152:
3153: }
3154:
3155: private static void stairs(double[] v) {
3156: if (isOnHold) {
3157: lineNum++;
3158: } else {
3159: lineNum = 1;
3160: }
3161: String fileName = null;
3162: fileName = saveStairPoints(v);
3163: String s = null;
3164: if (isOnHold) {
3165: String setStyle = "set style data lines";
3166: gplot(setStyle);
3167: lastRePlotCommands.add(setStyle);
3168: if (lastPlotCommands.size() > 0
3169: || lastRePlotCommands.size() > 0) {
3170: s = "replot " + "\'" + fileName + "\' t \"line "
3171: + lineNum + "\"";
3172: } else {
3173: s = "plot " + "\'" + fileName + "\' t \"line "
3174: + lineNum + "\"";
3175: }
3176: gplot(s);
3177: lastRePlotCommands.add(s);
3178: String unsetStyle = "unset style data";
3179: gplot(unsetStyle);
3180: lastRePlotCommands.add(unsetStyle);
3181: } else {
3182: resetAllLabels();
3183: lastRePlotCommands.clear();
3184: lastPlotCommands.clear();
3185: String setStyle = "set style data lines";
3186: gplot(setStyle);
3187: lastPlotCommands.add(setStyle);
3188: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
3189: + "\"";
3190: gplot(s);
3191: lastPlotCommands.add(s);
3192: lastCommand = s;
3193: String unsetStyle = "unset style data";
3194: gplot(unsetStyle);
3195: lastPlotCommands.add(unsetStyle);
3196: }
3197:
3198: }
3199:
3200: private static void stairs(double[] v, double[] w) {
3201: if (isOnHold) {
3202: lineNum++;
3203: } else {
3204: lineNum = 1;
3205: }
3206: String fileName = null;
3207: fileName = saveStairPoints(v, w);
3208: String s = null;
3209: if (isOnHold) {
3210: String setStyle = "set style data lines";
3211: gplot(setStyle);
3212: lastRePlotCommands.add(setStyle);
3213: if (lastPlotCommands.size() > 0
3214: || lastRePlotCommands.size() > 0) {
3215: s = "replot " + "\'" + fileName + "\' t \"line "
3216: + lineNum + "\"";
3217: } else {
3218: s = "plot " + "\'" + fileName + "\' t \"line "
3219: + lineNum + "\"";
3220: }
3221: gplot(s);
3222: lastRePlotCommands.add(s);
3223: String unsetStyle = "unset style data";
3224: gplot(unsetStyle);
3225: lastRePlotCommands.add(unsetStyle);
3226: } else {
3227: resetAllLabels();
3228: lastRePlotCommands.clear();
3229: lastPlotCommands.clear();
3230: String setStyle = "set style data lines";
3231: gplot(setStyle);
3232: lastPlotCommands.add(setStyle);
3233: s = "plot " + "\'" + fileName + "\' t \"line " + lineNum
3234: + "\"";
3235: gplot(s);
3236: lastPlotCommands.add(s);
3237: lastCommand = s;
3238: String unsetStyle = "unset style data";
3239: gplot(unsetStyle);
3240: lastPlotCommands.add(unsetStyle);
3241: }
3242:
3243: }
3244:
3245: public static void HIST(IMatrix m) {
3246: int rows = m.getRows();
3247: int cols = m.getCols();
3248: if (rows == 1 || cols == 1) {
3249: if (rows == 1) {
3250: double[] v = m.getRealRow(1);
3251: hist(v);
3252: } else {
3253: double[] v = m.getRealCol(1);
3254: hist(v);
3255: }
3256: } else {
3257: double[][] v = m.getRealMatrix();
3258: }
3259: }
3260:
3261: private static void hist(double[] v) {
3262: int size = v.length;
3263: double max = v[size - 1];
3264: double min = v[0];
3265: for (int i = 0; i < size; i++) {
3266: if (v[i] > max) {
3267: max = v[i];
3268: }
3269: if (v[i] < min) {
3270: min = v[i];
3271: }
3272: }
3273: double diff = max - min;
3274: double interval = diff / 10;
3275: diff = max - min + 2 * interval;
3276: interval = diff / 10;
3277: double[] bins = new double[10];
3278: double[] x = new double[10];
3279: double start = min - interval;
3280: for (int i = 0; i < 10; i++) {
3281: bins[i] = 0.0;
3282: for (int j = 0; j < size; j++) {
3283: if (v[j] > start && v[j] <= start + interval) {
3284: bins[i] = bins[i] + 1.0;
3285: }
3286: }
3287: x[i] = (2 * start + interval) / 2.0;
3288: start = start + interval;
3289: }
3290: bar(x, bins);
3291: }
3292:
3293: public static void PLOT3(IMatrix x, IMatrix y, IMatrix z) {
3294: PLOT3(x, y, z, null);
3295: }
3296:
3297: private static void plot(double[] u, double[] v, double[] w) {
3298: plot(u, v, w, null);
3299: }
3300:
3301: public static void PLOT3(IMatrix x, IMatrix y, IMatrix z, String opt) {
3302: int rows1 = x.getRows();
3303: int rows2 = y.getRows();
3304: int rows3 = z.getRows();
3305: int cols1 = x.getCols();
3306: int cols2 = y.getCols();
3307: int cols3 = z.getCols();
3308: if ((rows1 == 1 || cols1 == 1) && (rows2 == 1 || cols2 == 1)
3309: && (rows3 == 1 || cols3 == 1)) {
3310: double[] u = null;
3311: double[] v = null;
3312: double[] w = null;
3313: if (rows1 == 1) {
3314: u = x.getRealRow(1);
3315: } else if (cols1 == 1) {
3316: u = x.getRealCol(1);
3317: } else {
3318:
3319: }
3320: if (rows2 == 1) {
3321: v = y.getRealRow(1);
3322: } else if (cols2 == 1) {
3323: v = y.getRealCol(1);
3324: } else {
3325:
3326: }
3327: if (rows3 == 1) {
3328: w = z.getRealRow(1);
3329: } else if (cols2 == 1) {
3330: w = z.getRealCol(1);
3331: } else {
3332:
3333: }
3334: plot(u, v, w, opt);
3335: }
3336:
3337: }
3338:
3339: private static void plot(double[] u, double[] v, double[] w,
3340: String opt) {
3341: if (isOnHold) {
3342: lineNum++;
3343: } else {
3344: lineNum = 1;
3345: }
3346: String fileName = null;
3347: fileName = save(u, v, w);
3348: String s = null;
3349: String options = options(opt);
3350: if (isOnHold) {
3351: String setSurface = "set surface";
3352: gplot(setSurface);
3353: lastRePlotCommands.add(setSurface);
3354: String setStyle = "set style data lines";
3355: gplot(setStyle);
3356: lastRePlotCommands.add(setStyle);
3357: String setParameteric = "set parametric";
3358: gplot(setParameteric);
3359: lastRePlotCommands.add(setParameteric);
3360: String unsetHidden = "unset hidden3d";
3361: gplot(unsetHidden);
3362: lastRePlotCommands.add(unsetHidden);
3363: if (lastPlotCommands.size() > 0
3364: || lastRePlotCommands.size() > 0) {
3365: s = "replot " + "\'" + fileName + "\' t \"line "
3366: + lineNum + "\" " + options;
3367: } else {
3368: s = "splot " + "\'" + fileName + "\' t \"line "
3369: + lineNum + "\" " + options;
3370: }
3371: gplot(s);
3372: lastRePlotCommands.add(s);
3373: String setHidden = "set hidden3d";
3374: gplot(setHidden);
3375: lastRePlotCommands.add(setHidden);
3376: String unsetParameteric = "unset parametric";
3377: gplot(unsetParameteric);
3378: lastRePlotCommands.add(unsetParameteric);
3379: String unsetStyle = "unset style data";
3380: gplot(unsetStyle);
3381: lastRePlotCommands.add(unsetStyle);
3382: String unsetSurface = "unset surface";
3383: gplot(unsetSurface);
3384: lastRePlotCommands.add(unsetSurface);
3385: } else {
3386: resetAllLabels();
3387: lastRePlotCommands.clear();
3388: lastPlotCommands.clear();
3389: String setSurface = "set surface";
3390: gplot(setSurface);
3391: lastPlotCommands.add(setSurface);
3392: String setStyle = "set style data lines";
3393: gplot(setStyle);
3394: lastPlotCommands.add(setStyle);
3395: String setParameteric = "set parametric";
3396: gplot(setParameteric);
3397: lastPlotCommands.add(setParameteric);
3398: String unsetHidden = "unset hidden3d";
3399: gplot(unsetHidden);
3400: lastPlotCommands.add(unsetHidden);
3401: s = "splot " + "\'" + fileName + "\' t \"line " + lineNum
3402: + "\" " + options;
3403: gplot(s);
3404: lastCommand = s;
3405: lastPlotCommands.add(s);
3406: String setHidden = "set hidden3d";
3407: gplot(setHidden);
3408: lastPlotCommands.add(setHidden);
3409: String unsetParameteric = "unset parametric";
3410: gplot(unsetParameteric);
3411: lastPlotCommands.add(unsetParameteric);
3412: String unsetStyle = "unset style data";
3413: gplot(unsetStyle);
3414: lastPlotCommands.add(unsetStyle);
3415: String unsetSurface = "unset surface";
3416: gplot(unsetSurface);
3417: lastPlotCommands.add(unsetSurface);
3418: }
3419:
3420: }
3421:
3422: public static void MESH(IMatrix m) {
3423: int rows = m.getRows();
3424: int cols = m.getCols();
3425: double[] x = new double[rows];
3426: for (int i = 0; i < rows; i++) {
3427: x[i] = i + 1;
3428: }
3429: double[] y = new double[cols];
3430: for (int i = 0; i < cols; i++) {
3431: y[i] = i + 1;
3432: }
3433: mesh(x, y, m.getRealMatrix());
3434: }
3435:
3436: public static void MESH(IMatrix x, IMatrix y, IMatrix m) {
3437: int rows1 = x.getRows();
3438: int cols1 = x.getCols();
3439: int rows2 = y.getRows();
3440: int cols2 = y.getCols();
3441:
3442: double[] u = null;
3443: double[] v = null;
3444:
3445: if (rows1 == 1 || cols1 == 1) {
3446: if (rows1 == 1) {
3447: u = x.getRealRow(1);
3448: } else {
3449: u = x.getRealCol(1);
3450: }
3451: }
3452: if (rows2 == 1 || cols2 == 1) {
3453: if (rows2 == 1) {
3454: v = x.getRealRow(1);
3455: } else {
3456: v = x.getRealCol(1);
3457: }
3458: }
3459: mesh(u, v, m.getRealMatrix());
3460: }
3461:
3462: private static void mesh(double[] u, double[] v, double[][] w) {
3463: if (isOnHold) {
3464: lineNum++;
3465: } else {
3466: lineNum = 1;
3467: }
3468: String fileName = null;
3469: fileName = saveContour(u, v, w);
3470: String s = null;
3471: String options = options("b");
3472: if (isOnHold) {
3473: String setHidden = "set hidden3d";
3474: gplot(setHidden);
3475: lastRePlotCommands.add(setHidden);
3476: String setStyle = "set style data lines";
3477: gplot(setStyle);
3478: lastRePlotCommands.add(setStyle);
3479: String setSurface = "set surface";
3480: gplot(setSurface);
3481: lastRePlotCommands.add(setSurface);
3482: String unsetContour = "unset contour";
3483: gplot(unsetContour);
3484: lastRePlotCommands.add(unsetContour);
3485: String setView = "set view 60, 30, 1, 1";
3486: gplot(setView);
3487: lastRePlotCommands.add(setView);
3488: if (lastPlotCommands.size() > 0
3489: || lastRePlotCommands.size() > 0) {
3490: s = "replot " + "\'" + fileName + "\' t \"line "
3491: + lineNum + "\" " + options;
3492: } else {
3493: s = "splot " + "\'" + fileName + "\' t \"line "
3494: + lineNum + "\" " + options;
3495: }
3496: gplot(s);
3497: lastRePlotCommands.add(s);
3498: /* String unsetView = "unset view";
3499: gplot(unsetView);
3500: lastRePlotCommands.add(unsetView);
3501: String setContour = "set contour";
3502: gplot(setContour);
3503: lastRePlotCommands.add(setContour);
3504: String unsetSurface = "unset surface";
3505: gplot(unsetSurface);
3506: lastRePlotCommands.add(unsetSurface);
3507: String unsetStyle = "unset style data";
3508: gplot(unsetStyle);
3509: lastRePlotCommands.add(unsetStyle);
3510: String unsetHidden = "unset hidden3d";
3511: gplot(unsetHidden);
3512: lastRePlotCommands.add(unsetHidden);
3513: */} else {
3514: resetAllLabels();
3515: lastRePlotCommands.clear();
3516: lastPlotCommands.clear();
3517: String setHidden = "set hidden3d";
3518: gplot(setHidden);
3519: lastPlotCommands.add(setHidden);
3520: String setStyle = "set style data lines";
3521: gplot(setStyle);
3522: lastPlotCommands.add(setStyle);
3523: String setSurface = "set surface";
3524: gplot(setSurface);
3525: lastPlotCommands.add(setSurface);
3526: String unsetContour = "unset contour";
3527: gplot(unsetContour);
3528: lastPlotCommands.add(unsetContour);
3529: String setView = "set view 60, 30, 1, 1";
3530: gplot(setView);
3531: lastPlotCommands.add(setView);
3532: s = "splot " + "\'" + fileName + "\' t \"line " + lineNum
3533: + "\" " + options;
3534: gplot(s);
3535: lastCommand = s;
3536: lastPlotCommands.add(s);
3537: /* String unsetView = "unset view";
3538: gplot(unsetView);
3539: lastPlotCommands.add(unsetView);
3540: String setContour = "set contour";
3541: gplot(setContour);
3542: lastPlotCommands.add(setContour);
3543: String unsetSurface = "unset surface";
3544: gplot(unsetSurface);
3545: lastPlotCommands.add(unsetSurface);
3546: String unsetStyle = "unset style data";
3547: gplot(unsetStyle);
3548: lastPlotCommands.add(unsetStyle);
3549: String unsetHidden = "unset hidden3d";
3550: gplot(unsetHidden);
3551: lastPlotCommands.add(unsetHidden);
3552: */}
3553:
3554: }
3555:
3556: public static void MESHC(IMatrix m) {
3557: int rows = m.getRows();
3558: int cols = m.getCols();
3559: double[] x = new double[rows];
3560: for (int i = 0; i < rows; i++) {
3561: x[i] = i + 1;
3562: }
3563: double[] y = new double[cols];
3564: for (int i = 0; i < cols; i++) {
3565: y[i] = i + 1;
3566: }
3567: meshc(x, y, m.getRealMatrix());
3568: }
3569:
3570: public static void MESHC(IMatrix x, IMatrix y, IMatrix m) {
3571: int rows1 = x.getRows();
3572: int cols1 = x.getCols();
3573: int rows2 = y.getRows();
3574: int cols2 = y.getCols();
3575:
3576: double[] u = null;
3577: double[] v = null;
3578:
3579: if (rows1 == 1 || cols1 == 1) {
3580: if (rows1 == 1) {
3581: u = x.getRealRow(1);
3582: } else {
3583: u = x.getRealCol(1);
3584: }
3585: }
3586: if (rows2 == 1 || cols2 == 1) {
3587: if (rows2 == 1) {
3588: v = x.getRealRow(1);
3589: } else {
3590: v = x.getRealCol(1);
3591: }
3592: }
3593: meshc(u, v, m.getRealMatrix());
3594: }
3595:
3596: private static void meshc(double[] u, double[] v, double[][] w) {
3597: if (isOnHold) {
3598: lineNum++;
3599: } else {
3600: lineNum = 1;
3601: }
3602: String fileName = null;
3603: fileName = saveContour(u, v, w);
3604: String s = null;
3605: if (isOnHold) {
3606: String setHidden = "set hidden3d";
3607: gplot(setHidden);
3608: lastRePlotCommands.add(setHidden);
3609: String setStyle = "set style data lines";
3610: gplot(setStyle);
3611: lastRePlotCommands.add(setStyle);
3612: String setSurface = "set surface";
3613: gplot(setSurface);
3614: lastRePlotCommands.add(setSurface);
3615: String setContour = "set contour";
3616: gplot(setContour);
3617: lastRePlotCommands.add(setContour);
3618: String setLevel = "set cntrparam levels 10";
3619: gplot(setLevel);
3620: lastRePlotCommands.add(setLevel);
3621: String setView = "set view 60, 30, 1, 1";
3622: gplot(setView);
3623: lastRePlotCommands.add(setView);
3624: if (lastPlotCommands.size() > 0
3625: || lastRePlotCommands.size() > 0) {
3626: s = "replot " + "\'" + fileName + "\' t \"line "
3627: + lineNum + "\"";
3628: } else {
3629: s = "splot " + "\'" + fileName + "\' t \"line "
3630: + lineNum + "\"";
3631: }
3632: gplot(s);
3633: lastRePlotCommands.add(s);
3634: /* String unsetView = "unset view";
3635: gplot(unsetView);
3636: lastRePlotCommands.add(unsetView);
3637: String setContour = "set contour";
3638: gplot(setContour);
3639: lastRePlotCommands.add(setContour);
3640: String unsetSurface = "unset surface";
3641: gplot(unsetSurface);
3642: lastRePlotCommands.add(unsetSurface);
3643: String unsetStyle = "unset style data";
3644: gplot(unsetStyle);
3645: lastRePlotCommands.add(unsetStyle);
3646: String unsetHidden = "unset hidden3d";
3647: gplot(unsetHidden);
3648: lastRePlotCommands.add(unsetHidden);
3649: */} else {
3650: resetAllLabels();
3651: lastRePlotCommands.clear();
3652: lastPlotCommands.clear();
3653: String setHidden = "set hidden3d";
3654: gplot(setHidden);
3655: lastPlotCommands.add(setHidden);
3656: String setStyle = "set style data lines";
3657: gplot(setStyle);
3658: lastPlotCommands.add(setStyle);
3659: String setSurface = "set surface";
3660: gplot(setSurface);
3661: lastPlotCommands.add(setSurface);
3662: String setContour = "set contour";
3663: gplot(setContour);
3664: lastRePlotCommands.add(setContour);
3665: String setLevel = "set cntrparam levels 10";
3666: gplot(setLevel);
3667: lastPlotCommands.add(setLevel);
3668: String setView = "set view 60, 30, 1, 1";
3669: gplot(setView);
3670: lastPlotCommands.add(setView);
3671: s = "splot " + "\'" + fileName + "\' t \"line " + lineNum
3672: + "\"";
3673: gplot(s);
3674: lastCommand = s;
3675: lastPlotCommands.add(s);
3676: /* String unsetView = "unset view";
3677: gplot(unsetView);
3678: lastPlotCommands.add(unsetView);
3679: String setContour = "set contour";
3680: gplot(setContour);
3681: lastPlotCommands.add(setContour);
3682: String unsetSurface = "unset surface";
3683: gplot(unsetSurface);
3684: lastPlotCommands.add(unsetSurface);
3685: String unsetStyle = "unset style data";
3686: gplot(unsetStyle);
3687: lastPlotCommands.add(unsetStyle);
3688: String unsetHidden = "unset hidden3d";
3689: gplot(unsetHidden);
3690: lastPlotCommands.add(unsetHidden);
3691: */}
3692:
3693: }
3694:
3695: public static void CONTOUR(IMatrix m) {
3696: int rows = m.getRows();
3697: int cols = m.getCols();
3698: double[] x = new double[rows];
3699: for (int i = 0; i < rows; i++) {
3700: x[i] = i + 1;
3701: }
3702: double[] y = new double[cols];
3703: for (int i = 0; i < cols; i++) {
3704: y[i] = i + 1;
3705: }
3706: contour(x, y, m.getRealMatrix());
3707: }
3708:
3709: public static void CONTOUR(IMatrix x, IMatrix y, IMatrix m) {
3710: int rows1 = x.getRows();
3711: int cols1 = x.getCols();
3712: int rows2 = y.getRows();
3713: int cols2 = y.getCols();
3714:
3715: double[] u = null;
3716: double[] v = null;
3717:
3718: if (rows1 == 1 || cols1 == 1) {
3719: if (rows1 == 1) {
3720: u = x.getRealRow(1);
3721: } else {
3722: u = x.getRealCol(1);
3723: }
3724: }
3725: if (rows2 == 1 || cols2 == 1) {
3726: if (rows2 == 1) {
3727: v = x.getRealRow(1);
3728: } else {
3729: v = x.getRealCol(1);
3730: }
3731: }
3732: contour(u, v, m.getRealMatrix());
3733: }
3734:
3735: private static void contour(double[] u, double[] v, double[][] w) {
3736: if (isOnHold) {
3737: lineNum++;
3738: } else {
3739: lineNum = 1;
3740: }
3741: String fileName = null;
3742: fileName = saveContour(u, v, w);
3743: String s = null;
3744: if (isOnHold) {
3745: String setStyle = "set style data lines";
3746: gplot(setStyle);
3747: lastRePlotCommands.add(setStyle);
3748: String setView = "set view 0, 0, 1, 1";
3749: gplot(setView);
3750: lastRePlotCommands.add(setView);
3751: String unsetSurface = "unset surface";
3752: gplot(unsetSurface);
3753: lastRePlotCommands.add(unsetSurface);
3754: String setContour = "set contour base";
3755: gplot(setContour);
3756: lastRePlotCommands.add(setContour);
3757: String setLevels = "set cntrparam levels 10";
3758: gplot(setLevels);
3759: lastRePlotCommands.add(setLevels);
3760: if (lastPlotCommands.size() > 0
3761: || lastRePlotCommands.size() > 0) {
3762: s = "replot " + "\'" + fileName + "\' t \"line "
3763: + lineNum + "\"";
3764: } else {
3765: s = "splot " + "\'" + fileName + "\' t \"line "
3766: + lineNum + "\"";
3767: }
3768: gplot(s);
3769: lastRePlotCommands.add(s);
3770: /* String unsetView = "unset view";
3771: gplot(unsetView);
3772: lastRePlotCommands.add(unsetView);
3773: String unsetContour = "unset contour";
3774: gplot(unsetContour);
3775: lastRePlotCommands.add(unsetContour);
3776: */} else {
3777: resetAllLabels();
3778: lastRePlotCommands.clear();
3779: lastPlotCommands.clear();
3780: String setStyle = "set style data lines";
3781: gplot(setStyle);
3782: lastPlotCommands.add(setStyle);
3783: String setView = "set view 0, 0, 1, 1";
3784: gplot(setView);
3785: lastPlotCommands.add(setView);
3786: String unsetSurface = "unset surface";
3787: gplot(unsetSurface);
3788: lastPlotCommands.add(unsetSurface);
3789: String setContour = "set contour base";
3790: gplot(setContour);
3791: lastPlotCommands.add(setContour);
3792: String setLevels = "set cntrparam levels 10";
3793: gplot(setLevels);
3794: lastPlotCommands.add(setLevels);
3795: s = "splot " + "\'" + fileName + "\' t \"line " + lineNum
3796: + "\"";
3797: gplot(s);
3798: lastCommand = s;
3799: lastPlotCommands.add(s);
3800: /* String unsetView = "unset view";
3801: gplot(unsetView);
3802: lastRePlotCommands.add(unsetView);
3803: String unsetContour = "unset contour";
3804: gplot(unsetContour);
3805: lastRePlotCommands.add(unsetContour);
3806: */}
3807:
3808: }
3809:
3810: public static void main(String[] args) throws Exception {
3811: /* double[][] v = new double[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
3812: save(v);
3813: */
3814: gplot("plot sin(x)");
3815: }
3816: }
|