00001
00002
00003
00004
00005
00006 package gui.jmatlink;
00007
00008 import java.io.UnsupportedEncodingException;
00009
00010 import commandline.debuggingCode.Debug;
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 public class JMatLink {
00021
00022
00023 private CoreJMatLink coreJMatLink;
00024
00025
00026 private boolean debugB = false;
00027
00028
00039 public JMatLink() {
00040 if (debugB) Debug.print("JMatLink constructor");
00041
00042
00043 coreJMatLink = new CoreJMatLink();
00044 }
00045
00046
00051 public void kill() {
00052 coreJMatLink.kill();
00053 }
00054
00055
00067 public synchronized void engOpen()
00068 {
00069 engOpen( "" );
00070 }
00071
00072
00085 public void engOpen(String startCmdS)
00086 {
00087 coreJMatLink.engOpen(startCmdS);
00088 }
00089
00090
00107 public long engOpenSingleUse()
00108 {
00109 return engOpenSingleUse("");
00110 }
00111
00112
00128 public long engOpenSingleUse(String startCmdS)
00129 {
00130 return coreJMatLink.engOpenSingleUse(startCmdS);
00131 }
00132
00133
00144 public void engClose()
00145 {
00146 coreJMatLink.engClose( );
00147 }
00148
00149
00164 public void engClose( long epI)
00165 {
00166 coreJMatLink.engClose(epI);
00167 }
00168
00169
00183 public void engCloseAll()
00184 {
00185 coreJMatLink.engCloseAll();
00186 }
00187
00188
00194 public void engSetVisible(long epI, boolean visB)
00195 {
00196 coreJMatLink.engSetVisible(epI, visB);
00197 }
00198
00199
00205 public boolean engGetVisible(long epI)
00206 {
00207 return coreJMatLink.engGetVisible(epI);
00208 }
00209
00210
00221 public void engEvalString(String evalS)
00222 {
00223 coreJMatLink.engEvalString( evalS );
00224 }
00225
00226
00238 public void engEvalString(long epI, String evalS)
00239 {
00240 coreJMatLink.engEvalString(epI, evalS);
00241 }
00242
00243
00256 public double engGetScalar(String arrayS)
00257 {
00258 return coreJMatLink.engGetScalar(arrayS);
00259 }
00260
00261
00275 public double engGetScalar(long epI, String arrayS)
00276 {
00277
00278
00279
00280
00281 return coreJMatLink.engGetScalar(epI, arrayS);
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00307 public double[][] engGetArray(String arrayS)
00308 {
00309 return coreJMatLink.engGetArray( arrayS );
00310 }
00311
00312
00326 public double[][] engGetArray( int epI, String arrayS )
00327 {
00328 return coreJMatLink.engGetArray( epI, arrayS );
00329
00330 }
00331
00332
00346 public String[] engGetCharArray(String arrayS)
00347 {
00348
00349 engEvalString( "engGetCharArrayD=double(" + arrayS +")" );
00350
00351
00352 double[][] arrayD = engGetArray("engGetCharArrayD");
00353
00354
00355 engEvalString("clear engGetCharArrayD");
00356
00357
00358
00359 if (arrayD == null) return null;
00360
00361
00362 return double2String( arrayD );
00363 }
00364
00365
00377 public void engPutArray( String arrayS, int valueI )
00378 {
00379 engPutArray( arrayS, new Integer(valueI).doubleValue());
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00420 public void engPutArray( String arrayS, double valueD )
00421 {
00422 double vDD[][] = {{0.0}};
00423 vDD[0][0] = valueD;
00424 engPutArray( arrayS, vDD );
00425 }
00426
00427
00440 public void engPutArray( long epI, String arrayS, double valueD )
00441 {
00442
00443 double vDD[][] = {{0.0}};
00444 vDD[0][0] = valueD;
00445 engPutArray( epI, arrayS, vDD );
00446 }
00447
00448
00461 public void engPutArray(String arrayS, double[] valuesD)
00462 {
00463 double[][] vDD = new double[1][valuesD.length];
00464
00465 if (debugB) Debug.print("length = "+valuesD.length);
00466
00467 vDD[0] = valuesD;
00468
00469 engPutArray( arrayS, vDD );
00470 }
00471
00472
00486 public void engPutArray(long epI, String arrayS, double[] valuesD)
00487 {
00488 double[][] vDD = new double[1][valuesD.length];
00489
00490 if (debugB) Debug.print("length = "+valuesD.length);
00491
00492 vDD[0] = valuesD;
00493
00494 engPutArray( epI, arrayS, vDD );
00495 }
00496
00497
00510 public void engPutArray( String arrayS, double[][] valuesDD )
00511 {
00512 coreJMatLink.engPutArray( arrayS, valuesDD );
00513 }
00514
00515
00530 public void engPutArray(long epI, String arrayS, double[][] valuesDD)
00531 {
00532
00533
00534
00535 coreJMatLink.engPutArray( epI, arrayS, valuesDD );
00536 }
00537
00538
00552 public String engOutputBuffer( )
00553 {
00554 return coreJMatLink.engOutputBuffer();
00555 }
00556
00572 public String engOutputBuffer(long epI)
00573 {
00574 return engOutputBuffer( epI, 10000 );
00575 }
00576
00577
00594 public String engOutputBuffer( long epI, int buflenI )
00595 {
00596 return coreJMatLink.engOutputBuffer( epI, buflenI );
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 public void setDebug( boolean debugB )
00613 {
00614 coreJMatLink.setDebug( debugB );
00615 }
00616
00617
00620
00621
00622
00623 private String[] double2String(double[][] d)
00624 {
00625
00626
00627 if (d == null)
00628 {
00629
00630 return null;
00631 }
00632
00633 String encodeS[]=new String[d.length];
00634
00635
00636 for (int n=0; n<d.length; n++){
00637 byte b[] = new byte[d[n].length];
00638
00639 for (int i=0; i<d[n].length ;i++) b[i]=(byte)d[n][i];
00640
00641
00642 try { encodeS[n] = new String(b, "UTF8");}
00643 catch (UnsupportedEncodingException e) {}
00644 }
00645 return encodeS;
00646 }
00647
00648 }