signature:
public class MAMath { /** * Add elements of two arrays together , allocating the result array .
 * The result type and the operation type are taken from the type of a .
 * @ param a add values from here
 * @ param b add values from here
 * @ return result = a + b
 * @ throws IllegalArgumentException a and b are not conformable
 * @ throws UnsupportedOperationException dont support this data type yet */
public static Array add ( Array a , Array b ) throws IllegalArgumentException { } }

implementation: Array result = Array . factory ( a . getDataType ( ) , a . getShape ( ) ) ; if ( a . getElementType ( ) == double . class ) { addDouble ( result , a , b ) ; } else throw new UnsupportedOperationException ( ) ; return result ;


signature:
public class MAMath { /** * Add elements of two arrays together as doubles , place sum in the result array .
 * The values from the arrays a and b are converted to double ( if needed ) ,
 * and the sum is converted to the type of result ( if needed ) .
 * @ param result result array
 * @ param a operand
 * @ param b operand
 * @ throws IllegalArgumentException a , b , and result are not conformable */
public static void addDouble ( Array result , Array a , Array b ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( result , a ) || ! conformable ( a , b ) ) throw new IllegalArgumentException ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterB = b . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setDoubleNext ( iterA . getDoubleNext ( ) + iterB . getDoubleNext ( ) ) ;


signature:
public class MAMath { /** * Check that two arrays are conformable .
 * @ param a operand
 * @ param b operand
 * @ return true if conformable */
public static boolean conformable ( Array a , Array b ) { } }

implementation: return conformable ( a . getShape ( ) , b . getShape ( ) ) ;


signature:
public class MAMath { /** * Check that two array shapes are conformable .
 * The shapes must match exactly , except that dimensions of length 1 are ignored .
 * @ param shapeA shape of array 1
 * @ param shapeB shape of array 2
 * @ return true if conformable */
public static boolean conformable ( int [ ] shapeA , int [ ] shapeB ) { } }

implementation:
if ( reducedRank ( shapeA ) != reducedRank ( shapeB ) ) return false ; int rankB = shapeB . length ; int dimB = 0 ; for ( int aShapeA : shapeA ) { // System . out . println ( dimA + " " + dimB ) ;
// skip length 1 dimensions
if ( aShapeA == 1 ) continue ; while ( dimB < rankB ) if ( shapeB [ dimB ] == 1 ) dimB ++ ; else break ; // test same shape ( NB dimB cant be > rankB due to first test )
if ( aShapeA != shapeB [ dimB ] ) return false ; dimB ++ ; } return true ;


signature:
public class MAMath { /** * Convert original array to desired type
 * @ param org original array
 * @ param wantType desired type
 * @ return converted data of desired type , or original array if it is already */
public static Array convert ( Array org , DataType wantType ) { } }

implementation: if ( org == null ) return null ; Class wantClass = wantType . getPrimitiveClassType ( ) ; if ( org . getElementType ( ) . equals ( wantClass ) ) return org ; Array result = Array . factory ( wantType , org . getShape ( ) ) ; copy ( wantType , org . getIndexIterator ( ) , result . getIndexIterator ( ) ) ; return result ;


signature:
public class MAMath { /** * Copy using iterators . Will copy until ! from . hasNext ( ) .
 * @ param dataType use this operation type ( eg DataType . DOUBLE uses getDoubleNext ( ) )
 * @ param from copy from here
 * @ param to copy to here
 * @ throws IllegalArgumentException a and b are not conformable
 * @ throws UnsupportedOperationException dont support this data type */
public static void copy ( DataType dataType , IndexIterator from , IndexIterator to ) throws IllegalArgumentException { } }

implementation: if ( dataType == DataType . DOUBLE ) { while ( from . hasNext ( ) ) to . setDoubleNext ( from . getDoubleNext ( ) ) ; } else if ( dataType == DataType . FLOAT ) { while ( from . hasNext ( ) ) to . setFloatNext ( from . getFloatNext ( ) ) ; } else if ( dataType . getPrimitiveClassType ( ) == long . class ) { while ( from . hasNext ( ) ) to . setLongNext ( from . getLongNext ( ) ) ; } else if ( dataType . getPrimitiveClassType ( ) == int . class ) { while ( from . hasNext ( ) ) to . setIntNext ( from . getIntNext ( ) ) ; } else if ( dataType . getPrimitiveClassType ( ) == short . class ) { while ( from . hasNext ( ) ) to . setShortNext ( from . getShortNext ( ) ) ; } else if ( dataType == DataType . CHAR ) { while ( from . hasNext ( ) ) to . setCharNext ( from . getCharNext ( ) ) ; } else if ( dataType . getPrimitiveClassType ( ) == byte . class ) { while ( from . hasNext ( ) ) to . setByteNext ( from . getByteNext ( ) ) ; } else if ( dataType == DataType . BOOLEAN ) { while ( from . hasNext ( ) ) to . setBooleanNext ( from . getBooleanNext ( ) ) ; } else { while ( from . hasNext ( ) ) to . setObjectNext ( from . getObjectNext ( ) ) ; }


signature:
public class MAMath { /** * Copy array a to array result , the result array will be in canonical order
 * The operation type is taken from the type of a .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and b are not conformable
 * @ throws UnsupportedOperationException dont support this data type yet */
public static void copy ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: Class classType = a . getElementType ( ) ; if ( classType == double . class ) { copyDouble ( result , a ) ; } else if ( classType == float . class ) { copyFloat ( result , a ) ; } else if ( classType == long . class ) { copyLong ( result , a ) ; } else if ( classType == int . class ) { copyInt ( result , a ) ; } else if ( classType == short . class ) { copyShort ( result , a ) ; } else if ( classType == char . class ) { copyChar ( result , a ) ; } else if ( classType == byte . class ) { copyByte ( result , a ) ; } else if ( classType == boolean . class ) { copyBoolean ( result , a ) ; } else copyObject ( result , a ) ;


signature:
public class MAMath { /** * copy array a to array result as doubles
 * The values from the arrays a are converted to double ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyDouble ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setDoubleNext ( iterA . getDoubleNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as floats
 * The values from the arrays a are converted to float ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyFloat ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setFloatNext ( iterA . getFloatNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as longs
 * The values from the array a are converted to long ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyLong ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setLongNext ( iterA . getLongNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as integers
 * The values from the arrays a are converted to integer ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyInt ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setIntNext ( iterA . getIntNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as shorts
 * The values from the array a are converted to short ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyShort ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setShortNext ( iterA . getShortNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as char
 * The values from the array a are converted to char ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyChar ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setCharNext ( iterA . getCharNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as bytes
 * The values from the array a are converted to byte ( if needed ) ,
 * and then converted to the type of result ( if needed ) .
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyByte ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setByteNext ( iterA . getByteNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as bytes
 * The array a and result must be type boolean
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyBoolean ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) iterR . setBooleanNext ( iterA . getBooleanNext ( ) ) ;


signature:
public class MAMath { /** * copy array a to array result as an Object
 * The array a and result must be type object
 * @ param result copy to here
 * @ param a copy from here
 * @ throws IllegalArgumentException a and result are not conformable */
public static void copyObject ( Array result , Array a ) throws IllegalArgumentException { } }

implementation: if ( ! conformable ( a , result ) ) throw new IllegalArgumentException ( "copy arrays are not conformable" ) ; IndexIterator iterA = a . getIndexIterator ( ) ; IndexIterator iterR = result . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) { iterR . setObjectNext ( iterA . getObjectNext ( ) ) ; }


signature:
public class MAMath { /** * Find min and max value in this array , getting values as doubles . Skip Double . NaN .
 * @ param a the array .
 * @ return MinMax */
public static MAMath . MinMax getMinMax ( Array a ) { } }

implementation: IndexIterator iter = a . getIndexIterator ( ) ; double max = - Double . MAX_VALUE ; double min = Double . MAX_VALUE ; while ( iter . hasNext ( ) ) { double val = iter . getDoubleNext ( ) ; if ( Double . isNaN ( val ) ) continue ; if ( val > max ) max = val ; if ( val < min ) min = val ; } return new MinMax ( min , max ) ;


signature:
public class MAMath { /** * Set all the elements of this array to the given double value .
 * The value is converted to the element type of the array , if needed .
 * @ param result change this Array
 * @ param val set all elements to this value */
public static void setDouble ( Array result , double val ) { } }

implementation: IndexIterator iter = result . getIndexIterator ( ) ; while ( iter . hasNext ( ) ) { iter . setDoubleNext ( val ) ; }


signature:
public class MAMath { /** * sum all of the elements of array a as doubles .
 * The values from the array a are converted to double ( if needed ) .
 * @ param a read values from this Array
 * @ return sum of elements */
public static double sumDouble ( Array a ) { } }

implementation: double sum = 0 ; IndexIterator iterA = a . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) { sum += iterA . getDoubleNext ( ) ; } return sum ;


signature:
public class MAMath { /** * sum all of the elements of array a as doubles .
 * The values from the array a are converted to double ( if needed ) .
 * @ param a read values from this Array
 * @ param missingValue skip values equal to this , or which are NaNs
 * @ return sum of elements */
public static double sumDoubleSkipMissingData ( Array a , double missingValue ) { } }

implementation: double sum = 0 ; IndexIterator iterA = a . getIndexIterator ( ) ; while ( iterA . hasNext ( ) ) { double val = iterA . getDoubleNext ( ) ; if ( ( val == missingValue ) || Double . isNaN ( val ) ) continue ; sum += val ; } return sum ;


signature:
public class MAMath { /** * Calculate the scale / offset for an array of numbers .
 * < pre >
 * If signed :
 * then
 * max value unpacked = 2 ^ ( n - 1 ) - 1 packed
 * min value unpacked = - ( 2 ^ ( n - 1 ) - 1 ) packed
 * note that - 2 ^ ( n - 1 ) is unused , and a good place to map missing values
 * by solving 2 eq in 2 unknowns , we get :
 * scale = ( max - min ) / ( 2 ^ n - 2)
 * offset = ( max + min ) / 2
 * If unsigned then
 * max value unpacked = 2 ^ n - 1 packed
 * min value unpacked = 0 packed
 * and :
 * scale = ( max - min ) / ( 2 ^ n - 1)
 * offset = min
 * One could modify this to allow a holder for missing values .
 * < / pre >
 * @ param a array to convert ( not changed )
 * @ param missingValue skip these
 * @ param nbits map into this many bits
 * @ return ScaleOffset , calculated as above . */
public static MAMath . ScaleOffset calcScaleOffsetSkipMissingData ( Array a , double missingValue , int nbits ) { } }

implementation: MAMath . MinMax minmax = getMinMaxSkipMissingData ( a , missingValue ) ; if ( a . isUnsigned ( ) ) { long size = ( 1L << nbits ) - 1 ; double offset = minmax . min ; double scale = ( minmax . max - minmax . min ) / size ; return new ScaleOffset ( scale , offset ) ; } else { long size = ( 1L << nbits ) - 2 ; double offset = ( minmax . max + minmax . min ) / 2 ; double scale = ( minmax . max - minmax . min ) / size ; return new ScaleOffset ( scale , offset ) ; }


signature:
public class MAMath { /** * Returns true if the specified arrays have the same size , signedness , and < b > approximately < / b > equal corresponding
 * elements . { @ code float } elements must be within { @ link Misc # defaultMaxRelativeDiffFloat } of each other , as
 * determined by { @ link Misc # nearlyEquals ( double , double , double ) } . Similarly , { @ code double } elements must be within
 * { @ link Misc # defaultMaxRelativeDiffDouble } of each other .
 * { @ link # equals ( Array , Array ) } is an alternative to this method that requires that corresponding elements be
 * < b > exactly < / b > equal . It is suitable for use in { @ link Object # equals } implementations , whereas this method isn ' t .
 * @ param data1 one array to be tested for equality .
 * @ param data2 the other array to be tested for equality .
 * @ return true if the specified arrays have the same size , signedness , and approximately equal corresponding elems . */
public static boolean nearlyEquals ( Array data1 , Array data2 ) { } }

