PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/FloCK/FCSLoader/FCSLoader.java

https://code.google.com/p/ifcsoft/
Java | 665 lines | 498 code | 97 blank | 70 comment | 119 complexity | 8267c09a5dc67d245fd5f4870cba2afc MD5 | raw file
Possible License(s): GPL-3.0
  1. /**
  2. * Copyright (C) 2011 Tjibbe Donker
  3. *
  4. * This file originally came from the FloCK program
  5. * (http://theory.bio.uu.nl/tjibbe/flock/) and is now
  6. * part of the IFCSoft project (http://ifcsoft.com)
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package FloCK.FCSLoader;
  22. //import FloCK.FCSLoader.stats.*;
  23. //import fcs.matrix.*;
  24. import java.io.FileReader;
  25. import java.io.FileWriter;
  26. import java.io.IOException;
  27. import java.io.FileInputStream ;
  28. import java.io.File ;
  29. import java.io.InputStream ;
  30. import java.io.DataInputStream ;
  31. import javax.swing.*;
  32. import java.awt.event.*;
  33. //import components.*;
  34. import Jama.Matrix;
  35. import java.io.BufferedInputStream;
  36. public class FCSLoader {
  37. int progress = 0; //Added by Kyle Thayer for a reporting progress
  38. boolean BigDEBUG = false;
  39. boolean memDEBUG = false;
  40. boolean DEBUG = false;
  41. public File FCSFile;
  42. int length=2;
  43. int StartText=0;
  44. int StopText=0;
  45. int StartData=0;
  46. int StopData=0;
  47. int NumTextElements=1;
  48. int NumBytes=1;
  49. int ByteOrd[];
  50. char DataType='*';
  51. String CreatorMachine;
  52. String DateCreated;
  53. String DateExport;
  54. String VersionS;
  55. float VersionF;
  56. String ChannelNames[];
  57. boolean LogNorm[];
  58. boolean NeedCompensation = false;
  59. Matrix CompensationMatrix;
  60. Matrix invCompensationMatrix;
  61. int NumMChan;
  62. int CompensationChannels[];
  63. int NormScale = 1024;
  64. static JFrame frame;
  65. volatile boolean busy;
  66. public FCSLoader(){
  67. length=2;
  68. StartText=0;
  69. StopText=0;
  70. StartData=0;
  71. StopData=0;
  72. NumTextElements=1;
  73. NumBytes=1;
  74. ByteOrd = new int[4];
  75. }
  76. public void resetDataSet(){
  77. length=2;
  78. StartText=0;
  79. StopText=0;
  80. StartData=0;
  81. StopData=0;
  82. NumTextElements=1;
  83. NumBytes=1;
  84. ByteOrd = new int[4];
  85. }
  86. public float arr2float (byte[] arr, int start) {
  87. //http://www.captain.at/howto-java-convert-binary-data.php
  88. int i = 0;
  89. int len = 4;
  90. byte[] tmp = new byte[len];
  91. for (i = start; i < (start + len); i++)
  92. tmp[ByteOrd[i-start]] = arr[i];
  93. int accum = 0;
  94. i = 0;
  95. for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) {
  96. accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy; i++;
  97. }
  98. return Float.intBitsToFloat(accum);
  99. }
  100. public int arr2int (byte[] arr, int len) {
  101. // int len=2;
  102. int myMin=4;
  103. int myMax=0;
  104. int myInt=0;
  105. byte[] tmp = new byte[len];
  106. for(int i=0;i<len;i++){
  107. if(myMin>ByteOrd[i]) myMin=ByteOrd[i];
  108. if(myMax<ByteOrd[i]) myMax=ByteOrd[i];
  109. }
  110. if(myMax-myMin==len-1) {
  111. for(int i=0;i<len;i++)
  112. myInt+=((arr[ByteOrd[i]-myMin]&0xff)<<(8*i));
  113. } else myInt=-1;
  114. return myInt;
  115. }
  116. class CompareScreen extends JPanel implements ActionListener{
  117. JButton okButton;
  118. public CompareScreen(){
  119. okButton = new JButton("OK");
  120. add(okButton);
  121. okButton.addActionListener(this);
  122. }
  123. public void actionPerformed(ActionEvent e) {
  124. if(e.getSource()==okButton){
  125. synchronized(this){
  126. notifyAll();
  127. }
  128. }
  129. }
  130. }
  131. void CreateCompareScreen() {
  132. //Create and set up the window.
  133. JFrame NumClusInf = new JFrame("Cluster Number Information");
  134. NumClusInf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  135. //Create and set up the content pane.
  136. CompareScreen ComparePane = new CompareScreen();
  137. ComparePane.setOpaque(true); //content panes must be opaque
  138. NumClusInf.setContentPane(ComparePane);
  139. //Display the window.
  140. NumClusInf.pack();
  141. NumClusInf.setVisible(true);
  142. }
  143. public Stats ReadFCS(String Filename)throws IOException{
  144. return ReadFCS(Filename,true);
  145. }
  146. // Convert the string containing the spillover matrix to a real matrix
  147. public void LoadSpillmatrix(String loadedString){
  148. int CurIndex=0;
  149. int TransToMatrix[] = new int[ChannelNames.length];
  150. for(int j=0;j<ChannelNames.length;j++) TransToMatrix[j]=-1;
  151. int NewIndex=loadedString.indexOf(",",CurIndex);
  152. String str = loadedString.substring(CurIndex,NewIndex);
  153. NumMChan=(int)Integer.valueOf(str.trim()).intValue() ;
  154. double vals[][] = new double[NumMChan][NumMChan];
  155. if(DEBUG) System.out.println(loadedString);
  156. if(DEBUG) System.out.println("Number of channels in matrix: "+NumMChan);
  157. for(int i=0;i<NumMChan;i++){
  158. CurIndex=NewIndex;
  159. NewIndex=loadedString.indexOf(",",CurIndex+1);
  160. str = loadedString.substring(CurIndex+1,NewIndex).trim();
  161. int NameLink=-1;
  162. for(int j=0;j<ChannelNames.length;j++){
  163. if(ChannelNames[j].indexOf(str,0)!=-1)NameLink=j;
  164. }
  165. TransToMatrix[NameLink]=i;
  166. if(DEBUG) System.out.println(str+" at position "+NameLink);
  167. }
  168. for(int i=0;i<NumMChan;i++){
  169. for(int j=0;j<NumMChan;j++){
  170. CurIndex=NewIndex;
  171. NewIndex=loadedString.indexOf(",",CurIndex+1);
  172. if(NewIndex<0) NewIndex=loadedString.length();
  173. if(DEBUG) System.out.print(CurIndex+" to "+NewIndex);
  174. str = loadedString.substring(CurIndex+1,NewIndex).trim();
  175. vals[j][i]=Double.valueOf(str.trim()).doubleValue();
  176. //if(i!=j) vals[i][j]=-vals[i][j];
  177. if(DEBUG) System.out.println(" gives "+vals[i][j]);
  178. }}
  179. CompensationChannels=TransToMatrix;
  180. CompensationMatrix=new Matrix(vals);
  181. //System.out.println(CompensationMatrix);
  182. if(DEBUG){
  183. System.out.println("..");
  184. System.out.println(" TODO: Make it dump matrix");
  185. //CompensationMatrix.print();
  186. System.out.println("..");
  187. }
  188. invCompensationMatrix= CompensationMatrix.inverse();
  189. if(DEBUG){
  190. System.out.println(" TODO: Make it dump matrix");
  191. System.out.println("..");
  192. }
  193. if(DEBUG) for(int j=0;j<ChannelNames.length;j++)System.out.println(j+": "+TransToMatrix[j]);
  194. }
  195. //////////////////////////////////////////////////////////////////////////////////
  196. // //
  197. // This is the main FCS file reader: //
  198. // //
  199. //////////////////////////////////////////////////////////////////////////////////
  200. public Stats ReadFCS(String Filename, boolean renorm) throws IOException {
  201. FileReader inputStream = null;
  202. FileWriter outputStream = null;
  203. FCSFile = new File(Filename);
  204. int baseLines[];
  205. boolean mBool=false;
  206. int Events,MyChannels;
  207. Stats DA=new Stats(0,0); ;
  208. resetDataSet();
  209. System.gc();
  210. Events=0;
  211. try {
  212. inputStream = new FileReader(Filename);
  213. File file = new File(Filename);
  214. InputStream is = new BufferedInputStream(new FileInputStream(file)); //Added buffering to make it load files much, much faster
  215. DataInputStream dis = new DataInputStream( is );
  216. float c =0;
  217. char sep;
  218. String str;
  219. //Read the "FCS"
  220. char incomingData[] = new char[58];
  221. inputStream.read(incomingData);
  222. str = new String(incomingData,0,3);
  223. str.toUpperCase();
  224. if(str.indexOf("FCS")==-1){
  225. if(DEBUG){
  226. System.out.println("!--Warning--!");
  227. System.out.println("First check failed, Probably not an FCS file");
  228. System.out.println("Fatal error, exiting");
  229. System.out.println("!-----------!");
  230. }
  231. mBool=false;
  232. } else {
  233. str = new String(incomingData,3,3);
  234. if(DEBUG) System.out.println(str);
  235. c=(float)Float.valueOf(str).floatValue();
  236. VersionF=c;
  237. VersionS=str;
  238. if(c!=2.0)
  239. if(DEBUG){
  240. System.out.println("!--Warning--!");
  241. System.out.println("FCS version"+(int)c+"not supported");
  242. System.out.println("This might cause problems");
  243. System.out.println("!-----------!");
  244. }
  245. //Read Start of text
  246. str = new String(incomingData,10,8);
  247. StartText=(int)Integer.valueOf(str.trim()).intValue();
  248. if(DEBUG) System.out.println(StartText);
  249. //Read End of text
  250. str = new String(incomingData,18,8);
  251. StopText=(int)Integer.valueOf(str.trim()).intValue() ;
  252. if(DEBUG) System.out.println(StopText);
  253. str = new String(incomingData,26,8);
  254. StartData=(int)Integer.valueOf(str.trim()).intValue() ;
  255. if(DEBUG) System.out.println(StartData);
  256. //Read End of text
  257. str = new String(incomingData,34,8);
  258. StopData=(int)Integer.valueOf(str.trim()).intValue() ;
  259. if(DEBUG) System.out.println(StopData);
  260. /////////////////////////////////////////////////
  261. // Start reading the text part of the FCS file //
  262. /////////////////////////////////////////////////
  263. //Read text from file
  264. char TextPart[] = new char[(StopText-StartText)];
  265. inputStream.skip(StartText-58);
  266. inputStream.read(TextPart);
  267. //Put it into String *Is this needed?*
  268. int l=TextPart.length;
  269. str = new String(TextPart,0,l);
  270. if(DEBUG) System.out.println(l);
  271. //Determine the separator and count the number of records
  272. sep=TextPart[0];
  273. if(DEBUG) System.out.println("Separator was defined as: "+sep);
  274. int NumBreak=0;
  275. for(int i=0; i<l; i++){
  276. if(TextPart[i]==sep) NumBreak++;
  277. }
  278. NumTextElements = (int)(NumBreak/2);
  279. if(DEBUG) System.out.println(NumTextElements);
  280. //Translating text part to array
  281. String TextArray[][] = new String[NumTextElements][2];
  282. int CurIndex = 0;
  283. int NewIndex;
  284. int SecondIndex;
  285. for(int i=0;i<NumTextElements;i++){
  286. NewIndex=str.indexOf(sep,CurIndex+1);
  287. SecondIndex=str.indexOf(sep,NewIndex+1);
  288. TextArray[i][0]=str.substring(CurIndex+1,NewIndex);
  289. if(SecondIndex!=-1){
  290. TextArray[i][1]=str.substring(NewIndex+1,SecondIndex);
  291. } else {
  292. TextArray[i][1]=str.substring(NewIndex+1);
  293. }
  294. CurIndex=SecondIndex;
  295. }
  296. //Reading the needed variables from array
  297. //First the variables independent of number of channels
  298. for(int b=0;b<4;b++)
  299. ByteOrd[b]=b;
  300. MyChannels=-1;
  301. DataType='I';
  302. String TMPstr;
  303. for(int i=0;i<NumTextElements;i++){
  304. if(StartData==0){
  305. if(TextArray[i][0].indexOf("BEGINDATA")!=-1){StartData=(int)Integer.valueOf(TextArray[i][1].trim()).intValue();}
  306. if(TextArray[i][0].indexOf("ENDDATA")!=-1){StopData=(int)Integer.valueOf(TextArray[i][1].trim()).intValue();}
  307. }
  308. if(TextArray[i][0].indexOf("$PAR")==0){ // ==0 was !=-1
  309. MyChannels=(int)Integer.valueOf(TextArray[i][1].trim()).intValue();
  310. if(DEBUG) System.out.println("Number of channels found: "+MyChannels);
  311. }
  312. if(TextArray[i][0].indexOf("DATATYPE")!=-1){DataType=TextArray[i][1].charAt(0);}
  313. if((TextArray[i][0].indexOf("P1B")!=-1)&&(TextArray[i][0].indexOf("P1BS")==-1)){
  314. NumBytes=(int)((int)Integer.valueOf(TextArray[i][1].trim()).intValue()/8);
  315. }
  316. if(TextArray[i][0].indexOf("CREATOR")!=-1) CreatorMachine=TextArray[i][1];
  317. if(TextArray[i][0].indexOf("$DATE")!=-1) DateCreated=TextArray[i][1];
  318. if(TextArray[i][0].indexOf("EXPORT TIME")!=-1) DateExport=TextArray[i][1];
  319. if(TextArray[i][0].indexOf("TOT")!=-1){Events=(int)Integer.valueOf(TextArray[i][1].trim()).intValue();}
  320. if(TextArray[i][0].indexOf("APPLY COMPENSATION")!=-1&&TextArray[i][1].toUpperCase().indexOf("TRUE")!=-1)
  321. {NeedCompensation=true;}
  322. if(TextArray[i][0].indexOf("BYTEORD")!=-1){
  323. if(TextArray[i][1].indexOf(",")!=-1){
  324. for(int b=0;b<4;b++)
  325. ByteOrd[b]=(int)Integer.valueOf(TextArray[i][1].substring((b*2),(b*2)+1)).intValue()-1;
  326. } else {
  327. for(int b=0;b<4;b++)
  328. ByteOrd[b]=b;
  329. }
  330. if(DEBUG) System.out.println("ByteOrd = "+ByteOrd[0]+ByteOrd[1]+ByteOrd[2]+ByteOrd[3]);
  331. }
  332. }
  333. //If the number of channels (given by $PAR) is not found, use this
  334. //emergency procedure to detect the number of channels.
  335. if(MyChannels==-1){
  336. MyChannels=1;
  337. boolean foundC=true;
  338. while(foundC==true){
  339. TMPstr = "$P"+Integer.toString(MyChannels)+"N";
  340. foundC=false;
  341. for(int i=0;i<NumTextElements;i++){
  342. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  343. foundC=true;
  344. MyChannels++;
  345. }
  346. }
  347. }
  348. MyChannels--;
  349. }
  350. //Try to free some memory because after a short while we're going to load the data
  351. //This Needs some tweaking
  352. Object[] options = { "Yes", "No" };
  353. System.gc();
  354. Runtime rt = Runtime.getRuntime();
  355. long avMem=(int)((rt.maxMemory()-rt.totalMemory())*0.75);
  356. long needMem=(Events*(1+(MyChannels*6)+(27*4)));//+(MyChannels*(63+(25*20)))+1024; //63+(25*20)
  357. if(memDEBUG){
  358. System.out.println("----------------Before Loading--------------------------");
  359. System.out.println("Total memory allocated to VM: " + (int)(rt.totalMemory()/1024));
  360. System.out.println("Max memory allocated to VM: " + (int)(rt.maxMemory()/1024));
  361. System.out.println("Memory currently available: " + (int)(rt.freeMemory()/1024));
  362. System.out.println("Memory currently available: " + (int)(avMem/1024));
  363. System.out.println("Collecting garbage");
  364. System.gc();
  365. System.out.println("Memory currently available: " + (int)(rt.freeMemory()/1024));
  366. System.out.println("Estimated memory needed: "+(int)(needMem/1024));
  367. System.out.println("--------------------------------------------------------");
  368. } else {System.gc();}
  369. needMem=0; //temporary solution
  370. if(avMem<needMem)
  371. {
  372. int myNumEvents=(int)((avMem-1024-(MyChannels*(63+(20*25))))/(1+(MyChannels*6)+(27*4)));
  373. JOptionPane.showMessageDialog(null, "File too large.\n Memory available: "+
  374. Long.toString(avMem)+
  375. " KB, Needed: "+
  376. Long.toString(needMem)+
  377. " KB\nSetting events to "+
  378. Integer.toString(myNumEvents),
  379. "Memory Test",
  380. JOptionPane.WARNING_MESSAGE
  381. );
  382. Events=myNumEvents;
  383. }
  384. // Events = 300;//TEMPORARY
  385. int skippoints=0;
  386. int zeropoints=0;
  387. //int NewCN=MyChannels;
  388. /////////////////Loading channel dependent variables///////////////
  389. // This next bit loads the:
  390. // - Names
  391. // - Scales
  392. // - decades
  393. // - offsets
  394. // - lognorms
  395. // - ranges
  396. ///////////////////////////////////////////////////////////////////
  397. System.out.println("Using "+Events+" events and "+MyChannels+" channels");
  398. DA = new Stats(MyChannels,Events);
  399. LogNorm = new boolean[MyChannels];
  400. DA.logScale = new boolean[MyChannels];
  401. DA.decades = new float[MyChannels];
  402. DA.offsets = new float[MyChannels];
  403. for(int j=1;j<MyChannels+1;j++) LogNorm[j-1]=false;
  404. baseLines = new int[MyChannels];
  405. String tChannelNames[] = new String[MyChannels];
  406. boolean tLogNorm[] = new boolean[MyChannels];
  407. boolean tlogScale[] = new boolean[MyChannels];
  408. float tdecades[] = new float[MyChannels];
  409. float toffsets[] = new float[MyChannels];
  410. int tranges[] = new int[MyChannels];
  411. int tbaseLines[] = new int[MyChannels];
  412. for(int j=1;j<MyChannels+1;j++) tLogNorm[j-1]=false;
  413. for(int i=0;i<NumTextElements;i++){
  414. if(TextArray[i][0].indexOf("$P")!=-1){
  415. for(int j=1;j<MyChannels+1;j++) {
  416. TMPstr = "$P"+Integer.toString(j)+"N";
  417. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  418. tChannelNames[j-1]=TextArray[i][1];
  419. }
  420. TMPstr = "$P"+Integer.toString(j)+"E";
  421. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  422. if(TextArray[i][1].indexOf(",")!=-1){
  423. tdecades[j-1]=(float)Float.valueOf(TextArray[i][1].substring(0,TextArray[i][1].indexOf(","))).floatValue();
  424. toffsets[j-1]=(float)Float.valueOf(TextArray[i][1].substring(TextArray[i][1].indexOf(",")+1)).floatValue();
  425. if(tdecades[j-1]>0) tlogScale[j-1]=true; else tlogScale[j-1]=false;
  426. } else {
  427. if(DEBUG) System.out.println("No seperation between decades and offset found");
  428. }
  429. if(DEBUG) System.out.println("$P"+j+"E found: "+tdecades[j-1]+toffsets[j-1]);
  430. }
  431. TMPstr = "$P"+Integer.toString(j)+"R";
  432. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  433. tranges[j-1]=(int)Integer.valueOf(TextArray[i][1]).intValue();
  434. }
  435. }
  436. }
  437. if(TextArray[i][0].indexOf("P")!=-1){
  438. for(int j=1;j<MyChannels+1;j++) {
  439. TMPstr = "P"+Integer.toString(j)+"DISPLAY";
  440. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  441. if(TextArray[i][1].indexOf("LOG")!=-1){
  442. if(DEBUG) System.out.println("Log transform");
  443. tLogNorm[j-1]=true;
  444. tlogScale[j-1]=true;
  445. }
  446. }
  447. TMPstr = "P"+Integer.toString(j)+"BS";
  448. if(TextArray[i][0].indexOf(TMPstr)!=-1)
  449. tbaseLines[j-1]=(int)Integer.valueOf(TextArray[i][1]).intValue();
  450. }
  451. }
  452. }
  453. for(int i=0;i<NumTextElements;i++){
  454. if(TextArray[i][0].indexOf("$P")!=-1){
  455. for(int j=1;j<MyChannels+1;j++) {
  456. TMPstr = "$P"+Integer.toString(j)+"S";
  457. if(TextArray[i][0].indexOf(TMPstr)!=-1){
  458. tChannelNames[j-1]=tChannelNames[j-1]+" ( "+TextArray[i][1]+" )";
  459. }
  460. }
  461. }
  462. }
  463. for(int j=0;j<MyChannels;j++)
  464. if(tLogNorm[j]&&tdecades[j]==0){
  465. tdecades[j]=(float)(Math.log(tranges[j])/Math.log(10));
  466. if(DEBUG) System.out.println("Channel: "+j+", decades: "+tdecades[j]);
  467. }
  468. // If the number of channels are equal between datasets, the order is assumed to be the same
  469. // If not, then use the matcher to order the channels to match the previous dataset.
  470. int[] ChannelOrder;
  471. ChannelOrder = new int[MyChannels];
  472. System.out.println("ChannelOrderLength = "+MyChannels);
  473. for(int i=0;i<MyChannels;i++)
  474. ChannelOrder[i]=i;
  475. ChannelOrder = new int[MyChannels];
  476. for(int i=0;i<MyChannels;i++)
  477. ChannelOrder[i]=i;
  478. LogNorm = tLogNorm;
  479. DA.logScale = tlogScale;
  480. DA.decades = tdecades;
  481. DA.offsets = toffsets;
  482. DA.ranges = tranges;
  483. baseLines = tbaseLines;
  484. ChannelNames = tChannelNames;
  485. //}
  486. //Now that the names are known, load the Spillover Matrix
  487. for(int i=0;i<NumTextElements;i++){
  488. if(TextArray[i][0].indexOf("SPILL")!=-1){LoadSpillmatrix(TextArray[i][1]);}
  489. }
  490. if(BigDEBUG)
  491. for(int i=0;i<TextArray.length;i++){
  492. System.out.println(TextArray[i][0]+": "+TextArray[i][1]);
  493. }
  494. if(DEBUG) {
  495. for(int i=0;i<ChannelOrder.length;i++) System.out.println("nr "+i+" is "+ChannelOrder[i]);
  496. System.out.println("DataType is "+DataType);
  497. System.out.println("Data Part from "+StartData+" to "+StopData+" (Total "+DA.NumDataPoints+" datapoints in "+DA.NumEvents+" events and "+DA.NumChannels+" channels)");
  498. }
  499. // Start loading the data
  500. is.skip(StartData);
  501. float f=0;
  502. int myI=0;
  503. byte[] ch = new byte[NumBytes];
  504. int CountE=0;
  505. int CountT=0;
  506. for(int j=0;j<DA.NumEvents;j++){
  507. progress++; //Added by Kyle Thayer for a reporting progress
  508. CountE++;
  509. for(int i=0;i<MyChannels;i++){
  510. DA.DataArray[i][j]=0;
  511. }
  512. for(int i=0;i<MyChannels;i++){
  513. is.read(ch);
  514. if(ChannelOrder[i]<MyChannels&&ChannelOrder[i]>-1){
  515. if(DataType=='F') myI=(int)arr2float(ch, 0);
  516. if(DataType=='I') myI=arr2int(ch,NumBytes);
  517. DA.DataArray[ChannelOrder[i]][j]=myI;
  518. }
  519. CountT++;
  520. }
  521. mBool=true;
  522. }
  523. if(DEBUG) System.out.println("Data loaded. Events: "+CountE+", Total: "+CountT);
  524. if(memDEBUG){
  525. rt = Runtime.getRuntime();
  526. System.out.println("----------------After Loading----------------------------");
  527. System.out.println("Total memory allocated to VM: " + (int)(rt.totalMemory()/(1024)));
  528. System.out.println("Max memory allocated to VM: " + (int)(rt.maxMemory()/(1024)));
  529. System.out.println("Memory currently available: " + (int)(rt.freeMemory()/(1024)));
  530. System.out.println("Collecting garbage");
  531. System.gc();
  532. System.out.println("Memory currently available: " + (int)(rt.freeMemory()/(1024)));
  533. System.out.println("Estimated memory needed: "+(int)(needMem/1024));
  534. System.out.println("--------------------------------------------------------");
  535. }
  536. DA.MinAndMax(false);
  537. if(DEBUG)
  538. for(int i=0;i<MyChannels;i++){
  539. System.out.println("Channel "+i+": "+DA.min[i]+" to "+DA.max[i]);
  540. }
  541. DA.ChannelNames=ChannelNames;
  542. DA.CreatorMachine=CreatorMachine;
  543. DA.DateCreated=DateCreated;
  544. DA.DateExport=DateExport;
  545. DA.VersionS=VersionS;
  546. DA.VersionF=VersionF;
  547. DA.DataType=DataType;
  548. DA.CompOverRating();
  549. DA.NegativesToZero();
  550. DA.MinAndMax(false);
  551. DA.loaded=true;
  552. DA.ClusterNumbers=new char[DA.NumEvents];
  553. }
  554. } finally {
  555. if (inputStream != null) {
  556. inputStream.close();
  557. }
  558. if (outputStream != null) {
  559. outputStream.close();
  560. }
  561. }
  562. if(!mBool) DA = new Stats(0,0);
  563. return DA;
  564. }
  565. public int getProgress(){ //Added by Kyle Thayer for a reporting progress
  566. return progress;
  567. }
  568. }