### Build and Install grib2json Source: https://context7.com/cambecc/grib2json/llms.txt Clone the repository, build the project using Maven, and extract the distribution archive. Set JAVA_HOME and add the bin directory to your PATH. ```bash git clone https://github.com/cambecc/grib2json.git cd grib2json mvn package tar -xzf target/grib2json-0.8.0-SNAPSHOT.tar.gz -C /opt/ export PATH=$PATH:/opt/grib2json-0.8.0-SNAPSHOT/bin export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 ``` -------------------------------- ### Decode GRIB2 Data to JSON with Filters Source: https://github.com/cambecc/grib2json/blob/master/README.md Example of decoding a GRIB2 file, filtering by parameter, surface type, and surface value, and including names and data in the JSON output. The output is directed to stdout. ```json > grib2json --names --data --fp 2 --fs 103 --fv 10.0 gfs.t18z.pgrbf00.2p5deg.grib2 [ { "header":{ "discipline":0, "disciplineName":"Meteorological products", "gribEdition":2, "gribLength":27759, "center":7, "centerName":"US National Weather Service - NCEP(WMC)", "parameterNumber":2, "parameterNumberName":"U-component_of_wind", "parameterUnit":"m.s-1", "surface1Type":103, "surface1TypeName":"Specified height level above ground", "surface1Value":10.0, ... }, "data":[ -2.12, -2.27, -2.41, ... ] } ] ``` -------------------------------- ### Clone and Build grib2json Source: https://github.com/cambecc/grib2json/blob/master/README.md Clone the project repository and build the utility using Maven. The resulting package will be in the target directory. ```bash git clone mvn package ``` -------------------------------- ### grib2json Command Line Help Source: https://github.com/cambecc/grib2json/blob/master/README.md Display the help message for the grib2json utility to understand available options and their usage. ```bash > grib2json --help Usage: grib2json [options] FILE [--compact -c] : enable compact Json formatting [--data -d] : print GRIB record data [--filter.category --fc value] : select records with this numeric category [--filter.parameter --fp value] : select records with this numeric parameter [--filter.surface --fs value] : select records with this numeric surface type [--filter.value --fv value] : select records with this numeric surface value [--help -h] : display this help [--names -n] : print names of numeric codes [--output -o value] : write output to the specified file (default is stdout) [--verbose -v] : enable logging to stdout ``` -------------------------------- ### Programmatic Grib2Json Conversion in Java Source: https://context7.com/cambecc/grib2json/llms.txt Demonstrates how to parse options programmatically and use the Grib2Json class to convert a GRIB2 file to JSON. Ensure the input file exists and handle potential IO or argument exceptions. ```java import net.nullschool.grib2json.Grib2Json; import net.nullschool.grib2json.Options; import com.lexicalscope.jewel.cli.CliFactory; import java.io.File; import java.util.Collections; // Parse options programmatically Options options = CliFactory.parseArguments( Options.class, "--names", "--data", "--fp", "2", "--fs", "103", "--fv", "10.0", "--output", "wind-u.json" ); // Construct and run the converter File inputFile = new File("gfs.t18z.pgrbf00.2p5deg.grib2"); try { new Grib2Json(inputFile, Collections.singletonList(options)).write(); System.out.println("Conversion complete: wind-u.json"); } catch (IllegalArgumentException e) { System.err.println("File not found: " + e.getMessage()); } catch (java.io.IOException e) { System.err.println("Conversion failed: " + e.getMessage()); } ``` -------------------------------- ### Batch Extraction with --recipe Source: https://context7.com/cambecc/grib2json/llms.txt Use the --recipe option with a file containing filter and output configurations per line for batch processing. This allows multiple output files to be generated in a single pass over the input GRIB file. ```bash # recipe.txt contents: # --fp 2 --fs 103 --fv 10 --output wind-u-10m.json # --fp 3 --fs 103 --fv 10 --output wind-v-10m.json # --fp 0 --fs 103 --fv 2 --output temp-2m.json grib2json --names --data --recipe recipe.txt gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### grib2json Command-Line Usage Source: https://context7.com/cambecc/grib2json/llms.txt Displays the help message for grib2json, outlining available options for filtering and output formatting. ```text Usage: grib2json [options] FILE [--compact -c] : enable compact Json formatting [--data -d] : print GRIB record data [--filter.discipline --fd] : select records with this discipline code [--filter.category --fc] : select records with this numeric category [--filter.parameter --fp] : select records with this numeric parameter (or "wind") [--filter.surface --fs] : select records with this numeric surface type [--filter.value --fv] : select records with this numeric surface value [--help -h] : display this help [--names -n] : print names of numeric codes alongside codes [--output -o value] : write output to the specified file (default: stdout) [--recipe -r value] : a file containing a batch of filter option lines [--verbose -v] : enable logging to stdout ``` -------------------------------- ### Redirect Output to File with --output Source: https://context7.com/cambecc/grib2json/llms.txt Use the --output option to save JSON output to a file, which is practical for large datasets where piping is not feasible. The exit code indicates success or failure. ```bash grib2json --names --data --fp 2 --fs 103 --fv 10.0 \ --output wind-u-10m.json \ gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Compact JSON Output with --compact Source: https://context7.com/cambecc/grib2json/llms.txt Employ the --compact flag to disable pretty-printing, resulting in minified JSON with minimal whitespace. This significantly reduces file sizes for large GRIB datasets. ```bash grib2json --compact --data --fp wind --output wind.json gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Basic Conversion - Headers Only Source: https://context7.com/cambecc/grib2json/llms.txt Converts a GRIB2 file to JSON, outputting only the header information for each record. The `--data` flag is omitted to exclude potentially large data arrays. ```bash grib2json gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Include Human-Readable Code Names Source: https://context7.com/cambecc/grib2json/llms.txt Converts a GRIB2 file to JSON, including human-readable names for numeric codes by using the `--names` flag. This makes the output self-documenting. ```bash grib2json --names gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Include Data Arrays with Filters Source: https://context7.com/cambecc/grib2json/llms.txt Converts a GRIB2 file to JSON, including data arrays and applying filters for parameter, surface type, and surface value. Special IEEE 754 values are serialized as JSON strings. ```bash grib2json --names --data --fp 2 --fs 103 --fv 10.0 gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Filter GRIB Records by Multiple Criteria Source: https://context7.com/cambecc/grib2json/llms.txt Utilize filtering options like --fd (discipline), --fc (category), --fp (parameter), --fs (surface type), and --fv (surface value) to select specific GRIB records. All filters are ANDed together. ```bash # Filter by discipline (0=Meteorological), category (2=Momentum), # parameter (2=U-wind), surface type (103=Height above ground), surface value (10m) grib2json --fd 0 --fc 2 --fp 2 --fs 103 --fv 10.0 --names --data \ gfs.t18z.pgrbf00.2p5deg.grib2 ``` ```bash # Shorthand for both U and V wind components at 10m: grib2json --fp wind --fs 103 --fv 10.0 --names --data \ --output wind-uv-10m.json \ gfs.t18z.pgrbf00.2p5deg.grib2 ``` ```bash # Filter for 2m temperature (category=0, parameter=0, surface=103, value=2): grib2json --fc 0 --fp 0 --fs 103 --fv 2.0 --names --data \ --output temp-2m.json \ gfs.t18z.pgrbf00.2p5deg.grib2 ``` -------------------------------- ### Convert OSCAR NetCDF to JSON Source: https://context7.com/cambecc/grib2json/llms.txt When input files are not GRIB2, grib2json attempts to parse them as NetCDF, specifically for OSCAR ocean current data. The output maps NetCDF variables to GRIB2 header conventions with fixed grid resolution and data precision. ```bash # Convert an OSCAR NetCDF file to JSON with data arrays grib2json --names --data --output oscar-currents.json oscar_vel5day.nc ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.