implementation:
if ( data1 == data2 ) { // Covers case when both are null .
return true ; } else if ( data1 == null || data2 == null ) { return false ; } if ( data1 . getSize ( ) != data2 . getSize ( ) ) return false ; if ( data1 . isUnsigned ( ) != data2 . isUnsigned ( ) ) return false ; DataType dt = DataType . getType ( data1 ) ; IndexIterator iter1 = data1 . getIndexIterator ( ) ; IndexIterator iter2 = data2 . getIndexIterator ( ) ; if ( dt == DataType . DOUBLE ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { double v1 = iter1 . getDoubleNext ( ) ; double v2 = iter2 . getDoubleNext ( ) ; if ( ! Misc . nearlyEquals ( v1 , v2 , Misc . defaultMaxRelativeDiffDouble ) ) return false ; } } else if ( dt == DataType . FLOAT ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { float v1 = iter1 . getFloatNext ( ) ; float v2 = iter2 . getFloatNext ( ) ; if ( ! Misc . nearlyEquals ( v1 , v2 , Misc . defaultMaxRelativeDiffFloat ) ) return false ; } } else if ( dt . getPrimitiveClassType ( ) == int . class ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { int v1 = iter1 . getIntNext ( ) ; int v2 = iter2 . getIntNext ( ) ; if ( v1 != v2 ) return false ; } } else if ( dt . getPrimitiveClassType ( ) == byte . class ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { short v1 = iter1 . getShortNext ( ) ; short v2 = iter2 . getShortNext ( ) ; if ( v1 != v2 ) return false ; } } else if ( dt . getPrimitiveClassType ( ) == short . class ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { byte v1 = iter1 . getByteNext ( ) ; byte v2 = iter2 . getByteNext ( ) ; if ( v1 != v2 ) return false ; } } else if ( dt . getPrimitiveClassType ( ) == long . class ) { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { long v1 = iter1 . getLongNext ( ) ; long v2 = iter2 . getLongNext ( ) ; if ( v1 != v2 ) return false ; } } else { while ( iter1 . hasNext ( ) && iter2 . hasNext ( ) ) { if ( ! Objects . equals ( iter1 . next ( ) , iter2 . next ( ) ) ) { return false ; } } } return true ;


signature:
public class GridCS { /** * @ Override
 * public List < CalendarDate > getCalendarDates ( ) {
 * if ( getTimeAxis ( ) ! = null )
 * return getTimeAxis ( ) . getCalendarDates ( ) ;
 * else if ( getRunTimeAxis ( ) ! = null )
 * return getRunTimeAxis ( ) . getCalendarDates ( ) ;
 * else
 * return new ArrayList < > ( ) ; */
@ Override public CalendarDateRange getCalendarDateRange ( ) { } }

implementation: if ( getTimeAxis ( ) != null ) return getTimeAxis ( ) . getCalendarDateRange ( ) ; else if ( getRunTimeAxis ( ) != null ) return getRunTimeAxis ( ) . getCalendarDateRange ( ) ; else return null ;


signature:
public class ConfigCatalog { /** * turn ConfigCatalog into a mutable CatalogBuilder so we can mutate */
public CatalogBuilder makeCatalogBuilder ( ) { } }

implementation: CatalogBuilder builder = new CatalogBuilder ( this ) ; for ( Dataset ds : getDatasetsLocal ( ) ) { builder . addDataset ( makeDatasetBuilder ( null , ds ) ) ; } return builder ;


signature:
public class DAS { /** * Returns the < code > AttributeTable < / code > with the given name .
 * @ param name the name of the < code > AttributeTable < / code > to return .
 * @ return the < code > AttributeTable < / code > with the specified name , or null
 * if there is no matching < code > AttributeTable < / code > .
 * @ throws NoSuchAttributeException There is no AttributeTable with the passed name .
 * @ see AttributeTable */
public final AttributeTable getAttributeTable ( String name ) throws NoSuchAttributeException { } }

implementation: AttributeTable at = null ; Attribute a = getAttribute ( name ) ; if ( a != null ) { if ( a . isContainer ( ) ) { at = a . getContainer ( ) ; } } return ( at ) ;


signature:
public class DAS { /** * Returns the < code > AttributeTable < / code > with the given name .
 * @ param name the name of the < code > AttributeTable < / code > to return .
 * @ return the < code > AttributeTable < / code > with the specified name , or null
 * if there is no matching < code > AttributeTable < / code > .
 * @ see AttributeTable */
public final AttributeTable getAttributeTableN ( String name ) { } }

implementation: AttributeTable at = null ; Attribute a = getAttribute ( name ) ; if ( a != null ) { if ( a . isContainer ( ) ) { at = a . getContainerN ( ) ; } } return ( at ) ;


signature:
public class DAS { /** * This method searchs through the < code > DAS < / code >
 * for Alias members . When an Alias is found the method attempts to
 * resolve it to a specific Attribute .
 * This method is invoked by < code > parse ( InputStream is ) < / code > , and is
 * used to search for Aliases in AttributeTables found in the DAS .
 * If you are building a DAS from it ' s API it is important to call
 * this method prior to returning said DAS to an application . If
 * this call is not made , Aliases will not work correctly .
 * @ see Alias
 * @ see DDS # resolveAliases ( ) */
public void resolveAliases ( ) throws MalformedAliasException , UnresolvedAliasException , NoSuchAttributeException { } }

implementation:
resolveAliases ( this ) ; // Enforce the rule that Aliases at the highest level of the DAS
// must point to a container ( AttributeTable )
Enumeration e = getNames ( ) ; while ( e . hasMoreElements ( ) ) { String aName = ( String ) e . nextElement ( ) ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "DAS.resolveAliases() - aName: " + aName ) ; } Attribute at = getAttribute ( aName ) ; if ( at == null || ! at . isContainer ( ) ) { throw new MalformedAliasException ( "Aliases at the top-level of a DAS MUST reference a container (AttributeTable), not a simple Attribute" ) ; } }


signature:
public class DAS { /** * This method recursively searchs through the passed < code > AttributeTable < / code > parameter
 * at for Alias members . When an Alias is found the method attempts to
 * resolve it to a specific Attribute .
 * This method gets called is invoked by < code > reolveAliases ( BaseType bt ) < / code > , and is
 * used to search for Aliases in AttributeTables found in a BaseTypes Attributes .
 * This method manipulates the global variable < code > currentBT < / code > .
 * @ param at The < code > AttributeTable < / code > in which to search for and resolve Alias members */
private void resolveAliases ( AttributeTable at ) throws MalformedAliasException , UnresolvedAliasException , NoSuchAttributeException { } }

implementation:
// Cache the current ( parent ) Attribute table . This value is
// null if this method is called from parse ( ) ;
AttributeTable cacheAT = currentAT ; try { // Set the current AttributeTable to the one that we are searching .
currentAT = at ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "DAS.resolveAliases(at=" + at + ")" ) ; } // getall of the Attributes from the table .
Enumeration aNames = at . getNames ( ) ; while ( aNames . hasMoreElements ( ) ) { String aName = ( String ) aNames . nextElement ( ) ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "DAS.resolveAliases(at=" + at + ") - aName: " + aName ) ; } opendap . dap . Attribute thisA = currentAT . getAttribute ( aName ) ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "thisA.getClass().getName(): " + thisA . getClass ( ) . getName ( ) ) ; } if ( thisA . isAlias ( ) ) { // Is Alias ? Resolve it !
resolveAlias ( ( Alias ) thisA ) ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "Resolved Alias: '" + thisA . getEncodedName ( ) + "'\n" ) ; } } else if ( thisA . isContainer ( ) ) { // Is AttributeTable ( container ) ? Search it !
resolveAliases ( thisA . getContainer ( ) ) ; } } } finally { // Restore the previous currentAT state .
currentAT = cacheAT ; }


signature:
public class DAS { /** * This method attempts to resolve the past Alias to a specific Attribute in the DDS .
 * It does this by :
 * < ul >
 * < li > 1 ) Tokenizing the Alias ' s variable and attribute fields ( see < code > Alias < / code > ) < / li >
 * < li > 2 ) Evaluating the tokenized fields to determine if the Alias is defined in terms
 * of a relative or absolute path < / li >
 * < li > 3 ) Searching the DAS or the currentAT ( depending on results
 * of 2 ) for the target Attribute < / li >
 * < li > 4 ) Setting the Aliases intrnal reference to it ' s Attribute
 * < / ul >
 * If an Attribute matching the definition of the Alias cannot be located ,
 * an Exception is thrown
 * @ param alias The < code > Alias < / code > which needs to be resolved */
private void resolveAlias ( Alias alias ) throws MalformedAliasException , UnresolvedAliasException { } }

implementation:
// Get the crucial stuff out of the Alias
String name = alias . getClearName ( ) ; String attribute = alias . getAliasedToAttributeFieldAsClearString ( ) ; // Get ready !
Enumeration e = null ; currentAlias = alias ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "\n\nFound: Alias " + name + "  " + attribute ) ; } // Let ' s go
// see if we can find an Attribute within that DAS that matches the attribute field
// in the Alias declartion .
// The Attribute field MAY NOT be empty .
if ( attribute . equals ( "" ) ) { throw new MalformedAliasException ( "The attribute 'attribute' in the Alias " + "element must have a value other than an empty string." ) ; } if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "Attribute: `" + attribute + "'" ) ; } // Tokenize the attribute field .
Vector aNames = opendap . dap . DDS . tokenizeAliasField ( attribute ) ; if ( Debug . isSet ( "DAS" ) ) { DAPNode . log . debug ( "Attribute name tokenized to " + aNames . size ( ) + " elements" ) ; e = aNames . elements ( ) ; while ( e . hasMoreElements ( ) ) { String aname = ( String ) e . nextElement ( ) ; DAPNode . log . debug ( "name: " + aname ) ; } } opendap . dap . Attribute targetAT = null ; // Absolute paths for attributes names must start with the dot character .
boolean isAbsolutePath = aNames . get ( 0 ) . equals ( "." ) ; if ( isAbsolutePath ) { // Is it an absolute path ?
if ( aNames . size ( ) == 1 ) { throw new MalformedAliasException ( "Aliases must reference an Attribute. " + "An attribute field of dot (.) references the entire " + "DAS, which is not allowed." ) ; } else { // Dump the dot from the vector of tokens and go try to find
// the Attribute in the DAS .
aNames . remove ( 0 ) ; targetAT = getAliasAttribute ( this , aNames ) ; } } else { throw new MalformedAliasException ( "In the Alias '" + name + "'" + " the attribute 'attribute' does not begin with the character dot (.). " + "The 'attribute' field must always be an absoulute path name from the " + "top level of the dataset, and thus must always begin with the dot (.) character." ) ; } alias . setMyAttribute ( targetAT ) ;


signature:
public class DAS { /** * This method executes a ( recursive ) search of the < code > AttributeTable < / code >
 * parameter < b > at < / b > for an < code > Attribute < / code > whose name resolves to
 * the vector of names contained in the < code > Vector < / code > parameter
 * < b > aNames < / b > . An Attribute is considered a match if each of it ' s node
 * names in the hierarchy of AttributeTables contained in the
 * one passed as parameter < b > at < / b > matches ( equals ) the corresponding name
 * in the Vector < b > aNames < / b > .
 * @ param att The < code > AttributeTable < / code > to search
 * @ param aNames The < code > Vector < / code > of names to match to the nodes of < b > at < / b > */
private opendap . dap . Attribute getAliasAttribute ( AttributeTable att , Vector aNames ) throws MalformedAliasException , UnresolvedAliasException { } }

