private void setSharedDimensions ( Variable v , List < Element > values , List < Dimension > unknownDims , String location ) { if ( values . size ( ) == 0 ) { return ; } // remove the "scalar" dumbension Iterator < Element > iter = values . iterator ( ) ; while ( iter . hasNext ( ) ) { Element value = iter . next ( ) ; String dimName = value . getText ( ) . trim ( ) ; if ( dimName . equalsIgnoreCase ( "scalar" ) ) { iter . remove ( ) ; } } // gotta have same number of dimensions List < Dimension > oldDims = v . getDimensions ( ) ; if ( oldDims . size ( ) != values . size ( ) ) { log . error ( "Different number of dimensions for {} {}" , v , location ) ; return ; } List < Dimension > newDims = new ArrayList <> ( ) ; Group group = v . getParentGroup ( ) ; for ( int i = 0 ; i < values . size ( ) ; i ++ ) { Element value = values . get ( i ) ; String dimName = value . getText ( ) . trim ( ) ; dimName = NetcdfFile . makeValidCdmObjectName ( dimName ) ; Dimension dim = group . findDimension ( dimName ) ; Dimension oldDim = oldDims . get ( i ) ; if ( dim == null ) { dim = checkUnknownDims ( dimName , unknownDims , oldDim , location ) ; } if ( dim == null ) { log . error ( "Unknown Dimension= {} for variable = {} {} " , dimName , v . getFullName ( ) , location ) ; return ; } if ( dim . getLength ( ) != oldDim . getLength ( ) ) { log . error ( "Shared dimension ({}) has different length than data dimension ({}) shared={} org={} for {} {}" , dim . getShortName ( ) , oldDim . getShortName ( ) , dim . getLength ( ) , oldDim . getLength ( ) , v , location ) ; return ; } newDims . add ( dim ) ; } v . setDimensions ( newDims ) ; if ( showWork ) { log . debug ( " set shared dimensions for {}" , v . getNameAndDimensions ( ) ) ; } }
convert to shared dimensions