/* SCCS - @(#)NslOutFile.java 1.6 - 09/01/99 - 00:15:46 */ /* *Copyright(c) 1997 USC Brain Project. email nsl@java.usc.edu */ package nslj.src.display; import java.lang.*; import java.awt.*; import java.util.*; import java.io.*; import nslj.src.lang.*; import nslj.src.system.*; /** * The class to implement function of saving file * in various file formats * */ public final class NslOutFile { public static boolean readFromFile(String name, double [][][]values, int start, int time_offset){ // need to handle file exception here try { int type, mrows, ncols, imagf, namelen, total_time; //System.out.println("Reading from file " + name +" [ "+time_offset+" ] "); FileInputStream fin = new FileInputStream(name); DataInputStream din = new DataInputStream(fin); // Check machine type first Properties sysProperty = System.getProperties(); String osName = sysProperty.getProperty("os.name"); // System.out.println(osName+"SS"); // Big Endian, double precision, numeric data type = 1000; // Using the first variable name as output matrix name namelen = name.length(); type = din.readInt(); mrows = din.readInt(); ncols = din.readInt(); imagf = din.readInt(); // namelen = din.readInt(); // for (int k=0;k=0) && (end_time >=0) && (time_offset >=0)) { int type, mrows, ncols, imagf, namelen, total_time, i; // double [][][]values; String variable_name = variable.info.nslGetName(); Integer intval = new Integer( time_offset*(1+ (start_time/time_offset)) ); String name = variable_name + intval.toString(); // values = new double[variable.get_x()][variable.get_y()][time_offset]; for (i = time_offset*(start_time/time_offset); i< time_offset*(end_time/time_offset); i += time_offset) { //System.out.println("\n\n\n\n\nHEY!!!!!"+ i + "[ "+ start_time + " " + end_time +"]\n"); //readFromFile(name, values, i, time_offset*((start_time+time_offset)/time_offset)); readFromFile(name, values, i, time_offset); } return true; } return false; } public static boolean outVariable(NslVariable variable, int start_time, int end_time, int offset) { int type, mrows, ncols, imagf, namelen, total_time; String variable_name = variable.info.nslGetName(); Integer intval = new Integer( offset ); String name = variable_name + intval.toString(); // need to handle file exception here try { //FileOutputStream fout = new FileOutputStream("Test.mat"); //System.out.println("Printing at file " + name); FileOutputStream fout = new FileOutputStream(name); DataOutputStream dout = new DataOutputStream(fout); // Check machine type first Properties sysProperty = System.getProperties(); String osName = sysProperty.getProperty("os.name"); // System.out.println(osName+"SS"); // Big Endian, double precision, numeric data type = 1000; // Get rows and columns mrows = variable.info.getDimension(0); ncols = variable.info.getDimension(1); // Only real data imagf = 0; // Using the first variable name as output matrix name namelen = name.length(); dout.writeInt(type); dout.writeInt(mrows); dout.writeInt(ncols); dout.writeInt(imagf); // dout.writeInt(namelen); // dout.writeChars(name); for (total_time = start_time; total_time <= end_time ; total_time++) { //System.out.print("Time printed "+ total_time); // System.out.println(" Time [last_pos "+ variable.get_last_data_position() + " total time " + variable.get_absolute_last_data_position() +" "+ mrows +" "+ ncols+") "+ (time+time_offset)+ " " +total_time); for(int i=0; i