implementation:
// Get the first node name form the vector .
String aName = ( String ) aNames . get ( 0 ) ; // Get the list of child nodes from the AttributeTable
Enumeration e = att . getNames ( ) ; while ( e . hasMoreElements ( ) ) { // Get an Attribute
String atName = ( String ) e . nextElement ( ) ; opendap . dap . Attribute a = att . getAttribute ( atName ) ; // Get the Attributes name and Normalize it .
String normName = opendap . dap . DDS . normalize ( a . getEncodedName ( ) ) ; // Are they the same ?
if ( normName . equals ( aName ) ) { // Make sure this reference doesn ' t pass through an Alias .
if ( a . isAlias ( ) ) { throw new MalformedAliasException ( "Aliases may NOT point to other aliases" ) ; } // dump the name from the list of names .
aNames . remove ( 0 ) ; // Are there more ?
if ( aNames . size ( ) == 0 ) { // No ! We found it !
return ( a ) ; } else if ( a . isContainer ( ) ) { // Is this Attribute a container ( it better be )
try { // Recursively search for the rest of the name vector in the container .
return ( getAliasAttribute ( a . getContainer ( ) , aNames ) ) ; } catch ( NoSuchAttributeException nsae ) { throw new MalformedAliasException ( "Attribute " + a . getEncodedName ( ) + " is not an attribute container. (AttributeTable) " + " It may not contain the attribute: " + aName ) ; } } else { // Dead - end , through an exception !
throw new MalformedAliasException ( "Attribute " + a . getEncodedName ( ) + " is not an attribute container. (AttributeTable) " + " It may not contain the attribute: " + aName ) ; } } } // Nothing Matched , so this search failed .
throw new UnresolvedAliasException ( "The alias `" + currentAlias . getEncodedName ( ) + "` references the attribute: `" + aName + "` which cannot be found." ) ;


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

implementation: DAS das = ( DAS ) super . cloneDAG ( map ) ; return das ;


signature:
public class Grib1Gds { /** * Code table 6 – Data representation type
 * Code figure Meaning
 * 0 Latitude / longitude grid – equidistant cylindrical or Plate Carrée projection
 * 1 Mercator projection
 * 2 Gnomonic projection
 * 3 Lambert conformal , secant or tangent , conic or bi - polar , projection
 * 4 Gaussian latitude / longitude grid
 * 5 Polar stereographic projection
 * 6 Universal Transverse Mercator ( UTM ) projection
 * 7 Simple polyconic projection
 * 8 Albers equal - area , secant or tangent , conic or bi - polar , projection
 * 9 Miller ’ s cylindrical projection
 * 10 Rotated latitude / longitude grid
 * 11–12 Reserved
 * 13 Oblique Lambert conformal , secant or tangent , conic or bi - polar , projection
 * 14 Rotated Gaussian latitude / longitude grid
 * 15–19 Reserved
 * 20 Stretched latitude / longitude grid
 * 21–23 Reserved
 * 24 Stretched Gaussian latitude / longitude grid
 * 25–29 Reserved
 * 30 Stretched and rotated latitude / longitude grids
 * 31–33 Reserved
 * 34 Stretched and rotated Gaussian latitude / longitude grids
 * 35–49 Reserved
 * ^ 50 Spherical harmonic coefficients
 * 51–59 Reserved
 * 60 Rotated spherical harmonic coefficients
 * 61–69 Reserved
 * 70 Stretched spherical harmonics
 * 71–79 Reserved
 * 80 Stretched and rotated spherical harmonic coefficients
 * 81–89 Reserved
 * 90 Space view , perspective or orthographic
 * 91–191 Reserved
 * 192–254 Reserved for local use */
public static Grib1Gds factory ( int template , byte [ ] data ) { } }

implementation: switch ( template ) { case 0 : return new LatLon ( data , 0 ) ; case 1 : return new Mercator ( data , 1 ) ; case 3 : return new LambertConformal ( data , 3 ) ; case 4 : return new GaussianLatLon ( data , 4 ) ; case 5 : return new PolarStereographic ( data , 5 ) ; case 10 : return new RotatedLatLon ( data , 10 ) ; case 50 : return new SphericalHarmonicCoefficients ( data , 50 ) ; default : return new UnknownGds ( data , template ) ; }


signature:
public class Grib1Gds { /** * signed */
protected int getOctet3 ( int start ) { } }

implementation: return GribNumbers . int3 ( getOctet ( start ) , getOctet ( start + 1 ) , getOctet ( start + 2 ) ) ;


signature:
public class GetDirHandler { /** * Default handler for OPeNDAP directory requests . Returns an html document
 * with a list of all datasets on this server with links to their
 * DDS , DAS , Information , and HTML responses .
 * @ param rs The request state object for this client request .
 * @ see ReqState */
public void sendDIR ( ReqState rs ) throws opendap . dap . DAP2Exception , ParseException { } }

implementation:
if ( _Debug ) System . out . println ( "sendDIR request = " + rs . getRequest ( ) ) ; try { PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( rs . getResponse ( ) . getOutputStream ( ) , Util . UTF8 ) ) ; // ignore String ddxCacheDir = rs . getDDXCache ( rs . getRootPath ( ) ) ;
String ddsCacheDir = rs . getDDSCache ( rs . getRootPath ( ) ) ; String thisServer = rs . getRequest ( ) . getRequestURL ( ) . toString ( ) ; pw . println ( "" ) ; pw . println ( "" ) ; pw . println ( "<title>OPeNDAP Directory</title>" ) ; pw . println ( "<meta http-equiv=\"Content-Type\" content=\"text/html\">" ) ; pw . println ( "" ) ; pw . println ( "" ) ; pw . println ( "
OPeNDAP Directory for:
" ) ; pw . println ( "
" + thisServer + "
" ) ; // ignore printDIR ( pw , ddxCacheDir , " DDX " , thisServer ) ;
printDIR ( pw , ddsCacheDir , "DDS" , thisServer ) ; pw . println ( "
" ) ; pw . println ( "" ) ; pw . flush ( ) ; } catch ( FileNotFoundException fnfe ) { System . out . println ( "OUCH! FileNotFoundException: " + fnfe . getMessage ( ) ) ; fnfe . printStackTrace ( System . out ) ; } catch ( IOException ioe ) { System . out . println ( "OUCH! IOException: " + ioe . getMessage ( ) ) ; ioe . printStackTrace ( System . out ) ; }


signature:
public class ProjectionAdapter { /** * Create a ProjectionImpl from the projection
 * @ param proj projection
 * @ return a ProjectionImpl representing the projection */
static public ProjectionImpl factory ( Projection proj ) { } }

implementation: if ( proj instanceof ProjectionImpl ) { return ( ProjectionImpl ) proj ; } return new ProjectionAdapter ( proj ) ;


signature:
public class ProjectionAdapter { /** * Convert a LatLonPoint to projection coordinates
 * @ param latlon convert from these lat , lon coordinates
 * @ param result the object to write to
 * @ return the given result */
public ProjectionPoint latLonToProj ( LatLonPoint latlon , ProjectionPointImpl result ) { } }

implementation: return proj . latLonToProj ( latlon , result ) ;


signature:
public class ProjectionAdapter { /** * Convert projection coordinates to a LatLonPoint
 * Note : a new object is not created on each call for the return value .
 * @ param world convert from these projection coordinates
 * @ param result the object to write to
 * @ return LatLonPoint convert to these lat / lon coordinates */
public LatLonPoint projToLatLon ( ProjectionPoint world , LatLonPointImpl result ) { } }

implementation: return proj . projToLatLon ( world , result ) ;


signature: public class StationProfileCollectionImpl { @ Override public Iterator < StationProfileFeature > iterator ( ) { } }

implementation: try { PointFeatureCCIterator pfIterator = getNestedPointFeatureCollectionIterator ( ) ; return new NestedCollectionIteratorAdapter < > ( pfIterator ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; }


signature:
public class EscapeStrings { /** * Define the DEFINITIVE opendap identifier unescape function .
 * @ param id The identifier to unescape .
 * @ return The unescaped identifier . */
public static String unescapeDAPIdentifier ( String id ) { } }

implementation: String s ; try { s = unescapeString ( id ) ; } catch ( Exception e ) { s = null ; } return s ;


signature:
public class EscapeStrings { /** * Define the DEFINITIVE URL unescape function .
 * @ param s The string to unescape .
 * @ return The unescaped expression . */
public static String urlDecode ( String s ) { } }

implementation:
try { // s = unescapeString ( s , _ URIEscape , " " , false ) ;
s = URLDecoder . decode ( s , "UTF-8" ) ; } catch ( Exception e ) { s = null ; } return s ;


signature:
public class EscapeStrings { /** * Decode all of the parts of the url including query and fragment
 * @ param url the url to encode */
public static String unescapeURL ( String url ) { } }

implementation: String newurl ; newurl = urlDecode ( url ) ; return newurl ;


signature:
public class EscapeStrings { /** * backslash escape a string
 * @ param x escape this ; may be null
 * @ param reservedChars these chars get a backslash in front of them
 * @ return escaped string */
static public String backslashEscape ( String x , String reservedChars ) { } }

implementation:
if ( x == null ) { return null ; } else if ( reservedChars == null ) { return x ; } boolean ok = true ; for ( int pos = 0 ; pos < x . length ( ) ; pos ++ ) { char c = x . charAt ( pos ) ; if ( reservedChars . indexOf ( c ) >= 0 ) { ok = false ; break ; } } if ( ok ) return x ; // gotta do it
StringBuilder sb = new StringBuilder ( x ) ; for ( int pos = 0 ; pos < sb . length ( ) ; pos ++ ) { char c = sb . charAt ( pos ) ; if ( reservedChars . indexOf ( c ) < 0 ) { continue ; } sb . setCharAt ( pos , '\\' ) ; pos ++ ; sb . insert ( pos , c ) ; pos ++ ; } return sb . toString ( ) ;


signature:
public class EscapeStrings { /** * backslash unescape a string
 * @ param x unescape this
 * @ return string with \ c - > c */
static public String backslashUnescape ( String x ) { } }

implementation:
if ( ! x . contains ( "\\" ) ) return x ; // gotta do it
StringBuilder sb = new StringBuilder ( x . length ( ) ) ; for ( int pos = 0 ; pos < x . length ( ) ; pos ++ ) { char c = x . charAt ( pos ) ; if ( c == '\\' ) { c = x . charAt ( ++ pos ) ; // skip backslash , get next cha
} sb . append ( c ) ; } return sb . toString ( ) ;


signature:
public class EscapeStrings { /** * Tokenize an escaped name using " . " as delimiter , skipping " \ . "
 * @ param escapedName an escaped name
 * @ return list of tokens */
public static List < String > tokenizeEscapedName ( String escapedName ) { } }

implementation:
List < String > result = new ArrayList < > ( ) ; int pos = 0 ; int start = 0 ; while ( true ) { pos = escapedName . indexOf ( sep , pos + 1 ) ; if ( pos <= 0 ) break ; if ( ( pos > 0 ) && escapedName . charAt ( pos - 1 ) != '\\' ) { result . add ( escapedName . substring ( start , pos ) ) ; start = pos + 1 ; } } result . add ( escapedName . substring ( start , escapedName . length ( ) ) ) ; // remaining
return result ;


signature:
public class EscapeStrings { /** * Find first occurence of char c in escapedName , excluding escaped c .
 * @ param escapedName search in this string
 * @ param c for this char but not \ \ cha
 * @ return pos in string , or - 1 */
public static int indexOf ( String escapedName , char c ) { } }

implementation: int pos = 0 ; while ( true ) { pos = escapedName . indexOf ( c , pos + 1 ) ; if ( pos <= 0 ) return pos ; if ( ( pos > 0 ) && escapedName . charAt ( pos - 1 ) != '\\' ) return pos ; }


signature:
public class EscapeStrings { /** * Given a backslash escaped name ,
 * convert to a DAP escaped name
 * @ param bs the string to DAP encode ; may have backslash escapes
 * @ return escaped string */
public static String backslashToDAP ( String bs ) { } }

implementation:
StringBuilder buf = new StringBuilder ( ) ; int len = bs . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = bs . charAt ( i ) ; if ( i < ( len - 1 ) && c == '\\' ) { c = bs . charAt ( ++ i ) ; } if ( _allowableInDAP . indexOf ( c ) < 0 ) { buf . append ( _URIEscape ) ; // convert the char to hex
String ashex = Integer . toHexString ( ( int ) c ) ; if ( ashex . length ( ) < 2 ) buf . append ( '0' ) ; buf . append ( ashex ) ; } else buf . append ( c ) ; } return buf . toString ( ) ;


signature:
public class EscapeStrings { /** * Given a DAP ( attribute ) string , insert backslashes
 * before ' " ' and ' / ' characters . This code also escapes
 * control characters , although the spec does not call for it ;
 * make that code conditional . */
static public String backslashEscapeDapString ( String s ) { } }

implementation: StringBuilder buf = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int c = s . charAt ( i ) ; if ( true ) { if ( c < ' ' ) { switch ( c ) { case '\n' : case '\r' : case '\t' : case '\f' : buf . append ( ( char ) c ) ; break ; default : buf . append ( String . format ( "\\x%02x" , ( c & 0xff ) ) ) ; break ; } continue ; } } if ( c == '"' ) { buf . append ( "\\\"" ) ; } else if ( c == '\\' ) { buf . append ( "\\\\" ) ; } else buf . append ( ( char ) c ) ; } return buf . toString ( ) ;


signature:
public class EscapeStrings { /** * Given a CDM string , insert backslashes
 * before < toescape > characters . */
static public String backslashEscapeCDMString ( String s , String toescape ) { } }

implementation: if ( toescape == null || toescape . length ( ) == 0 ) return s ; if ( s == null || s . length ( ) == 0 ) return s ; StringBuilder buf = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int c = s . charAt ( i ) ; if ( toescape . indexOf ( c ) >= 0 ) { buf . append ( '\\' ) ; } buf . append ( ( char ) c ) ; } return buf . toString ( ) ;


