~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to examples/callsci/callsciJava (Windows)/JAVASCI/Matrix.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package javasci ;
 
2
 
 
3
 
 
4
/**
 
5
 * Cette classe permet de cr�er des matrices et de faire effectuer des 
 
6
 * calculs sur ces matrices par Scilab 
 
7
 */
 
8
 
 
9
public class  Matrix {
 
10
  /**
 
11
   * contient les �l�ments de la matrice stock�s colonne par 
 
12
   * colonne. 
 
13
   */
 
14
 
 
15
  protected double [] x ;
 
16
  protected String s[] ;
 
17
 
 
18
  private int m, n, t;
 
19
  private String name; 
 
20
 
 
21
  /**
 
22
   * renvoit le nombre de lignes de la matrice. 
 
23
   */
 
24
  public int getRow() { return m;}
 
25
  /**
 
26
   * renvoit le nombre de colonnes de la matrice. 
 
27
   */
 
28
  public int getCol() { return n;}
 
29
  /**
 
30
   * renvoit le nom Scilab de la matrice.
 
31
   */
 
32
  public String getName() {return name;}
 
33
 
 
34
  /**
 
35
   * renvoit un tableau unidimensionnel de <tt>double</tt> contenant
 
36
   * les �l�ments de la matrice stock�s colonne par colonne.
 
37
   */
 
38
  public double[] getData() { return x;}
 
39
  public String[] getSData() { return s;}
 
40
 
 
41
  /**
 
42
   * Construit une matrice <tt>mxn</tt> de nom <tt>name</tt> 
 
43
   * (ce sera le nom Scilab de la matrice) dont les �l�ments sont 
 
44
   * initialis�e avec la valeur z�ro. 
 
45
   */
 
46
  public Matrix(String name,int m,int n) 
 
47
  {
 
48
 
 
49
    x = new double[m*n];
 
50
    this.m = m ;
 
51
    this.n = n;
 
52
    this.name = name;
 
53
    this.t = 0 ;   // real matrix
 
54
  }
 
55
 
 
56
  public Matrix(String name,int m,int n, int typemat) 
 
57
  {
 
58
    if ( typemat == 0 )
 
59
    {
 
60
      /** Complex matrix */
 
61
      x = new double[m*n];
 
62
    }
 
63
    else if ( typemat == 1 )
 
64
    {
 
65
      /** Complex matrix */
 
66
      x = new double[2*m*n];
 
67
    }
 
68
    else if ( typemat == 2 )
 
69
    {
 
70
      /** String matrix */
 
71
      s = new String[m*n];
 
72
    }
 
73
    this.t = typemat;
 
74
    this.m = m ;
 
75
    this.n = n;
 
76
    this.name = name;
 
77
  }
 
78
 
 
79
 
 
80
  /**
 
81
   * Construit une matrice <tt>mxn</tt> de nom <tt>name</tt> 
 
82
   * (ce sera le nom Scilab de la matrice) dont les �l�ments sont 
 
83
   * initialis�e avec le vecteur de double <tt>x</tt>. <tt>x</tt>
 
84
   * contient les valeurs des �l�ments de la matrice stock�s 
 
85
   * colonne par colonne. l'�l�ment <tt>(i,j)</tt> est donc en 
 
86
   * <tt>x[i+ m*j]</tt> pour <tt>i</tt> dans <tt>[0,m]</tt> et <tt>j</tt>
 
87
   * dans <tt>[0,n]</tt>. 
 
88
   */
 
89
  public Matrix(String name,int m,int n,double []x ) 
 
90
  {
 
91
    if ( m*n != x.length && 2*m*n != x.length ) 
 
92
      throw new BadDataArgumentException("Bad Matrix call, size of third argument is wrong");
 
93
    this.x = x ;  this.m = m ;  this.n = n;
 
94
    this.name = name;
 
95
    if ( m*n == x.length )
 
96
    {
 
97
      this.t = 0 ;
 
98
    }
 
99
    else
 
100
    {
 
101
      this.t = 1 ;
 
102
    }  
 
103
  }
 
104
 
 
105
  public Matrix(String name,int m,int n, String[]s ) 
 
106
  {
 
107
    if ( m*n != s.length ) 
 
108
      throw new BadDataArgumentException("Bad Matrix call, size of third argument is wrong");
 
109
    this.m = m ;  this.n = n;
 
110
    this.name = name;
 
111
    this.t = 2 ;  // String matrix
 
112
    this.s = s ;
 
113
  }
 
114
 
 
115
  /**
 
116
   * Envoit la matrice r�f�renc�e par l'objet <tt>Matrix</tt> � scilab. 
 
117
   * Fait executer le calcul Scilab d�crit par la cha�ne 
 
118
   * <tt>job</tt> et renvoit dans l'objet <tt>Matrix</tt> 
 
119
   * l'�tat de la matrice apr�s le calul. C'est le champ 
 
120
   * <tt>name</tt> qui d�signe le nom Scilab de la Matrice. 
 
121
   *
 
122
   * @param job Cha�ne de carat�re (Attention le caract�re <tt>'</tt>
 
123
   * pour �tre utilis� dans la cha�ne <tt>job</tt> doit �tre 
 
124
   * dupliqu�. 
 
125
   */
 
126
 
 
127
  public void scilabGet()
 
128
  {
 
129
        // Appel de scilabGet native
 
130
        if ( t != 2 )
 
131
        {
 
132
           scilabGetN();
 
133
        }
 
134
        else
 
135
        {
 
136
           int ix, j;
 
137
           for(ix=0;ix<m;ix++)
 
138
           {
 
139
              for(j=0;j<n;j++)
 
140
              {
 
141
                 s[ix+j*m] = scilabGetSN(ix, j);
 
142
              }
 
143
           }
 
144
        }
 
145
  }
 
146
 
 
147
  public native void scilabJob(String job);
 
148
  /**
 
149
   * Envoit la matrice r�f�renc�e par l'objet <tt>Matrix</tt> � scilab. 
 
150
   */
 
151
  public native void scilabSend();
 
152
  /**
 
153
   * Recopie dans l'objet <tt>Matrix</tt> la valeur de l'objet Scilab 
 
154
   * de type Matrice correspondant.
 
155
   */
 
156
  public native void scilabGetN();
 
157
  public native String scilabGetSN(int ix, int j);
 
158
  /**
 
159
   * Fait executer le calcul Scilab d�crit par la cha�ne 
 
160
   * <tt>job</tt>. 
 
161
   */
 
162
  public static native void scilabExec(String job);
 
163
 
 
164
 
 
165
  public native void testFill();
 
166
 
 
167
  static 
 
168
  {
 
169
    System.loadLibrary("javasci");
 
170
  }
 
171
 
 
172
}
 
173