示例#1
0
  public static void writeParam(String xNameFile) {
    //
    // write to file xpar all parameters.....
    //
    IOseq xFile;

    xFile = new IOseq(xNameFile);
    xFile.IOseqOpenW(false);

    try {

      Class c = Class.forName("jneat.Neat");
      Field[] fieldlist = c.getDeclaredFields();

      for (int i = 0; i < fieldlist.length; i++) {
        Field f1 = fieldlist[i];
        String x1 = f1.getName();

        if (x1.startsWith("p_")) {
          Field f2 = c.getField("d_" + Neat.normalizeName(x1));
          Object s1 = f1.get(c);
          Object s2 = f2.get(c);
          //	   String riga = s1 + "  " + s2;
          String riga = x1 + "  " + s1;
          xFile.IOseqWrite(riga);
        }
      }

    } catch (Throwable e) {
      System.err.println(e);
    }

    xFile.IOseqCloseW();
  }
示例#2
0
  public static boolean readParam(String xNomeFile) {

    boolean ret = true;
    String xline;
    IOseq xFile;
    StringTokenizer st;
    String s1;
    String s2;
    Object m1;

    xFile = new IOseq("parameters.ne");
    ret = xFile.IOseqOpenR();
    if (ret) {
      try {
        Class c = Class.forName("jneat.Neat");
        Field[] fieldlist = c.getDeclaredFields();

        int number_params = fieldlist.length / 2;

        for (int i = 0; i < number_params; i++) {
          Field f1 = fieldlist[i];
          String x1 = f1.getName();
          Object x2 = f1.getType();
          xline = xFile.IOseqRead();

          st = new StringTokenizer(xline);
          // skip comment

          s1 = st.nextToken();
          // real value
          s1 = st.nextToken();

          if (x1.startsWith("p_")) {
            if (x2.toString().equals("double")) {
              double n1 = Double.parseDouble(s1);
              f1.set(c, (new Double(n1)));
            }
            if (x2.toString().equals("int")) {
              int n1 = Integer.parseInt(s1);
              f1.set(c, (new Integer(n1)));
            }
          }
        }

      } catch (Throwable e) {
        System.err.println(e);
      }

      xFile.IOseqCloseR();

    } else System.err.print("\n : error during open " + xNomeFile);

    return ret;
  }