signature:
public class Grib2DataReader { /** * Data template 7.3 – Grid point data – complex packing and spatial differencing
 * Note : For most templates , details of the packing process are described in Regulation 92.9.4.
 * Octet No . Contents
 * 6 – ww First value ( s ) of original ( undifferenced ) scaled data values , followed by the overall minimum
 * of the differences . The number of values stored is 1 greater than the order of differentiation ,
 * and the field width is described at octet 49 of data representation template 5.3 ( see Note 1)
 * [ ww + 1 ] – xx NG group reference values ( X1 in the decoding formula ) , each of which is encoded using the number
 * of bits specified in octet 20 of data representation template 5.0 . Bits set to zero shall be
 * appended where necessary to ensure this sequence of numbers ends on an octet boundary
 * [ xx + 1 ] – nn Same as for data representation template 7.2
 * Notes :
 * ( 1 ) Referring to the notation in Note 1 of data representation template 5.3 , at order 1 , the values stored in octets 6 – ww are
 * g1 and gmin . At order 2 , the values stored are h1 , h2 , and hmin .
 * ( 2 ) Extra descriptors related to spatial differencing are added before the splitting descriptors , to reflect the separation
 * between the two approaches . It enables to share software parts between cases with and without spatial differencing .
 * ( 3 ) The position of overall minimum after initial data values is a choice that enables less software management .
 * ( 4 ) Overall minimum will be negative in most cases . First bit should indicate the sign : 0 if positive , 1 if negative . */
private float [ ] getData3 ( RandomAccessFile raf , Grib2Drs . Type3 gdrs ) throws IOException { } }

implementation:
int mvm = gdrs . missingValueManagement ; float mv = getMissingValue ( gdrs ) ; float DD = ( float ) java . lang . Math . pow ( ( double ) 10 , ( double ) gdrs . decimalScaleFactor ) ; float R = gdrs . referenceValue ; float EE = ( float ) java . lang . Math . pow ( 2.0 , ( double ) gdrs . binaryScaleFactor ) ; float ref_val = R / DD ; int NG = gdrs . numberOfGroups ; if ( NG == 0 ) { return nGroups0 ( bitmapIndicator , ref_val , mv ) ; } BitReader reader = new BitReader ( raf , startPos + 5 ) ; int ival1 ; int ival2 = 0 ; int minsd ; // [6 - ww ] 1st values of undifferenced scaled values and minimums
int os = gdrs . orderSpatial ; int nbitsd = gdrs . descriptorSpatial ; int sign ; // ds is number of bytes , convert to bits - 1 for sign bit
nbitsd = nbitsd * 8 ; if ( nbitsd > 0 ) { // first order spatial differencing g1 and gMin
sign = ( int ) reader . bits2UInt ( 1 ) ; ival1 = ( int ) reader . bits2UInt ( nbitsd - 1 ) ; if ( sign == 1 ) { ival1 = - ival1 ; } if ( os == 2 ) { // second order spatial differencing h1 , h2 , hMin
sign = ( int ) reader . bits2UInt ( 1 ) ; ival2 = ( int ) reader . bits2UInt ( nbitsd - 1 ) ; if ( sign == 1 ) { ival2 = - ival2 ; } } sign = ( int ) reader . bits2UInt ( 1 ) ; minsd = ( int ) reader . bits2UInt ( nbitsd - 1 ) ; if ( sign == 1 ) { minsd = - minsd ; } } else { float [ ] data = new float [ totalNPoints ] ; for ( int i = 0 ; i < totalNPoints ; i ++ ) { data [ i ] = mv ; } return data ; } // [ ww + 1 ] - xx Get reference values for groups ( X1 ' s )
// X1 = = gref
int [ ] X1 = new int [ NG ] ; // initialized to zero
int nb = gdrs . numberOfBits ; if ( nb != 0 ) { reader . incrByte ( ) ; for ( int i = 0 ; i < NG ; i ++ ) { X1 [ i ] = ( int ) reader . bits2UInt ( nb ) ; } } // [ xx + 1 ] - yy Get number of bits used to encode each group
// NB = = gwidth
int [ ] NB = new int [ NG ] ; // initialized to zero
nb = gdrs . bitsGroupWidths ; if ( nb != 0 ) { reader . incrByte ( ) ; for ( int i = 0 ; i < NG ; i ++ ) { NB [ i ] = ( int ) reader . bits2UInt ( nb ) ; } } int referenceGroupWidths = gdrs . referenceGroupWidths ; for ( int i = 0 ; i < NG ; i ++ ) { NB [ i ] += referenceGroupWidths ; } // [ yy + 1 ] - zz Get the scaled group lengths using formula
// Ln = ref + Kn * len _ inc , where n = 1 - NG ,
// ref = referenceGroupLength , and len _ inc = lengthIncrement
int [ ] L = new int [ NG ] ; // initialized to zero
int referenceGroupLength = gdrs . referenceGroupLength ; nb = gdrs . bitsScaledGroupLength ; int len_inc = gdrs . lengthIncrement ; if ( nb != 0 ) { reader . incrByte ( ) ; for ( int i = 0 ; i < NG ; i ++ ) { L [ i ] = ( int ) reader . bits2UInt ( nb ) ; } } int totalL = 0 ; for ( int i = 0 ; i < NG ; i ++ ) { L [ i ] = L [ i ] * len_inc + referenceGroupLength ; totalL += L [ i ] ; } totalL -= L [ NG - 1 ] ; totalL += gdrs . lengthLastGroup ; // enter Length of Last Group
L [ NG - 1 ] = gdrs . lengthLastGroup ; // test
if ( mvm != 0 ) { if ( totalL != totalNPoints ) { logger . warn ( "NPoints != gds.nPts: " + totalL + "!=" + totalNPoints ) ; float [ ] data = new float [ totalNPoints ] ; for ( int i = 0 ; i < totalNPoints ; i ++ ) { data [ i ] = mv ; } return data ; } } else { if ( totalL != dataNPoints ) { logger . warn ( "NPoints != drs.nPts: " + totalL + "!=" + totalNPoints ) ; float [ ] data = new float [ totalNPoints ] ; for ( int i = 0 ; i < totalNPoints ; i ++ ) { data [ i ] = mv ; } return data ; } } float [ ] data = new float [ totalNPoints ] ; // [ zz + 1 ] - nn get X2 values and calculate the results Y using formula
// formula used to create values , Y * 10 * * D = R + ( X1 + X2 ) * 2 * * E
// Y = ( R + ( X1 + X2 ) * ( 2 * * E ) ) / ( 10 * * D ) ]
// WHERE :
// Y = THE VALUE WE ARE UNPACKING
// R = THE REFERENCE VALUE ( FIRST ORDER MINIMA )
// X1 = THE PACKED VALUE
// X2 = THE SECOND ORDER MINIMA
// E = THE BINARY SCALE FACTOR
// D = THE DECIMAL SCALE FACTOR
int count = 0 ; reader . incrByte ( ) ; int dataSize = 0 ; boolean [ ] dataBitMap = null ; if ( mvm == 0 ) { for ( int i = 0 ; i < NG ; i ++ ) { if ( NB [ i ] != 0 ) { for ( int j = 0 ; j < L [ i ] ; j ++ ) { data [ count ++ ] = ( int ) reader . bits2UInt ( NB [ i ] ) + X1 [ i ] ; } } else { for ( int j = 0 ; j < L [ i ] ; j ++ ) { data [ count ++ ] = X1 [ i ] ; } } } // end for i
} else if ( mvm == 1 || mvm == 2 ) { // don ' t add missing values into data but keep track of them in dataBitMap
dataBitMap = new boolean [ totalNPoints ] ; dataSize = 0 ; for ( int i = 0 ; i < NG ; i ++ ) { if ( NB [ i ] != 0 ) { int msng1 = bitsmv1 [ NB [ i ] ] ; int msng2 = msng1 - 1 ; for ( int j = 0 ; j < L [ i ] ; j ++ ) { data [ count ] = ( int ) reader . bits2UInt ( NB [ i ] ) ; if ( data [ count ] == msng1 || mvm == 2 && data [ count ] == msng2 ) { dataBitMap [ count ] = false ; } else { dataBitMap [ count ] = true ; data [ dataSize ++ ] = data [ count ] + X1 [ i ] ; } count ++ ; } } else { // ( NB [ i ] = = 0
int msng1 = bitsmv1 [ gdrs . numberOfBits ] ; int msng2 = msng1 - 1 ; if ( X1 [ i ] == msng1 ) { for ( int j = 0 ; j < L [ i ] ; j ++ ) { dataBitMap [ count ++ ] = false ; } // data [ count + + ] = X1 [ i ] ;
} else if ( mvm == 2 && X1 [ i ] == msng2 ) { for ( int j = 0 ; j < L [ i ] ; j ++ ) { dataBitMap [ count ++ ] = false ; } } else { for ( int j = 0 ; j < L [ i ] ; j ++ ) { dataBitMap [ count ] = true ; data [ dataSize ++ ] = X1 [ i ] ; count ++ ; } } } } // end for i
} // first order spatial differencing
if ( os == 1 ) { // g1 and gMin
// encoded by G ( n ) = F ( n ) - F ( n - 1 )
// decoded by F ( n ) = G ( n ) + F ( n - 1 )
// data [ ] at this point contains G0 , G1 , G2 , . . . .
data [ 0 ] = ival1 ; int itemp ; if ( mvm == 0 ) { // no missing values
itemp = totalNPoints ; } else { itemp = dataSize ; } for ( int i = 1 ; i < itemp ; i ++ ) { data [ i ] += minsd ; data [ i ] = data [ i ] + data [ i - 1 ] ; } } else if ( os == 2 ) { // 2nd order
data [ 0 ] = ival1 ; data [ 1 ] = ival2 ; int itemp ; if ( mvm == 0 ) { // no missing values
itemp = totalNPoints ; } else { itemp = dataSize ; } for ( int i = 2 ; i < itemp ; i ++ ) { data [ i ] += minsd ; data [ i ] = data [ i ] + ( 2 * data [ i - 1 ] ) - data [ i - 2 ] ; } } // formula used to create values , Y * 10 * * D = R + ( X1 + X2 ) * 2 * * E
// Y = ( R + ( X1 + X2 ) * ( 2 * * E ) ) / ( 10 * * D ) ]
// WHERE :
// Y = THE VALUE WE ARE UNPACKING
// R = THE REFERENCE VALUE ( FIRST ORDER MINIMA )
// X1 = THE PACKED VALUE
// X2 = THE SECOND ORDER MINIMA
// E = THE BINARY SCALE FACTOR
// D = THE DECIMAL SCALE FACTOR
if ( mvm == 0 ) { // no missing values
for ( int i = 0 ; i < data . length ; i ++ ) { data [ i ] = ( R + ( data [ i ] * EE ) ) / DD ; } } else if ( mvm == 1 || mvm == 2 ) { // missing value = = 1 | | missing value = = 2
int count2 = 0 ; float [ ] tmp = new float [ totalNPoints ] ; for ( int i = 0 ; i < data . length ; i ++ ) { if ( dataBitMap [ i ] ) { tmp [ i ] = ( R + ( data [ count2 ++ ] * EE ) ) / DD ; } else { // mvm = 1 or 2
tmp [ i ] = mv ; } } data = tmp ; } // bit map is used
if ( bitmap != null ) { int idx = 0 ; float [ ] tmp = new float [ totalNPoints ] ; for ( int i = 0 ; i < totalNPoints ; i ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ i / 8 ] , i % 8 ) ) { tmp [ i ] = data [ idx ++ ] ; } else { tmp [ i ] = mv ; } } data = tmp ; } return data ;


signature:
public class Grib2DataReader { /** * Grid point data - JPEG 2000 code stream format */
private float [ ] getData40 ( RandomAccessFile raf , Grib2Drs . Type40 gdrs ) throws IOException { } }

implementation:
// 6 - xx jpeg2000 data block to decode
// dataPoints are number of points encoded , it could be less than the
// totalNPoints in the grid record if bitMap is used , otherwise equal
// int dataPoints = drs . getDataPoints ( ) ;
int nb = gdrs . numberOfBits ; int D = gdrs . decimalScaleFactor ; float DD = ( float ) java . lang . Math . pow ( ( double ) 10 , ( double ) D ) ; float R = gdrs . referenceValue ; int E = gdrs . binaryScaleFactor ; float EE = ( float ) java . lang . Math . pow ( 2.0 , ( double ) E ) ; float ref_val = R / DD ; Grib2JpegDecoder g2j = null ; // try {
if ( nb != 0 ) { // there ' s data to decode
g2j = new Grib2JpegDecoder ( nb , false ) ; byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; g2j . decode ( buf ) ; gdrs . hasSignedProblem = g2j . hasSignedProblem ( ) ; } float [ ] result = new float [ totalNPoints ] ; // no data to decode , set to reference value
if ( nb == 0 ) { for ( int i = 0 ; i < dataNPoints ; i ++ ) { result [ i ] = ref_val ; } return result ; } int [ ] idata = g2j . getGdata ( ) ; if ( bitmap == null ) { // must be one decoded value in idata for every expected data point
if ( idata . length != dataNPoints ) { logger . debug ( "Number of points in the data record {} != {} expected from GDS" , idata . length , dataNPoints ) ; throw new IllegalStateException ( "Number of points in the data record {} != expected from GDS" ) ; } for ( int i = 0 ; i < dataNPoints ; i ++ ) { // Y * 10 ^ D = R + ( X1 + X2 ) * 2 ^ E ; / / regulation 92.9.4
// Y = ( R + ( 0 + X2 ) * EE ) / DD ;
result [ i ] = ( R + idata [ i ] * EE ) / DD ; } return result ; } else { // use bitmap to skip missing values
for ( int i = 0 , j = 0 ; i < totalNPoints ; i ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ i / 8 ] , i % 8 ) ) { if ( j >= idata . length ) { logger . warn ( "HEY jj2000 data count %d < bitmask count %d, i=%d, totalNPoints=%d%n" , idata . length , j , i , totalNPoints ) ; break ; } int indata = idata [ j ] ; result [ i ] = ( R + indata * EE ) / DD ; j ++ ; } else { result [ i ] = staticMissingValue ; } } } return result ; /* } catch ( NullPointerException npe ) {
 logger . error ( " Grib2DataReader2 . jpeg2000Unpacking : bit rate too small nb = " + nb + " for file " + raf . getLocation ( ) ) ;
 float [ ] data = new float [ dataNPoints ] ;
 for ( int i = 0 ; i < dataNPoints ; i + + ) {
 data [ i ] = staticMissingValue ; / / LOOK ? ?
 return data ; */


