public float [ ] readGrid ( McIDASGridRecord gr ) throws IOException { float [ ] data ; //try { int te = ( gr . getOffsetToHeader ( ) + 64 ) * 4 ; int rows = gr . getRows ( ) ; int cols = gr . getColumns ( ) ; rf . seek ( te ) ; float scale = ( float ) gr . getParamScale ( ) ; data = new float [ rows * cols ] ; rf . order ( needToSwap ? RandomAccessFile . LITTLE_ENDIAN : RandomAccessFile . BIG_ENDIAN ) ; // int n = 0; // store such that 0,0 is in lower left corner... for ( int nc = 0 ; nc < cols ; nc ++ ) { for ( int nr = 0 ; nr < rows ; nr ++ ) { int temp = rf . readInt ( ) ; // check for missing value data [ ( rows - nr - 1 ) * cols + nc ] = ( temp == McIDASUtil . MCMISSING ) ? Float . NaN : ( ( float ) temp ) / scale ; } } rf . order ( RandomAccessFile . BIG_ENDIAN ) ; //} catch (Exception esc) { // System.out.println(esc); //} return data ; }
Read the grid