signature:
public class GribCollectionMutable { /** * public by accident , do not use
 * @ param indexRaf the open raf of the index file */
void setIndexRaf ( RandomAccessFile indexRaf ) { } }

implementation: this . indexRaf = indexRaf ; if ( indexRaf != null ) { this . indexFilename = indexRaf . getLocation ( ) ; }


signature:
public class GribCollectionMutable { /** * get index filename
 * @ return index filename ; may not exist ; may be in disk cache */
private String getIndexFilepathInCache ( ) { } }

implementation: File indexFile = GribCdmIndex . makeIndexFile ( name , directory ) ; return GribIndexCache . getFileOrCache ( indexFile . getPath ( ) ) . getPath ( ) ;


signature:
public class GribCollectionMutable { /** * set from GribCollectionBuilderFromIndex . readFromIndex ( ) */
File setOrgDirectory ( String orgDirectory ) { } }

implementation: this . orgDirectory = orgDirectory ; directory = new File ( orgDirectory ) ; if ( ! directory . exists ( ) ) { File indexFile = new File ( indexFilename ) ; File parent = indexFile . getParentFile ( ) ; if ( parent . exists ( ) ) directory = parent ; } return directory ;


signature:
public class GribCollectionMutable { /** * stuff for FileCacheable */
public void close ( ) throws java . io . IOException { } }

implementation: if ( indexRaf != null ) { indexRaf . close ( ) ; indexRaf = null ; }


signature:
public class DConstructor { /** * Coverity [ CALL _ SUPER ] */
public void printXML ( PrintWriter pw , String pad , boolean constrained ) { } }

implementation: Enumeration e = getAttributeNames ( ) ; Enumeration ve = getVariables ( ) ; boolean hasAttributes = e . hasMoreElements ( ) ; boolean hasVariables = ve . hasMoreElements ( ) ; pw . print ( pad + "<" + getTypeName ( ) ) ; if ( getEncodedName ( ) != null ) { pw . print ( " name=\"" + DDSXMLParser . normalizeToXML ( getClearName ( ) ) + "\"" ) ; } if ( hasAttributes || hasVariables ) { pw . println ( ">" ) ; while ( e . hasMoreElements ( ) ) { String aName = ( String ) e . nextElement ( ) ; Attribute a = getAttribute ( aName ) ; if ( a != null ) a . printXML ( pw , pad + "\t" , constrained ) ; } while ( ve . hasMoreElements ( ) ) { BaseType bt = ( BaseType ) ve . nextElement ( ) ; bt . printXML ( pw , pad + "\t" , constrained ) ; } pw . println ( pad + "</" + getTypeName ( ) + ">" ) ; } else { pw . println ( "/>" ) ; }


signature:
public class BitCounterCompressed { /** * Number of nested fields
 * @ return 1 if no nested fields , otherwise count of nested fields */
public int ncounters ( ) { } }

implementation: if ( nested == null ) return 1 ; else { int ncounters = 0 ; for ( BitCounterCompressed [ ] counters : nested ) { if ( counters == null ) continue ; for ( BitCounterCompressed counter : counters ) if ( counter != null ) ncounters += counter . ncounters ( ) ; } return ncounters ; }


signature:
public class NetcdfFileWriteable { /** * Open an existing Netcdf file for writing data .
 * Cannot add new objects , you can only read / write data to existing Variables .
 * Setting fill = false is more efficient , use when you know you will write all data .
 * @ param location name of existing file to open .
 * @ param fill if true , the data is first written with fill values .
 * @ return existing file that can be written to
 * @ throws IOException on I / O error */
static public NetcdfFileWriteable openExisting ( String location , boolean fill ) throws IOException { } }

implementation: return new NetcdfFileWriteable ( location , fill , true ) ;


signature:
public class NetcdfFileWriteable { /** * Create a new Netcdf file , put it into define mode . Make calls to addXXX ( ) , then
 * when all objects are added , call create ( ) . You cannot read or write data until create ( ) is called .
 * Setting fill = false is more efficient , use when you know you will write all data .
 * @ param location name of new file to open ; if it exists , will overwrite it .
 * @ param fill if true , the data is first written with fill values .
 * Leave false if you expect to write all data values , set to true if you want to be
 * sure that unwritten data values have the fill value in it . ( default is false )
 * @ return new file that can be written to
 * @ throws IOException on I / O error */
static public NetcdfFileWriteable createNew ( String location , boolean fill ) throws IOException { } }

implementation: return new NetcdfFileWriteable ( location , fill , false ) ;


