public Variable slice ( int dim , int value ) throws InvalidRangeException { if ( ( dim < 0 ) || ( dim >= shape . length ) ) throw new InvalidRangeException ( "Slice dim invalid= " + dim ) ; // ok to make slice of record dimension with length 0 boolean recordSliceOk = false ; if ( ( dim == 0 ) && ( value == 0 ) ) { Dimension d = getDimension ( 0 ) ; recordSliceOk = d . isUnlimited ( ) ; } // otherwise check slice in range if ( ! recordSliceOk ) { if ( ( value < 0 ) || ( value >= shape [ dim ] ) ) throw new InvalidRangeException ( "Slice value invalid= " + value + " for dimension " + dim ) ; } // create a copy of this variable with a proxy reader Variable sliceV = copy ( ) ; // subclasses must override Section slice = new Section ( getShapeAsSection ( ) ) ; slice . replaceRange ( dim , new Range ( value , value ) ) . makeImmutable ( ) ; sliceV . setProxyReader ( new SliceReader ( this , dim , slice ) ) ; sliceV . createNewCache ( ) ; // dont share the cache sliceV . setCaching ( false ) ; // dont cache // remove that dimension - reduce rank sliceV . dimensions . remove ( dim ) ; sliceV . resetShape ( ) ; return sliceV ; }
Create a new Variable that is a logical slice of this Variable by fixing the specified dimension at the specified index value . This reduces rank by 1 . No data is read until a read method is called on it .