signature:
public class Nc4Cursor { /** * 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 ( ) ; int rank = atomvar . getRank ( ) ; assert slices != null && ( ( rank == 0 && slices . size ( ) == 1 ) || ( slices . size ( ) == rank ) ) ; // Get VarNotes and TypeNotes
Notes n = ( ( Nc4DSP ) this . dsp ) . find ( this . template ) ; Object result = null ; long count = DapUtil . sliceProduct ( slices ) ; VarNotes vn = ( VarNotes ) n ; TypeNotes ti = vn . getBaseType ( ) ; if ( getContainer ( ) == null ) { if ( rank == 0 ) { // scalar
result = readAtomicScalar ( vn , ti ) ; } else { result = readAtomicVector ( vn , ti , count , slices ) ; } } else { // field of a structure instance or record
long elemsize = ( ( DapType ) ti . get ( ) ) . getSize ( ) ; assert ( this . container != null ) ; long trueoffset = computeTrueOffset ( this ) ; Nc4Pointer varmem = getMemory ( ) ; Nc4Pointer mem = varmem . share ( trueoffset , count * elemsize ) ; result = getatomicdata ( ti . getType ( ) , count , elemsize , mem ) ; } return result ;


signature:
public class Nc4Cursor { /** * Read a top - level scalar atomic variable
 * @ param vi
 * @ param ti
 * @ return
 * @ throws DapException */
protected Object readAtomicScalar ( VarNotes vi , TypeNotes ti ) throws DapException { } }

implementation:
DapVariable atomvar = ( DapVariable ) getTemplate ( ) ; // Get into memory
Nc4prototypes nc4 = ( ( Nc4DSP ) this . dsp ) . getJNI ( ) ; int ret ; DapType basetype = ti . getType ( ) ; Object result = null ; if ( basetype . isFixedSize ( ) ) { long memsize = ( ( DapType ) ti . get ( ) ) . getSize ( ) ; Nc4Pointer mem = Nc4Pointer . allocate ( memsize ) ; readcheck ( nc4 , ret = nc4 . nc_get_var ( vi . gid , vi . id , mem . p ) ) ; setMemory ( mem ) ; result = getatomicdata ( ti . getType ( ) , 1 , mem . size , mem ) ; } else if ( basetype . isStringType ( ) ) { String [ ] s = new String [ 1 ] ; readcheck ( nc4 , ret = nc4 . nc_get_var_string ( vi . gid , vi . id , s ) ) ; result = s ; } else if ( basetype . isOpaqueType ( ) ) { Nc4Pointer mem = Nc4Pointer . allocate ( ti . getSize ( ) ) ; readcheck ( nc4 , ret = nc4 . nc_get_var ( vi . gid , vi . id , mem . p ) ) ; setMemory ( mem ) ; ByteBuffer [ ] buf = new ByteBuffer [ 1 ] ; buf [ 0 ] = mem . p . getByteBuffer ( 0 , ti . getSize ( ) ) ; result = buf ; } else throw new DapException ( "Unexpected atomic type: " + basetype ) ; return result ;


signature:
public class Nc4Cursor { /** * Nc4Cursor Extensions */
public long getOffset ( ) { } }

implementation: DapVariable dv = ( DapVariable ) getTemplate ( ) ; Notes n = ( ( Nc4DSP ) this . dsp ) . find ( dv ) ; return n . getOffset ( ) ;


signature:
public class Nc4Cursor { /** * Utilities */
protected long getElementSize ( TypeNotes ti ) { } }

implementation: DapType type = ti . getType ( ) ; switch ( type . getTypeSort ( ) ) { case Structure : case Sequence : return ti . getSize ( ) ; case String : case URL : return Pointer . SIZE ; case Enum : return getElementSize ( ( TypeNotes ) ( ( Nc4DSP ) getDSP ( ) ) . find ( ti . enumbase , NoteSort . TYPE ) ) ; case Opaque : return ti . getSize ( ) ; default : return type . getSize ( ) ; }


signature:
public class Nc4Cursor { /** * Given a field ref , compute the true offset with respect to
 * it top - level containing structure / record
 * @ param f field cursor
 * @ return
 * @ throws DapException */
long computeTrueOffset ( Nc4Cursor f ) throws DapException { } }

implementation:
List < Nc4Cursor > path = getCursorPath ( f ) ; long totaloffset = 0 ; Nc4Cursor current ; // First element is presumed to be a structure ore record variable ,
// and that its memory covers only it ' s instance .
// Walk intermediate nodes
for ( int i = 1 ; i < ( path . size ( ) - 1 ) ; i ++ ) { current = path . get ( i ) ; DapVariable template = ( DapVariable ) current . getTemplate ( ) ; VarNotes vi = ( VarNotes ) ( ( Nc4DSP ) getDSP ( ) ) . find ( template ) ; long size = vi . getSize ( ) ; long offset = current . getOffset ( ) ; long pos = 0 ; switch ( current . getScheme ( ) ) { case SEQUENCE : case STRUCTURE : pos = current . getIndex ( ) . index ( ) ; break ; case RECORD : // readrecord will have set our memory to the start of the record
pos = 0 ; break ; default : throw new DapException ( "Illegal cursor type: " + current . getScheme ( ) ) ; } long delta = size * pos + offset ; totaloffset += delta ; } assert path . get ( path . size ( ) - 1 ) == f ; totaloffset += f . getOffset ( ) ; return totaloffset ;


signature:
public class Nc4Cursor { /** * Given a cursor , get a list of " containing " cursors
 * with the following constraints .
 * 1 . the first element in the path is a top - level variable .
 * 2 . the remaining elements are the enclosing compound variables
 * 3 . the last element is the incoming cursor .
 * @ param cursor
 * @ return */
static List < Nc4Cursor > getCursorPath ( Nc4Cursor cursor ) { } }

implementation:
List < Nc4Cursor > path = new ArrayList < > ( ) ; for ( ; ; ) { if ( ! cursor . getScheme ( ) . isCompoundArray ( ) ) // suppress
path . add ( 0 , cursor ) ; if ( cursor . getScheme ( ) == Scheme . SEQUENCE ) { // Stop here because the sequence has the vlen mem as its mem
break ; } Nc4Cursor next = ( Nc4Cursor ) cursor . getContainer ( ) ; if ( next == null ) { assert cursor . getTemplate ( ) . isTopLevel ( ) ; break ; } assert next . getTemplate ( ) . getSort ( ) == DapSort . VARIABLE ; cursor = next ; } return path ;


signature:
public class Nc4Cursor { /** * If the basetype is sequence ( = > isVlen ( ) ) ,
 * then return the type of the first field of this sequence .
 * Otherwise return null .
 * @ return the type of the first field */
public TypeNotes getVlenType ( DapVariable v ) { } }

implementation: DapType t = v . getBaseType ( ) ; if ( t . getSort ( ) != DapSort . SEQUENCE || ( ( DapSequence ) t ) . getFields ( ) . size ( ) != 1 ) throw new IllegalArgumentException ( t . getFQN ( ) ) ; DapSequence ds = ( DapSequence ) t ; DapVariable f0 = ds . getField ( 0 ) ; DapType f0type = f0 . getBaseType ( ) ; return ( TypeNotes ) ( ( Nc4DSP ) this . dsp ) . find ( f0type ) ;


signature:
public class CachingThreddsS3Client { /** * { @ inheritDoc }
 * WARNING : If the content at { @ code s3uri } was previously saved using this method , and the old file to which it was
 * saved is < b > not < / b > the same as { @ code file } , the object content will be copied to the new file and the old file
 * will be deleted . */
@ Override public File saveObjectToFile ( S3URI s3uri , File file ) throws IOException { } }

implementation:
Optional < File > cachedFile = objectFileCache . getIfPresent ( s3uri ) ; if ( cachedFile == null ) { logger . debug ( "Object cache MISS: '%s'" , s3uri ) ; // Do download below .
} else { logger . debug ( "Object cache hit: '%s'" , s3uri ) ; if ( ! cachedFile . isPresent ( ) ) { return null ; } else if ( ! cachedFile . get ( ) . exists ( ) ) { logger . info ( String . format ( "Found cache entry {'%s'-->'%s'}, but local file doesn't exist. " + "Was it deleted? Re-downloading." , s3uri , cachedFile . get ( ) ) ) ; objectFileCache . invalidate ( s3uri ) ; // Evict old entry . Re - download below .
} else if ( ! cachedFile . get ( ) . equals ( file ) ) { // Copy content of cachedFile to file . Evict cachedFile from the cache .
Files . copy ( cachedFile . get ( ) , file ) ; objectFileCache . put ( s3uri , Optional . of ( file ) ) ; return file ; } else { return file ; // File already contains the content of the object at s3uri .
} } cachedFile = Optional . fromNullable ( threddsS3Client . saveObjectToFile ( s3uri , file ) ) ; objectFileCache . put ( s3uri , cachedFile ) ; return cachedFile . orNull ( ) ;


signature:
public class SwingUtils { /** * Convenience method for searching below < code > container < / code > in the
 * component hierarchy and return nested components that are instances of
 * class < code > clazz < / code > it finds . Returns an empty list if no such
 * components exist in the container .
 * Invoking this method with a class parameter of JComponent . class
 * will return all nested components .
 * This method invokes getDescendantsOfType ( clazz , container , true )
 * @ param clazz the class of components whose instances are to be found .
 * @ param container the container at which to begin the search
 * @ return the List of components */
public static < T extends JComponent > List < T > getDescendantsOfType ( Class < T > clazz , Container container ) { } }

implementation: return getDescendantsOfType ( clazz , container , true ) ;


