Input:
Write an Html representation of the given dataset .
 With datasetEvents catrefEvents = true this is used to construct an HTML page on the client ( eg using HtmlPage ) ; the client then detects URL clicks and processes .
 With datasetEvents catrefEvents = false this is used to construct an HTML page on the server . ( eg using HtmlPage ) ; the client then detects URL clicks and processes . [CODESPLIT] static public void writeHtmlDescription ( StringBuilder buff , InvDatasetImpl ds , boolean complete , boolean isServer , boolean datasetEvents , boolean catrefEvents , boolean resolveRelativeUrls ) { if ( ds == null ) return ; if ( complete ) { buff . append ( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" ) . append ( "        \"http://www.w3.org/TR/html4/loose.dtd\">\n" ) . append ( "\n" ) ; buff . append ( "" ) ; buff . append ( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" ) ; buff . append ( "" ) ; buff . append ( "\n" ) ; } buff . append ( "
Dataset: " ) . append ( ds . getFullName ( ) ) . append ( "
\n
\n" ) ; if ( ( ds . getDataFormatType ( ) != null ) && ( ds . getDataFormatType ( ) != DataFormatType . NONE ) ) buff . append ( "
Data format: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getDataFormatType ( ) . toString ( ) ) ) . append ( "
\n" ) ; if ( ( ds . getDataSize ( ) != 0.0 ) && ! Double . isNaN ( ds . getDataSize ( ) ) ) buff . append ( "
Data size: " ) . append ( Format . formatByteSize ( ds . getDataSize ( ) ) ) . append ( "
\n" ) ; if ( ( ds . getDataType ( ) != null ) && ( ds . getDataType ( ) != FeatureType . ANY ) ) buff . append ( "
Data type: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getDataType ( ) . toString ( ) ) ) . append ( "
\n" ) ; if ( ( ds . getCollectionType ( ) != null ) && ( ds . getCollectionType ( ) != CollectionType . NONE ) ) buff . append ( "
Collection type: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getCollectionType ( ) . toString ( ) ) ) . append ( "
\n" ) ; if ( ds . isHarvest ( ) ) buff . append ( "
Harvest: " ) . append ( ds . isHarvest ( ) ) . append ( "
\n" ) ; if ( ds . getAuthority ( ) != null ) buff . append ( "
Naming Authority: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getAuthority ( ) ) ) . append ( "
\n" ) ; if ( ds . getID ( ) != null ) buff . append ( "
ID: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getID ( ) ) ) . append ( "
\n" ) ; if ( ds . getRestrictAccess ( ) != null ) buff . append ( "
RestrictAccess: " ) . append ( StringUtil2 . quoteHtmlContent ( ds . getRestrictAccess ( ) ) ) . append ( "
\n" ) ; if ( ds instanceof InvCatalogRef ) { InvCatalogRef catref = ( InvCatalogRef ) ds ; String href = resolveRelativeUrls || catrefEvents ? resolve ( ds , catref . getXlinkHref ( ) ) : catref . getXlinkHref ( ) ; if ( catrefEvents ) href = "catref:" + href ; buff . append ( "
CatalogRef: " ) . append ( makeHref ( href , null ) ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; java . util . List < InvDocumentation > docs = ds . getDocumentation ( ) ; if ( docs . size ( ) > 0 ) { buff . append ( "
Documentation:
\n
\n" ) ; for ( InvDocumentation doc : docs ) { String type = ( doc . getType ( ) == null ) ? "" : "" + StringUtil2 . quoteHtmlContent ( doc . getType ( ) ) + ": " ; String inline = doc . getInlineContent ( ) ; if ( ( inline != null ) && ( inline . length ( ) > 0 ) ) buff . append ( "
" ) . append ( type ) . append ( StringUtil2 . quoteHtmlContent ( inline ) ) . append ( "
\n" ) ; if ( doc . hasXlink ( ) ) { // buff.append("
" + type + makeHrefResolve(ds, url.toString(), doc.getXlinkTitle()) + "\n"); buff . append ( "
" ) . append ( type ) . append ( makeHref ( doc . getXlinkHref ( ) , doc . getXlinkTitle ( ) ) ) . append ( "
\n" ) ; } } buff . append ( "
\n" ) ; } java . util . List < InvAccess > access = ds . getAccess ( ) ; if ( access . size ( ) > 0 ) { buff . append ( "
Access:
\n
\n" ) ; for ( InvAccess a : access ) { InvService s = a . getService ( ) ; String urlString = resolveRelativeUrls || datasetEvents ? a . getStandardUrlName ( ) : a . getUnresolvedUrlName ( ) ; String fullUrlString = urlString ; if ( datasetEvents ) fullUrlString = "dataset:" + fullUrlString ; if ( isServer ) { ServiceType stype = s . getServiceType ( ) ; if ( ( stype == ServiceType . OPENDAP ) || ( stype == ServiceType . DODS ) ) fullUrlString = fullUrlString + ".html" ; else if ( stype == ServiceType . DAP4 ) fullUrlString = fullUrlString + ".dmr.xml" ; else if ( stype == ServiceType . WCS ) fullUrlString = fullUrlString + "?service=WCS&version=1.0.0&request=GetCapabilities" ; else if ( stype == ServiceType . WMS ) fullUrlString = fullUrlString + "?service=WMS&version=1.3.0&request=GetCapabilities" ; //NGDC update 8/18/2011 else if ( stype == ServiceType . NCML || stype == ServiceType . UDDC || stype == ServiceType . ISO ) { String catalogUrl = ds . getCatalogUrl ( ) ; String datasetId = ds . id ; if ( catalogUrl . indexOf ( ' ' ) > 0 ) catalogUrl = catalogUrl . substring ( 0 , catalogUrl . lastIndexOf ( ' ' ) ) ; try { catalogUrl = URLEncoder . encode ( catalogUrl , "UTF-8" ) ; datasetId = URLEncoder . encode ( datasetId , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } fullUrlString = fullUrlString + "?catalog=" + catalogUrl + "&dataset=" + datasetId ; } else if ( stype == ServiceType . NetcdfSubset ) fullUrlString = fullUrlString + "/dataset.html" ; else if ( ( stype == ServiceType . CdmRemote ) || ( stype == ServiceType . CdmrFeature ) ) fullUrlString = fullUrlString + "?req=form" ; } buff . append ( "
 " ) . append ( StringUtil2 . quoteHtmlContent ( s . getServiceType ( ) . toString ( ) ) ) ; buff . append ( ": " ) . append ( makeHref ( fullUrlString , urlString ) ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < ThreddsMetadata . Contributor > contributors = ds . getContributors ( ) ; if ( contributors . size ( ) > 0 ) { buff . append ( "
Contributors:
\n
\n" ) ; for ( ThreddsMetadata . Contributor t : contributors ) { String role = ( t . getRole ( ) == null ) ? "" : " (" + StringUtil2 . quoteHtmlContent ( t . getRole ( ) ) + ") " ; buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( t . getName ( ) ) ) . append ( role ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < ThreddsMetadata . Vocab > keywords = ds . getKeywords ( ) ; if ( keywords . size ( ) > 0 ) { buff . append ( "
Keywords:
\n
\n" ) ; for ( ThreddsMetadata . Vocab t : keywords ) { String vocab = ( t . getVocabulary ( ) == null ) ? "" : " (" + StringUtil2 . quoteHtmlContent ( t . getVocabulary ( ) ) + ") " ; buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( t . getText ( ) ) ) . append ( vocab ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < DateType > dates = ds . getDates ( ) ; if ( dates . size ( ) > 0 ) { buff . append ( "
Dates:
\n
\n" ) ; for ( DateType d : dates ) { String type = ( d . getType ( ) == null ) ? "" : " (" + StringUtil2 . quoteHtmlContent ( d . getType ( ) ) + ") " ; buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( d . getText ( ) ) ) . append ( type ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < ThreddsMetadata . Vocab > projects = ds . getProjects ( ) ; if ( projects . size ( ) > 0 ) { buff . append ( "
Projects:
\n
\n" ) ; for ( ThreddsMetadata . Vocab t : projects ) { String vocab = ( t . getVocabulary ( ) == null ) ? "" : " (" + StringUtil2 . quoteHtmlContent ( t . getVocabulary ( ) ) + ") " ; buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( t . getText ( ) ) ) . append ( vocab ) . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < ThreddsMetadata . Source > creators = ds . getCreators ( ) ; if ( creators . size ( ) > 0 ) { buff . append ( "
Creators:
\n
\n" ) ; for ( ThreddsMetadata . Source t : creators ) { buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( t . getName ( ) ) ) . append ( "
\n" ) ; buff . append ( "
email: " ) . append ( StringUtil2 . quoteHtmlContent ( t . getEmail ( ) ) ) . append ( "
\n" ) ; if ( t . getUrl ( ) != null ) { String newUrl = resolveRelativeUrls ? makeHrefResolve ( ds , t . getUrl ( ) , null ) : makeHref ( t . getUrl ( ) , null ) ; buff . append ( "
 " ) . append ( newUrl ) . append ( "
\n" ) ; } buff . append ( "

\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < ThreddsMetadata . Source > publishers = ds . getPublishers ( ) ; if ( publishers . size ( ) > 0 ) { buff . append ( "
Publishers:
\n
\n" ) ; for ( ThreddsMetadata . Source t : publishers ) { buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( t . getName ( ) ) ) . append ( "
\n" ) ; buff . append ( "
email: " ) . append ( StringUtil2 . quoteHtmlContent ( t . getEmail ( ) ) ) . append ( "\n" ) ; if ( t . getUrl ( ) != null ) { String urlLink = resolveRelativeUrls ? makeHrefResolve ( ds , t . getUrl ( ) , null ) : makeHref ( t . getUrl ( ) , null ) ; buff . append ( "
 " ) . append ( urlLink ) . append ( "\n" ) ; } buff . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } /*
    4.2:

Variables:

Vocabulary [DIF]:

Reflectivity =   = EARTH SCIENCE > Spectral/Engineering > Radar > Radar Reflectivity (db)

Velocity =   = EARTH SCIENCE > Spectral/Engineering > Radar > Doppler Velocity (m/s)

SpectrumWidth =   = EARTH SCIENCE > Spectral/Engineering > Radar > Doppler Spectrum Width (m/s)

    4.3:

Variables:

Vocabulary [CF-1.0]:

d3d (meters)  =  3D Depth at Nodes

         = depth_at_nodes

depth (meters)  =  Bathymetry = depth

eta (m)  =   =

temp (Celsius)  =  Temperature

         = sea_water_temperature

u (m/s)  =  Eastward Water

          Velocity

         = eastward_sea_water_velocity

v (m/s)  =  Northward Water

          Velocity

         = northward_sea_water_velocity

     */ java . util . List < ThreddsMetadata . Variables > vars = ds . getVariables ( ) ; if ( vars . size ( ) > 0 ) { buff . append ( "
Variables:
\n
\n" ) ; for ( ThreddsMetadata . Variables t : vars ) { buff . append ( "
Vocabulary [" ) ; if ( t . getVocabUri ( ) != null ) { URI uri = t . getVocabUri ( ) ; String vocabLink = resolveRelativeUrls ? makeHrefResolve ( ds , uri . toString ( ) , t . getVocabulary ( ) ) : makeHref ( uri . toString ( ) , t . getVocabulary ( ) ) ; buff . append ( vocabLink ) ; } else { buff . append ( StringUtil2 . quoteHtmlContent ( t . getVocabulary ( ) ) ) ; } buff . append ( "]:\n
\n" ) ; java . util . List < ThreddsMetadata . Variable > vlist = t . getVariableList ( ) ; if ( vlist . size ( ) > 0 ) { for ( ThreddsMetadata . Variable v : vlist ) { String units = ( v . getUnits ( ) == null || v . getUnits ( ) . length ( ) == 0 ) ? "" : " (" + v . getUnits ( ) + ") " ; buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( v . getName ( ) + units ) ) . append ( " = " ) ; String desc = ( v . getDescription ( ) == null ) ? "" : " " + StringUtil2 . quoteHtmlContent ( v . getDescription ( ) ) + " = " ; buff . append ( desc ) ; if ( v . getVocabularyName ( ) != null ) buff . append ( StringUtil2 . quoteHtmlContent ( v . getVocabularyName ( ) ) ) ; buff . append ( "\n" ) ; } } buff . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } if ( ds . getVariableMapLink ( ) != null ) { buff . append ( "
Variables:
\n" ) ; buff . append ( "

" + makeHref ( ds . getVariableMapLink ( ) , "VariableMap" ) + "

\n" ) ; } ThreddsMetadata . GeospatialCoverage gc = ds . getGeospatialCoverage ( ) ; if ( ( gc != null ) && ! gc . isEmpty ( ) ) { buff . append ( "
GeospatialCoverage:
\n
\n" ) ; if ( gc . isGlobal ( ) ) buff . append ( "
 Global \n" ) ; buff . append ( "
 Longitude:  " ) . append ( rangeString ( gc . getEastWestRange ( ) ) ) . append ( "
\n" ) ; buff . append ( "
 Latitude:  " ) . append ( rangeString ( gc . getNorthSouthRange ( ) ) ) . append ( "
\n" ) ; if ( gc . getUpDownRange ( ) != null ) { buff . append ( "
 Altitude:  " ) . append ( rangeString ( gc . getUpDownRange ( ) ) ) . append ( " (positive is " ) . append ( StringUtil2 . quoteHtmlContent ( gc . getZPositive ( ) ) ) . append ( ")
\n" ) ; } java . util . List < ThreddsMetadata . Vocab > nlist = gc . getNames ( ) ; if ( ( nlist != null ) && ( nlist . size ( ) > 0 ) ) { buff . append ( "
  Names:
\n" ) ; for ( ThreddsMetadata . Vocab elem : nlist ) { buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( elem . getText ( ) ) ) . append ( "\n" ) ; } buff . append ( "
\n" ) ; } buff . append ( "
\n" ) ; } CalendarDateRange tc = ds . getCalendarDateCoverage ( ) ; if ( tc != null ) { buff . append ( "
TimeCoverage:
\n
\n" ) ; CalendarDate start = tc . getStart ( ) ; if ( start != null ) buff . append ( "
  Start:  " ) . append ( start . toString ( ) ) . append ( "\n" ) ; CalendarDate end = tc . getEnd ( ) ; if ( end != null ) { buff . append ( "
  End:  " ) . append ( end . toString ( ) ) . append ( "\n" ) ; } CalendarDuration duration = tc . getDuration ( ) ; if ( duration != null ) buff . append ( "
  Duration:  " ) . append ( StringUtil2 . quoteHtmlContent ( duration . toString ( ) ) ) . append ( "\n" ) ; CalendarDuration resolution = tc . getResolution ( ) ; if ( resolution != null ) { buff . append ( "
  Resolution:  " ) . append ( StringUtil2 . quoteHtmlContent ( resolution . toString ( ) ) ) . append ( "\n" ) ; } buff . append ( "
\n" ) ; } java . util . List < InvMetadata > metadata = ds . getMetadata ( ) ; boolean gotSomeMetadata = false ; for ( InvMetadata m : metadata ) { if ( m . hasXlink ( ) ) gotSomeMetadata = true ; } if ( gotSomeMetadata ) { buff . append ( "
Metadata:
\n
\n" ) ; for ( InvMetadata m : metadata ) { String type = ( m . getMetadataType ( ) == null ) ? "" : m . getMetadataType ( ) ; if ( m . hasXlink ( ) ) { String title = ( m . getXlinkTitle ( ) == null ) ? "Type " + type : m . getXlinkTitle ( ) ; String mdLink = resolveRelativeUrls ? makeHrefResolve ( ds , m . getXlinkHref ( ) , title ) : makeHref ( m . getXlinkHref ( ) , title ) ; buff . append ( "
 " ) . append ( mdLink ) . append ( "\n" ) ; } //else { //buff.append("

"+m.getMetadataType()+" "+m.getContentObject()+"
\n"); //} } buff . append ( "
\n" ) ; } java . util . List < InvProperty > propsOrg = ds . getProperties ( ) ; java . util . List < InvProperty > props = new ArrayList <> ( ds . getProperties ( ) . size ( ) ) ; for ( InvProperty p : propsOrg ) { if ( ! p . getName ( ) . startsWith ( "viewer" ) ) // eliminate the viewer properties from the html view props . add ( p ) ; } if ( props . size ( ) > 0 ) { buff . append ( "
Properties:
\n
\n" ) ; for ( InvProperty p : props ) { if ( p . getName ( ) . equals ( "attachments" ) ) // LOOK whats this ? { String attachLink = resolveRelativeUrls ? makeHrefResolve ( ds , p . getValue ( ) , p . getName ( ) ) : makeHref ( p . getValue ( ) , p . getName ( ) ) ; buff . append ( "
" ) . append ( attachLink ) . append ( "\n" ) ; } else { buff . append ( "
" ) . append ( StringUtil2 . quoteHtmlContent ( p . getName ( ) + " = \"" + p . getValue ( ) ) ) . append ( "\"\n" ) ; } } buff . append ( "
\n" ) ; } if ( complete ) buff . append ( "" ) ; }


Input: resolve reletive URLS against the catalog URL . [CODESPLIT] static public String resolve ( InvDataset ds , String href ) { InvCatalog cat = ds . getParentCatalog ( ) ; if ( cat != null ) { try { java . net . URI uri = cat . resolveUri ( href ) ; href = uri . toString ( ) ; } catch ( java . net . URISyntaxException e ) { logger . warn ( "InvDatasetImpl.writeHtml: error parsing URL= " + href ) ; } } return href ; }


Input: Validate this DatasetNamer object . Return true if valid false if invalid . [CODESPLIT] boolean validate ( StringBuilder out ) { this . isValid = true ; // If log from construction has content, append to validation output msg. if ( this . msgLog . length ( ) > 0 ) { out . append ( this . msgLog ) ; } // Check that name is not null (it can be an empty string). if ( this . getName ( ) == null ) { this . isValid = false ; out . append ( " ** DatasetNamer (1): null value for name is not valid." ) ; } // Check that addLevel is not null. // boolean can't be null //if ( this.getAddLevel() == null) //{ //  this.isValid = false; //  out.append(" ** DatasetNamer (2): null value for addLevel is not valid."); //} // Check that type is not null. if ( this . getType ( ) == null ) { this . isValid = false ; out . append ( " ** DatasetNamer (3): null value for type is not valid (set with bad string?)." ) ; } if ( this . getType ( ) == DatasetNamerType . REGULAR_EXPRESSION && ( this . getMatchPattern ( ) == null || this . getSubstitutePattern ( ) == null ) ) { this . isValid = false ; out . append ( " ** DatasetNamer (4): invalid datasetNamer <" + this . getName ( ) + ">;" + " type is " + this . getType ( ) . toString ( ) + ": matchPattern(" + this . getMatchPattern ( ) + ") and substitutionPattern(" + this . getSubstitutePattern ( ) + ") " + "must not be null." ) ; } if ( this . getType ( ) == DatasetNamerType . DODS_ATTRIBUTE && ( this . getAttribContainer ( ) == null || this . getAttribName ( ) == null ) ) { this . isValid = false ; out . append ( " ** DatasetNamer (5): invalid datasetNamer <" + this . getName ( ) + ">;" + " type is " + this . getType ( ) . toString ( ) + ": attriuteContainer(" + this . getAttribContainer ( ) + ") and attributeName(" + this . getAttribName ( ) + ") must not be null." ) ; } return ( this . isValid ) ; }


Input:
Try to name the given dataset . [CODESPLIT] public boolean nameDataset ( InvDatasetImpl dataset ) { if ( this . type == DatasetNamerType . REGULAR_EXPRESSION ) { return ( this . nameDatasetRegExp ( dataset ) ) ; } /* else if (this.type == DatasetNamerType.DODS_ATTRIBUTE) {
      return (this.nameDatasetDodsAttrib(dataset));
    } */ else { String tmpMsg = "This DatasetNamer <" + this . getName ( ) + "> has unsupported type <" + this . type . toString ( ) + ">." ; logger . error ( "nameDataset(): " + tmpMsg ) ; throw new IllegalStateException ( tmpMsg ) ; } }


Input: Try to name the given dataset . [CODESPLIT] public boolean nameDatasetList ( java . util . List datasetList ) throws java . lang . Exception { boolean returnValue = false ; InvDatasetImpl curDataset = null ; for ( int i = 0 ; i < datasetList . size ( ) ; i ++ ) { curDataset = ( InvDatasetImpl ) datasetList . get ( i ) ; returnValue &= this . nameDataset ( curDataset ) ; } return ( returnValue ) ; }


Input: get list of data descriptors as Strings [CODESPLIT] public final List < String > getDescriptors ( ) { List < String > desc = new ArrayList < String > ( ) ; for ( short fxy : descriptors ) desc . ( Descriptor . makeString ( fxy ) ) ; return desc ; }


Input:
initialize [CODESPLIT] private void init ( double a , double f , int zone , boolean hemisphere_north ) { A = a ; F = 1.0 / f ; // F is flattening
 this . zone = zone ; this . hemisphere_north = hemisphere_north ; //  Create the ERM constants.
 Eps2 = ( F ) * ( 2.0 - F ) ; Eps25 = .25 * ( Eps2 ) ; EF = F / ( 2.0 - F ) ; Con2 = 2 / ( 1.0 - Eps2 ) ; Con6 = .166666666666667 ; Con24 = 4 * .0416666666666667 / ( 1 - Eps2 ) ; Con120 = .00833333333333333 ; Con720 = 4 * .00138888888888888 / ( 1 - Eps2 ) ; double polx1a = 1.0 - Eps2 / 4.0 - 3.0 / 64.0 * Math . pow ( Eps2 , 2 ) - 5.0 / 256.0 * Math . pow ( Eps2 , 3 ) - 175.0 / 16384.0 * Math . pow ( Eps2 , 4 ) ; conap = A * polx1a ; double polx2a = 3.0 / 2.0 * EF - 27.0 / 32.0 * Math . pow ( EF , 3 ) ; double polx4a = 21.0 / 16.0 * Math . pow ( EF , 2 ) - 55.0 / 32.0 * Math . pow ( EF , 4 ) ; double polx6a = 151.0 / 96.0 * Math . pow ( EF , 3 ) ; double polx8a = 1097.0 / 512.0 * Math . pow ( EF , 4 ) ; polx2b = polx2a * 2.0 + polx4a * 4.0 + polx6a * 6.0 + polx8a * 8.0 ; polx3b = polx4a * - 8.0 - polx6a * 32.0 - 80.0 * polx8a ; polx4b = polx6a * 32.0 + 192.0 * polx8a ; polx5b = - 128.0 * polx8a ; }


Input:
/ * Difficult thing is to return the extra line assocated with the previous good log We do this by not returning until we get a match on the next log . We have to rewind . [CODESPLIT] public LogReader . Log nextLog ( BufferedReader dataIS ) throws IOException { ServletLog log = new ServletLog ( ) ; boolean haveLog = false ; while ( true ) { dataIS . mark ( 20 * 1000 ) ; // track where we are
 String line = dataIS . readLine ( ) ; if ( line == null ) { return haveLog ? log : null ; } // if (count++ < limit) System.out.println("\n" + line);                      nTest reqe
 try { Matcher m = commonPattern . matcher ( line ) ; if ( m . matches ( ) ) { if ( haveLog ) { // have a log, next one matches, proceed
 try { dataIS . reset ( ) ; return log ; } catch ( Throwable t ) { System . out . println ( "Cant reset " + line ) ; } } haveLog = true ; // next match will return the current log
 log . date = convertDate ( m . group ( 1 ) ) ; log . reqTime = parseLong ( m . group ( 2 ) ) ; log . reqSeq = parseLong ( m . group ( 3 ) ) ; log . level = m . group ( 4 ) . intern ( ) ; log . where = m . group ( 5 ) ; String rest = m . group ( 6 ) ; if ( rest . contains ( "Request Completed" ) ) { int pos = rest . indexOf ( "Request Completed" ) ; Matcher m2 = donePattern . matcher ( rest . substring ( pos ) ) ; if ( m2 . matches ( ) ) { log . returnCode = parse ( m2 . group ( 1 ) ) ; log . sizeBytes = parseLong ( m2 . group ( 2 ) ) ; log . msecs = parseLong ( m2 . group ( 3 ) ) ; log . isDone = true ; } else { System . out . println ( "Cant parse donePattern= " + rest ) ; System . out . println ( " line= " + line ) ; log . addExtra ( rest ) ; } } else if ( rest . contains ( "Remote host" ) ) { int pos = rest . indexOf ( "Remote host" ) ; Matcher m2 = startPattern . matcher ( rest . substring ( pos ) ) ; if ( m2 . matches ( ) ) { log . ip = m2 . group ( 1 ) ; log . verb = m2 . group ( 2 ) . intern ( ) ; log . path = EscapeStrings . urlDecode ( m2 . group ( 3 ) ) ; //old  URLDecoder.decode(m2.group(3));
 if ( m2 . groupCount ( ) > 4 ) log . http = m2 . group ( 4 ) . intern ( ) ; log . isStart = true ; } else { System . out . println ( "Cant parse startPattern= " + rest ) ; System . out . println ( " line= " + line ) ; log . addExtra ( rest ) ; } } else { // a non-start, non-done log
 log . addExtra ( rest ) ; } } else { // the true extra line
 //System.out.println("No match on " + line);
 log . addExtra ( line ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; System . out . println ( "Cant parse " + line ) ; log . addExtra ( line ) ; } } }


Input: Constructs the full server URI from a request [CODESPLIT] public static String constructServerPath ( HttpServletRequest hsreq ) { return hsreq . getScheme ( ) + "://" + hsreq . getServerName ( ) + ":" + hsreq . getServerPort ( ) + "/thredds/wfs/" ; }


Input: Processes GetCapabilities requests . [CODESPLIT] private void getCapabilities ( PrintWriter out , HttpServletRequest hsreq , SimpleGeometryCSBuilder sgcs ) { WFSGetCapabilitiesWriter gcdw = new WFSGetCapabilitiesWriter ( out , WFSController . constructServerPath ( hsreq ) ) ; gcdw . startXML ( ) ; gcdw . addOperation ( WFSRequestType . GetCapabilities ) ; gcdw . addOperation ( WFSRequestType . DescribeFeatureType ) ; gcdw . addOperation ( WFSRequestType . GetFeature ) ; gcdw . writeOperations ( ) ; List < String > seriesNames = sgcs . getGeometrySeriesNames ( ) ; for ( String name : seriesNames ) { gcdw . addFeature ( new WFSFeature ( TDSNAMESPACE + ":" + name , name ) ) ; } gcdw . writeFeatureTypes ( ) ; gcdw . finishXML ( ) ; }


Input:
Processes GetFeature requests . [CODESPLIT] private WFSExceptionWriter getFeature ( PrintWriter out , HttpServletRequest hsreq , SimpleGeometryCSBuilder sgcs , String ftName , String fullFtName ) { List < SimpleGeometry > geometryList = new ArrayList < SimpleGeometry > ( ) ; GeometryType geoT = sgcs . getGeometryType ( ftName ) ; if ( geoT == null ) { return new WFSExceptionWriter ( "Feature Type of " + fullFtName + " not found." , "GetFeature" , "OperationProcessingFailed" ) ; } try { switch ( geoT ) { case POINT : Point pt = sgcs . getPoint ( ftName , 0 ) ; int j = 0 ; while ( pt != null ) { geometryList . add ( pt ) ; j ++ ; pt = sgcs . getPoint ( ftName , j ) ; } break ; case LINE : Line line = sgcs . getLine ( ftName , 0 ) ; int k = 0 ; while ( line != null ) { geometryList . add ( line ) ; k ++ ; line = sgcs . getLine ( ftName , k ) ; } break ; case POLYGON : Polygon poly = sgcs . getPolygon ( ftName , 0 ) ; int i = 0 ; while ( poly != null ) { geometryList . add ( poly ) ; i ++ ; poly = sgcs . getPolygon ( ftName , i ) ; } break ; } } // Perhaps will change this to be implemented in the CFPolygon class
 catch ( ArrayIndexOutOfBoundsException aout ) { } WFSGetFeatureWriter gfdw = new WFSGetFeatureWriter ( out , WFSController . constructServerPath ( hsreq ) , WFSController . getXMLNamespaceXMLNSValue ( hsreq ) , geometryList , ftName ) ; gfdw . startXML ( ) ; gfdw . writeMembers ( ) ; gfdw . finishXML ( ) ; return null ; }


Input:
Checks request parameters for errors . Will send back an XML Exception if any errors are encountered . [CODESPLIT] private WFSExceptionWriter checkParametersForError ( String request , String version , String service , String typeName ) { // The SERVICE parameter is required. If not specified, is an error (throw exception through XML).
 if ( service != null ) { // For the WFS servlet it must be WFS if not, write out an InvalidParameterValue exception.
 if ( ! service . equalsIgnoreCase ( "WFS" ) ) { return new WFSExceptionWriter ( "WFS Server error. SERVICE parameter must be of value WFS." , "service" , "InvalidParameterValue" ) ; } } else { return new WFSExceptionWriter ( "WFS server error. SERVICE parameter is required." , "request" , "MissingParameterValue" ) ; } // The REQUEST Parameter is required. If not specified, is an error (throw exception through XML).
 if ( request != null ) { // Only go through version checks if NOT a Get Capabilities request, the VERSION parameter is required for all operations EXCEPT GetCapabilities section 7.6.25 of WFS 2.0 Interface Standard
 if ( ! request . equalsIgnoreCase ( WFSRequestType . GetCapabilities . toString ( ) ) ) { if ( version != null ) { // If the version is not failed report exception VersionNegotiationFailed, from OGC Web Services Common Standard section 7.4.1
 // Get each part
 String [ ] versionParts = version . split ( "\\." ) ; for ( int ind = 0 ; ind < versionParts . length ; ind ++ ) { // Check if number will throw NumberFormatException if not.
 try { Integer . valueOf ( versionParts [ ind ] ) ; } /* Version parameters are only allowed to consist of numbers and periods. If this is not the case then
						 * It qualifies for InvalidParameterException
						 */ catch ( NumberFormatException excep ) { return new WFSExceptionWriter ( "WFS server error. VERSION parameter consists of invalid characters." , "version" , "InvalidParameterValue" ) ; } } /* Now the version parts are all constructed from the parameter
					 * Analyze for correctness.
					 */ boolean validVersion = false ; // If just number 2 is specified, assume 2.0.0, pass the check
 if ( versionParts . length == 1 ) if ( versionParts [ 0 ] . equals ( "2" ) ) validVersion = true ; // Two or more version parts specified, make sure it's 2.0.#.#...
 if ( versionParts . length >= 2 ) if ( versionParts [ 0 ] . equals ( "2" ) && versionParts [ 1 ] . equals ( "0" ) ) validVersion = true ; /* Another exception VersionNegotiationFailed is specified by OGC Web Services Common
					 * for version mismatches. If the version check failed print this exception
					 */ if ( ! validVersion ) { return new WFSExceptionWriter ( "WFS Server error. Version requested is not supported." , null , "VersionNegotiationFailed" ) ; } } else { return new WFSExceptionWriter ( "WFS server error. VERSION parameter is required." , "request" , "MissingParameterValue" ) ; } // Last check to see if typenames is specified, must be for GetFeature, DescribeFeatureType
 if ( typeName == null ) { return new WFSExceptionWriter ( "WFS server error. For the specifed request, parameter typename or typenames must be specified." , request , "MissingParameterValue" ) ; } } WFSRequestType reqToProc = WFSRequestType . getWFSRequestType ( request ) ; if ( reqToProc == null ) return new WFSExceptionWriter ( "WFS server error. REQUEST parameter is not valid. Possible values: GetCapabilities, " + "DescribeFeatureType, GetFeature" , "request" , "InvalidParameterValue" ) ; } else { return new WFSExceptionWriter ( "WFS server error. REQUEST parameter is required." , "request" , "MissingParameterValue" ) ; } return null ; }


Input:
A handler for WFS based HTTP requests that sends to other request handlers to handle the request . [CODESPLIT] @ RequestMapping ( "**" ) public void httpHandler ( HttpServletRequest hsreq , HttpServletResponse hsres ) { try { PrintWriter wr = hsres . getWriter ( ) ; List < String > paramNames = new LinkedList < String > ( ) ; Enumeration < String > paramNamesE = hsreq . getParameterNames ( ) ; while ( paramNamesE . hasMoreElements ( ) ) paramNames . add ( paramNamesE . nextElement ( ) ) ; // Prepare parameters
 String request = null ; String version = null ; String service = null ; String typeNames = null ; String datasetReqPath = null ; String actualPath = null ; String actualFTName = null ; NetcdfDataset dataset = null ; if ( hsreq . getServletPath ( ) . length ( ) > 4 ) { datasetReqPath = hsreq . getServletPath ( ) . substring ( 4 , hsreq . getServletPath ( ) . length ( ) ) ; } actualPath = TdsRequestedDataset . getLocationFromRequestPath ( datasetReqPath ) ; if ( actualPath != null ) dataset = NetcdfDataset . openDataset ( actualPath ) ; else return ; List < CoordinateSystem > csList = dataset . getCoordinateSystems ( ) ; SimpleGeometryCSBuilder cs = new SimpleGeometryCSBuilder ( dataset , csList . get ( 0 ) , null ) ; /* Look for parameter names to assign values
			 * in order to avoid casing issues with parameter names (such as a mismatch between reQUEST and request and REQUEST).
			 */ for ( String paramName : paramNames ) { if ( paramName . equalsIgnoreCase ( "REQUEST" ) ) { request = hsreq . getParameter ( paramName ) ; } if ( paramName . equalsIgnoreCase ( "VERSION" ) ) { version = hsreq . getParameter ( paramName ) ; } if ( paramName . equalsIgnoreCase ( "SERVICE" ) ) { service = hsreq . getParameter ( paramName ) ; } if ( paramName . equalsIgnoreCase ( "TYPENAMES" ) || paramName . equalsIgnoreCase ( "TYPENAME" ) ) { typeNames = hsreq . getParameter ( paramName ) ; // Remove namespace header for getFeature
 if ( typeNames != null ) if ( typeNames . length ( ) > TDSNAMESPACE . length ( ) ) { actualFTName = typeNames . substring ( TDSNAMESPACE . length ( ) + 1 , typeNames . length ( ) ) ; } } } WFSExceptionWriter paramError = checkParametersForError ( request , version , service , typeNames ) ; WFSExceptionWriter requestProcessingError = null ; // If parameter checks all pass launch the request
 if ( paramError == null ) { WFSRequestType reqToProc = WFSRequestType . getWFSRequestType ( request ) ; switch ( reqToProc ) { case GetCapabilities : getCapabilities ( wr , hsreq , cs ) ; break ; case DescribeFeatureType : describeFeatureType ( wr , hsreq , actualFTName ) ; break ; case GetFeature : requestProcessingError = getFeature ( wr , hsreq , cs , actualFTName , typeNames ) ; break ; } } // Parameter checks did not all pass, print the error and return
 else { paramError . write ( hsres ) ; return ; } /* Specifically writes out exceptions that were incurred
			 * while processing requests.
			 */ if ( requestProcessingError != null ) { requestProcessingError . write ( hsres ) ; return ; } } catch ( IOException io ) { throw new RuntimeException ( "The writer may not have been able to been have retrieved" + " or the requested dataset was not found" , io ) ; } }


Input: A path is a DAP4 path if at least one of the following is true . 1 . it has dap4 : as its leading protocol 2 . it has #protocol = dap4 in its fragment [CODESPLIT] public boolean dspMatch ( String url , DapContext context ) { try { XURI xuri = new XURI ( url ) ; if ( true ) { boolean found = false ; for ( String scheme : DAP4SCHEMES ) { if ( scheme . equalsIgnoreCase ( xuri . getBaseProtocol ( ) ) || scheme . equalsIgnoreCase ( xuri . getFormatProtocol ( ) ) ) { found = true ; break ; } } if ( ! found ) return false ; // Might still be a non-dap4 url String formatproto = xuri . getFormatProtocol ( ) ; if ( DAP4PROTO . equalsIgnoreCase ( formatproto ) ) return true ; for ( String [ ] pair : DAP4QUERYMARKERS ) { String tag = xuri . getQueryFields ( ) . get ( pair [ 0 ] ) ; if ( tag != null && ( pair [ 1 ] == null || pair [ 1 ] . equalsIgnoreCase ( tag ) ) ) return true ; } for ( String [ ] pair : DAP4FRAGMARKERS ) { String tag = xuri . getFragFields ( ) . get ( pair [ 0 ] ) ; if ( tag != null && ( pair [ 1 ] == null || pair [ 1 ] . equalsIgnoreCase ( tag ) ) ) return true ; } } else return true ; } catch ( URISyntaxException use ) { return false ; } return false ; }


Input: Open a connection and make a request for the ( possibly constrained ) DMR . [CODESPLIT] protected void build ( ) throws DapException { String methodurl = buildURL ( this . xuri . assemble ( XURI . URLONLY ) , DATASUFFIX , this . dmr , this . basece ) ; InputStream stream ; // Make the request and return an input stream for accessing the databuffer // Should fill in bigendian and stream fields stream = callServer ( methodurl ) ; try { ChunkInputStream reader ; if ( DEBUG ) { byte [ ] raw = DapUtil . readbinaryfile ( stream ) ; ByteArrayInputStream bis = new ByteArrayInputStream ( raw ) ; DapDump . dumpbytestream ( raw , getOrder ( ) , "httpdsp.build" ) ; reader = new ChunkInputStream ( bis , RequestMode . DAP , getOrder ( ) ) ; } else { // Wrap the input stream as a ChunkInputStream reader = new ChunkInputStream ( stream , RequestMode . DAP , getOrder ( ) ) ; } // Extract and "compile" the server response String document = reader . readDMR ( ) ; // Extract all the remaining bytes byte [ ] bytes = DapUtil . readbinaryfile ( reader ) ; // use super.build to compile super . build ( document , bytes , getOrder ( ) ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; throw new DapException ( t ) ; } finally { try { stream . close ( ) ; } catch ( IOException ioe ) { /*ignore*/ } } }


Input: Provide a method for getting the capabilities document . [CODESPLIT] public String getCapabilities ( String url ) throws IOException { // Save the original url String saveurl = this . xuri . getOriginal ( ) ; parseURL ( url ) ; String fdsurl = buildURL ( this . xuri . assemble ( XURI . URLALL ) , DSRSUFFIX , null , null ) ; try { // Make the request and return an input stream for accessing the databuffer // Should fill in context bigendian and stream fields InputStream stream = callServer ( fdsurl ) ; // read the result, convert to string and return. byte [ ] bytes = DapUtil . readbinaryfile ( stream ) ; String document = new String ( bytes , DapUtil . UTF8 ) ; return document ; } finally { parseURL ( saveurl ) ; } }


Input: Utilities [CODESPLIT] static protected String buildURL ( String baseurl , String suffix , DapDataset template , String ce ) { StringBuilder methodurl = new StringBuilder ( ) ; methodurl . append ( baseurl ) ; if ( suffix != null ) { methodurl . append ( ' ' ) ; methodurl . append ( suffix ) ; } if ( ce != null && ce . length ( ) > 0 ) { methodurl . append ( QUERYSTART ) ; methodurl . append ( CONSTRAINTTAG ) ; methodurl . append ( ' ' ) ; methodurl . append ( ce ) ; } return methodurl . toString ( ) ; }


Input: ////////////////////////////////////// CrawlableDatasetFile //////////////////////////////////////// [CODESPLIT] @ Override public File getFile ( ) { try { return threddsS3Client . saveObjectToFile ( s3uri , s3uri . getTempFile ( ) ) ; } catch ( IOException e ) { logger . error ( String . format ( "Could not save S3 object '%s' to file." , s3uri ) , e ) ; return null ; } }


Input:
Returns the size of the dataset in bytes . Will be zero if this dataset is a collection or non - existent . [CODESPLIT] @ Override public long length ( ) { // If the summary is already in the cache, return it. // It'll have been added by a listDatasets() call on the parent directory. S3ObjectSummary objectSummary = objectSummaryCache . getIfPresent ( s3uri ) ; if ( objectSummary != null ) { return objectSummary . getSize ( ) ; } /* Get the metadata directly from S3. This will be expensive.
         * We get punished hard if length() and/or lastModified() is called on a bunch of datasets without
         * listDatasets() first being called on their parent directory.
         *
         * So, is the right thing to do here "getParentDataset().listDatasets()" and then query the cache again?
         * Perhaps, but listDatasets() throws an IOException, and length() and lastModified() do not.
         * We would have to change their signatures and the upstream client code to make it work.
         */ ObjectMetadata metadata = threddsS3Client . getObjectMetadata ( s3uri ) ; if ( metadata != null ) { return metadata . getContentLength ( ) ; } else { // "this" may be a collection or non-existent. In both cases, we return 0. return 0 ; } }


Input: Returns the date that the dataset was last modified . Will be null if the dataset is a collection or non - existent . [CODESPLIT] @ Override public Date lastModified ( ) { S3ObjectSummary objectSummary = objectSummaryCache . getIfPresent ( s3uri ) ; if ( objectSummary != null ) { return objectSummary . getLastModified ( ) ; } ObjectMetadata metadata = threddsS3Client . getObjectMetadata ( s3uri ) ; if ( metadata != null ) { return metadata . getLastModified ( ) ; } else { // "this" may be a collection or non-existent. In both cases, we return null. return null ; } }


Input: Exception handlers [CODESPLIT] @ ExceptionHandler ( NcssException . class ) public ResponseEntity < String > handle ( NcssException e ) { HttpHeaders responseHeaders = new HttpHeaders ( ) ; responseHeaders . setContentType ( MediaType . TEXT_PLAIN ) ; return new ResponseEntity <> ( e . getMessage ( ) , responseHeaders , HttpStatus . BAD_REQUEST ) ; }


Input: unit testing [CODESPLIT] public static String getDatasetPath ( String path ) { if ( path . startsWith ( StandardService . netcdfSubsetGrid . getBase ( ) ) ) { // strip off /ncss/grid/ path = path . substring ( StandardService . netcdfSubsetGrid . getBase ( ) . length ( ) ) ; } else if ( path . startsWith ( StandardService . netcdfSubsetPoint . getBase ( ) ) ) { // strip off /ncss/point/ path = path . substring ( StandardService . netcdfSubsetPoint . getBase ( ) . length ( ) ) ; } // strip off endings for ( String ending : endings ) { if ( path . endsWith ( ending ) ) { int len = path . length ( ) - ending . length ( ) ; path = path . substring ( 0 , len ) ; break ; } } return path ; }


Input: Generator [CODESPLIT] public void generate ( CEConstraint ce , ChunkWriter cw , boolean withdmr , ChecksumMode mode ) throws DapException { begin ( ce , cw , withdmr , mode ) ; if ( this . withdmr ) generateDMR ( this . dmr ) ; dataset ( this . dmr ) ; end ( ) ; }


Input: Node specific generators [CODESPLIT] public void dataset ( DapDataset dmr ) throws DapException { // Iterate over the variables in order for ( DapVariable var : this . dmr . getTopVariables ( ) ) { if ( ! this . ce . references ( var ) ) continue ; variable ( var ) ; } }


Input:
Given a dataset variable and index automatically populates this Point and returns it . If not found returns null . [CODESPLIT] public Point setupPoint ( NetcdfDataset set , Variable vari , int index ) { // Points are much simpler, node_count is used multigeometries so it's a bit different
 // No need for the index finder here, unless there is a multipoint
 Array xPts = null ; Array yPts = null ; Integer ind = ( int ) index ; Variable nodeCounts = null ; boolean multi = false ; SimpleGeometryIndexFinder indexFinder = null ; List < CoordinateAxis > axes = set . getCoordinateAxes ( ) ; CoordinateAxis x = null ; CoordinateAxis y = null ; String [ ] nodeCoords = vari . findAttributeIgnoreCase ( CF . NODE_COORDINATES ) . getStringValue ( ) . split ( " " ) ; // Look for x and y
 for ( CoordinateAxis ax : axes ) { if ( ax . getFullName ( ) . equals ( nodeCoords [ 0 ] ) ) x = ax ; if ( ax . getFullName ( ) . equals ( nodeCoords [ 1 ] ) ) y = ax ; } // Node count is used very differently in points
 // Similar use to part_node_count in other geometries
 String node_c_str = vari . findAttValueIgnoreCase ( CF . NODE_COUNT , "" ) ; if ( ! node_c_str . equals ( "" ) ) { nodeCounts = set . findVariable ( node_c_str ) ; indexFinder = new SimpleGeometryIndexFinder ( nodeCounts ) ; multi = true ; } try { //
 if ( multi ) { xPts = x . read ( indexFinder . getBeginning ( index ) + ":" + indexFinder . getEnd ( index ) ) . reduce ( ) ; yPts = y . read ( indexFinder . getBeginning ( index ) + ":" + indexFinder . getEnd ( index ) ) . reduce ( ) ; } else { xPts = x . read ( ind . toString ( ) ) . reduce ( ) ; yPts = y . read ( ind . toString ( ) ) . reduce ( ) ; this . x = xPts . getDouble ( 0 ) ; this . y = yPts . getDouble ( 0 ) ; } // Set points
 if ( ! multi ) { this . x = xPts . getDouble ( 0 ) ; this . y = yPts . getDouble ( 0 ) ; // Set data of each
 switch ( vari . getRank ( ) ) { case 2 : this . setData ( vari . read ( CFSimpleGeometryHelper . getSubsetString ( vari , index ) ) . reduce ( ) ) ; break ; case 1 : this . setData ( vari . read ( "" + index ) ) ; break ; default : throw new InvalidDataseriesException ( InvalidDataseriesException . RANK_MISMATCH ) ; // currently do not support anything but dataseries and scalar associations
 } } else { IndexIterator itrX = xPts . getIndexIterator ( ) ; IndexIterator itrY = yPts . getIndexIterator ( ) ; this . next = null ; this . prev = null ; Point point = this ; // x and y should have the same shape (size), will add some handling on this
 while ( itrX . hasNext ( ) ) { point . setX ( itrX . getDoubleNext ( ) ) ; point . setY ( itrY . getDoubleNext ( ) ) ; // Set data of each
 switch ( vari . getRank ( ) ) { case 2 : point . setData ( vari . read ( CFSimpleGeometryHelper . getSubsetString ( vari , index ) ) . reduce ( ) ) ; break ; case 1 : point . setData ( vari . read ( "" + index ) ) ; break ; default : throw new InvalidDataseriesException ( InvalidDataseriesException . RANK_MISMATCH ) ; // currently do not support anything but dataseries and scalar associations
 } point . setNext ( new CFPoint ( ) ) ; // -1 is a default value, it gets assigned eventually
 point = point . getNext ( ) ; } // Clean up the last point since it will be invalid
 point = point . getPrev ( ) ; point . setNext ( null ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } catch ( InvalidRangeException e ) { e . printStackTrace ( ) ; return null ; } catch ( InvalidDataseriesException e ) { e . printStackTrace ( ) ; return null ; } return this ; }


Input: Return the file path dealing with leading and trailing path seperators ( which must be a slash ( / )) for the given directory and file paths . <p / > Note : Dealing with path strings is fragile . ToDo : Switch from using path strings to java . io . Files . [CODESPLIT] public static String formFilename ( String dirPath , String filePath ) { if ( ( dirPath == null ) || ( filePath == null ) ) return null ; if ( filePath . startsWith ( "/" ) ) filePath = filePath . substring ( 1 ) ; return dirPath . endsWith ( "/" ) ? dirPath + filePath : dirPath + "/" + filePath ; }


Input:
Write a file to the response stream . [CODESPLIT] public static void returnFile ( HttpServlet servlet , String contentPath , String path , HttpServletRequest req , HttpServletResponse res , String contentType ) throws IOException { String filename = ServletUtil . formFilename ( contentPath , path ) ; log . debug ( "returnFile(): returning file <" + filename + ">." ) ; // No file, nothing to view
 if ( filename == null ) { res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } // dontallow ..
 if ( filename . contains ( ".." ) ) { res . sendError ( HttpServletResponse . SC_FORBIDDEN ) ; return ; } // dont allow access to WEB-INF or META-INF
 String upper = filename . toUpperCase ( ) ; if ( upper . contains ( "WEB-INF" ) || upper . contains ( "META-INF" ) ) { res . sendError ( HttpServletResponse . SC_FORBIDDEN ) ; return ; } returnFile ( servlet , req , res , new File ( filename ) , contentType ) ; }


Input:
Write a file to the response stream . Handles Range requests . [CODESPLIT] public static void returnFile ( HttpServlet servlet , HttpServletRequest req , HttpServletResponse res , File file , String contentType ) throws IOException { // No file, nothing to view
 if ( file == null ) { res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } // check that it exists
 if ( ! file . exists ( ) ) { res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } // not a directory
 if ( ! file . isFile ( ) ) { res . sendError ( HttpServletResponse . SC_BAD_REQUEST ) ; return ; } // Set the type of the file
 String filename = file . getPath ( ) ; if ( null == contentType ) { if ( filename . endsWith ( ".html" ) ) contentType = ContentType . html . getContentHeader ( ) ; else if ( filename . endsWith ( ".xml" ) ) contentType = ContentType . xml . getContentHeader ( ) ; else if ( filename . endsWith ( ".txt" ) || ( filename . endsWith ( ".log" ) ) ) contentType = ContentType . text . getContentHeader ( ) ; else if ( filename . indexOf ( ".log." ) > 0 ) contentType = ContentType . text . getContentHeader ( ) ; else if ( filename . endsWith ( ".nc" ) ) contentType = ContentType . netcdf . getContentHeader ( ) ; else if ( filename . endsWith ( ".nc4" ) ) contentType = ContentType . netcdf . getContentHeader ( ) ; else if ( servlet != null ) contentType = servlet . getServletContext ( ) . getMimeType ( filename ) ; if ( contentType == null ) contentType = ContentType . binary . getContentHeader ( ) ; } returnFile ( req , res , file , contentType ) ; }


Input:
Write a file to the response stream . Handles Range requests . [CODESPLIT] public static void returnFile ( HttpServletRequest req , HttpServletResponse res , File file , String contentType ) throws IOException { res . setContentType ( contentType ) ; res . addDateHeader ( "Last-Modified" , file . lastModified ( ) ) ; // res.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
 // see if its a Range Request
 boolean isRangeRequest = false ; long startPos = 0 , endPos = Long . MAX_VALUE ; String rangeRequest = req . getHeader ( "Range" ) ; if ( rangeRequest != null ) { // bytes=12-34 or bytes=12-
 int pos = rangeRequest . indexOf ( "=" ) ; if ( pos > 0 ) { int pos2 = rangeRequest . indexOf ( "-" ) ; if ( pos2 > 0 ) { String startString = rangeRequest . substring ( pos + 1 , pos2 ) ; String endString = rangeRequest . substring ( pos2 + 1 ) ; startPos = Long . parseLong ( startString ) ; if ( endString . length ( ) > 0 ) endPos = Long . parseLong ( endString ) + 1 ; isRangeRequest = true ; } } } // set content length
 long fileSize = file . length ( ) ; long contentLength = fileSize ; if ( isRangeRequest ) { endPos = Math . min ( endPos , fileSize ) ; contentLength = endPos - startPos ; } // when compression is turned on, ContentLength has to be overridden
 // this is also true for HEAD, since this must be the same as GET without the body
 if ( contentLength > Integer . MAX_VALUE ) res . addHeader ( "Content-Length" , Long . toString ( contentLength ) ) ; // allow content length > MAX_INT
 else res . setContentLength ( ( int ) contentLength ) ; String filename = file . getPath ( ) ; // indicate we allow Range Requests
 res . addHeader ( "Accept-Ranges" , "bytes" ) ; if ( req . getMethod ( ) . equals ( "HEAD" ) ) { return ; } try { if ( isRangeRequest ) { // set before content is sent
 res . addHeader ( "Content-Range" , "bytes " + startPos + "-" + ( endPos - 1 ) + "/" + fileSize ) ; res . setStatus ( HttpServletResponse . SC_PARTIAL_CONTENT ) ; try ( RandomAccessFile craf = RandomAccessFile . acquire ( filename ) ) { IO . copyRafB ( craf , startPos , contentLength , res . getOutputStream ( ) , new byte [ 60000 ] ) ; return ; } } // Return the file
 ServletOutputStream out = res . getOutputStream ( ) ; IO . copyFileB ( file , out , 60 * 1000 ) ; /* try (WritableByteChannel cOut = Channels.newChannel(out)) {
        IO.copyFileWithChannels(file, cOut);
        res.flushBuffer();
      } */ } // @todo Split up this exception handling: those from file access vs those from dealing with response
 //       File access: catch and res.sendError()
 //       response: don't catch (let bubble up out of doGet() etc)
 catch ( FileNotFoundException e ) { log . error ( "returnFile(): FileNotFoundException= " + filename ) ; if ( ! res . isCommitted ( ) ) res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; } catch ( java . net . SocketException e ) { log . info ( "returnFile(): SocketException sending file: " + filename + " " + e . getMessage ( ) ) ; } catch ( IOException e ) { String eName = e . getClass ( ) . getName ( ) ; // dont want compile time dependency on ClientAbortException
 if ( eName . equals ( "org.apache.catalina.connector.ClientAbortException" ) ) { log . debug ( "returnFile(): ClientAbortException while sending file: " + filename + " " + e . getMessage ( ) ) ; return ; } if ( e . getMessage ( ) . startsWith ( "File transfer not complete" ) ) { // coming from FileTransfer.transferTo()
 log . debug ( "returnFile() " + e . getMessage ( ) ) ; return ; } log . error ( "returnFile(): IOException (" + e . getClass ( ) . getName ( ) + ") sending file " , e ) ; if ( ! res . isCommitted ( ) ) res . sendError ( HttpServletResponse . SC_NOT_FOUND , "Problem sending file: " + e . getMessage ( ) ) ; } }


Input: Send given content string as the HTTP response . [CODESPLIT] public static void returnString ( String contents , HttpServletResponse res ) throws IOException { try { ServletOutputStream out = res . getOutputStream ( ) ; IO . copy ( new ByteArrayInputStream ( contents . getBytes ( CDM . utf8Charset ) ) , out ) ; } catch ( IOException e ) { log . error ( " IOException sending string: " , e ) ; res . sendError ( HttpServletResponse . SC_NOT_FOUND , "Problem sending string: " + e . getMessage ( ) ) ; } }


Input: Set the proper content length for the string [CODESPLIT] public static int setResponseContentLength ( HttpServletResponse response , String s ) throws UnsupportedEncodingException { int length = s . getBytes ( response . getCharacterEncoding ( ) ) . length ; response . setContentLength ( length ) ; return length ; }


Input: Return the request URL relative to the server ( i . e . starting with the context path ) . [CODESPLIT] public static String getReletiveURL ( HttpServletRequest req ) { return req . getContextPath ( ) + req . getServletPath ( ) + req . getPathInfo ( ) ; }


Input:
Forward this request to the CatalogServices servlet ( / catalog . html ) . [CODESPLIT] public static void forwardToCatalogServices ( HttpServletRequest req , HttpServletResponse res ) throws IOException , ServletException { String reqs = "catalog=" + getReletiveURL ( req ) ; String query = req . getQueryString ( ) ; if ( query != null ) reqs = reqs + "&" + query ; log . info ( "forwardToCatalogServices(): request string = \"/catalog.html?" + reqs + "\"" ) ; // dispatch to CatalogHtml servlet
 RequestForwardUtils . forwardRequestRelativeToCurrentContext ( "/catalog.html?" + reqs , req , res ) ; }


Input: This is the server part eg http : // motherlode : 8080 [CODESPLIT] public static String getRequestServer ( HttpServletRequest req ) { return req . getScheme ( ) + "://" + req . getServerName ( ) + ":" + req . getServerPort ( ) ; }


Input: The request base as a URI [CODESPLIT] public static URI getRequestURI ( HttpServletRequest req ) { try { return new URI ( getRequestBase ( req ) ) ; } catch ( URISyntaxException e ) { e . printStackTrace ( ) ; return null ; } }


Input: servletPath + pathInfo [CODESPLIT] public static String getRequestPath ( HttpServletRequest req ) { StringBuilder buff = new StringBuilder ( ) ; if ( req . getServletPath ( ) != null ) buff . append ( req . getServletPath ( ) ) ; if ( req . getPathInfo ( ) != null ) buff . append ( req . getPathInfo ( ) ) ; return buff . toString ( ) ; }


Input: The entire request including query string [CODESPLIT] public static String getRequest ( HttpServletRequest req ) { String query = req . getQueryString ( ) ; return getRequestBase ( req ) + ( query == null ? "" : "?" + query ) ; }


Input: Return the value of the given parameter for the given request . Should only be used if the parameter is known to only have one value . If used on a multi - valued parameter the first value is returned . [CODESPLIT] public static String getParameterIgnoreCase ( HttpServletRequest req , String paramName ) { Enumeration e = req . getParameterNames ( ) ; while ( e . hasMoreElements ( ) ) { String s = ( String ) e . nextElement ( ) ; if ( s . equalsIgnoreCase ( paramName ) ) return req . getParameter ( s ) ; } return null ; }


Input:
Show details about the request [CODESPLIT] static public String showRequestDetail ( HttpServletRequest req ) { StringBuilder sbuff = new StringBuilder ( ) ; sbuff . append ( "Request Info\n" ) ; sbuff . append ( " req.getServerName(): " ) . append ( req . getServerName ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getServerPort(): " ) . append ( req . getServerPort ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getContextPath:" ) . append ( req . getContextPath ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getServletPath:" ) . append ( req . getServletPath ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getPathInfo:" ) . append ( req . getPathInfo ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getQueryString:" ) . append ( req . getQueryString ( ) ) . append ( "\n" ) ; sbuff . append ( " getQueryStringDecoded:" ) . append ( EscapeStrings . urlDecode ( req . getQueryString ( ) ) ) . append ( "\n" ) ; /*try {
      sbuff.append(" getQueryStringDecoded:").append(URLDecoder.decode(req.getQueryString(), "UTF-8")).append("\n");
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }*/ sbuff . append ( " req.getRequestURI:" ) . append ( req . getRequestURI ( ) ) . append ( "\n" ) ; sbuff . append ( " getRequestBase:" ) . append ( getRequestBase ( req ) ) . append ( "\n" ) ; sbuff . append ( " getRequestServer:" ) . append ( getRequestServer ( req ) ) . append ( "\n" ) ; sbuff . append ( " getRequest:" ) . append ( getRequest ( req ) ) . append ( "\n" ) ; sbuff . append ( "\n" ) ; sbuff . append ( " req.getPathTranslated:" ) . append ( req . getPathTranslated ( ) ) . append ( "\n" ) ; sbuff . append ( "\n" ) ; sbuff . append ( " req.getScheme:" ) . append ( req . getScheme ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getProtocol:" ) . append ( req . getProtocol ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getMethod:" ) . append ( req . getMethod ( ) ) . append ( "\n" ) ; sbuff . append ( "\n" ) ; sbuff . append ( " req.getContentType:" ) . append ( req . getContentType ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getContentLength:" ) . append ( req . getContentLength ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getRemoteAddr():" ) . append ( req . getRemoteAddr ( ) ) ; try { sbuff . append ( " getRemoteHost():" ) . append ( java . net . InetAddress . getByName ( req . getRemoteHost ( ) ) . getHostName ( ) ) . append ( "\n" ) ; } catch ( java . net . UnknownHostException e ) { sbuff . append ( " getRemoteHost():" ) . append ( e . getMessage ( ) ) . append ( "\n" ) ; } sbuff . append ( " getRemoteUser():" ) . append ( req . getRemoteUser ( ) ) . append ( "\n" ) ; sbuff . append ( "\n" ) ; sbuff . append ( "Request Parameters:\n" ) ; Enumeration params = req . getParameterNames ( ) ; while ( params . hasMoreElements ( ) ) { String name = ( String ) params . nextElement ( ) ; String values [ ] = req . getParameterValues ( name ) ; if ( values != null ) { for ( int i = 0 ; i < values . length ; i ++ ) { sbuff . append ( "  " ) . append ( name ) . append ( "  (" ) . append ( i ) . append ( "): " ) . append ( values [ i ] ) . append ( "\n" ) ; } } } sbuff . append ( "\n" ) ; sbuff . append ( "Request Headers:\n" ) ; Enumeration names = req . getHeaderNames ( ) ; while ( names . hasMoreElements ( ) ) { String name = ( String ) names . nextElement ( ) ; Enumeration values = req . getHeaders ( name ) ; // support multiple values
 if ( values != null ) { while ( values . hasMoreElements ( ) ) { String value = ( String ) values . nextElement ( ) ; sbuff . append ( "  " ) . append ( name ) . append ( ": " ) . append ( value ) . append ( "\n" ) ; } } } sbuff . append ( " ------------------\n" ) ; return sbuff . toString ( ) ; }


Input: / * static public void showSession ( HttpServletRequest req PrintStream out ) { [CODESPLIT] static public String showSecurity ( HttpServletRequest req , String role ) { StringBuilder sbuff = new StringBuilder ( ) ; sbuff . append ( "Security Info\n" ) ; sbuff . append ( " req.getRemoteUser(): " ) . append ( req . getRemoteUser ( ) ) . append ( "\n" ) ; sbuff . append ( " req.getUserPrincipal(): " ) . append ( req . getUserPrincipal ( ) ) . append ( "\n" ) ; sbuff . append ( " req.isUserInRole(" ) . append ( role ) . append ( "):" ) . append ( req . isUserInRole ( role ) ) . append ( "\n" ) ; sbuff . append ( " ------------------\n" ) ; return sbuff . toString ( ) ; }


Input: / * static private String getServerInfoName ( String serverInfo ) { int slash = serverInfo . indexOf ( / ) ; if ( slash == - 1 ) return serverInfo ; else return serverInfo . substring ( 0 slash ) ; } [CODESPLIT] static public void showThreads ( PrintStream pw ) { Thread current = Thread . currentThread ( ) ; ThreadGroup group = current . getThreadGroup ( ) ; while ( true ) { if ( group . getParent ( ) == null ) break ; group = group . getParent ( ) ; } showThreads ( pw , group , current ) ; }


Input: /////////////////////////////////////////////////////////////////////// [CODESPLIT] protected AxisType getAxisType ( NetcdfDataset ds , VariableEnhanced ve ) { Variable v = ( Variable ) ve ; String vname = v . getShortName ( ) ; String units = v . getUnitsString ( ) ; if ( units . equalsIgnoreCase ( CDM . LON_UNITS ) ) return AxisType . Lon ; if ( units . equalsIgnoreCase ( CDM . LAT_UNITS ) ) return AxisType . Lat ; if ( vname . equalsIgnoreCase ( "x" ) ) return AxisType . GeoX ; if ( vname . equalsIgnoreCase ( "lon" ) ) return AxisType . Lon ; if ( vname . equalsIgnoreCase ( "y" ) ) return AxisType . GeoY ; if ( vname . equalsIgnoreCase ( "lat" ) ) return AxisType . Lat ; if ( vname . equalsIgnoreCase ( "record" ) ) return AxisType . Time ; Dimension dim = v . getDimension ( 0 ) ; if ( ( dim != null ) && dim . getShortName ( ) . equalsIgnoreCase ( "record" ) ) return AxisType . Time ; String unit = ve . getUnitsString ( ) ; if ( unit != null ) { if ( SimpleUnit . isCompatible ( "millibar" , unit ) ) return AxisType . Pressure ; if ( SimpleUnit . isCompatible ( "m" , unit ) ) return AxisType . Height ; } return AxisType . GeoZ ; }


Input: Save persistent state . [CODESPLIT] public void save ( ) { if ( catListBox != null ) catListBox . save ( ) ; if ( prefs != null ) { if ( fileChooser != null ) fileChooser . save ( ) ; if ( catgenFileChooser != null ) catgenFileChooser . save ( ) ; prefs . putInt ( HDIVIDER , split . getDividerLocation ( ) ) ; } }


Input: Wrap this in a JDialog component . [CODESPLIT] public JDialog makeDialog ( RootPaneContainer parent , String title , boolean modal ) { this . parent = parent ; return new Dialog ( parent , title , modal ) ; }


Input: Write a file directory . [CODESPLIT] public int writeDirectory ( HttpServletResponse res , File dir , String path ) throws IOException { // error checking if ( dir == null ) { res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; return 0 ; } if ( ! dir . exists ( ) || ! dir . isDirectory ( ) ) { res . sendError ( HttpServletResponse . SC_NOT_FOUND ) ; return 0 ; } // Get directory as HTML String dirHtmlString = getDirectory ( path , dir ) ; thredds . servlet . ServletUtil . setResponseContentLength ( res , dirHtmlString ) ; res . setContentType ( ContentType . html . getContentHeader ( ) ) ; PrintWriter writer = res . getWriter ( ) ; writer . write ( dirHtmlString ) ; writer . flush ( ) ; return dirHtmlString . length ( ) ; }


Input: / * create new ArrayFloat with given indexImpl and backing store . Should be private . [CODESPLIT] static ArrayFloat factory ( Index index , float [ ] storage ) { if ( index instanceof Index0D ) { return new ArrayFloat . D0 ( index , storage ) ; } else if ( index instanceof Index1D ) { return new ArrayFloat . D1 ( index , storage ) ; } else if ( index instanceof Index2D ) { return new ArrayFloat . D2 ( index , storage ) ; } else if ( index instanceof Index3D ) { return new ArrayFloat . D3 ( index , storage ) ; } else if ( index instanceof Index4D ) { return new ArrayFloat . D4 ( index , storage ) ; } else if ( index instanceof Index5D ) { return new ArrayFloat . D5 ( index , storage ) ; } else if ( index instanceof Index6D ) { return new ArrayFloat . D6 ( index , storage ) ; } else if ( index instanceof Index7D ) { return new ArrayFloat . D7 ( index , storage ) ; } else { return new ArrayFloat ( index , storage ) ; } }


Input: copy from javaArray to storage using the iterator : used by factory ( Object ) ; [CODESPLIT] protected void copyFrom1DJavaArray ( IndexIterator iter , Object javaArray ) { float [ ] ja = ( float [ ] ) javaArray ; for ( float aJa : ja ) iter . setFloatNext ( aJa ) ; }


Input: wml2 : MeasurementTVP / wml2 : time [CODESPLIT] public static TimePositionType initTime ( TimePositionType time , PointFeature pointFeat ) { // TEXT time . setStringValue ( pointFeat . getNominalTimeAsCalendarDate ( ) . toString ( ) ) ; return time ; }


Input: wml2 : Collection / wml2 : observationMember / om : OM_Observation / om : phenomenonTime / gml : TimePeriod / gml : beginPosition [CODESPLIT] public static TimePositionType initBeginPosition ( TimePositionType beginPosition , CalendarDate date ) throws IOException { // TEXT beginPosition . setStringValue ( date . toString ( ) ) ; return beginPosition ; }


Input: wml2 : Collection / wml2 : observationMember / om : OM_Observation / om : phenomenonTime / gml : TimePeriod / gml : endPosition [CODESPLIT] public static TimePositionType initEndPosition ( TimePositionType endPosition , CalendarDate date ) throws IOException { // TEXT endPosition . setStringValue ( date . toString ( ) ) ; return endPosition ; }


Input: wml2 : Collection / wml2 : observationMember / om : OM_Observation / om : resultTime / gml : TimeInstant / gml : timePosition [CODESPLIT] public static TimePositionType initTimePosition ( TimePositionType timePosition ) { DateTime resultTime = MarshallingUtil . fixedResultTime ; if ( resultTime == null ) { resultTime = new DateTime ( ) ; // Initialized to "now". } // TEXT timePosition . setStringValue ( resultTime . toString ( ) ) ; return timePosition ; }


Input: /////////////////////////////////////////////// [CODESPLIT] public Object isMine ( FeatureType wantFeatureType , NetcdfDataset ncd , Formatter errlog ) throws IOException { String format = ncd . findAttValueIgnoreCase ( null , "format" , null ) ; if ( format != null ) { if ( format . startsWith ( "nssl/netcdf" ) ) return this ; } Dimension az = ncd . findDimension ( "Azimuth" ) ; Dimension gt = ncd . findDimension ( "Gate" ) ; if ( ( null != az ) && ( null != gt ) ) { return this ; } return null ; }


Input: not used yet [CODESPLIT] public void setBitOffset ( DataDescriptor dkey ) { if ( bitPosition == null ) bitPosition = new HashMap < DataDescriptor , Integer > ( 2 * parent . getSubKeys ( ) . size ( ) ) ; bitPosition . put ( dkey , bitOffset ) ; bitOffset += dkey . getBitWidth ( ) ; }


Input:
Track nested Tables . [CODESPLIT] public BitCounterUncompressed makeNested ( DataDescriptor subKey , int n , int row , int replicationCountSize ) { if ( subCounters == null ) subCounters = new HashMap < DataDescriptor , BitCounterUncompressed [ ] > ( 5 ) ; // assumes DataDescriptor.equals is ==
 BitCounterUncompressed [ ] subCounter = subCounters . get ( subKey ) ; if ( subCounter == null ) { subCounter = new BitCounterUncompressed [ nrows ] ; // one for each row in this table
 subCounters . put ( subKey , subCounter ) ; } BitCounterUncompressed rc = new BitCounterUncompressed ( subKey , n , replicationCountSize ) ; subCounter [ row ] = rc ; return rc ; }


Input:
total bits of this table and all subtables [CODESPLIT] int countBits ( int startBit ) { countBits = replicationCountSize ; this . startBit = new int [ nrows ] ; for ( int i = 0 ; i < nrows ; i ++ ) { this . startBit [ i ] = startBit + countBits ; if ( debug ) System . out . println ( " BitCounterUncompressed row " + i + " startBit=" + this . startBit [ i ] ) ; for ( DataDescriptor nd : parent . subKeys ) { BitCounterUncompressed [ ] bitCounter = ( subCounters == null ) ? null : subCounters . get ( nd ) ; if ( bitCounter == null ) // a regular field
 countBits += nd . getBitWidth ( ) ; else { if ( debug ) System . out . println ( " ---------> nested " + nd . getFxyName ( ) + " starts at =" + ( startBit + countBits ) ) ; countBits += bitCounter [ i ] . countBits ( startBit + countBits ) ; if ( debug ) System . out . println ( " <--------- nested " + nd . getFxyName ( ) + " ends at =" + ( startBit + countBits ) ) ; } } } return countBits ; }


Input: / * ! GRIB2 parameter table ! !D# = Discipline number !CT# = Category number ( Octet 10 Code Table 4 . 2 ) !ID# = Parameter number ( Octet 11 ) !PD# = Product Definition Template number ( Octet 8 - 9 Code Table 4 . 0 ) ! ! temperature !D# CT# ID# PD# NAME UNITS GNAM SCALE MISSING HZREMAP DIRECTION !23|123|123|123|12345678901234567890123456789012|12345678901234567890|123456789012|12345|123456 . 89|12345678|1234567890 1 2 3 4 5 6 7 8 9 10 11 12 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 000 000 000 000 Temperature K TMPK 0 - 9999 . 00 0 0 000 000 000 019 Temperature Below Normal % PTBN 0 - 9999 . 00 0 0 000 000 000 029 Temperature Near Normal % PTNN 0 - 9999 . 00 0 0 000 000 000 039 Temperature Above Normal % PTAN 0 - 9999 . 00 0 0 000 000 001 000 Virtual Temperature K TVRK 0 - 9999 . 00 0 0 000 000 002 000 Potential Temperature K THTA 0 - 9999 . 00 0 0 000 000 003 000 Equivalent Potential Temp K THTE 0 - 9999 . 00 0 0 000 000 004 008 Maximum Temperature K TMXK 0 - 9999 . 00 0 0 000 000 005 008 Minimum Temperature K TMNK 0 - 9999 . 00 0 0 000 000 006 000 Dew Point Temperature K DWPK 0 - 9999 . 00 0 0 000 000 007 000 Dew Point Depression K DPDK 0 - 9999 . 00 0 0 000 000 008 000 Lapse Rate K m ** - 1 LAPS 0 - 9999 . 00 0 0 000 000 009 000 Temperature Anomaly K TMPKA 0 - 9999 . 00 0 0 000 000 010 000 Latent Heat Net Flux W m ** - 2 FXLH 0 - 9999 . 00 0 0 000 000 011 000 Sensible Heat Net Flux W m ** - 2 FXSH 0 - 9999 . 00 0 0 000 000 012 000 Heat Index K HEAT 0 - 9999 . 00 0 0 000 000 013 000 Wind Chill Factor K CHILL 0 - 9999 . 00 0 0 !000 000 014 000 Minimum Dew Point Depression K ???? 0 - 9999 . 00 0 0 !000 000 015 000 Virtual Potential Temperature K ???? 0 - 9999 . 00 0 0 ! ! moisture !D# CT# ID# PD# NAME UNITS GNAM SCALE MISSING HZREMAP DIRECTION !23|123|123|123|12345678901234567890123456789012|12345678901234567890|123456789012|12345|123456 . 89|12345678|1234567890 000 001 000 000 Specific Humidity kg kg ** - 1 SPFH 0 - 9999 . 00 0 0 [CODESPLIT] private Map < Integer , Grib2Parameter > initLocalTable ( String resourcePath , @ Nullable Formatter f ) { Map < Integer , Grib2Parameter > result = new HashMap <> ( 100 ) ; try ( InputStream is = GribResourceReader . getInputStream ( resourcePath ) ) { if ( f != null ) f . format ( "%s, %-20s, %-20s, %-20s%n" , "id" , "name" , "units" , "gname" ) ; TableParser parser = new TableParser ( "3i,7i,11i,15i,49,69,74," ) ; parser . setComment ( "!" ) ; List < TableParser . Record > recs = parser . readAllRecords ( is , 50000 ) ; for ( TableParser . Record record : recs ) { int disc = ( Integer ) record . get ( 0 ) ; int cat = ( Integer ) record . get ( 1 ) ; int id = ( Integer ) record . get ( 2 ) ; int template = ( Integer ) record . get ( 3 ) ; // LOOK - 19, 29, 39 ??? String name = ( ( String ) record . get ( 4 ) ) . trim ( ) ; String units = ( ( String ) record . get ( 5 ) ) . trim ( ) ; String gname = ( ( String ) record . get ( 6 ) ) . trim ( ) ; String ids = disc + "-" + cat + "-" + id ; if ( f != null ) f . format ( "%s == %-20s, %-20s, %-20s%n" , ids , name , units , gname ) ; Grib2Parameter gp = new Grib2Parameter ( disc , cat , id , gname , units , null , name ) ; result . put ( Grib2Tables . makeParamId ( disc , cat , id ) , gp ) ; } } catch ( IOException ioe ) { throw new RuntimeException ( ioe ) ; } return result ; }


Input: Append this line to the bottom of the JTextArea . A newline is added and JTextArea is scrolled to bottom ; remove lines at top if needed . [CODESPLIT] public void appendLine ( String line ) { if ( count >= nlines ) { try { int remove = Math . max ( removeIncr , count - nlines ) ; // nlines may have changed int offset = ta . getLineEndOffset ( remove ) ; ta . replaceRange ( "" , 0 , offset ) ; } catch ( Exception e ) { log . error ( "Problem in TextHistoryPane" , e ) ; } count = nlines - removeIncr ; } ta . append ( line ) ; ta . append ( "\n" ) ; count ++ ; // scroll to end ta . setCaretPosition ( ta . getText ( ) . length ( ) ) ; }


Input:
/ * This is part of the Lexer interface [CODESPLIT] public int yylex ( ) throws ParseException { int token ; int c ; token = 0 ; yytext . setLength ( 0 ) ; /* invariant: p always points to current char */ try { token = - 1 ; while ( token < 0 ) { if ( ( c = read ( ) ) <= 0 ) break ; if ( c == ' ' ) { } else if ( c <= ' ' || c == ' ' ) { /* whitespace: ignore */ } else if ( worddelims . indexOf ( c ) >= 0 ) { /* don't put in yytext to avoid memory leak */ token = c ; } else if ( c == ' ' ) { boolean more = true ; /* We have a string token; will be reported as SCAN_STRINGCONST */ while ( more && ( c = read ( ) ) > 0 ) { if ( c == ' ' ) more = false ; else if ( c == ' ' ) { c = read ( ) ; if ( c < 0 ) more = false ; } if ( more ) yytext . append ( ( char ) c ) ; } token = SCAN_STRINGCONST ; } else if ( false && numchars1 . indexOf ( c ) >= 0 ) { // we might have a SCAN_NUMBERCONST boolean isnumber = false ; yytext . append ( ( char ) c ) ; while ( ( c = read ( ) ) > 0 ) { if ( numcharsn . indexOf ( c ) < 0 ) { pushback ( c ) ; break ; } yytext . append ( ( char ) c ) ; } removetrailingblanks ( ) ; //See if this is a number try { Double number = new Double ( yytext . toString ( ) ) ; isnumber = true ; } catch ( NumberFormatException nfe ) { isnumber = false ; } //A number followed by an id char is assumed to just be a funny id if ( isnumber ) { c = read ( ) ; if ( wordcharsn . indexOf ( c ) >= 0 ) { // this is apparently just a funny id token = SCAN_WORD ; } else { // its really a number token = SCAN_NUMBERCONST ; if ( c != ' ' ) pushback ( c ) ; } } else { // !isNumber /* Now, if the funny word has a "." in it,
                           we have to back up to that dot */ int dotpoint = yytext . toString ( ) . indexOf ( ' ' ) ; if ( dotpoint >= 0 ) { for ( int i = 0 ; i < dotpoint ; i ++ ) { pushback ( yytext . charAt ( i ) ) ; } yytext . setLength ( dotpoint ) ; } token = SCAN_WORD ; } } else if ( wordornumberchars1 . indexOf ( c ) >= 0 ) { boolean isnumber = false ; /* we have a WORD or a number*/ yytext . append ( ( char ) c ) ; while ( ( c = read ( ) ) > 0 ) { if ( wordornumbercharsn . indexOf ( c ) < 0 ) { pushback ( c ) ; break ; } yytext . append ( ( char ) c ) ; } removetrailingblanks ( ) ; /* If this looks like a number, then treat it as such.*/ try { new Double ( yytext . toString ( ) ) ; isnumber = true ; } catch ( NumberFormatException nfe ) { isnumber = false ; } if ( isnumber ) token = SCAN_NUMBERCONST ; else { token = SCAN_WORD ; /* If this is a mistaken number, then we need to
                           backup to the last occurrence of a dot '.'
                           because all other number characters are legitmate
                           identifier characters. Special case occurs when
                           we are left with a single dot.
                         */ int dotpoint = yytext . toString ( ) . indexOf ( ' ' ) ; if ( dotpoint >= 0 ) { // pushback the whole of yytext (in reverse order) for ( int i = yytext . length ( ) - 1 ; i >= 0 ; i -- ) pushback ( yytext . charAt ( i ) ) ; yytext . setLength ( 0 ) ; if ( dotpoint == 0 ) { // single character delimiter token = ' ' ; yytext . append ( ( char ) ( c = read ( ) ) ) ; } else  { // Recollect up to but not including the first dot. for ( int i = 0 ; i < dotpoint ; i ++ ) yytext . append ( ( char ) ( c = read ( ) ) ) ; } } } } else { /* we have a single char token */ token = c ; } } if ( token < 0 ) { token = 0 ; lval = null ; } else { // We have to apply DAP2 %xx escaping if this is a SCAN_WORD String text = yytext . toString ( ) ; if ( token == SCAN_WORD ) text = EscapeStrings . unescapeDAPIdentifier ( text ) ; lval = ( text . length ( ) == 0 ? ( String ) null : text ) ; } if ( parsestate . getDebugLevel ( ) > 0 ) dumptoken ( token , ( String ) lval ) ; return token ; /* Return the type of the token.  */ } catch ( IOException ioe ) { throw new ParseException ( ioe ) ; } }


Input: Entry point for error reporting . Emits an error in a user - defined way . [CODESPLIT] public void yyerror ( String s ) { Ceparse . log . error ( "yyerror: constraint parse error:" + s + "; char " + charno ) ; if ( yytext . length ( ) > 0 ) Ceparse . log . error ( " near |" + yytext + "|" ) ; // Add extra info if ( parsestate . getURL ( ) != null ) Ceparse . log . error ( "\turl=" + parsestate . getURL ( ) ) ; Ceparse . log . error ( "\tconstraint=" + ( constraint == null ? "none" : constraint ) ) ; }


Input: System . out . println ( drag : + deltax + + deltay ) ; } [CODESPLIT] public static void main ( String args [ ] ) { JFrame frame = new JFrame ( "Test MyMouseAdapter" ) ; frame . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { System . exit ( 0 ) ; } } ) ; JLabel comp = new JLabel ( "test  sdfk sdf ks;dflk ;sdlkf ldsk lk" ) ; comp . setOpaque ( true ) ; comp . setBackground ( Color . white ) ; comp . setForeground ( Color . black ) ; comp . addMouseListener ( new MyMouseAdapter ( ) ) ; JPanel main = new JPanel ( new FlowLayout ( ) ) ; frame . getContentPane ( ) . add ( main ) ; main . setPreferredSize ( new Dimension ( 200 , 200 ) ) ; main . add ( comp ) ; frame . pack ( ) ; frame . setLocation ( 300 , 300 ) ; frame . setVisible ( true ) ; }


Input: Accessors [CODESPLIT] public DapVariable findByName ( String shortname ) { for ( DapVariable field : fields ) { if ( shortname . equals ( field . getShortName ( ) ) ) return field ; } return null ; }


Input:
Create an XML document for the stations in this dataset possible subsetted by bb . Must be a station dataset . [CODESPLIT] public Document makeStationCollectionDocument ( LatLonRect bb , String [ ] names ) throws IOException { List < DsgFeatureCollection > list = fdp . getPointFeatureCollectionList ( ) ; DsgFeatureCollection fc = list . get ( 0 ) ; // LOOK maybe should pass in the dsg?
 if ( ! ( fc instanceof StationTimeSeriesFeatureCollection ) ) { throw new UnsupportedOperationException ( fc . getClass ( ) . getName ( ) + " not a StationTimeSeriesFeatureCollection" ) ; } StationTimeSeriesFeatureCollection sobs = ( StationTimeSeriesFeatureCollection ) fc ; Element rootElem = new Element ( "stationCollection" ) ; Document doc = new Document ( rootElem ) ; List < StationFeature > stations ; if ( bb != null ) stations = sobs . getStationFeatures ( bb ) ; else if ( names != null ) stations = sobs . getStationFeatures ( Arrays . asList ( names ) ) ; else stations = sobs . getStationFeatures ( ) ; for ( Station s : stations ) { Element sElem = new Element ( "station" ) ; sElem . setAttribute ( "name" , s . getName ( ) ) ; if ( s . getWmoId ( ) != null ) sElem . setAttribute ( "wmo_id" , s . getWmoId ( ) ) ; if ( ( s . getDescription ( ) != null ) && ( s . getDescription ( ) . length ( ) > 0 ) ) sElem . addContent ( new Element ( "description" ) . addContent ( s . getDescription ( ) ) ) ; sElem . addContent ( new Element ( "longitude" ) . addContent ( Double . toString ( s . getLongitude ( ) ) ) ) ; sElem . addContent ( new Element ( "latitide" ) . addContent ( Double . toString ( s . getLatitude ( ) ) ) ) ; if ( ! Double . isNaN ( s . getAltitude ( ) ) ) sElem . addContent ( new Element ( "altitude" ) . addContent ( Double . toString ( s . getAltitude ( ) ) ) ) ; rootElem . addContent ( sElem ) ; } return doc ; }


Input:
Create the capabilities XML document for this dataset [CODESPLIT] public Document getCapabilitiesDocument ( ) { Element rootElem = new Element ( "capabilities" ) ; Document doc = new Document ( rootElem ) ; if ( null != path ) { rootElem . setAttribute ( "location" , path ) ; Element elem = new Element ( "featureDataset" ) ; FeatureType ft = fdp . getFeatureType ( ) ; elem . setAttribute ( "type" , ft . toString ( ) . toLowerCase ( ) ) ; String url = path . replace ( "dataset.xml" , ft . toString ( ) . toLowerCase ( ) + ".xml" ) ; elem . setAttribute ( "url" , url ) ; rootElem . addContent ( elem ) ; } List < DsgFeatureCollection > list = fdp . getPointFeatureCollectionList ( ) ; DsgFeatureCollection fc = list . get ( 0 ) ; // LOOK maybe should pass in the dsg?
 rootElem . addContent ( writeTimeUnit ( fc . getTimeUnit ( ) ) ) ; rootElem . addContent ( new Element ( "AltitudeUnits" ) . addContent ( fc . getAltUnits ( ) ) ) ; // data variables
 List < ? extends VariableSimpleIF > vars = fdp . getDataVariables ( ) ; Collections . sort ( vars ) ; for ( VariableSimpleIF v : vars ) { rootElem . addContent ( writeVariable ( v ) ) ; } /* CollectionInfo info;
    try {
      info = new DsgCollectionHelper(fc).calcBounds();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } */ LatLonRect bb = fc . getBoundingBox ( ) ; if ( bb != null ) rootElem . addContent ( writeBoundingBox ( bb ) ) ; // add date range
 CalendarDateRange dateRange = fc . getCalendarDateRange ( ) ; if ( dateRange != null ) { Element drElem = new Element ( "TimeSpan" ) ; // from KML
 drElem . addContent ( new Element ( "begin" ) . addContent ( dateRange . getStart ( ) . toString ( ) ) ) ; drElem . addContent ( new Element ( "end" ) . addContent ( dateRange . getEnd ( ) . toString ( ) ) ) ; if ( dateRange . getResolution ( ) != null ) drElem . addContent ( new Element ( "resolution" ) . addContent ( dateRange . getResolution ( ) . toString ( ) ) ) ; rootElem . addContent ( drElem ) ; } /* add accept list
    Element elem = new Element("AcceptList");
    //elem.addContent(new Element("accept").addContent("raw"));
    elem.addContent(new Element("accept").addContent("csv").setAttribute("displayName", "csv"));
    elem.addContent(new Element("accept").addContent("text/csv").setAttribute("displayName", "csv (file)"));
    elem.addContent(new Element("accept").addContent("xml").setAttribute("displayName", "xml"));
    elem.addContent(new Element("accept").addContent("text/xml").setAttribute("displayName", "xml (file)"));
    elem.addContent(new Element("accept").addContent("waterml2").setAttribute("displayName", "WaterML 2.0"));
    elem.addContent(new Element("accept").addContent("netcdf").setAttribute("displayName", "CF/NetCDF-3"));
    //elem.addContent(new Element("accept").addContent("ncstream"));
    rootElem.addContent(elem); */ return doc ; }


Input: package private . use Array . factory () [CODESPLIT] static ArrayByte factory ( Index index , boolean isUnsigned ) { return ArrayByte . factory ( index , isUnsigned , null ) ; }


Input: copy from javaArray to storage using the iterator : used by factory ( Object ) ; [CODESPLIT] protected void copyFrom1DJavaArray ( IndexIterator iter , Object javaArray ) { byte [ ] ja = ( byte [ ] ) javaArray ; for ( byte aJa : ja ) iter . setByteNext ( aJa ) ; }


Input: package private : mostly for iterators [CODESPLIT] public double getDouble ( int index ) { byte val = storage [ index ] ; return ( double ) ( isUnsigned ( ) ? DataType . unsignedByteToShort ( val ) : val ) ; }


Input: coord based record finding . note only one record at a time [CODESPLIT] @ Nullable synchronized Record getRecordAt ( SubsetParams coords ) { int [ ] want = new int [ getRank ( ) ] ; int count = 0 ; int runIdx = - 1 ; for ( Coordinate coord : getCoordinates ( ) ) { int idx = - 1 ; switch ( coord . getType ( ) ) { case runtime : CalendarDate runtimeCooord = coords . getRunTime ( ) ; idx = coord . getIndex ( runtimeCooord ) ; runIdx = idx ; break ; case timeIntv : double [ ] timeIntv = coords . getTimeOffsetIntv ( ) ; idx = coord . getIndex ( new TimeCoordIntvValue ( ( int ) timeIntv [ 0 ] , ( int ) timeIntv [ 1 ] ) ) ; break ; case time : Double timeOffset = coords . getTimeOffset ( ) ; // Double int coordInt = timeOffset . intValue ( ) ; idx = coord . getIndex ( coordInt ) ; break ; case time2D : timeIntv = coords . getTimeOffsetIntv ( ) ; if ( timeIntv != null ) { TimeCoordIntvValue coordTinv = new TimeCoordIntvValue ( ( int ) timeIntv [ 0 ] , ( int ) timeIntv [ 1 ] ) ; idx = ( ( CoordinateTime2D ) coord ) . findTimeIndexFromVal ( runIdx , coordTinv ) ; // LOOK can only use if orthogonal break ; } Double timeCoord = coords . getTimeOffset ( ) ; if ( timeCoord != null ) { coordInt = timeCoord . intValue ( ) ; idx = ( ( CoordinateTime2D ) coord ) . findTimeIndexFromVal ( runIdx , coordInt ) ; break ; } // the OneTime case CoordinateTime2D coord2D = ( CoordinateTime2D ) coord ; if ( coord2D . getNtimes ( ) == 1 ) { idx = 0 ; break ; } throw new IllegalStateException ( "time2D must have timeOffset ot timeOffsetIntv coordinare" ) ; case vert : double [ ] vertIntv = coords . getVertCoordIntv ( ) ; if ( vertIntv != null ) { VertCoordValue coordVert = new VertCoordValue ( vertIntv [ 0 ] , vertIntv [ 1 ] ) ; idx = coord . getIndex ( coordVert ) ; break ; } Double vertCoord = coords . getVertCoord ( ) ; if ( vertCoord != null ) { VertCoordValue coordVert = new VertCoordValue ( vertCoord ) ; idx = coord . getIndex ( coordVert ) ; } break ; case ens : Double ensVal = coords . getEnsCoord ( ) ; idx = ( ( CoordinateEns ) coord ) . getIndexByMember ( ensVal ) ; break ; default : logger . warn ( "GribCollectionImmutable: missing CoordVal for {}%n" , coord . getName ( ) ) ; } if ( idx < 0 ) { logger . debug ( "Cant find index for value in axis {} in variable {}" , coord . getName ( ) , name ) ; return null ; } want [ count ++ ] = idx ; } return sa . getContent ( want ) ; }


Input: get the ith coordinate [CODESPLIT] public Coordinate getCoordinate ( int index ) { int grpIndex = coordIndex . get ( index ) ; return group . coords . get ( grpIndex ) ; }


Input: DMRFactory API [CODESPLIT] public DapAttribute newAttribute ( String name , DapType basetype ) { DapAttribute node = new DapAttribute ( name , basetype ) ; return node ; }


Input:
Add the item to the top of the list . If it already exists move it to the top . [CODESPLIT] public void addItem ( Object item ) { if ( item == null ) return ; for ( int i = 0 ; i < getItemCount ( ) ; i ++ ) { if ( item . equals ( getItemAt ( i ) ) ) { if ( i == 0 ) { setSelectedIndex ( 0 ) ; return ; // already there
 } removeItemAt ( i ) ; } } // add as first in the list
 insertItemAt ( item , 0 ) ; setSelectedIndex ( 0 ) ; }


Input:
Use this to obtain the list of items . [CODESPLIT] public List < Object > getItemList ( ) { ArrayList < Object > list = new ArrayList < Object > ( ) ; for ( int i = 0 ; i < getItemCount ( ) && i < nkeep ; i ++ ) list . ( getItemAt ( i ) ) ; return list ; } /**
   * Use this to set the list of items.
   * @param list of items, may be any Object type.
   */ public void setItemList ( Collection < Object > list ) { if ( list == null ) return ; setModel ( new DefaultComboBoxModel ( list . toArray ( ) ) ) ; if ( list . size ( ) > 0 ) setSelectedIndex ( 0 ) ; } /** Set the number of items to keep */ public void setNkeep  ( int nkeep ) { this . nkeep = nkeep ; } /** Get the number of items to keep */ public int getNkeep  ( ) { return nkeep ; } /** Get value from Store, will be an ArrayList or null */ protected Object getStoreValue  ( Object defValue ) { if ( prefs == null ) return defValue ; return ( ( PreferencesExt ) prefs ) . getBean ( LIST , defValue ) ; } /** Put new value into Store, must be a List of Strings */ protected void setStoreValue  ( List newValue ) { if ( prefs != null ) prefs . putList ( LIST , newValue ) ; } // debug
 private static long lastEvent ; public static void main  ( String args [ ] ) throws IOException { JFrame frame = new JFrame ( "Test" ) ; frame . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { System . exit ( 0 ) ; } } ) ; final ComboBox cb = new ComboBox ( null ) ; cb . addActionListener ( e -> { System . out . println ( "**** cb event=" + e ) ; if ( e . getActionCommand ( ) . equals ( "comboBoxChanged" ) ) { //System.out.println("cb.getSelectedItem="+cb.getSelectedItem());
 cb . addItem ( cb . getSelectedItem ( ) ) ; } } ) ; cb . getEditor ( ) . getEditorComponent ( ) . setForeground ( Color . red ) ; /* JButton butt = new JButton("accept");
   butt.addActionListener( new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("butt accept");
        cb.accept();
     }
   }); */ JPanel main = new JPanel ( ) ; main . add ( cb ) ; // main.add(butt);
 frame . getContentPane ( ) . add ( main ) ; // cb.setPreferredSize(new java.awt.Dimension(500, 200));
 frame . pack ( ) ; frame . setLocation ( 300 , 300 ) ; frame . setVisible ( true ) ; } }


Input: Get the 3D vertical coordinate array for this time step . [CODESPLIT] public ArrayDouble . D3 getCoordinateArray ( int timeIndex ) throws IOException , InvalidRangeException { int nz = ( int ) pressure . getSize ( ) ; int [ ] shape2D = pressure . getShape ( ) ; int ny = shape2D [ 0 ] ; int nx = shape2D [ 1 ] ; ArrayDouble . D3 result = new ArrayDouble . D3 ( nz , ny , nx ) ; IndexIterator ii = pressure . getIndexIterator ( ) ; for ( int z = 0 ; z < nz ; z ++ ) { double p = ii . getDoubleNext ( ) ; for ( int y = 0 ; y < ny ; y ++ ) { for ( int x = 0 ; x < nx ; x ++ ) { result . set ( z , y , x , p ) ; } } } return result ; }


Input: LOOK this could be a problem [CODESPLIT] @ ExceptionHandler ( Throwable . class ) public ResponseEntity < String > handle ( Throwable ex ) throws Throwable { // If the exception is annotated with @ResponseStatus rethrow it and let // the framework handle it - like the OrderNotFoundException example // at the start of this post. // AnnotationUtils is a Spring Framework utility class. // see https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc if ( AnnotationUtils . findAnnotation ( ex . getClass ( ) , ResponseStatus . class ) != null ) throw ex ; logger . error ( "uncaught exception" , ex ) ; // ex.printStackTrace(); // temporary - remove in production HttpHeaders responseHeaders = new HttpHeaders ( ) ; responseHeaders . setContentType ( MediaType . TEXT_PLAIN ) ; String msg = ex . getMessage ( ) ; StringWriter sw = new StringWriter ( ) ; PrintWriter p = new PrintWriter ( sw ) ; ex . printStackTrace ( p ) ; p . close ( ) ; sw . close ( ) ; msg = sw . toString ( ) ; return new ResponseEntity <> ( "Throwable exception handled : " + htmlEscape ( msg ) , responseHeaders , HttpStatus . INTERNAL_SERVER_ERROR ) ; }


Input: Return ith slice [CODESPLIT] public Slice slice ( int i ) { if ( i < 0 || i >= this . rank ) throw new IllegalArgumentException ( ) ; return this . slices . get ( i ) ; }


Input: Compute the total number of elements . [CODESPLIT] public long totalSize ( ) { long size = 1 ; for ( int i = 0 ; i < this . rank ; i ++ ) { size *= this . slices . get ( i ) . getCount ( ) ; } return size ; }


Input: Iterator API [CODESPLIT] @ Override public boolean hasNext ( ) { int stop = this . rank ; switch ( this . state ) { case INITIAL : return true ; case STARTED : int i ; for ( i = stop - 1 ; i >= 0 ; i -- ) { // walk backwards if ( this . index . indices [ i ] <= this . endpoint [ i ] ) return true ; } this . state = STATE . DONE ; break ; case DONE : } return false ; }


Input: return - 1 if we have completed . [CODESPLIT] public int step ( int firstpos , int lastpos ) { for ( int i = lastpos - 1 ; i >= firstpos ; i -- ) { // walk backwards if ( this . index . indices [ i ] > this . endpoint [ i ] ) this . index . indices [ i ] = this . slices . get ( i ) . getFirst ( ) ; // reset this position else { this . index . indices [ i ] += this . slices . get ( i ) . getStride ( ) ; // move to next indices return i ; } } return - 1 ; }


Input: http : // www . nco . ncep . noaa . gov / pmb / docs / on388 / table5 . html [CODESPLIT] @ Override public GribStatType getStatType ( int timeRangeIndicator ) { switch ( timeRangeIndicator ) { case 128 : case 129 : case 130 : case 131 : case 132 : case 133 : case 137 : case 138 : case 139 : case 140 : return GribStatType . Average ; case 134 : return GribStatType . RootMeanSquare ; case 135 : case 136 : return GribStatType . StandardDeviation ; default : return super . getStatType ( timeRangeIndicator ) ; } }


Input:
public so can be called from Grib2 [CODESPLIT] @ Nullable public static Map < Integer , String > getNcepGenProcess ( ) { if ( genProcessMap != null ) return genProcessMap ; String path = "resources/grib1/ncep/ncepTableA.xml" ; try ( InputStream is = GribResourceReader . getInputStream ( path ) ) { SAXBuilder builder = new SAXBuilder ( ) ; org . jdom2 . Document doc = builder . build ( is ) ; Element root = doc . getRootElement ( ) ; HashMap < Integer , String > result = new HashMap <> ( 200 ) ; List < Element > params = root . getChildren ( "parameter" ) ; for ( Element elem1 : params ) { int code = Integer . parseInt ( elem1 . getAttributeValue ( "code" ) ) ; String desc = elem1 . getChildText ( "description" ) ; result . put ( code , desc ) ; } return Collections . unmodifiableMap ( result ) ; // all at once - thread safe
 } catch ( IOException | JDOMException ioe ) { logger . error ( "Cant read NCEP Table 1 = " + path , ioe ) ; return null ; } }


Input:
/////////////////////////////////////// levels [CODESPLIT] protected VertCoordType getLevelType ( int code ) { if ( code < 129 ) return super . getLevelType ( code ) ; // LOOK dont let NCEP override standard tables (??) looks like a conflict with level code 210 (!)
 if ( levelTypesMap == null ) levelTypesMap = readTable3 ( "resources/grib1/ncep/ncepTable3.xml" ) ; if ( levelTypesMap == null ) return super . getLevelType ( code ) ; VertCoordType levelType = levelTypesMap . get ( code ) ; if ( levelType != null ) return levelType ; return super . getLevelType ( code ) ; }


Input:
/ * MAGIC_START version sizeRecords SparseArray s ( sizeRecords bytes ) sizeIndex GribCollectionIndex ( sizeIndex bytes ) [CODESPLIT] boolean writeIndex ( String name , File idxFile , CoordinateRuntime masterRuntime , List < Group > groups , List < MFile > files , GribCollectionImmutable . Type type , CalendarDateRange dateRange ) throws IOException { Grib2Record first = null ; // take global metadata from here boolean deleteOnClose = false ; if ( idxFile . exists ( ) ) { RandomAccessFile . eject ( idxFile . getPath ( ) ) ; if ( ! idxFile . delete ( ) ) { logger . error ( "gc2 cant delete index file {}" , idxFile . getPath ( ) ) ; } } logger . debug ( " createIndex for {}" , idxFile . getPath ( ) ) ; try ( RandomAccessFile raf = new RandomAccessFile ( idxFile . getPath ( ) , "rw" ) ) { //// header message raf . order ( RandomAccessFile . BIG_ENDIAN ) ; raf . write ( MAGIC_START . getBytes ( CDM . utf8Charset ) ) ; raf . writeInt ( version ) ; long lenPos = raf . getFilePointer ( ) ; raf . writeLong ( 0 ) ; // save space to write the length of the record section long countBytes = 0 ; int countRecords = 0 ; Set < Integer > allFileSet = new HashSet <> ( ) ; for ( Group g : groups ) { g . fileSet = new HashSet <> ( ) ; for ( Grib2CollectionBuilder . VariableBag vb : g . gribVars ) { if ( first == null ) first = vb . first ; GribCollectionProto . SparseArray vr = writeSparseArray ( vb , g . fileSet ) ; byte [ ] b = vr . toByteArray ( ) ; vb . pos = raf . getFilePointer ( ) ; vb . length = b . length ; raf . write ( b ) ; countBytes += b . length ; countRecords += vb . coordND . getSparseArray ( ) . countNotMissing ( ) ; } allFileSet . addAll ( g . fileSet ) ; } if ( logger . isDebugEnabled ( ) ) { long bytesPerRecord = countBytes / ( ( countRecords == 0 ) ? 1 : countRecords ) ; logger . debug ( "  write RecordMaps: bytes = {} record = {} bytesPerRecord={}" , countBytes , countRecords , bytesPerRecord ) ; } if ( first == null ) { deleteOnClose = true ; throw new IOException ( "GribCollection " + name + " has no records" ) ; } long pos = raf . getFilePointer ( ) ; raf . seek ( lenPos ) ; raf . writeLong ( countBytes ) ; raf . seek ( pos ) ; // back to the output. /*
      message GribCollection {
        string name = 1;         // must be unique - index filename is name.ncx
        string topDir = 2;       // MFile, Partition filenames are reletive to this
        repeated MFile mfiles = 3;        // list of grib MFiles
        repeated Dataset dataset = 4;
        repeated Gds gds = 5;             // unique Gds, shared amongst datasets
        Coord masterRuntime = 6;  // list of runtimes in this GC

        int32 center = 7;      // these 4 fields are to get a GribCustomizer
        int32 subcenter = 8;
        int32 master = 9;
        int32 local = 10;       // grib1 table Version

        int32 genProcessType = 11;
        int32 genProcessId = 12;
        int32 backProcessId = 13;
        int32 version = 14;     // >= 3 for proto3 (5.0+)

        // repeated Parameter params = 20;      // not used
        FcConfig config = 21;

        // extensions
        repeated Partition partitions = 100;
        bool isPartitionOfPartitions = 101;
        repeated uint32 run2part = 102 [packed=true];  // masterRuntime index to partition index
      }
       */ GribCollectionProto . GribCollection . Builder indexBuilder = GribCollectionProto . GribCollection . newBuilder ( ) ; indexBuilder . setName ( name ) ; indexBuilder . setTopDir ( dcm . getRoot ( ) ) ; indexBuilder . setVersion ( currentVersion ) ; // directory and mfile list File directory = new File ( dcm . getRoot ( ) ) ; List < GcMFile > gcmfiles = GcMFile . makeFiles ( directory , files , allFileSet ) ; for ( GcMFile gcmfile : gcmfiles ) { GribCollectionProto . MFile . Builder b = GribCollectionProto . MFile . newBuilder ( ) ; b . setFilename ( gcmfile . getName ( ) ) ; b . setLastModified ( gcmfile . getLastModified ( ) ) ; b . setLength ( gcmfile . getLength ( ) ) ; b . setIndex ( gcmfile . index ) ; indexBuilder . addMfiles ( b . build ( ) ) ; } indexBuilder . setMasterRuntime ( writeCoordProto ( masterRuntime ) ) ; //gds for ( Object go : groups ) { Group g = ( Group ) go ; indexBuilder . addGds ( writeGdsProto ( g . gdss . getRawBytes ( ) , - 1 ) ) ; } // the GC dataset indexBuilder . addDataset ( writeDatasetProto ( type , groups ) ) ; // what about just storing first ?? Grib2SectionIdentification ids = first . getId ( ) ; indexBuilder . setCenter ( ids . getCenter_id ( ) ) ; indexBuilder . setSubcenter ( ids . getSubcenter_id ( ) ) ; indexBuilder . setMaster ( ids . getMaster_table_version ( ) ) ; indexBuilder . setLocal ( ids . getLocal_table_version ( ) ) ; Grib2Pds pds = first . getPDS ( ) ; indexBuilder . setGenProcessType ( pds . getGenProcessType ( ) ) ; indexBuilder . setGenProcessId ( pds . getGenProcessId ( ) ) ; indexBuilder . setBackProcessId ( pds . getBackProcessId ( ) ) ; indexBuilder . setStartTime ( dateRange . getStart ( ) . getMillis ( ) ) ; indexBuilder . setEndTime ( dateRange . getEnd ( ) . getMillis ( ) ) ; GribCollectionProto . GribCollection index = indexBuilder . build ( ) ; byte [ ] b = index . toByteArray ( ) ; NcStream . writeVInt ( raf , b . length ) ; // message size raf . write ( b ) ; // message  - all in one gulp logger . debug ( "  write GribCollectionIndex= {} bytes" , b . length ) ; } finally { // remove it on failure if ( deleteOnClose && ! idxFile . delete ( ) ) logger . error ( " gc2 cant deleteOnClose index file {}" , idxFile . getPath ( ) ) ; } return true ; }


Input: / * message Record { uint32 fileno = 1 ; // which GRIB file ? key into GC . fileMap uint64 pos = 2 ; // offset in GRIB file of the start of entire message uint64 bmsPos = 3 ; // use alternate bms if non - zero uint32 drsOffset = 4 ; // offset of drs from pos ( grib2 only ) } [CODESPLIT] private GribCollectionProto . SparseArray writeSparseArray ( Grib2CollectionBuilder . VariableBag vb , Set < Integer > fileSet ) { GribCollectionProto . SparseArray . Builder b = GribCollectionProto . SparseArray . newBuilder ( ) ; SparseArray < Grib2Record > sa = vb . coordND . getSparseArray ( ) ; for ( int size : sa . getShape ( ) ) b . addSize ( size ) ; for ( int track : sa . getTrack ( ) ) b . addTrack ( track ) ; for ( Grib2Record gr : sa . getContent ( ) ) { GribCollectionProto . Record . Builder br = GribCollectionProto . Record . newBuilder ( ) ; br . setFileno ( gr . getFile ( ) ) ; fileSet . add ( gr . getFile ( ) ) ; long startPos = gr . getIs ( ) . getStartPos ( ) ; br . setStartPos ( startPos ) ; if ( gr . isBmsReplaced ( ) ) { Grib2SectionBitMap bms = gr . getBitmapSection ( ) ; br . setBmsOffset ( ( int ) ( bms . getStartingPosition ( ) - startPos ) ) ; } Grib2SectionDataRepresentation drs = gr . getDataRepresentationSection ( ) ; br . setDrsOffset ( ( int ) ( drs . getStartingPosition ( ) - startPos ) ) ; b . addRecords ( br ) ; } b . setNdups ( sa . getNdups ( ) ) ; return b . build ( ) ; }