/* * GridDataReaderAndWriter.java * * Created on August 1, 2002, 10:40 PM */ package uk.ac.leeds.ccg.projects.MedAction.FuzzyInference; /** * * @author ma0101 */ import uk.ac.leeds.ccg.andyt.grids.*; import uk.ac.leeds.ccg.geotools.*; import java.io.*; import uk.ac.leeds.ccg.raster.*; import com.sun.java.util.collections.*; import uk.ac.leeds.ccg.geotools.classification.*; import uk.ac.leeds.ccg.widgets.*; import java.awt.*; public class GridDataReaderAndWriter { private String[] allFileName = null; private String[] inputFileName = null; private String outFileName = null; private AbstractGrid2DSquareCellDouble[] allReadGrid = null; static public final int WRITEOUTFILE = 1; static public final int READOUTFILE = 0; private double[] outValue = null; private AbstractGrid2DSquareCellDouble[] inputGrid = null; /** Creates a new instance of GridDataReaderAndWriter */ public GridDataReaderAndWriter( String[] allFileName,int outType ) { this.setAllFileName(allFileName,outType); } /** * * @param inputFileName * @param outFileName * @param outType */ public GridDataReaderAndWriter(String[] inputFileName,String outFileName,int outType) { this.setInputFileName(inputFileName); this.setOutFileName(outFileName); iniGrid2DSquareCellDoubleArray(outType); } public GridDataReaderAndWriter() { } /** * * @param id * @return */ public double[] readAllGridOrAllInputGrid(int id){ if(this.allReadGrid==null&&this.inputGrid==null) return null; if(this.allReadGrid!=null) { return readGrids(this.allReadGrid,id); } else if(this.inputGrid!=null) { return readGrids(this.inputGrid,id); } else return null; } private double[] readGrids(AbstractGrid2DSquareCellDouble[] grids,int id){ double[] temp=new double[grids.length]; for(int i=0;i1.0) throw new Exception("problem with reranging" + i); } GridDataReaderAndWriter.OutputToGridFile(out,ingrid,cols,rows); } catch (Exception e ) { System.out.println(e); e.printStackTrace(); // ingrid = ff.createGrid2DSquareCellDouble( new File("d:/temp/arc/minor.asc"), true ); // ff.setFile(new File(in.getPath()+"temp")); // outgrid.toAsciiFile(new File("d:/temp/arc/minorden.asc")); } } private double getMin(double[] value){ int length=value.length; double min=1.0; for(int i=0;imax)){max=value[i];} } return max; } private static synchronized void writeTrainingData(double[][] x, double[] y, File file) { try { PrintWriter pw = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) ); // Write header info int inputFileNumber = x[0].length; int inputNumber = x.length; pw.println( "inputFileNumber " + inputFileNumber ); pw.println( "inputNumber " + inputNumber ); // Write x[][] values for ( int i = 0; i < inputNumber; i ++ ) { for ( int j = 0 ; j < inputFileNumber; j ++ ) { pw.print( x[i][j] + " " ); } pw.println( "" ); } // write y[] value for(int i=0;imaxE) {maxE=eachCellError[i];} } // get meanError for(int i=0;i