Skip to content

Commit

Permalink
documentation and license
Browse files Browse the repository at this point in the history
  • Loading branch information
cambecc committed Oct 25, 2013
1 parent 95a4597 commit dbe7454
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 107 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Cameron Beccario

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
<url>https://github.com/cambecc/grib2json</url>
<inceptionYear>2013</inceptionYear>

<!--
<licenses>
<license>
<name>CC0 1.0 Universal</name>
<url>http://creativecommons.org/publicdomain/zero/1.0/</url>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
-->

<developers>
<developer>
Expand Down
1 change: 0 additions & 1 deletion src/bin/grib2json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh
#set -x

LIB_DIR=$(dirname "$0")/../lib
LAUNCH_JAR=$LIB_DIR/grib2json-*.jar
$JAVA_HOME/bin/java -Xmx1G -jar $LAUNCH_JAR $@
6 changes: 6 additions & 0 deletions src/main/java/net/nullschool/grib2json/FloatValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
/**
* 2013-10-24<p/>
*
* A Json float value. This class uses Float.toString to produce the Json text for a float. This avoids the
* noise caused by the default JsonGenerator when it widens to double.
*
* This class also defines the Json representations for NaN, Infinity, and -Infinity to be their equivalent
* String representations. For example: [1.0, 2.3, "NaN", 0.7, "Infinity"]
*
* @author Cameron Beccario
*/
final class FloatValue implements JsonNumber {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/nullschool/grib2json/Grib2Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
/**
* 2013-10-25<p/>
*
* Converts a GRIB2 file to Json. GRIB2 decoding is performed by the NetCDF GRIB decoder.
*
* This class was initially based on Grib2Dump, part of the NetCDF Java library written by University
* Corporation for Atmospheric Research/Unidata. However, what appears below is a complete rewrite.
*
* @author Cameron Beccario
*/
public final class Grib2Json {
Expand All @@ -27,6 +32,9 @@ public Grib2Json(Options options) {
this.options = options;
}

/**
* Convert the GRIB2 file to Json as specified by the command line options.
*/
public void write() throws IOException {

RandomAccessFile raf = new RandomAccessFile(options.getFile().getPath(), "r");
Expand All @@ -42,7 +50,7 @@ public void write() throws IOException {

JsonGeneratorFactory jgf =
Json.createGeneratorFactory(
options.isCompact() ?
options.isCompactFormat() ?
null :
singletonMap(JsonGenerator.PRETTY_PRINTING, true));
JsonGenerator jg = jgf.createGenerator(output);
Expand All @@ -55,7 +63,7 @@ public void write() throws IOException {
if (rw.isSelected()) {
jg.writeStartObject();
rw.writeHeader();
if (options.isData()) {
if (options.getPrintData()) {
rw.writeData(new Grib2Data(raf));
}
jg.writeEnd();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/nullschool/grib2json/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/**
* 2013-10-24<p/>
*
* Execution shim for the grib2json utility. Parses command line options and invokes the {@link Grib2Json} converter.
*
* @author Cameron Beccario
*/
class Launcher {
Expand All @@ -30,13 +32,13 @@ public static void main(String args[]) {
return;
}

if (options.isHelp() || options.getFile() == null) {
if (options.getShowHelp() || options.getFile() == null) {
printUsage();
return;
}

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
if (!options.isVerbose()) {
if (!options.getEnableLogging()) {
lc.stop();
}

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/net/nullschool/grib2json/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
/**
* 2013-10-25<p/>
*
* Command line options for the grib2json utility. This interface is proxied by the Jewel Cli options parsing library.
*
* @author Cameron Beccario
*/

@CommandLineInterface(application="grib2json")
public interface Options {

@Option(shortName={"h", "?"}, description="display help")
boolean isHelp();
@Option(longName="help", shortName={"h", "?"}, description="display help")
boolean getShowHelp();

@Option(shortName="n", description="print names of codes")
boolean isNames();
@Option(longName="names", shortName="n", description="print names of the numeric codes")
boolean getPrintNames();

@Option(shortName="d", description="print record data")
boolean isData();
@Option(longName="data", shortName="d", description="print record data")
boolean getPrintData();

@Option(shortName="c", description="enable compact formatting")
boolean isCompact();
@Option(longName="compact", shortName="c", description="enable compact formatting")
boolean isCompactFormat();

@Option(shortName="v", description="enable logging")
boolean isVerbose();
@Option(longName="verbose", shortName="v", description="enable logging")
boolean getEnableLogging();

@Option(shortName="o", description="print to specified file", defaultToNull=true)
@Option(longName="output", shortName="o", description="print to specified file", defaultToNull=true)
File getOutput();

@Unparsed(name="FILE", defaultToNull=true)
Expand Down
Loading

0 comments on commit dbe7454

Please sign in to comment.