signature:
public class Grib2DataReader { /** * Grid point data - JPEG 2000 code stream format */
@ Nullable private int [ ] getData40raw ( RandomAccessFile raf , Grib2Drs . Type40 gdrs ) throws IOException { } }

implementation:
int nb = gdrs . numberOfBits ; if ( nb == 0 ) { return null ; } int missing_value = ( 2 << nb - 1 ) - 1 ; // all ones - reserved for missing value
Grib2JpegDecoder g2j ; g2j = new Grib2JpegDecoder ( nb , false ) ; byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; g2j . decode ( buf ) ; gdrs . hasSignedProblem = g2j . hasSignedProblem ( ) ; int [ ] idata = g2j . getGdata ( ) ; if ( bitmap == null ) { // must be one decoded value in idata for every expected data point
if ( idata . length != totalNPoints ) { logger . debug ( "Number of points in the data record {} != {} expected from GDS" , idata . length , totalNPoints ) ; return null ; } return idata ; } else { // use bitmap to skip missing values
int [ ] result = new int [ totalNPoints ] ; for ( int i = 0 , j = 0 ; i < totalNPoints ; i ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ i / 8 ] , i % 8 ) ) { if ( j >= idata . length ) { logger . warn ( "HEY jj2000 data count %d < bitmask count %d, i=%d, totalNPoints=%d%n" , idata . length , j , i , totalNPoints ) ; break ; } result [ i ] = idata [ j ] ; j ++ ; } else { result [ i ] = missing_value ; } } return result ; }


signature:
public class Grib2DataReader { /** * Code taken from esupport ticket ZVT - 415274 */
private float [ ] getData41 ( RandomAccessFile raf , Grib2Drs . Type0 gdrs ) throws IOException { } }

implementation:
int nb = gdrs . numberOfBits ; int D = gdrs . decimalScaleFactor ; float DD = ( float ) java . lang . Math . pow ( ( double ) 10 , ( double ) D ) ; float R = gdrs . referenceValue ; int E = gdrs . binaryScaleFactor ; float EE = ( float ) java . lang . Math . pow ( 2.0 , ( double ) E ) ; // LOOK : can # datapoints differ from bitmap and data ?
// dataPoints are number of points encoded , it could be less than the
// totalNPoints in the grid record if bitMap is used , otherwise equal
float [ ] data = new float [ totalNPoints ] ; // no data to decode , set to reference value
if ( nb == 0 ) { Arrays . fill ( data , R ) ; return data ; } // Y * 10 * * D = R + ( X1 + X2 ) * 2 * * E
// E = binary scale factor
// D = decimal scale factor
// R = reference value
// X1 = 0
// X2 = scaled encoded value
// data [ i ] = ( R + ( X1 + X2 ) * EE ) / DD ;
byte [ ] buf = new byte [ dataLength - 5 ] ; raf . readFully ( buf ) ; InputStream in = new ByteArrayInputStream ( buf ) ; BufferedImage image = ImageIO . read ( in ) ; if ( nb != image . getColorModel ( ) . getPixelSize ( ) ) { logger . debug ( "PNG pixel size disagrees with grib number of bits: " , image . getColorModel ( ) . getPixelSize ( ) , nb ) ; } DataBuffer db = image . getRaster ( ) . getDataBuffer ( ) ; if ( bitmap == null ) { for ( int i = 0 ; i < dataNPoints ; i ++ ) { data [ i ] = ( R + db . getElem ( i ) * EE ) / DD ; } } else { for ( int bitPt = 0 , dataPt = 0 ; bitPt < totalNPoints ; bitPt ++ ) { if ( GribNumbers . testBitIsSet ( bitmap [ bitPt / 8 ] , bitPt % 8 ) ) { data [ bitPt ] = ( R + db . getElem ( dataPt ++ ) * EE ) / DD ; } else { data [ bitPt ] = staticMissingValue ; } } } return data ;


signature:
public class Grib2DataReader { /** * ported from https : / / github . com / erdc - cm / grib _ api / blob / master / src / grib _ accessor _ class _ data _ g1second _ order _ general _ extended _ packing . c */
private float [ ] getData50002 ( RandomAccessFile raf , Grib2Drs . Type50002 gdrs ) throws IOException { } }

implementation: BitReader reader ; reader = new BitReader ( raf , startPos + 5 ) ; int [ ] groupWidth = new int [ gdrs . p1 ] ; for ( int i = 0 ; i < gdrs . p1 ; i ++ ) { groupWidth [ i ] = ( int ) reader . bits2UInt ( gdrs . widthOfWidth ) ; } reader = new BitReader ( raf , raf . getFilePointer ( ) ) ; int [ ] groupLength = new int [ gdrs . p1 ] ; for ( int i = 0 ; i < gdrs . p1 ; i ++ ) { groupLength [ i ] = ( int ) reader . bits2UInt ( gdrs . widthOfLength ) ; } reader = new BitReader ( raf , raf . getFilePointer ( ) ) ; int [ ] firstOrderValues = new int [ gdrs . p1 ] ; for ( int i = 0 ; i < gdrs . p1 ; i ++ ) { firstOrderValues [ i ] = ( int ) reader . bits2UInt ( gdrs . widthOfFirstOrderValues ) ; } int bias = 0 ; if ( gdrs . orderOfSPD > 0 ) { bias = gdrs . spd [ gdrs . orderOfSPD ] ; } reader = new BitReader ( raf , raf . getFilePointer ( ) ) ; int cnt = gdrs . orderOfSPD ; int [ ] data = new int [ totalNPoints ] ; for ( int i = 0 ; i < gdrs . p1 ; i ++ ) { if ( groupWidth [ i ] > 0 ) { for ( int j = 0 ; j < groupLength [ i ] ; j ++ ) { data [ cnt ] = ( int ) reader . bits2UInt ( groupWidth [ i ] ) ; data [ cnt ] += firstOrderValues [ i ] ; cnt ++ ; } } else { for ( int j = 0 ; j < groupLength [ i ] ; j ++ ) { data [ cnt ] = firstOrderValues [ i ] ; cnt ++ ; } } } if ( gdrs . orderOfSPD >= 0 ) { System . arraycopy ( gdrs . spd , 0 , data , 0 , gdrs . orderOfSPD ) ; } int y , z , w ; switch ( gdrs . orderOfSPD ) { case 1 : y = data [ 0 ] ; for ( int i = 1 ; i < totalNPoints ; i ++ ) { y += data [ i ] + bias ; data [ i ] = y ; } break ; case 2 : y = data [ 1 ] - data [ 0 ] ; z = data [ 1 ] ; for ( int i = 2 ; i < totalNPoints ; i ++ ) { y += data [ i ] + bias ; z += y ; data [ i ] = z ; } break ; case 3 : y = data [ 2 ] - data [ 1 ] ; z = y - ( data [ 1 ] - data [ 0 ] ) ; w = data [ 2 ] ; for ( int i = 3 ; i < totalNPoints ; i ++ ) { z += data [ i ] + bias ; y += z ; w += y ; data [ i ] = w ; } break ; } int D = gdrs . decimalScaleFactor ; float DD = ( float ) java . lang . Math . pow ( ( double ) 10 , ( double ) D ) ; float R = gdrs . referenceValue ; int E = gdrs . binaryScaleFactor ; float EE = ( float ) java . lang . Math . pow ( 2.0 , ( double ) E ) ; float [ ] ret = new float [ totalNPoints ] ; for ( int i = 0 ; i < totalNPoints ; i ++ ) { ret [ i ] = ( ( ( data [ i ] * EE ) + R ) * DD ) ; } return ret ;


signature:
public class Grib2DataReader { /** * LOOK might be wrong for a quasi regular ( thin ) grid ? ? */
private void scanningModeCheck ( float [ ] data , int scanMode , int Xlength ) { } }

implementation:
// Mode 0 + x , - y , adjacent x , adjacent rows same dir
// Mode 64 + x , + y , adjacent x , adjacent rows same dir
if ( ( scanMode == 0 ) || ( scanMode == 64 ) ) // dont flip Y - handle it in the HorizCoordSys
{ return ; } // change - x to + x ie east to west - > west to east
if ( ! GribUtils . scanModeXisPositive ( scanMode ) ) { float tmp ; int mid = Xlength / 2 ; for ( int index = 0 ; index < data . length ; index += Xlength ) { for ( int idx = 0 ; idx < mid ; idx ++ ) { tmp = data [ index + idx ] ; data [ index + idx ] = data [ index + Xlength - idx - 1 ] ; data [ index + Xlength - idx - 1 ] = tmp ; } } return ; } if ( ! GribUtils . scanModeSameDirection ( scanMode ) ) { float tmp ; int mid = Xlength / 2 ; for ( int index = 0 ; index < data . length ; index += Xlength ) { int row = index / Xlength ; if ( row % 2 != 0 ) { // odd numbered row , calculate reverse index
for ( int idx = 0 ; idx < mid ; idx ++ ) { tmp = data [ index + idx ] ; data [ index + idx ] = data [ index + Xlength - idx - 1 ] ; data [ index + Xlength - idx - 1 ] = tmp ; } } } }


signature:
public class CDMCursor { /** * AbstractCursor Abstract Methods */
@ Override public Object read ( List < Slice > slices ) throws DapException { } }

implementation: switch ( this . scheme ) { case ATOMIC : return readAtomic ( slices ) ; case STRUCTURE : if ( ( ( DapVariable ) this . getTemplate ( ) ) . getRank ( ) > 0 || DapUtil . isScalarSlices ( slices ) ) throw new DapException ( "Cannot slice a scalar variable" ) ; CDMCursor [ ] instances = new CDMCursor [ 1 ] ; instances [ 0 ] = this ; return instances ; case SEQUENCE : if ( ( ( DapVariable ) this . getTemplate ( ) ) . getRank ( ) > 0 || DapUtil . isScalarSlices ( slices ) ) throw new DapException ( "Cannot slice a scalar variable" ) ; instances = new CDMCursor [ 1 ] ; instances [ 0 ] = this ; return instances ; case STRUCTARRAY : Odometer odom = Odometer . factory ( slices ) ; instances = new CDMCursor [ ( int ) odom . totalSize ( ) ] ; for ( int i = 0 ; odom . hasNext ( ) ; i ++ ) { instances [ i ] = readStructure ( odom . next ( ) ) ; } return instances ; case SEQARRAY : instances = readSequence ( slices ) ; return instances ; default : throw new DapException ( "Attempt to slice a scalar object" ) ; }


signature:
public class CDMCursor { /** * Support Methods */
protected Object readAtomic ( List < Slice > slices ) throws DapException { } }

implementation: if ( slices == null ) throw new DapException ( "DataCursor.read: null set of slices" ) ; assert ( this . scheme == scheme . ATOMIC ) ; DapVariable atomvar = ( DapVariable ) getTemplate ( ) ; assert slices != null && ( ( atomvar . getRank ( ) == 0 && slices . size ( ) == 1 ) || ( slices . size ( ) == atomvar . getRank ( ) ) ) ; return sliceAtomic ( slices , this . array , atomvar ) ;


signature:
public class CFGridWriter { /** * Write a netcdf - 3 file from a subset of a grid dataset
 * @ param location write new file
 * @ param gds from this grid dataset
 * @ param gridList just these grids
 * @ param llbb horiz subset , may be null
 * @ param range time subset , may be null
 * @ throws IOException
 * @ throws InvalidRangeException */
static public void makeFile ( String location , ucar . nc2 . dt . GridDataset gds , List < String > gridList , LatLonRect llbb , CalendarDateRange range ) throws IOException , InvalidRangeException { } }

implementation: CFGridWriter writer = new CFGridWriter ( ) ; writer . makeFile ( location , gds , gridList , llbb , range , false , 1 , 1 , 1 ) ;


signature:
public class CFGridWriter { /** * Write a netcdf - 3 file from a subset of a grid dataset , as long as it doesnt exceed a certain file size .
 * @ param gds from this grid dataset
 * @ param gridList just these grids
 * @ param llbb horiz subset , may be null
 * @ param zRange vertical subset , may be null
 * @ param dateRange time subset , may be null
 * @ param stride _ time time may be strided , - 1 if want all
 * @ param addLatLon optionally add a lat / lon coordinate ( if dataset uses projection coords )
 * @ return file size
 * @ throws IOException
 * @ throws InvalidRangeException */
public long makeGridFileSizeEstimate ( ucar . nc2 . dt . GridDataset gds , List < String > gridList , LatLonRect llbb , int horizStride , Range zRange , CalendarDateRange dateRange , int stride_time , boolean addLatLon ) throws IOException , InvalidRangeException { } }

implementation: return makeOrTestSize ( null , gds , gridList , llbb , horizStride , zRange , dateRange , stride_time , addLatLon , true , NetcdfFileWriter . Version . netcdf3 ) ;


signature:
public class CFGridWriter { /** * Write a CF compliant Netcdf - 3 file from any gridded dataset .
 * @ param location write to this location on disk
 * @ param gds A gridded dataset
 * @ param gridList the list of grid names to be written , must not be empty . Full name ( not short ) .
 * @ param llbb optional lat / lon bounding box
 * @ param range optional time range
 * @ param addLatLon should 2D lat / lon variables be added , if its a projection coordinate system ?
 * @ param horizStride x , y stride
 * @ param stride _ z not implemented yet
 * @ param stride _ time not implemented yet
 * @ throws IOException if write or read error
 * @ throws InvalidRangeException if subset is illegal */
public void makeFile ( String location , ucar . nc2 . dt . GridDataset gds , List < String > gridList , LatLonRect llbb , CalendarDateRange range , boolean addLatLon , int horizStride , int stride_z , int stride_time ) throws IOException , InvalidRangeException { } }

