private CoordinateAxis makeTimeCoordAxisFromReference ( NetcdfDataset ds , Variable timeVar , Array vals ) { Variable refVar = ds . findVariable ( "reftime" ) ; if ( refVar == null ) return null ; double refValue ; try { Array refArray = refVar . read ( ) ; refValue = refArray . getDouble ( refArray . getIndex ( ) ) ; // get the first value } catch ( IOException ioe ) { return null ; } if ( refValue == N3iosp . NC_FILL_DOUBLE ) return null ; // construct the values array - make it a double to be safe Array dvals = Array . factory ( DataType . DOUBLE , vals . getShape ( ) ) ; IndexIterator diter = dvals . getIndexIterator ( ) ; IndexIterator iiter = vals . getIndexIterator ( ) ; while ( iiter . hasNext ( ) ) diter . setDoubleNext ( iiter . getDoubleNext ( ) + refValue ) ; // add reftime to each of the values String units = ds . findAttValueIgnoreCase ( refVar , CDM . UNITS , "seconds since 1970-1-1 00:00:00" ) ; units = normalize ( units ) ; String desc = "synthesized time coordinate from reftime, valtimeMINUSreftime" ; CoordinateAxis1D timeCoord = new CoordinateAxis1D ( ds , null , "timeCoord" , DataType . DOUBLE , "record" , units , desc ) ; timeCoord . setCachedData ( dvals , true ) ; parseInfo . format ( "Created Time Coordinate Axis From Reference = " ) ; timeCoord . getNameAndDimensions ( parseInfo , true , false ) ; parseInfo . format ( "%n" ) ; return timeCoord ; }
construct time coordinate from reftime variable