Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/ArrayFile.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package fileIO; | |
2 | |
3 | |
4 public class ArrayFile extends TextFile{ | |
5 | |
6 public static void main(String[] args){ | |
7 | |
8 try { | |
9 //Name of mat file | |
10 String name=args[0]; | |
11 | |
12 ArrayFile mat=new ArrayFile(name); | |
13 | |
14 String s=null; | |
15 | |
16 for(s=mat.readLine(); s!=null; s=mat.readLine()){ | |
17 System.out.println(s); | |
18 } | |
19 } catch (Exception e) { | |
20 throw new RuntimeException(e); | |
21 } | |
22 | |
23 } | |
24 | |
25 | |
26 public ArrayFile(String name){super(name, false);} | |
27 | |
28 @Override | |
29 public String nextLine(){ | |
30 String line=readLine(); | |
31 char c=line.charAt(0); | |
32 | |
33 while(line!=null && c!='{' && c!='/'){ | |
34 line=readLine(); | |
35 c=line.charAt(0); | |
36 } | |
37 return line; | |
38 } | |
39 | |
40 public float[] nextArray(){ | |
41 String line; | |
42 String[] split; | |
43 | |
44 line=nextLine(); | |
45 if(line==null || line.startsWith("//end")){return null;} | |
46 | |
47 assert(line.startsWith("//name: ")) : line; | |
48 String name=line.replace("//name: ","").trim(); | |
49 | |
50 line=nextLine(); | |
51 assert(line.startsWith("//size: ")) : line; | |
52 line=line.replace("//size: ",""); | |
53 int length=Integer.parseInt(line); | |
54 | |
55 | |
56 float[] grid=new float[length]; | |
57 | |
58 line=nextLine(); | |
59 assert(line.startsWith("{")); | |
60 if(line.endsWith(",")){line=line.substring(0, line.length()-1);} | |
61 assert(line.endsWith("}")); | |
62 line=line.replace("{", "").replace("}", "").replace(" ", ""); | |
63 split=line.split(","); | |
64 assert(split.length==length); | |
65 for(int i=0; i<split.length; i++){ | |
66 grid[i]=Float.parseFloat(split[i]); | |
67 } | |
68 | |
69 return grid; | |
70 } | |
71 | |
72 } |