implementation: makeFile ( location , gds , gridList , llbb , horizStride , null , range , stride_time , addLatLon , NetcdfFileWriter . Version . netcdf3 ) ;


signature:
public class CFGridWriter { /** * Process the coordinate transformations ( formula _ terms ) and adds the variables needed for performing that transformation to the list of variables in the new file .
 * Also , subsets the grids variables , if needed .
 * @ param varList
 * @ param varNameList
 * @ param ncd
 * @ param gds
 * @ param grid
 * @ param timeRange
 * @ param zRangeUse
 * @ param llbb
 * @ param z _ stride
 * @ param y _ stride
 * @ param x _ stride
 * @ return size of the added variables
 * @ throws InvalidRangeException */
private long processTransformationVars ( ArrayList < Variable > varList , ArrayList < String > varNameList , NetcdfDataset ncd , ucar . nc2 . dt . GridDataset gds , GridDatatype grid , Range timeRange , Range zRangeUse , LatLonRect llbb , int z_stride , int y_stride , int x_stride , List < CoordinateAxis > axisList ) throws InvalidRangeException { } }

implementation: List < Range > yxRanges = new ArrayList < Range > ( 2 ) ; if ( llbb == null ) { yxRanges . add ( null ) ; yxRanges . add ( null ) ; } else { yxRanges = grid . getCoordinateSystem ( ) . getRangesFromLatLonRect ( llbb ) ; } return processTransformationVars ( varList , varNameList , ncd , gds , grid , timeRange , zRangeUse , yxRanges . get ( 0 ) , yxRanges . get ( 1 ) , z_stride , y_stride , x_stride ) ;


signature:
public class StationRenderer { /** * Set the list of stations .
 * @ param stns : list of DDStation objects */
public void setStations ( java . util . List < ucar . unidata . geoloc . Station > stns ) { } }

implementation:
stations = new ArrayList < StationUI > ( stns . size ( ) ) ; stationHash . clear ( ) ; for ( int i = 0 ; i < stns . size ( ) ; i ++ ) { ucar . unidata . geoloc . Station s = ( ucar . unidata . geoloc . Station ) stns . get ( i ) ; StationUI sui = new StationUI ( s ) ; // wrap in a StationUI
stations . add ( sui ) ; // wrap in a StationUI
stationHash . put ( s . getName ( ) , sui ) ; } posWasCalc = false ; calcWorldPos ( ) ;


signature:
public class StationRenderer { /** * set selected station based on the sttion id . */
public void setSelectedStation ( String name ) { } }

implementation: StationUI sui = ( StationUI ) stationHash . get ( name ) ; if ( sui != null ) { setSelectedStation ( sui ) ; }


signature:
public class StationRenderer { /** * Find station that contains this point . If it exists , make it the
 * " selected " station .
 * @ param pickPt : world coordinates
 * @ return station that contains this point , or null if none . */
public ucar . unidata . geoloc . Station pick ( Point2D pickPt ) { } }

implementation:
if ( world2Normal == null || pickPt == null || stations . isEmpty ( ) ) return null ; world2Normal . transform ( pickPt , ptN ) ; // work in normalized coordinate space
StationUI closest = ( StationUI ) stationGrid . findIntersection ( ptN ) ; setSelectedStation ( closest ) ; return getSelectedStation ( ) ;


signature:
public class StationRenderer { /** * Find station closest to this point . Make it the " selected " station .
 * @ param pickPt : world coordinates
 * @ return station that contains this point , or null if none . */
public ucar . unidata . geoloc . Station pickClosest ( Point2D pickPt ) { } }

implementation:
if ( world2Normal == null || pickPt == null || stations . isEmpty ( ) ) return null ; world2Normal . transform ( pickPt , ptN ) ; // work in normalized coordinate space
StationUI closest = ( StationUI ) stationGrid . findClosest ( ptN ) ; if ( debug ) System . out . println ( "closest= " + closest ) ; setSelectedStation ( closest ) ; return getSelectedStation ( ) ;


signature:
public class StationRenderer { /** * Get the selected station .
 * @ return the selected station , or null if none selected */
public ucar . unidata . geoloc . Station getSelectedStation ( ) { } }

implementation: return ( selected != null ) ? selected . ddStation : null ;


signature: public class BufrConfig { private void merge ( Element iospParam ) { } }

implementation:
assert iospParam . getName ( ) . equals ( "iospParam" ) ; Element bufr2nc = iospParam . getChild ( "bufr2nc" , Catalog . ncmlNS ) ; if ( bufr2nc == null ) return ; for ( Element child : bufr2nc . getChildren ( "fld" , Catalog . ncmlNS ) ) merge ( child , rootConverter ) ; } private void merge ( Element jdom , FieldConverter parent ) { if ( jdom == null || parent == null ) return ; FieldConverter fld = null ; // find the corresponding field
String idxName = jdom . getAttributeValue ( "idx" ) ; if ( idxName != null ) { try { int idx = Integer . parseInt ( idxName ) ; fld = parent . getChild ( idx ) ; } catch ( NumberFormatException ne ) { log . info ( "BufrConfig cant find Child member index={} for file = {}" , idxName , filename ) ; } } if ( fld == null ) { String fxyName = jdom . getAttributeValue ( "fxy" ) ; if ( fxyName != null ) { fld = parent . findChildByFxyName ( fxyName ) ; if ( fld == null ) { log . info ( "BufrConfig cant find Child member fxy={} for file = {}" , fxyName , filename ) ; } } } if ( fld == null ) { String name = jdom . getAttributeValue ( "name" ) ; if ( name != null ) { fld = parent . findChild ( name ) ; if ( fld == null ) { log . info ( "BufrConfig cant find Child member name={} for file = {}" , name , filename ) ; } } } if ( fld == null ) { log . info ( "BufrConfig must have idx, name or fxy attribute = {} for file = {}" , jdom , filename ) ; return ; } String action = jdom . getAttributeValue ( "action" ) ; if ( action != null && ! action . isEmpty ( ) ) fld . setAction ( action ) ; if ( jdom . getChildren ( "fld" ) != null ) { for ( Element child : jdom . getChildren ( "fld" , Catalog . ncmlNS ) ) { merge ( child , fld ) ; } } } private StandardFields . StandardFieldsFromStructure extract ; private boolean hasStations = false ; private boolean hasDate = false ; private int countObs = 0 ; private void scanBufrFile ( RandomAccessFile raf ) throws Exception { NetcdfFile ncd = null ; countObs = 0 ; try { MessageScanner scanner = new MessageScanner ( raf ) ; Message protoMessage = scanner . getFirstDataMessage ( ) ; if ( protoMessage == null ) throw new IOException ( "No message found!" ) ; messHash = protoMessage . hashCode ( ) ; standardFields = StandardFields . extract ( protoMessage ) ; rootConverter = new FieldConverter ( protoMessage . ids . getCenterId ( ) , protoMessage . getRootDataDescriptor ( ) ) ; if ( standardFields . hasStation ( ) ) { hasStations = true ; map = new HashMap < > ( 1000 ) ; } featureType = guessFeatureType ( standardFields ) ; hasDate = standardFields . hasTime ( ) ; // ncd = NetcdfDataset . openDataset ( raf . getLocation ( ) , BufrIosp2 . enhance , - 1 , null , null ) ; / / LOOK opening another raf
ncd = NetcdfFile . open ( raf . getLocation ( ) ) ; // LOOK opening another raf
Attribute centerAtt = ncd . findGlobalAttribute ( BufrIosp2 . centerId ) ; int center = ( centerAtt == null ) ? 0 : centerAtt . getNumericValue ( ) . intValue ( ) ; Sequence seq = ( Sequence ) ncd . findVariable ( null , BufrIosp2 . obsRecord ) ; extract = new StandardFields . StandardFieldsFromStructure ( center , seq ) ; StructureDataIterator iter = seq . getStructureIterator ( ) ; processSeq ( iter , rootConverter , true ) ; setStandardActions ( rootConverter ) ; } finally { if ( ncd != null ) ncd . close ( ) ; } System . out . printf ( "nobs = %d%n" , countObs ) ; } private FeatureType guessFeatureType ( StandardFields . StandardFieldsFromMessage standardFields ) { if ( standardFields . hasStation ( ) ) return FeatureType . STATION ; if ( standardFields . hasTime ( ) ) return FeatureType . POINT ; return FeatureType . ANY ; } private void setStandardActions ( FieldConverter fld ) { fld . setAction ( fld . makeAction ( ) ) ; if ( fld . flds == null ) return ; for ( FieldConverter child : fld . flds ) setStandardActions ( child ) ; } private CalendarDate today = CalendarDate . present ( ) ; private void processSeq ( StructureDataIterator sdataIter , FieldConverter parent , boolean isTop ) throws IOException { try { while ( sdataIter . hasNext ( ) ) { StructureData sdata = sdataIter . next ( ) ; if ( isTop ) { countObs ++ ; if ( debug && countObs % 100 == 0 ) System . out . printf ( "%d " , countObs ) ; if ( hasStations ) processStations ( parent , sdata ) ; if ( hasDate ) { extract . extract ( sdata ) ; CalendarDate date = extract . makeCalendarDate ( ) ; if ( Math . abs ( date . getDifferenceInMsecs ( today ) ) > 1000L * 3600 * 24 * 100 ) { extract . makeCalendarDate ( ) ; } long msecs = date . getMillis ( ) ; if ( this . start > msecs ) { this . start = msecs ; // System . out . printf ( " new start % s % n " , date ) ;
} if ( this . end < msecs ) { this . end = msecs ; // System . out . printf ( " new end % s % n " , date ) ;
} } } int count = 0 ; for ( StructureMembers . Member m : sdata . getMembers ( ) ) { if ( m . getDataType ( ) == DataType . SEQUENCE ) { FieldConverter fld = parent . getChild ( count ) ; ArraySequence data = ( ArraySequence ) sdata . getArray ( m ) ; int n = data . getStructureDataCount ( ) ; fld . trackSeqCounts ( n ) ; processSeq ( data . getStructureDataIterator ( ) , fld , false ) ; } count ++ ; } } } finally { sdataIter . close ( ) ; } } private void processStations ( FieldConverter parent , StructureData sdata ) { BufrStation station = new BufrStation ( ) ; station . read ( parent , sdata ) ; if ( station . getName ( ) == null ) { log . warn ( "bad station name: " + station ) ; return ; } BufrStation check = map . get ( station . getName ( ) ) ; if ( check == null ) map . put ( station . getName ( ) , station ) ; else { check . count ++ ; if ( ! station . equals ( check ) ) log . warn ( "bad station doesnt equal " + station + " != " + check ) ; } } public class BufrStation extends StationImpl { public int count = 1 ; void read ( FieldConverter parent , StructureData sdata ) { extract . extract ( sdata ) ; setName ( extract . getStationId ( ) ) ; setLatitude ( extract . getFieldValueD ( BufrCdmIndexProto . FldType . lat ) ) ; setLongitude ( extract . getFieldValueD ( BufrCdmIndexProto . FldType . lon ) ) ; if ( extract . hasField ( BufrCdmIndexProto . FldType . stationDesc ) ) setDescription ( extract . getFieldValueS ( BufrCdmIndexProto . FldType . stationDesc ) ) ; if ( extract . hasField ( BufrCdmIndexProto . FldType . wmoId ) ) setWmoId ( extract . getFieldValueS ( BufrCdmIndexProto . FldType . wmoId ) ) ; if ( extract . hasField ( BufrCdmIndexProto . FldType . heightOfStation ) ) setAltitude ( extract . getFieldValueD ( BufrCdmIndexProto . FldType . heightOfStation ) ) ; } /* void read ( FieldConverter parent , StructureData sdata ) {
 int count = 0;
 List < FieldConverter > flds = parent . getChildren ( ) ; / / asssume these track exactly the members
 for ( StructureMembers . Member m : sdata . getMembers ( ) ) {
 FieldConverter fld = flds . get ( count + + ) ;
 if ( fld . getType ( ) = = null ) continue ;
 switch ( fld . getType ( ) ) {
 case stationId :
 setName ( readString ( sdata , m ) ) ;
 break ;
 case stationDesc :
 setDescription ( sdata . getScalarString ( m ) ) ;
 break ;
 case wmoId :
 setWmoId ( readString ( sdata , m ) ) ;
 break ;
 case lat :
 setLatitude ( sdata . convertScalarDouble ( m ) ) ;
 break ;
 case lon :
 setLongitude ( sdata . convertScalarDouble ( m ) ) ;
 break ;
 case height :
 setAltitude ( sdata . convertScalarDouble ( m ) ) ;
 break ;
 case heightOfStation :
 setAltitude ( sdata . convertScalarDouble ( m ) ) ;
 break ;
 String readString ( StructureData sdata , StructureMembers . Member m ) {
 if ( m . getDataType ( ) . isString ( ) )
 return sdata . getScalarString ( m ) ;
 else if ( m . getDataType ( ) . isIntegral ( ) )
 return Integer . toString ( sdata . convertScalarInt ( m ) ) ;
 else if ( m . getDataType ( ) . isNumeric ( ) )
 return Double . toString ( sdata . convertScalarDouble ( m ) ) ;
 else return " type " + m . getDataType ( ) ; */
@ Override public boolean equals ( Object o ) { if ( this == o ) return true ; if ( o == null || getClass ( ) != o . getClass ( ) ) return false ; BufrStation that = ( BufrStation ) o ; if ( Double . compare ( that . alt , alt ) != 0 ) return false ; if ( Double . compare ( that . lat , lat ) != 0 ) return false ; if ( Double . compare ( that . lon , lon ) != 0 ) return false ; if ( desc != null ? ! desc . equals ( that . desc ) : that . desc != null ) return false ; if ( ! name . equals ( that . name ) ) return false ; if ( wmoId != null ? ! wmoId . equals ( that . wmoId ) : that . wmoId != null ) return false ; return true ; } @ Override public int hashCode ( ) { int result ; long temp ; temp = Double . doubleToLongBits ( lat ) ; result = ( int ) ( temp ^ ( temp >>> 32 ) ) ; temp = Double . doubleToLongBits ( lon ) ; result = 31 * result + ( int ) ( temp ^ ( temp >>> 32 ) ) ; temp = Double . doubleToLongBits ( alt ) ; result = 31 * result + ( int ) ( temp ^ ( temp >>> 32 ) ) ; result = 31 * result + name . hashCode ( ) ; result = 31 * result + ( desc != null ? desc . hashCode ( ) : 0 ) ; result = 31 * result + ( wmoId != null ? wmoId . hashCode ( ) : 0 ) ; return result ; } } public class FieldConverter implements BufrField { DataDescriptor dds ; List < FieldConverter > flds ; BufrCdmIndexProto . FldType type ; BufrCdmIndexProto . FldAction action ; int min = Integer . MAX_VALUE ; int max = 0 ; boolean isSeq ; private FieldConverter ( int center , DataDescriptor dds ) { this . dds = dds ; this . type = StandardFields . findField ( center , dds . getFxyName ( ) ) ; if ( dds . getSubKeys ( ) != null ) { this . flds = new ArrayList < > ( dds . getSubKeys ( ) . size ( ) ) ; for ( DataDescriptor subdds : dds . getSubKeys ( ) ) { FieldConverter subfld = new FieldConverter ( center , subdds ) ; flds . add ( subfld ) ; } } } public String getName ( ) { return dds . getName ( ) ; } public String getDesc ( ) { return dds . getDesc ( ) ; } public String getUnits ( ) { return dds . getUnits ( ) ; } public short getFxy ( ) { return dds . getFxy ( ) ; } public String getFxyName ( ) { return dds . getFxyName ( ) ; } public BufrCdmIndexProto . FldAction getAction ( ) { return action ; } public BufrCdmIndexProto . FldType getType ( ) { return type ; } public List < FieldConverter > getChildren ( ) { return flds ; } public boolean isSeq ( ) { return isSeq ; } public int getMin ( ) { return min ; } public int getMax ( ) { return max ; } public int getScale ( ) { return dds . getScale ( ) ; } public int getReference ( ) { return dds . getRefVal ( ) ; } public int getBitWidth ( ) { return dds . getBitWidth ( ) ; } public void setAction ( String action ) { BufrCdmIndexProto . FldAction act = BufrCdmIndexProto . FldAction . valueOf ( action ) ; if ( act != null ) this . action = act ; } public void setAction ( BufrCdmIndexProto . FldAction action ) { this . action = action ; } FieldConverter findChild ( String want ) { for ( FieldConverter child : flds ) { String name = child . dds . getName ( ) ; if ( name != null && name . equals ( want ) ) return child ; } return null ; } FieldConverter findChildByFxyName ( String fxyName ) { for ( FieldConverter child : flds ) { String name = child . dds . getFxyName ( ) ; if ( name != null && name . equals ( fxyName ) ) return child ; } return null ; } public FieldConverter getChild ( int i ) { return flds . get ( i ) ; } void trackSeqCounts ( int n ) { isSeq = true ; if ( n > max ) max = n ; if ( n < min ) min = n ; } void showRange ( Formatter f ) { if ( ! isSeq ) return ; if ( max == min ) f . format ( " isConstant='%d'" , max ) ; else if ( max < 2 ) f . format ( " isBinary='true'" ) ; else f . format ( " range='[%d,%d]'" , min , max ) ; } BufrCdmIndexProto . FldAction makeAction ( ) { if ( ! isSeq ) return null ; if ( max == 0 ) return BufrCdmIndexProto . FldAction . remove ; if ( max < 2 ) return BufrCdmIndexProto . FldAction . asMissing ; else return BufrCdmIndexProto . FldAction . asArray ; } void show ( Formatter f , Indent indent , int index ) { boolean hasContent = false ; if ( isSeq ) f . format ( "%s<fld idx='%d' name='%s'" , indent , index , dds . getName ( ) ) ; else f . format ( "%s<fld idx='%d' fxy='%s' name='%s' desc='%s' units='%s' bits='%d'" , indent , index , dds . getFxyName ( ) , dds . getName ( ) , dds . getDesc ( ) , dds . getUnits ( ) , dds . getBitWidth ( ) ) ; if ( type != null ) f . format ( " type='%s'" , type ) ; showRange ( f ) ; f . format ( " action='%s'" , makeAction ( ) ) ; /* if ( type ! = null ) {
 f . format ( " > % n " ) ;
 indent . incr ( ) ;
 f . format ( " % s < type > % s < / type > % n " , indent , type ) ;
 indent . decr ( ) ;
 hasContent = true ; */
if ( flds != null ) { f . format ( ">%n" ) ; indent . incr ( ) ; int subidx = 0 ; for ( FieldConverter cc : flds ) { cc . show ( f , indent , subidx ++ ) ; } indent . decr ( ) ; hasContent = true ; } if ( hasContent ) f . format ( "%s</fld>%n" , indent ) ; else f . format ( " />%n" ) ; } } public void show ( Formatter out ) { if ( standardFields != null ) out . format ( "Standard Fields%n%s%n%n" , standardFields ) ; Indent indent = new Indent ( 2 ) ; out . format ( "<bufr2nc location='%s' hash='%s' featureType='%s'>%n" , filename , Integer . toHexString ( messHash ) , featureType ) ; indent . incr ( ) ; int index = 0 ; for ( FieldConverter fld : rootConverter . flds ) { fld . show ( out , indent , index ++ ) ; } indent . decr ( ) ; out . format ( "</bufr2nc>%n" ) ; } public static void main ( String [ ] args ) throws IOException { String filename = "G:/work/manross/split/872d794d.bufr" ; // String filename = " Q : / cdmUnitTest / formats / bufr / US058MCUS - BUFtdp . SPOUT _ 00011 _ buoy _ 20091101021700 . bufr " ;
try ( RandomAccessFile raf = new RandomAccessFile ( filename , "r" ) ) { BufrConfig config = BufrConfig . scanEntireFile ( raf ) ; Formatter out = new Formatter ( ) ; config . show ( out ) ; System . out . printf ( "%s%n" , out ) ; } }