signature:
public class SwingUtils { /** * Convenience method for searching below < code > container < / code > in the
 * component hierarchy and return nested components that are instances of
 * class < code > clazz < / code > it finds . Returns an empty list if no such
 * components exist in the container .
 * Invoking this method with a class parameter of JComponent . class
 * will return all nested components .
 * @ param clazz the class of components whose instances are to be found .
 * @ param container the container at which to begin the search
 * @ param nested true to list components nested within another listed
 * component , false otherwise
 * @ return the List of components */
public static < T extends JComponent > List < T > getDescendantsOfType ( Class < T > clazz , Container container , boolean nested ) { } }

implementation: List < T > tList = new ArrayList < T > ( ) ; for ( Component component : container . getComponents ( ) ) { if ( clazz . isAssignableFrom ( component . getClass ( ) ) ) { tList . add ( clazz . cast ( component ) ) ; } if ( nested || ! clazz . isAssignableFrom ( component . getClass ( ) ) ) { tList . addAll ( SwingUtils . < T > getDescendantsOfType ( clazz , ( Container ) component , nested ) ) ; } } return tList ;


signature:
public class SwingUtils { /** * Convenience method that searches below < code > container < / code > in the
 * component hierarchy and returns the first found component that is an
 * instance of class < code > clazz < / code > and has the bound property value .
 * Returns { @ code null } if such component cannot be found .
 * @ param clazz the class of component whose instance to be found .
 * @ param container the container at which to begin the search
 * @ param property the className of the bound property , exactly as expressed in
 * the accessor e . g . " Text " for getText ( ) , " Value " for getValue ( ) .
 * @ param value the value of the bound property
 * @ param nested true to list components nested within another component
 * which is also an instance of < code > clazz < / code > , false otherwise
 * @ return the component , or null if no such component exists in the
 * container
 * @ throws IllegalArgumentException if the bound property does
 * not exist for the class or cannot be accessed */
public static < T extends JComponent > T getDescendantOfType ( Class < T > clazz , Container container , String property , Object value , boolean nested ) throws IllegalArgumentException { } }

implementation: List < T > list = getDescendantsOfType ( clazz , container , nested ) ; return getComponentFromList ( clazz , list , property , value ) ;


signature:
public class SwingUtils { /** * Convenience method that searches below < code > container < / code > in the
 * component hierarchy in a depth first manner and returns the first
 * found component of class < code > clazz < / code > having the bound property
 * value .
 * Returns { @ code null } if such component cannot be found .
 * This method invokes getDescendantOfClass ( clazz , container , property ,
 * value , true )
 * @ param clazz the class of component to be found .
 * @ param container the container at which to begin the search
 * @ param property the className of the bound property , exactly as expressed in
 * the accessor e . g . " Text " for getText ( ) , " Value " for getValue ( ) .
 * This parameter is case sensitive .
 * @ param value the value of the bound property
 * @ return the component , or null if no such component exists in the
 * container ' s hierarchy .
 * @ throws IllegalArgumentException if the bound property does
 * not exist for the class or cannot be accessed */
public static < T extends JComponent > T getDescendantOfClass ( Class < T > clazz , Container container , String property , Object value ) throws IllegalArgumentException { } }

implementation: return getDescendantOfClass ( clazz , container , property , value , true ) ;


signature:
public class SwingUtils { /** * Convenience method that searches below < code > container < / code > in the
 * component hierarchy in a depth first manner and returns the first
 * found component of class < code > clazz < / code > having the bound property
 * value .
 * Returns { @ code null } if such component cannot be found .
 * @ param clazz the class of component to be found .
 * @ param container the container at which to begin the search
 * @ param property the className of the bound property , exactly as expressed
 * in the accessor e . g . " Text " for getText ( ) , " Value " for getValue ( ) .
 * This parameter is case sensitive .
 * @ param value the value of the bound property
 * @ param nested true to include components nested within another listed
 * component , false otherwise
 * @ return the component , or null if no such component exists in the
 * container ' s hierarchy
 * @ throws IllegalArgumentException if the bound property does
 * not exist for the class or cannot be accessed */
public static < T extends JComponent > T getDescendantOfClass ( Class < T > clazz , Container container , String property , Object value , boolean nested ) throws IllegalArgumentException { } }

implementation: List < T > list = getDescendantsOfClass ( clazz , container , nested ) ; return getComponentFromList ( clazz , list , property , value ) ;


signature:
public class SwingUtils { /** * Convenience method for mapping a container in the hierarchy to its
 * contained components . The keys are the containers , and the values
 * are lists of contained components .
 * Implementation note : The returned value is a HashMap and the values
 * are of type ArrayList . This is subject to change , so callers should
 * code against the interfaces Map and List .
 * @ param container The JComponent to be mapped
 * @ param nested true to drill down to nested containers , false otherwise
 * @ return the Map of the UI */
public static Map < JComponent , List < JComponent > > getComponentMap ( JComponent container , boolean nested ) { } }

implementation: HashMap < JComponent , List < JComponent > > retVal = new HashMap < JComponent , List < JComponent > > ( ) ; for ( JComponent component : getDescendantsOfType ( JComponent . class , container , false ) ) { if ( ! retVal . containsKey ( container ) ) { retVal . put ( container , new ArrayList < JComponent > ( ) ) ; } retVal . get ( container ) . add ( component ) ; if ( nested ) { retVal . putAll ( getComponentMap ( component , nested ) ) ; } } return retVal ;


signature:
public class SwingUtils { /** * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class .
 * @ param clazz the class of interest
 * @ return the UIDefaults of the class */
public static UIDefaults getUIDefaultsOfClass ( Class clazz ) { } }

implementation: String name = clazz . getName ( ) ; name = name . substring ( name . lastIndexOf ( "." ) + 2 ) ; return getUIDefaultsOfClass ( name ) ;


signature:
public class SwingUtils { /** * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class .
 * @ param className fully qualified name of the class of interest
 * @ return the UIDefaults of the class named */
public static UIDefaults getUIDefaultsOfClass ( String className ) { } }

implementation: UIDefaults retVal = new UIDefaults ( ) ; UIDefaults defaults = UIManager . getLookAndFeelDefaults ( ) ; List < ? > listKeys = Collections . list ( defaults . keys ( ) ) ; for ( Object key : listKeys ) { if ( key instanceof String && ( ( String ) key ) . startsWith ( className ) ) { String stringKey = ( String ) key ; String property = stringKey ; if ( stringKey . contains ( "." ) ) { property = stringKey . substring ( stringKey . indexOf ( "." ) + 1 ) ; } retVal . put ( property , defaults . get ( key ) ) ; } } return retVal ;


signature:
public class SwingUtils { /** * Convenience method for retrieving the UIDefault for a single property
 * of a particular class .
 * @ param clazz the class of interest
 * @ param property the property to query
 * @ return the UIDefault property , or null if not found */
public static Object getUIDefaultOfClass ( Class clazz , String property ) { } }

implementation: Object retVal = null ; UIDefaults defaults = getUIDefaultsOfClass ( clazz ) ; List < Object > listKeys = Collections . list ( defaults . keys ( ) ) ; for ( Object key : listKeys ) { if ( key . equals ( property ) ) { return defaults . get ( key ) ; } if ( key . toString ( ) . equalsIgnoreCase ( property ) ) { retVal = defaults . get ( key ) ; } } return retVal ;


signature:
public class SwingUtils { /** * Convenience method for obtaining most non - null human readable properties
 * of a JComponent . Array properties are not included .
 * Implementation note : The returned value is a HashMap . This is subject
 * to change , so callers should code against the interface Map .
 * @ param component the component whose proerties are to be determined
 * @ return the class and value of the properties */
public static Map < Object , Object > getProperties ( JComponent component ) { } }

implementation:
Map < Object , Object > retVal = new HashMap < Object , Object > ( ) ; Class < ? > clazz = component . getClass ( ) ; Method [ ] methods = clazz . getMethods ( ) ; Object value = null ; for ( Method method : methods ) { if ( method . getName ( ) . matches ( "^(is|get).*" ) && method . getParameterTypes ( ) . length == 0 ) { try { Class returnType = method . getReturnType ( ) ; if ( returnType != void . class && ! returnType . getName ( ) . startsWith ( "[" ) && ! setExclude . contains ( method . getName ( ) ) ) { String key = method . getName ( ) ; value = method . invoke ( component ) ; if ( value != null && ! ( value instanceof Component ) ) { retVal . put ( key , value ) ; } } // ignore exceptions that arise if the property could not be accessed
} catch ( IllegalAccessException ex ) { } catch ( IllegalArgumentException ex ) { } catch ( InvocationTargetException ex ) { } } } return retVal ;


signature:
public class SwingUtils { /** * Convenience method to obtain the Swing class from which this
 * component was directly or indirectly derived .
 * @ param component The component whose Swing superclass is to be
 * determined
 * @ return The nearest Swing class in the inheritance tree */
public static < T extends JComponent > Class getJClass ( T component ) { } }

implementation: Class < ? > clazz = component . getClass ( ) ; while ( ! clazz . getName ( ) . matches ( "javax.swing.J[^.]*$" ) ) { clazz = clazz . getSuperclass ( ) ; } return clazz ;


signature:
public class D4DataCompiler { /** * The goal here is to process the serialized
 * databuffer and locate top - level variable positions
 * in the serialized databuffer . Access to non - top - level
 * variables is accomplished on the fly .
 * @ return
 * @ throws DapException */
public void compile ( ) throws DapException { } }

implementation:
assert ( this . dataset != null && this . databuffer != null ) ; // iterate over the variables represented in the databuffer
for ( DapVariable vv : this . dataset . getTopVariables ( ) ) { D4Cursor data = compileVar ( vv , null ) ; this . dsp . addVariableData ( vv , data ) ; }


signature:
public class D4DataCompiler { /** * Compile a structure array .
 * @ param var the template
 * @ param container if inside a compound object
 * @ return A DataCompoundArray for the databuffer for this struct .
 * @ throws DapException */
protected D4Cursor compileStructureArray ( DapVariable var , D4Cursor container ) throws DapException { } }

implementation: DapStructure dapstruct = ( DapStructure ) var . getBaseType ( ) ; D4Cursor structarray = new D4Cursor ( Scheme . STRUCTARRAY , this . dsp , var , container ) . setOffset ( getPos ( this . databuffer ) ) ; List < DapDimension > dimset = var . getDimensions ( ) ; long dimproduct = DapUtil . dimProduct ( dimset ) ; D4Cursor [ ] instances = new D4Cursor [ ( int ) dimproduct ] ; Odometer odom = Odometer . factory ( DapUtil . dimsetToSlices ( dimset ) , dimset ) ; while ( odom . hasNext ( ) ) { Index index = odom . next ( ) ; D4Cursor instance = compileStructure ( var , dapstruct , structarray ) ; instance . setIndex ( index ) ; instances [ ( int ) index . index ( ) ] = instance ; } structarray . setElements ( instances ) ; return structarray ;


signature:
public class D4DataCompiler { /** * Compile a structure instance .
 * @ param dapstruct The template
 * @ param container
 * @ return A DataStructure for the databuffer for this struct .
 * @ throws DapException */
protected D4Cursor compileStructure ( DapVariable var , DapStructure dapstruct , D4Cursor container ) throws DapException { } }

implementation: int pos = getPos ( this . databuffer ) ; D4Cursor d4ds = new D4Cursor ( Scheme . STRUCTURE , ( D4DSP ) this . dsp , var , container ) . setOffset ( pos ) ; List < DapVariable > dfields = dapstruct . getFields ( ) ; for ( int m = 0 ; m < dfields . size ( ) ; m ++ ) { DapVariable dfield = dfields . get ( m ) ; D4Cursor dvfield = compileVar ( dfield , d4ds ) ; d4ds . addField ( m , dvfield ) ; assert dfield . getParent ( ) != null ; } return d4ds ;


signature:
public class D4DataCompiler { /** * Compile a sequence array .
 * @ param var the template
 * @ return A DataCompoundArray for the databuffer for this sequence .
 * @ throws DapException */
protected D4Cursor compileSequenceArray ( DapVariable var , D4Cursor container ) throws DapException { } }

