private Dimension makeZCoordAxis ( NetcdfDataset ds , List < String > values , String units ) throws IOException { int len = values . size ( ) ; String name = makeZCoordName ( units ) ; if ( len > 1 ) name = name + Integer . toString ( len ) ; else name = name + values . get ( 0 ) ; StringUtil2 . replace ( name , ' ' , "-" ) ; Dimension dim ; if ( null != ( dim = ds . getRootGroup ( ) . findDimension ( name ) ) ) { if ( dim . getLength ( ) == len ) { // check against actual values Variable coord = ds . getRootGroup ( ) . findVariable ( name ) ; Array coordData = coord . read ( ) ; Array newData = Array . makeArray ( coord . getDataType ( ) , values ) ; if ( MAMath . nearlyEquals ( coordData , newData ) ) { if ( debugBreakup ) parseInfo . format ( " use existing coord %s%n" , dim ) ; return dim ; } } } String orgName = name ; int count = 1 ; while ( ds . getRootGroup ( ) . findDimension ( name ) != null ) { name = orgName + "-" + count ; count ++ ; } // create new one dim = new Dimension ( name , len ) ; ds . addDimension ( null , dim ) ; if ( debugBreakup ) parseInfo . format ( " make Dimension = %s length = %d%n" , name , len ) ; // if (len < 2) return dim; // skip 1D if ( debugBreakup ) { parseInfo . format ( " make ZCoordAxis = = %s length = %d%n" , name , len ) ; } CoordinateAxis v = new CoordinateAxis1D ( ds , null , name , DataType . DOUBLE , name , makeUnitsName ( units ) , makeLongName ( name ) ) ; String positive = getZisPositive ( ds , v ) ; if ( null != positive ) v . addAttribute ( new Attribute ( _Coordinate . ZisPositive , positive ) ) ; v . setValues ( values ) ; ds . addCoordinateAxis ( v ) ; parseInfo . format ( "Created Z Coordinate Axis = " ) ; v . getNameAndDimensions ( parseInfo , true , false ) ; parseInfo . format ( "%n" ) ; return dim ; }
make a new variable out of the list in values