signature:
public class DataRootExt { /** * / * message DataRoot {
 * required string urlPath = 1;
 * required string dirLocation = 2;
 * required DataRootType type = 3;
 * optional string catLocation = 4 ; / / omit for simple dataset root */
public void writeExternal ( DataOutputStream out ) throws IOException { } }

implementation: ConfigCatalogExtProto . DataRoot . Builder builder = ConfigCatalogExtProto . DataRoot . newBuilder ( ) ; builder . setUrlPath ( path ) ; builder . setDirLocation ( dirLocation ) ; builder . setType ( convertDataRootType ( type ) ) ; if ( type != DataRoot . Type . datasetRoot ) { builder . setCatLocation ( catLocation ) ; builder . setName ( name ) ; } if ( restrict != null ) builder . setRestrict ( restrict ) ; ConfigCatalogExtProto . DataRoot index = builder . build ( ) ; byte [ ] b = index . toByteArray ( ) ; out . writeInt ( b . length ) ; out . write ( b ) ; total_count ++ ; total_nbytes += b . length + 4 ; if ( debug ) System . out . printf ( " %d: DataRootExt.writeExternal len=%d total=%d%n" , total_count , b . length , total_nbytes ) ;


signature:
public class DataRootExt { /** * Type { datasetRoot , datasetScan , catalogScan , featureCollection } */
static public DataRoot . Type convertDataRootType ( ConfigCatalogExtProto . DataRootType type ) { } }

implementation: switch ( type ) { case datasetRoot : return DataRoot . Type . datasetRoot ; case datasetScan : return DataRoot . Type . datasetScan ; case catalogScan : return DataRoot . Type . catalogScan ; case featureCollection : return DataRoot . Type . featureCollection ; } throw new IllegalStateException ( "illegal DataRootType " + type ) ;


signature:
public class McGridDefRecord { /** * Set the parameters for the GDS */
private void setParams ( ) { } }

