jpayne@68: package fileIO; jpayne@68: jpayne@68: jpayne@68: public class ArrayFile extends TextFile{ jpayne@68: jpayne@68: public static void main(String[] args){ jpayne@68: jpayne@68: try { jpayne@68: //Name of mat file jpayne@68: String name=args[0]; jpayne@68: jpayne@68: ArrayFile mat=new ArrayFile(name); jpayne@68: jpayne@68: String s=null; jpayne@68: jpayne@68: for(s=mat.readLine(); s!=null; s=mat.readLine()){ jpayne@68: System.out.println(s); jpayne@68: } jpayne@68: } catch (Exception e) { jpayne@68: throw new RuntimeException(e); jpayne@68: } jpayne@68: jpayne@68: } jpayne@68: jpayne@68: jpayne@68: public ArrayFile(String name){super(name, false);} jpayne@68: jpayne@68: @Override jpayne@68: public String nextLine(){ jpayne@68: String line=readLine(); jpayne@68: char c=line.charAt(0); jpayne@68: jpayne@68: while(line!=null && c!='{' && c!='/'){ jpayne@68: line=readLine(); jpayne@68: c=line.charAt(0); jpayne@68: } jpayne@68: return line; jpayne@68: } jpayne@68: jpayne@68: public float[] nextArray(){ jpayne@68: String line; jpayne@68: String[] split; jpayne@68: jpayne@68: line=nextLine(); jpayne@68: if(line==null || line.startsWith("//end")){return null;} jpayne@68: jpayne@68: assert(line.startsWith("//name: ")) : line; jpayne@68: String name=line.replace("//name: ","").trim(); jpayne@68: jpayne@68: line=nextLine(); jpayne@68: assert(line.startsWith("//size: ")) : line; jpayne@68: line=line.replace("//size: ",""); jpayne@68: int length=Integer.parseInt(line); jpayne@68: jpayne@68: jpayne@68: float[] grid=new float[length]; jpayne@68: jpayne@68: line=nextLine(); jpayne@68: assert(line.startsWith("{")); jpayne@68: if(line.endsWith(",")){line=line.substring(0, line.length()-1);} jpayne@68: assert(line.endsWith("}")); jpayne@68: line=line.replace("{", "").replace("}", "").replace(" ", ""); jpayne@68: split=line.split(","); jpayne@68: assert(split.length==length); jpayne@68: for(int i=0; i