implementation: DapSequence dapseq = ( DapSequence ) var . getBaseType ( ) ; D4Cursor seqarray = new D4Cursor ( Scheme . SEQARRAY , this . dsp , var , container ) . setOffset ( getPos ( this . databuffer ) ) ; List < DapDimension > dimset = var . getDimensions ( ) ; long dimproduct = DapUtil . dimProduct ( dimset ) ; D4Cursor [ ] instances = new D4Cursor [ ( int ) dimproduct ] ; Odometer odom = Odometer . factory ( DapUtil . dimsetToSlices ( dimset ) , dimset ) ; while ( odom . hasNext ( ) ) { Index index = odom . next ( ) ; D4Cursor instance = compileSequence ( var , dapseq , seqarray ) ; instance . setIndex ( index ) ; instances [ ( int ) index . index ( ) ] = instance ; } seqarray . setElements ( instances ) ; return seqarray ;


signature:
public class D4DataCompiler { /** * Compile a sequence as a set of records .
 * @ param dapseq
 * @ param container
 * @ return
 * @ throws DapException */
public D4Cursor compileSequence ( DapVariable var , DapSequence dapseq , D4Cursor container ) throws DapException { } }

implementation:
int pos = getPos ( this . databuffer ) ; D4Cursor seq = new D4Cursor ( Scheme . SEQUENCE , this . dsp , var , container ) . setOffset ( pos ) ; List < DapVariable > dfields = dapseq . getFields ( ) ; // Get the count of the number of records
long nrecs = getCount ( this . databuffer ) ; for ( int r = 0 ; r < nrecs ; r ++ ) { pos = getPos ( this . databuffer ) ; D4Cursor rec = ( D4Cursor ) new D4Cursor ( D4Cursor . Scheme . RECORD , this . dsp , var , container ) . setOffset ( pos ) . setRecordIndex ( r ) ; for ( int m = 0 ; m < dfields . size ( ) ; m ++ ) { DapVariable dfield = dfields . get ( m ) ; D4Cursor dvfield = compileVar ( dfield , rec ) ; rec . addField ( m , dvfield ) ; assert dfield . getParent ( ) != null ; } seq . addRecord ( rec ) ; } return seq ;


signature:
public class D4DataCompiler { /** * Utilities */
protected int extractChecksum ( ByteBuffer data ) throws DapException { } }

implementation: assert ChecksumMode . DAP . enabled ( this . checksummode ) ; if ( data . remaining ( ) < DapUtil . CHECKSUMSIZE ) throw new DapException ( "Short serialization: missing checksum" ) ; return data . getInt ( ) ;


signature:
public class BeLeDataInputStream { /** * Reads < code > n < / code > little - endian doubles from a random access file .
 * < p > This method is provided for speed when accessing a number
 * of consecutive values of the same type .
 * @ param d the buffer into which the doubles are read
 * @ param n number of little - endian doubles to read */
public final void readLEDoubles ( double [ ] d , int n ) throws IOException { } }

implementation: int nLeft = n ; int dCount = 0 ; int nToRead = kLongs ; while ( nLeft > 0 ) { if ( nToRead > nLeft ) nToRead = nLeft ; readLELongs ( longWorkSpace , nToRead ) ; for ( int i = 0 ; i < nToRead ; i ++ ) { d [ dCount ++ ] = Double . longBitsToDouble ( longWorkSpace [ i ] ) ; } nLeft -= nToRead ; }


signature:
public class BeLeDataInputStream { /** * read a long in little endian format
 * @ return long from next 8 bytes in stream , littleEndian order */
public long readLELong ( ) throws IOException { } }


signature:
public class BeLeDataInputStream { /** * Reads < code > n < / code > little - endian longs from a random access file .
 * < p > This method is provided for speed when accessing a number
 * of consecutive values of the same type .
 * @ param lbuf the buffer into which the longs are read
 * @ param n the number of little - endian longs to read */
public final void readLELongs ( long lbuf [ ] , int n ) throws IOException { } }

implementation: int nLeft = n ; int lCount = 0 ; int nToRead = kLongs ; while ( nLeft > 0 ) { if ( nToRead > nLeft ) nToRead = nLeft ; readFully ( byteWorkSpace , 0 , 8 * nToRead ) ; int j = 0 ; for ( int i = 0 ; i < nToRead ; i ++ ) { lbuf [ lCount ++ ] = ( long ) ( byteWorkSpace [ j ] & 0xff ) | ( long ) ( byteWorkSpace [ j + 1 ] & 0xff ) << 8 | ( long ) ( byteWorkSpace [ j + 2 ] & 0xff ) << 16 | ( long ) ( byteWorkSpace [ j + 3 ] & 0xff ) << 24 | ( long ) ( byteWorkSpace [ j + 4 ] & 0xff ) << 32 | ( long ) ( byteWorkSpace [ j + 5 ] & 0xff ) << 40 | ( long ) ( byteWorkSpace [ j + 6 ] & 0xff ) << 48 | ( long ) ( byteWorkSpace [ j + 7 ] & 0xff ) << 56 ; j += 8 ; } nLeft -= nToRead ; }


signature:
public class TableConfigurerImpl { /** * / * protected Variable findVariableWithStandardNameAndNotDimension ( NetcdfDataset ds , String standard _ name , Dimension outer , Formatter errlog ) {
 * for ( Variable v : ds . getVariables ( ) ) {
 * String stdName = ds . findAttValueIgnoreCase ( v , CF . STANDARD _ NAME , null ) ;
 * if ( ( stdName ! = null ) & & stdName . equals ( standard _ name ) & & v . getRank ( ) > 0 & & ! v . getDimension ( 0 ) . equals ( outer ) )
 * return v ;
 * return null ;
 * protected String matchAxisTypeAndDimension ( NetcdfDataset ds , AxisType type , final Dimension outer ) {
 * Variable var = CoordSysEvaluator . findCoordByType ( ds , type , new CoordSysEvaluator . Predicate ( ) {
 * public boolean match ( CoordinateAxis axis ) {
 * if ( ( outer = = null ) & & ( axis . getRank ( ) = = 0 ) )
 * return true ;
 * if ( ( outer ! = null ) & & ( axis . getRank ( ) = = 1 ) & & ( outer . equals ( axis . getDimension ( 0 ) ) ) )
 * return true ;
 * return false ;
 * if ( var = = null ) return null ;
 * return var . getShortName ( ) ; */
protected String matchAxisTypeAndDimension ( NetcdfDataset ds , AxisType type , final Dimension outer , final Dimension inner ) { } }

implementation: Variable var = CoordSysEvaluator . findCoordByType ( ds , type , new CoordSysEvaluator . Predicate ( ) { @ Override public boolean match ( CoordinateAxis axis ) { return ( ( axis . getRank ( ) == 2 ) && outer . equals ( axis . getDimension ( 0 ) ) && inner . equals ( axis . getDimension ( 1 ) ) ) ; } } ) ; if ( var == null ) return null ; return var . getShortName ( ) ;


signature:
public class Grib1CollectionBuilderFromIndex { /** * read in the index , index raf already open ; return null on failure */
@ Nullable static Grib1Collection readFromIndex ( String name , RandomAccessFile raf , FeatureCollectionConfig config , org . slf4j . Logger logger ) { } }

implementation: Grib1CollectionBuilderFromIndex builder = new Grib1CollectionBuilderFromIndex ( name , config , logger ) ; if ( ! builder . readIndex ( raf ) ) return null ; if ( builder . gc . getFiles ( ) . size ( ) == 0 ) { logger . warn ( "Grib1CollectionBuilderFromIndex {}: has no files, force recreate " , builder . gc . getName ( ) ) ; return null ; } return new Grib1Collection ( builder . gc ) ;


signature:
public class PrefPanel { /** * Add listener : action event sent if " apply " button is pressed */
public void addActionListener ( ActionListener l ) { } }

implementation: listenerList . add ( java . awt . event . ActionListener . class , l ) ;


signature:
public class PrefPanel { /** * Remove listener */
public void removeActionListener ( ActionListener l ) { } }

implementation: listenerList . remove ( java . awt . event . ActionListener . class , l ) ;


signature:
public class PrefPanel { /** * Call Field . accept ( ) on all Fields . This puts any edits into the Store ,
 * and fires PropertyChangeEvents if any values change , and sends an
 * ActionEvent to any listeners . */
public boolean accept ( ) { } }

implementation:
StringBuffer buff = new StringBuffer ( "Invalid field value " ) ; boolean ok = true ; for ( Object o : flds . values ( ) ) ok &= ( ( Field ) o ) . accept ( buff ) ; if ( ! ok ) { try { JOptionPane . showMessageDialog ( PrefPanel . findActiveFrame ( ) , buff . toString ( ) ) ; } catch ( HeadlessException e ) { } return false ; } /* store the text widths if they exist
 if ( storeData ! = null ) {
 Preferences substore = prefs . node ( " sizes " ) ;
 iter = flds . values ( ) . iterator ( ) ;
 while ( iter . hasNext ( ) ) {
 Field fld = ( Field ) iter . next ( ) ;
 JComponent comp = fld . getEditComponent ( ) ;
 substore . putInt ( fld . getName ( ) , ( int ) comp . getPreferredSize ( ) . getWidth ( ) ) ; */
fireEvent ( new ActionEvent ( this , 0 , "Accept" ) ) ; return true ;


signature:
public class PrefPanel { /** * Find the field with the specified name .
 * @ param name of Field
 * @ return Field or null if not found */
public Field getField ( String name ) { } }

implementation: Field fld = flds . get ( name ) ; if ( fld == null ) return null ; return ( fld instanceof FieldResizable ) ? ( ( FieldResizable ) fld ) . getDelegate ( ) : fld ;


signature:
public class PrefPanel { /** * Get current value of the named field
 * @ param name of field
 * @ return value of named field */
public Object getFieldValue ( String name ) { } }

implementation: Field fld = getField ( name ) ; if ( fld == null ) throw new IllegalArgumentException ( "no field named " + name ) ; return fld . getValue ( ) ;


signature:
public class PrefPanel { /** * Set the current value of the named field
 * @ param name of field
 * @ param value of field */
public void setFieldValue ( String name , Object value ) { } }

implementation: Field fld = getField ( name ) ; if ( fld == null ) throw new IllegalArgumentException ( "no field named " + name ) ; fld . setValue ( value ) ;


signature:
public class PrefPanel { /** * Add a field created by the user .
 * @ param fld add this field . */
public Field addField ( Field fld ) { } }

implementation: addField ( fld , cursorCol , cursorRow , null ) ; cursorRow ++ ; return fld ;


signature:
public class PrefPanel { /** * Add a boolean field as a checkbox .
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value */
public Field . CheckBox addCheckBoxField ( String fldName , String label , boolean defValue ) { } }

implementation: Field . CheckBox fld = new Field . CheckBox ( fldName , label , defValue , storeData ) ; addField ( fld ) ; return fld ;


signature:
public class PrefPanel { /** * Add a field that edits a date
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value */
public Field . Date addDateField ( String fldName , String label , Date defValue ) { } }

implementation: Field . Date fld = new Field . Date ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ;


signature:
public class PrefPanel { /** * Add a field that edits a double
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value */
public Field . Double addDoubleField ( String fldName , String label , double defValue ) { } }