implementation:
/* PS and CONF projection parameters */
double xrowi ; // row # of North Pole * 10000
double xcoli ; // column # of North Pole * 10000
double xqlon ; // longitude parallel to columns
double xspace ; // column spacing at standard latitude
double yspace ; // row spacing at standard latitude
double xt1 ; // standard latitude
double xt2 ; // 2nd standard latitude
double xh ; double xfac ; double xblat ; /* Merc and pseudo _ merc parameters */
double glamx ; // max latitude
double glomx ; // max longitude
double glamn ; // min latitude
double glomn ; // min longitude
double ginct ; // grid increment in latitude
double gincn ; // grid increment in longitude
try { GRIDnav nav = new GRIDnav ( vals ) ; int gridType = vals [ 33 ] ; int navType = gridType % 10 ; addParam ( "Proj" , String . valueOf ( navType ) ) ; boolean wierd = gridType / 10 == 1 ; int ny = vals [ 1 ] ; int nx = vals [ 2 ] ; addParam ( PROJ , getProjName ( navType ) ) ; addParam ( NX , String . valueOf ( nx ) ) ; addParam ( NY , String . valueOf ( ny ) ) ; double [ ] [ ] input ; if ( nav . isFlippedRowCoordinates ( ) ) { input = new double [ ] [ ] { { 1 , nx } , { 1 , ny } } ; } else { input = new double [ ] [ ] { { 1 , nx } , { ny , 1 } } ; } double [ ] [ ] llur = nav . toLatLon ( input ) ; /* if ( cnt = = 0 & & navType = = 6 ) {
 System . out . println ( " Proj = " + getProjName ( navType ) + " : " + navType ) ;
 System . out . println ( " isFlipped = " + nav . isFlippedRowCoordinates ( ) ) ;
 ucar . unidata . util . Misc . printArray ( " input x " , input [ 0 ] ) ;
 ucar . unidata . util . Misc . printArray ( " input y " , input [ 1 ] ) ;
 ucar . unidata . util . Misc . printArray ( " lats " , llur [ 0 ] ) ;
 ucar . unidata . util . Misc . printArray ( " lons " , llur [ 1 ] ) ;
 cnt + + ; */
addParam ( LA1 , String . valueOf ( llur [ 0 ] [ 0 ] ) ) ; addParam ( LO1 , String . valueOf ( llur [ 1 ] [ 0 ] ) ) ; addParam ( LA2 , String . valueOf ( llur [ 0 ] [ 1 ] ) ) ; addParam ( LO2 , String . valueOf ( llur [ 1 ] [ 1 ] ) ) ; switch ( navType ) { case PSEUDO_MERCATOR : case PSEUDO_MERCATOR_GENERAL : glamx = vals [ 34 ] / 10000. ; glomx = - vals [ 35 ] / 10000. ; glamn = vals [ 34 ] / 10000. ; glomn = - vals [ 35 ] / 10000. ; ginct = vals [ 38 ] / 10000. ; gincn = ( navType == PSEUDO_MERCATOR_GENERAL ) ? vals [ 39 ] / 10000. : ginct ; addParam ( "Latin" , String . valueOf ( 20 ) ) ; // addParam ( DX , String . valueOf ( gincn ) ) ;
// addParam ( DY , String . valueOf ( ginct ) ) ;
/* if ( wierd ) {
 double x = xnr ;
 xnr = xnc ;
 xnc = x ; */
break ; case PS_OR_LAMBERT_CONIC : xrowi = vals [ 34 ] / 10000. ; // row # of the North pole * 10000
xcoli = vals [ 35 ] / 10000. ; // col # of the North pole * 10000
xspace = vals [ 36 ] ; // column spacing at standard lat ( m )
xqlon = - vals [ 37 ] / 10000. ; // lon parallel to cols ( deg * 10000)
xt1 = vals [ 38 ] / 10000. ; // first standard lat
xt2 = vals [ 39 ] / 10000. ; // second standard lat
addParam ( LATIN1 , String . valueOf ( xt1 ) ) ; addParam ( LOV , String . valueOf ( xqlon ) ) ; addParam ( LATIN2 , String . valueOf ( xt2 ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( xspace ) ) ; /* xh = ( xt1 > = 0 ) ? 1 . : - 1 . ;
 xt1 = ( 90 . - xh * xt1 ) * xrad ;
 xt2 = ( 90 . - xh * xt2 ) * xrad ;
 xfac = 1.0;
 if ( xt1 ! = xt2)
 xfac = ( Math . log ( Math . sin ( xt1 ) ) - Math . log ( Math . sin ( xt2 ) ) ) /
 ( Math . log ( Math . tan ( . 5 * xt1 ) ) - Math . log ( Math . tan ( . 5 * xt2 ) ) ) ;
 xfac = 1.0 / xfac ;
 xblat = 6370 . * Math . sin ( xt1 ) /
 ( xspace * xfac * ( Math . pow ( Math . tan ( xt1 * . 5 ) , xfac ) ) ) ;
 if ( wierd ) {
 double x = xnr ;
 xnr = xnc ;
 xnc = x ;
 x = xcoli ;
 xcoli = xrowi ;
 xrowi = xnr - x + 1.0;
 xqlon = xqlon + 90 . ; */
break ; case EQUIDISTANT : xrowi = 1. ; xcoli = 1. ; glamx = vals [ 34 ] / 10000. ; // lat of ( 1,1 ) degrees * 10000
glomx = - vals [ 35 ] / 10000. ; // lon of ( 1,1 ) degrees * 10000
// xrot = - xrad * vals [ 36 ] / 10000 . ; / / clockwise rotation of col 1
xspace = vals [ 37 ] / 1000. ; // column spacing
yspace = vals [ 38 ] / 1000. ; // row spacing
addParam ( LA1 , String . valueOf ( glamx ) ) ; addParam ( LO1 , String . valueOf ( glomx ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( yspace ) ) ; /* xblat = EARTH _ RADIUS * xrad / yspace ;
 xblon = EARTH _ RADIUS * xrad / xspace ;
 if ( wierd ) {
 double x = xnr ;
 xnr = xnc ;
 xnc = x ; */
break ; case LAMBERT_CONFORMAL_TANGENT : xrowi = vals [ 34 ] / 10000. ; // lat at ( 1,1)
xcoli = vals [ 35 ] / 10000. ; // lon at ( 1,1)
xspace = vals [ 36 ] ; // column spacing at standard lat ( m )
xqlon = - vals [ 37 ] / 10000. ; // lon parallel to cols ( deg * 10000)
xt1 = vals [ 38 ] / 10000. ; // standard lat 1
xt2 = vals [ 39 ] / 10000. ; // standard lat 2
if ( Double . compare ( xt2 , ( double ) McIDASUtil . MCMISSING ) == 0 || ( xt2 == 0 ) ) { // LOOK suspicious floating point point compare
xt2 = xt1 ; } addParam ( LATIN1 , String . valueOf ( xt1 ) ) ; addParam ( LOV , String . valueOf ( xqlon ) ) ; addParam ( LATIN2 , String . valueOf ( xt2 ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( xspace ) ) ; /* xh = ( xt1 > = 0 ) ? 1 . : - 1 . ;
 xt1 = ( 90 . - xh * xt1 ) * xrad ;
 xfac = Math . cos ( xt1 ) ;
 xblat = EARTH _ RADIUS * Math . tan ( xt1 ) /
 ( xspace * Math . pow ( Math . tan ( xt1 * . 5 ) , xfac ) ) ; */
break ; default : break ; } } catch ( McIDASException me ) { System . out . println ( "couldn't set nav" ) ; }


signature:
public class McGridDefRecord { /** * Get the name for the projection type
 * @ param type the projection type
 * @ return a String name for the type */
public String getProjName ( int type ) { } }

implementation: String projName ; switch ( type ) { case PSEUDO_MERCATOR : case PSEUDO_MERCATOR_GENERAL : projName = "MERC" ; break ; case PS_OR_LAMBERT_CONIC : projName = ( vals [ 38 ] == vals [ 39 ] ) ? "PS" : "CONF" ; break ; case EQUIDISTANT : projName = "EQUI" ; break ; case LAMBERT_CONFORMAL_TANGENT : projName = "CONF" ; break ; default : projName = "NAV" + type ; } return projName ;


signature:
public class SocketMessage { /** * public void exit ( ) { listen . exit ( ) ; } */
private void sendMessage ( int port , String message ) { } }

implementation: Socket connection = null ; try { connection = new Socket ( "localhost" , port ) ; IO . writeContents ( message , connection . getOutputStream ( ) ) ; if ( debug ) System . out . println ( " sent message " + message ) ; } catch ( IOException e ) { System . err . println ( e ) ; e . printStackTrace ( ) ; } finally { try { if ( connection != null ) connection . close ( ) ; } catch ( IOException e ) { } }


signature: public class SocketMessage { public static void main ( String [ ] args ) throws IOException { } }

implementation:
if ( false ) { new SocketMessage ( 9999 , "startNewServer" ) ; raw = true ; } else { String url = "http://localhost:8080/thredds/test/it" // + EscapeStrings . escapeOGC ( " yabba / bad [ 0 ] / good " )
+ "?" + EscapeStrings . escapeOGC ( "quuery[1]" ) ; System . out . printf ( "send '%s'%n" , url ) ; try ( HTTPMethod method = HTTPFactory . Head ( url ) ) { method . execute ( ) ; int status = method . getStatusCode ( ) ; System . out . printf ( "%d%n" , status ) ; } // close method , close method internal session
}


signature:
public class RubberbandRectangleHandles { /** * Erase the last rectangle and shift the rectangle and redraw
 * deltax , deltay : position from original position */
public void move ( int deltax , int deltay ) { } }

implementation:
lastPt . x = stretchedPt . x ; lastPt . y = stretchedPt . y ; Graphics2D g = ( Graphics2D ) component . getGraphics ( ) ; if ( g != null ) { try { g . setXORMode ( component . getBackground ( ) ) ; if ( firstStretch == true ) firstStretch = false ; else drawLast ( g ) ; anchorPt . x = current . x + deltax ; anchorPt . y = current . y + deltay ; stretchedPt . x = current . x + current . width + deltax ; stretchedPt . y = current . y + current . height + deltay ; drawNext ( g ) ; } finally { g . dispose ( ) ; } // try
} // if


signature:
public class BufrMessageViewer { /** * / * private void compare ( Message m1 , Message m2 , Formatter f ) {
 * Formatter f1 = new Formatter ( ) ;
 * Formatter f2 = new Formatter ( ) ;
 * m1 . dump ( f1 ) ;
 * m1 . dump ( f2 ) ;
 * TextHistoryPane ta = new TextHistoryPane ( ) ;
 * IndependentWindow info = new IndependentWindow ( " Extra Information " , BAMutil . getImage ( " netcdfUI " ) , ta ) ;
 * info . setBounds ( ( Rectangle ) prefs . getBean ( " InfoWindowBounds " , new Rectangle ( 300 , 300 , 500 , 300 ) ) ) ;
 * ta . appendLine ( f . toString ( ) ) ;
 * ta . gotoTop ( ) ;
 * info . show ( ) ; */
private void showDDS ( Message m1 ) { } }

implementation: Formatter f1 = new Formatter ( ) ; m1 . dump ( f1 ) ; TextHistoryPane ta = new TextHistoryPane ( ) ; IndependentWindow info = new IndependentWindow ( "Extra Information" , BAMutil . getImage ( "netcdfUI" ) , ta ) ; info . setBounds ( ( Rectangle ) prefs . getBean ( "InfoWindowBounds" , new Rectangle ( 300 , 300 , 500 , 300 ) ) ) ; ta . appendLine ( f1 . toString ( ) ) ; ta . gotoTop ( ) ; info . show ( ) ;


signature: public class BufrMessageViewer { public void save ( ) { } }

implementation: messageTable . saveState ( false ) ; ddsTable . saveState ( false ) ; obsTable . saveState ( false ) ; prefs . putBeanObject ( "InfoWindowBounds" , infoWindow . getBounds ( ) ) ; prefs . putBeanObject ( "InfoWindowBounds2" , infoWindow2 . getBounds ( ) ) ; prefs . putInt ( "splitPos" , split . getDividerLocation ( ) ) ; prefs . putInt ( "splitPos2" , split2 . getDividerLocation ( ) ) ; if ( fileChooser != null ) fileChooser . save ( ) ;


signature:
public class StationDatasetCollection { /** * Get all the Stations within a bounding box .
 * @ param boundingBox within this bounding box
 * @ return List of Station
 * @ throws java . io . IOException I / O error */
public List getStations ( ucar . unidata . geoloc . LatLonRect boundingBox ) throws IOException { } }

implementation: return typical . getStations ( boundingBox ) ;


signature:
public class StationDatasetCollection { /** * Find a Station by name
 * @ param name name of the Station
 * @ return Station with that name , or null if not found */
public ucar . unidata . geoloc . Station getStation ( String name ) { } }

implementation: return typical . getStation ( name ) ;


signature:
public class StationDatasetCollection { /** * Get all data for this Station .
 * @ param s Station
 * @ return iterator over type getDataClass ( )
 * @ throws java . io . IOException I / O error */
public DataIterator getDataIterator ( ucar . unidata . geoloc . Station s ) throws IOException { } }

implementation: return new StationDataIterator ( s ) ;


signature:
public class StationDatasetCollection { /** * Get data for this Station within the specified date range .
 * @ param s Station
 * @ param start starting Date
 * @ param end ending Date
 * @ return Iterator over type getDataClass ( )
 * @ throws java . io . IOException I / O error */
public DataIterator getDataIterator ( ucar . unidata . geoloc . Station s , Date start , Date end ) throws IOException { } }

implementation: return new StationDateDataIterator ( s , start , end ) ;


signature:
public class Ray { /** * Read data from this ray .
 * @ param raf read from this file
 * @ param abbrev which data type we want
 * @ param gateRange handles the possible subset of data to return
 * @ param ii put the data here
 * @ throws java . io . IOException */
public void readData ( RandomAccessFile raf , String abbrev , Range gateRange , IndexIterator ii ) throws IOException { } }

implementation: long offset = rayOffset ; offset += ( getDataOffset ( abbrev ) * 2 - 2 ) ; raf . seek ( offset ) ; byte [ ] b2 = new byte [ 2 ] ; int dataCount = getGateCount ( abbrev ) ; byte [ ] data = new byte [ dataCount * 2 ] ; raf . readFully ( data ) ; for ( int gateIdx : gateRange ) { if ( gateIdx >= dataCount ) ii . setShortNext ( uf_header2 . missing ) ; else { b2 [ 0 ] = data [ gateIdx * 2 ] ; b2 [ 1 ] = data [ gateIdx * 2 + 1 ] ; short value = getShort ( b2 , 0 ) ; ii . setShortNext ( value ) ; } }


signature:
public class DStructure { /** * Returns the number of variables contained in this object . For simple and
 * vector type variables , it always returns 1 . To count the number
 * of simple - type variable in the variable tree rooted at this variable , set
 * < code > leaves < / code > to < code > true < / code > .
 * @ param leaves If true , count all the simple types in the ` tree ' of
 * variables rooted at this variable .
 * @ return the number of contained variables . */
public int elementCount ( boolean leaves ) { } }

implementation: if ( ! leaves ) return vars . size ( ) ; else { int count = 0 ; for ( Enumeration e = vars . elements ( ) ; e . hasMoreElements ( ) ; ) { BaseType bt = ( BaseType ) e . nextElement ( ) ; count += bt . elementCount ( leaves ) ; } return count ; }


signature:
public class DStructure { /** * Gets the indexed variable . For a DStructure this returns the
 * < code > BaseType < / code > from the < code > index < / code > th column from the
 * internal storage < code > Vector < / code > .
 * @ param index the index of the variable in the < code > Vector < / code > Vars .
 * @ return the indexed variable .
 * @ throws NoSuchVariableException if the named variable does not
 * exist in this container . */
public BaseType getVar ( int index ) throws NoSuchVariableException { } }

implementation: if ( index < vars . size ( ) ) return ( ( BaseType ) vars . elementAt ( index ) ) ; else throw new NoSuchVariableException ( "DStructure.getVariable(" + index + " - 1)" ) ;


signature:
public class DStructure { /** * Prints the value of the variable , with its declaration . This
 * function is primarily intended for debugging OPeNDAP applications and
 * text - based clients such as geturl .
 * @ param os the < code > PrintWriter < / code > on which to print the value .
 * @ param space this value is passed to the < code > printDecl < / code > method ,
 * and controls the leading spaces of the output .
 * @ param print _ decl _ p a boolean value controlling whether the
 * variable declaration is printed as well as the value .
 * @ see BaseType # printVal ( PrintWriter , String , boolean ) */
public void printVal ( PrintWriter os , String space , boolean print_decl_p ) { } }

implementation: if ( print_decl_p ) { printDecl ( os , space , false ) ; os . print ( " = " ) ; } os . print ( "{ " ) ; for ( Enumeration e = vars . elements ( ) ; e . hasMoreElements ( ) ; ) { BaseType bt = ( BaseType ) e . nextElement ( ) ; bt . printVal ( os , "" , false ) ; if ( e . hasMoreElements ( ) ) os . print ( ", " ) ; } os . print ( " }" ) ; if ( print_decl_p ) os . println ( ";" ) ;


signature:
public class DStructure { /** * Reads data from a < code > DataInputStream < / code > . This method is only used
 * on the client side of the OPeNDAP client / server connection .
 * @ param source a < code > DataInputStream < / code > to read from .
 * @ param sv the < code > ServerVersion < / code > returned by the server .
 * @ param statusUI the < code > StatusUI < / code > object to use for GUI updates
 * and user cancellation notification ( may be null ) .
 * @ throws EOFException if EOF is found before the variable is completely
 * deserialized .
 * @ throws IOException thrown on any other InputStream exception .
 * @ throws DataReadException if an unexpected value was read .
 * @ see ClientIO # deserialize ( DataInputStream , ServerVersion , StatusUI ) */
public synchronized void deserialize ( DataInputStream source , ServerVersion sv , StatusUI statusUI ) throws IOException , EOFException , DataReadException { } }

implementation: for ( Enumeration e = vars . elements ( ) ; e . hasMoreElements ( ) ; ) { if ( statusUI != null && statusUI . userCancelled ( ) ) throw new DataReadException ( "User cancelled" ) ; ClientIO bt = ( ClientIO ) e . nextElement ( ) ; bt . deserialize ( source , sv , statusUI ) ; }


signature:
public class DStructure { /** * Writes data to a < code > DataOutputStream < / code > . This method is used
 * primarily by GUI clients which need to download OPeNDAP data , manipulate
 * it , and then re - save it as a binary file .
 * @ param sink a < code > DataOutputStream < / code > to write to .
 * @ throws IOException thrown on any < code > OutputStream < / code >
 * exception . */
public void externalize ( DataOutputStream sink ) throws IOException { } }

implementation: for ( Enumeration e = vars . elements ( ) ; e . hasMoreElements ( ) ; ) { ClientIO bt = ( ClientIO ) e . nextElement ( ) ; bt . externalize ( sink ) ; }


signature:
public class DStructure { /** * Returns a clone of this < code > Structure < / code > .
 * See DAPNode . cloneDag ( )
 * @ param map track previously cloned nodes
 * @ return a clone of this object . */
public DAPNode cloneDAG ( CloneMap map ) throws CloneNotSupportedException { } }

implementation: DStructure s = ( DStructure ) super . cloneDAG ( map ) ; s . vars = new Vector ( ) ; for ( int i = 0 ; i < vars . size ( ) ; i ++ ) { BaseType bt = ( BaseType ) vars . elementAt ( i ) ; BaseType btclone = ( BaseType ) cloneDAG ( map , bt ) ; s . vars . addElement ( btclone ) ; } return s ;


signature:
public class Float32PrimitiveVector { /** * Writes data to a < code > DataOutputStream < / code > . This method is used
 * primarily by GUI clients which need to download OPeNDAP data , manipulate
 * it , and then re - save it as a binary file .
 * @ param sink a < code > DataOutputStream < / code > to write to .
 * @ throws IOException thrown on any < code > OutputStream < / code >
 * exception . */
public void externalize ( DataOutputStream sink ) throws IOException { } }

implementation: for ( int i = 0 ; i < vals . length ; i ++ ) { sink . writeFloat ( vals [ i ] ) ; }


signature:
public class Grib2Utils { /** * isLatLon2D is true , check parameter to see if its a 2D lat / lon coordinate */
@ Nullable public static LatLon2DCoord getLatLon2DcoordType ( int discipline , int category , int parameter ) { } }

implementation: if ( ( discipline != 0 ) || ( category != 2 ) || ( parameter < 198 || parameter > 203 ) ) return null ; switch ( parameter ) { case 198 : return LatLon2DCoord . U_Latitude ; case 199 : return LatLon2DCoord . U_Longitude ; case 200 : return LatLon2DCoord . V_Latitude ; case 201 : return LatLon2DCoord . V_Longitude ; case 202 : return LatLon2DCoord . P_Latitude ; case 203 : return LatLon2DCoord . P_Longitude ; } return null ;


signature:
public class Grib2Utils { /** * This looks for snippets in the variable name / desc as to whether it wants U , V , or P 2D coordinates
 * @ param desc variable name / desc
 * @ return U , V , or P for normal variables , null for the coordinates themselves */
public static LatLonCoordType getLatLon2DcoordType ( String desc ) { } }

implementation: LatLonCoordType type ; if ( desc . contains ( "u-component" ) ) type = LatLonCoordType . U ; else if ( desc . contains ( "v-component" ) ) type = LatLonCoordType . V ; else if ( desc . contains ( "Latitude of" ) || desc . contains ( "Longitude of" ) ) type = null ; else type = LatLonCoordType . P ; return type ;


signature:
public class Grib2Utils { /** * Compare 2 tables , print report . */
public static void compareTables ( String name1 , String name2 , List < ? extends GribTables . Parameter > test , Grib2Tables reference , Formatter f ) { } }

implementation:
int extra = 0 ; int udunits = 0 ; int conflict = 0 ; f . format ( "Table 1 : %s%n" , name1 ) ; f . format ( "Table 2 : %s%n" , name2 ) ; for ( GribTables . Parameter p1 : test ) { GribTables . Parameter p2 = reference . getParameter ( p1 . getDiscipline ( ) , p1 . getCategory ( ) , p1 . getNumber ( ) ) ; if ( p2 == null ) { if ( p1 . getCategory ( ) < 192 && p1 . getNumber ( ) < 192 ) { extra ++ ; f . format ( "  WMO missing %s%n" , p1 ) ; } } else { String p1n = Util . cleanName ( p1 . getName ( ) ) ; String p2n = Util . cleanName ( p2 . getName ( ) ) ; if ( ! p1n . equalsIgnoreCase ( p2n ) ) { f . format ( "  p1=%10s %40s %15s %15s %s%n" , p1 . getId ( ) , p1 . getName ( ) , p1 . getUnit ( ) , p1 . getAbbrev ( ) , p1 . getDescription ( ) ) ; f . format ( "  p2=%10s %40s %15s %15s %s%n%n" , p2 . getId ( ) , p2 . getName ( ) , p2 . getUnit ( ) , p2 . getAbbrev ( ) , p2 . getDescription ( ) ) ; conflict ++ ; } if ( ! p1 . getUnit ( ) . equalsIgnoreCase ( p2 . getUnit ( ) ) ) { String cu1 = Util . cleanUnit ( p1 . getUnit ( ) ) ; String cu2 = Util . cleanUnit ( p2 . getUnit ( ) ) ; // eliminate common non - udunits
boolean isUnitless1 = Util . isUnitless ( cu1 ) ; boolean isUnitless2 = Util . isUnitless ( cu2 ) ; if ( isUnitless1 != isUnitless2 ) { f . format ( "  ud=%10s %s != %s for %s (%s)%n%n" , p1 . getId ( ) , cu1 , cu2 , p1 . getId ( ) , p1 . getName ( ) ) ; udunits ++ ; } else if ( ! isUnitless1 ) { try { SimpleUnit su1 = SimpleUnit . factoryWithExceptions ( cu1 ) ; if ( ! su1 . isCompatible ( cu2 ) ) { f . format ( "  ud=%10s %s (%s) != %s for %s (%s)%n%n" , p1 . getId ( ) , cu1 , su1 , cu2 , p1 . getId ( ) , p1 . getName ( ) ) ; udunits ++ ; } } catch ( Exception e ) { f . format ( "  udunits cant parse=%10s %15s %15s%n" , p1 . getId ( ) , cu1 , cu2 ) ; } } } } } f . format ( "Conflicts=%d extra=%d udunits=%d%n%n" , conflict , extra , udunits ) ; f . format ( "Parameters in %s not in %s%n" , name1 , name2 ) ; int local = 0 ; for ( GribTables . Parameter p1 : test ) { GribTables . Parameter p2 = reference . getParameter ( p1 . getDiscipline ( ) , p1 . getCategory ( ) , p1 . getNumber ( ) ) ; if ( p2 == null ) { local ++ ; f . format ( "  %s%n" , p1 ) ; } } f . format ( " missing=%d%n%n" , local ) ;


signature:
public class MAVector { /** * Cos between two vectors = dot ( v ) / norm ( ) * norm ( v )
 * @ param v cosine with this vector
 * @ return double result : cos between this and v
 * @ exception IllegalArgumentException if nelems ! = v . getNelems ( ) . */
public double cos ( MAVector v ) { } }

implementation: if ( nelems != v . getNelems ( ) ) throw new IllegalArgumentException ( "MAVector.cos " + nelems + " != " + v . getNelems ( ) ) ; double norm = norm ( ) ; double normV = v . norm ( ) ; if ( ( norm == 0.0 ) || ( normV == 0.0 ) ) return 0.0 ; else return dot ( v ) / ( norm * normV ) ;


signature:
public class MAVector { /** * Dot product of 2 vectors
 * @ param v dot product with this vector
 * @ return double result : dot product
 * @ exception IllegalArgumentException if nelems ! = v . getNelems ( ) . */
public double dot ( MAVector v ) { } }

implementation: if ( nelems != v . getNelems ( ) ) throw new IllegalArgumentException ( "MAVector.dot " + nelems + " != " + v . getNelems ( ) ) ; double sum = 0.0 ; for ( int k = 0 ; k < nelems ; k ++ ) sum += getDouble ( k ) * v . getDouble ( k ) ; return sum ;


signature:
public class MAVector { /** * Get the L2 norm of this vector .
 * @ return double norm */
public double norm ( ) { } }

implementation: double sum = 0.0 ; for ( int k = 0 ; k < nelems ; k ++ ) { double val = getDouble ( k ) ; sum += val * val ; } return Math . sqrt ( sum ) ;


signature:
public class MAVector { /** * Normalize this vector , so it has norm = 1.0. */
public void normalize ( ) { } }

implementation: double norm = norm ( ) ; if ( norm <= 0.0 ) return ; for ( int k = 0 ; k < nelems ; k ++ ) { double val = getDouble ( k ) ; setDouble ( k , val / norm ) ; }


signature: public class CatalogBuilder { public Catalog makeCatalog ( ) { } }

implementation: setServices ( getDatasets ( ) ) ; Map < String , Object > flds = setFields ( ) ; return new Catalog ( baseURI , name , flds , datasetBuilders ) ;


signature:
public class CatalogBuilder { /** * pull services out of the datasets and into the catalog */
private void setServices ( Iterable < DatasetBuilder > dsIter ) { } }

implementation:
for ( DatasetBuilder dsb : dsIter ) { for ( Service s : dsb . getServices ( ) ) { addService ( s ) ; } setServices ( dsb . getDatasets ( ) ) ; // recurse
}


signature:
public class CatalogBuilder { /** * / * private void readXML ( String fileName ) throws IOException {
 * try {
 * StAXStreamBuilder staxBuilder = new StAXStreamBuilder ( ) ;
 * XMLInputFactory xmlInputFactory = XMLInputFactory . newInstance ( ) ;
 * XMLStreamReader xmlStreamReader = xmlInputFactory . createXMLStreamReader ( new FileInputStream ( fileName ) ) ;
 * Document jdomDoc = staxBuilder . build ( xmlStreamReader ) ;
 * readCatalog ( jdomDoc . getRootElement ( ) ) ;
 * } catch ( Exception e ) {
 * errlog . format ( " failed to read catalog at ' % s ' err = ' % s ' % n " , fileName , e ) ;
 * logger . error ( " failed to read catalog at " + fileName , e ) ;
 * e . printStackTrace ( ) ;
 * fatalError = true ; */
private void readXML ( String location ) throws IOException { } }

implementation: try { SAXBuilder saxBuilder = new SAXBuilder ( ) ; Document jdomDoc = saxBuilder . build ( location ) ; readCatalog ( jdomDoc . getRootElement ( ) ) ; } catch ( Exception e ) { errlog . format ( "failed to read catalog at '%s' err='%s'%n" , location , e ) ; logger . error ( "failed to read catalog at {}, {}" , location , e . toString ( ) ) ; if ( logger . isTraceEnabled ( ) ) { e . printStackTrace ( ) ; } fatalError = true ; }


signature:
public class CatalogBuilder { /** * / * < xsd : element name = " catalog " >
 * < xsd : complexType >
 * < xsd : sequence >
 * < xsd : element ref = " service " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " property " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " dataset " minOccurs = " 1 " maxOccurs = " unbounded " / >
 * < / xsd : sequence >
 * < xsd : attribute name = " name " type = " xsd : string " / >
 * < xsd : attribute name = " expires " type = " dateType " / >
 * < xsd : attribute name = " version " type = " xsd : token " default = " 1.0.2 " / >
 * < / xsd : complexType >
 * < / xsd : element > */
private void readCatalog ( Element catalogElem ) { } }

implementation:
String name = catalogElem . getAttributeValue ( "name" ) ; String catSpecifiedBaseURL = catalogElem . getAttributeValue ( "base" ) ; // LOOK what is this ? ?
String expiresS = catalogElem . getAttributeValue ( "expires" ) ; String version = catalogElem . getAttributeValue ( "version" ) ; CalendarDate expires = null ; if ( expiresS != null ) { try { expires = CalendarDateFormatter . isoStringToCalendarDate ( null , expiresS ) ; } catch ( Exception e ) { errlog . format ( "bad expires date '%s' err='%s'%n" , expiresS , e . getMessage ( ) ) ; logger . debug ( "bad expires date '{}' err='{}'%n" , expiresS , e . getMessage ( ) ) ; } } if ( catSpecifiedBaseURL != null ) { try { URI userSpecifiedBaseUri = new URI ( catSpecifiedBaseURL ) ; this . baseURI = userSpecifiedBaseUri ; } catch ( URISyntaxException e ) { errlog . format ( "readCatalog(): bad catalog specified base URI='%s' %n" , catSpecifiedBaseURL ) ; logger . debug ( "bad catalog specified base URI='{}'" ) ; } } setName ( name ) ; setExpires ( expires ) ; setVersion ( version ) ; // read top - level services
java . util . List < Element > sList = catalogElem . getChildren ( "service" , Catalog . defNS ) ; for ( Element e : sList ) { addService ( readService ( e ) ) ; } // read top - level properties
java . util . List < Element > pList = catalogElem . getChildren ( "property" , Catalog . defNS ) ; for ( Element e : pList ) { addProperty ( readProperty ( e ) ) ; } // look for top - level dataset and catalogRefs elements ( keep them in order )
java . util . List < Element > allChildren = catalogElem . getChildren ( ) ; for ( Element e : allChildren ) { if ( e . getName ( ) . equals ( "dataset" ) ) { addDataset ( readDataset ( null , e ) ) ; } else if ( e . getName ( ) . equals ( "catalogRef" ) ) { addDataset ( readCatalogRef ( null , e ) ) ; } else { addDataset ( buildOtherDataset ( null , e ) ) ; } }


signature:
public class CatalogBuilder { /** * / * < xsd : element name = " access " >
 * < xsd : complexType >
 * < xsd : sequence >
 * < xsd : element ref = " dataSize " minOccurs = " 0 " / > / / whyd we do that ?
 * < / xsd : sequence >
 * < xsd : attribute name = " urlPath " type = " xsd : token " use = " required " / >
 * < xsd : attribute name = " serviceName " type = " xsd : string " / >
 * < xsd : attribute name = " dataFormat " type = " dataFormatTypes " / >
 * < / xsd : complexType >
 * < / xsd : element > */
protected AccessBuilder readAccess ( DatasetBuilder dataset , Element accessElem ) { } }

implementation: String urlPath = accessElem . getAttributeValue ( "urlPath" ) ; String serviceName = accessElem . getAttributeValue ( "serviceName" ) ; String dataFormat = accessElem . getAttributeValue ( "dataFormat" ) ; Service s = serviceMap . get ( serviceName ) ; if ( s == null ) { errlog . format ( "Cant find service name='%s'%n" , serviceName ) ; logger . debug ( "Can't find service name='{}'" , serviceName ) ; } return new AccessBuilder ( dataset , urlPath , s , dataFormat , readDataSize ( accessElem ) ) ;


signature:
public class CatalogBuilder { /** * / * < xsd : element name = " service " >
 * < xsd : complexType >
 * < xsd : sequence >
 * < xsd : element ref = " property " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " service " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < / xsd : sequence >
 * < xsd : attribute name = " name " type = " xsd : string " use = " required " / >
 * < xsd : attribute name = " base " type = " xsd : string " use = " required " / >
 * < xsd : attribute name = " serviceType " type = " serviceTypes " use = " required " / >
 * < xsd : attribute name = " desc " type = " xsd : string " / >
 * < xsd : attribute name = " accessType " type = " xsd : string " / >
 * < xsd : attribute name = " suffix " type = " xsd : string " / >
 * < / xsd : complexType >
 * < / xsd : element > */
protected Service readService ( Element s ) { } }

implementation:
String name = s . getAttributeValue ( "name" ) ; String typeS = s . getAttributeValue ( "serviceType" ) ; String serviceBase = s . getAttributeValue ( "base" ) ; String suffix = s . getAttributeValue ( "suffix" ) ; String desc = s . getAttributeValue ( "desc" ) ; String accessType = s . getAttributeValue ( "accessType" ) ; ServiceType type = ServiceType . getServiceTypeIgnoreCase ( typeS ) ; if ( type == null ) { errlog . format ( " non-standard service type = '%s'%n" , typeS ) ; logger . debug ( " non-standard service type = '{}'" , typeS ) ; } else { if ( desc == null ) { desc = type . getDescription ( ) ; } if ( accessType == null ) { accessType = type . getAccessType ( ) ; } } List < Property > properties = null ; List < Element > propertyList = s . getChildren ( "property" , Catalog . defNS ) ; for ( Element e : propertyList ) { if ( properties == null ) { properties = new ArrayList < > ( ) ; } properties . add ( readProperty ( e ) ) ; } // nested services
List < Service > services = null ; java . util . List < Element > serviceList = s . getChildren ( "service" , Catalog . defNS ) ; for ( Element e : serviceList ) { if ( services == null ) { services = new ArrayList < > ( ) ; } services . add ( readService ( e ) ) ; } Service result = new Service ( name , serviceBase , typeS , desc , suffix , services , properties , accessType ) ; serviceMap . put ( name , result ) ; return result ;


signature:
public class CatalogBuilder { /** * < xsd : element name = " catalogRef " substitutionGroup = " dataset " >
 * < xsd : complexType >
 * < xsd : complexContent >
 * < xsd : extension base = " DatasetType " >
 * < xsd : attributeGroup ref = " XLink " / >
 * < xsd : attribute name = " useRemoteCatalogService " type = " xsd : boolean " / >
 * < / xsd : extension >
 * < / xsd : complexContent >
 * < / xsd : complexType >
 * < / xsd : element > */
protected DatasetBuilder readCatalogRef ( DatasetBuilder parent , Element catRefElem ) { } }

implementation: String title = catRefElem . getAttributeValue ( "title" , Catalog . xlinkNS ) ; if ( title == null ) { title = catRefElem . getAttributeValue ( "name" ) ; } String href = catRefElem . getAttributeValue ( "href" , Catalog . xlinkNS ) ; CatalogRefBuilder catRef = new CatalogRefBuilder ( parent ) ; readDatasetInfo ( catRef , catRefElem ) ; catRef . setTitle ( title ) ; catRef . setHref ( href ) ; return catRef ;


signature:
public class CatalogBuilder { /** * / * < xsd : complexType name = " DatasetType " >
 * < xsd : sequence >
 * < xsd : group ref = " threddsMetadataGroup " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " access " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " ncml : netcdf " minOccurs = " 0 " / >
 * < xsd : element ref = " dataset " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < / xsd : sequence >
 * < xsd : attribute name = " name " type = " xsd : string " use = " required " / >
 * < xsd : attribute name = " alias " type = " xsd : token " / >
 * < xsd : attribute name = " authority " type = " xsd : string " / > < ! - - deprecated : use element - - >
 * < xsd : attribute name = " collectionType " type = " collectionTypes " / >
 * < xsd : attribute name = " dataType " type = " dataTypes " / > < ! - - deprecated : use element - - >
 * < xsd : attribute name = " harvest " type = " xsd : boolean " / >
 * < xsd : attribute name = " ID " type = " xsd : token " / >
 * < xsd : attribute name = " resourceControl " type = " xsd : string " / >
 * < xsd : attribute name = " serviceName " type = " xsd : string " / > < ! - - deprecated : use element - - >
 * < xsd : attribute name = " urlPath " type = " xsd : token " / >
 * < / xsd : complexType > */
protected DatasetBuilder readDataset ( DatasetBuilder parent , Element dsElem ) { } }

implementation:
DatasetBuilder dataset = new DatasetBuilder ( parent ) ; readDatasetInfo ( dataset , dsElem ) ; // look for access elements
java . util . List < Element > aList = dsElem . getChildren ( "access" , Catalog . defNS ) ; for ( Element e : aList ) { dataset . addAccess ( readAccess ( dataset , e ) ) ; } // look for nested dataset and catalogRefs elements ( keep them in order )
java . util . List < Element > allChildren = dsElem . getChildren ( ) ; for ( Element e : allChildren ) { if ( e . getName ( ) . equals ( "dataset" ) ) { dataset . addDataset ( readDataset ( dataset , e ) ) ; } else if ( e . getName ( ) . equals ( "catalogRef" ) ) { dataset . addDataset ( readCatalogRef ( dataset , e ) ) ; } else { dataset . addDataset ( buildOtherDataset ( dataset , e ) ) ; } } return dataset ;


signature:
public class CatalogBuilder { /** * < ! - - group of elements can be used in a dataset or in metadata elements - - >
 * < xsd : group name = " threddsMetadataGroup " >
 * < xsd : choice >
 * < xsd : element name = " documentation " type = " documentationType " / >
 * < xsd : element ref = " metadata " / >
 * < xsd : element ref = " property " / >
 * < xsd : element ref = " contributor " / >
 * < xsd : element name = " creator " type = " sourceType " / >
 * < xsd : element name = " date " type = " dateTypeFormatted " / >
 * < xsd : element name = " keyword " type = " controlledVocabulary " / >
 * < xsd : element name = " project " type = " controlledVocabulary " / >
 * < xsd : element name = " publisher " type = " sourceType " / >
 * < xsd : element ref = " geospatialCoverage " / >
 * < xsd : element name = " timeCoverage " type = " timeCoverageType " / >
 * < xsd : element ref = " variables " / >
 * < xsd : element ref = " variableMap " / >
 * < xsd : element name = " dataType " type = " dataTypes " / >
 * < xsd : element name = " dataFormat " type = " dataFormatTypes " / >
 * < xsd : element name = " serviceName " type = " xsd : string " / >
 * < xsd : element name = " authority " type = " xsd : string " / >
 * < xsd : element ref = " dataSize " / >
 * < / xsd : choice >
 * < / xsd : group > */
protected void readThreddsMetadataGroup ( Map < String , Object > flds , DatasetBuilder dataset , Element parent ) { } }

implementation:
List < Element > list ; // look for creators - kind of a Source
list = parent . getChildren ( "creator" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Creators , readSource ( e ) ) ; } // look for contributors
list = parent . getChildren ( "contributor" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Contributors , readContributor ( e ) ) ; } // look for dates
list = parent . getChildren ( "date" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Dates , readDate ( e , null ) ) ; } // look for documentation
list = parent . getChildren ( "documentation" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Documentation , readDocumentation ( e ) ) ; } // look for keywords - kind of a controlled vocabulary
list = parent . getChildren ( "keyword" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Keywords , readControlledVocabulary ( e ) ) ; } // look for metadata elements
list = parent . getChildren ( "metadata" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . MetadataOther , readMetadata ( flds , dataset , e ) ) ; } // look for projects - kind of a controlled vocabulary
list = parent . getChildren ( "project" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Projects , readControlledVocabulary ( e ) ) ; } // look for properties
list = parent . getChildren ( "property" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Properties , readProperty ( e ) ) ; } // look for publishers - kind of a Source
list = parent . getChildren ( "publisher" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . Publishers , readSource ( e ) ) ; } // look for variables
list = parent . getChildren ( "variables" , Catalog . defNS ) ; for ( Element e : list ) { DatasetBuilder . addToList ( flds , Dataset . VariableGroups , readVariables ( e ) ) ; } // can only be one each of these kinds
ThreddsMetadata . GeospatialCoverage gc = readGeospatialCoverage ( parent . getChild ( "geospatialCoverage" , Catalog . defNS ) ) ; if ( gc != null ) { flds . put ( Dataset . GeospatialCoverage , gc ) ; } DateRange tc = readTimeCoverage ( parent . getChild ( "timeCoverage" , Catalog . defNS ) ) ; if ( tc != null ) { flds . put ( Dataset . TimeCoverage , tc ) ; } Element serviceNameElem = parent . getChild ( "serviceName" , Catalog . defNS ) ; if ( serviceNameElem != null ) { flds . put ( Dataset . ServiceName , serviceNameElem . getText ( ) ) ; } Element authElem = parent . getChild ( "authority" , Catalog . defNS ) ; if ( authElem != null ) { flds . put ( Dataset . Authority , authElem . getText ( ) ) ; } Element dataTypeElem = parent . getChild ( "dataType" , Catalog . defNS ) ; if ( dataTypeElem != null ) { String dataTypeName = dataTypeElem . getText ( ) ; flds . put ( Dataset . FeatureType , dataTypeName ) ; if ( ( dataTypeName != null ) && ( dataTypeName . length ( ) > 0 ) ) { FeatureType dataType = FeatureType . getType ( dataTypeName . toUpperCase ( ) ) ; if ( dataType == null ) { errlog . format ( " ** warning: non-standard feature type = '%s'%n" , dataTypeName ) ; logger . debug ( " ** warning: non-standard feature type = '{}'" , dataTypeName ) ; } } } Element dataFormatElem = parent . getChild ( "dataFormat" , Catalog . defNS ) ; if ( dataFormatElem != null ) { String dataFormatTypeName = dataFormatElem . getText ( ) ; if ( ( dataFormatTypeName != null ) && ( dataFormatTypeName . length ( ) > 0 ) ) { DataFormatType dataFormatType = DataFormatType . getType ( dataFormatTypeName ) ; if ( dataFormatType == null ) { errlog . format ( " ** warning: non-standard dataFormat type = '%s'%n" , dataFormatTypeName ) ; logger . debug ( " ** warning: non-standard dataFormat type = '{}'" , dataFormatTypeName ) ; } flds . put ( Dataset . DataFormatType , dataFormatTypeName ) ; } } long size = readDataSize ( parent ) ; if ( size > 0 ) { flds . put ( Dataset . DataSize , size ) ; } // LOOK : we seem to have put a variableMap element not contained by < variables >
ThreddsMetadata . UriResolved mapUri = readUri ( parent . getChild ( "variableMap" , Catalog . defNS ) , "variableMap" ) ; if ( mapUri != null ) { flds . put ( Dataset . VariableMapLinkURI , mapUri ) ; }


