public void setGaussianLats ( int nparallels , float la1 , float la2 ) { log . debug ( "la1 {}, la2 {}" , la1 , la2 ) ; if ( this . gaussLats != null ) throw new RuntimeException ( "Cant modify GdsHorizCoordSys" ) ; int nlats = ( 2 * nparallels ) ; GaussianLatitudes gaussLats = GaussianLatitudes . factory ( nlats ) ; int bestStartIndex = 0 , bestEndIndex = 0 ; double bestStartDiff = Double . MAX_VALUE ; double bestEndDiff = Double . MAX_VALUE ; for ( int i = 0 ; i < nlats ; i ++ ) { double diff = Math . abs ( gaussLats . latd [ i ] - la1 ) ; if ( diff < bestStartDiff ) { bestStartDiff = diff ; bestStartIndex = i ; } diff = Math . abs ( gaussLats . latd [ i ] - la2 ) ; if ( diff < bestEndDiff ) { bestEndDiff = diff ; bestEndIndex = i ; } } log . debug ( "first pass: bestStartIndex {}, bestEndIndex {}" , bestStartIndex , bestEndIndex ) ; if ( Math . abs ( bestEndIndex - bestStartIndex ) + 1 != nyRaw ) { log . warn ( "GRIB gaussian lats: NP != NY, use NY" ) ; // see email from Toussaint@dkrz.de datafil: nlats = nyRaw ; gaussLats = GaussianLatitudes . factory ( nlats ) ; bestStartIndex = 0 ; bestEndIndex = nyRaw - 1 ; } boolean goesUp = bestEndIndex > bestStartIndex ; log . debug ( "bestStartIndex {}, bestEndIndex {}, goesUp {}" , bestStartIndex , bestEndIndex , goesUp ) ; // create the data int useIndex = bestStartIndex ; float [ ] data = new float [ nyRaw ] ; float [ ] gaussw = new float [ nyRaw ] ; for ( int i = 0 ; i < nyRaw ; i ++ ) { data [ i ] = ( float ) gaussLats . latd [ useIndex ] ; gaussw [ i ] = ( float ) gaussLats . gaussw [ useIndex ] ; log . trace ( "i {}, useIndex {}, data {}, gaussw {}" , i , useIndex , data [ i ] , gaussw [ i ] ) ; if ( goesUp ) { useIndex ++ ; } else { useIndex -- ; } } this . gaussLats = Array . factory ( DataType . FLOAT , new int [ ] { nyRaw } , data ) ; this . gaussw = Array . factory ( DataType . FLOAT , new int [ ] { nyRaw } , gaussw ) ; }
some weird adjustment for la1 and la2 .