signature:
public class NetcdfFileWriteable { /** * Add a Dimension to the file . Must be in define mode .
 * @ param dimName name of dimension
 * @ param length size of dimension .
 * @ return the created dimension */
public Dimension addDimension ( String dimName , int length ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( length <= 0 ) throw new IllegalArgumentException ( "dimension length must be > 0 :" + length ) ; if ( ! N3iosp . isValidNetcdfObjectName ( dimName ) ) throw new IllegalArgumentException ( "illegal netCDF-3 dimension name: " + dimName ) ; Dimension dim = new Dimension ( dimName , length , true , false , false ) ; super . addDimension ( null , dim ) ; return dim ;


signature:
public class NetcdfFileWriteable { /** * Add a Dimension to the file . Must be in define mode .
 * @ param dimName name of dimension
 * @ param length size of dimension .
 * @ param isShared if dimension is shared
 * @ param isUnlimited if dimension is unlimited
 * @ param isVariableLength if dimension is variable length
 * @ return the created dimension */
public Dimension addDimension ( String dimName , int length , boolean isShared , boolean isUnlimited , boolean isVariableLength ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( dimName ) ) throw new IllegalArgumentException ( "illegal netCDF-3 dimension name " + dimName ) ; Dimension dim = new Dimension ( dimName , length , isShared , isUnlimited , isVariableLength ) ; super . addDimension ( null , dim ) ; return dim ;


signature:
public class NetcdfFileWriteable { /** * Rename a Dimension . Must be in define mode .
 * @ param oldName existing dimension has this name
 * @ param newName rename to this
 * @ return renamed dimension , or null if not found */
public Dimension renameDimension ( String oldName , String newName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Dimension dim = findDimension ( oldName ) ; if ( null != dim ) dim . setName ( newName ) ; return dim ;


signature:
public class NetcdfFileWriteable { /** * Add a Global attribute to the file . Must be in define mode .
 * @ param att the attribute .
 * @ return the created attribute */
public Attribute addGlobalAttribute ( Attribute att ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( att . getShortName ( ) ) ) { String attName = N3iosp . makeValidNetcdfObjectName ( att . getShortName ( ) ) ; log . warn ( "illegal netCDF-3 attribute name= " + att . getShortName ( ) + " change to " + attName ) ; att = new Attribute ( attName , att . getValues ( ) ) ; } return super . addAttribute ( null , att ) ;


signature:
public class NetcdfFileWriteable { /** * Add a Global attribute of type String to the file . Must be in define mode .
 * @ param name name of attribute .
 * @ param value value of atribute .
 * @ return the created attribute */
public Attribute addGlobalAttribute ( String name , String value ) { } }

implementation: return addGlobalAttribute ( new Attribute ( name , value ) ) ;


signature:
public class NetcdfFileWriteable { /** * Add a Global attribute of type Array to the file . Must be in define mode .
 * @ param name name of attribute .
 * @ param values Array of values
 * @ return the created attribute */
public Attribute addGlobalAttribute ( String name , Array values ) { } }

implementation: return addGlobalAttribute ( new Attribute ( name , values ) ) ;


signature:
public class NetcdfFileWriteable { /** * Delete a global Attribute . Must be in define mode .
 * @ param attName existing Attribute has this name
 * @ return deleted Attribute , or null if not found */
public Attribute deleteGlobalAttribute ( String attName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Attribute att = findGlobalAttribute ( attName ) ; if ( null == att ) return null ; rootGroup . remove ( att ) ; return att ;


signature:
public class NetcdfFileWriteable { /** * Rename a global Attribute . Must be in define mode .
 * @ param oldName existing Attribute has this name
 * @ param newName rename to this
 * @ return renamed Attribute , or null if not found */
public Attribute renameGlobalAttribute ( String oldName , String newName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Attribute att = findGlobalAttribute ( oldName ) ; if ( null == att ) return null ; rootGroup . remove ( att ) ; att = new Attribute ( newName , att . getValues ( ) ) ; rootGroup . addAttribute ( att ) ; return att ;


signature:
public class NetcdfFileWriteable { /** * Add a variable to the file . Must be in define mode .
 * @ param varName name of Variable , must be unique with the file .
 * @ param dataType type of underlying element
 * @ param dims array of Dimensions for the variable , must already have been added . Use an array of length 0
 * for a scalar variable .
 * @ return the Variable that has been added */
public Variable addVariable ( String varName , DataType dataType , Dimension [ ] dims ) { } }

implementation: ArrayList < Dimension > list = new ArrayList < Dimension > ( ) ; list . addAll ( Arrays . asList ( dims ) ) ; return addVariable ( varName , dataType , list ) ;


signature:
public class NetcdfFileWriteable { /** * Add a variable to the file . Must be in define mode .
 * @ param varName name of Variable , must be unique with the file .
 * @ param dataType type of underlying element
 * @ param dims names of Dimensions for the variable , blank seperated .
 * Must already have been added . Use an empty string for a scalar variable .
 * @ return the Variable that has been added */
public Variable addVariable ( String varName , DataType dataType , String dims ) { } }

implementation:
// parse the list
ArrayList < Dimension > list = new ArrayList < Dimension > ( ) ; StringTokenizer stoker = new StringTokenizer ( dims ) ; while ( stoker . hasMoreTokens ( ) ) { String tok = stoker . nextToken ( ) ; Dimension d = rootGroup . findDimension ( tok ) ; if ( null == d ) throw new IllegalArgumentException ( "Cant find dimension " + tok ) ; list . add ( d ) ; } return addVariable ( varName , dataType , list ) ;


signature:
public class NetcdfFileWriteable { /** * Add a variable to the file . Must be in define mode .
 * @ param shortName name of Variable , must be unique with the file .
 * @ param dataType type of underlying element
 * @ param dims list of Dimensions for the variable , must already have been added . Use a list of length 0
 * for a scalar variable .
 * @ return the Variable that has been added */
public Variable addVariable ( String shortName , DataType dataType , List < Dimension > dims ) { } }

implementation:
if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( shortName ) ) throw new IllegalArgumentException ( "illegal netCDF-3 variable name: " + shortName ) ; if ( ! valid . contains ( dataType ) ) throw new IllegalArgumentException ( "illegal dataType for netcdf-3 format: " + dataType ) ; // check unlimited
int count = 0 ; for ( Dimension d : dims ) { if ( d . isUnlimited ( ) ) if ( count != 0 ) throw new IllegalArgumentException ( "Unlimited dimension " + d + " must be first instead its  =" + count ) ; count ++ ; } Variable v = new Variable ( this , rootGroup , null , shortName ) ; v . setDataType ( dataType ) ; v . setDimensions ( dims ) ; long size = v . getSize ( ) * v . getElementSize ( ) ; if ( size > N3iosp . MAX_VARSIZE ) throw new IllegalArgumentException ( "Variable size in bytes " + size + " may not exceed " + N3iosp . MAX_VARSIZE ) ; super . addVariable ( null , v ) ; return v ;


signature:
public class NetcdfFileWriteable { /** * Add a variable with DataType = String to the file . Must be in define mode .
 * The variable will be stored in the file as a CHAR variable .
 * A new dimension with name " varName _ strlen " is automatically added , with length max _ strlen .
 * @ param varName name of Variable , must be unique within the file .
 * @ param dims list of Dimensions for the variable , must already have been added . Use a list of length 0
 * for a scalar variable . Do not include the string length dimension .
 * @ param max _ strlen maximum string length .
 * @ return the Variable that has been added */
public Variable addStringVariable ( String varName , List < Dimension > dims , int max_strlen ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( varName ) ) throw new IllegalArgumentException ( "illegal netCDF-3 variable name: " + varName ) ; Variable v = new Variable ( this , rootGroup , null , varName ) ; v . setDataType ( DataType . CHAR ) ; Dimension d = addDimension ( varName + "_strlen" , max_strlen ) ; ArrayList < Dimension > sdims = new ArrayList < Dimension > ( dims ) ; sdims . add ( d ) ; v . setDimensions ( sdims ) ; super . addVariable ( null , v ) ; return v ;


signature:
public class NetcdfFileWriteable { /** * Rename a Variable . Must be in define mode .
 * @ param oldName existing Variable has this name
 * @ param newName rename to this
 * @ return renamed Variable , or null if not found */
public Variable renameVariable ( String oldName , String newName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Variable v = findVariable ( oldName ) ; if ( null != v ) v . setName ( newName ) ; return v ;


signature:
public class NetcdfFileWriteable { /** * Add an attribute to the named Variable . Must be in define mode .
 * @ param varName name of variable . must already have been added to the file .
 * @ param att Attribute to add . */
public void addVariableAttribute ( String varName , Attribute att ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( att . getShortName ( ) ) ) { String attName = N3iosp . makeValidNetcdfObjectName ( att . getShortName ( ) ) ; log . warn ( "illegal netCDF-3 attribute name= " + att . getShortName ( ) + " change to " + attName ) ; att = new Attribute ( attName , att . getValues ( ) ) ; } Variable v = rootGroup . findVariable ( varName ) ; if ( null == v ) throw new IllegalArgumentException ( "addVariableAttribute variable name not found = <" + varName + ">" ) ; v . addAttribute ( att ) ;


signature:
public class NetcdfFileWriteable { /** * Add an attribute of type String to the named Variable . Must be in define mode .
 * @ param varName name of variable . must already have been added to the file .
 * @ param attName name of attribute .
 * @ param value String value of atribute . */
public void addVariableAttribute ( String varName , String attName , String value ) { } }

implementation: addVariableAttribute ( varName , new Attribute ( attName , value ) ) ;


signature:
public class NetcdfFileWriteable { /** * Add an attribute of type Array to the named Variable . Must be in define mode .
 * @ param varName name of variable . IllegalArgumentException if not valid name .
 * @ param attName name of attribute .
 * @ param value Array of valkues */
public void addVariableAttribute ( String varName , String attName , Array value ) { } }

implementation: Attribute att = new Attribute ( attName , value ) ; addVariableAttribute ( varName , att ) ;


signature:
public class NetcdfFileWriteable { /** * Delete a variable Attribute . Must be in define mode .
 * @ param varName existing Variable name
 * @ param attName existing Attribute has this name
 * @ return deleted Attribute , or null if not found */
public Attribute deleteVariableAttribute ( String varName , String attName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Variable v = findVariable ( varName ) ; if ( v == null ) return null ; Attribute att = v . findAttribute ( attName ) ; if ( null == att ) return null ; v . remove ( att ) ; return att ;


signature:
public class NetcdfFileWriteable { /** * Rename a variable Attribute . Must be in define mode .
 * @ param varName existing Variable name
 * @ param attName existing Attribute has this name
 * @ param newName rename to this
 * @ return renamed Attribute , or null if not found */
public Attribute renameVariableAttribute ( String varName , String attName , String newName ) { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; Variable v = findVariable ( varName ) ; if ( v == null ) return null ; Attribute att = v . findAttribute ( attName ) ; if ( null == att ) return null ; v . remove ( att ) ; att = new Attribute ( newName , att . getValues ( ) ) ; v . addAttribute ( att ) ; return att ;


signature:
public class NetcdfFileWriteable { /** * Update the value of an existing attribute . Attribute is found by name , which must match exactly .
 * You cannot make an attribute longer , or change the number of values .
 * For strings : truncate if longer , zero fill if shorter . Strings are padded to 4 byte boundaries , ok to use padding if it exists .
 * For numerics : must have same number of values .
 * @ param v2 variable , or null for global attribute
 * @ param att replace with this value
 * @ throws IOException if I / O error */
public void updateAttribute ( ucar . nc2 . Variable v2 , Attribute att ) throws IOException { } }

implementation: if ( defineMode ) throw new UnsupportedOperationException ( "in define mode" ) ; spiw . updateAttribute ( v2 , att ) ;


signature:
public class NetcdfFileWriteable { /** * After you have added all of the Dimensions , Variables , and Attributes ,
 * call create ( ) to actually create the file . You must be in define mode .
 * After this call , you are no longer in define mode .
 * @ throws java . io . IOException if I / O error */
public void create ( ) throws java . io . IOException { } }

implementation: if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( cached_spiw == null ) { spi = SPFactory . getServiceProvider ( ) ; spiw = ( IOServiceProviderWriter ) spi ; } else { spiw = cached_spiw ; spi = spiw ; } spiw . setFill ( fill ) ; spiw . create ( location , this , extraHeader , preallocateSize , isLargeFile ) ; defineMode = false ;


signature:
public class NetcdfFileWriteable { /** * rewrite entire file */
private void rewrite ( ) throws IOException { } }

implementation:
// close existing file , rename and open as read - only
spiw . flush ( ) ; spiw . close ( ) ; File prevFile = new File ( location ) ; File tmpFile = new File ( location + ".tmp" ) ; if ( tmpFile . exists ( ) ) tmpFile . delete ( ) ; if ( ! prevFile . renameTo ( tmpFile ) ) { System . out . printf ( "%50s prevFile.exists=%s canRead=%s canWrite=%s%n" , prevFile . getPath ( ) , prevFile . exists ( ) , prevFile . canRead ( ) , prevFile . canWrite ( ) ) ; System . out . printf ( "%50s  tmpFile.exists=%s canRead=%s canWrite=%s%n" , tmpFile . getPath ( ) , tmpFile . exists ( ) , tmpFile . canRead ( ) , tmpFile . canWrite ( ) ) ; throw new RuntimeException ( "Cant rename " + prevFile . getAbsolutePath ( ) + " to " + tmpFile . getAbsolutePath ( ) ) ; } NetcdfFile oldFile = NetcdfFile . open ( tmpFile . getPath ( ) ) ; // use record dimension if it has one
Structure recordVar = null ; if ( oldFile . hasUnlimitedDimension ( ) ) { oldFile . sendIospMessage ( NetcdfFile . IOSP_MESSAGE_ADD_RECORD_STRUCTURE ) ; recordVar = ( Structure ) oldFile . findVariable ( "record" ) ; /* if ( recordVar ! = null ) {
 Boolean result = ( Boolean ) spiw . sendIospMessage ( NetcdfFile . IOSP _ MESSAGE _ ADD _ RECORD _ STRUCTURE ) ;
 if ( ! result )
 recordVar = null ; */
} // create new file with current set of objects
spiw . create ( location , this , extraHeader , preallocateSize , isLargeFile ) ; spiw . setFill ( fill ) ; // isClosed = false ;
// wait till header is written before adding the record variable to the file
if ( recordVar != null ) { Boolean result = ( Boolean ) spiw . sendIospMessage ( NetcdfFile . IOSP_MESSAGE_ADD_RECORD_STRUCTURE ) ; if ( ! result ) recordVar = null ; } // copy old file to new
List < Variable > oldList = new ArrayList < Variable > ( getVariables ( ) . size ( ) ) ; for ( Variable v : getVariables ( ) ) { Variable oldVar = oldFile . findVariable ( v . getFullNameEscaped ( ) ) ; if ( oldVar != null ) oldList . add ( oldVar ) ; } FileWriter . copyVarData ( this , oldList , recordVar , null ) ; flush ( ) ; // delete old
oldFile . close ( ) ; if ( ! tmpFile . delete ( ) ) throw new RuntimeException ( "Cant delete " + location ) ;


signature:
public class NetcdfFileWriteable { /** * Write data to the named variable , origin assumed to be 0 . Must not be in define mode .
 * @ param fullNameEsc name of variable . IllegalArgumentException if variable name does not exist .
 * @ param values write this array ; must be same type and rank as Variable
 * @ throws IOException if I / O error
 * @ throws ucar . ma2 . InvalidRangeException if values Array has illegal shape */
public void write ( String fullNameEsc , Array values ) throws java . io . IOException , InvalidRangeException { } }

implementation: write ( fullNameEsc , new int [ values . getRank ( ) ] , values ) ;


signature:
public class NetcdfFileWriteable { /** * Write data to the named variable . Must not be in define mode .
 * @ param fullNameEsc full , escaped name of variable . IllegalArgumentException if variable name does not exist .
 * @ param origin offset within the variable to start writing .
 * @ param values write this array ; must be same type and rank as Variable
 * @ throws IOException if I / O error
 * @ throws ucar . ma2 . InvalidRangeException if values Array has illegal shape */
public void write ( String fullNameEsc , int [ ] origin , Array values ) throws java . io . IOException , InvalidRangeException { } }

implementation: if ( defineMode ) throw new UnsupportedOperationException ( "in define mode" ) ; ucar . nc2 . Variable v2 = findVariable ( fullNameEsc ) ; if ( v2 == null ) throw new IllegalArgumentException ( "NetcdfFileWriteable.write illegal variable name = " + fullNameEsc ) ; spiw . writeData ( v2 , new Section ( origin , values . getShape ( ) ) , values ) ; v2 . invalidateCache ( ) ;


signature:
public class NetcdfFileWriteable { /** * Write String data to a CHAR variable , origin assumed to be 0 . Must not be in define mode .
 * @ param varName name of variable , must be of type CHAR .
 * @ param values write this array ; must be ArrayObject of String
 * @ throws IOException if I / O error
 * @ throws ucar . ma2 . InvalidRangeException if values Array has illegal shape */
public void writeStringData ( String varName , Array values ) throws java . io . IOException , InvalidRangeException { } }

implementation: writeStringData ( varName , new int [ values . getRank ( ) ] , values ) ;


signature:
public class NetcdfFileWriteable { /** * Write String data to a CHAR variable . Must not be in define mode .
 * @ param fullNameEsc name of variable , must be of type CHAR .
 * @ param origin offset to start writing , ignore the strlen dimension .
 * @ param values write this array ; must be ArrayObject of String
 * @ throws IOException if I / O error
 * @ throws ucar . ma2 . InvalidRangeException if values Array has illegal shape */
public void writeStringData ( String fullNameEsc , int [ ] origin , Array values ) throws java . io . IOException , InvalidRangeException { } }

implementation:
if ( values . getElementType ( ) != String . class ) throw new IllegalArgumentException ( "Must be ArrayObject of String " ) ; ucar . nc2 . Variable v2 = findVariable ( fullNameEsc ) ; if ( v2 == null ) throw new IllegalArgumentException ( "illegal variable name = " + fullNameEsc ) ; if ( v2 . getDataType ( ) != DataType . CHAR ) throw new IllegalArgumentException ( "variable " + fullNameEsc + " is not type CHAR" ) ; int rank = v2 . getRank ( ) ; int strlen = v2 . getShape ( rank - 1 ) ; // turn it into an ArrayChar
ArrayChar cvalues = ArrayChar . makeFromStringArray ( ( ArrayObject ) values , strlen ) ; int [ ] corigin = new int [ rank ] ; System . arraycopy ( origin , 0 , corigin , 0 , rank - 1 ) ; write ( fullNameEsc , corigin , cvalues ) ;


signature:
public class NetcdfFileWriteable { /** * close the file .
 * @ throws IOException if I / O error */
@ Override public synchronized void close ( ) throws java . io . IOException { } }

implementation: if ( spiw != null ) { flush ( ) ; spiw . close ( ) ; spiw = null ; } spi = null ;


signature:
public class NetcdfFileWriteable { /** * Add a variable to the file . Must be in define mode .
 * @ param varName name of Variable , must be unique with the file .
 * @ param componentType type of underlying element : String , double or Double , etc .
 * @ param dims array of Dimensions for the variable , must already have been added .
 * @ deprecated use addVariable ( String varName , DataType dataType , ArrayList dims ) ;
 * @ return the Varible added */
public Variable addVariable ( String varName , Class componentType , Dimension [ ] dims ) { } }

implementation: List < Dimension > list = new ArrayList < Dimension > ( ) ; list . addAll ( Arrays . asList ( dims ) ) ; return addVariable ( varName , DataType . getType ( componentType , false ) , list ) ; // LOOK unsigned


signature:
public class GempakSurfaceFileReader { /** * Initialize the file , read in all the metadata ( ala DM _ OPEN )
 * @ param raf RandomAccessFile to read .
 * @ param fullCheck if true , check entire structure
 * @ return A GempakSurfaceFileReader
 * @ throws IOException problem reading file */
public static GempakSurfaceFileReader getInstance ( RandomAccessFile raf , boolean fullCheck ) throws IOException { } }

implementation: GempakSurfaceFileReader gsfr = new GempakSurfaceFileReader ( ) ; gsfr . init ( raf , fullCheck ) ; return gsfr ;


signature:
public class GempakSurfaceFileReader { /** * Initialize this reader . Get the Grid specific info
 * @ param fullCheck check to make sure there are grids we can handle
 * @ return true if successful
 * @ throws IOException problem reading the data */
protected boolean init ( boolean fullCheck ) throws IOException { } }

implementation:
if ( ! super . init ( fullCheck ) ) { return false ; } // Modeled after SF _ OFIL
if ( dmLabel . kftype != MFSF ) { logError ( "not a surface data file " ) ; return false ; } int numParams = 0 ; String partType = ( ( dmLabel . kfsrce == 100 ) && ( dmLabel . kprt == 1 ) ) ? SFTX : SFDT ; DMPart part = getPart ( partType ) ; if ( part == null ) { logError ( "No part named " + partType + " found" ) ; return false ; } else { numParams = part . kparms ; } if ( ! readStationsAndTimes ( true ) ) { logError ( "Unable to read stations and times" ) ; return false ; } // since the reads are ob by ob , set buffer size small
if ( subType . equals ( STANDARD ) ) rf . setBufferSize ( 256 ) ; return true ;


signature:
public class GempakSurfaceFileReader { /** * Set the file subType . */
protected void makeFileSubType ( ) { } }

implementation:
// determine file type
Key key = findKey ( GempakStation . SLAT ) ; if ( key == null ) throw new IllegalStateException ( "File does not have key=" + GempakStation . SLAT ) ; String latType = key . type ; Key dateKey = findKey ( DATE ) ; if ( dateKey != null && ! dateKey . type . equals ( latType ) ) { if ( latType . equals ( ROW ) ) { subType = CLIMATE ; } else { subType = STANDARD ; } } else { subType = SHIP ; }


signature:
public class GempakSurfaceFileReader { /** * Print the list of dates in the file
 * @ param row ob row
 * @ param col ob column */
public void printOb ( int row , int col ) { } }

implementation: int stnIndex = ( getFileSubType ( ) . equals ( CLIMATE ) ) ? row : col ; List < GempakStation > stations = getStations ( ) ; if ( stations . isEmpty ( ) || stnIndex > stations . size ( ) ) { System . out . println ( "\nNo data available" ) ; return ; } GempakStation station = getStations ( ) . get ( stnIndex - 1 ) ; StringBuilder builder = new StringBuilder ( ) ; builder . append ( "\nStation:\n" ) ; builder . append ( station . toString ( ) ) ; builder . append ( "\nObs\n\t" ) ; List < GempakParameter > params = getParameters ( SFDT ) ; for ( GempakParameter parm : params ) { builder . append ( StringUtil2 . padLeft ( parm . getName ( ) , 7 ) ) ; builder . append ( "\t" ) ; } builder . append ( "\n" ) ; RData rd ; try { rd = DM_RDTR ( row , col , SFDT ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; rd = null ; } if ( rd == null ) { builder . append ( "No Data Available" ) ; } else { builder . append ( "\t" ) ; float [ ] data = rd . data ; for ( int i = 0 ; i < data . length ; i ++ ) { builder . append ( StringUtil2 . padLeft ( Format . formatDouble ( data [ i ] , 7 , 1 ) , 7 ) ) ; builder . append ( "\t" ) ; } int [ ] header = rd . header ; if ( header . length > 0 ) { builder . append ( "\nOb Time = " ) ; builder . append ( header [ 0 ] ) ; } } System . out . println ( builder . toString ( ) ) ;


signature:
public class GempakSurfaceFileReader { /** * Run the program
 * @ param args [ 0 ] filename ( required ) ,
 * [ 1 ] variable name ( X for default ) ,
 * [ 2 ] X to not list grids
 * @ throws IOException problem reading the file */
public static void main ( String [ ] args ) throws IOException { } }

implementation:
if ( args . length == 0 ) { System . out . println ( "need to supply a GEMPAK surface file name" ) ; System . exit ( 1 ) ; } try { GempakParameters . addParameters ( "resources/nj22/tables/gempak/params.tbl" ) ; } catch ( Exception e ) { System . out . println ( "unable to init param tables" ) ; } GempakSurfaceFileReader gsfr = getInstance ( getFile ( args [ 0 ] ) , true ) ; System . out . println ( "Type = " + gsfr . getSurfaceFileType ( ) ) ; gsfr . printFileLabel ( ) ; gsfr . printKeys ( ) ; gsfr . printHeaders ( ) ; gsfr . printParts ( ) ; // gsfr . printDates ( ) ;
// gsfr . printStations ( false ) ;
int row = 1 ; int col = 1 ; if ( args . length > 1 ) { row = Integer . parseInt ( args [ 1 ] ) ; } if ( args . length > 2 ) { col = Integer . parseInt ( args [ 2 ] ) ; } gsfr . printOb ( row , col ) ;


signature:
public class WFSGetFeatureWriter { /** * Writes headers and bounding box */
private void writeHeadersAndBB ( ) { } }

implementation:
fileOutput += "<wfs:FeatureCollection xsi:schemaLocation=" + WFSXMLHelper . encQuotes ( "http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd " + namespace + " " + server + "?request=DescribeFeatureType" + WFSXMLHelper . AMPERSAND + "service=wfs" + WFSXMLHelper . AMPERSAND + "version=2.0.0" + WFSXMLHelper . AMPERSAND + "typename=" + WFSController . TDSNAMESPACE + "%3A" + ftName ) + " xmlns:xsi=" + WFSXMLHelper . encQuotes ( "http://www.w3.org/2001/XMLSchema-instance" ) + " xmlns:xlink=" + WFSXMLHelper . encQuotes ( "http://www.w3.org/1999/xlink" ) + " xmlns:gml=" + WFSXMLHelper . encQuotes ( "http://opengis.net/gml/3.2" ) + " xmlns:fes=" + WFSXMLHelper . encQuotes ( "http://www.opengis.net/fes/2.0" ) + " xmlns:ogc=" + WFSXMLHelper . encQuotes ( "http://www.opengis.net/ogc" ) + " xmlns:wfs=" + WFSXMLHelper . encQuotes ( "http://opengis.net/wfs/2.0" ) + " xmlns:" + WFSController . TDSNAMESPACE + "=" + WFSXMLHelper . encQuotes ( namespace ) + " xmlns=" + WFSXMLHelper . encQuotes ( "http://www.opengis.net/wfs/2.0" ) + " version=\"2.0.0\" numberMatched=" + WFSXMLHelper . encQuotes ( String . valueOf ( geometries . size ( ) ) ) + " numberReturned=" + WFSXMLHelper . encQuotes ( String . valueOf ( geometries . size ( ) ) ) + ">" ; double [ ] boundLower ; double [ ] boundUpper ; if ( geometries . isEmpty ( ) ) { boundLower = new double [ 2 ] ; boundUpper = new double [ 2 ] ; boundLower [ 0 ] = - 180 ; boundLower [ 1 ] = - 90 ; boundUpper [ 0 ] = 180 ; boundUpper [ 1 ] = 90 ; } else { boundLower = geometries . get ( 0 ) . getBBLower ( ) ; boundUpper = geometries . get ( 0 ) . getBBUpper ( ) ; } // WFS Bounding Box
for ( SimpleGeometry item : geometries ) { // Find the overall BB
// Test Lower
double [ ] low = item . getBBLower ( ) ; if ( boundLower [ 0 ] > low [ 0 ] ) boundLower [ 0 ] = low [ 0 ] ; if ( boundLower [ 1 ] > low [ 1 ] ) boundLower [ 1 ] = low [ 1 ] ; // Test Upper
double [ ] upper = item . getBBUpper ( ) ; if ( boundUpper [ 0 ] < upper [ 0 ] ) boundUpper [ 0 ] = upper [ 0 ] ; if ( boundUpper [ 1 ] < upper [ 1 ] ) boundUpper [ 1 ] = upper [ 1 ] ; // Add some padding
boundLower [ 0 ] -= 10 ; boundLower [ 1 ] -= 10 ; boundUpper [ 0 ] += 10 ; boundUpper [ 1 ] += 10 ; } fileOutput += "<wfs:boundedBy>" + "<wfs:Envelope srsName=" + "\"urn:ogc:def:crs:EPSG::4326\"" + ">" + "<wfs:lowerCorner>" + boundLower [ 0 ] + " " + boundLower [ 1 ] + "</wfs:lowerCorner>" + "<wfs:upperCorner>" + boundUpper [ 0 ] + " " + boundUpper [ 1 ] + "</wfs:upperCorner>" + "</wfs:Envelope>" + "</wfs:boundedBy>" ;


signature:
public class WFSGetFeatureWriter { /** * In the WFS specification for GetFeature each feature type is its own
 * member and so writeMembers add each member to the fileOutput */
public void writeMembers ( ) { } }

implementation:
int index = 1 ; GMLFeatureWriter writer = new GMLFeatureWriter ( ) ; for ( SimpleGeometry geometryItem : geometries ) { // Find bounding box information
double [ ] lowerCorner = geometryItem . getBBLower ( ) ; double [ ] upperCorner = geometryItem . getBBUpper ( ) ; fileOutput += "<wfs:member>" // Write Geometry Information
+ "<" + WFSController . TDSNAMESPACE + ":" + ftName + " gml:id=\"" + ftName + "." + index + "\">" // GML Bounding Box
+ "<gml:boundedBy>" + "<gml:Envelope srsName=" + "\"urn:ogc:def:crs:EPSG::4326\"" + ">" + "<gml:lowerCorner>" + lowerCorner [ 0 ] + " " + lowerCorner [ 1 ] + "</gml:lowerCorner>" + "<gml:upperCorner>" + upperCorner [ 0 ] + " " + upperCorner [ 1 ] + "</gml:upperCorner>" + "</gml:Envelope>" + "</gml:boundedBy>" + "<" + WFSController . TDSNAMESPACE + ":geometryInformation>" ; // write GML features
fileOutput += writer . writeFeature ( geometryItem ) ; // Cap off headers
fileOutput += "</" + WFSController . TDSNAMESPACE + ":geometryInformation>" + "</" + WFSController . TDSNAMESPACE + ":" + ftName + ">" + "</wfs:member>" ; index ++ ; }


signature:
public class StationObsDatasetInfo { /** * Write stationObsDataset XML document */
public String writeStationObsDatasetXML ( ) { } }

implementation: XMLOutputter fmt = new XMLOutputter ( Format . getPrettyFormat ( ) ) ; return fmt . outputString ( makeStationObsDatasetDocument ( ) ) ;


signature:
public class StationObsDatasetInfo { /** * Write stationCollection XML document */
public String writeStationCollectionXML ( ) throws IOException { } }

implementation: XMLOutputter fmt = new XMLOutputter ( Format . getPrettyFormat ( ) ) ; return fmt . outputString ( makeStationCollectionDocument ( ) ) ;


signature:
public class StationObsDatasetInfo { /** * Create an XML document from this info */
public Document makeStationCollectionDocument ( ) throws IOException { } }

implementation: Element rootElem = new Element ( "stationCollection" ) ; Document doc = new Document ( rootElem ) ; List stns = sobs . getStations ( ) ; System . out . println ( "nstns = " + stns . size ( ) ) ; for ( int i = 0 ; i < stns . size ( ) ; i ++ ) { ucar . unidata . geoloc . Station s = ( ucar . unidata . geoloc . Station ) stns . get ( i ) ; Element sElem = new Element ( "station" ) ; sElem . setAttribute ( "name" , s . getName ( ) ) ; if ( s . getWmoId ( ) != null ) sElem . setAttribute ( "wmo_id" , s . getWmoId ( ) ) ; if ( s . getDescription ( ) != null ) sElem . addContent ( new Element ( "description" ) . addContent ( s . getDescription ( ) ) ) ; sElem . addContent ( new Element ( "longitude" ) . addContent ( ucar . unidata . util . Format . d ( s . getLongitude ( ) , 6 ) ) ) ; sElem . addContent ( new Element ( "latitide" ) . addContent ( ucar . unidata . util . Format . d ( s . getLatitude ( ) , 6 ) ) ) ; if ( ! Double . isNaN ( s . getAltitude ( ) ) ) sElem . addContent ( new Element ( "altitude" ) . addContent ( ucar . unidata . util . Format . d ( s . getAltitude ( ) , 6 ) ) ) ; rootElem . addContent ( sElem ) ; } return doc ;


signature:
public class StationObsDatasetInfo { /** * Create an XML document from this info */
public Document makeStationObsDatasetDocument ( ) { } }

implementation:
Element rootElem = new Element ( "stationObsDataset" ) ; Document doc = new Document ( rootElem ) ; rootElem . setAttribute ( "location" , sobs . getLocationURI ( ) ) ; if ( null != path ) rootElem . setAttribute ( "path" , path ) ; /* dimensions
 List dims = getDimensions ( sobs ) ;
 for ( int j = 0 ; j < dims . size ( ) ; j + + ) {
 Dimension dim = ( Dimension ) dims . get ( j ) ;
 rootElem . addContent ( ucar . nc2 . ncml . NcMLWriter . writeDimension ( dim , null ) ) ; */
/* coordinate axes
 List coordAxes = getCoordAxes ( sobs ) ;
 for ( int i = 0 ; i < coordAxes . size ( ) ; i + + ) {
 CoordinateAxis axis = ( CoordinateAxis ) coordAxes . get ( i ) ;
 rootElem . addContent ( writeAxis ( axis ) ) ; */
// grids
List vars = sobs . getDataVariables ( ) ; Collections . sort ( vars ) ; for ( int i = 0 ; i < vars . size ( ) ; i ++ ) { VariableSimpleIF v = ( VariableSimpleIF ) vars . get ( i ) ; rootElem . addContent ( writeVariable ( v ) ) ; } /* global attributes
 Iterator atts = sobs . getGlobalAttributes ( ) . iterator ( ) ;
 while ( atts . hasNext ( ) ) {
 ucar . nc2 . Attribute att = ( ucar . nc2 . Attribute ) atts . next ( ) ;
 rootElem . addContent ( ucar . nc2 . ncml . NcMLWriter . writeAttribute ( att , " attribute " , null ) ) ; */
// add lat / lon bounding box
LatLonRect bb = sobs . getBoundingBox ( ) ; if ( bb != null ) rootElem . addContent ( writeBoundingBox ( bb ) ) ; // add date range
Date start = sobs . getStartDate ( ) ; Date end = sobs . getEndDate ( ) ; if ( ( start != null ) && ( end != null ) ) { DateFormatter format = new DateFormatter ( ) ; Element dateRange = new Element ( "TimeSpan" ) ; dateRange . addContent ( new Element ( "begin" ) . addContent ( format . toDateTimeStringISO ( start ) ) ) ; dateRange . addContent ( new Element ( "end" ) . addContent ( format . toDateTimeStringISO ( end ) ) ) ; rootElem . addContent ( dateRange ) ; } // add accept list
Element elem = new Element ( "AcceptList" ) ; elem . addContent ( new Element ( "accept" ) . addContent ( "raw" ) ) ; elem . addContent ( new Element ( "accept" ) . addContent ( "xml" ) ) ; elem . addContent ( new Element ( "accept" ) . addContent ( "csv" ) ) ; elem . addContent ( new Element ( "accept" ) . addContent ( "netcdf" ) ) ; elem . addContent ( new Element ( "accept" ) . addContent ( "netcdfStream" ) ) ; rootElem . addContent ( elem ) ; return doc ;


signature:
public class StationObsDatasetInfo { /** * debug */
public static void main ( String args [ ] ) throws IOException { } }

implementation: String url = "C:/data/metars/Surface_METAR_20060326_0000.nc" ; StationObsDataset ncd = ( StationObsDataset ) TypedDatasetFactory . open ( FeatureType . STATION , url , null , new StringBuilder ( ) ) ; StationObsDatasetInfo info = new StationObsDatasetInfo ( ncd , null ) ; FileOutputStream fos2 = new FileOutputStream ( "C:/TEMP/stationCollection.xml" ) ; GZIPOutputStream zout = new GZIPOutputStream ( fos2 ) ; info . writeStationObsDatasetXML ( System . out ) ; info . writeStationCollectionXML ( zout ) ; zout . close ( ) ; File f = new File ( "C:/TEMP/stationCollection.xml" ) ; System . out . println ( " size=" + f . length ( ) ) ;


signature:
public class ChunkWriter { /** * Write the DSR ; do not bother to cache .
 * @ param dsr The DSR string
 * @ throws IOException on IO related errors */
public void writeDSR ( String dsr ) throws IOException { } }

implementation:
if ( state != State . INITIAL ) throw new DapException ( "Attempt to write DSR twice" ) ; if ( dsr == null ) throw new DapException ( "Attempt to write empty DSR" ) ; // Strip off any trailing sequence of CR or LF .
int len = dsr . length ( ) ; while ( len > 0 ) { char c = dsr . charAt ( len - 1 ) ; if ( c != '\r' && c != '\n' ) break ; len -- ; } if ( dsr . length ( ) == 0 ) throw new DapException ( "Attempt to write empty DSR" ) ; dsr = dsr . substring ( 0 , len ) + DapUtil . CRLF ; // Add < ? xml . . . ? > prefix
dsr = XMLDOCUMENTHEADER + "\n" + dsr ; // Convert the dsr to UTF - 8 and then to byte [ ]
byte [ ] dsr8 = DapUtil . extract ( DapUtil . UTF8 . encode ( dsr ) ) ; sendDXR ( dsr8 ) ; state = State . END ;


signature:
public class ChunkWriter { /** * Cache the DMR . What it really does is
 * cache the DMR and write it at the point
 * where it is needed ; either in close ( ) , if writing
 * the DMR only , or in writeChunk ( ) if writing data as well .
 * @ param dmr The DMR string
 * @ throws IOException on IO related errors */
public void cacheDMR ( String dmr ) throws IOException { } }

implementation:
if ( state != State . INITIAL ) throw new DapException ( "Attempt to write DMR twice" ) ; if ( dmr == null ) throw new DapException ( "Attempt to write empty DMR" ) ; // Strip off any trailing sequence of CR or LF .
int len = dmr . length ( ) ; while ( len > 0 ) { char c = dmr . charAt ( len - 1 ) ; if ( c != '\r' && c != '\n' ) break ; len -- ; } if ( dmr . length ( ) == 0 ) throw new DapException ( "Attempt to write empty DMR" ) ; dmr = dmr . substring ( 0 , len ) + DapUtil . CRLF ; // Prepend the < ? xml . . . ? > prefix
dmr = XMLDOCUMENTHEADER + "\n" + dmr ; // Convert the dmr to UTF - 8 and then to byte [ ]
this . dmr8 = DapUtil . extract ( DapUtil . UTF8 . encode ( dmr ) ) ; state = State . DMR ;


signature:
public class ChunkWriter { /** * Output the specifiedd DMR or DSR or . . . , but xml only .
 * @ throws IOException on IO related errors */
void sendDXR ( byte [ ] dxr8 ) throws IOException { } }

implementation:
if ( dxr8 == null || dxr8 . length == 0 ) return ; // do nothing
if ( mode == RequestMode . DMR || mode == RequestMode . DSR ) { state = State . END ; } else { // mode = = DATA
// Prefix with chunk header
int flags = DapUtil . CHUNK_DATA ; if ( this . writeorder == ByteOrder . LITTLE_ENDIAN ) flags |= DapUtil . CHUNK_LITTLE_ENDIAN ; chunkheader ( dxr8 . length , flags , this . header ) ; // write the header
output . write ( DapUtil . extract ( this . header ) ) ; state = State . DATA ; } // write the DXR
output . write ( dxr8 ) ; output . flush ( ) ;


signature:
public class ChunkWriter { /** * Write an error chunk .
 * If mode = = DMR then replaces the dmr
 * else reset the current chunk thus
 * losing any partial write .
 * @ param httpcode The httpcode , 0 = > ignore
 * @ param msg The < Error > < Message > , null = > ignore
 * @ param cxt The < Error > < Context > , null = > ignore
 * @ param other The < Error > < OtherInformation > , null = > ignore
 * @ throws IOException on IO related errors */
public void writeError ( int httpcode , String msg , String cxt , String other ) throws IOException { } }

implementation:
dmr8 = null ; ErrorResponse response = new ErrorResponse ( httpcode , msg , cxt , other ) ; String errorbody = response . buildXML ( ) ; // Convert the error body into utf8 then to byte [ ]
byte [ ] errbody8 = DapUtil . extract ( DapUtil . UTF8 . encode ( errorbody ) ) ; if ( mode == RequestMode . DMR ) { sendDXR ( errbody8 ) ; } else { // mode = = DATA
// clear any partial chunk
chunk . clear ( ) ; // create an error header
int flags = DapUtil . CHUNK_ERROR | DapUtil . CHUNK_END ; chunkheader ( errbody8 . length , flags , header ) ; output . write ( DapUtil . extract ( header ) ) ; output . write ( errbody8 ) ; output . flush ( ) ; } state = State . ERROR ;


signature:
public class ChunkWriter { /** * Write out the current chunk ( with given set of flags ) .
 * @ param flags The flags for the header
 * @ throws IOException on IO related errors */
void writeChunk ( int flags ) throws IOException { } }

implementation:
// If flags indicate CHUNK _ END
// and amount to write is zero ,
// go ahead and write the zero size chunk .
if ( chunk == null ) chunk = ByteBuffer . allocate ( maxbuffersize ) ; int buffersize = chunk . position ( ) ; chunkheader ( buffersize , flags , header ) ; // output the header followed by the data ( if any )
// Zero size chunk is ok .
output . write ( DapUtil . extract ( header ) ) ; if ( buffersize > 0 ) output . write ( chunk . array ( ) , 0 , buffersize ) ; chunk . clear ( ) ; // reset


signature:
public class ChunkWriter { /** * Closes this output stream and releases any system resources
 * associated with this stream . Except , the underlying stream is not
 * actually closed ; that is left to the servlet level
 * @ throws IOException on IO related errors */
public void close ( ) throws IOException { } }

implementation:
if ( closed ) return ; closed = true ; if ( dmr8 != null ) { sendDXR ( dmr8 ) ; dmr8 = null ; } if ( mode == RequestMode . DMR ) return ; // only DMR should be sent
// If there is no partial chunk to write then
// we are done ; else verify we can write and write the last
// chunk ; = > multiple closes are ok .
if ( chunk == null || chunk . position ( ) == 0 ) return ; // There is data left to write .
verifystate ( ) ; // are we in a state supporting data write ?
// Force out the current chunk ( might be empty )
// but do not close the underlying output stream
state = State . DATA ; // pretend
int flags = DapUtil . CHUNK_END ; writeChunk ( flags ) ; state = State . END ; this . output . flush ( ) ; // Do not close
if ( this . saveoutput != null ) { // write to true output target
this . saveoutput . write ( ( ( ByteArrayOutputStream ) this . output ) . toByteArray ( ) ) ; }


signature:
public class ChunkWriter { /** * Overload flush to also write out the DMR
 * @ throws IOException */
@ Override public void flush ( ) throws IOException { } }

implementation:
if ( mode == RequestMode . DMR ) return ; // leave to close ( ) to do this
if ( dmr8 != null ) { sendDXR ( dmr8 ) ; dmr8 = null ; }


signature:
public class ChunkWriter { /** * Writes len bytes from the specified byte array starting at
 * offset off to this output stream .
 * If this write fills up the chunk buffer ,
 * then write out the buffer and put
 * the remaining bytes into the reset buffer .
 * @ param b the data
 * @ param off start point in b from which to write data
 * @ param len number of bytes to write
 * @ throws IOException if an I / O error occurs */
@ Override public void write ( byte [ ] b , int off , int len ) throws IOException { } }

implementation:
verifystate ( ) ; if ( writecount + len >= writelimit ) throw new DapException ( "Attempt to write too much data: limit=" + writecount + len ) . setCode ( DapCodes . SC_REQUESTED_RANGE_NOT_SATISFIABLE ) ; if ( chunk == null ) chunk = ByteBuffer . allocate ( maxbuffersize ) . order ( getWriteOrder ( ) ) ; if ( state == State . DMR ) { chunk . clear ( ) ; // reset
state = State . DATA ; } assert ( state == State . DATA ) ; if ( b . length < off + len ) throw new BufferUnderflowException ( ) ; int left = len ; int offset = off ; while ( left > 0 ) { int avail = chunk . remaining ( ) ; do { if ( avail == 0 ) { writeChunk ( DapUtil . CHUNK_DATA ) ; avail = chunk . remaining ( ) ; } int towrite = ( left < avail ? left : avail ) ; chunk . put ( b , off , towrite ) ; left -= towrite ; avail -= towrite ; } while ( left > 0 ) ; } writecount += len ;


signature:
public class UtmProjection { /** * needed for constructCopy */
@ Override public ProjectionImpl constructCopy ( ) { } }

implementation: ProjectionImpl result = ( saveParams == null ) ? new UtmProjection ( getZone ( ) , isNorth ( ) ) : new UtmProjection ( saveParams . a , saveParams . f , getZone ( ) , isNorth ( ) ) ; result . setDefaultMapArea ( defaultMapArea ) ; result . setName ( name ) ; return result ;


signature:
public class UtmProjection { /** * 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: double fromLat = latLon . getLatitude ( ) ; double fromLon = latLon . getLongitude ( ) ; return convert2xy . latLonToProj ( fromLat , fromLon , result ) ;


signature:
public class UtmProjection { /** * 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 convert2latlon . projToLatLon ( world . getX ( ) , world . getY ( ) , result ) ;


signature:
public class UtmProjection { /** * roszelld @ usgs . gov
 * ' m transforming coordinates ( which are in UTM Zone 17N projection ) to
 * lat / lon .
 * If I get the ProjectionImpl from the grid ( stage ) and use the projToLatLon
 * function with { { 577.8000001 } , { 2951.8 } } in kilometers for example , I
 * get { { 26.553706785076937 } , { - 80.21754983617633 } } , which is not very
 * accurate at all when I plot them .
 * If I use GeoTools to build a transform based on the same projection
 * parameters read from the projectionimpl , I get { { 26.685132668190793 } ,
 * { - 80.21802662821469 } } which appears to be MUCH more accurate when I plot
 * them on a map . */
public static void main ( String arg [ ] ) { } }

implementation: UtmProjection utm = new UtmProjection ( 17 , true ) ; LatLonPoint ll = utm . projToLatLon ( 577.8000000000001 , 2951.8 ) ; System . out . printf ( "%15.12f %15.12f%n" , ll . getLatitude ( ) , ll . getLongitude ( ) ) ; assert Misc . nearlyEquals ( ll . getLongitude ( ) , - 80.21802662821469 , 1.0e-8 ) ; assert Misc . nearlyEquals ( ll . getLatitude ( ) , 26.685132668190793 , 1.0e-8 ) ;


signature:
public class StationImpl { /** * got to use this or subclass readObservations ( ) */
public void addObs ( StationObsDatatype sobs ) { } }

implementation: if ( null == obsList ) obsList = new ArrayList < StationObsDatatype > ( ) ; obsList . add ( sobs ) ;


signature:
public class CollectionUpdater { /** * Look at config and decide if tasks need to be started */
public void scheduleTasks ( FeatureCollectionConfig config , Logger logger ) { } }

implementation:
if ( disabled || failed ) return ; if ( logger == null ) logger = fcLogger ; FeatureCollectionConfig . UpdateConfig updateConfig = ( isTdm ) ? config . tdmConfig : config . updateConfig ; if ( updateConfig == null || updateConfig . updateType == CollectionUpdateType . never ) return ; String collectionName = config . getCollectionName ( ) ; // prob dont need to set a job if theres no chron job ?
// Job to update the collection
org . quartz . JobDataMap map = new org . quartz . JobDataMap ( ) ; map . put ( EVENT_BUS , eventBus ) ; map . put ( COLLECTION_NAME , collectionName ) ; map . put ( LOGGER , logger ) ; JobDetail updateJob = JobBuilder . newJob ( UpdateCollectionJob . class ) . withIdentity ( collectionName , "UpdateCollection" ) . storeDurably ( ) . usingJobData ( map ) . build ( ) ; try { if ( ! scheduler . checkExists ( updateJob . getKey ( ) ) ) { scheduler . addJob ( updateJob , false ) ; } else { logger . warn ( "scheduler failed to add updateJob for " + updateJob . getKey ( ) + ". Another Job exists with that identification." ) ; } } catch ( Throwable e ) { logger . error ( "scheduler failed to add updateJob for " + config , e ) ; return ; } // task to run the job on startup
if ( updateConfig . startupType != CollectionUpdateType . never ) { map = new org . quartz . JobDataMap ( ) ; map . put ( UpdateType , updateConfig . startupType ) ; map . put ( Source , "startup" ) ; Date runTime = new Date ( new Date ( ) . getTime ( ) + startupWait ) ; // wait startupWait before trigger
SimpleTrigger startupTrigger = ( SimpleTrigger ) TriggerBuilder . newTrigger ( ) . withIdentity ( collectionName , "startup" ) . startAt ( runTime ) . forJob ( updateJob ) . usingJobData ( map ) . build ( ) ; try { scheduler . scheduleJob ( startupTrigger ) ; logger . info ( "scheduleJob startup scan force={} for '{}' at {}" , updateConfig . startupType . toString ( ) , config . collectionName , runTime ) ; } catch ( Throwable e ) { logger . error ( "scheduleJob failed to schedule startup Job for " + config , e ) ; return ; } } // task to run the job periodically , with rescan
if ( updateConfig . rescan != null ) { map = new org . quartz . JobDataMap ( ) ; map . put ( UpdateType , updateConfig . updateType ) ; map . put ( Source , "rescan" ) ; CronTrigger rescanTrigger = TriggerBuilder . newTrigger ( ) . withIdentity ( collectionName , "rescan" ) . withSchedule ( CronScheduleBuilder . cronSchedule ( updateConfig . rescan ) ) . forJob ( updateJob ) . usingJobData ( map ) . build ( ) ; try { scheduler . scheduleJob ( rescanTrigger ) ; logger . info ( "scheduleJob recurring scan for '{}' cronExpr={}" , config . collectionName , updateConfig . rescan ) ; } catch ( Throwable e ) { logger . error ( "scheduleJob failed to schedule cron Job" , e ) ; // e . printStackTrace ( ) ;
} } /* updating the proto dataset
 FeatureCollectionConfig . ProtoConfig pconfig = config . protoConfig ;
 if ( pconfig . change ! = null ) {
 org . quartz . JobDataMap pmap = new org . quartz . JobDataMap ( ) ;
 pmap . put ( DCM _ NAME , manager ) ;
 map . put ( LOGGER , logger ) ;
 JobDetail protoJob = JobBuilder . newJob ( ChangeProtoJob . class )
 . withIdentity ( jobName , " UpdateProto " )
 . usingJobData ( pmap )
 . storeDurably ( )
 . build ( ) ;
 try {
 CronTrigger protoTrigger = TriggerBuilder . newTrigger ( )
 . withIdentity ( jobName , " rereadProto " )
 . withSchedule ( CronScheduleBuilder . cronSchedule ( pconfig . change ) )
 . build ( ) ;
 scheduler . scheduleJob ( protoJob , protoTrigger ) ;
 if ( logger ! = null ) logger . info ( " Schedule proto update for ' { } ' cronExpr = { } " , config . collectionName , pconfig . change ) ;
 } catch ( Throwable e ) {
 if ( logger ! = null ) logger . error ( " cronExecutor failed to schedule RereadProtoJob " , e ) ;
 / / e . printStackTrace ( ) ; */


signature:
public class Range { /** * Is want contained in this Range ?
 * @ param want index in the original Range
 * @ return true if the ith element would be returned by the Range iterator */
public boolean contains ( int want ) { } }

implementation: if ( want < first ( ) ) return false ; if ( want > last ( ) ) return false ; if ( stride == 1 ) return true ; return ( want - first ) % stride == 0 ;


signature:
public class Range { /** * Create a new Range by composing a Range that is reletive to this Range .
 * Revised 2013/04/19 by Dennis Heimbigner to handle edge cases .
 * See the commentary associated with the netcdf - c file dceconstraints . h ,
 * function dceslicecompose ( ) .
 * @ param r range reletive to base
 * @ return combined Range , may be EMPTY
 * @ throws InvalidRangeException elements must be nonnegative , 0 < = first < = last */
public Range compose ( Range r ) throws InvalidRangeException { } }

implementation:
if ( ( length ( ) == 0 ) || ( r . length ( ) == 0 ) ) return EMPTY ; if ( this == VLEN || r == VLEN ) return VLEN ; /* if ( false ) { / / Original version
 / / Note that this version assumes that range r is
 / / correct with respect to this .
 int first = element ( r . first ( ) ) ;
 int stride = stride ( ) * r . stride ( ) ;
 int last = element ( r . last ( ) ) ;
 return new Range ( name , first , last , stride ) ;
 } else { / / new version : handles versions all values of r . */
int sr_stride = this . stride * r . stride ; int sr_first = element ( r . first ( ) ) ; // MAP ( this , i ) = = element ( i )
int lastx = element ( r . last ( ) ) ; int sr_last = ( last ( ) < lastx ? last ( ) : lastx ) ; // min ( last ( ) , lastx )
// unused int sr _ length = ( sr _ last + 1 ) - sr _ first ;
return new Range ( name , sr_first , sr_last , sr_stride ) ;


signature:
public class Range { /** * Create a new Range by compacting this Range by removing the stride .
 * first = first / stride , last = last / stride , stride = 1.
 * @ return compacted Range
 * @ throws InvalidRangeException elements must be nonnegative , 0 < = first < = last */
public Range compact ( ) throws InvalidRangeException { } }

implementation:
if ( stride == 1 ) return this ; int first = first ( ) / stride ; // LOOK WTF ?
int last = first + length ( ) - 1 ; return new Range ( name , first , last , 1 ) ;


signature:
public class Range { /** * Get ith element
 * @ param i index of the element
 * @ return the i - th element of a range .
 * @ throws InvalidRangeException i must be : 0 < = i < length */
public int element ( int i ) throws InvalidRangeException { } }

implementation: if ( i < 0 ) throw new InvalidRangeException ( "i must be >= 0" ) ; if ( i >= length ) throw new InvalidRangeException ( "i must be < length" ) ; return first + i * stride ;


signature:
public class Range { /** * Get the index for this element : inverse of element
 * @ param want the element of the range
 * @ return index
 * @ throws InvalidRangeException if illegal elem */
public int index ( int want ) throws InvalidRangeException { } }

implementation: if ( want < first ) throw new InvalidRangeException ( "elem must be >= first" ) ; int result = ( want - first ) / stride ; if ( result > length ) throw new InvalidRangeException ( "elem must be <= first = n * stride" ) ; return result ;


signature:
public class Range { /** * Create a new Range by intersecting with a Range using same interval as this Range .
 * NOTE : we dont yet support intersection when both Ranges have strides
 * @ param r range to intersect
 * @ return intersected Range , may be EMPTY
 * @ throws InvalidRangeException elements must be nonnegative */
public Range intersect ( Range r ) throws InvalidRangeException { } }

implementation:
if ( ( length ( ) == 0 ) || ( r . length ( ) == 0 ) ) return EMPTY ; if ( this == VLEN || r == VLEN ) return VLEN ; int last = Math . min ( this . last ( ) , r . last ( ) ) ; int resultStride = stride * r . stride ( ) ; int useFirst ; if ( resultStride == 1 ) { // both strides are 1
useFirst = Math . max ( this . first ( ) , r . first ( ) ) ; } else if ( stride == 1 ) { // then r has a stride
if ( r . first ( ) >= first ( ) ) useFirst = r . first ( ) ; else { int incr = ( first ( ) - r . first ( ) ) / resultStride ; useFirst = r . first ( ) + incr * resultStride ; if ( useFirst < first ( ) ) useFirst += resultStride ; } } else if ( r . stride == 1 ) { // then this has a stride
if ( first ( ) >= r . first ( ) ) useFirst = first ( ) ; else { int incr = ( r . first ( ) - first ( ) ) / resultStride ; useFirst = first ( ) + incr * resultStride ; if ( useFirst < r . first ( ) ) useFirst += resultStride ; } } else { throw new UnsupportedOperationException ( "Intersection when both ranges have a stride" ) ; } if ( useFirst > last ) return EMPTY ; return new Range ( name , useFirst , last , resultStride ) ;


signature:
public class Range { /** * Determine if a given Range intersects this one .
 * NOTE : we dont yet support intersection when both Ranges have strides
 * @ param r range to intersect
 * @ return true if they intersect
 * @ throws UnsupportedOperationException if both Ranges have strides */
public boolean intersects ( Range r ) { } }

implementation:
if ( ( length ( ) == 0 ) || ( r . length ( ) == 0 ) ) return false ; if ( this == VLEN || r == VLEN ) return true ; int last = Math . min ( this . last ( ) , r . last ( ) ) ; int resultStride = stride * r . stride ( ) ; int useFirst ; if ( resultStride == 1 ) { // both strides are 1
useFirst = Math . max ( this . first ( ) , r . first ( ) ) ; } else if ( stride == 1 ) { // then r has a stride
if ( r . first ( ) >= first ( ) ) useFirst = r . first ( ) ; else { int incr = ( first ( ) - r . first ( ) ) / resultStride ; useFirst = r . first ( ) + incr * resultStride ; if ( useFirst < first ( ) ) useFirst += resultStride ; } } else if ( r . stride ( ) == 1 ) { // then this has a stride
if ( first ( ) >= r . first ( ) ) useFirst = first ( ) ; else { int incr = ( r . first ( ) - first ( ) ) / resultStride ; useFirst = first ( ) + incr * resultStride ; if ( useFirst < r . first ( ) ) useFirst += resultStride ; } } else { throw new UnsupportedOperationException ( "Intersection when both ranges have a stride" ) ; } return ( useFirst <= last ) ;


signature:
public class Range { /** * Create a new Range shifting this range by a constant factor .
 * @ param origin subtract this from each element
 * @ return shifted range
 * @ throws InvalidRangeException elements must be nonnegative , 0 < = first < = last */
public Range shiftOrigin ( int origin ) throws InvalidRangeException { } }

implementation: if ( this == VLEN ) return VLEN ; int first = first ( ) - origin ; int last = last ( ) - origin ; return new Range ( name , first , last , stride ) ;


signature:
public class Range { /** * Create a new Range by making the union with a Range using same interval as this Range .
 * NOTE : no strides
 * @ param r range to add
 * @ return intersected Range , may be EMPTY
 * @ throws InvalidRangeException elements must be nonnegative */
public Range union ( Range r ) throws InvalidRangeException { } }

implementation: if ( length ( ) == 0 ) return r ; if ( this == VLEN || r == VLEN ) return VLEN ; if ( r . length ( ) == 0 ) return this ; int first = Math . min ( this . first ( ) , r . first ( ) ) ; int last = Math . max ( this . last ( ) , r . last ( ) ) ; return new Range ( name , first , last ) ;


signature:
public class Range { /** * Find the first element in a strided array after some index start .
 * Return the smallest element k in the Range , such that < ul >
 * < li > k > = first
 * < li > k > = start
 * < li > k < = last
 * < li > k = element of this Range
 * < / ul >
 * @ param start starting index
 * @ return first in interval , else - 1 if there is no such element . */
public int getFirstInInterval ( int start ) { } }

implementation:
if ( start > last ( ) ) return - 1 ; if ( start <= first ) return first ; if ( stride == 1 ) return start ; int offset = start - first ; int i = offset / stride ; i = ( offset % stride == 0 ) ? i : i + 1 ; // round up
return first + i * stride ;


signature:
public class ArrayLong { /** * package private . use Array . factory ( ) */
static ArrayLong factory ( Index index , boolean isUnsigned ) { } }

implementation: return ArrayLong . factory ( index , isUnsigned , null ) ;


signature:
public class ArrayLong { /** * copy from javaArray to storage using the iterator : used by factory ( Object ) ; */
protected void copyFrom1DJavaArray ( IndexIterator iter , Object javaArray ) { } }

implementation: long [ ] ja = ( long [ ] ) javaArray ; for ( long aJa : ja ) iter . setLongNext ( aJa ) ;


signature:
public class N3raf { /** * Read data subset from file for a variable , create primitive array .
 * @ param index handles skipping around in the file .
 * @ param dataType dataType of the variable
 * @ return primitive array with data read in */
protected Object readData ( Layout index , DataType dataType ) throws java . io . IOException { } }

implementation: return IospHelper . readDataFill ( raf , index , dataType , null , - 1 ) ;


signature:
public class N3raf { /** * Read data subset from file for a variable , to WritableByteChannel .
 * Will send as bigendian , since thats what the underlying file has .
 * @ param index handles skipping around in the file .
 * @ param dataType dataType of the variable */
protected long readData ( Layout index , DataType dataType , WritableByteChannel out ) throws java . io . IOException { } }

implementation: long count = 0 ; if ( dataType . getPrimitiveClassType ( ) == byte . class || dataType == DataType . CHAR ) { while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; count += raf . readToByteChannel ( out , chunk . getSrcPos ( ) , chunk . getNelems ( ) ) ; } } else if ( dataType . getPrimitiveClassType ( ) == short . class ) { while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; count += raf . readToByteChannel ( out , chunk . getSrcPos ( ) , 2 * chunk . getNelems ( ) ) ; } } else if ( dataType . getPrimitiveClassType ( ) == int . class || ( dataType == DataType . FLOAT ) ) { while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; count += raf . readToByteChannel ( out , chunk . getSrcPos ( ) , 4 * chunk . getNelems ( ) ) ; } } else if ( ( dataType == DataType . DOUBLE ) || dataType . getPrimitiveClassType ( ) == long . class ) { while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; count += raf . readToByteChannel ( out , chunk . getSrcPos ( ) , 8 * chunk . getNelems ( ) ) ; } } return count ;


signature:
public class N3raf { /** * write data to a file for a variable .
 * @ param values write this data .
 * @ param index handles skipping around in the file .
 * @ param dataType dataType of the variable */
protected void writeData ( Array values , Layout index , DataType dataType ) throws java . io . IOException { } }

implementation:
if ( ( dataType == DataType . BYTE ) || ( dataType == DataType . CHAR ) ) { IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) raf . write ( ii . getByteNext ( ) ) ; } return ; } else if ( dataType == DataType . STRING ) { // LOOK not legal
IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) { String val = ( String ) ii . getObjectNext ( ) ; if ( val != null ) raf . write ( val . getBytes ( CDM . utf8Charset ) ) ; // LOOK ? ?
} } return ; } else if ( dataType == DataType . SHORT ) { IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) raf . writeShort ( ii . getShortNext ( ) ) ; } return ; } else if ( dataType == DataType . INT ) { IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) raf . writeInt ( ii . getIntNext ( ) ) ; } return ; } else if ( dataType == DataType . FLOAT ) { IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) raf . writeFloat ( ii . getFloatNext ( ) ) ; } return ; } else if ( dataType == DataType . DOUBLE ) { IndexIterator ii = values . getIndexIterator ( ) ; while ( index . hasNext ( ) ) { Layout . Chunk chunk = index . next ( ) ; raf . seek ( chunk . getSrcPos ( ) ) ; for ( int k = 0 ; k < chunk . getNelems ( ) ; k ++ ) raf . writeDouble ( ii . getDoubleNext ( ) ) ; } return ; } throw new IllegalStateException ( "dataType= " + dataType ) ;


signature:
public class Madis { /** * < ! - - C : / data / dt2 / station / madis2 . sao - - >
 * < stationCollection >
 * < table dim = " maxStaticIds " limit = " nStaticIds " >
 * < lastLink > lastRecord < / lastLink >
 * < table dim = " recNum " >
 * < stationId > : stationIdVariable < / stationId >
 * < stationWmoId > wmoId < / stationWmoId >
 * < coordAxis type = " time " > timeObs < / coordAxis >
 * < coordAxis type = " lat " > latitude < / coordAxis >
 * < coordAxis type = " lon " > longitude < / coordAxis >
 * < coordAxis type = " height " > elevation < / coordAxis >
 * < prevLink > prevRecord < / prevLink >
 * < / table >
 * < / table >
 * < cdmDataType > : thredds _ data _ type < / cdmDataType >
 * < / stationCollection > */
public TableConfig getConfig ( FeatureType wantFeatureType , NetcdfDataset ds , Formatter errlog ) { } }

implementation:
Dimension obsDim = Evaluator . getDimension ( ds , "recNum" , errlog ) ; if ( obsDim == null ) { errlog . format ( "MADIS: must have an Observation dimension: named recNum" ) ; return null ; } VNames vn = getVariableNames ( ds , errlog ) ; String levVarName = null ; String levDimName = null ; boolean hasStruct = Evaluator . hasNetcdf3RecordStructure ( ds ) ; FeatureType ft = Evaluator . getFeatureType ( ds , ":thredds_data_type" , errlog ) ; if ( null == ft ) { if ( ( ds . findDimension ( "manLevel" ) != null ) && ( ds . findVariable ( "prMan" ) != null ) ) { ft = FeatureType . STATION_PROFILE ; levVarName = "prMan" ; levDimName = "manLevel" ; } else if ( ( ds . findDimension ( "level" ) != null ) && ( ds . findVariable ( "levels" ) != null ) ) { ft = FeatureType . STATION_PROFILE ; levVarName = "levels" ; levDimName = "level" ; } } if ( null == ft ) ft = FeatureType . POINT ; // points
if ( ( wantFeatureType == FeatureType . POINT ) || ( ft == FeatureType . POINT ) ) { TableConfig ptTable = new TableConfig ( Table . Type . Structure , hasStruct ? "record" : obsDim . getShortName ( ) ) ; ptTable . structName = "record" ; ptTable . featureType = FeatureType . POINT ; ptTable . structureType = hasStruct ? TableConfig . StructureType . Structure : TableConfig . StructureType . PsuedoStructure ; ptTable . dimName = obsDim . getShortName ( ) ; ptTable . time = vn . obsTime ; ptTable . timeNominal = vn . nominalTime ; ptTable . lat = vn . lat ; ptTable . lon = vn . lon ; ptTable . elev = vn . elev ; return ptTable ; } if ( ft == FeatureType . STATION ) { TableConfig stnTable = new TableConfig ( Table . Type . Construct , "station" ) ; stnTable . featureType = FeatureType . STATION ; TableConfig obs = new TableConfig ( Table . Type . ParentId , "record" ) ; obs . parentIndex = vn . stnId ; obs . dimName = Evaluator . getDimensionName ( ds , "recNum" , errlog ) ; obs . time = vn . obsTime ; obs . timeNominal = vn . nominalTime ; obs . stnId = vn . stnId ; obs . stnDesc = vn . stnDesc ; obs . lat = vn . lat ; obs . lon = vn . lon ; obs . elev = vn . elev ; stnTable . addChild ( obs ) ; return stnTable ; } else if ( ft == FeatureType . STATION_PROFILE ) { TableConfig stnTable = new TableConfig ( Table . Type . Construct , "station" ) ; stnTable . featureType = FeatureType . STATION_PROFILE ; TableConfig obs = new TableConfig ( Table . Type . ParentId , "record" ) ; obs . parentIndex = vn . stnId ; obs . dimName = Evaluator . getDimensionName ( ds , "recNum" , errlog ) ; obs . time = vn . obsTime ; obs . timeNominal = vn . nominalTime ; obs . stnId = vn . stnId ; obs . stnDesc = vn . stnDesc ; obs . lat = vn . lat ; obs . lon = vn . lon ; obs . stnAlt = vn . elev ; stnTable . addChild ( obs ) ; TableConfig lev = new TableConfig ( Table . Type . MultidimInner , "mandatory" ) ; lev . elev = levVarName ; lev . outerName = obs . dimName ; lev . innerName = levDimName ; obs . addChild ( lev ) ; return stnTable ; } return null ;


signature:
public class NcSDCharArray { /** * Read the data values ( parameters are ignored ) .
 * Use the start , stop and stride values that were set by the constraint evaluator .
 * @ param datasetName not used
 * @ param specialO not used
 * @ return false ( no more data to be read )
 * @ throws IOException
 * @ throws EOFException */
public boolean read ( String datasetName , Object specialO ) throws IOException { } }

implementation:
boolean hasStride = false ; Array a ; try { if ( debugRead ) { System . out . println ( "NcSDCharArray read " + ncVar . getFullName ( ) ) ; for ( int i = 0 ; i < numDimensions ( ) ; i ++ ) { DArrayDimension d = getDimension ( i ) ; System . out . println ( " " + d . getEncodedName ( ) + " " + getStart ( i ) + " " + getStop ( i ) + " " + getStride ( i ) ) ; } } // set up the netcdf read
int n = numDimensions ( ) ; int [ ] origin = new int [ n + 1 ] ; int [ ] shape = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { origin [ i ] = getStart ( i ) ; shape [ i ] = getStop ( i ) - getStart ( i ) + 1 ; hasStride = hasStride || ( getStride ( i ) > 1 ) ; } origin [ n ] = 0 ; shape [ n ] = strLen ; a = ncVar . read ( origin , shape ) ; if ( debugRead ) System . out . println ( "  Read = " + a . getSize ( ) + " elems of type = " + a . getElementType ( ) ) ; // deal with strides using a section
if ( hasStride ) { List < Range > ranges = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int s = getStride ( i ) ; if ( s > 1 ) { // otherwise null , means " take all elements "
ranges . add ( new Range ( 0 , shape [ i ] , s ) ) ; if ( debugRead ) System . out . println ( " Section dim " + i + " stride = " + s ) ; } } ranges . add ( null ) ; // get all
a = a . section ( ranges ) ; if ( debugRead ) System . out . println ( "   section size " + a . getSize ( ) ) ; } } catch ( InvalidDimensionException e ) { log . error ( "read char array" , e ) ; throw new IllegalStateException ( "NcSDCharArray InvalidDimensionException" ) ; } catch ( InvalidRangeException e ) { log . error ( "read char array" , e ) ; throw new IllegalStateException ( "NcSDCharArray InvalidRangeException" ) ; } setData ( a ) ; return ( false ) ;


signature:
public class BooleanPrimitiveVector { /** * Writes data to a < code > DataOutputStream < / code > . This method is used
 * on the server side of the OPeNDAP client / server connection , and possibly
 * by GUI clients which need to download OPeNDAP data , manipulate it , and
 * then resave it as a binary file .
 * @ param sink a < code > DataOutputStream < / code > to write to .
 * @ throws IOException thrown on any < code > OutputStream < / code > exception . */
public void externalize ( DataOutputStream sink ) throws IOException { } }

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


signature:
public class BooleanPrimitiveVector { /** * Write a subset of the data to a < code > DataOutputStream < / code > .
 * @ param sink a < code > DataOutputStream < / code > to write to .
 * @ param start starting index ( i = start )
 * @ param stop ending index ( i < = stop )
 * @ param stride index stride ( i + = stride )
 * @ throws IOException thrown on any < code > OutputStream < / code > exception . */
public void externalize ( DataOutputStream sink , int start , int stop , int stride ) throws IOException { } }

implementation: for ( int i = start ; i <= stop ; i += stride ) sink . writeBoolean ( vals [ i ] ) ;


signature:
public class BooleanPrimitiveVector { /** * Create a new primitive vector using a subset of the data .
 * @ param start starting index ( i = start )
 * @ param stop ending index ( i < = stop )
 * @ param stride index stride ( i + = stride )
 * @ return new primitive vector , of type BooleanPrimitiveVector . */
public PrimitiveVector subset ( int start , int stop , int stride ) { } }

implementation: BooleanPrimitiveVector n = new BooleanPrimitiveVector ( getTemplate ( ) ) ; stride = Math . max ( stride , 1 ) ; stop = Math . max ( start , stop ) ; int length = 1 + ( stop - start ) / stride ; n . setLength ( length ) ; int count = 0 ; for ( int i = start ; i <= stop ; i += stride ) { n . setValue ( count , vals [ i ] ) ; count ++ ; } return n ;


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

implementation: BooleanPrimitiveVector v = ( BooleanPrimitiveVector ) super . cloneDAG ( map ) ; if ( vals != null ) { v . vals = new boolean [ vals . length ] ; System . arraycopy ( vals , 0 , v . vals , 0 , vals . length ) ; } return v ;


signature:
public class H4type { /** * / * type info codes from hntdefs . h
 * # define DFNT _ UCHAR8 3
 * # define DFNT _ CHAR8 4
 * # define DFNT _ FLOAT32 5
 * # define DFNT _ FLOAT64 6
 * # define DFNT _ INT8 20
 * # define DFNT _ UINT8 21
 * # define DFNT _ INT16 22
 * # define DFNT _ UINT16 23
 * # define DFNT _ INT32 24
 * # define DFNT _ UINT32 25
 * # define DFNT _ INT64 26
 * # define DFNT _ UINT64 27 */
static DataType setDataType ( short type , Variable v ) { } }

implementation: DataType dt ; switch ( type ) { case 3 : dt = DataType . UBYTE ; break ; case 4 : dt = DataType . CHAR ; break ; case 5 : dt = DataType . FLOAT ; break ; case 6 : dt = DataType . DOUBLE ; break ; case 20 : dt = DataType . BYTE ; break ; case 21 : dt = DataType . UBYTE ; break ; case 22 : dt = DataType . SHORT ; break ; case 23 : dt = DataType . USHORT ; break ; case 24 : dt = DataType . INT ; break ; case 25 : dt = DataType . UINT ; break ; case 26 : dt = DataType . LONG ; break ; case 27 : dt = DataType . ULONG ; break ; default : throw new IllegalStateException ( "unknown type= " + type ) ; } if ( v != null ) { v . setDataType ( dt ) ; } return dt ;


signature:
public class CatalogTracker { /** * return sorted catalogs */
public Iterable < ? extends CatalogExt > getCatalogs ( ) { } }

implementation:
if ( catalogs == null ) readCatalogs ( ) ; List < CatalogExt > result = new ArrayList < > ( ) ; for ( CatalogExt ext : catalogs . values ( ) ) result . add ( ext ) ; Collections . sort ( result , ( o1 , o2 ) -> o1 . getCatRelLocation ( ) . compareTo ( o2 . getCatRelLocation ( ) ) ) ; // java 8 lambda , baby
return result ;


signature:
public class URLMapDefault { /** * Accessors */
@ Override public void addEntry ( String urlpath , String fileprefix ) throws DapException { } }

implementation:
// Canonicalize the urlpath
String urlprefix = DapUtil . canonicalpath ( urlpath ) ; // Canonicalize the file path
fileprefix = DapUtil . canonicalpath ( fileprefix ) ; url2path . put ( urlprefix , fileprefix ) ; // overwrite
path2url . put ( fileprefix , urlprefix ) ; // overwrite


signature:
public class URLMapDefault { /** * File loader */
public void load ( String filepath ) throws IOException { } }

implementation: String [ ] lines ; try ( InputStream is = new FileInputStream ( filepath ) ; ) { String content = DapUtil . readtextfile ( is ) ; lines = content . split ( "[\n]" ) ; } for ( String line : lines ) { String [ ] pieces = line . split ( "[=]" ) ; if ( pieces . length != 2 ) throw new IOException ( "File: " + filepath + "; malformed line: " + line ) ; addEntry ( pieces [ 0 ] , pieces [ 1 ] ) ; }


signature:
public class URLMapDefault { /** * URLMap API */
@ Override public Result mapURL ( String urlpath ) throws DapException { } }

implementation:
// Canonicalize the urlpath
urlpath = DapUtil . canonicalpath ( urlpath ) ; Result result = longestmatch ( url2path , urlpath ) ; return result ;


signature:
public class DatasetTrackerChronicle { /** * delete old databases */
public static void cleanupBefore ( String pathname , long trackerNumber ) { } }

implementation: for ( long tnum = trackerNumber - 1 ; tnum > 0 ; tnum -- ) { File oldDatabaseFile = new File ( pathname + datasetName + "." + tnum ) ; if ( ! oldDatabaseFile . exists ( ) ) break ; if ( oldDatabaseFile . delete ( ) ) { catalogInitLog . info ( "DatasetTrackerChronicle deleted {} " , oldDatabaseFile . getAbsolutePath ( ) ) ; } else { catalogInitLog . error ( "DatasetTrackerChronicle not able to delete {} " , oldDatabaseFile . getAbsolutePath ( ) ) ; } }


signature:
public class NavigationBlock { /** * Set the grid nav block values
 * @ param values the raw values */
public void setValues ( float [ ] values ) { } }

implementation: vals = values ; proj = GempakUtil . ST_ITOC ( Float . floatToIntBits ( vals [ 1 ] ) ) . trim ( ) ; addParam ( PROJ , proj ) ; addParam ( GDS_KEY , this . toString ( ) ) ; setParams ( ) ;


signature:
public class NavigationBlock { /** * Set the parameters for the GDS .
 * TODO Add the following :
 * The following simple map projections may be specified :
 * NOR North Orthographic
 * SOR South Orthographic
 * MER ( CYL ) Mercator
 * CED ( CYL ) Cylindrical Equidistant
 * MCD ( CYL ) Modified Cylindrical Equidistant
 * STR ( AZM ) Polar Stereographic
 * AED ( AZM ) Azimuthal Equidistant
 * ORT ( AZM ) Orthographic
 * LEA ( AZM ) Lambert equal area
 * GNO ( AZM ) Gnomonic
 * < / TODO >
 * In addition for full map projections , three angles MUST be specified
 * in PROJ . The angles have the following meanings for the different
 * projection classes :
 * CYL angle1 - - latitude of origin on the projection cylinder
 * 0 = Equator
 * angle2 - - longitude of origin on the projection cylinder
 * 0 = Greenwich meridian
 * angle3 - - angle to skew the projection by rotation of
 * the cylindrical surface of projection about
 * the line from the Earth ' s center passing
 * through the origin point . This results in
 * curved latitude and longitude lines .
 * If angle3 is greater than 360 or less than - 360
 * degrees , then the rectangular Cartesian coordinate
 * system on the projection plane is rotated
 * + / - | angle3 | - 360 degrees . This results in
 * latitude and longitude lines that are skewed
 * with respect to the edge of the map . This option
 * is only valid when specifying a map projection and
 * is not available for grid projections .
 * The difference between | angle3 | < 360 and
 * | angle3 | > 360 is that , in the former case ,
 * the rotation is applied to the developable
 * cylindrical surface before projection and
 * subsequent development ; while , in the latter
 * case , the rotation is applied to the Cartesian
 * coordinate system in the plane after development .
 * Development here refers to the mathematical
 * flattening of the surface of projection into a
 * planar surface .
 * Exception :
 * MCD angle1 - - scaling factor for latitude
 * 0 = default scaling ( 1 / cos ( avglat ) )
 * angle2 - - longitude of origin ( center longitude )
 * angle3 - - not used
 * AZM angle1 - - latitude of the projection ' s point of tangency
 * angle2 - - longitude of the projection ' s point of tangency
 * angle3 - - angle to skew the projection by rotation about
 * the line from the Earth ' s center passing
 * through the point of tangency
 * CON angle1 - - standard latitude 1
 * angle2 - - polon is the central longitude
 * angle3 - - standard latitude 2 */
private void setParams ( ) { } }

implementation:
String angle1 = String . valueOf ( vals [ 10 ] ) ; String angle2 = String . valueOf ( vals [ 11 ] ) ; String angle3 = String . valueOf ( vals [ 12 ] ) ; String lllat = String . valueOf ( vals [ 6 ] ) ; String lllon = String . valueOf ( vals [ 7 ] ) ; String urlat = String . valueOf ( vals [ 8 ] ) ; String urlon = String . valueOf ( vals [ 9 ] ) ; addParam ( NX , String . valueOf ( vals [ 4 ] ) ) ; addParam ( NY , String . valueOf ( vals [ 5 ] ) ) ; addParam ( LA1 , lllat ) ; addParam ( LO1 , lllon ) ; addParam ( LA2 , urlat ) ; addParam ( LO2 , urlon ) ; switch ( proj ) { case "STR" : case "NPS" : case "SPS" : addParam ( LOV , angle2 ) ; // TODO : better to just set pole ?
if ( proj . equals ( "SPS" ) ) { addParam ( "NpProj" , "false" ) ; } break ; case "LCC" : case "SCC" : addParam ( LATIN1 , angle1 ) ; addParam ( LOV , angle2 ) ; addParam ( LATIN2 , angle3 ) ; // TODO : test this
break ; case "MER" : case "MCD" : String standardLat ; if ( vals [ 10 ] == 0 ) { // use average latitude
float lat = ( vals [ 8 ] + vals [ 6 ] ) / 2 ; standardLat = String . valueOf ( lat ) ; } else { standardLat = angle1 ; } addParam ( "Latin" , standardLat ) ; addParam ( LOV , angle2 ) ; break ; case "CED" : double lllatv = vals [ 6 ] ; double lllonv = vals [ 7 ] ; double urlatv = vals [ 8 ] ; double urlonv = vals [ 9 ] ; if ( urlonv <= lllonv ) { urlonv += 360. ; } double dx = Math . abs ( ( urlonv - lllonv ) / ( vals [ 4 ] - 1 ) ) ; double dy = Math . abs ( ( urlatv - lllatv ) / ( vals [ 5 ] - 1 ) ) ; addParam ( DX , String . valueOf ( dx ) ) ; addParam ( DY , String . valueOf ( dy ) ) ; addParam ( LO2 , String . valueOf ( urlonv ) ) ; break ; }


signature:
public class GeoTiffWriter2 { /** * seems to handle swath as well ? ? */
public void writeGrid ( String gridDataset_filename , String gridName , int time , int level , boolean greyScale , LatLonRect pt ) throws IOException { } }

implementation:
try ( GridDataset dataset = ucar . nc2 . dt . grid . GridDataset . open ( gridDataset_filename ) ) { GridDatatype grid = dataset . findGridDatatype ( gridName ) ; if ( grid == null ) { throw new IllegalArgumentException ( "No grid named " + gridName + " in fileName" ) ; } GridCoordSystem gcs = grid . getCoordinateSystem ( ) ; ProjectionImpl proj = grid . getProjection ( ) ; if ( ! gcs . isRegularSpatial ( ) ) { Attribute att = dataset . findGlobalAttributeIgnoreCase ( "datasetId" ) ; if ( att != null && att . getStringValue ( ) . contains ( "DMSP" ) ) { // LOOK ! !
writeSwathGrid ( gridDataset_filename , gridName , time , level , greyScale , pt ) ; return ; } else { throw new IllegalArgumentException ( "Must have 1D x and y axes for " + grid . getFullName ( ) ) ; } } CoordinateAxis1D xaxis = ( CoordinateAxis1D ) gcs . getXHorizAxis ( ) ; CoordinateAxis1D yaxis = ( CoordinateAxis1D ) gcs . getYHorizAxis ( ) ; if ( ! xaxis . isRegular ( ) || ! yaxis . isRegular ( ) ) { throw new IllegalArgumentException ( "Must be evenly spaced grid = " + grid . getFullName ( ) ) ; } // read in data
Array data = grid . readDataSlice ( time , level , - 1 , - 1 ) ; Array lon = xaxis . read ( ) ; Array lat = yaxis . read ( ) ; // units may need to be scaled to meters
double scaler = ( xaxis . getUnitsString ( ) . equalsIgnoreCase ( "km" ) ) ? 1000.0 : 1.0 ; if ( yaxis . getCoordValue ( 0 ) < yaxis . getCoordValue ( 1 ) ) { data = data . flip ( 0 ) ; lat = lat . flip ( 0 ) ; } if ( gcs . isLatLon ( ) ) { data = geoShiftDataAtLon ( data , lon ) ; lon = geoShiftLon ( lon ) ; } // now it is time to subset the data out of latlonrect
// it is assumed that latlonrect pt is in + - 180
LatLonPointImpl llp0 = pt . getLowerLeftPoint ( ) ; LatLonPointImpl llpn = pt . getUpperRightPoint ( ) ; double minLon = llp0 . getLongitude ( ) ; double minLat = llp0 . getLatitude ( ) ; double maxLon = llpn . getLongitude ( ) ; double maxLat = llpn . getLatitude ( ) ; // ( x1 , y1 ) is upper left point and ( x2 , y2 ) is lower right point
int x1 ; int x2 ; int y1 ; int y2 ; double xStart ; double yStart ; if ( ! gcs . isLatLon ( ) ) { ProjectionPoint pjp0 = proj . latLonToProj ( maxLat , minLon ) ; x1 = getXIndex ( lon , pjp0 . getX ( ) , 0 ) ; y1 = getYIndex ( lat , pjp0 . getY ( ) , 0 ) ; yStart = pjp0 . getY ( ) * 1000.0 ; // latArray [ y1 ] ;
xStart = pjp0 . getX ( ) * 1000.0 ; // lonArray [ x1 ] ;
ProjectionPoint pjpn = proj . latLonToProj ( minLat , maxLon ) ; x2 = getXIndex ( lon , pjpn . getX ( ) , 1 ) ; y2 = getYIndex ( lat , pjpn . getY ( ) , 1 ) ; } else { xStart = minLon ; yStart = maxLat ; x1 = getLonIndex ( lon , minLon , 0 ) ; y1 = getLatIndex ( lat , maxLat , 0 ) ; x2 = getLonIndex ( lon , maxLon , 1 ) ; y2 = getLatIndex ( lat , minLat , 1 ) ; } // data must go from top to bottom
double xInc = xaxis . getIncrement ( ) * scaler ; double yInc = Math . abs ( yaxis . getIncrement ( ) ) * scaler ; // subsetting data inside the box
Array data1 = getYXDataInBox ( data , x1 , x2 , y1 , y2 ) ; if ( pageNumber > 1 ) { geotiff . initTags ( ) ; } // write it out
writeGrid ( grid , data1 , greyScale , xStart , yStart , xInc , yInc , pageNumber ) ; pageNumber ++ ; }


signature:
public class GeoTiffWriter2 { /** * Write Swath Grid data to the geotiff file .
 * @ param fileName _ more _
 * @ param gridName _ more _
 * @ param time _ more _
 * @ param level _ more _
 * @ param greyScale _ more _
 * @ param llr _ more _
 * @ throws IOException _ more _ */
private void writeSwathGrid ( String fileName , String gridName , int time , int level , boolean greyScale , LatLonRect llr ) throws IOException { } }

implementation:
GridDataset dataset = ucar . nc2 . dt . grid . GridDataset . open ( fileName ) ; GridDatatype grid = dataset . findGridDatatype ( gridName ) ; GridCoordSystem gcs = grid . getCoordinateSystem ( ) ; ProjectionImpl proj = grid . getProjection ( ) ; CoordinateAxis2D xaxis = ( CoordinateAxis2D ) gcs . getXHorizAxis ( ) ; CoordinateAxis2D yaxis = ( CoordinateAxis2D ) gcs . getYHorizAxis ( ) ; // read in data
Array data = grid . readDataSlice ( time , level , - 1 , - 1 ) ; Array lon = xaxis . read ( ) ; Array lat = yaxis . read ( ) ; double [ ] swathInfo = getSwathLatLonInformation ( lat , lon ) ; // units may need to be scaled to meters
double scaler = ( xaxis . getUnitsString ( ) . equalsIgnoreCase ( "km" ) ) ? 1000.0 : 1.0 ; // if ( yaxis . getCoordValue ( 0 , 0 ) < yaxis . getCoordValue ( 0 , 1 ) ) { / / ? ? ?
data = data . flip ( 0 ) ; // lat = lat . flip ( 0 ) ;
if ( gcs . isLatLon ( ) ) { data = geoShiftDataAtLon ( data , lon ) ; lon = geoShiftLon ( lon ) ; } double minLon ; double minLat ; double maxLon ; double maxLat ; double xStart ; double yStart ; // upper right point
double xInc = swathInfo [ 0 ] * scaler ; double yInc = swathInfo [ 1 ] * scaler ; // ( x1 , y1 ) is upper left point and ( x2 , y2 ) is lower right point
int x1 ; int x2 ; int y1 ; int y2 ; if ( llr == null ) { // get the whole area
minLon = swathInfo [ 4 ] ; minLat = swathInfo [ 2 ] ; maxLon = swathInfo [ 5 ] ; maxLat = swathInfo [ 3 ] ; xStart = minLon ; yStart = maxLat ; x1 = 0 ; y1 = 0 ; x2 = ( int ) ( ( maxLon - minLon ) / xInc + 0.5 ) ; y2 = ( int ) ( ( maxLat - minLat ) / yInc + 0.5 ) ; } else { // assign the special area surrounded by the llr
LatLonPointImpl llp0 = llr . getLowerLeftPoint ( ) ; LatLonPointImpl llpn = llr . getUpperRightPoint ( ) ; minLon = ( llp0 . getLongitude ( ) < swathInfo [ 4 ] ) ? swathInfo [ 4 ] : llp0 . getLongitude ( ) ; minLat = ( llp0 . getLatitude ( ) < swathInfo [ 2 ] ) ? swathInfo [ 2 ] : llp0 . getLatitude ( ) ; maxLon = ( llpn . getLongitude ( ) > swathInfo [ 5 ] ) ? swathInfo [ 5 ] : llpn . getLongitude ( ) ; maxLat = ( llpn . getLatitude ( ) > swathInfo [ 3 ] ) ? swathInfo [ 3 ] : llpn . getLatitude ( ) ; // construct the swath LatLonRect
LatLonPointImpl pUpLeft = new LatLonPointImpl ( swathInfo [ 3 ] , swathInfo [ 4 ] ) ; LatLonPointImpl pDownRight = new LatLonPointImpl ( swathInfo [ 2 ] , swathInfo [ 5 ] ) ; LatLonRect swathLLR = new LatLonRect ( pUpLeft , pDownRight ) ; LatLonRect bIntersect = swathLLR . intersect ( llr ) ; if ( bIntersect == null ) { throw new IllegalArgumentException ( "The assigned extent of latitude and longitude is unvalid. No intersection with the swath extent" ) ; } xStart = minLon ; yStart = maxLat ; x1 = ( int ) ( ( minLon - swathInfo [ 4 ] ) / xInc + 0.5 ) ; y1 = ( int ) Math . abs ( ( maxLat - swathInfo [ 3 ] ) / yInc + 0.5 ) ; x2 = ( int ) ( ( maxLon - swathInfo [ 4 ] ) / xInc + 0.5 ) ; y2 = ( int ) Math . abs ( ( minLat - swathInfo [ 3 ] ) / yInc + 0.5 ) ; } if ( ! gcs . isLatLon ( ) ) { ProjectionPoint pjp0 = proj . latLonToProj ( maxLat , minLon ) ; x1 = getXIndex ( lon , pjp0 . getX ( ) , 0 ) ; y1 = getYIndex ( lat , pjp0 . getY ( ) , 0 ) ; yStart = pjp0 . getY ( ) * scaler ; // latArray [ y1 ] ;
xStart = pjp0 . getX ( ) * scaler ; // lonArray [ x1 ] ;
ProjectionPoint pjpn = proj . latLonToProj ( minLat , maxLon ) ; x2 = getXIndex ( lon , pjpn . getX ( ) , 1 ) ; y2 = getYIndex ( lat , pjpn . getY ( ) , 1 ) ; } else { // calculate the x1 , x2 , y1 , y2 , xstart , ystart .
} Array targetImage = getTargetImagerFromSwath ( lat , lon , data , swathInfo ) ; Array interpolatedImage = interpolation ( targetImage ) ; Array clippedImage = getClippedImageFromInterpolation ( interpolatedImage , x1 , x2 , y1 , y2 ) ; // Array clippedImage = getYXDataInBox ( interpolatedImage , x1 , x2 , y1 , y2 ) ;
if ( pageNumber > 1 ) { geotiff . initTags ( ) ; } writeGrid ( grid , clippedImage , greyScale , xStart , yStart , xInc , yInc , pageNumber ) ; pageNumber ++ ;


signature:
public class GeoTiffWriter2 { /** * interpolate the swath data to regular grid
 * @ param arr swath array
 * @ return regular grid */
private Array interpolation ( Array arr ) { } }

implementation:
int [ ] orishape = arr . getShape ( ) ; int width = orishape [ 1 ] ; int height = orishape [ 0 ] ; int pixelNum = width * height ; Array interpolatedArray = Array . factory ( DataType . FLOAT , orishape ) ; for ( int i = 0 ; i < height ; i ++ ) { for ( int j = 0 ; j < width ; j ++ ) { int curIndex = i * width + j ; float curValue = arr . getFloat ( curIndex ) ; if ( curValue == 0 ) // Black hole . Need to fill .
{ float tempPixelSum = 0 ; int numNeighborHasValue = 0 ; // Get the values of eight neighborhood
if ( ( curIndex - 1 >= 0 ) && ( curIndex - 1 < pixelNum ) ) { float left = arr . getFloat ( curIndex - 1 ) ; if ( left > 0 ) { tempPixelSum += left ; numNeighborHasValue ++ ; } } if ( ( curIndex + 1 >= 0 ) && ( curIndex + 1 < pixelNum ) ) { float right = arr . getFloat ( curIndex + 1 ) ; if ( right > 0 ) { tempPixelSum += right ; numNeighborHasValue ++ ; } } if ( ( curIndex - width >= 0 ) && ( curIndex - width < pixelNum ) ) { float up = arr . getFloat ( curIndex - width ) ; if ( up > 0 ) { tempPixelSum += up ; numNeighborHasValue ++ ; } } if ( ( curIndex + width >= 0 ) && ( curIndex + width < pixelNum ) ) { float down = arr . getFloat ( curIndex + width ) ; if ( down > 0 ) { tempPixelSum += down ; numNeighborHasValue ++ ; } } if ( ( curIndex - width - 1 >= 0 ) && ( curIndex - width - 1 < pixelNum ) ) { float upleft = arr . getFloat ( curIndex - width - 1 ) ; if ( upleft > 0 ) { tempPixelSum += upleft ; numNeighborHasValue ++ ; } } if ( ( curIndex - width + 1 >= 0 ) && ( curIndex - width + 1 < pixelNum ) ) { float upright = arr . getFloat ( curIndex - width + 1 ) ; if ( upright > 0 ) { tempPixelSum += upright ; numNeighborHasValue ++ ; } } if ( ( curIndex + width - 1 >= 0 ) && ( curIndex + width - 1 < pixelNum ) ) { float downleft = arr . getFloat ( curIndex + width - 1 ) ; if ( downleft > 0 ) { tempPixelSum += downleft ; numNeighborHasValue ++ ; } } if ( ( curIndex + width + 1 >= 0 ) && ( curIndex + width + 1 < pixelNum ) ) { float downright = arr . getFloat ( curIndex + width + 1 ) ; if ( downright > 0 ) { tempPixelSum += downright ; numNeighborHasValue ++ ; } } if ( tempPixelSum > 0 ) { float val = numNeighborHasValue == 0 ? 0 : tempPixelSum / numNeighborHasValue ; interpolatedArray . setFloat ( curIndex , val ) ; } } else { interpolatedArray . setFloat ( curIndex , curValue ) ; } } } return interpolatedArray ;


signature:
public class GeoTiffWriter2 { /** * get lat lon information from the swath
 * @ param lat 2D lat array
 * @ param lon 2D lon array
 * @ return double array for geotiff */
private double [ ] getSwathLatLonInformation ( Array lat , Array lon ) { } }

implementation:
// Calculate the increment of latitude and longitude of original swath data
// Calculate the size of the boundingBox
// element0 : Longitude increment
// element1 : Latitude increment
// element2 : minLat
// element3 : maxLat
// element4 : minLon
// element5 : maxLon
// element6 : width of the boundingBox
// element7 : height of the boundingBox
double increment [ ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; IndexIterator latIter = lat . getIndexIterator ( ) ; IndexIterator lonIter = lon . getIndexIterator ( ) ; int numScan = ( lat . getShape ( ) ) [ 0 ] ; int numSample = ( lat . getShape ( ) ) [ 1 ] ; double maxLat = - 91 , minLat = 91 , maxLon = - 181 , minLon = 181 ; float firstLineStartLat = 0 ; float firstLineStartLon = 0 ; float firstLineEndLat = 0 ; float firstLineEndLon = 0 ; float lastLineStartLat = 0 ; float lastLineStartLon = 0 ; float lastLineEndLat = 0 ; float lastLineEndLon = 0 ; for ( int i = 0 ; i < numScan ; i ++ ) { for ( int j = 0 ; j < numSample ; j ++ ) { if ( latIter . hasNext ( ) && lonIter . hasNext ( ) ) { float curLat = latIter . getFloatNext ( ) ; float curLon = lonIter . getFloatNext ( ) ; if ( ( i == 0 ) && ( j == 0 ) ) { firstLineStartLat = curLat ; firstLineStartLon = curLon ; } else if ( ( i == 0 ) && ( j == numSample - 1 ) ) { firstLineEndLat = curLat ; firstLineEndLon = curLon ; } else if ( ( i == numScan - 1 ) && ( j == 0 ) ) { lastLineStartLat = curLat ; lastLineStartLon = curLon ; } else if ( ( i == numScan - 1 ) && ( j == numSample - 1 ) ) { lastLineEndLat = curLat ; lastLineEndLon = curLon ; } } } } double [ ] edgeLat = { firstLineStartLat , firstLineEndLat , lastLineStartLat , lastLineEndLat } ; double [ ] edgeLon = { firstLineStartLon , firstLineEndLon , lastLineStartLon , lastLineEndLon } ; for ( int i = 0 ; i < edgeLat . length ; i ++ ) { maxLat = ( ( maxLat > edgeLat [ i ] ) ? maxLat : edgeLat [ i ] ) ; minLat = ( ( minLat < edgeLat [ i ] ) ? minLat : edgeLat [ i ] ) ; maxLon = ( ( maxLon > edgeLon [ i ] ) ? maxLon : edgeLon [ i ] ) ; minLon = ( ( minLon < edgeLon [ i ] ) ? minLon : edgeLon [ i ] ) ; } double xInc1 = Math . abs ( ( firstLineEndLon - firstLineStartLon ) / numSample ) ; // double xInc2 = Math . abs ( ( lastLineEndLon - lastLineStartLon ) / numSample ) ;
double yInc1 = Math . abs ( ( lastLineStartLat - firstLineStartLat ) / numScan ) ; // double yInc2 = Math . abs ( ( lastLineEndLat - firstLineEndLat ) / numScan ) ;
increment [ 0 ] = xInc1 ; // > xInc2 ? xInc1 : xInc2;
increment [ 1 ] = yInc1 ; // > yInc2 ? yInc1 : yInc2;
increment [ 2 ] = minLat ; increment [ 3 ] = maxLat ; increment [ 4 ] = minLon ; increment [ 5 ] = maxLon ; increment [ 6 ] = ( maxLon - minLon ) / xInc1 ; increment [ 7 ] = ( maxLat - minLat ) / yInc1 ; return increment ;


signature:
public class DataBTree { /** * used by H5tiledLayout */
LayoutTiled . DataChunkIterator getDataChunkIteratorNoFilter ( Section want , int nChunkDim ) throws IOException { } }

implementation:
/* if ( if ( debugChunkOrder ) ) {
 DataChunkIteratorNoFilter iter = new DataChunkIteratorNoFilter ( null , nChunkDim ) ;
 int count = 0;
 int last = - 1;
 while ( iter . hasNext ( ) ) {
 LayoutTiled . DataChunk chunk = iter . next ( ) ;
 System . out . printf ( " % d : % d % n " , count + + , tiling . order ( chunk . offset ) ) ;
 if ( tiling . order ( chunk . offset ) < = last )
 System . out . println ( " HEY " ) ;
 last = tiling . order ( chunk . offset ) ; */
return new DataChunkIteratorNoFilter ( want , nChunkDim ) ;


signature:
public class McIDASAreaProjection { /** * 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: double toX , toY ; double fromLat = latLon . getLatitude ( ) ; double fromLon = latLon . getLongitude ( ) ; double [ ] [ ] xy = anav . toLinEle ( new double [ ] [ ] { { fromLat } , { fromLon } } ) ; if ( xy == null ) return null ; toX = xy [ 0 ] [ 0 ] ; toY = xy [ 1 ] [ 0 ] ; result . setLocation ( toX , toY ) ; return result ;