signature: public class CatalogBuilder { protected Documentation readDocumentation ( Element s ) { } }

implementation:
String href = s . getAttributeValue ( "href" , Catalog . xlinkNS ) ; String title = s . getAttributeValue ( "title" , Catalog . xlinkNS ) ; String type = s . getAttributeValue ( "type" ) ; // not XLink type
String content = s . getTextNormalize ( ) ; URI uri = null ; if ( href != null ) { try { uri = Catalog . resolveUri ( baseURI , href ) ; } catch ( Exception e ) { errlog . format ( " ** Invalid documentation href = '%s' err='%s'%n" , href , e . getMessage ( ) ) ; logger . debug ( " ** Invalid documentation href = '{}' err='{}'" , href , e . getMessage ( ) ) ; } } return new Documentation ( href , uri , title , type , content ) ;


signature:
public class CatalogBuilder { /** * < xsd : element name = " metadata " >
 * < xsd : complexType >
 * < xsd : choice >
 * < xsd : group ref = " threddsMetadataGroup " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : any namespace = " # # other " minOccurs = " 0 " maxOccurs = " unbounded " processContents = " lax " / >
 * < / xsd : choice >
 * < xsd : attribute name = " inherited " type = " xsd : boolean " default = " false " / >
 * < xsd : attribute name = " metadataType " type = " metadataTypeEnum " / >
 * < xsd : attributeGroup ref = " XLink " / >
 * < / xsd : complexType >
 * < / xsd : element > */
protected ThreddsMetadata . MetadataOther readMetadata ( Map < String , Object > flds , DatasetBuilder dataset , Element mdataElement ) { } }

