MxFormatWrite.java
01 /*
02  * $Id: MxFormatWrite.java,v 1.5 2008/02/02 05:53:02 koga Exp $
03  *
04  * Copyright (C) 2004 Koga Laboratory. All rights reserved.
05  *
06  */
07 package matxbook.chap14;
08 
09 import java.io.FileOutputStream;
10 import java.io.IOException;
11 import java.io.OutputStream;
12 
13 import org.mklab.nfc.matrix.DoubleMatrix;
14 import org.mklab.nfc.matx.MatxInteger;
15 import org.mklab.nfc.matx.MatxList;
16 import org.mklab.nfc.matx.MatxString;
17 import org.mklab.nfc.scalar.DoubleComplexNumber;
18 
19 
20 /**
21  * MaTXのMX形式としてデータを書き込むサンプルです。
22  * @author koga
23  * @version $Revision: 1.5 $, 2004/04/26
24  */
25 public class MxFormatWrite {
26 
27   /**
28    * メインメソッド
29    * 
30    * @param args コマンドライン引数
31    * @throws IOException ファイルに出力できない場合
32    */
33   @SuppressWarnings("nls")
34   public static void main(String[] args) throws IOException {
35     int a = 1;
36     String b = "hello";
37     DoubleMatrix c = new DoubleMatrix(new double[][] { {1, 2}, {3, 4}});
38     MatxList d = new MatxList(new Object[] {Integer.valueOf(1), new Double(1.2), new DoubleComplexNumber(3, 4)});
39 
40     OutputStream output = new FileOutputStream("data.mx");
41     MatxInteger.writeMxFormat(a, output, "a");
42     MatxString.writeMxFormat(b, output, "b");
43     c.writeMxFormat(output, "c");
44     d.writeMxFormat(output, "d");
45     output.close();
46   }
47 }