Input: The time unit statistical type derived from code table 5 ) [CODESPLIT] @ Nullable public static GribStatType getStatType ( int timeRangeIndicator ) { switch ( timeRangeIndicator ) { case 3 : case 6 : case 7 : case 51 : case 113 : case 115 : case 117 : case 120 : case 123 : return GribStatType . Average ; case 4 : case 114 : case 116 : case 124 : return GribStatType . Accumulation ; case 5 : return GribStatType . DifferenceFromEnd ; case 118 : return GribStatType . Covariance ; case 119 : case 125 : return GribStatType . StandardDeviation ; default : return null ; } }


Input:
/////////////////////////////////////////////////////////////////////////////////// [CODESPLIT] public Optional < HorizCoordSys > subset ( SubsetParams params ) { LatLonRect llbb = ( LatLonRect ) params . get ( SubsetParams . latlonBB ) ; ProjectionRect projbb = ( ProjectionRect ) params . get ( SubsetParams . projBB ) ; LatLonPoint latlon = ( LatLonPoint ) params . get ( SubsetParams . latlonPoint ) ; Integer horizStride = ( Integer ) params . get ( SubsetParams . horizStride ) ; if ( horizStride == null || horizStride < 1 ) horizStride = 1 ; CoverageCoordAxis1D xaxisSubset = null , yaxisSubset = null ; CoverageCoordAxis lataxisSubset = null , lonaxisSubset = null ; Optional < CoverageCoordAxis > opt ; Optional < CoverageCoordAxisBuilder > optb ; Formatter errMessages = new Formatter ( ) ; try { if ( latlon != null ) { // overrides other horiz subset params if ( isProjection ) { CoordAxisHelper xhelper = new CoordAxisHelper ( xAxis ) ; CoordAxisHelper yhelper = new CoordAxisHelper ( yAxis ) ; // we have to transform latlon to projection coordinates ProjectionImpl proj = transform . getProjection ( ) ; ProjectionPoint pp = proj . latLonToProj ( latlon ) ; optb = xhelper . subsetContaining ( pp . getX ( ) ) ; if ( optb . isPresent ( ) ) xaxisSubset = new CoverageCoordAxis1D ( optb . get ( ) ) ; else errMessages . format ( "xaxis: %s;%n" , optb . getErrorMessage ( ) ) ; optb = yhelper . subsetContaining ( pp . getY ( ) ) ; if ( optb . isPresent ( ) ) yaxisSubset = new CoverageCoordAxis1D ( optb . get ( ) ) ; else errMessages . format ( "yaxis: %s;%n" , optb . getErrorMessage ( ) ) ; } else { CoordAxisHelper xhelper = new CoordAxisHelper ( lonAxis ) ; CoordAxisHelper yhelper = new CoordAxisHelper ( latAxis ) ; double lonNormal = LatLonPointImpl . lonNormalFrom ( latlon . getLongitude ( ) , lonAxis . getStartValue ( ) ) ; optb = xhelper . subsetContaining ( lonNormal ) ; if ( optb . isPresent ( ) ) lonaxisSubset = new CoverageCoordAxis1D ( optb . get ( ) ) ; else errMessages . format ( "lonaxis: %s;%n" , optb . getErrorMessage ( ) ) ; optb = yhelper . subsetContaining ( latlon . getLatitude ( ) ) ; if ( optb . isPresent ( ) ) lataxisSubset = new CoverageCoordAxis1D ( optb . get ( ) ) ; else errMessages . format ( "lataxis: %s;%n" , optb . getErrorMessage ( ) ) ; } } else if ( projbb != null ) { if ( isProjection ) { opt = xAxis . subset ( projbb . getMinX ( ) , projbb . getMaxX ( ) , horizStride ) ; if ( opt . isPresent ( ) ) xaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "xaxis: %s;%n" , opt . getErrorMessage ( ) ) ; opt = yAxis . subset ( projbb . getMinY ( ) , projbb . getMaxY ( ) , horizStride ) ; if ( opt . isPresent ( ) ) yaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "yaxis: %s;%n" , opt . getErrorMessage ( ) ) ; } /* else {  // WTF projbb on non Projection ?
          ProjectionImpl proj = transform.getProjection();
          LatLonRect llrect = proj.projToLatLonBB(projbb);
          opt = lonaxis.subset(llrect.getLonMin(), llrect.getLonMax(), horizStride);
          if (opt.isPresent()) lonaxisSubset = opt.get();
          else errMessages.format("lonaxis: %s;%n", opt.getErrorMessage());

          opt = lataxis.subset(llrect.getLatMin(), llrect.getLatMax(), horizStride);
          if (opt.isPresent()) lataxisSubset = opt.get();
          else errMessages.format("lataxis: %s;%n", opt.getErrorMessage());
        } */ } else if ( llbb != null ) { LatLonRect full = calcLatLonBoundingBox ( ) ; assert full != null ; if ( ! full . containedIn ( llbb ) ) { // if request contains entire bb, then no subsetting needed if ( isProjection ) { // we have to transform latlon to projection coordinates ProjectionImpl proj = transform . getProjection ( ) ; ProjectionRect prect = proj . latLonToProjBB ( llbb ) ; // allow projection to override opt = xAxis . subset ( prect . getMinX ( ) , prect . getMaxX ( ) , horizStride ) ; if ( opt . isPresent ( ) ) xaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "xaxis: %s;%n" , opt . getErrorMessage ( ) ) ; opt = yAxis . subset ( prect . getMinY ( ) , prect . getMaxY ( ) , horizStride ) ; if ( opt . isPresent ( ) ) yaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "yaxis: %s;%n" , opt . getErrorMessage ( ) ) ; } else { opt = subsetLon ( llbb , horizStride ) ; if ( opt . isPresent ( ) ) lonaxisSubset = opt . get ( ) ; else errMessages . format ( "lonaxis: %s;%n" , opt . getErrorMessage ( ) ) ; opt = latAxis . subset ( llbb . getLatMin ( ) , llbb . getLatMax ( ) , horizStride ) ; if ( opt . isPresent ( ) ) lataxisSubset = opt . get ( ) ; else errMessages . format ( "lataxis: %s;%n" , opt . getErrorMessage ( ) ) ; } } } else if ( horizStride > 1 ) { // no bounding box, just horiz stride if ( isProjection ) { opt = xAxis . subsetByIndex ( xAxis . getRange ( ) . setStride ( horizStride ) ) ; if ( opt . isPresent ( ) ) xaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "xaxis: %s;%n" , opt . getErrorMessage ( ) ) ; opt = yAxis . subsetByIndex ( yAxis . getRange ( ) . setStride ( horizStride ) ) ; if ( opt . isPresent ( ) ) yaxisSubset = ( CoverageCoordAxis1D ) opt . get ( ) ; else errMessages . format ( "yaxis: %s;%n" , opt . getErrorMessage ( ) ) ; } else { opt = lonAxis . subsetByIndex ( lonAxis . getRange ( ) . setStride ( horizStride ) ) ; if ( opt . isPresent ( ) ) lonaxisSubset = opt . get ( ) ; else errMessages . format ( "lonaxis: %s;%n" , opt . getErrorMessage ( ) ) ; opt = latAxis . subsetByIndex ( latAxis . getRange ( ) . setStride ( horizStride ) ) ; if ( opt . isPresent ( ) ) lataxisSubset = opt . get ( ) ; else errMessages . format ( "lataxis: %s;%n" , opt . getErrorMessage ( ) ) ; } } } catch ( InvalidRangeException e ) { errMessages . format ( "%s;%n" , e . getMessage ( ) ) ; } String errs = errMessages . toString ( ) ; if ( errs . length ( ) > 0 ) return Optional . empty ( errs ) ; // makes a copy of the axis if ( xaxisSubset == null && xAxis != null ) xaxisSubset = ( CoverageCoordAxis1D ) xAxis . copy ( ) ; if ( yaxisSubset == null && yAxis != null ) yaxisSubset = ( CoverageCoordAxis1D ) yAxis . copy ( ) ; if ( lataxisSubset == null && latAxis != null ) lataxisSubset = latAxis . copy ( ) ; if ( lonaxisSubset == null && lonAxis != null ) lonaxisSubset = lonAxis . copy ( ) ; return Optional . of ( new HorizCoordSys ( xaxisSubset , yaxisSubset , lataxisSubset , lonaxisSubset , transform ) ) ; }


Input: here s where to deal with crossing seam [CODESPLIT] private Optional < CoverageCoordAxis > subsetLon ( LatLonRect llbb , int stride ) throws InvalidRangeException { double wantMin = LatLonPointImpl . lonNormalFrom ( llbb . getLonMin ( ) , lonAxis . getStartValue ( ) ) ; double wantMax = LatLonPointImpl . lonNormalFrom ( llbb . getLonMax ( ) , lonAxis . getStartValue ( ) ) ; double start = lonAxis . getStartValue ( ) ; double end = lonAxis . getEndValue ( ) ; // use MAMath.MinMax as a container for two values, min and max List < MAMath . MinMax > lonIntvs = subsetLonIntervals ( wantMin , wantMax , start , end ) ; if ( lonIntvs . size ( ) == 0 ) return Optional . empty ( String . format ( "longitude want [%f,%f] does not intersect lon axis [%f,%f]" , wantMin , wantMax , start , end ) ) ; if ( lonIntvs . size ( ) == 1 ) { MAMath . MinMax lonIntv = lonIntvs . get ( 0 ) ; return lonAxis . subset ( lonIntv . min , lonIntv . max , stride ) ; } // this is the seam crossing case return lonAxis . subsetByIntervals ( lonIntvs , stride ) ; }


Input: / * longitude subset after normalizing to start draw a circle representing longitude values from start to start + 360 . all values are on this circle and are > start . put start at bottom of circle end > start data has values from start counterclockwise to end . wantMin wantMax can be anywhere want goes from wantMin counterclockwise to wantMax . wantMin may be less than or greater than wantMax . [CODESPLIT] private List < MAMath . MinMax > subsetLonIntervals ( double wantMin , double wantMax , double start , double end ) { if ( wantMin <= wantMax ) { if ( wantMin > end && wantMax > end ) // none A.1 return Collections . EMPTY_LIST ; if ( wantMin < end && wantMax < end ) // A.2 return Lists . newArrayList ( new MAMath . MinMax ( wantMin , wantMax ) ) ; if ( wantMin < end && wantMax > end ) // A.3 return Lists . newArrayList ( new MAMath . MinMax ( wantMin , end ) ) ; } else { if ( wantMin > end && wantMax > end ) // all B.1 return Lists . newArrayList ( new MAMath . MinMax ( start , end ) ) ; if ( wantMin < end && wantMax < end ) { // B.2 return Lists . newArrayList ( new MAMath . MinMax ( wantMin , end ) , new MAMath . MinMax ( start , wantMax ) ) ; } if ( wantMin < end && wantMax > end ) // B.3 return Lists . newArrayList ( new MAMath . MinMax ( wantMin , end ) ) ; } // otherwise shouldnt get to this logger . error ( "longitude want [%f,%f] does not intersect axis [%f,%f]" , wantMin , wantMax , start , end ) ; return Collections . EMPTY_LIST ; }


Input: return y x range [CODESPLIT] public List < RangeIterator > getRanges ( ) { List < RangeIterator > result = new ArrayList <> ( ) ; result . add ( getYAxis ( ) . getRange ( ) ) ; RangeIterator lonRange = getXAxis ( ) . getRangeIterator ( ) ; if ( lonRange == null ) lonRange = getXAxis ( ) . getRange ( ) ; // clumsy result . add ( lonRange ) ; return result ; }


Input: Calculates the bounding box of this coordinate reference system in projection coordinates . If this CRS { @link #isProjection isn t a projection } than { @code null } is returned . [CODESPLIT] public ProjectionRect calcProjectionBoundingBox ( ) { if ( ! isProjection ) return null ; double minX = Math . min ( xAxis . getCoordEdgeFirst ( ) , xAxis . getCoordEdgeLast ( ) ) ; double minY = Math . min ( yAxis . getCoordEdgeFirst ( ) , yAxis . getCoordEdgeLast ( ) ) ; double width = Math . abs ( xAxis . getCoordEdgeLast ( ) - xAxis . getCoordEdgeFirst ( ) ) ; double height = Math . abs ( yAxis . getCoordEdgeLast ( ) - yAxis . getCoordEdgeFirst ( ) ) ; return new ProjectionRect ( new ProjectionPointImpl ( minX , minY ) , width , height ) ; }


Input: Calculates the bounding box of this coordinate reference system in latitude / longitude . This method properly handles coverages that straddle the international date line by deriving its bounding box from the { @link #calcConnectedLatLonBoundaryPoints ( int int ) connected latitude / longitude boundary } . <p > If this CRS { @link #isProjection is a projection } its lat / lon boundary is computed by converting each point in its { @link #calcProjectionBoundaryPoints () projection boundary } to latitude / longitude using the { @link Projection projection } . [CODESPLIT] public LatLonRect calcLatLonBoundingBox ( ) { double minLat = Double . MAX_VALUE ; double minLon = Double . MAX_VALUE ; double maxLat = - Double . MAX_VALUE ; double maxLon = - Double . MAX_VALUE ; for ( LatLonPointNoNormalize boundaryPoint : calcConnectedLatLonBoundaryPoints ( ) ) { minLat = Math . min ( minLat , boundaryPoint . getLatitude ( ) ) ; minLon = Math . min ( minLon , boundaryPoint . getLongitude ( ) ) ; maxLat = Math . max ( maxLat , boundaryPoint . getLatitude ( ) ) ; maxLon = Math . max ( maxLon , boundaryPoint . getLongitude ( ) ) ; } return new LatLonRect ( new LatLonPointImpl ( minLat , minLon ) , new LatLonPointImpl ( maxLat , maxLon ) ) ; }


Input: Calculates the latitude / longitude boundary of this coordinate reference system . The boundary starts at the lower left corner of the coverage -- i . e . { @code ( y [ 0 ] x [ 0 ] ) } -- and consists of the points that lie along the bottom right top and left edges in that order . <p > The { @code maxPointsInYEdge } parameter establishes a limit on the number of boundary points that ll be included from the right and left edges . { @code maxPointsInXEdge } establishes a similar limit for the bottom and top edges . The size of the returned list will be { @code ≤ 2 * maxPointsInYEdge + 2 * maxPointsInXEdge } . Note that the corners are always included regardless of the arguments . If you wish to include ALL of the points along the edges in the boundary simply choose values for the parameters that are greater than the lengths of the corresponding axes in the CRS . { @link Integer#MAX_VALUE } works great . In that case the size of the returned list will be { @code 2 * numXcoords + 2 * numYcoords } . <p > If this CRS { @link #isProjection is a projection } the lat / lon boundary is computed by converting each point in its { @link #calcProjectionBoundaryPoints () projection boundary } to latitude / longitude using the { @link Projection projection } . <p > Points in the boundary will be { @link #connectLatLonPoints connected } . This facilitates proper interpretation of the boundary if it s rendered as a georeferenced polygon particularly when the boundary crosses the international date line . [CODESPLIT] public List < LatLonPointNoNormalize > calcConnectedLatLonBoundaryPoints ( int maxPointsInYEdge , int maxPointsInXEdge ) { List < LatLonPoint > points ; if ( isProjection ) { points = calcLatLonBoundaryPointsFromProjection ( maxPointsInYEdge , maxPointsInXEdge ) ; } else if ( isLatLon1D ) { points = calcLatLon1DBoundaryPoints ( maxPointsInYEdge , maxPointsInXEdge ) ; } else if ( isLatLon2D ) { points = calcLatLon2DBoundaryPoints ( maxPointsInYEdge , maxPointsInXEdge ) ; } else { throw new AssertionError ( "HorizCoordSys was not a projection, latLon1D, or latLon2D." ) ; } return connectLatLonPoints ( points ) ; }


Input: Calculates the boundary of this coordinate reference system in projection coordinates . The boundary starts at the lower left corner of the coverage -- i . e . { @code ( y [ 0 ] x [ 0 ] ) } -- and consists of the points that lie along the bottom right top and left edges in that order . <p > The { @code maxPointsInYEdge } parameter establishes a limit on the number of boundary points that ll be included from the right and left edges . { @code maxPointsInXEdge } establishes a similar limit for the bottom and top edges . The size of the returned list will be { @code ≤ 2 * maxPointsInYEdge + 2 * maxPointsInXEdge } . Note that the corners are always included regardless of the arguments . If you wish to include ALL of the points along the edges in the boundary simply choose values for the parameters that are greater than the lengths of the corresponding axes in the CRS . { @link Integer#MAX_VALUE } works great . In that case the size of the returned list will be { @code 2 * numXcoords + 2 * numYcoords } . [CODESPLIT] public List < ProjectionPoint > calcProjectionBoundaryPoints ( int maxPointsInYEdge , int maxPointsInXEdge ) { if ( ! isProjection ) { throw new UnsupportedOperationException ( "Coordinate system is not a projection." ) ; } checkMaxPointsInEdges ( maxPointsInYEdge , maxPointsInXEdge ) ; int numYtotal = yAxis . getNcoords ( ) ; int numXtotal = xAxis . getNcoords ( ) ; int strideY = calcStride ( numYtotal , maxPointsInYEdge ) ; int strideX = calcStride ( numXtotal , maxPointsInXEdge ) ; List < ProjectionPoint > points = new LinkedList <> ( ) ; // Bottom boundary points for ( int i = 0 ; i < numXtotal ; i += strideX ) { points . add ( new ProjectionPointImpl ( xAxis . getCoordEdge1 ( i ) , yAxis . getCoordEdgeFirst ( ) ) ) ; } // Right boundary points for ( int j = 0 ; j < numYtotal ; j += strideY ) { points . add ( new ProjectionPointImpl ( xAxis . getCoordEdgeLast ( ) , yAxis . getCoordEdge1 ( j ) ) ) ; } // Top boundary points for ( int i = numXtotal - 1 ; i >= 0 ; i -= strideX ) { points . add ( new ProjectionPointImpl ( xAxis . getCoordEdge2 ( i ) , yAxis . getCoordEdgeLast ( ) ) ) ; } // Left boundary points for ( int j = numYtotal - 1 ; j >= 0 ; j -= strideY ) { points . add ( new ProjectionPointImpl ( xAxis . getCoordEdgeFirst ( ) , yAxis . getCoordEdge2 ( j ) ) ) ; } assertNotExceedingMaxBoundaryPoints ( points . size ( ) , maxPointsInYEdge , maxPointsInXEdge ) ; return points ; }


Input: Returns a list of points that is equivalent to the input list but with longitude values adjusted to ensure that adjacent elements are connected . <p > Two points are connected if the absolute difference of their { @link LatLonPointImpl#lonNormal normalized longitudes } is { @code ≤180 } . For example the longitudes { @code 112 } and { @code 124 } are connected . So are { @code 15 } and { @code - 27 } . <p > Two points may be disconnected if they lie on opposite sides of the international date line . For example the longitudes { @code 175 } and { @code - 175 } are disconnected because their absolute difference is { @code 350 } which is { @code > 180 } . To connect the two points we adjust the second longitude to an equivalent value in the range { @code [ firstLon ± 180 ] } by adding or subtracting { @code 360 } . So { @code - 175 } would become { @code 185 } . We perform this adjustment for each pair of adjacent elements in the list . <p > Performing the above adjustment will result in longitudes that lie outside of the normalized range of ( { @code [ - 180 180 ] } ) . To be precise if adjustments are necessary all of the longitudes in the returned list will be in either { @code [ - 360 0 ] } or { @code [ 0 360 ] } . Consequently adjusted points cannot be returned as { @link LatLonPoint } s ; they are returned as { @link LatLonPointNoNormalize } objects instead . <p > Longitudes { @code lon1 } and { @code lon2 } are considered equivalent if { @code lon1 == lon2 + 360 * i } for some integer { @code i } . [CODESPLIT] public static List < LatLonPointNoNormalize > connectLatLonPoints ( List < LatLonPoint > points ) { LinkedList < LatLonPointNoNormalize > connectedPoints = new LinkedList <> ( ) ; for ( LatLonPoint point : points ) { double curLat = point . getLatitude ( ) ; double curLon = point . getLongitude ( ) ; if ( ! connectedPoints . isEmpty ( ) ) { double prevLon = connectedPoints . getLast ( ) . getLongitude ( ) ; curLon = LatLonPointImpl . lonNormal ( curLon , prevLon ) ; } connectedPoints . add ( new LatLonPointNoNormalize ( curLat , curLon ) ) ; } return connectedPoints ; }


Input: Returns the { @link #calcConnectedLatLonBoundaryPoints ( int int ) latitude / longitude boundary } of this coordinate reference system as a polygon in WKT . It is used in the OpenLayers map in NCSS as well as the datasetBoundaries endpoint . [CODESPLIT] public String getLatLonBoundaryAsWKT ( int maxPointsInYEdge , int maxPointsInXEdge ) { List < LatLonPointNoNormalize > points = calcConnectedLatLonBoundaryPoints ( maxPointsInYEdge , maxPointsInXEdge ) ; StringBuilder sb = new StringBuilder ( "POLYGON((" ) ; for ( LatLonPointNoNormalize point : points ) { sb . append ( String . format ( "%.3f %.3f, " , point . getLongitude ( ) , point . getLatitude ( ) ) ) ; } sb . delete ( sb . length ( ) - 2 , sb . length ( ) ) ; // Nuke trailing comma and space. sb . append ( "))" ) ; return sb . toString ( ) ; }


Input: Provide defaults for a settings map [CODESPLIT] static synchronized protected void setDefaults ( Map < Prop , Object > props ) { if ( false ) { // turn off for now props . put ( Prop . HANDLE_AUTHENTICATION , Boolean . TRUE ) ; } props . put ( Prop . HANDLE_REDIRECTS , Boolean . TRUE ) ; props . put ( Prop . ALLOW_CIRCULAR_REDIRECTS , Boolean . TRUE ) ; props . put ( Prop . MAX_REDIRECTS , ( Integer ) DFALTREDIRECTS ) ; props . put ( Prop . SO_TIMEOUT , ( Integer ) DFALTSOTIMEOUT ) ; props . put ( Prop . CONN_TIMEOUT , ( Integer ) DFALTCONNTIMEOUT ) ; props . put ( Prop . CONN_REQ_TIMEOUT , ( Integer ) DFALTCONNREQTIMEOUT ) ; props . put ( Prop . USER_AGENT , DFALTUSERAGENT ) ; }


Input: Timeouts [CODESPLIT] static synchronized public void setGlobalConnectionTimeout ( int timeout ) { if ( timeout >= 0 ) { globalsettings . put ( Prop . CONN_TIMEOUT , ( Integer ) timeout ) ; globalsettings . put ( Prop . CONN_REQ_TIMEOUT , ( Integer ) timeout ) ; } }


Input: Compression [CODESPLIT] static synchronized public void setGlobalCompression ( String compressors ) { if ( globalsettings . get ( Prop . COMPRESSION ) != null ) removeGlobalCompression ( ) ; String compresslist = checkCompressors ( compressors ) ; if ( HTTPUtil . nullify ( compresslist ) == null ) throw new IllegalArgumentException ( "Bad compressors: " + compressors ) ; globalsettings . put ( Prop . COMPRESSION , compresslist ) ; HttpResponseInterceptor hrsi ; if ( compresslist . contains ( "gzip" ) ) { hrsi = new GZIPResponseInterceptor ( ) ; rspintercepts . add ( hrsi ) ; } if ( compresslist . contains ( "deflate" ) ) { hrsi = new DeflateResponseInterceptor ( ) ; rspintercepts . add ( hrsi ) ; } }


Input: It is convenient to be able to directly set the Credentials ( not the provider ) when those credentials are fixed . [CODESPLIT] static public void setGlobalCredentials ( Credentials creds , AuthScope scope ) throws HTTPException { assert ( creds != null ) ; if ( scope == null ) scope = AuthScope . ANY ; CredentialsProvider provider = new BasicCredentialsProvider ( ) ; provider . setCredentials ( scope , creds ) ; setGlobalCredentialsProvider ( provider , scope ) ; }


Input: Interceptors : Only supported at global level [CODESPLIT] static protected void setInterceptors ( HttpClientBuilder cb ) { for ( HttpRequestInterceptor hrq : reqintercepts ) { cb . addInterceptorLast ( hrq ) ; } for ( HttpResponseInterceptor hrs : rspintercepts ) { cb . addInterceptorLast ( hrs ) ; } // Add debug interceptors for ( HttpRequestInterceptor hrq : dbgreq ) { cb . addInterceptorFirst ( hrq ) ; } for ( HttpResponseInterceptor hrs : dbgrsp ) { cb . addInterceptorFirst ( hrs ) ; } // Hack: add Content-Encoding suppressor cb . addInterceptorFirst ( CEKILL ) ; }


Input: Extract the sessionid cookie value [CODESPLIT] public String getSessionID ( ) { String sid = null ; String jsid = null ; List < Cookie > cookies = this . sessioncontext . getCookieStore ( ) . getCookies ( ) ; for ( Cookie cookie : cookies ) { if ( cookie . getName ( ) . equalsIgnoreCase ( "sessionid" ) ) sid = cookie . getValue ( ) ; if ( cookie . getName ( ) . equalsIgnoreCase ( "jsessionid" ) ) jsid = cookie . getValue ( ) ; } return ( sid == null ? jsid : sid ) ; }


Input: Set the max number of redirects to follow [CODESPLIT] public HTTPSession setMaxRedirects ( int n ) { if ( n < 0 ) //validate throw new IllegalArgumentException ( "setMaxRedirects" ) ; localsettings . put ( Prop . MAX_REDIRECTS , n ) ; this . cachevalid = false ; return this ; }


Input: Enable / disable redirection following Default is yes . [CODESPLIT] public HTTPSession setFollowRedirects ( boolean tf ) { localsettings . put ( Prop . HANDLE_REDIRECTS , ( Boolean ) tf ) ; this . cachevalid = false ; return this ; }


Input: Should we use sessionid s? [CODESPLIT] public HTTPSession setUseSessions ( boolean tf ) { localsettings . put ( Prop . USESESSIONS , ( Boolean ) tf ) ; this . cachevalid = false ; return this ; }


Input: Close the session . This implies closing any open methods . [CODESPLIT] synchronized public void close ( ) { if ( this . closed ) return ; // multiple calls ok closed = true ; for ( HTTPMethod m : this . methods ) { m . close ( ) ; // forcibly close; will invoke removemethod(). } methods . clear ( ) ; }


Input: This is the most general case [CODESPLIT] public HTTPSession setCredentialsProvider ( CredentialsProvider provider , AuthScope scope ) throws HTTPException { if ( provider == null ) throw new NullPointerException ( this . getClass ( ) . getName ( ) ) ; if ( scope == null ) scope = AuthScope . ANY ; localcreds . put ( scope , provider ) ; return this ; }


Input: It is convenient to be able to directly set the Credentials ( not the provider ) when those credentials are fixed . [CODESPLIT] public HTTPSession setCredentials ( Credentials creds , AuthScope scope ) throws HTTPException { assert ( creds != null ) ; if ( scope == null ) scope = AuthScope . ANY ; CredentialsProvider provider = new BasicCredentialsProvider ( ) ; provider . setCredentials ( scope , creds ) ; setCredentialsProvider ( provider , scope ) ; return this ; }


Input: Handle authentication and Proxy ing [CODESPLIT] synchronized protected void setAuthenticationAndProxy ( HttpClientBuilder cb ) throws HTTPException { // First, setup the ssl factory cb . setSSLSocketFactory ( ( SSLConnectionSocketFactory ) authcontrols . get ( AuthProp . SSLFACTORY ) ) ; // Second, Construct a CredentialsProvider that is // the union of the Proxy credentials plus // either the global or local credentials; local overrides global // Unfortunately, we cannot either clone or extract the contents // of the client supplied provider, so we are forced (for now) // to modify the client supplied provider. // Look in the local credentials first for for best scope match AuthScope bestMatch = HTTPAuthUtil . bestmatch ( scope , localcreds . keySet ( ) ) ; CredentialsProvider cp = null ; if ( bestMatch != null ) { cp = localcreds . get ( bestMatch ) ; } else { bestMatch = HTTPAuthUtil . bestmatch ( scope , globalcredfactories . keySet ( ) ) ; if ( bestMatch != null ) { HTTPProviderFactory factory = globalcredfactories . get ( bestMatch ) ; cp = factory . getProvider ( bestMatch ) ; } } // Build the proxy credentials and AuthScope Credentials proxycreds = null ; AuthScope proxyscope = null ; String user = ( String ) authcontrols . get ( AuthProp . PROXYUSER ) ; String pwd = ( String ) authcontrols . get ( AuthProp . PROXYPWD ) ; HttpHost httpproxy = ( HttpHost ) authcontrols . get ( AuthProp . HTTPPROXY ) ; HttpHost httpsproxy = ( HttpHost ) authcontrols . get ( AuthProp . HTTPSPROXY ) ; if ( user != null && ( httpproxy != null || httpsproxy != null ) ) { if ( httpproxy != null ) proxyscope = HTTPAuthUtil . hostToAuthScope ( httpproxy ) ; else //httpsproxy != null proxyscope = HTTPAuthUtil . hostToAuthScope ( httpsproxy ) ; proxycreds = new UsernamePasswordCredentials ( user , pwd ) ; } if ( cp == null && proxycreds != null && proxyscope != null ) { // If client provider is null and proxycreds are not, // then use proxycreds alone cp = new BasicCredentialsProvider ( ) ; cp . setCredentials ( proxyscope , proxycreds ) ; } else if ( cp != null && proxycreds != null && proxyscope != null ) { // If client provider is not null and proxycreds are not, // then add proxycreds to the client provider cp . setCredentials ( proxyscope , proxycreds ) ; } if ( cp != null ) this . sessioncontext . setCredentialsProvider ( cp ) ; }


Input: / * package scope [CODESPLIT] public Map < Prop , Object > mergedSettings ( ) { Map < Prop , Object > merged ; synchronized ( this ) { // keep coverity happy //Merge Settings; merged = HTTPUtil . merge ( globalsettings , localsettings ) ; } return Collections . unmodifiableMap ( merged ) ; }


Input: Utilities [CODESPLIT] static String getCanonicalURL ( String legalurl ) { if ( legalurl == null ) return null ; int index = legalurl . indexOf ( ' ' ) ; if ( index >= 0 ) legalurl = legalurl . substring ( 0 , index ) ; // remove any trailing extension //index = legalurl.lastIndexOf('.'); //if(index >= 0) legalurl = legalurl.substring(0,index); return HTTPUtil . canonicalpath ( legalurl ) ; }


Input: If we are testing then track the sessions for kill [CODESPLIT] static protected synchronized void track ( HTTPSession session ) { if ( ! TESTING ) throw new UnsupportedOperationException ( ) ; if ( sessionList == null ) sessionList = new ConcurrentSkipListSet < HTTPSession > ( ) ; sessionList . add ( session ) ; }


Input: / * Only allow if debugging [CODESPLIT] static public void clearkeystore ( ) { if ( ! TESTING ) throw new UnsupportedOperationException ( ) ; authcontrols . setReadOnly ( false ) ; authcontrols . remove ( AuthProp . KEYSTORE ) ; authcontrols . remove ( AuthProp . KEYPASSWORD ) ; authcontrols . remove ( AuthProp . TRUSTSTORE ) ; authcontrols . remove ( AuthProp . TRUSTPASSWORD ) ; authcontrols . setReadOnly ( true ) ; }


Input: / * Only allow if debugging [CODESPLIT] static public void rebuildkeystore ( String path , String pwd ) { if ( ! TESTING ) throw new UnsupportedOperationException ( ) ; KeyStore newks = buildkeystore ( path , pwd ) ; authcontrols . setReadOnly ( false ) ; authcontrols . put ( AuthProp . KEYSTORE , newks ) ; authcontrols . setReadOnly ( true ) ; }


Input: Deprecated but here for back compatibility [CODESPLIT] @ Deprecated static public void setGlobalCredentialsProvider ( AuthScope scope , CredentialsProvider provider ) throws HTTPException { setGlobalCredentialsProvider ( provider , scope ) ; }


Input: obsolete [CODESPLIT] static protected synchronized void kill ( ) { if ( sessionList != null ) { for ( HTTPSession session : sessionList ) { session . close ( ) ; } sessionList . clear ( ) ; connmgr . close ( ) ; } }


Input: This is the most general case [CODESPLIT] @ Deprecated static public void setGlobalCredentialsProvider ( CredentialsProvider provider , AuthScope scope ) throws HTTPException { HTTPProviderFactory factory = new SingleProviderFactory ( provider ) ; setCredentialsProviderFactory ( factory , scope ) ; }


Input: private DqcFactory dqcFactory = null ; [CODESPLIT] void validate ( String urlString ) { if ( urlString == null ) return ; URI uri ; try { uri = new URI ( urlString ) ; } catch ( URISyntaxException e ) { javax . swing . JOptionPane . showMessageDialog ( null , "URISyntaxException on URL (" + urlString + ") " + e . getMessage ( ) + "\n" ) ; return ; } String contents = getText ( ) ; //boolean isCatalog = contents.indexOf("queryCapability") < 0; ByteArrayInputStream is = new ByteArrayInputStream ( contents . getBytes ( CDM . utf8Charset ) ) ; try { CatalogBuilder catFactory = new CatalogBuilder ( ) ; Catalog cat = catFactory . buildFromLocation ( urlString , null ) ; boolean isValid = ! catFactory . hasFatalError ( ) ; javax . swing . JOptionPane . showMessageDialog ( this , "Catalog Validation = " + isValid + "\n" + catFactory . getErrorMessage ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }


Input: Generate a subclass of Index optimized for this array s rank [CODESPLIT] static public Index factory ( int [ ] shape ) { int rank = shape . length ; switch ( rank ) { case 0 : return new Index0D ( ) ; case 1 : return new Index1D ( shape ) ; case 2 : return new Index2D ( shape ) ; case 3 : return new Index3D ( shape ) ; case 4 : return new Index4D ( shape ) ; case 5 : return new Index5D ( shape ) ; case 6 : return new Index6D ( shape ) ; case 7 : return new Index7D ( shape ) ; default : return new Index ( shape ) ; } }


Input:
Compute standard strides based on array s shape . Ignore vlen [CODESPLIT] static private long computeStrides ( int [ ] shape , int [ ] stride ) { long product = 1 ; for ( int ii = shape . length - 1 ; ii >= 0 ; ii -- ) { final int thisDim = shape [ ii ] ; if ( thisDim < 0 ) continue ; // ignore vlen
 stride [ ii ] = ( int ) product ; product *= thisDim ; } return product ; }


Input:
Create a new Index based on current one except flip the index so that it runs from shape [ index ] - 1 to 0 . Leave rightmost vlen alone . [CODESPLIT] Index flip ( int index ) { if ( ( index < 0 ) || ( index >= rank ) ) throw new IllegalArgumentException ( ) ; Index i = ( Index ) this . clone ( ) ; if ( shape [ index ] >= 0 ) { // !vlen case
 i . offset += stride [ index ] * ( shape [ index ] - 1 ) ; i . stride [ index ] = - stride [ index ] ; } i . fastIterator = false ; i . precalc ( ) ; // any subclass-specific optimizations
 return i ; }


Input:
create a new Index based on a subsection of this one with rank reduction if dimension length == 1 . [CODESPLIT] Index section ( List < Range > ranges ) throws InvalidRangeException { // check ranges are valid
 if ( ranges . size ( ) != rank ) throw new InvalidRangeException ( "Bad ranges [] length" ) ; for ( int ii = 0 ; ii < rank ; ii ++ ) { Range r = ranges . get ( ii ) ; if ( r == null ) continue ; if ( r == Range . VLEN ) continue ; if ( ( r . first ( ) < 0 ) || ( r . first ( ) >= shape [ ii ] ) ) throw new InvalidRangeException ( "Bad range starting value at index " + ii + " == " + r . first ( ) ) ; if ( ( r . last ( ) < 0 ) || ( r . last ( ) >= shape [ ii ] ) ) throw new InvalidRangeException ( "Bad range ending value at index " + ii + " == " + r . last ( ) ) ; } int reducedRank = rank ; for ( Range r : ranges ) { if ( ( r != null ) && ( r . length ( ) == 1 ) ) reducedRank -- ; } Index newindex = Index . factory ( reducedRank ) ; newindex . offset = offset ; // calc shape, size, and index transformations
 // calc strides into original (backing) store
 int newDim = 0 ; for ( int ii = 0 ; ii < rank ; ii ++ ) { Range r = ranges . get ( ii ) ; if ( r == null ) { // null range means use the whole original dimension
 newindex . shape [ newDim ] = shape [ ii ] ; newindex . stride [ newDim ] = stride [ ii ] ; //if (name != null) newindex.name[newDim] = name[ii];
 newDim ++ ; } else if ( r . length ( ) != 1 ) { newindex . shape [ newDim ] = r . length ( ) ; newindex . stride [ newDim ] = stride [ ii ] * r . stride ( ) ; newindex . offset += stride [ ii ] * r . first ( ) ; //if (name != null) newindex.name[newDim] = name[ii];
 newDim ++ ; } else { newindex . offset += stride [ ii ] * r . first ( ) ; // constant due to rank reduction
 } } newindex . size = computeSize ( newindex . shape ) ; newindex . fastIterator = fastIterator && ( newindex . size == size ) ; // if equal, then its not a real subset, so can still use fastIterator
 newindex . precalc ( ) ; // any subclass-specific optimizations
 return newindex ; }


Input:
Create a new Index based on current one by eliminating any dimensions with length one . [CODESPLIT] Index reduce ( ) { Index c = this ; for ( int ii = 0 ; ii < rank ; ii ++ ) if ( shape [ ii ] == 1 ) { // do this on the first one you find
 Index newc = c . reduce ( ii ) ; return newc . reduce ( ) ; // any more to do?
 } return c ; }


Input:
Create a new Index based on current one by eliminating the specified dimension ; [CODESPLIT] Index reduce ( int dim ) { if ( ( dim < 0 ) || ( dim >= rank ) ) throw new IllegalArgumentException ( "illegal reduce dim " + dim ) ; if ( shape [ dim ] != 1 ) throw new IllegalArgumentException ( "illegal reduce dim " + dim + " : length != 1" ) ; Index newindex = Index . factory ( rank - 1 ) ; newindex . offset = offset ; int count = 0 ; for ( int ii = 0 ; ii < rank ; ii ++ ) { if ( ii != dim ) { newindex . shape [ count ] = shape [ ii ] ; newindex . stride [ count ] = stride [ ii ] ; //if (name != null) newindex.name[count] = name[ii];
 count ++ ; } } newindex . size = computeSize ( newindex . shape ) ; newindex . fastIterator = fastIterator ; newindex . precalc ( ) ; // any subclass-specific optimizations
 return newindex ; }


Input:
create a new Index based on current one except transpose two of the indices . [CODESPLIT] Index transpose ( int index1 , int index2 ) { if ( ( index1 < 0 ) || ( index1 >= rank ) ) throw new IllegalArgumentException ( ) ; if ( ( index2 < 0 ) || ( index2 >= rank ) ) throw new IllegalArgumentException ( ) ; Index newIndex = ( Index ) this . clone ( ) ; newIndex . stride [ index1 ] = stride [ index2 ] ; newIndex . stride [ index2 ] = stride [ index1 ] ; newIndex . shape [ index1 ] = shape [ index2 ] ; newIndex . shape [ index2 ] = shape [ index1 ] ; /* if (name != null) {
      newIndex.name[index1] = name[index2];
      newIndex.name[index2] = name[index1];
    } */ newIndex . fastIterator = false ; newIndex . precalc ( ) ; // any subclass-specific optimizations
 return newIndex ; }


Input:
create a new Index based on a permutation of the current indices ; vlen fails . [CODESPLIT] Index permute ( int [ ] dims ) { if ( dims . length != shape . length ) throw new IllegalArgumentException ( ) ; for ( int dim : dims ) if ( ( dim < 0 ) || ( dim >= rank ) ) throw new IllegalArgumentException ( ) ; boolean isPermuted = false ; Index newIndex = ( Index ) this . clone ( ) ; for ( int i = 0 ; i < dims . length ; i ++ ) { newIndex . stride [ i ] = stride [ dims [ i ] ] ; newIndex . shape [ i ] = shape [ dims [ i ] ] ; //if (name != null) newIndex.name[i] = name[dims[i]];
 if ( i != dims [ i ] ) isPermuted = true ; } newIndex . fastIterator = fastIterator && ! isPermuted ; // useful optimization
 newIndex . precalc ( ) ; // any subclass-specific optimizations
 return newIndex ; }


Input: Get an index iterator for traversing the array in canonical order . [CODESPLIT] IndexIterator getIndexIterator ( Array maa ) { if ( fastIterator ) return new IteratorFast ( size , maa ) ; else return new IteratorImpl ( maa ) ; }


Input:
Get the current element s index into the 1D backing array . VLEN stops processing . [CODESPLIT] public int currentElement ( ) { int value = offset ; // NB: dont have to check each index again
 for ( int ii = 0 ; ii < rank ; ii ++ ) { // general rank
 if ( shape [ ii ] < 0 ) break ; //vlen
 value += current [ ii ] * stride [ ii ] ; } return value ; }


Input:
Set the current counter from the 1D current element currElement = offset + stride [ 0 ] * current [ 0 ] + ... [CODESPLIT] public void setCurrentCounter ( int currElement ) { currElement -= offset ; for ( int ii = 0 ; ii < rank ; ii ++ ) { // general rank
 if ( shape [ ii ] < 0 ) { current [ ii ] = - 1 ; break ; } current [ ii ] = currElement / stride [ ii ] ; currElement -= current [ ii ] * stride [ ii ] ; } set ( current ) ; // transfer to subclass fields
 }


Input: Set the current element s index . General - rank case . [CODESPLIT] public Index set ( int [ ] index ) { if ( index . length != rank ) throw new ArrayIndexOutOfBoundsException ( ) ; if ( rank == 0 ) return this ; int prefixrank = ( hasvlen ? rank : rank - 1 ) ; System . arraycopy ( index , 0 , current , 0 , prefixrank ) ; if ( hasvlen ) current [ prefixrank ] = - 1 ; return this ; }


Input:
set current element at dimension dim to v [CODESPLIT] public void setDim ( int dim , int value ) { if ( value < 0 || value >= shape [ dim ] ) // check index here
 throw new ArrayIndexOutOfBoundsException ( ) ; if ( shape [ dim ] >= 0 ) //!vlen
 current [ dim ] = value ; }


Input: set current element at dimension 0 1 2 to v0 v1 v2 [CODESPLIT] public Index set ( int v0 , int v1 , int v2 ) { setDim ( 0 , v0 ) ; setDim ( 1 , v1 ) ; setDim ( 2 , v2 ) ; return this ; }


Input:
String representation [CODESPLIT] public String toStringDebug ( ) { StringBuilder sbuff = new StringBuilder ( 100 ) ; sbuff . setLength ( 0 ) ; sbuff . append ( " shape= " ) ; for ( int ii = 0 ; ii < rank ; ii ++ ) { sbuff . append ( shape [ ii ] ) ; sbuff . append ( " " ) ; } sbuff . append ( " stride= " ) ; for ( int ii = 0 ; ii < rank ; ii ++ ) { sbuff . append ( stride [ ii ] ) ; sbuff . append ( " " ) ; } /* if (name != null) {
      sbuff.append(" names= ");
      for (int ii = 0; ii < rank; ii++) {
        sbuff.append(name[ii]);
        sbuff.append(" ");
      }
    } */ sbuff . append ( " offset= " ) . append ( offset ) ; sbuff . append ( " rank= " ) . append ( rank ) ; sbuff . append ( " size= " ) . append ( size ) ; sbuff . append ( " current= " ) ; for ( int ii = 0 ; ii < rank ; ii ++ ) { sbuff . append ( current [ ii ] ) ; sbuff . append ( " " ) ; } return sbuff . toString ( ) ; }


Input: Check if we all time intervals have the same length . [CODESPLIT] public String getTimeIntervalName ( ) { // are they the same length ? int firstValue = - 1 ; for ( TimeCoordIntvValue tinv : timeIntervals ) { int value = ( tinv . getBounds2 ( ) - tinv . getBounds1 ( ) ) ; if ( firstValue < 0 ) firstValue = value ; else if ( value != firstValue ) return MIXED_INTERVALS ; } firstValue = ( firstValue * timeUnit . getValue ( ) ) ; return firstValue + "_" + timeUnit . getField ( ) . toString ( ) ; }


Input: Make calendar date range using the first and last ending bounds [CODESPLIT] @ Override public CalendarDateRange makeCalendarDateRange ( ucar . nc2 . time . Calendar cal ) { CalendarDateUnit cdu = CalendarDateUnit . of ( cal , timeUnit . getField ( ) , refDate ) ; CalendarDate start = cdu . makeCalendarDate ( timeUnit . getValue ( ) * timeIntervals . get ( 0 ) . getBounds2 ( ) ) ; CalendarDate end = cdu . makeCalendarDate ( timeUnit . getValue ( ) * timeIntervals . get ( getSize ( ) - 1 ) . getBounds2 ( ) ) ; return CalendarDateRange . of ( start , end ) ; }


Input: Initialize this reader . Get the Grid specific info [CODESPLIT] protected boolean init ( boolean fullCheck ) throws IOException { //Trace.startTrace(); if ( ! super . init ( fullCheck ) ) { return false ; } if ( ( dmLabel . kftype != MFSN ) && ( dmLabel . kftype != MFSF ) ) { logError ( "not a point data file " ) ; return false ; } return true ; }


Input: Read in the stations and times . Subclasses should call this during init () [CODESPLIT] protected boolean readStationsAndTimes ( boolean uniqueTimes ) { for ( DMPart apart : parts ) { List < GempakParameter > params = makeParams ( apart ) ; partParamMap . put ( apart . kprtnm , params ) ; } // get the date/time keys dateTimeKeys = getDateTimeKeys ( ) ; if ( ( dateTimeKeys == null ) || dateTimeKeys . isEmpty ( ) ) { return false ; } // get the station info stationKeys = findStationKeys ( ) ; if ( ( stationKeys == null ) || stationKeys . isEmpty ( ) ) { return false ; } stations = getStationList ( ) ; makeFileSubType ( ) ; // null out the old cached list dates = null ; dateList = makeDateList ( uniqueTimes ) ; return true ; }


Input: Get the date / time information [CODESPLIT] private List < Key > getDateTimeKeys ( ) { Key date = findKey ( DATE ) ; Key time = findKey ( TIME ) ; if ( ( date == null ) || ( time == null ) || ! date . type . equals ( time . type ) ) { return null ; } List < Key > dt = new ArrayList <> ( 2 ) ; dt . add ( date ) ; dt . add ( time ) ; return dt ; }


Input: Get the list of dates [CODESPLIT] protected List < String > makeDateList ( boolean unique ) { Key date = dateTimeKeys . get ( 0 ) ; Key time = dateTimeKeys . get ( 1 ) ; List < int [ ] > toCheck ; if ( date . type . equals ( ROW ) ) { toCheck = headers . rowHeaders ; } else { toCheck = headers . colHeaders ; } List < String > fileDates = new ArrayList <> ( ) ; for ( int [ ] header : toCheck ) { if ( header [ 0 ] != IMISSD ) { // convert to GEMPAK date/time int idate = header [ date . loc + 1 ] ; int itime = header [ time . loc + 1 ] ; // TODO: Add in the century String dateTime = GempakUtil . TI_CDTM ( idate , itime ) ; fileDates . add ( dateTime ) ; } } if ( unique && ! fileDates . isEmpty ( ) ) { SortedSet < String > uniqueTimes = Collections . synchronizedSortedSet ( new TreeSet < String > ( ) ) ; uniqueTimes . addAll ( fileDates ) ; fileDates . clear ( ) ; fileDates . addAll ( uniqueTimes ) ; } return fileDates ; }


Input: Make GempakParameters from the list of [CODESPLIT] private List < GempakParameter > makeParams ( DMPart part ) { List < GempakParameter > gemparms = new ArrayList <> ( part . kparms ) ; for ( DMParam param : part . params ) { String name = param . kprmnm ; GempakParameter parm = GempakParameters . getParameter ( name ) ; if ( parm == null ) { //System.out.println("couldn't find " + name //                   + " in params table"); parm = new GempakParameter ( 1 , name , name , "" , 0 ) ; } gemparms . add ( parm ) ; } return gemparms ; }


Input: Get the station list [CODESPLIT] private List < GempakStation > getStationList ( ) { Key slat = findKey ( GempakStation . SLAT ) ; if ( slat == null ) { return null ; } List < int [ ] > toCheck ; if ( slat . type . equals ( ROW ) ) { toCheck = headers . rowHeaders ; } else { toCheck = headers . colHeaders ; } List < GempakStation > fileStations = new ArrayList <> ( ) ; int i = 0 ; for ( int [ ] header : toCheck ) { if ( header [ 0 ] != IMISSD ) { GempakStation station = makeStation ( header ) ; if ( station != null ) { station . setIndex ( i + 1 ) ; fileStations . add ( station ) ; } } i ++ ; } return fileStations ; }


Input: Make a station from the header info [CODESPLIT] private GempakStation makeStation ( int [ ] header ) { if ( ( stationKeys == null ) || stationKeys . isEmpty ( ) ) { return null ; } GempakStation newStation = new GempakStation ( ) ; for ( Key key : stationKeys ) { int loc = key . loc + 1 ; switch ( key . name ) { case GempakStation . STID : newStation . setSTID ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; case GempakStation . STNM : newStation . setSTNM ( header [ loc ] ) ; break ; case GempakStation . SLAT : newStation . setSLAT ( header [ loc ] ) ; break ; case GempakStation . SLON : newStation . setSLON ( header [ loc ] ) ; break ; case GempakStation . SELV : newStation . setSELV ( header [ loc ] ) ; break ; case GempakStation . SPRI : newStation . setSPRI ( header [ loc ] ) ; break ; case GempakStation . STAT : newStation . setSTAT ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; case GempakStation . COUN : newStation . setCOUN ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; case GempakStation . SWFO : newStation . setSWFO ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; case GempakStation . WFO2 : newStation . setWFO2 ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; case GempakStation . STD2 : newStation . setSTD2 ( GempakUtil . ST_ITOC ( header [ loc ] ) . trim ( ) ) ; break ; } } return newStation ; }


Input: Get the station key names [CODESPLIT] public List < String > getStationKeyNames ( ) { List < String > keys = new ArrayList <> ( ) ; if ( ( stationKeys != null ) && ! stationKeys . isEmpty ( ) ) { for ( Key key : stationKeys ) { keys . add ( key . name ) ; } } return keys ; }


Input: Get the station keys [CODESPLIT] private List < Key > findStationKeys ( ) { Key stid = findKey ( GempakStation . STID ) ; Key stnm = findKey ( GempakStation . STNM ) ; Key slat = findKey ( GempakStation . SLAT ) ; Key slon = findKey ( GempakStation . SLON ) ; Key selv = findKey ( GempakStation . SELV ) ; Key stat = findKey ( GempakStation . STAT ) ; Key coun = findKey ( GempakStation . COUN ) ; Key std2 = findKey ( GempakStation . STD2 ) ; Key spri = findKey ( GempakStation . SPRI ) ; Key swfo = findKey ( GempakStation . SWFO ) ; Key wfo2 = findKey ( GempakStation . WFO2 ) ; if ( ( slat == null ) || ( slon == null ) || ! slat . type . equals ( slon . type ) ) { return null ; } String tslat = slat . type ; // check to make sure they are all in the same set of keys List < Key > stKeys = new ArrayList <> ( ) ; stKeys . add ( slat ) ; stKeys . add ( slon ) ; if ( ( stid != null ) && ! stid . type . equals ( tslat ) ) { return null ; } else if ( ( stnm != null ) && ! stnm . type . equals ( tslat ) ) { return null ; } else if ( ( selv != null ) && ! selv . type . equals ( tslat ) ) { return null ; } else if ( ( stat != null ) && ! stat . type . equals ( tslat ) ) { return null ; } else if ( ( coun != null ) && ! coun . type . equals ( tslat ) ) { return null ; } else if ( ( std2 != null ) && ! std2 . type . equals ( tslat ) ) { return null ; } else if ( ( spri != null ) && ! spri . type . equals ( tslat ) ) { return null ; } else if ( ( swfo != null ) && ! swfo . type . equals ( tslat ) ) { return null ; } else if ( ( wfo2 != null ) && ! wfo2 . type . equals ( tslat ) ) { return null ; } if ( stid != null ) { stKeys . add ( stid ) ; } if ( stnm != null ) { stKeys . add ( stnm ) ; } if ( selv != null ) { stKeys . add ( selv ) ; } if ( stat != null ) { stKeys . add ( stat ) ; } if ( coun != null ) { stKeys . add ( coun ) ; } if ( std2 != null ) { stKeys . add ( std2 ) ; } if ( spri != null ) { stKeys . add ( spri ) ; } if ( swfo != null ) { stKeys . add ( swfo ) ; } if ( wfo2 != null ) { stKeys . add ( wfo2 ) ; } return stKeys ; }


Input: Get the list of dates in this file . [CODESPLIT] public List < Date > getDates ( ) { if ( ( dates == null || dates . isEmpty ( ) ) && ! dateList . isEmpty ( ) ) { dates = new ArrayList <> ( dateList . size ( ) ) ; dateFmt . setTimeZone ( TimeZone . getTimeZone ( "GMT" ) ) ; for ( String dateString : dateList ) { Date d = dateFmt . parse ( dateString , new ParsePosition ( 0 ) ) ; //DateFromString.getDateUsingSimpleDateFormat(dateString, //    DATE_FORMAT); dates . add ( d ) ; } } return dates ; }


Input: Print the list of dates in the file [CODESPLIT] public void printDates ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "\nDates:\n" ) ; for ( String date : dateList ) { builder . append ( "\t" ) ; builder . append ( date ) ; builder . append ( "\n" ) ; } System . out . println ( builder . toString ( ) ) ; }


Input: Print the list of dates in the file [CODESPLIT] public void printStations ( boolean list ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "\nStations:\n" ) ; if ( list ) { for ( GempakStation station : getStations ( ) ) { builder . append ( station ) ; builder . append ( "\n" ) ; } } else { builder . append ( "\t" ) ; builder . append ( getStations ( ) . size ( ) ) ; } System . out . println ( builder . toString ( ) ) ; }


Input: Find the station index for the specified station id . [CODESPLIT] public int findStationIndex ( String id ) { for ( GempakStation station : getStations ( ) ) { if ( station . getSTID ( ) . equals ( id ) ) { return station . getIndex ( ) ; } } return - 1 ; }


Input: Get the type for this file [CODESPLIT] public String getFileType ( ) { String type = "Unknown" ; switch ( dmLabel . kftype ) { case MFSN : type = "Sounding" ; break ; case MFSF : type = "Surface" ; break ; default : } if ( ! subType . equals ( "" ) ) { type = type + " (" + subType + ")" ; } return type ; }


Input: Set depth + = n [CODESPLIT] public void indent ( int n ) { depth += n ; if ( depth < 0 ) depth = 0 ; else if ( depth > MAXDEPTH ) depth = MAXDEPTH ; }


Input: Set depth = n [CODESPLIT] public void setIndent ( int n ) { depth = n ; if ( depth < 0 ) depth = 0 ; else if ( depth > MAXDEPTH ) depth = MAXDEPTH ; }


Input: / * Only call on the root node [CODESPLIT] public void init ( CEEvaluator ceEval , BaseTypeFactory factory , ClauseFactory clauseFactory , ServerDDS sdds , List < AST > nodes ) { this . ceEval = ceEval ; this . clauseFactory = clauseFactory ; this . factory = factory ; this . sdds = sdds ; this . root = this ; for ( AST node : nodes ) node . setRoot ( this ) ; }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; boolean first = true ; if ( projections ! = null ) for ( ASTprojection p : projections ) { buf . append (( first ? : ) + p . toString () ) ; first = false ; } first = true ; if ( selections ! = null ) for ( ASTclause c : selections ) { buf . append ( c . toString () ) ; first = false ; } return buf . toString () ; } [CODESPLIT] public void walkConstraint ( ) throws DAP2ServerSideException , DAP2Exception { if ( projections != null ) for ( ASTprojection proj : projections ) { proj . walk ( ceEval ) ; } else getCeEval ( ) . markAll ( true ) ; if ( selections != null ) for ( ASTclause cl : selections ) { getCeEval ( ) . appendClause ( cl . translate ( ) ) ; } }


Input: / * public String toString () { if ( var ! = null ) return var . toString () ; else return fcn . toString () ; } [CODESPLIT] void walk ( CEEvaluator ceEval ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { if ( fcn != null ) { SubClause subclause = fcn . translate ( ) ; getCeEval ( ) . appendClause ( subclause ) ; } else { Stack components = new Stack ( ) ; components = var . collect ( components ) ; markStackedVariables ( components ) ; } }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; boolean first = true ; buf . append ( fcnname ) ; buf . append ( ( ) ; if ( args ! = null ) for ( ASTvalue arg : args ) { if ( !first ) buf . append ( ) ; else { first = false ; } buf . append ( arg . toString () ) ; } buf . append ( ) ) ; return buf . toString () ; } [CODESPLIT] SubClause translate ( ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { SubClause subclause = null ; Vector < SubClause > cvtargs = new Vector < SubClause > ( ) ; if ( args != null ) for ( ASTvalue arg : args ) cvtargs . addElement ( arg . translate ( ) ) ; subclause = getClauseFactory ( ) . newBTFunctionClause ( fcnname , cvtargs ) ; return subclause ; }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; boolean first = true ; for ( ASTsegment seg : segments ) { buf . append (( first ? : . ) + seg . toString () ) ; first = false ; } return buf . toString () ; } [CODESPLIT] Stack collect ( Stack components ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { for ( ASTsegment segment : segments ) { components = segment . collect ( components ) ; } return components ; }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; buf . append ( name ) ; if ( slices ! = null ) for ( ASTslice slice : slices ) { buf . append ( slice . toString () ) ; } return buf . toString () ; } [CODESPLIT] Stack collect ( Stack components ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { BaseType bt = null ; ServerArrayMethods sam = null ; components = getSdds ( ) . search ( name , components ) ; if ( slices != null && slices . size ( ) > 0 ) { try { bt = ( BaseType ) components . peek ( ) ; } catch ( ClassCastException cce ) { String msg = "Attempt to treat the variable `" + name + "' as if it is an array." ; throw new DAP2Exception ( DAP2Exception . MALFORMED_EXPR , msg ) ; } if ( bt instanceof DGrid ) { // project the grid and the coordinate variable DGrid grid = ( ( DGrid ) bt ) ; bt = grid . getArray ( ) ; sam = ( ServerArrayMethods ) bt ; for ( int i = 0 ; i < slices . size ( ) ; i ++ ) { ASTslice slice = slices . get ( i ) ; slice . walk ( sam , i ) ; } // walk the coordinate variables also for ( int i = 0 ; i < slices . size ( ) ; i ++ ) { ASTslice slice = slices . get ( i ) ; bt = grid . getVar ( i + 1 ) ; sam = ( ServerArrayMethods ) bt ; slice . walk ( sam , 0 ) ; } } else if ( bt instanceof ServerArrayMethods ) { sam = ( ServerArrayMethods ) bt ; for ( int i = 0 ; i < slices . size ( ) ; i ++ ) { ASTslice slice = slices . get ( i ) ; slice . walk ( sam , i ) ; } } } return components ; }


Input: / * public String toString () { if ( stride == 1 ) { if ( first == last ) return String . format ( [ %d ] first ) ; else return String . format ( [ %d : %d ] first last ) ; } else return String . format ( [ %d : %d : %d ] first stride last ) ; } [CODESPLIT] void walk ( ServerArrayMethods sam , int index ) throws InvalidDimensionException , SBHException { sam . setProjection ( index , ( int ) start , ( int ) stride , ( int ) stop ) ; }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; if ( constant ! = null ) buf . append ( constant . toString () ) ; else if ( var ! = null ) buf . append ( var . toString () ) ; else if ( fcn ! = null ) buf . append ( fcn . toString () ) ; else assert ( false ) ; return buf . toString () ; } [CODESPLIT] SubClause translate ( ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { SubClause subclause = null ; if ( constant != null ) { subclause = constant . translate ( ) ; } else if ( var != null ) { Stack components = new Stack ( ) ; components = var . collect ( components ) ; subclause = getClauseFactory ( ) . newValueClause ( ( BaseType ) components . pop ( ) , false ) ; } else if ( fcn != null ) { subclause = fcn . translate ( ) ; } else assert ( false ) ; return subclause ; }


Input: / * public String toString () { StringBuilder buf = new StringBuilder () ; switch ( tag ) { case STRINGCONST : buf . append ( String . format ( \ %s \ text )) ; break ; case INTCONST : buf . append ( String . format ( %d intvalue )) ; break ; case FLOATCONST : buf . append ( String . format ( % . 1f floatvalue )) ; break ; default : assert ( false ) ; } return buf . toString () ; } [CODESPLIT] SubClause translate ( ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { SubClause subclause = null ; switch ( tag ) { case ExprParserConstants . INTCONST : { String s = String . format ( "%d" , intvalue ) ; DInt32 i = getFactory ( ) . newDInt32 ( s ) ; i . setValue ( ( int ) intvalue ) ; ( ( ServerMethods ) i ) . setRead ( true ) ; ( ( ServerMethods ) i ) . setProject ( true ) ; subclause = getClauseFactory ( ) . newValueClause ( i , false ) ; } break ; case ExprParserConstants . FLOATCONST : { String s = String . format ( "%.1f" , floatvalue ) ; DFloat64 f = getFactory ( ) . newDFloat64 ( s ) ; f . setValue ( floatvalue ) ; subclause = getClauseFactory ( ) . newValueClause ( f , false ) ; } break ; case ExprParserConstants . STRINGCONST : { DString s = getFactory ( ) . newDString ( text ) ; s . setValue ( text ) ; ( ( ServerMethods ) s ) . setRead ( true ) ; ( ( ServerMethods ) s ) . setProject ( true ) ; subclause = getClauseFactory ( ) . newValueClause ( s , false ) ; } break ; default : assert ( false ) ; } return subclause ; }


Input: / * public String toString () { if ( boolfcn ! = null ) { return & + boolfcn . toString () ; } else { StringBuilder buf = new StringBuilder ( & ) ; buf . append ( lhs . toString () ) ; buf . append ( operatorString ( operator )) ; boolean first = true ; if ( rhs . size () > 1 ) buf . append ( { ) ; if ( rhs ! = null ) for ( ASTvalue value : rhs ) { buf . append (( first ? : ) + value . toString () ) ; first = false ; } if ( rhs . size () > 1 ) buf . append ( } ) ; return buf . toString () ; } } [CODESPLIT] public Clause translate ( ) throws DAP2ServerSideException , DAP2Exception , NoSuchFunctionException , NoSuchVariableException { Clause clause = null ; if ( boolfcn != null ) clause = boolfcn . translate ( ) ; else { Vector < SubClause > cvtrhs = new Vector < SubClause > ( ) ; for ( ASTvalue v : rhs ) cvtrhs . addElement ( v . translate ( ) ) ; SubClause lhsclause = lhs . translate ( ) ; clause = getClauseFactory ( ) . newRelOpClause ( operator , lhsclause , cvtrhs ) ; } return clause ; }


Input: assume first dimension is TIME series [CODESPLIT] public void setVariable ( Variable v ) throws IOException { log . info ( "variable " + v . getShortName ( ) ) ; AbstractIntervalXYDataset dataset = null ; Dimension dim = v . getDimension ( 0 ) ; String dimName = dim . getShortName ( ) ; Attribute title = file . findGlobalAttribute ( "title" ) ; if ( title != null ) chart . setTitle ( title . getStringValue ( ) ) ; Variable varXdim = file . findVariable ( null , dimName ) ; boolean hasXdim = false ; if ( varXdim != null ) hasXdim = true ; boolean xIsTime = false ; XYPlot p = chart . getXYPlot ( ) ; if ( hasXdim ) { Attribute xUnit = varXdim . findAttribute ( "units" ) ; Attribute xAxis = varXdim . findAttribute ( "axis" ) ; if ( xUnit != null ) if ( xUnit . getStringValue ( ) . contains ( "since" ) ) xIsTime = true ; if ( xAxis != null ) if ( xAxis . getStringValue ( ) . equals ( "T" ) ) xIsTime = true ; if ( xUnit != null ) p . getDomainAxis ( ) . setLabel ( xUnit . getStringValue ( ) ) ; else p . getDomainAxis ( ) . setLabel ( dimName ) ; if ( xAxis != null ) log . info ( "X axis type " + xUnit . getDataType ( ) + " value " + xUnit . toString ( ) + " is Time " + xIsTime ) ; } int ax = 0 ; log . info ( "dataset count " + p . getDatasetCount ( ) ) ; if ( p . getDatasetCount ( ) >= 1 ) { if ( p . getDataset ( p . getDatasetCount ( ) - 1 ) != null ) { log . info ( "number in dataset " + p . getDataset ( 0 ) ) ; ax = p . getDatasetCount ( ) ; if ( ax > 0 ) { p . setRangeAxis ( ax , new NumberAxis ( ) ) ; } } } log . info ( "axis number " + ax ) ; final XYItemRenderer renderer = p . getRenderer ( ) ; if ( xIsTime ) { final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator ( StandardXYToolTipGenerator . DEFAULT_TOOL_TIP_FORMAT , new SimpleDateFormat ( "d-MMM-yyyy" ) , new DecimalFormat ( "0.00" ) ) ; renderer . setBaseToolTipGenerator ( g ) ; dataset = new TimeSeriesCollection ( ) ; } else { final StandardXYToolTipGenerator g = new StandardXYToolTipGenerator ( StandardXYToolTipGenerator . DEFAULT_TOOL_TIP_FORMAT , new DecimalFormat ( "0.00" ) , new DecimalFormat ( "0.00" ) ) ; renderer . setBaseToolTipGenerator ( g ) ; dataset = new XYSeriesCollection ( ) ; p . setDomainAxis ( new NumberAxis ( ) ) ; // change to NumberAxis from DateAxis which is what is created } p . getRangeAxis ( ax ) . setAutoRange ( true ) ; Attribute vUnit = v . findAttribute ( "units" ) ; Attribute vfill = v . findAttribute ( "_FillValue" ) ; double dfill = Double . NaN ; if ( vfill != null ) dfill = vfill . getNumericValue ( ) . doubleValue ( ) ; if ( vUnit != null ) p . getRangeAxis ( ax ) . setLabel ( vUnit . getStringValue ( ) ) ; NetcdfDataset fds = new NetcdfDataset ( file ) ; CoordinateAxis1DTime tm = null ; List < CalendarDate > dates = null ; Array varXarray = null ; if ( hasXdim ) { varXarray = varXdim . read ( ) ; if ( xIsTime ) { tm = CoordinateAxis1DTime . factory ( fds , new VariableDS ( null , varXdim , true ) , null ) ; dates = tm . getCalendarDates ( ) ; } } Array a = v . read ( ) ; Index idx = a . getIndex ( ) ; idx . setCurrentCounter ( 0 ) ; int d2 = 1 ; int rank = idx . getRank ( ) ; for ( int k = 1 ; k < rank ; k ++ ) { d2 *= idx . getShape ( k ) ; } log . info ( "variable : " + v . getShortName ( ) + " : dims " + v . getDimensionsString ( ) + " rank " + rank + " d2 " + d2 ) ; double max = - 1000 ; double min = 1000 ; for ( int j = 0 ; j < d2 ; j ++ ) { if ( rank > 1 ) idx . set1 ( j ) ; // this wont work for 3rd dimension > 1 String name = v . getShortName ( ) ; if ( d2 > 1 ) name += "-" + j ; Series s1 ; if ( xIsTime ) s1 = new TimeSeries ( name ) ; else s1 = new XYSeries ( name ) ; for ( int i = 0 ; i < idx . getShape ( 0 ) ; i ++ ) { idx . set0 ( i ) ; float f = a . getFloat ( idx ) ; if ( f != dfill ) { if ( ! Float . isNaN ( f ) ) { max = Math . max ( max , f ) ; min = Math . min ( min , f ) ; } if ( xIsTime ) { Date ts = new Date ( dates . get ( i ) . getMillis ( ) ) ; ( ( TimeSeries ) s1 ) . addOrUpdate ( new Second ( ts ) , f ) ; } else if ( hasXdim ) { ( ( XYSeries ) s1 ) . addOrUpdate ( varXarray . getDouble ( i ) , f ) ; } else { ( ( XYSeries ) s1 ) . addOrUpdate ( i , f ) ; } } } if ( dataset instanceof TimeSeriesCollection ) ( ( TimeSeriesCollection ) dataset ) . addSeries ( ( TimeSeries ) s1 ) ; if ( dataset instanceof XYSeriesCollection ) ( ( XYSeriesCollection ) dataset ) . addSeries ( ( XYSeries ) s1 ) ; } final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer ( true , false ) ; p . setRenderer ( ax , renderer1 ) ; log . info ( "dataset " + ax + " max " + max + " min " + min + " : " + dataset ) ; p . setDataset ( ax , dataset ) ; p . mapDatasetToRangeAxis ( ax , ax ) ; p . getRangeAxis ( ax ) . setLowerBound ( min ) ; p . getRangeAxis ( ax ) . setUpperBound ( max ) ; }


Input: / * [CODESPLIT] @ Override public void setBounds ( Rectangle r ) { // keep window on the screen Rectangle screenSize = ScreenUtils . getScreenVirtualSize ( ) ; Rectangle result = r . intersection ( screenSize ) ; if ( ! result . isEmpty ( ) ) super . setBounds ( result ) ; }


Input:
Create a gbx9 index from a single grib1 or grib2 file . Use the existing index if it already exists . [CODESPLIT] public static GribIndex readOrCreateIndexFromSingleFile ( boolean isGrib1 , MFile mfile , CollectionUpdateType force , org . slf4j . Logger logger ) throws IOException { GribIndex index = isGrib1 ? new Grib1Index ( ) : new Grib2Index ( ) ; if ( ! index . readIndex ( mfile . getPath ( ) , mfile . getLastModified ( ) , force ) ) { // heres where the index date is checked against the data file
 index . makeIndex ( mfile . getPath ( ) , null ) ; logger . debug ( "  Index written: {} == {} records" , mfile . getName ( ) + GBX9_IDX , index . getNRecords ( ) ) ; } else if ( debug ) { logger . debug ( "  Index read: {} == {} records" , mfile . getName ( ) + GBX9_IDX , index . getNRecords ( ) ) ; } return index ; }


Input: called from Aggregation Fmrc FeatureDatasetFactoryManager [CODESPLIT] static public MFileCollectionManager open ( String collectionName , String collectionSpec , String olderThan , Formatter errlog ) throws IOException { return new MFileCollectionManager ( collectionName , collectionSpec , olderThan , errlog ) ; }


Input:
Add a directory scan to the collection [CODESPLIT] public void addDirectoryScan ( String dirName , String suffix , String regexpPatternString , String subdirsS , String olderS , Object auxInfo ) { CompositeMFileFilter filters = new CompositeMFileFilter ( ) ; if ( null != regexpPatternString ) filters . addIncludeFilter ( new RegExpMatchOnName ( regexpPatternString ) ) ; else if ( suffix != null ) filters . addIncludeFilter ( new WildcardMatchOnPath ( "*" + suffix + "$" ) ) ; if ( olderS != null ) { try { TimeDuration tu = new TimeDuration ( olderS ) ; filters . addAndFilter ( new LastModifiedLimit ( ( long ) ( 1000 * tu . getValueInSeconds ( ) ) ) ) ; } catch ( Exception e ) { logger . error ( collectionName + ": Invalid time unit for olderThan = {}" , olderS ) ; } } boolean wantSubdirs = true ; if ( ( subdirsS != null ) && subdirsS . equalsIgnoreCase ( "false" ) ) wantSubdirs = false ; CollectionConfig mc = new CollectionConfig ( dirName , dirName , wantSubdirs , filters , auxInfo ) ; // create name
 StringBuilder sb = new StringBuilder ( dirName ) ; if ( wantSubdirs ) sb . append ( "**/" ) ; if ( null != regexpPatternString ) sb . append ( regexpPatternString ) ; else if ( suffix != null ) sb . append ( suffix ) ; else sb . append ( "noFilter" ) ; collectionName = sb . toString ( ) ; scanList . add ( mc ) ; }


Input:
Compute if synchronous scan is needed . True if recheck is true and enough time has elapsed . [CODESPLIT] @ Override public boolean isScanNeeded ( ) { // see if we need to recheck
 if ( recheck == null ) { logger . debug ( "{}: scan not needed, recheck null" , collectionName ) ; return false ; } if ( ! hasScans ( ) ) { logger . debug ( "{}: scan not needed, no scanners" , collectionName ) ; return false ; } synchronized ( this ) { if ( map == null && ! isStatic ( ) ) { logger . debug ( "{}: scan needed, never scanned" , collectionName ) ; return true ; } } Date now = new Date ( ) ; Date lastCheckedDate = new Date ( getLastScanned ( ) ) ; Date need = recheck . add ( lastCheckedDate ) ; if ( now . before ( need ) ) { logger . debug ( "{}: scan not needed, last scanned={}, now={}" , collectionName , lastCheckedDate , now ) ; return false ; } return true ; }


Input:
only called from synch methods [CODESPLIT] private boolean scanFirstTime ( ) throws IOException { Map < String , MFile > newMap = new HashMap <> ( ) ; if ( ! hasScans ( ) ) { map = newMap ; return false ; } reallyScan ( newMap ) ; // deleteOld(newMap); // ?? hmmmmm LOOK this seems wrong; maintainence in background ?? generally collection doesnt exist
 // implement olderThan
 if ( olderThanInMsecs > 0 ) { long olderThan = System . currentTimeMillis ( ) - olderThanInMsecs ; // new files must be older than this.
 Iterator < MFile > iter = newMap . values ( ) . iterator ( ) ; // need iterator so we can remove()
 while ( iter . hasNext ( ) ) { MFile newFile = iter . next ( ) ; String path = newFile . getPath ( ) ; if ( newFile . getLastModified ( ) > olderThan ) { // the file is too new
 iter . remove ( ) ; logger . debug ( "{}: scan found new Dataset but its too recently modified = {}" , collectionName , path ) ; } } } map = newMap ; this . lastScanned = System . currentTimeMillis ( ) ; this . lastChanged . set ( this . lastScanned ) ; logger . debug ( "{} : initial scan found n datasets = {} " , collectionName , map . keySet ( ) . size ( ) ) ; return map . keySet ( ) . size ( ) > 0 ; }


Input: Set debugging flags [CODESPLIT] public static void setDebugFlags ( ucar . nc2 . util . DebugFlags debugFlags ) { debug = debugFlags . isSet ( "ncfileWriter2/debug" ) ; debugWrite = debugFlags . isSet ( "ncfileWriter2/debugWrite" ) ; debugChunk = debugFlags . isSet ( "ncfileWriter2/debugChunk" ) ; }


Input: Specify which variable will get written [CODESPLIT] public Variable addVariable ( Variable oldVar ) { List < Dimension > newDims = getNewDimensions ( oldVar ) ; Variable newVar ; if ( ( oldVar . getDataType ( ) . equals ( DataType . STRING ) ) && ( ! version . isExtendedModel ( ) ) ) { newVar = writer . addStringVariable ( null , oldVar , newDims ) ; } else { newVar = writer . addVariable ( null , oldVar . getShortName ( ) , oldVar . getDataType ( ) , newDims ) ; } varMap . put ( oldVar , newVar ) ; varList . add ( oldVar ) ; for ( Attribute orgAtt : oldVar . getAttributes ( ) ) writer . addVariableAttribute ( newVar , convertAttribute ( orgAtt ) ) ; return newVar ; }


Input:
Write the input file to the output file . [CODESPLIT] public NetcdfFile write ( CancelTask cancel ) throws IOException { try { if ( version . isExtendedModel ( ) ) addGroupExtended ( null , fileIn . getRootGroup ( ) ) ; else addGroupClassic ( ) ; if ( cancel != null && cancel . isCancel ( ) ) return null ; // create the file
 writer . create ( ) ; if ( cancel != null && cancel . isCancel ( ) ) return null ; double total = copyVarData ( varList , null , cancel ) ; if ( cancel != null && cancel . isCancel ( ) ) return null ; writer . flush ( ) ; if ( debug ) System . out . println ( "FileWriter done total bytes = " + total ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; writer . abort ( ) ; // clean up
 throw ioe ; } return writer . getNetcdfFile ( ) ; }


Input: / * package [CODESPLIT] void add ( long recno , int fieldno , Array field ) { //Make sure all the space is allocated if ( records . length <= recno ) { FieldSet [ ] newrecs = new FieldSet [ ( int ) recno + 1 ] ; System . arraycopy ( records , 0 , newrecs , 0 , records . length ) ; records = newrecs ; } FieldSet fs = records [ ( int ) recno ] ; if ( fs == null ) { records [ ( int ) recno ] = ( fs = new FieldSet ( this . nmembers ) ) ; } fs . fields [ fieldno ] = field ; }


Input: /////////////////////// [CODESPLIT] protected CDMArrayAtomic getAtomicArray ( int index , StructureMembers . Member m ) { Array dd = memberArray ( index , CDMArrayStructure . memberIndex ( m ) ) ; if ( dd . getDataType ( ) != DataType . STRUCTURE && dd . getDataType ( ) != DataType . SEQUENCE ) return ( CDMArrayAtomic ) dd ; throw new ForbiddenConversionException ( "Cannot convert structure to AtomicArray" ) ; }


Input: Write the information as an XML document [CODESPLIT] public String writeXML ( ) { XMLOutputter fmt = new XMLOutputter ( Format . getPrettyFormat ( ) ) ; return fmt . outputString ( makeDocument ( ) ) ; }


Input: Create an XML document from this info [CODESPLIT] public Document makeDocument ( ) { Element rootElem = new Element ( "netcdfDatasetInfo" ) ; Document doc = new Document ( rootElem ) ; rootElem . setAttribute ( "location" , ds . getLocation ( ) ) ; rootElem . addContent ( new Element ( "convention" ) . setAttribute ( "name" , getConventionUsed ( ) ) ) ; int nDataVariables = 0 ; int nOtherVariables = 0 ; List < CoordinateAxis > axes = ds . getCoordinateAxes ( ) ; int nCoordAxes = axes . size ( ) ; for ( CoordinateAxis axis : axes ) { Element axisElem = new Element ( "axis" ) ; rootElem . addContent ( axisElem ) ; axisElem . setAttribute ( "name" , axis . getFullName ( ) ) ; axisElem . setAttribute ( "decl" , getDecl ( axis ) ) ; if ( axis . getAxisType ( ) != null ) axisElem . setAttribute ( "type" , axis . getAxisType ( ) . toString ( ) ) ; if ( axis . getUnitsString ( ) != null ) { axisElem . setAttribute ( CDM . UNITS , axis . getUnitsString ( ) ) ; axisElem . setAttribute ( "udunits" , isUdunits ( axis . getUnitsString ( ) ) ) ; } if ( axis instanceof CoordinateAxis1D ) { CoordinateAxis1D axis1D = ( CoordinateAxis1D ) axis ; if ( axis1D . isRegular ( ) ) axisElem . setAttribute ( "regular" , ucar . unidata . util . Format . d ( axis1D . getIncrement ( ) , 5 ) ) ; } } List < CoordinateSystem > csList = ds . getCoordinateSystems ( ) ; for ( CoordinateSystem cs : csList ) { Element csElem ; if ( GridCoordSys . isGridCoordSys ( null , cs , null ) ) { GridCoordSys gcs = new GridCoordSys ( cs , null ) ; csElem = new Element ( "gridCoordSystem" ) ; csElem . setAttribute ( "name" , cs . getName ( ) ) ; csElem . setAttribute ( "horizX" , gcs . getXHorizAxis ( ) . getFullName ( ) ) ; csElem . setAttribute ( "horizY" , gcs . getYHorizAxis ( ) . getFullName ( ) ) ; if ( gcs . hasVerticalAxis ( ) ) csElem . setAttribute ( "vertical" , gcs . getVerticalAxis ( ) . getFullName ( ) ) ; if ( gcs . hasTimeAxis ( ) ) csElem . setAttribute ( "time" , cs . getTaxis ( ) . getFullName ( ) ) ; } else { csElem = new Element ( "coordSystem" ) ; csElem . setAttribute ( "name" , cs . getName ( ) ) ; } List < CoordinateTransform > coordTransforms = cs . getCoordinateTransforms ( ) ; for ( CoordinateTransform ct : coordTransforms ) { Element ctElem = new Element ( "coordTransform" ) ; csElem . addContent ( ctElem ) ; ctElem . setAttribute ( "name" , ct . getName ( ) ) ; ctElem . setAttribute ( "type" , ct . getTransformType ( ) . toString ( ) ) ; } rootElem . addContent ( csElem ) ; } List < CoordinateTransform > coordTransforms = ds . getCoordinateTransforms ( ) ; for ( CoordinateTransform ct : coordTransforms ) { Element ctElem = new Element ( "coordTransform" ) ; rootElem . addContent ( ctElem ) ; ctElem . setAttribute ( "name" , ct . getName ( ) ) ; ctElem . setAttribute ( "type" , ct . getTransformType ( ) . toString ( ) ) ; List < Parameter > params = ct . getParameters ( ) ; for ( Parameter pp : params ) { Element ppElem = new Element ( "param" ) ; ctElem . addContent ( ppElem ) ; ppElem . setAttribute ( "name" , pp . getName ( ) ) ; ppElem . setAttribute ( "value" , pp . getStringValue ( ) ) ; } } for ( Variable var : ds . getVariables ( ) ) { VariableEnhanced ve = ( VariableEnhanced ) var ; if ( ve instanceof CoordinateAxis ) continue ; GridCoordSys gcs = getGridCoordSys ( ve ) ; if ( null != gcs ) { nDataVariables ++ ; Element gridElem = new Element ( "grid" ) ; rootElem . addContent ( gridElem ) ; gridElem . setAttribute ( "name" , ve . getFullName ( ) ) ; gridElem . setAttribute ( "decl" , getDecl ( ve ) ) ; if ( ve . getUnitsString ( ) != null ) { gridElem . setAttribute ( CDM . UNITS , ve . getUnitsString ( ) ) ; gridElem . setAttribute ( "udunits" , isUdunits ( ve . getUnitsString ( ) ) ) ; } gridElem . setAttribute ( "coordSys" , gcs . getName ( ) ) ; } } for ( Variable var : ds . getVariables ( ) ) { VariableEnhanced ve = ( VariableEnhanced ) var ; if ( ve instanceof CoordinateAxis ) continue ; GridCoordSys gcs = getGridCoordSys ( ve ) ; if ( null == gcs ) { nOtherVariables ++ ; Element elem = new Element ( "variable" ) ; rootElem . addContent ( elem ) ; elem . setAttribute ( "name" , ve . getFullName ( ) ) ; elem . setAttribute ( "decl" , getDecl ( ve ) ) ; if ( ve . getUnitsString ( ) != null ) { elem . setAttribute ( CDM . UNITS , ve . getUnitsString ( ) ) ; elem . setAttribute ( "udunits" , isUdunits ( ve . getUnitsString ( ) ) ) ; } elem . setAttribute ( "coordSys" , getCoordSys ( ve ) ) ; } } if ( nDataVariables > 0 ) { rootElem . addContent ( new Element ( "userAdvice" ) . addContent ( "Dataset contains useable gridded data." ) ) ; if ( nOtherVariables > 0 ) rootElem . addContent ( new Element ( "userAdvice" ) . addContent ( "Some variables are not gridded fields; check that is what you expect." ) ) ; } else { if ( nCoordAxes == 0 ) rootElem . addContent ( new Element ( "userAdvice" ) . addContent ( "No Coordinate Axes were found." ) ) ; else rootElem . addContent ( new Element ( "userAdvice" ) . addContent ( "No gridded data variables were found." ) ) ; } String userAdvice = getUserAdvice ( ) ; if ( userAdvice . length ( ) > 0 ) { StringTokenizer toker = new StringTokenizer ( userAdvice , "\n" ) ; while ( toker . hasMoreTokens ( ) ) rootElem . addContent ( new Element ( "userAdvice" ) . addContent ( toker . nextToken ( ) ) ) ; } return doc ; }


Input: debug [CODESPLIT] public static void main ( String args [ ] ) throws IOException { String url = "C:/data/badmodels/RUC_CONUS_80km_20051211_1900.nc" ; try ( NetcdfDatasetInfo info = new NetcdfDatasetInfo ( url ) ) { String infoString = info . writeXML ( ) ; System . out . println ( infoString ) ; } }


Input: ///////////////////////////////////////////// Marshalling /////////////////////////////////////////////// [CODESPLIT] public static void marshalPointDataset ( FeatureDatasetPoint fdPoint , OutputStream outputStream ) throws IOException , XmlException { marshalPointDataset ( fdPoint , fdPoint . getDataVariables ( ) , outputStream ) ; }


Input: Validates an xml doc . If the validation fails the exception contains a detailed list of errors . [CODESPLIT] public static void validate ( XmlObject doc , boolean strict ) throws XmlException { // Create an XmlOptions instance and set the error listener. Set < XmlError > validationErrors = new HashSet <> ( ) ; XmlOptions validationOptions = new XmlOptions ( ) ; validationOptions . setErrorListener ( validationErrors ) ; // Validate the XML document final boolean isValid = doc . validate ( validationOptions ) ; // Create Exception with error message if the xml document is invalid if ( ! isValid && ! strict ) { // check if we have special validation cases which could let the message pass anyhow validationErrors = filterToOnlySerious ( validationErrors ) ; } if ( ! validationErrors . isEmpty ( ) ) { throw new XmlException ( createErrorMessage ( validationErrors ) ) ; } }


Input: Convert this multislice to a string suitable for use in a constraint [CODESPLIT] @ Override public String toConstraintString ( ) throws DapException { assert this . first != UNDEFINED && this . stride != UNDEFINED && this . stop != UNDEFINED ; StringBuilder buf = new StringBuilder ( ) ; buf . append ( "[" ) ; boolean first = true ; for ( Slice sub : this . subslices ) { if ( ! first ) buf . append ( "," ) ; first = false ; if ( ( sub . stop - sub . first ) == 0 ) { buf . append ( "0" ) ; } else if ( sub . stride == 1 ) { if ( ( sub . stop - sub . first ) == 1 ) buf . append ( sub . first ) ; else buf . append ( String . format ( "%d:%d" , sub . first , sub . stop - 1 ) ) ; } else buf . append ( String . format ( "%d:%d:%d" , sub . first , sub . stride , sub . stop - 1 ) ) ; } buf . append ( "]" ) ; return buf . toString ( ) ; }


Input: copy () doesnt work because convert gets called twice [CODESPLIT] @ Override public Structure select ( List < String > memberNames ) { StructureDS result = new StructureDS ( getParentGroup ( ) , orgVar ) ; List < Variable > members = new ArrayList <> ( ) ; for ( String name : memberNames ) { Variable m = findVariable ( name ) ; if ( null != m ) members . add ( m ) ; } result . setMemberVariables ( members ) ; result . isSubset = true ; return result ; }


Input: Set the Structure to wrap . [CODESPLIT] public void setOriginalVariable ( ucar . nc2 . Variable orgVar ) { if ( ! ( orgVar instanceof Structure ) ) throw new IllegalArgumentException ( "StructureDS must wrap a Structure; name=" + orgVar . getFullName ( ) ) ; this . orgVar = ( Structure ) orgVar ; }


Input:
regular Variables . [CODESPLIT] @ Override public Array reallyRead ( Variable client , CancelTask cancelTask ) throws IOException { Array result ; if ( hasCachedData ( ) ) result = super . reallyRead ( client , cancelTask ) ; else if ( orgVar != null ) result = orgVar . read ( ) ; else { throw new IllegalStateException ( "StructureDS has no way to get data" ) ; //Object data = smProxy.getFillValue(getDataType());
 //return Array.factoryConstant(dataType.getPrimitiveClassType(), getShape(), data);
 } return convert ( result , null ) ; }


Input:
section of regular Variable [CODESPLIT] @ Override public Array reallyRead ( Variable client , Section section , CancelTask cancelTask ) throws IOException , InvalidRangeException { if ( section . computeSize ( ) == getSize ( ) ) return _read ( ) ; Array result ; if ( hasCachedData ( ) ) result = super . reallyRead ( client , section , cancelTask ) ; else if ( orgVar != null ) result = orgVar . read ( section ) ; else { throw new IllegalStateException ( "StructureDS has no way to get data" ) ; //Object data = smProxy.getFillValue(getDataType());
 //return Array.factoryConstant(dataType.getPrimitiveClassType(), section.getShape(), data);
 } // do any needed conversions (enum/scale/offset/missing/unsigned, etc)
 return convert ( result , section ) ; }


Input:
is conversion needed? [CODESPLIT] private boolean convertNeeded ( StructureMembers smData ) { for ( Variable v : getVariables ( ) ) { if ( v instanceof VariableDS ) { VariableDS vds = ( VariableDS ) v ; if ( vds . needConvert ( ) ) return true ; } else if ( v instanceof StructureDS ) { StructureDS nested = ( StructureDS ) v ; if ( nested . convertNeeded ( null ) ) return true ; } // a variable with no data in the underlying smData
 if ( ( smData != null ) && ! varHasData ( v , smData ) ) return true ; } return false ; }


Input:
3 ) variable with cached data added to StructureDS through NcML [CODESPLIT] protected ArrayStructure convert ( Array data , Section section ) throws IOException { ArrayStructure orgAS = ( ArrayStructure ) data ; if ( ! convertNeeded ( orgAS . getStructureMembers ( ) ) ) { // name, info change only
 convertMemberInfo ( orgAS . getStructureMembers ( ) ) ; return orgAS ; } // LOOK! converting to ArrayStructureMA
 // do any enum/scale/offset/missing/unsigned conversions
 ArrayStructure newAS = ArrayStructureMA . factoryMA ( orgAS ) ; for ( StructureMembers . Member m : newAS . getMembers ( ) ) { VariableEnhanced v2 = ( VariableEnhanced ) findVariable ( m . getName ( ) ) ; if ( ( v2 == null ) && ( orgVar != null ) ) // these are from orgVar - may have been renamed
 v2 = findVariableFromOrgName ( m . getName ( ) ) ; if ( v2 == null ) continue ; if ( v2 instanceof VariableDS ) { VariableDS vds = ( VariableDS ) v2 ; if ( vds . needConvert ( ) ) { Array mdata = newAS . extractMemberArray ( m ) ; // mdata has not yet been enhanced, but vds would *think* that it has been if we used the 1-arg version of
 // VariableDS.convert(). So, we use the 2-arg version to explicitly request enhancement.
 mdata = vds . convert ( mdata , vds . getEnhanceMode ( ) ) ; newAS . setMemberArray ( m , mdata ) ; } } else if ( v2 instanceof StructureDS ) { StructureDS innerStruct = ( StructureDS ) v2 ; if ( innerStruct . convertNeeded ( null ) ) { if ( innerStruct . getDataType ( ) == DataType . SEQUENCE ) { ArrayObject . D1 seqArray = ( ArrayObject . D1 ) newAS . extractMemberArray ( m ) ; ArrayObject . D1 newSeq = ( ArrayObject . D1 ) Array . factory ( DataType . SEQUENCE , new int [ ] { ( int ) seqArray . getSize ( ) } ) ; m . setDataArray ( newSeq ) ; // put back into member array
 // wrap each Sequence
 for ( int i = 0 ; i < seqArray . getSize ( ) ; i ++ ) { ArraySequence innerSeq = ( ArraySequence ) seqArray . get ( i ) ; // get old ArraySequence
 newSeq . set ( i , new SequenceConverter ( innerStruct , innerSeq ) ) ; // wrap in converter
 } // non-Sequence Structures
 } else { Array mdata = newAS . extractMemberArray ( m ) ; mdata = innerStruct . convert ( mdata , null ) ; newAS . setMemberArray ( m , mdata ) ; } } // always convert the inner StructureMembers
 innerStruct . convertMemberInfo ( m . getStructureMembers ( ) ) ; } } StructureMembers sm = newAS . getStructureMembers ( ) ; convertMemberInfo ( sm ) ; // check for variables that have been added by NcML
 for ( Variable v : getVariables ( ) ) { if ( ! varHasData ( v , sm ) ) { try { Variable completeVar = getParentGroup ( ) . findVariable ( v . getShortName ( ) ) ; // LOOK BAD
 Array mdata = completeVar . read ( section ) ; StructureMembers . Member m = sm . addMember ( v . getShortName ( ) , v . getDescription ( ) , v . getUnitsString ( ) , v . getDataType ( ) , v . getShape ( ) ) ; newAS . setMemberArray ( m , mdata ) ; } catch ( InvalidRangeException e ) { throw new IOException ( e . getMessage ( ) ) ; } } } return newAS ; }


Input:
/ * convert original structureData to one that conforms to this Structure [CODESPLIT] protected StructureData convert ( StructureData orgData , int recno ) throws IOException { if ( ! convertNeeded ( orgData . getStructureMembers ( ) ) ) { // name, info change only
 convertMemberInfo ( orgData . getStructureMembers ( ) ) ; return orgData ; } // otherwise we create a new StructureData and convert to it. expensive
 StructureMembers smResult = new StructureMembers ( orgData . getStructureMembers ( ) ) ; StructureDataW result = new StructureDataW ( smResult ) ; for ( StructureMembers . Member m : orgData . getMembers ( ) ) { VariableEnhanced v2 = ( VariableEnhanced ) findVariable ( m . getName ( ) ) ; if ( ( v2 == null ) && ( orgVar != null ) ) // why ?
 v2 = findVariableFromOrgName ( m . getName ( ) ) ; if ( v2 == null ) { findVariableFromOrgName ( m . getName ( ) ) ; // debug
 // log.warn("StructureDataDS.convert Cant find member " + m.getName());
 continue ; } StructureMembers . Member mResult = smResult . findMember ( m . getName ( ) ) ; if ( v2 instanceof VariableDS ) { VariableDS vds = ( VariableDS ) v2 ; Array mdata = orgData . getArray ( m ) ; if ( vds . needConvert ( ) ) // mdata has not yet been enhanced, but vds would *think* that it has been if we used the 1-arg version of
 // VariableDS.convert(). So, we use the 2-arg version to explicitly request enhancement.
 mdata = vds . convert ( mdata , vds . getEnhanceMode ( ) ) ; result . setMemberData ( mResult , mdata ) ; } // recurse into sub-structures
 if ( v2 instanceof StructureDS ) { StructureDS innerStruct = ( StructureDS ) v2 ; // if (innerStruct.convertNeeded(null)) {
 if ( innerStruct . getDataType ( ) == DataType . SEQUENCE ) { Array a = orgData . getArray ( m ) ; if ( a instanceof ArrayObject . D1 ) { // LOOK when does this happen vs ArraySequence?
 ArrayObject . D1 seqArray = ( ArrayObject . D1 ) a ; ArrayObject . D1 newSeq = ( ArrayObject . D1 ) Array . factory ( DataType . SEQUENCE , new int [ ] { ( int ) seqArray . getSize ( ) } ) ; mResult . setDataArray ( newSeq ) ; // put into result member array
 for ( int i = 0 ; i < seqArray . getSize ( ) ; i ++ ) { ArraySequence innerSeq = ( ArraySequence ) seqArray . get ( i ) ; // get old ArraySequence
 newSeq . set ( i , new SequenceConverter ( innerStruct , innerSeq ) ) ; // wrap in converter
 } } else { ArraySequence seqArray = ( ArraySequence ) a ; result . setMemberData ( mResult , new SequenceConverter ( innerStruct , seqArray ) ) ; // wrap in converter
 } // non-Sequence Structures
 } else { Array mdata = orgData . getArray ( m ) ; mdata = innerStruct . convert ( mdata , null ) ; result . setMemberData ( mResult , mdata ) ; } //}
 // always convert the inner StructureMembers
 innerStruct . convertMemberInfo ( mResult . getStructureMembers ( ) ) ; } } StructureMembers sm = result . getStructureMembers ( ) ; convertMemberInfo ( sm ) ; // check for variables that have been added by NcML
 for ( Variable v : getVariables ( ) ) { if ( ! varHasData ( v , sm ) ) { try { Variable completeVar = getParentGroup ( ) . findVariable ( v . getShortName ( ) ) ; // LOOK BAD
 Array mdata = completeVar . read ( new Section ( ) . appendRange ( recno , recno ) ) ; StructureMembers . Member m = sm . addMember ( v . getShortName ( ) , v . getDescription ( ) , v . getUnitsString ( ) , v . getDataType ( ) , v . getShape ( ) ) ; result . setMemberData ( m , mdata ) ; } catch ( InvalidRangeException e ) { throw new IOException ( e . getMessage ( ) ) ; } } } return result ; }


Input:
the wrapper StructureMembers must be converted to correspond to the wrapper Structure [CODESPLIT] private void convertMemberInfo ( StructureMembers wrapperSm ) { for ( StructureMembers . Member m : wrapperSm . getMembers ( ) ) { Variable v = findVariable ( m . getName ( ) ) ; if ( ( v == null ) && ( orgVar != null ) ) // may have been renamed
 v = ( Variable ) findVariableFromOrgName ( m . getName ( ) ) ; if ( v != null ) { // a section will have missing variables LOOK wrapperSm probably wrong in that case
 //  log.error("Cant find " + m.getName());
 //else
 m . setVariableInfo ( v . getShortName ( ) , v . getDescription ( ) , v . getUnitsString ( ) , v . getDataType ( ) ) ; } // nested structures
 if ( v instanceof StructureDS ) { StructureDS innerStruct = ( StructureDS ) v ; innerStruct . convertMemberInfo ( m . getStructureMembers ( ) ) ; } } }


Input: look for the top variable that has an orgVar with the wanted orgName [CODESPLIT] private VariableEnhanced findVariableFromOrgName ( String orgName ) { for ( Variable vTop : getVariables ( ) ) { Variable v = vTop ; while ( v instanceof VariableEnhanced ) { VariableEnhanced ve = ( VariableEnhanced ) v ; if ( ( ve . getOriginalName ( ) != null ) && ( ve . getOriginalName ( ) . equals ( orgName ) ) ) return ( VariableEnhanced ) vTop ; v = ve . getOriginalVariable ( ) ; } } return null ; }


Input: verify that the variable has data in the data array [CODESPLIT] private boolean varHasData ( Variable v , StructureMembers sm ) { if ( sm . findMember ( v . getShortName ( ) ) != null ) return true ; while ( v instanceof VariableEnhanced ) { VariableEnhanced ve = ( VariableEnhanced ) v ; if ( sm . findMember ( ve . getOriginalName ( ) ) != null ) return true ; v = ve . getOriginalVariable ( ) ; } return false ; }


Input: DO NOT USE DIRECTLY . public by accident . recalc any enhancement info [CODESPLIT] public void enhance ( Set < NetcdfDataset . Enhance > mode ) { for ( Variable v : getVariables ( ) ) { VariableEnhanced ve = ( VariableEnhanced ) v ; ve . enhance ( mode ) ; } }


Input: return null means request has been handled and calling routine should exit without further processing [CODESPLIT] public NetcdfFile openNetcdfFile ( HttpServletRequest req , HttpServletResponse res , String reqPath ) throws IOException { if ( log . isDebugEnabled ( ) ) log . debug ( "DatasetHandler wants " + reqPath ) ; if ( reqPath == null ) return null ; if ( reqPath . startsWith ( "/" ) ) reqPath = reqPath . substring ( 1 ) ; // see if its under resource control if ( ! resourceControlOk ( req , res , reqPath ) ) return null ; // HEY LOOK datascan below has its own Ncml // look for a dataset (non scan, non fmrc) that has an ncml element String ncml = datasetTracker . findNcml ( reqPath ) ; if ( ncml != null ) { NetcdfFile ncfile = NetcdfDataset . acquireFile ( new NcmlFileFactory ( ncml ) , null , DatasetUrl . findDatasetUrl ( reqPath ) , - 1 , null , null ) ; if ( ncfile == null ) throw new FileNotFoundException ( reqPath ) ; return ncfile ; } // look for a match DataRootManager . DataRootMatch match = dataRootManager . findDataRootMatch ( reqPath ) ; // look for an feature collection dataset if ( ( match != null ) && ( match . dataRoot . getFeatureCollection ( ) != null ) ) { FeatureCollectionRef featCollection = match . dataRoot . getFeatureCollection ( ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  -- DatasetHandler found FeatureCollection= " + featCollection ) ; InvDatasetFeatureCollection fc = featureCollectionCache . get ( featCollection ) ; NetcdfFile ncfile = fc . getNetcdfDataset ( match . remaining ) ; if ( ncfile == null ) throw new FileNotFoundException ( reqPath ) ; return ncfile ; } // might be a pluggable DatasetSource: NetcdfFile ncfile = null ; for ( DatasetSource datasetSource : datasetSources ) { // LOOK linear if ( datasetSource . isMine ( req ) ) { ncfile = datasetSource . getNetcdfFile ( req , res ) ; if ( ncfile != null ) return ncfile ; } } // common case - its a file if ( match != null ) { org . jdom2 . Element netcdfElem = null ; // find ncml if it exists if ( match . dataRoot != null ) { DatasetScan dscan = match . dataRoot . getDatasetScan ( ) ; // if (dscan == null) dscan = match.dataRoot.getDatasetRootProxy();  // no ncml possible in getDatasetRootProxy if ( dscan != null ) netcdfElem = dscan . getNcmlElement ( ) ; } String location = dataRootManager . getLocationFromRequestPath ( reqPath ) ; if ( location == null ) throw new FileNotFoundException ( reqPath ) ; // if theres an ncml element, open it directly through NcMLReader, therefore not being cached. // this is safer given all the trouble we have with ncml and caching. if ( netcdfElem != null ) { String ncmlLocation = "DatasetScan#" + location ; // LOOK some descriptive name NetcdfDataset ncd = NcMLReader . readNcML ( ncmlLocation , netcdfElem , "file:" + location , null ) ; //new NcMLReader().readNetcdf(reqPath, ncd, ncd, netcdfElem, null); //if (log.isDebugEnabled()) log.debug("  -- DatasetHandler found DataRoot NcML = " + ds); return ncd ; } DatasetUrl durl = DatasetUrl . findDatasetUrl ( location ) ; ncfile = NetcdfDataset . acquireFile ( durl , null ) ; } if ( ncfile == null ) throw new FileNotFoundException ( reqPath ) ; return ncfile ; }


Input: return null means request has been handled and calling routine should exit without further processing [CODESPLIT] public GridDataset openGridDataset ( HttpServletRequest req , HttpServletResponse res , String reqPath ) throws IOException { // first look for a feature collection DataRootManager . DataRootMatch match = dataRootManager . findDataRootMatch ( reqPath ) ; if ( ( match != null ) && ( match . dataRoot . getFeatureCollection ( ) != null ) ) { // see if its under resource control if ( ! resourceAuthorized ( req , res , match . dataRoot . getRestrict ( ) ) ) return null ; FeatureCollectionRef featCollection = match . dataRoot . getFeatureCollection ( ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  -- DatasetHandler found FeatureCollection= " + featCollection ) ; InvDatasetFeatureCollection fc = featureCollectionCache . get ( featCollection ) ; GridDataset gds = fc . getGridDataset ( match . remaining ) ; if ( gds == null ) throw new FileNotFoundException ( reqPath ) ; return gds ; } // fetch it as a NetcdfFile; this deals with possible NcML NetcdfFile ncfile = openNetcdfFile ( req , res , reqPath ) ; if ( ncfile == null ) return null ; NetcdfDataset ncd = null ; try { // Convert to NetcdfDataset ncd = NetcdfDataset . wrap ( ncfile , NetcdfDataset . getDefaultEnhanceMode ( ) ) ; return new ucar . nc2 . dt . grid . GridDataset ( ncd ) ; } catch ( Throwable t ) { if ( ncd == null ) ncfile . close ( ) ; else ncd . close ( ) ; if ( t instanceof IOException ) throw ( IOException ) t ; String msg = ncd == null ? "Problem wrapping NetcdfFile in NetcdfDataset" : "Problem creating GridDataset from NetcdfDataset" ; log . error ( "openGridDataset(): " + msg , t ) ; throw new IOException ( msg + t . getMessage ( ) ) ; } }


Input: return null means request has been handled and calling routine should exit without further processing [CODESPLIT] public CoverageCollection openCoverageDataset ( HttpServletRequest req , HttpServletResponse res , String reqPath ) throws IOException { if ( reqPath == null ) return null ; if ( reqPath . startsWith ( "/" ) ) reqPath = reqPath . substring ( 1 ) ; // see if its under resource control if ( ! resourceControlOk ( req , res , reqPath ) ) return null ; DataRootManager . DataRootMatch match = dataRootManager . findDataRootMatch ( reqPath ) ; // first look for a feature collection if ( ( match != null ) && ( match . dataRoot . getFeatureCollection ( ) != null ) ) { FeatureCollectionRef featCollection = match . dataRoot . getFeatureCollection ( ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  -- DatasetHandler found FeatureCollection= " + featCollection ) ; InvDatasetFeatureCollection fc = featureCollectionCache . get ( featCollection ) ; CoverageCollection gds = fc . getGridCoverage ( match . remaining ) ; if ( gds == null ) throw new FileNotFoundException ( reqPath ) ; return gds ; } // otherwise assume its a local file // try to open as a FeatureDatasetCoverage. This allows GRIB to be handle specially String location = getLocationFromRequestPath ( reqPath ) ; if ( location != null ) { Optional < FeatureDatasetCoverage > opt = CoverageDatasetFactory . openCoverageDataset ( location ) ; if ( ! opt . isPresent ( ) ) throw new FileNotFoundException ( "Not a Grid Dataset " + reqPath + " err=" + opt . getErrorMessage ( ) ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  -- DatasetHandler found FeatureCollection from file= " + location ) ; return opt . get ( ) . getSingleCoverageCollection ( ) ; // LOOK doesnt have to be single, then what is the URL? } // if ncml, must handle special, otherwise we're out of options for opening // a coverage collection. String ncml = datasetTracker . findNcml ( reqPath ) ; if ( ncml != null ) { Optional < FeatureDatasetCoverage > opt = CoverageDatasetFactory . openNcmlString ( ncml ) ; if ( ! opt . isPresent ( ) ) throw new FileNotFoundException ( "NcML is not a Grid Dataset " + reqPath + " err=" + opt . getErrorMessage ( ) ) ; if ( log . isDebugEnabled ( ) ) log . debug ( "  -- DatasetHandler found FeatureCollection from NcML" ) ; return opt . get ( ) . getSingleCoverageCollection ( ) ; } return null ; }


Input: Check if this is making a request for a restricted dataset and if so if its allowed . [CODESPLIT] public boolean resourceControlOk ( HttpServletRequest req , HttpServletResponse res , String reqPath ) { if ( null == reqPath ) reqPath = TdsPathUtils . extractPath ( req , null ) ; // see if its under resource control String rc = null ; DataRootManager . DataRootMatch match = dataRootManager . findDataRootMatch ( reqPath ) ; if ( match != null ) { rc = match . dataRoot . getRestrict ( ) ; // datasetScan, featCollection are restricted at the dataRoot } if ( rc == null ) { rc = datasetTracker . findResourceControl ( reqPath ) ; // regular datasets tracked here } return resourceAuthorized ( req , res , rc ) ; }


Input: DatasetSource [CODESPLIT] public void registerDatasetSource ( String className ) { Class vClass ; try { vClass = DatasetManager . class . getClassLoader ( ) . loadClass ( className ) ; } catch ( ClassNotFoundException e ) { log . error ( "Attempt to load DatasetSource class " + className + " not found" ) ; return ; } if ( ! ( DatasetSource . class . isAssignableFrom ( vClass ) ) ) { log . error ( "Attempt to load class " + className + " does not implement " + DatasetSource . class . getName ( ) ) ; return ; } // create instance of the class Object instance ; try { instance = vClass . newInstance ( ) ; } catch ( InstantiationException e ) { log . error ( "Attempt to load Viewer class " + className + " cannot instantiate, probably need default Constructor." ) ; return ; } catch ( IllegalAccessException e ) { log . error ( "Attempt to load Viewer class " + className + " is not accessible." ) ; return ; } registerDatasetSource ( ( DatasetSource ) instance ) ; }


Input: Prints the original string representation of this clause . For use in debugging . [CODESPLIT] public void printConstraint ( PrintWriter os ) { os . print ( function . getName ( ) + "(" ) ; Iterator it = children . iterator ( ) ; boolean first = true ; while ( it . hasNext ( ) ) { ValueClause vc = ( ValueClause ) it . next ( ) ; if ( ! first ) os . print ( "," ) ; vc . printConstraint ( os ) ; first = false ; } os . print ( ")" ) ; }