implementation: Field . Double fld = new Field . Double ( fldName , label , defValue , - 1 , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ;


signature:
public class PrefPanel { /** * Add a field that edits an integer
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value */
public Field . Int addIntField ( String fldName , String label , int defValue ) { } }

implementation: Field . Int fld = new Field . Int ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ;


signature:
public class PrefPanel { /** * Add a password text field .
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value */
public Field . Password addPasswordField ( String fldName , String label , String defValue ) { } }

implementation: Field . Password fld = new Field . Password ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ;


signature:
public class PrefPanel { /** * Add a text field .
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValue default value
 * @ return the Field . Text object that was added */
public Field . Text addTextField ( String fldName , String label , String defValue ) { } }

implementation: Field . Text fld = new Field . Text ( fldName , label , defValue , storeData ) ; addField ( new FieldResizable ( fld , this ) ) ; return fld ;


signature:
public class PrefPanel { /** * Add a text combobox field .
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param defValues list of default values ( Strings ) to include in the comboBox . May be null .
 * These are added to the combobox ( at the end ) no matter how many there are .
 * @ param nKeep number of most recently used values to keep
 * @ param editable whether the user can add new entries the list to select from . */
public Field . TextCombo addTextComboField ( String fldName , String label , java . util . Collection defValues , int nKeep , boolean editable ) { } }

implementation: Field . TextCombo fld = new Field . TextCombo ( fldName , label , defValues , nKeep , storeData ) ; addField ( fld ) ; fld . setEditable ( editable ) ; return fld ;


signature:
public class PrefPanel { /** * Add a TextArea field .
 * @ param fldName the name to store the data in the PersistenceManagerData
 * @ param label used as the label on the panel
 * @ param def default value
 * @ param nrows number of rows */
public Field . TextArea addTextAreaField ( String fldName , String label , String def , int nrows ) { } }

implementation: Field . TextArea fld = new Field . TextArea ( fldName , label , def , nrows , storeData ) ; addField ( fld ) ; return fld ;


signature:
public class PrefPanel { /** * Add a heading at the specified row . this spans all columns */
public void addHeading ( String heading , int row ) { } }

implementation: layoutComponents . add ( new LayoutComponent ( heading , 0 , row , null ) ) ;


signature:
public class PrefPanel { /** * Add a Component . */
public void addComponent ( Component comp , int col , int row , String constraint ) { } }

implementation: layoutComponents . add ( new LayoutComponent ( comp , col , row , constraint ) ) ;


signature:
public class PrefPanel { /** * Add a seperator after the last field added . */
public void addEmptyRow ( int row , int size ) { } }

implementation: layoutComponents . add ( new LayoutComponent ( null , size , row , null ) ) ;


signature:
public class PrefPanel { /** * Call when finished adding components to the PrefPanel .
 * @ param addButtons if true , add buttons
 * @ param where BorderLayout . NORTH , SOUTH , EAST , WEST */
public void finish ( boolean addButtons , String where ) { } }

implementation:
if ( finished ) throw new IllegalStateException ( "PrefPanel " + name + ": already called finish()" ) ; StringBuilder sbuff = new StringBuilder ( ) ; // column layout , first sort by col
Collections . sort ( layoutComponents , new Comparator < LayoutComponent > ( ) { public int compare ( LayoutComponent o1 , LayoutComponent o2 ) { return o1 . col - o2 . col ; } public boolean equals ( Object o1 ) { return o1 == this ; } } ) ; // now create column layout spec and x cell constraint
sbuff . setLength ( 0 ) ; int currCol = - 1 ; Iterator iter = layoutComponents . iterator ( ) ; while ( iter . hasNext ( ) ) { LayoutComponent lc = ( LayoutComponent ) iter . next ( ) ; if ( lc . col > currCol ) { if ( currCol >= 0 ) sbuff . append ( ", 5dlu, " ) ; else sbuff . append ( "3dlu, " ) ; sbuff . append ( "right:default, 3dlu, default:grow" ) ; currCol += 2 ; } lc . ccLabel . gridX = 2 * lc . col + 2 ; lc . cc . gridX = 2 * lc . col + 4 ; } String colSpec = sbuff . toString ( ) ; if ( debugLayout ) System . out . println ( " column layout = " + colSpec ) ; int ncols = 2 * currCol ; // row layout , first sort by row
Collections . sort ( layoutComponents , new Comparator < LayoutComponent > ( ) { public int compare ( LayoutComponent o1 , LayoutComponent o2 ) { return o1 . row - o2 . row ; } public boolean equals ( Object o1 ) { return o1 == this ; } } ) ; // now adjust for any headings , put into y cell constraint
int incr = 0 ; iter = layoutComponents . iterator ( ) ; while ( iter . hasNext ( ) ) { LayoutComponent lc = ( LayoutComponent ) iter . next ( ) ; if ( ( lc . comp instanceof String ) && ( lc . row > 0 ) ) // its a header , not in first position
incr ++ ; // leave space by adding a row
lc . cc . gridY = lc . row + incr + 1 ; // adjust downward
lc . ccLabel . gridY = lc . cc . gridY ; if ( debugLayout ) System . out . println ( lc + " constraint = " + lc . cc ) ; } // now create row layout spec
sbuff . setLength ( 0 ) ; int currRow = - 1 ; iter = layoutComponents . iterator ( ) ; while ( iter . hasNext ( ) ) { LayoutComponent lc = ( LayoutComponent ) iter . next ( ) ; while ( lc . row > currRow ) { if ( ( lc . comp instanceof String ) && ( lc . row > 0 ) ) { sbuff . append ( ", 5dlu, default" ) ; } else if ( ( lc . comp == null ) ) { sbuff . append ( ", " ) . append ( lc . col ) . append ( "dlu" ) ; } else { if ( currRow >= 0 ) sbuff . append ( ", " ) ; sbuff . append ( "default" ) ; } currRow ++ ; } } String rowSpec = sbuff . toString ( ) ; if ( debugLayout ) System . out . println ( " row layout = " + rowSpec ) ; // the jgoodies form layout
FormLayout layout = new FormLayout ( colSpec , rowSpec ) ; PanelBuilder builder = new PanelBuilder ( layout ) ; builder . setDefaultDialogBorder ( ) ; CellConstraints cc = new CellConstraints ( ) ; // now add each component with correct constraint
iter = layoutComponents . iterator ( ) ; while ( iter . hasNext ( ) ) { LayoutComponent lc = ( LayoutComponent ) iter . next ( ) ; if ( lc . comp instanceof Field ) { Field fld = ( Field ) lc . comp ; builder . addLabel ( fld . getLabel ( ) + ":" , lc . ccLabel ) ; Component comp = fld . getEditComponent ( ) ; if ( lc . comp instanceof Field . TextArea ) comp = new JScrollPane ( comp ) ; builder . add ( comp , lc . cc ) ; } else if ( lc . comp instanceof String ) { String header = ( String ) lc . comp ; builder . addSeparator ( header , cc . xyw ( 1 , lc . cc . gridY , ncols ) ) ; } else if ( lc . comp instanceof Component ) { builder . add ( ( Component ) lc . comp , lc . cc ) ; } } mainPanel = builder . getPanel ( ) ; // button panel
JPanel buttPanel = new JPanel ( ) ; JButton acceptButton = new JButton ( "Apply" ) ; buttPanel . add ( acceptButton , null ) ; for ( JComponent auxButton : auxButtons ) buttPanel . add ( auxButton , null ) ; // button listeners
acceptButton . addActionListener ( new ActionListener ( ) { public void actionPerformed ( ActionEvent evt ) { accept ( ) ; } } ) ; setLayout ( new BorderLayout ( ) ) ; add ( mainPanel , BorderLayout . CENTER ) ; if ( addButtons ) { if ( where . equals ( BorderLayout . SOUTH ) ) { JPanel south = new JPanel ( ) ; south . setLayout ( new BoxLayout ( south , BoxLayout . Y_AXIS ) ) ; south . add ( new JSeparator ( SwingConstants . HORIZONTAL ) ) ; south . add ( buttPanel ) ; add ( south , BorderLayout . SOUTH ) ; } else add ( buttPanel , where ) ; } finished = true ;


signature:
public class PrefPanel { /** * thanks to Heinz M . Kabutz */
static public Frame findActiveFrame ( ) { } }

implementation: Frame [ ] frames = JFrame . getFrames ( ) ; for ( Frame frame : frames ) { if ( frame . isVisible ( ) ) return frame ; } return null ;


signature:
public class NcSDString { /** * Read the value ( parameters are ignored ) . */
public boolean read ( String datasetName , Object specialO ) throws IOException { } }

implementation:
if ( localVal == null ) // read first time
setData ( ncVar . read ( ) ) ; setValue ( localVal ) ; setRead ( true ) ; return ( false ) ;


signature:
public class DoradeRADD { /** * Get the cell spacing . An exception is thrown if the cell spacing
 * is not constant .
 * @ return the cell spacing , in meters
 * @ throws DescriptorException if the cell spacing is not constant . */
public float getCellSpacing ( ) throws DescriptorException { } }

implementation:
float [ ] cellRanges = myCELV . getCellRanges ( ) ; // use the first cell spacing as our expected value
float cellSpacing = cellRanges [ 1 ] - cellRanges [ 0 ] ; // Check the rest of the cells against the expected value , allowing
// 1 % fudge
for ( int i = 2 ; i < cellRanges . length ; i ++ ) { float space = cellRanges [ i ] - cellRanges [ i - 1 ] ; if ( ! Misc . nearlyEquals ( space , cellSpacing ) && ( Math . abs ( space / cellSpacing - 1.0 ) > 0.01 ) ) { throw new DescriptorException ( "variable cell spacing" ) ; } } return cellSpacing ;


signature:
public class Dimension { /** * Returns the array of Factor - s constituting this dimension .
 * @ return The array of Factor - s constituting this dimension . */
public final Factor [ ] getFactors ( ) { } }

implementation: final Factor [ ] factors = new Factor [ _factors . length ] ; System . arraycopy ( _factors , 0 , factors , 0 , factors . length ) ; return factors ;


signature:
public class Dimension { /** * Multiplies this dimension by another dimension .
 * @ param that
 * The other dimension .
 * @ return The product of the Factor - s of this dimension and the Factor - s of
 * the other dimension . */
protected Factor [ ] mult ( final Dimension that ) { } }

implementation:
// relys on _ factors always sorted
final Factor [ ] factors1 = _factors ; final Factor [ ] factors2 = that . _factors ; int i1 = 0 ; int i2 = 0 ; int k = 0 ; Factor [ ] newFactors = new Factor [ factors1 . length + factors2 . length ] ; for ( ; ; ) { if ( i1 == factors1 . length ) { final int n = factors2 . length - i2 ; System . arraycopy ( factors2 , i2 , newFactors , k , n ) ; k += n ; break ; } if ( i2 == factors2 . length ) { final int n = factors1 . length - i1 ; System . arraycopy ( factors1 , i1 , newFactors , k , n ) ; k += n ; break ; } final Factor f1 = factors1 [ i1 ] ; final Factor f2 = factors2 [ i2 ] ; final int comp = f1 . getID ( ) . compareTo ( f2 . getID ( ) ) ; if ( comp < 0 ) { newFactors [ k ++ ] = f1 ; i1 ++ ; } else if ( comp == 0 ) { final int exponent = f1 . getExponent ( ) + f2 . getExponent ( ) ; if ( exponent != 0 ) { newFactors [ k ++ ] = new Factor ( f1 , exponent ) ; } i1 ++ ; i2 ++ ; } else { newFactors [ k ++ ] = f2 ; i2 ++ ; } } if ( k < newFactors . length ) { final Factor [ ] tmp = new Factor [ k ] ; System . arraycopy ( newFactors , 0 , tmp , 0 , k ) ; newFactors = tmp ; } return newFactors ;


signature:
public class Dimension { /** * Raises this dimension to a power .
 * @ param power
 * The power to raise this dimension by .
 * @ return The Factor - s of this dimension raised to the power
 * < code > power < / code > . */
protected Factor [ ] pow ( final int power ) { } }

implementation: Factor [ ] factors ; if ( power == 0 ) { factors = new Factor [ 0 ] ; } else { factors = getFactors ( ) ; if ( power != 1 ) { for ( int i = factors . length ; -- i >= 0 ; ) { factors [ i ] = factors [ i ] . pow ( power ) ; } } } return factors ;


signature:
public class Dimension { /** * Indicates if this Dimension is the reciprocal of another dimension .
 * @ param that
 * The other dimension .
 * @ return < code > true < / code > if and only if this dimension is the reciprocal
 * of the other dimension . */
public final boolean isReciprocalOf ( final Dimension that ) { } }

implementation: final Factor [ ] theseFactors = _factors ; final Factor [ ] thoseFactors = that . _factors ; boolean isReciprocalOf ; if ( theseFactors . length != thoseFactors . length ) { isReciprocalOf = false ; } else { int i ; for ( i = theseFactors . length ; -- i >= 0 ; ) { if ( ! theseFactors [ i ] . isReciprocalOf ( thoseFactors [ i ] ) ) { break ; } } isReciprocalOf = i < 0 ; } return isReciprocalOf ;


signature:
public class Dimension { /** * Indicates if this dimension is dimensionless . A dimension is
 * dimensionless if it has no Factor - s or if all Factor - s are , themselves ,
 * dimensionless .
 * @ return < code > true < / code > if and only if this dimension is dimensionless . */
public final boolean isDimensionless ( ) { } }

implementation: for ( int i = _factors . length ; -- i >= 0 ; ) { if ( ! _factors [ i ] . isDimensionless ( ) ) { return false ; } } return true ;


signature:
public class NcOMObservationPropertyType { /** * wml2 : Collection / wml2 : observationMember */
public static OMObservationPropertyType initObservationMember ( OMObservationPropertyType observationMember , StationTimeSeriesFeature stationFeat , VariableSimpleIF dataVar ) throws IOException { } }

implementation:
// om : OM _ Observation
NcOMObservationType . initOmObservation ( observationMember . addNewOMObservation ( ) , stationFeat , dataVar ) ; return observationMember ;


signature:
public class TreeTableModelAbstract { /** * Notify all listeners that have registered interest for
 * notification on this event type . The event instance
 * is lazily created using the parameters passed into
 * the fire method .
 * @ see EventListenerList */
protected void fireTreeNodesChanged ( Object source , Object [ ] path , int [ ] childIndices , Object [ ] children ) { } }

implementation:
// Guaranteed to return a non - null array
Object [ ] listeners = listenerList . getListenerList ( ) ; TreeModelEvent e = null ; // Process the listeners last to first , notifying
// those that are interested in this event
for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == TreeModelListener . class ) { // Lazily create the event :
if ( e == null ) e = new TreeModelEvent ( source , path , childIndices , children ) ; ( ( TreeModelListener ) listeners [ i + 1 ] ) . treeNodesChanged ( e ) ; } }


