Building with Maven artifacts
We make the NetCDF-Java library available as Maven artifacts. To use them in your build, you need to add the Unidata Releases repository:
<!-- In Maven -->
<repositories>
<repository>
<id>unidata-all</id>
<name>Unidata All</name>
<url>https://artifacts.unidata.ucar.edu/repository/unidata-all/</url>
</repository>
</repositories>
// In Gradle
repositories {
maven {
url "https://artifacts.unidata.ucar.edu/repository/unidata-all/"
}
}
Next, select modules based on the functionality you need. In the minimal case, you’ll just want cdm
and a
logger. cdm
implements the CDM data model and allows you to read NetCD-3 files (and a number of other
file types). An example using JDK14 logging:
<!-- In Maven -->
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>cdm</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>${slf4jVersion}</version>
<scope>runtime</scope>
</dependency>
// In Gradle
dependencies {
compile "edu.ucar:cdm:${netcdfJavaVersion}"
runtime "org.slf4j:slf4j-jdk14:${slf4jVersion}"
}
There are optional modules add support for reading (and sometimes writing) various scientific data formats. The formats associated with each module are:
-
bufr
: BUFR -
clcommon
: GINI and FYSAT -
grib
: GRIB-1 and GRIB-2 -
netcdf4
: NetCDF-4. Writing requires the NetCDF-4 C library to be installed. -
opendap
: OPeNDAP -
visadCdm
: GEMPAK grid, station, and sounding; McIDAS grid; and ADDE image and station
You can include any number of the above components. To do so in Maven and Gradle:
<!-- In Maven -->
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>bufr</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>clcommon</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>grib</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>netcdf4</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>opendap</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>visadCdm</artifactId>
<version>${netcdfJavaVersion}</version>
<scope>runtime</scope>
</dependency>
// In Gradle
dependencies {
runtime "edu.ucar:bufr:${netcdfJavaVersion}"
runtime "edu.ucar:clcommon:${netcdfJavaVersion}"
runtime "edu.ucar:grib:${netcdfJavaVersion}"
runtime "edu.ucar:netcdf4:${netcdfJavaVersion}"
runtime "edu.ucar:opendap:${netcdfJavaVersion}"
runtime "edu.ucar:visadCdm:${netcdfJavaVersion}"
}
Building with netcdfAll
This is the appropriate option if you’re not using a dependency management tool like Maven or Gradle and you don’t care about jar size or compatibility with other libraries. Simply include netcdfAll-${netcdfJavaVersion}.jar on the classpath when you run your program. You’ll also need a logger.
Logging
The NetCDF-Java library uses the SLF4J logging facade. This allows applications to choose their own logging implementation, by including the appropriate jar file on the classpath at runtime. Common choices are:
JDK Logging
-
You must include the SLF4J-to-JDK Logging interface jar:
slf4j-jdk14-${slf4jVersion}.jar
. -
The actual logging is implemented in the
java.util.log
package, part of the Java runtime.
To configure JDK logging:
-
Modify the file
$JAVA_HOME/jre/lib/logging.properties
. Or, create you own logging properties file and specify it with thejava.util.logging.config.file
system property. -
Possible log levels are
SEVERE
,WARNING
,INFO
,CONFIG
,FINE
,FINER
,FINEST
, andALL
. -
To show only
SEVERE
messages for all loggers, use:.level= SEVERE
You can also set the configuration by using java.util.logging.LogManager in your application, most likely by creating your own properties file or resources and calling:
FileInputStream inputStream = new FileInputStream("my.properties");
LogManager lm = java.util.logging.LogManager.getLogManager();
lm.readConfiguration(inputStream);
Log4j 2
-
You must include the Log4j 2 SLF4J Binding (
log4j-slf4j-impl-${log4j2Version}.jar
) and the Log4j 2 implementation (log4j-core-${log4j2Version}.jar
) on the classpath. -
You should then configure the logging by adding a
log4j2.xml
config file to your classpath. A minimal version is:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>