implementation:
// there are 6 cases to deal with : threddsNamespace vs not & inline vs Xlink & ( if thredds ) inherited or not
Namespace namespace ; List inlineElements = mdataElement . getChildren ( ) ; if ( inlineElements . size ( ) > 0 ) { // look at the namespace of the children , if they exist
namespace = ( ( Element ) inlineElements . get ( 0 ) ) . getNamespace ( ) ; } else { namespace = mdataElement . getNamespace ( ) ; // will be thredds
} String mtype = mdataElement . getAttributeValue ( "metadataType" ) ; String href = mdataElement . getAttributeValue ( "href" , Catalog . xlinkNS ) ; String title = mdataElement . getAttributeValue ( "title" , Catalog . xlinkNS ) ; String inheritedS = mdataElement . getAttributeValue ( "inherited" ) ; boolean inherited = ( inheritedS != null ) && inheritedS . equalsIgnoreCase ( "true" ) ; boolean isThreddsNamespace = ( ( mtype == null ) || mtype . equalsIgnoreCase ( "THREDDS" ) ) && namespace . getURI ( ) . equals ( Catalog . CATALOG_NAMESPACE_10 ) ; // the case where its not ThreddsMetadata
if ( ! isThreddsNamespace ) { if ( inlineElements . size ( ) > 0 ) { // just hold onto the jdom elements as the " content "
return new ThreddsMetadata . MetadataOther ( mtype , namespace . getURI ( ) , namespace . getPrefix ( ) , inherited , mdataElement ) ; } else { // otherwise it must be an Xlink
return new ThreddsMetadata . MetadataOther ( href , title , mtype , namespace . getURI ( ) , namespace . getPrefix ( ) , inherited ) ; } } // the case where its ThreddsMetadata
Map < String , Object > useFlds ; if ( inherited ) { // the case where its inherited ThreddsMetadata : gonna put stuff in the tmi .
ThreddsMetadata tmi = ( ThreddsMetadata ) dataset . get ( Dataset . ThreddsMetadataInheritable ) ; if ( tmi == null ) { tmi = new ThreddsMetadata ( ) ; dataset . put ( Dataset . ThreddsMetadataInheritable , tmi ) ; } useFlds = tmi . getFlds ( ) ; } else { // the case where its non - inherited ThreddsMetadata : gonna put stuff directly into the dataset
useFlds = flds ; } readThreddsMetadataGroup ( useFlds , dataset , mdataElement ) ; // also need to capture any XLinks . see http : / / www . unidata . ucar . edu / software / thredds / v4.6 / tds / catalog / InvCatalogSpec . html # metadataElement
// in this case we just suck it in as if it was inline
if ( href != null ) { try { URI xlinkUri = Catalog . resolveUri ( baseURI , href ) ; Element remoteMdata = readMetadataFromUrl ( xlinkUri ) ; return readMetadata ( useFlds , dataset , remoteMdata ) ; } catch ( Exception ioe ) { errlog . format ( "Cant read in referenced metadata %s err=%s%n" , href , ioe . getMessage ( ) ) ; logger . debug ( "Can't read in referenced metadata {} err={}}" , href , ioe . getMessage ( ) ) ; } } return null ; // ThreddsMetadata . MetadataOther was directly added


