Last change
on this file since 8189 was 8189, checked in by kjdon, 20 years ago |
first version of Imperial College's Visualiser code
|
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.9 KB
|
Line | |
---|
1 | package vishnu.testvis.dendro;
|
---|
2 |
|
---|
3 | import java.io.*;
|
---|
4 | import java.util.*;
|
---|
5 |
|
---|
6 | public class TheVectors
|
---|
7 | {
|
---|
8 | public Vector theData;
|
---|
9 | public int size;
|
---|
10 | public Vector coding;
|
---|
11 | public int zeros;
|
---|
12 |
|
---|
13 |
|
---|
14 | TheVectors(String file, int VECTOR_SIZE)
|
---|
15 | {
|
---|
16 | theData= new Vector(VECTOR_SIZE);
|
---|
17 | coding= new Vector(VECTOR_SIZE);
|
---|
18 | int index,code =0, zerolist=0;
|
---|
19 | double ssum,value;
|
---|
20 | try
|
---|
21 | {
|
---|
22 | FileReader inFile = new FileReader(file);
|
---|
23 | BufferedReader inLines = new BufferedReader(inFile);
|
---|
24 | size=0;
|
---|
25 | String line = null, tokenString;
|
---|
26 | do
|
---|
27 | {
|
---|
28 |
|
---|
29 | line = inLines.readLine();
|
---|
30 | if (line!= null)
|
---|
31 | {
|
---|
32 |
|
---|
33 | double[] row= new double[VECTOR_SIZE];
|
---|
34 | StringTokenizer tokens = new StringTokenizer(line," ");
|
---|
35 | ssum=0.0;
|
---|
36 | for (index=0; index<VECTOR_SIZE; index++)
|
---|
37 | {
|
---|
38 | if(tokens.hasMoreTokens())
|
---|
39 | {
|
---|
40 | tokenString = tokens.nextToken();
|
---|
41 | value = Double.parseDouble(tokenString);
|
---|
42 | row[index]= value;
|
---|
43 | ssum+= value*value;
|
---|
44 | }
|
---|
45 | else
|
---|
46 | {
|
---|
47 | row[index]=0.0;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | if(index==0) continue;
|
---|
51 | ssum=Math.sqrt(ssum);
|
---|
52 | if(ssum!=0.0)
|
---|
53 | {
|
---|
54 | for(int i=0;i<index;i++)
|
---|
55 | row[i]/=ssum;
|
---|
56 | theData.addElement(row);
|
---|
57 | coding.addElement(new TheInt(code));
|
---|
58 | size++;
|
---|
59 | }
|
---|
60 | else
|
---|
61 | {
|
---|
62 | if(zerolist==0)
|
---|
63 | {
|
---|
64 | //System.out.print("0 ");
|
---|
65 | zerolist=1;
|
---|
66 | }
|
---|
67 | System.out.print(code + " ");
|
---|
68 | }
|
---|
69 | }
|
---|
70 | code++;
|
---|
71 | }while(line != null);
|
---|
72 | }
|
---|
73 | catch(IOException e)
|
---|
74 | {
|
---|
75 | System.err.println("IO Exception in read_vectors");
|
---|
76 | e.printStackTrace();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.