signature:
public class TreeTableModelAbstract { /** * Notify all listeners that have registered interest for
 * notification on this event type . The event instance
 * is lazily created using the parameters passed into
 * the fire method .
 * @ see EventListenerList */
protected void fireTreeNodesInserted ( Object source , Object [ ] path , int [ ] childIndices , Object [ ] children ) { } }

implementation:
// Guaranteed to return a non - null array
Object [ ] listeners = listenerList . getListenerList ( ) ; TreeModelEvent e = null ; // Process the listeners last to first , notifying
// those that are interested in this event
for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == TreeModelListener . class ) { // Lazily create the event :
if ( e == null ) e = new TreeModelEvent ( source , path , childIndices , children ) ; ( ( TreeModelListener ) listeners [ i + 1 ] ) . treeNodesInserted ( e ) ; } }


signature:
public class TreeTableModelAbstract { /** * Notify all listeners that have registered interest for
 * notification on this event type . The event instance
 * is lazily created using the parameters passed into
 * the fire method .
 * @ see EventListenerList */
protected void fireTreeNodesRemoved ( Object source , Object [ ] path , int [ ] childIndices , Object [ ] children ) { } }

implementation:
// Guaranteed to return a non - null array
Object [ ] listeners = listenerList . getListenerList ( ) ; TreeModelEvent e = null ; // Process the listeners last to first , notifying
// those that are interested in this event
for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == TreeModelListener . class ) { // Lazily create the event :
if ( e == null ) e = new TreeModelEvent ( source , path , childIndices , children ) ; ( ( TreeModelListener ) listeners [ i + 1 ] ) . treeNodesRemoved ( e ) ; } }


signature:
public class AggregationExisting { /** * Persist info ( ncoords , coordValues ) from joinExisting , since that can be expensive to recreate .
 * @ throws IOException */
public void persistWrite ( ) throws IOException { } }

implementation:
if ( diskCache2 == null ) return ; String cacheName = getCacheName ( ) ; if ( cacheName == null ) return ; if ( cacheName . startsWith ( "file:" ) ) // LOOK
cacheName = cacheName . substring ( 5 ) ; File cacheFile = diskCache2 . getCacheFile ( cacheName ) ; if ( cacheFile == null ) throw new IllegalStateException ( ) ; // only write out if something changed after the cache file was last written , or if the file has been deleted
if ( ! cacheDirty && cacheFile . exists ( ) ) return ; FileChannel channel = null ; try { File dir = cacheFile . getParentFile ( ) ; if ( ! dir . exists ( ) ) { if ( ! dir . mkdirs ( ) ) logger . error ( "Cant make cache directory= " + cacheFile ) ; } // Get a file channel for the file
FileOutputStream fos = new FileOutputStream ( cacheFile ) ; channel = fos . getChannel ( ) ; // Try acquiring the lock without blocking . This method returns
// null or throws an exception if the file is already locked .
FileLock lock ; try { lock = channel . tryLock ( ) ; } catch ( OverlappingFileLockException e ) { // File is already locked in this thread or virtual machine
return ; // give up
} if ( lock == null ) return ; PrintWriter out = new PrintWriter ( new OutputStreamWriter ( fos , CDM . utf8Charset ) ) ; out . print ( "<?xml version='1.0' encoding='UTF-8'?>\n" ) ; out . print ( "<aggregation xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' version='3' " ) ; out . print ( "type='" + type + "' " ) ; if ( dimName != null ) out . print ( "dimName='" + dimName + "' " ) ; if ( datasetManager . getRecheck ( ) != null ) out . print ( "recheckEvery='" + datasetManager . getRecheck ( ) + "' " ) ; out . print ( ">\n" ) ; List < Dataset > nestedDatasets = getDatasets ( ) ; for ( Dataset dataset : nestedDatasets ) { DatasetOuterDimension dod = ( DatasetOuterDimension ) dataset ; if ( dod . getId ( ) == null ) logger . warn ( "id is null" ) ; out . print ( "  <netcdf id='" + dod . getId ( ) + "' " ) ; out . print ( "ncoords='" + dod . getNcoords ( null ) + "' >\n" ) ; for ( CacheVar pv : cacheList ) { Array data = pv . getData ( dod . getId ( ) ) ; if ( data != null ) { out . print ( "    <cache varName='" + pv . varName + "' >" ) ; while ( data . hasNext ( ) ) out . printf ( "%s " , data . next ( ) ) ; out . print ( "</cache>\n" ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( " wrote array = " + pv . varName + " nelems= " + data . getSize ( ) + " for " + dataset . getLocation ( ) ) ; } } out . print ( "  </netcdf>\n" ) ; } out . print ( "</aggregation>\n" ) ; out . close ( ) ; // this also closes the channel and releases the lock
long time = datasetManager . getLastScanned ( ) ; if ( time == 0 ) time = System . currentTimeMillis ( ) ; // no scans ( eg all static ) will have a 0
if ( ! cacheFile . setLastModified ( time ) ) logger . warn ( "FAIL to set lastModified on {}" , cacheFile . getPath ( ) ) ; cacheDirty = false ; if ( logger . isDebugEnabled ( ) ) logger . debug ( "Aggregation persisted = " + cacheFile . getPath ( ) + " lastModified= " + new Date ( datasetManager . getLastScanned ( ) ) ) ; } finally { if ( channel != null ) channel . close ( ) ; }


signature:
public class AggregationExisting { /** * read info from the persistent XML file , if it exists */
protected void persistRead ( ) { } }

implementation:
if ( diskCache2 == null ) return ; String cacheName = getCacheName ( ) ; if ( cacheName == null ) return ; if ( cacheName . startsWith ( "file:" ) ) // LOOK
cacheName = cacheName . substring ( 5 ) ; File cacheFile = diskCache2 . getCacheFile ( cacheName ) ; if ( cacheFile == null ) throw new IllegalStateException ( ) ; if ( ! cacheFile . exists ( ) ) return ; long lastWritten = cacheFile . lastModified ( ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( " Try to Read cache {} " + cacheFile . getPath ( ) ) ; Element aggElem ; try { aggElem = ucar . nc2 . util . xml . Parse . readRootElement ( "file:" + cacheFile . getPath ( ) ) ; } catch ( IOException e ) { if ( debugCache ) System . out . println ( " No cache for " + cacheName + " - " + e . getMessage ( ) ) ; return ; } String version = aggElem . getAttributeValue ( "version" ) ; if ( ( version == null ) || ! version . equals ( "3" ) ) return ; // dont read old cache files , recreate
// use a map to find datasets to avoid O ( n * * 2 ) searching
Map < String , Dataset > map = new HashMap < String , Dataset > ( ) ; for ( Dataset ds : getDatasets ( ) ) { map . put ( ds . getId ( ) , ds ) ; } List < Element > ncList = aggElem . getChildren ( "netcdf" , Catalog . ncmlNS ) ; for ( Element netcdfElemNested : ncList ) { String id = netcdfElemNested . getAttributeValue ( "id" ) ; DatasetOuterDimension dod = ( DatasetOuterDimension ) map . get ( id ) ; if ( null == dod ) { // this should mean that the dataset has been deleted . so not a problem
if ( logger . isDebugEnabled ( ) ) logger . debug ( " have cache but no dataset= {}" , id ) ; continue ; } if ( logger . isDebugEnabled ( ) ) logger . debug ( " use cache for dataset= {}" , id ) ; MFile mfile = dod . getMFile ( ) ; if ( mfile != null && mfile . getLastModified ( ) > lastWritten ) { // skip datasets that have changed
if ( logger . isDebugEnabled ( ) ) logger . debug ( " dataset was changed= {}" , mfile ) ; continue ; } if ( dod . ncoord == 0 ) { String ncoordsS = netcdfElemNested . getAttributeValue ( "ncoords" ) ; try { dod . ncoord = Integer . parseInt ( ncoordsS ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( " Read the cache; ncoords = {}" , dod . ncoord ) ; } catch ( NumberFormatException e ) { logger . error ( "bad ncoord attribute on dataset=" + id ) ; } } // if ( dod . coordValue ! = null ) continue ; / / allow ncml to override
List < Element > cacheElemList = netcdfElemNested . getChildren ( "cache" , Catalog . ncmlNS ) ; for ( Element cacheElemNested : cacheElemList ) { String varName = cacheElemNested . getAttributeValue ( "varName" ) ; CacheVar pv = findCacheVariable ( varName ) ; if ( pv != null ) { String sdata = cacheElemNested . getText ( ) ; if ( sdata . length ( ) == 0 ) continue ; if ( logger . isDebugEnabled ( ) ) logger . debug ( " read data for var = " + varName + " size= " + sdata . length ( ) ) ; // long start = System . nanoTime ( ) ;
String [ ] vals = sdata . split ( " " ) ; // double took = . 001 * . 001 * . 001 * ( System . nanoTime ( ) - start ) ;
// if ( debugPersist ) System . out . println ( " split took = " + took + " sec ; " ) ;
try { // start = System . nanoTime ( ) ;
Array data = Array . makeArray ( pv . dtype , vals ) ; // took = . 001 * . 001 * . 001 * ( System . nanoTime ( ) - start ) ;
// if ( debugPersist ) System . out . println ( " makeArray took = " + took + " sec nelems = " + data . getSize ( ) ) ;
pv . putData ( id , data ) ; countCacheUse ++ ; } catch ( Exception e ) { logger . warn ( "Error reading cached data " , e ) ; } } else { logger . warn ( "not a cache var=" + varName ) ; } } }