signature:
public class CatalogBuilder { /** * < xsd : complexType name = " sourceType " >
 * < xsd : sequence >
 * < xsd : element name = " name " type = " controlledVocabulary " / >
 * < xsd : element name = " contact " >
 * < xsd : complexType >
 * < xsd : attribute name = " email " type = " xsd : string " use = " required " / >
 * < xsd : attribute name = " url " type = " xsd : anyURI " / >
 * < / xsd : complexType >
 * < / xsd : element >
 * < / xsd : sequence >
 * < / xsd : complexType > */
protected ThreddsMetadata . Source readSource ( Element elem ) { } }

implementation: if ( elem == null ) { return null ; } ThreddsMetadata . Vocab name = readControlledVocabulary ( elem . getChild ( "name" , Catalog . defNS ) ) ; Element contact = elem . getChild ( "contact" , Catalog . defNS ) ; if ( contact == null ) { errlog . format ( " ** Parse error: Missing contact element in = '%s'%n" , elem . getName ( ) ) ; logger . debug ( " ** Parse error: Missing contact element in = '{}'" , elem . getName ( ) ) ; return null ; } return new ThreddsMetadata . Source ( name , contact . getAttributeValue ( "url" ) , contact . getAttributeValue ( "email" ) ) ;


signature:
public class CatalogBuilder { /** * < xsd : complexType name = " timeCoverageType " >
 * < xsd : sequence >
 * < xsd : attribute name = " calendar " type = " xsd : string " / >
 * < xsd : choice minOccurs = " 2 " maxOccurs = " 3 " >
 * < xsd : element name = " start " type = " dateTypeFormatted " / >
 * < xsd : element name = " end " type = " dateTypeFormatted " / >
 * < xsd : element name = " duration " type = " duration " / >
 * < / xsd : choice >
 * < xsd : element name = " resolution " type = " duration " minOccurs = " 0 " / >
 * < / xsd : sequence >
 * < / xsd : complexType >
 * < ! - - may be a dateType or have a format attribute - - >
 * < xsd : complexType name = " dateTypeFormatted " >
 * < xsd : simpleContent >
 * < xsd : extension base = " dateType " >
 * < xsd : attribute name = " format " type = " xsd : string " / >
 * < ! - - follow java . text . SimpleDateFormat - - >
 * < xsd : attribute name = " type " type = " dateEnumTypes " / >
 * < / xsd : extension >
 * < / xsd : simpleContent >
 * < / xsd : complexType >
 * < ! - - may be a built in date or dateTIme , or a udunit encoded string - - >
 * < xsd : simpleType name = " dateType " >
 * < xsd : union memberTypes = " xsd : date xsd : dateTime udunitDate " >
 * < xsd : simpleType >
 * < xsd : restriction base = " xsd : token " >
 * < xsd : enumeration value = " present " / >
 * < / xsd : restriction >
 * < / xsd : simpleType >
 * < / xsd : union >
 * < / xsd : simpleType >
 * < xsd : simpleType name = " udunitDate " >
 * < xsd : restriction base = " xsd : string " >
 * < xsd : annotation >
 * < xsd : documentation > Must conform to complete udunits date string , eg " 20 days since 1991-01-01 " < / xsd : documentation >
 * < / xsd : annotation >
 * < / xsd : restriction >
 * < / xsd : simpleType >
 * < xsd : simpleType name = " duration " >
 * < xsd : union memberTypes = " xsd : duration udunitDuration " / >
 * < / xsd : simpleType >
 * < xsd : simpleType name = " udunitDuration " >
 * < xsd : restriction base = " xsd : string " >
 * < xsd : annotation >
 * < xsd : documentation > Must conform to udunits time duration , eg " 20.1 hours " < / xsd : documentation >
 * < / xsd : annotation >
 * < / xsd : restriction >
 * < / xsd : simpleType > */
protected DateRange readTimeCoverage ( Element tElem ) { } }

implementation: if ( tElem == null ) { return null ; } Calendar calendar = readCalendar ( tElem . getAttributeValue ( "calendar" ) ) ; DateType start = readDate ( tElem . getChild ( "start" , Catalog . defNS ) , calendar ) ; DateType end = readDate ( tElem . getChild ( "end" , Catalog . defNS ) , calendar ) ; TimeDuration duration = readDuration ( tElem . getChild ( "duration" , Catalog . defNS ) ) ; TimeDuration resolution = readDuration ( tElem . getChild ( "resolution" , Catalog . defNS ) ) ; try { return new DateRange ( start , end , duration , resolution ) ; } catch ( java . lang . IllegalArgumentException e ) { errlog . format ( " ** warning: TimeCoverage error ='%s'%n" , e . getMessage ( ) ) ; logger . debug ( " ** warning: TimeCoverage error ='{}'" , e . getMessage ( ) ) ; return null ; }


signature:
public class CatalogBuilder { /** * < xsd : element name = " variables " >
 * < xsd : complexType >
 * < xsd : choice >
 * < xsd : element ref = " variable " minOccurs = " 0 " maxOccurs = " unbounded " / >
 * < xsd : element ref = " variableMap " minOccurs = " 0 " / >
 * < / xsd : choice >
 * < xsd : attribute name = " vocabulary " type = " variableNameVocabulary " use = " optional " / >
 * < xsd : attributeGroup ref = " XLink " / >
 * < / xsd : complexType >
 * < / xsd : element >
 * < xsd : element name = " variable " >
 * < xsd : complexType mixed = " true " >
 * < xsd : attribute name = " name " type = " xsd : string " use = " required " / >
 * < xsd : attribute name = " vocabulary _ name " type = " xsd : string " use = " optional " / >
 * < xsd : attribute name = " vocabulary _ id " type = " xsd : string " use = " optional " / >
 * < xsd : attribute name = " units " type = " xsd : string " / >
 * < / xsd : complexType >
 * < / xsd : element >
 * < xsd : element name = " variableMap " >
 * < xsd : complexType >
 * < xsd : attributeGroup ref = " XLink " / >
 * < / xsd : complexType >
 * < / xsd : element >
 * < xsd : simpleType name = " variableNameVocabulary " >
 * < xsd : union memberTypes = " xsd : token " >
 * < xsd : simpleType >
 * < xsd : restriction base = " xsd : token " >
 * < xsd : enumeration value = " CF - 1.0 " / >
 * < xsd : enumeration value = " DIF " / >
 * < xsd : enumeration value = " GRIB - 1 " / >
 * < xsd : enumeration value = " GRIB - 2 " / >
 * < / xsd : restriction >
 * < / xsd : simpleType >
 * < / xsd : union >
 * < / xsd : simpleType > */
protected ThreddsMetadata . VariableGroup readVariables ( Element varsElem ) { } }

implementation:
if ( varsElem == null ) { return null ; } String vocab = varsElem . getAttributeValue ( "vocabulary" ) ; ThreddsMetadata . UriResolved variableVocabUri = readUri ( varsElem , "Variables vocabulary" ) ; java . util . List < Element > vlist = varsElem . getChildren ( "variable" , Catalog . defNS ) ; ThreddsMetadata . UriResolved variableMap = readUri ( varsElem . getChild ( "variableMap" , Catalog . defNS ) , "Variables Map" ) ; if ( ( variableMap != null ) && vlist . size ( ) > 0 ) { // cant do both
errlog . format ( " ** Catalog error: cant have variableMap and variable in same element '%s'%n" , varsElem ) ; } List < ThreddsMetadata . Variable > variables = new ArrayList < > ( ) ; for ( Element e : vlist ) { variables . add ( readVariable ( e ) ) ; } return new ThreddsMetadata . VariableGroup ( vocab , variableVocabUri , variableMap , variables ) ;


signature:
public class TimeDuration { /** * A time span as defined in the W3C XML Schema 1.0 specification :
 * " PnYnMnDTnHnMnS , where nY represents the number of years , nM the number of months , nD the number of days ,
 * ' T ' is the date / time separator , nH the number of hours , nM the number of minutes and nS the number of seconds .
 * The number of seconds can include decimal digits to arbitrary precision . "
 * @ param text parse this text , format PnYnMnDTnHnMnS
 * @ return TimeDuration
 * @ throws java . text . ParseException when text is misformed */
static public TimeDuration parseW3CDuration ( String text ) throws java . text . ParseException { } }

implementation:
TimeDuration td = new TimeDuration ( ) ; text = ( text == null ) ? "" : text . trim ( ) ; td . text = text ; try { DatatypeFactory factory = DatatypeFactory . newInstance ( ) ; Duration d = factory . newDuration ( text ) ; // long secs = d . getTimeInMillis ( new Date ( ) ) / 1000;
Calendar c = Calendar . getInstance ( ) ; c . set ( 1900 , 0 , 1 , 0 , 0 , 0 ) ; long secs = d . getTimeInMillis ( c . getTime ( ) ) / 1000 ; td . timeUnit = new TimeUnit ( secs + " secs" ) ; } catch ( Exception e ) { throw new java . text . ParseException ( e . getMessage ( ) , 0 ) ; } return td ;


signature:
public class TimeDuration { /** * test */
private static void doDuration ( String s ) { } }

implementation: try { System . out . println ( "start = (" + s + ")" ) ; TimeDuration d = new TimeDuration ( s ) ; System . out . println ( "duration = (" + d . toString ( ) + ")" ) ; } catch ( java . text . ParseException e ) { e . printStackTrace ( ) ; }


signature:
public class NcStreamWriterChannel { /** * / * public long sendData ( WritableByteChannel wbc , StructureData sdata ) throws IOException {
 * long size = 0;
 * ByteBuffer bb = IospHelper . copyToByteBuffer ( sdata ) ;
 * byte [ ] datab = bb . array ( ) ;
 * size + = writeBytes ( wbc , NcStream . MAGIC _ DATA ) ; / / magic
 * size + = NcStream . writeVInt ( wbc , datab . length ) ; / / data len
 * size + = writeBytes ( wbc , datab ) ; / / data
 * return size ; */
private int writeBytes ( WritableByteChannel wbc , byte [ ] b ) throws IOException { } }

implementation: return wbc . write ( ByteBuffer . wrap ( b ) ) ;


signature:
public class Grib1ParamTableReader { /** * Get the parameter with id . If not found , look in default table .
 * @ param id the parameter number
 * @ return the Grib1Parameter , or null if not found */
public Grib1Parameter getParameter ( int id ) { } }

implementation: if ( parameters == null ) { parameters = readParameterTable ( ) ; } return parameters . get ( id ) ;


signature:
public class Grib1ParamTableReader { /** * Get the parameter with id , but dont look in default table .
 * @ param id the parameter number
 * @ return the Grib1Parameter , or null if not found */
public Grib1Parameter getLocalParameter ( int id ) { } }


signature:
public class Grib1ParamTableReader { /** * reading */
private synchronized Map < Integer , Grib1Parameter > readParameterTable ( ) { } }

implementation:
if ( path == null ) { throw new IllegalStateException ( name ) ; } try { if ( name . startsWith ( "table_2_" ) || name . startsWith ( "local_table_2_" ) ) { return readParameterTableEcmwf ( ) ; // ecmwf
} else if ( name . startsWith ( "US058" ) ) { return readParameterTableXml ( new FnmocParser ( ) ) ; // FNMOC
} else if ( name . endsWith ( ".tab" ) ) { return readParameterTableTab ( ) ; // wgrib format
} else if ( name . endsWith ( ".wrf" ) ) { return readParameterTableSplit ( "\\|" , new int [ ] { 0 , 3 , 1 , 2 } ) ; // WRF AMPS
} else if ( name . endsWith ( ".h" ) ) { return readParameterTableNcl ( ) ; // NCL
} else if ( name . endsWith ( ".dss" ) ) { return readParameterTableSplit ( "\t" , new int [ ] { 0 , - 1 , 1 , 2 } ) ; // NCAR DSS
} else if ( name . endsWith ( ".xml" ) ) { return readParameterTableXml ( new DssParser ( Namespace . NO_NAMESPACE ) ) ; // NCAR DSS XML format
} else if ( name . startsWith ( "2.98" ) ) { return readParameterTableEcmwfEcCodes ( ) ; // ecmwf from ecCodes package
} else { throw new RuntimeException ( "Grib1ParamTableReader: Dont know how to read " + name + " file=" + path ) ; } } catch ( IOException ioError ) { logger . warn ( "An error occurred in Grib1ParamTable while trying to open the parameter table {}:{}" , path , ioError . getMessage ( ) ) ; throw new RuntimeException ( ioError ) ; }