public static HashMap<CellIndex,Double> readRMatrixFromFS(String filePath){
  HashMap<CellIndex,Double> expectedValues=new HashMap<CellIndex,Double>();
  BufferedReader reader=null;
  try {
    reader=new BufferedReader(new FileReader(filePath));
    String line=reader.readLine();
    int matrixType=-1;
    if (line.endsWith(" general"))     matrixType=1;
    if (line.endsWith(" symmetric"))     matrixType=2;
    if (matrixType == -1)     throw new RuntimeException("unknown matrix type while reading R matrix: ." + line);
    line=reader.readLine();
    while ((line=reader.readLine()) != null) {
      StringTokenizer st=new StringTokenizer(line," ");
      int i=Integer.parseInt(st.nextToken());
      int j=Integer.parseInt(st.nextToken());
      if (st.hasMoreTokens()) {
        double v=Double.parseDouble(st.nextToken());
        if (v == 0.0)         continue;
        expectedValues.put(new CellIndex(i,j),v);
        if (matrixType == 2)         expectedValues.put(new CellIndex(j,i),v);
      }
 else       expectedValues.put(new CellIndex(i,j),1.0);
    }
  }
 catch (  IOException e) {
    assertTrue("could not read from file " + filePath,false);
  }
 finally {
    IOUtilFunctions.closeSilently(reader);
  }
  return expectedValues;
}

public static HashMap < CellIndex , Double > readRMatrixFromFS ( String filePath ) { HashMap < CellIndex , Double > expectedValues = new HashMap < CellIndex , Double > ( ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( filePath ) ) ; String line = reader . readLine ( ) ; int matrixType = - 1 ; if ( line . endsWith ( " general" ) ) matrixType = 1 ; if ( line . endsWith ( " symmetric" ) ) matrixType = 2 ; if ( matrixType == - 1 ) throw new RuntimeException ( "unknown matrix type while reading R matrix: ." + line ) ; line = reader . readLine ( ) ; while ( ( line = reader . readLine ( ) ) != null ) { StringTokenizer st = new StringTokenizer ( line , " " ) ; int i = Integer . parseInt ( st . nextToken ( ) ) ; int j = Integer . parseInt ( st . nextToken ( ) ) ; if ( st . hasMoreTokens ( ) ) { double v = Double . parseDouble ( st . nextToken ( ) ) ; if ( v == 0.0 ) continue ; expectedValues . put ( new CellIndex ( i , j ) , v ) ; if ( matrixType == 2 ) expectedValues . put ( new CellIndex ( j , i ) , v ) ; } else expectedValues . put ( new CellIndex ( i , j ) , 1.0 ) ; } } catch ( IOException e ) { assertTrue ( "could not read from file " + filePath , false ) ; } finally { IOUtilFunctions . closeSilently ( reader ) ; } return expectedValues ; }
reads values from a matrix file in os ' s fs in r format
