You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(56) |
Jul
(15) |
Aug
(7) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <rit...@us...> - 2010-08-30 07:31:10
|
Revision: 86 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=86&view=rev Author: ritacsiro Date: 2010-08-30 07:31:03 +0000 (Mon, 30 Aug 2010) Log Message: ----------- ANDSWRON-462:ANDSWRDM - Conversion Tools - Error handling when fillrange exceeds actual range of values in binary file Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java Modified: trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-30 06:10:19 UTC (rev 85) +++ trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-30 07:31:03 UTC (rev 86) @@ -601,8 +601,9 @@ String line = dataIn.readLine(); if (line == null) { - System.err.println("Expected block of " + buffer.getSize() + " values but ran out after " + i + "."); - break; + String error = "Expected block of " + buffer.getSize() + " values but ran out after " + i + "."; + System.err.println(error); + throw new IllegalArgumentException(error); } if (isFloat) { @@ -702,7 +703,7 @@ { String error = "Expected block of " + buffer.getSize() + " values but ran out after " + i + "."; System.err.println(error); - throw new EOFException(error); + throw new IllegalArgumentException(error); } i++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rit...@us...> - 2010-08-30 06:10:25
|
Revision: 85 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=85&view=rev Author: ritacsiro Date: 2010-08-30 06:10:19 +0000 (Mon, 30 Aug 2010) Log Message: ----------- ANDSWRON-462:ANDSWRDM - Conversion Tools - Error handling when fillrange exceeds actual range of values in binary file Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java trunk/src/main/java/au/csiro/netcdf/cli/NetCDFTool.java Modified: trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-25 05:56:46 UTC (rev 84) +++ trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-30 06:10:19 UTC (rev 85) @@ -22,6 +22,7 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataInputStream; +import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -662,41 +663,49 @@ int i = 0; while (i < buffer.getSize()) { - - if (isFloat) + try { - buffer.setFloat(i, dataIn.readFloat()); + if (isFloat) + { + buffer.setFloat(i, dataIn.readFloat()); + } + else if (isDouble) + { + buffer.setDouble(i, dataIn.readDouble()); + } + else if (isLong) + { + buffer.setLong(i, dataIn.readLong()); + } + else if (isInt) + { + buffer.setInt(i, dataIn.readInt()); + } + else if (isChar) + { + buffer.setChar(i, dataIn.readChar()); + } + else if (isByte) + { + buffer.setByte(i, dataIn.readByte()); + } + else if (isBoolean) + { + buffer.setBoolean(i, dataIn.readBoolean()); + } + else if (isShort) + { + buffer.setShort(i, dataIn.readShort()); + } } - else if (isDouble) + catch (EOFException e) { - buffer.setDouble(i, dataIn.readDouble()); + String error = "Expected block of " + buffer.getSize() + " values but ran out after " + i + "."; + System.err.println(error); + throw new EOFException(error); } - else if (isLong) - { - buffer.setLong(i, dataIn.readLong()); - } - else if (isInt) - { - buffer.setInt(i, dataIn.readInt()); - } - else if (isChar) - { - buffer.setChar(i, dataIn.readChar()); - } - else if (isByte) - { - buffer.setByte(i, dataIn.readByte()); - } - else if (isBoolean) - { - buffer.setBoolean(i, dataIn.readBoolean()); - } - else if (isShort) - { - buffer.setShort(i, dataIn.readShort()); - } i++; } - + } } Modified: trunk/src/main/java/au/csiro/netcdf/cli/NetCDFTool.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/cli/NetCDFTool.java 2010-08-25 05:56:46 UTC (rev 84) +++ trunk/src/main/java/au/csiro/netcdf/cli/NetCDFTool.java 2010-08-30 06:10:19 UTC (rev 85) @@ -85,10 +85,9 @@ catch (Exception e) { LOG.error(e); - e.printStackTrace(); +// e.printStackTrace(); System.out.println("Error: " + e.getMessage()); System.out.println(command.getUsageString()); -// e.printStackTrace(); System.exit(2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-08-25 05:56:54
|
Revision: 84 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=84&view=rev Author: robertbridle Date: 2010-08-25 05:56:46 +0000 (Wed, 25 Aug 2010) Log Message: ----------- ANDSWRON-289 - Moved from using GnuParser to BasicParser. The BasicParser uses a basic flattening method and doesn't allow options that would seem to be invalid. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/NcCSVExtract.java trunk/src/main/java/au/csiro/netcdf/NcDefineAttributes.java trunk/src/main/java/au/csiro/netcdf/NcDefineDimension.java trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/NcCSVExtract.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcCSVExtract.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/NcCSVExtract.java 2010-08-25 05:56:46 UTC (rev 84) @@ -22,8 +22,8 @@ import java.io.PrintWriter; import java.io.StringWriter; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; @@ -135,7 +135,7 @@ public void execute(String[] args) throws ParseException, IOException { // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); String filename = parsedCommandLine.getOptionValue(INPUT_FILE); int numRecords = Util.fastFileLineCounter(filename); @@ -207,7 +207,7 @@ // check required options are provided try { - parsedCommandLine = new GnuParser().parse(options, commandLine); + parsedCommandLine = new BasicParser().parse(options, commandLine); } catch (ParseException ex) { Modified: trunk/src/main/java/au/csiro/netcdf/NcDefineAttributes.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcDefineAttributes.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/NcDefineAttributes.java 2010-08-25 05:56:46 UTC (rev 84) @@ -29,8 +29,8 @@ import java.util.List; import java.util.Set; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; @@ -151,7 +151,7 @@ public void execute(String[] args) throws ParseException, IOException, IllegalArgumentException { // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(this.options, args); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, args); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine @@ -523,7 +523,7 @@ try { // try parsing the command line, where ParseException can be thrown from - CommandLine parsedCommandLine = new GnuParser().parse(this.options, commandLine); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, commandLine); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine Modified: trunk/src/main/java/au/csiro/netcdf/NcDefineDimension.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcDefineDimension.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/NcDefineDimension.java 2010-08-25 05:56:46 UTC (rev 84) @@ -26,8 +26,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; @@ -106,7 +106,7 @@ public void execute(String[] args) throws ParseException, IOException, IllegalArgumentException { // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(this.options, args); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, args); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine @@ -357,7 +357,7 @@ try { // try parsing the command line, where ParseException can be thrown from - CommandLine parsedCommandLine = new GnuParser().parse(this.options, commandLine); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, commandLine); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine Modified: trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java 2010-08-25 05:56:46 UTC (rev 84) @@ -30,8 +30,8 @@ import java.util.Set; import java.util.regex.PatternSyntaxException; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; @@ -157,7 +157,7 @@ public void execute(String[] args) throws IllegalArgumentException, IOException, ParseException { // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(this.options, args); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, args); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine @@ -506,7 +506,7 @@ try { // try parsing the command line, where ParseException can be thrown from - CommandLine parsedCommandLine = new GnuParser().parse(this.options, commandLine); + CommandLine parsedCommandLine = new BasicParser().parse(this.options, commandLine); // try converting command line parameters to their associated types, where IllegalArgumentException can be // thrown from Modified: trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-25 05:56:46 UTC (rev 84) @@ -32,8 +32,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.OptionBuilder; @@ -117,7 +117,7 @@ public void execute(String[] args) throws ParseException, IOException { // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); // get the command line argument values String outputFilenameArg = (parsedCommandLine.hasOption(OUTPUT_FILE)) ? parsedCommandLine @@ -331,7 +331,7 @@ try { // try parsing the command line, where ParseException can be thrown from - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); // try converting command line parameters to their associated types, where IllegalArgumentException can be // thrown from Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-08-25 05:56:46 UTC (rev 84) @@ -27,8 +27,8 @@ import java.util.Date; import java.util.List; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.MissingOptionException; import org.apache.commons.cli.Option; @@ -161,7 +161,7 @@ options.addOption(outputDirectoryName); // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); String inputDir = parsedCommandLine.getOptionValue(INPUT_DIR); String outputDir = parsedCommandLine.getOptionValue(OUTPUT_DIR); Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-08-25 05:56:46 UTC (rev 84) @@ -45,8 +45,8 @@ import java.util.TreeSet; import java.util.regex.Pattern; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.MissingOptionException; import org.apache.commons.cli.Option; @@ -280,7 +280,7 @@ options.addOption(endLat); // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); INPUT_CSV_DIRECTORY = (parsedCommandLine.hasOption("inputDirectory")) ? parsedCommandLine .getOptionValue("inputDirectory") : ""; Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-08-18 05:16:33 UTC (rev 83) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-08-25 05:56:46 UTC (rev 84) @@ -45,8 +45,8 @@ import java.util.TreeSet; import java.util.regex.Pattern; +import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.MissingOptionException; import org.apache.commons.cli.Option; @@ -308,7 +308,7 @@ options.addOption(endLat); // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser().parse(options, args); + CommandLine parsedCommandLine = new BasicParser().parse(options, args); INPUT_CSV_DIRECTORY = (parsedCommandLine.hasOption("inputDirectory")) ? parsedCommandLine .getOptionValue("inputDirectory") : ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-08-18 05:16:41
|
Revision: 83 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=83&view=rev Author: robertbridle Date: 2010-08-18 05:16:33 +0000 (Wed, 18 Aug 2010) Log Message: ----------- ANDSWRON-290 - Caught NullPointerException when an invalid variable is specified on the command line. We now throw an InvalidArgumentException instead. Modified Paths: -------------- trunk/src/test/java/au/csiro/netcdf/TestNcWriteVariable.java Modified: trunk/src/test/java/au/csiro/netcdf/TestNcWriteVariable.java =================================================================== --- trunk/src/test/java/au/csiro/netcdf/TestNcWriteVariable.java 2010-08-18 05:07:38 UTC (rev 82) +++ trunk/src/test/java/au/csiro/netcdf/TestNcWriteVariable.java 2010-08-18 05:16:33 UTC (rev 83) @@ -477,7 +477,7 @@ fail("testWriteToInvalidVariable should have failed"); } - catch (NullPointerException expected) + catch (IllegalArgumentException expected) { // this is exactly what we were expecting so // let's just ignore it and let the test pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-08-18 05:07:44
|
Revision: 82 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=82&view=rev Author: robertbridle Date: 2010-08-18 05:07:38 +0000 (Wed, 18 Aug 2010) Log Message: ----------- ANDSWRON-290 - Caught NullPointerException when an invalid variable is specified on the command line. We now throw an InvalidArgumentException instead. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java Modified: trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-16 07:40:34 UTC (rev 81) +++ trunk/src/main/java/au/csiro/netcdf/NcWriteVariable.java 2010-08-18 05:07:38 UTC (rev 82) @@ -172,6 +172,14 @@ try { Variable variable = ncfile.findVariable(NetcdfFile.escapeName(variableName)); + + // Check the variable exists + if (variable == null) + { + throw new IllegalArgumentException("The variable: " + variableName + " does not exist in the file: " + + ncfile.getLocation()); + } + List<Range> ranges = variable.getRanges(); // Check the ranges match @@ -224,7 +232,6 @@ { ncfile.close(); } - } /* (non-Javadoc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-08-16 07:40:41
|
Revision: 81 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=81&view=rev Author: robertbridle Date: 2010-08-16 07:40:34 +0000 (Mon, 16 Aug 2010) Log Message: ----------- ANDSWRON-900 - Added "Model-" suffix to the generated netCDF filenames. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-08-11 02:35:21 UTC (rev 80) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-08-16 07:40:34 UTC (rev 81) @@ -1413,7 +1413,7 @@ if (CLIMATE_MODELS.containsKey(directoryModelName)) { String[] modelNameMapping = new String[2]; - modelNameMapping[FILE_NAME_MODEL_NAME] = directoryModelName; + modelNameMapping[FILE_NAME_MODEL_NAME] = MODEL_NAME_PREFIX + directoryModelName; modelNameMapping[IPCC_MODEL_NAME] = CLIMATE_MODELS.get(directoryModelName); return modelNameMapping; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-08-11 02:35:27
|
Revision: 80 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=80&view=rev Author: jdempsey Date: 2010-08-11 02:35:21 +0000 (Wed, 11 Aug 2010) Log Message: ----------- ANDSWRON-703 - Fix up issues reported by checkstyle Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-26 05:51:53 UTC (rev 79) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-08-11 02:35:21 UTC (rev 80) @@ -61,8 +61,7 @@ /** * Constant that defines the logger to be used. */ - private static final Logger LOG = Logger - .getLogger(MdbsyNetCDF2CSVConverter.class.getName()); + private static final Logger LOG = Logger.getLogger(MdbsyNetCDF2CSVConverter.class.getName()); /** * The latitude variable name used in the netCDF files. @@ -129,42 +128,40 @@ * A string containing the date column text to be written out as the first column in all the csv files. */ private static String DATE_COLUMN_TEXT = null; - + /** * The attribute name used to store a variable's type. */ private static final String UNITS = "units"; /** - * @param args + * Command line entry point for the MdbsyNetCDF2CSVConverter class. Gets the input and output directory names + * from the command line and runs a conversion. + * + * @param args The command line arguments + * @throws ParseException If an error occurs when parsing the arguments. + * @throws IOException If the files cannot be read or written to. + * @throws InvalidRangeException if an invalid range is attempted to be read from a netCDf variable */ @SuppressWarnings("static-access") - public static void main(String[] args) throws ParseException, IOException, - InvalidRangeException, java.text.ParseException + public static void main(String[] args) throws ParseException, IOException, InvalidRangeException { Options options = new Options(); try { - Option inputDirectoryName = OptionBuilder - .withArgName("dir") - .hasArg() - .withDescription( - "1. the directory path containing the netCDF files (split by latitude) to be converted into csv.") + Option inputDirectoryName = OptionBuilder.withArgName("dir").hasArg().withDescription( + "1. the directory path containing the netCDF files (split by latitude) to be converted into csv.") .isRequired(true).withLongOpt(INPUT_DIR).create("i"); - Option outputDirectoryName = OptionBuilder - .withArgName("dir") - .hasArg() - .withDescription( - "2: the directory path to place the new csv files.") - .isRequired(true).withLongOpt(OUTPUT_DIR).create("o"); + Option outputDirectoryName = OptionBuilder.withArgName("dir").hasArg().withDescription( + "2: the directory path to place the new csv files.").isRequired(true).withLongOpt(OUTPUT_DIR) + .create("o"); options.addOption(inputDirectoryName); options.addOption(outputDirectoryName); // parse the command line arguments - CommandLine parsedCommandLine = new GnuParser() - .parse(options, args); + CommandLine parsedCommandLine = new GnuParser().parse(options, args); String inputDir = parsedCommandLine.getOptionValue(INPUT_DIR); String outputDir = parsedCommandLine.getOptionValue(OUTPUT_DIR); @@ -187,8 +184,8 @@ StringWriter sw = new StringWriter(); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new CommandLineOptionsComparator()); - formatter.printHelp(new PrintWriter(sw), 80, "-", header, options, - 0, 1, footer); + final int lineWidth = 80; + formatter.printHelp(new PrintWriter(sw), lineWidth, "-", header, options, 0, 1, footer); System.out.println(sw.toString()); } } @@ -202,10 +199,10 @@ * the directory in which the csv file will be placed. * @throws InvalidRangeException * thrown if an invalid range is attempted to be read from a netCDf variable. - * @throws IOException + * @throws IOException + * If the files cannot be read or written to. */ - public void execute(String inputDir, String outputDir) throws IOException, - InvalidRangeException + public void execute(String inputDir, String outputDir) throws IOException, InvalidRangeException { // perform an initial conversion from netCDF to csv, the csv files will look like this: // Date, 1985-01-01, 1895-01-02, 1985-01-03, ... @@ -244,21 +241,21 @@ * thrown if an invalid range is attempted to be read from a netCDf variable. * @throws IOException */ - private void writeCSVFiles(String inputDir, String outputDir) - throws IOException, InvalidRangeException + private void writeCSVFiles(String inputDir, String outputDir) throws IOException, InvalidRangeException { File dir = new File(inputDir); File[] files = dir.listFiles(); - if(files == null) + if (files == null) { System.out.println("The input directory does not exist: " + inputDir); LOG.error("The input directory does not exist: " + inputDir); return; } - + for (int fileIndex = 0; fileIndex < files.length; fileIndex++) { - if (files[fileIndex].isFile() && NETCDF_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) + if (files[fileIndex].isFile() + && NETCDF_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) { NetcdfFile nc = null; try @@ -268,43 +265,35 @@ Array latitudes = getLatitudeValues(nc); Array longitudes = getLongitudeValues(nc); - LOG.info("latitude coordinate variable size: " - + latitudes.getSize()); - LOG.info("longitude coordinate variable size: " - + longitudes.getSize()); + LOG.info("latitude coordinate variable size: " + latitudes.getSize()); + LOG.info("longitude coordinate variable size: " + longitudes.getSize()); for (int latIndex = 0; latIndex < latitudes.getSize(); latIndex++) { - for (int longIndex = 0; longIndex < longitudes - .getSize(); longIndex++) + for (int longIndex = 0; longIndex < longitudes.getSize(); longIndex++) { - String fileName = createFileNameBasedOnLatLong(nc, - latIndex, longIndex); - String filePath = outputDir - + System.getProperty("file.separator") - + fileName + ".csv"; - + String fileName = createFileNameBasedOnLatLong(nc, latIndex, longIndex); + String filePath = outputDir + System.getProperty("file.separator") + fileName + ".csv"; + LOG.info("\tWorking on file: " + filePath); // if the csv file already exists, then append the next variable. if (Util.fileExists(filePath)) { File file = new File(filePath); - PrintWriter out = new PrintWriter( - new BufferedWriter(new FileWriter(file, - true /* append mode */))); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true /* + * append + * mode + */))); List<String> variablesAlreadyWrittenOut = getVariablesAlreadyWrittenOut(file); List<String> variablesThatCanBeWrittenOut = getVariablesThatCanBeWrittenOut(nc); - variablesThatCanBeWrittenOut - .removeAll(variablesAlreadyWrittenOut); - + variablesThatCanBeWrittenOut.removeAll(variablesAlreadyWrittenOut); + try { - writeOutVariable(nc, out, - variablesThatCanBeWrittenOut, - latIndex, longIndex); + writeOutVariable(nc, out, variablesThatCanBeWrittenOut, latIndex, longIndex); } finally { @@ -315,19 +304,17 @@ else // if the csv file does not exist, create a new csv file and write all available variables. { - PrintWriter out = new PrintWriter(new BufferedWriter( - new FileWriter(new File(filePath), - false /* append mode */))); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(new File(filePath), + false /* append mode */))); List<String> variablesThatCanBeWrittenOut = getVariablesThatCanBeWrittenOut(nc); try { - out.println(writeOutDateColumn(nc)); // note: we only write out the date column when a new csv file is created. - - writeOutVariable(nc, out, - variablesThatCanBeWrittenOut, - latIndex, longIndex); + out.println(writeOutDateColumn(nc)); // note: we only write out the date column when + // a new csv file is created. + + writeOutVariable(nc, out, variablesThatCanBeWrittenOut, latIndex, longIndex); } finally { @@ -359,16 +346,13 @@ * @throws IOException * */ - private void writeOutVariable(NetcdfFile nc, PrintWriter out, - List<String> variablesThatCanBeWrittenOut, int latIndex, - int longIndex) throws IOException, InvalidRangeException + private void writeOutVariable(NetcdfFile nc, PrintWriter out, List<String> variablesThatCanBeWrittenOut, + int latIndex, int longIndex) throws IOException, InvalidRangeException { for (String variableName : variablesThatCanBeWrittenOut) { - Array subsection = getVariableAcrossTime(nc, variableName, - latIndex, longIndex); - out.println(variableName + "," - + subsection.toString().replaceAll(" ", ",")); + Array subsection = getVariableAcrossTime(nc, variableName, latIndex, longIndex); + out.println(variableName + "," + subsection.toString().replaceAll(" ", ",")); } } @@ -383,7 +367,7 @@ { File dir = new File(outputDir); File[] files = dir.listFiles(); - if(files == null) + if (files == null) { System.out.println("The output directory does not exist: " + outputDir); LOG.error("The output directory does not exist: " + outputDir); @@ -392,14 +376,16 @@ for (int fileIndex = 0; fileIndex < files.length; fileIndex++) { - if (files[fileIndex].isFile() && CSV_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) + if (files[fileIndex].isFile() + && CSV_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) { String[][] matrix = readLookupFile(files[fileIndex]); // write over-the-top of the csv file. - PrintWriter out = new PrintWriter( - new BufferedWriter(new FileWriter(files[fileIndex], - false /* append mode */))); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(files[fileIndex], false /* + * append + * mode + */))); // transpose String[][] matrix and write back out to csv String[][] transposed = transpose(matrix); @@ -411,7 +397,7 @@ for (int col = 0; col < transposed[0].length; col++) { out.print(transposed[row][col]); - if(col < (transposed[0].length-1)) + if (col < (transposed[0].length - 1)) { out.print(", "); } @@ -460,8 +446,7 @@ * @return the name of the variables that have already be written out to a csv file. * @throws IOException */ - private List<String> getVariablesAlreadyWrittenOut(File file) - throws IOException + private List<String> getVariablesAlreadyWrittenOut(File file) throws IOException { List<String> variablesAlreadyWrittenOut = new ArrayList<String>(); @@ -487,15 +472,11 @@ * @throws InvalidRangeException * @throws IOException */ - private String createFileNameBasedOnLatLong(NetcdfFile nc, int latIndex, - int longIndex) throws IOException, InvalidRangeException + private String createFileNameBasedOnLatLong(NetcdfFile nc, int latIndex, int longIndex) throws IOException, + InvalidRangeException { - return "region_" - + nc.readSection("lat(" + latIndex + ":" + latIndex + ")") - .toString().trim() - + "_" - + nc.readSection("long(" + longIndex + ":" + longIndex + ")") - .toString().trim(); + return "region_" + nc.readSection("lat(" + latIndex + ":" + latIndex + ")").toString().trim() + "_" + + nc.readSection("long(" + longIndex + ":" + longIndex + ")").toString().trim(); } /** @@ -510,7 +491,7 @@ { RandomAccessFile raf = new RandomAccessFile(file, "r"); List<String[]> lineList = new ArrayList<String[]>(); - + try { String line = raf.readLine(); @@ -533,11 +514,12 @@ /** * Transpose a matrix, e.g. [a][b] -> [b][a] * - * @param values a String[][] matrix. + * @param values + * a String[][] matrix. */ private String[][] transpose(String[][] values) { - if(values.length == 0) + if (values.length == 0) { return new String[0][0]; } @@ -568,21 +550,19 @@ * @throws IOException * @throws InvalidRangeException */ - private Array getVariableAcrossTime(NetcdfFile nc, String variableName, - int latIndex, int longIndex) throws IOException, - InvalidRangeException + private Array getVariableAcrossTime(NetcdfFile nc, String variableName, int latIndex, int longIndex) + throws IOException, InvalidRangeException { try { - return nc.readSection(variableName + "(" + latIndex + ":" - + latIndex + "," + longIndex + ":" + longIndex + ",:)"); + return nc.readSection(variableName + "(" + latIndex + ":" + latIndex + "," + longIndex + ":" + longIndex + + ",:)"); } catch (InvalidRangeException ire) { ire.printStackTrace(); - LOG.error("Could not read section: " + variableName + "(" - + latIndex + ":" + latIndex + "," + longIndex + ":" - + longIndex + ",:)", ire); + LOG.error("Could not read section: " + variableName + "(" + latIndex + ":" + latIndex + "," + longIndex + + ":" + longIndex + ",:)", ire); } return null; } @@ -596,25 +576,21 @@ * @throws IOException * @throws IllegalArgumentException */ - private Array getLongitudeValues(NetcdfFile nc) throws IOException, - IllegalArgumentException + private Array getLongitudeValues(NetcdfFile nc) throws IOException, IllegalArgumentException { List<Variable> variables = nc.getVariables(); - if(variables != null) + if (variables != null) { for (Variable v : variables) { - if (v.isCoordinateVariable() - && LONGITUDE_VARIABLE_NAME.equals(v.getName())) + if (v.isCoordinateVariable() && LONGITUDE_VARIABLE_NAME.equals(v.getName())) { return v.read(); } } } - LOG.error("Could not find coordinate variable: " - + LONGITUDE_VARIABLE_NAME); - throw new IllegalStateException("Could not find coordinate variable: " - + LONGITUDE_VARIABLE_NAME); + LOG.error("Could not find coordinate variable: " + LONGITUDE_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + LONGITUDE_VARIABLE_NAME); } /** @@ -626,25 +602,21 @@ * @throws IOException * @throws IllegalArgumentException */ - private Array getLatitudeValues(NetcdfFile nc) throws IOException, - IllegalArgumentException + private Array getLatitudeValues(NetcdfFile nc) throws IOException, IllegalArgumentException { List<Variable> variables = nc.getVariables(); - if(variables != null) + if (variables != null) { for (Variable v : variables) { - if (v.isCoordinateVariable() - && LATITUDE_VARIABLE_NAME.equals(v.getName())) + if (v.isCoordinateVariable() && LATITUDE_VARIABLE_NAME.equals(v.getName())) { return v.read(); } } } - LOG.error("Could not find coordinate variable: " - + LATITUDE_VARIABLE_NAME); - throw new IllegalStateException("Could not find coordinate variable: " - + LATITUDE_VARIABLE_NAME); + LOG.error("Could not find coordinate variable: " + LATITUDE_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + LATITUDE_VARIABLE_NAME); } /** @@ -655,24 +627,21 @@ * @return the time variable. * @throws IllegalArgumentException */ - private static Variable getTimeVariable(NetcdfFile nc) - throws IllegalArgumentException + private static Variable getTimeVariable(NetcdfFile nc) throws IllegalArgumentException { List<Variable> variables = nc.getVariables(); - if(variables != null) + if (variables != null) { for (Variable v : variables) { - if (v.isCoordinateVariable() - && TIME_VARIABLE_NAME.equals(v.getName())) + if (v.isCoordinateVariable() && TIME_VARIABLE_NAME.equals(v.getName())) { return v; } } } LOG.error("Could not find coordinate variable: " + TIME_VARIABLE_NAME); - throw new IllegalStateException("Could not find coordinate variable: " - + TIME_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + TIME_VARIABLE_NAME); } /** @@ -694,21 +663,23 @@ try { Variable time = getTimeVariable(nc); - + String timeUnits = getVariablesUnits(time); - String epocString = timeUnits.substring(timeUnits.indexOf("days since") + 11); // we expect the time value to be in units of: "days since yyyy-mm-dd h:m:s" - + String epocString = timeUnits.substring(timeUnits.indexOf("days since") + 11); // we expect the time + // value to be in units + // of: + // "days since yyyy-mm-dd h:m:s" + epocDate = dateFormatter.dateOnlyFormat(epocString); strBuf.append("Date,"); long timeVariableSize = time.getSize(); for (int i = 0; i < timeVariableSize; i++) { - strBuf.append(dateFormatter.toDateOnlyString(new Date(epocDate - .getTime() - + (i * MILLISECONDS_IN_A_DAY))).trim()); - - if(i < (timeVariableSize-1)) + strBuf.append(dateFormatter.toDateOnlyString( + new Date(epocDate.getTime() + (i * MILLISECONDS_IN_A_DAY))).trim()); + + if (i < (timeVariableSize - 1)) { strBuf.append(","); } @@ -735,11 +706,11 @@ private static String getVariablesUnits(Variable variable) { List<Attribute> attributes = variable.getAttributes(); - if(attributes != null) + if (attributes != null) { - for(Attribute attribute : attributes) + for (Attribute attribute : attributes) { - if(UNITS.equals(attribute.getName())) + if (UNITS.equals(attribute.getName())) { return attribute.getStringValue(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-26 05:52:00
|
Revision: 79 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=79&view=rev Author: jdempsey Date: 2010-07-26 05:51:53 +0000 (Mon, 26 Jul 2010) Log Message: ----------- ANDSWRON-791 - By latitude files do not have out of region areas set to fill values Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-24 06:23:13 UTC (rev 78) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-26 05:51:53 UTC (rev 79) @@ -383,6 +383,8 @@ this.fillCoordinateVariables(filenames[i], sortedLongitudes, sortedLatitudes, dates, blockLatRange, blockLongRange, TIME_RANGE); this.fillSpatialVariables(filenames[i], triples); + this.fillDataForLatitude(filenames[i], i, sortedLongitudes, sortedLatitudes, dates, Arrays.asList(LAT, + LONG, TIME)); } // for each cellId csv file we read, we will have available the values for both rainFall and PVET, therefore @@ -847,6 +849,39 @@ } /** + * Populate the data variable with fill values. Used to ensure cells within + * the rectangular bounds but for which we have no data are set to the fill value. + * + * @param varIndex The variable being filled + * @param sortedLongitudes The longitudes to fill. + * @param sortedLatitudes The latitudes to fill + * @param dates The dates to fill + * @param dimensionOrdering The order of the dimensions in the files + * @throws IOException If the data cannot be written + */ + private void fillDataForLatitude(String filename, int varIndex, Set<String> sortedLongitudes, Set<String> sortedLatitudes, + List<String> dates, List<String> dimensionOrdering) throws IOException + { + StringBuffer fillBlock = new StringBuffer(); + String fillLine = variableFillValues[varIndex] + "\n"; + for (int i = 0; i < dates.size(); i++) + { + fillBlock.append(fillLine); + } + + NcWriteVariable writeVarCmd = new NcWriteVariable(); + for (String latitude : sortedLatitudes) + { + for (String longitude : sortedLongitudes) + { + String fillRange = this.constructFillRange(dimensionOrdering, latitude, longitude, dates.size()); + writeVarCmd.execute(new File(filename), variableNames[varIndex], fillRange, + new ByteArrayInputStream(fillBlock.toString().getBytes(ENCODING)), false); + } + } + } + + /** * Fills the variables with data for a particular latitude. * * @param variableFileNames The filenames for this latitude for each of the variables Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-24 06:23:13 UTC (rev 78) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-26 05:51:53 UTC (rev 79) @@ -410,6 +410,8 @@ this.fillCoordinateVariables(filenames[i], sortedLongitudes, sortedLatitudes, dates, blockLatRange, blockLongRange, TIME_RANGE); this.fillSpatialVariables(filenames[i], triples); + this.fillDataForLatitude(filenames[i], i, sortedLongitudes, sortedLatitudes, dates, Arrays.asList(LAT, + LONG, TIME)); } // for each cellId csv file we read, we will have available the values for both rainFall and PVET, therefore @@ -868,6 +870,39 @@ } /** + * Populate the data variable with fill values. Used to ensure cells within + * the rectangular bounds but for which we have no data are set to the fill value. + * + * @param varIndex The variable being filled + * @param sortedLongitudes The longitudes to fill. + * @param sortedLatitudes The latitudes to fill + * @param dates The dates to fill + * @param dimensionOrdering The order of the dimensions in the files + * @throws IOException If the data cannot be written + */ + private void fillDataForLatitude(String filename, int varIndex, Set<String> sortedLongitudes, Set<String> sortedLatitudes, + List<String> dates, List<String> dimensionOrdering) throws IOException + { + StringBuffer fillBlock = new StringBuffer(); + String fillLine = variableFillValues[varIndex] + "\n"; + for (int i = 0; i < dates.size(); i++) + { + fillBlock.append(fillLine); + } + + NcWriteVariable writeVarCmd = new NcWriteVariable(); + for (String latitude : sortedLatitudes) + { + for (String longitude : sortedLongitudes) + { + String fillRange = this.constructFillRange(dimensionOrdering, latitude, longitude, dates.size()); + writeVarCmd.execute(new File(filename), variableNames[varIndex], fillRange, + new ByteArrayInputStream(fillBlock.toString().getBytes(ENCODING)), false); + } + } + } + + /** * Fills the variables with data for a particular latitude. * * @param variableFileNames The filenames for this latitude for each of the variables This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-16 06:20:50
|
Revision: 77 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=77&view=rev Author: jdempsey Date: 2010-07-16 06:20:44 +0000 (Fri, 16 Jul 2010) Log Message: ----------- ANDSWRON-665 - Place IPCC standard model names as metadata in the netCDF files. - Fix typo Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-16 02:58:47 UTC (rev 76) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-16 06:20:44 UTC (rev 77) @@ -1366,10 +1366,11 @@ private static String[] getModelMapping(String directoryModelName) { // strip "Model-" prefix that may be used. - int beginIndex = directoryModelName.indexOf("Model-"); + final String MODEL_NAME_PREFIX = "Model-"; + int beginIndex = directoryModelName.indexOf(MODEL_NAME_PREFIX); if (beginIndex != -1) { - directoryModelName = directoryModelName.substring(beginIndex + ("Model-1".length() - 1)); + directoryModelName = directoryModelName.substring(beginIndex + (MODEL_NAME_PREFIX.length())); } // determine the mapping between the climate model used to name the file and the IPCC standard climate This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-16 02:58:55
|
Revision: 76 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=76&view=rev Author: jdempsey Date: 2010-07-16 02:58:47 +0000 (Fri, 16 Jul 2010) Log Message: ----------- ANDSWRON-773 - Use SF user names in SF projects - Correct capitalisation of Vivek's name. Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-07-15 06:22:41 UTC (rev 75) +++ trunk/pom.xml 2010-07-16 02:58:47 UTC (rev 76) @@ -552,7 +552,7 @@ </developer> <developer> <id>vivekpulukuri</id> - <name>vivek pulukuri</name> + <name>Vivek Pulukuri</name> <email>viv...@us...</email> <organization>CSIRO</organization> <timezone>+11</timezone> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-15 06:22:48
|
Revision: 75 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=75&view=rev Author: robertbridle Date: 2010-07-15 06:22:41 +0000 (Thu, 15 Jul 2010) Log Message: ----------- ANDSWRON-773 - The pom.xml contains the developers CSIRO NEXUS Ids and email addresses. We should use the developers SourceForge Ids and email adresses. Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-07-13 23:12:49 UTC (rev 74) +++ trunk/pom.xml 2010-07-15 06:22:41 UTC (rev 75) @@ -523,32 +523,39 @@ </reporting> <developers> <developer> - <id>dem040</id> + <id>jdempsey</id> <name>James Dempsey</name> - <email>Jam...@cs...</email> + <email>jde...@us...</email> <organization>CSIRO</organization> <timezone>+11</timezone> </developer> <developer> - <id>che256</id> + <id>ritacsiro</id> <name>Rita Chen</name> - <email>Rit...@cs...</email> + <email>rit...@us...</email> <organization>CSIRO</organization> <timezone>+11</timezone> </developer> <developer> - <id>pie046</id> + <id>mpienaar</id> <name>Martin Pienaar</name> - <email>Mar...@cs...</email> + <email>mpi...@us...</email> <organization>CSIRO</organization> <timezone>+10</timezone> </developer> <developer> - <id>bri26e</id> + <id>robertbridle</id> <name>Robert Bridle</name> - <email>Rob...@cs...</email> + <email>rob...@us...</email> <organization>CSIRO</organization> <timezone>+11</timezone> </developer> + <developer> + <id>vivekpulukuri</id> + <name>vivek pulukuri</name> + <email>viv...@us...</email> + <organization>CSIRO</organization> + <timezone>+11</timezone> + </developer> </developers> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-13 23:12:56
|
Revision: 74 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=74&view=rev Author: robertbridle Date: 2010-07-13 23:12:49 +0000 (Tue, 13 Jul 2010) Log Message: ----------- ANDSWRON-665 - Place IPCC standard model names as metadata in the netCDF files. Modified Paths: -------------- trunk/launch/ScenarioCConverter-AllData.launch trunk/launch/ScenarioCConverter.launch trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/launch/ScenarioCConverter-AllData.launch =================================================================== --- trunk/launch/ScenarioCConverter-AllData.launch 2010-07-13 06:36:28 UTC (rev 73) +++ trunk/launch/ScenarioCConverter-AllData.launch 2010-07-13 23:12:49 UTC (rev 74) @@ -8,7 +8,7 @@ </listAttribute> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="au.csiro.netcdf.wron.MdbsyScenarioCConverter"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--lookupFile "C:\dev\scenC\unq_cells_dem9s2rc.csv_corLat_regions.csv" --inputDirectory "U:\_ScenarioC_RRModellingData\cccma_t47\High_Global_Warming\\" --outputDirectory "C:\dev\scenC\output\\" --metadataFile "C:\dev\scenC\attributes.txt" --scenario "Scenario-C" --model "Model-ccma_t47" --case "Case-High" -r 2 --decade --latitude"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--lookupFile "C:\dev\scenC\unq_cells_dem9s2rc.csv_corLat_regions.csv" --inputDirectory "U:\_ScenarioC_RRModellingData\cccma_t47\High_Global_Warming\\" --outputDirectory "C:\dev\scenC\output\\" --metadataFile "C:\dev\scenC\attributes.txt" --scenario "Scenario-C" --model "Model-cccma_t47" --case "Case-High" -r 2 --decade --latitude"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="netcdf-tools"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx1500m -Xms800m"/> Modified: trunk/launch/ScenarioCConverter.launch =================================================================== --- trunk/launch/ScenarioCConverter.launch 2010-07-13 06:36:28 UTC (rev 73) +++ trunk/launch/ScenarioCConverter.launch 2010-07-13 23:12:49 UTC (rev 74) @@ -8,7 +8,7 @@ </listAttribute> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="au.csiro.netcdf.wron.MdbsyScenarioCConverter"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--lookupFile "C:\dev\scenC\unq_cells_dem9s2rc.csv_corLat_regions.csv" --inputDirectory "U:\_ScenarioC_RRModellingData\cccma_t47\High_Global_Warming\\" --outputDirectory "C:\dev\scenC\output\\" --metadataFile "C:\dev\scenC\attributes.txt" --scenario "Scenario-C" --model "Model-ccma_t47" --case "Case-High" -r 250 --decade --latitude"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--lookupFile "C:\dev\scenC\unq_cells_dem9s2rc.csv_corLat_regions.csv" --inputDirectory "U:\_ScenarioC_RRModellingData\cccma_t47\High_Global_Warming\\" --outputDirectory "C:\dev\scenC\output\\" --metadataFile "C:\dev\scenC\attributes.txt" --scenario "Scenario-C" --model "Model-cccma_t47" --case "Case-High" -r 250 --latitude"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="netcdf-tools"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx1500m -Xms800m"/> Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-13 06:36:28 UTC (rev 73) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-13 23:12:49 UTC (rev 74) @@ -82,7 +82,7 @@ // netCDF file naming components private static String COLLECTION = "Collection-MDBSY_Climate"; private static String SCENARIO = ""; - private static String MODEL = ""; + private static String[] MODEL_NAMES; private static String CASE = ""; /** @@ -94,7 +94,7 @@ * The file containing the metadata attributes (if any). */ private static String METADATA_FILE = ""; - + /** * The directory containing the Scenario C csv data files. */ @@ -114,6 +114,34 @@ * Encoding used to fill variables. */ private static final String ENCODING = "UTF-8"; + + /** + * The 15 climate models used in the MDBSY project. + */ + private static Map<String, String> CLIMATE_MODELS = new HashMap<String, String>(); + static + { + CLIMATE_MODELS.put("cccma_t47", "CCCMA T47"); + CLIMATE_MODELS.put("cccma_t63", "CCCMA T63"); + CLIMATE_MODELS.put("cnrm", "CNRM"); + CLIMATE_MODELS.put("csiro", "CSIRO-MK3.0"); + CLIMATE_MODELS.put("gfdl", "GFDL 2.0"); + CLIMATE_MODELS.put("giss_aom", "GISS-AOM"); + CLIMATE_MODELS.put("iap", "IAP"); + CLIMATE_MODELS.put("inmcm", "INMCM"); + CLIMATE_MODELS.put("ipsl", "IPSL"); + CLIMATE_MODELS.put("miroc", "MIROC-M"); + CLIMATE_MODELS.put("miub", "MIUB"); + CLIMATE_MODELS.put("mpi", "MPI-ECHAM5"); + CLIMATE_MODELS.put("mri", "MRI"); + CLIMATE_MODELS.put("ncar_ccsm", "NCAR-CCSM"); + CLIMATE_MODELS.put("ncar_pcm", "NCAR-PCM1"); + } + /** + * Index of model names in {@link MdbsyScenarioCConverter#MODEL_NAMES}. + */ + private static final int FILE_NAME_MODEL_NAME = 0; + private static final int IPCC_MODEL_NAME = 1; // Variables private static final String[] variableNames = new String[] { "rainfall", "APET" }; @@ -291,7 +319,7 @@ SCENARIO = (parsedCommandLine.hasOption("scenario")) ? parsedCommandLine.getOptionValue("scenario") : ""; METADATA_FILE = (parsedCommandLine.hasOption("metadataFile")) ? parsedCommandLine .getOptionValue("metadataFile") : ""; - MODEL = (parsedCommandLine.hasOption("model")) ? parsedCommandLine.getOptionValue("model") : ""; + MODEL_NAMES = getModelMapping((parsedCommandLine.hasOption("model")) ? parsedCommandLine.getOptionValue("model") : ""); CASE = (parsedCommandLine.hasOption("case")) ? parsedCommandLine.getOptionValue("case") : ""; ROW_CHUNK_SIZE = (parsedCommandLine.hasOption("rows")) ? Integer.valueOf(parsedCommandLine .getOptionValue("rows")) : ROW_CHUNK_SIZE; @@ -526,9 +554,11 @@ // Add attributes DateFormat utcDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); Attribute converter = new Attribute("History", utcDateTime.format(new Date()) + " Converted to netCDF by " - + "$Id: MdbsyScenarioCConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); + + "$Id: MdbsyScenarioCConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); + Attribute ipccClimateModel = new Attribute("IPCC Climate Model Name", MODEL_NAMES[IPCC_MODEL_NAME]); List<Attribute> globalAttrs = new ArrayList<Attribute>(); globalAttrs.add(converter); + globalAttrs.add(ipccClimateModel); if (METADATA_FILE.length() > 0) { globalAttrs.addAll(NetCDFUtils.readAttributesFromStream(new FileInputStream(METADATA_FILE))); @@ -1259,9 +1289,9 @@ private String generateLatitudeFilename(String latitudeDegree, String variable) { String filename = OUTPUT_NETCDF_DIRECTORY + COLLECTION + "." + SCENARIO + "."; - if (MODEL.length() > 0) + if (MODEL_NAMES[FILE_NAME_MODEL_NAME].length() > 0) { - filename += MODEL + "."; + filename += MODEL_NAMES[FILE_NAME_MODEL_NAME] + "."; } if (CASE.length() > 0) { @@ -1283,9 +1313,9 @@ private String generateDecadeFilename(String decadeStr, String variable) { String filename = OUTPUT_NETCDF_DIRECTORY + COLLECTION + "." + SCENARIO + "."; - if (MODEL.length() > 0) + if (MODEL_NAMES[FILE_NAME_MODEL_NAME].length() > 0) { - filename += MODEL + "."; + filename += MODEL_NAMES[FILE_NAME_MODEL_NAME] + "."; } if (CASE.length() > 0) { @@ -1324,5 +1354,34 @@ { CELLID, LONGITUDE, LATITUDE, ELEVATION, CATCHMENTID, REPORTINGREGIONID } + + /** + * Maps a climate model name used for file naming to an IPCC standard climate model name. + * + * @param directoryModelName + * a climate model name used for file naming. + * @return a String[] which forms a mapping from a climate model name used for file naming to an IPCC standard + * climate model name. + */ + private static String[] getModelMapping(String directoryModelName) + { + // strip "Model-" prefix that may be used. + int beginIndex = directoryModelName.indexOf("Model-"); + if (beginIndex != -1) + { + directoryModelName = directoryModelName.substring(beginIndex + ("Model-1".length() - 1)); + } + // determine the mapping between the climate model used to name the file and the IPCC standard climate + // model name stored as metadata. + if (CLIMATE_MODELS.containsKey(directoryModelName)) + { + String[] modelNameMapping = new String[2]; + modelNameMapping[FILE_NAME_MODEL_NAME] = directoryModelName; + modelNameMapping[IPCC_MODEL_NAME] = CLIMATE_MODELS.get(directoryModelName); + return modelNameMapping; + } + throw new IllegalArgumentException("Unknown model: " + directoryModelName + ". Valid models are: " + + CLIMATE_MODELS.keySet()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-13 06:36:34
|
Revision: 73 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=73&view=rev Author: robertbridle Date: 2010-07-13 06:36:28 +0000 (Tue, 13 Jul 2010) Log Message: ----------- ANDSWRON-642 - Setup contribution message for project. Modified Paths: -------------- trunk/src/site/apt/index.apt Modified: trunk/src/site/apt/index.apt =================================================================== --- trunk/src/site/apt/index.apt 2010-07-13 00:20:21 UTC (rev 72) +++ trunk/src/site/apt/index.apt 2010-07-13 06:36:28 UTC (rev 73) @@ -45,6 +45,10 @@ * <<netcdf-tools-??-javadoc.jar>> - The project's javadoc. +Contribution + + For instructions on how to contribute to this project, consult the Trac wiki page: {{{https://sourceforge.net/apps/trac/netcdftools/wiki/ContributionGuide}Contribution Guide}}. + Background The project was originally created to provide a set of tools for converting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-13 00:20:28
|
Revision: 72 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=72&view=rev Author: robertbridle Date: 2010-07-13 00:20:21 +0000 (Tue, 13 Jul 2010) Log Message: ----------- ANDSWRON-703 - Review fix - Modified code to obtain EPOC dateTime from netCDF file instead of from a hard coded constant - UPDATED UNIT TEST. Modified Paths: -------------- trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java Modified: trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java 2010-07-13 00:09:49 UTC (rev 71) +++ trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java 2010-07-13 00:20:21 UTC (rev 72) @@ -1,3 +1,19 @@ +/** + * Copyright 2010, CSIRO Australia. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package au.csiro.netcdf.wron; import java.io.ByteArrayInputStream; @@ -3,18 +19,14 @@ import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import au.csiro.netcdf.NcWriteVariable; -import au.csiro.netcdf.util.Util; - +import junit.framework.TestCase; import ucar.ma2.DataType; +import ucar.nc2.Attribute; import ucar.nc2.Dimension; -import ucar.nc2.NCdumpW; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFileWriteable; import ucar.nc2.Variable; -import junit.framework.TestCase; +import au.csiro.netcdf.NcWriteVariable; +import au.csiro.netcdf.util.Util; /** @@ -192,7 +204,8 @@ // define coordinate variables. ncFile.addVariable(VAR_LATITUDE, DataType.FLOAT, DIM_LATITUDE); ncFile.addVariable(VAR_LONGITUDE, DataType.FLOAT, DIM_LONGITUDE); - ncFile.addVariable(VAR_TIME, DataType.INT, DIM_TIME); + Variable timeVariable = ncFile.addVariable(VAR_TIME, DataType.INT, DIM_TIME); + ncFile.addVariableAttribute(timeVariable.getName(), new Attribute("units", "days since 1895-01-01 0:0:0")); // variable is defined over three coordinates dimensions. ncFile.addVariable(VAR_APET, DataType.FLOAT, DIM_LATITUDE + " " + DIM_LONGITUDE + " " + DIM_TIME); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-13 00:09:56
|
Revision: 71 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=71&view=rev Author: robertbridle Date: 2010-07-13 00:09:49 +0000 (Tue, 13 Jul 2010) Log Message: ----------- ANDSWRON-703 - Review fix - Modified code to obtain EPOC dateTime from netCDF file instead of from a hard coded constant. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-08 09:35:45 UTC (rev 70) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-13 00:09:49 UTC (rev 71) @@ -1,3 +1,19 @@ +/** + * Copyright 2010, CSIRO Australia. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package au.csiro.netcdf.wron; import java.io.BufferedWriter; @@ -23,6 +39,7 @@ import ucar.ma2.Array; import ucar.ma2.InvalidRangeException; +import ucar.nc2.Attribute; import ucar.nc2.NetcdfFile; import ucar.nc2.Variable; import ucar.nc2.units.DateFormatter; @@ -41,8 +58,6 @@ */ public class MdbsyNetCDF2CSVConverter { - private static final String EPOC = "1895-01-01"; - /** * Constant that defines the logger to be used. */ @@ -114,6 +129,11 @@ * A string containing the date column text to be written out as the first column in all the csv files. */ private static String DATE_COLUMN_TEXT = null; + + /** + * The attribute name used to store a variable's type. + */ + private static final String UNITS = "units"; /** * @param args @@ -187,18 +207,26 @@ public void execute(String inputDir, String outputDir) throws IOException, InvalidRangeException { - // perform an initial conversion from netCDF to csv, the csv file will look like this: + // perform an initial conversion from netCDF to csv, the csv files will look like this: // Date, 1985-01-01, 1895-01-02, 1985-01-03, ... // APET, 0.1, 0.3, 0.0, .... // rainfall,0.0, 0.4, 0.1, ... + System.out.println("Starting intial convert of NetCDF 2 CSV."); + LOG.info("Starting intial convert of NetCDF 2 CSV."); writeCSVFiles(inputDir, outputDir); + System.out.println("Finished intial convert of NetCDF 2 CSV."); + LOG.info("Finished intial convert of NetCDF 2 CSV."); - // transpose the csv files so the will look like this: + // transpose the csv files so they will look like this: // Date, APET, rainfall // 1895-01-01, 0.1, 0.0 // 1895-01-02, 0.3, 0.4 // 1895-01-03, 0.0, 0.1 + System.out.println("Started transposition of CSV."); + LOG.info("Started transposition of CSV."); transposeCSVFiles(outputDir); + System.out.println("Finished transposition of CSV."); + LOG.info("Finished transposition of CSV."); } /** @@ -255,6 +283,8 @@ String filePath = outputDir + System.getProperty("file.separator") + fileName + ".csv"; + + LOG.info("\tWorking on file: " + filePath); // if the csv file already exists, then append the next variable. if (Util.fileExists(filePath)) @@ -293,7 +323,7 @@ try { - out.println(writeOutDateColumn(nc)); + out.println(writeOutDateColumn(nc)); // note: we only write out the date column when a new csv file is created. writeOutVariable(nc, out, variablesThatCanBeWrittenOut, @@ -569,12 +599,16 @@ private Array getLongitudeValues(NetcdfFile nc) throws IOException, IllegalArgumentException { - for (Variable v : nc.getVariables()) + List<Variable> variables = nc.getVariables(); + if(variables != null) { - if (v.isCoordinateVariable() - && LONGITUDE_VARIABLE_NAME.equals(v.getName())) + for (Variable v : variables) { - return v.read(); + if (v.isCoordinateVariable() + && LONGITUDE_VARIABLE_NAME.equals(v.getName())) + { + return v.read(); + } } } LOG.error("Could not find coordinate variable: " @@ -595,12 +629,16 @@ private Array getLatitudeValues(NetcdfFile nc) throws IOException, IllegalArgumentException { - for (Variable v : nc.getVariables()) + List<Variable> variables = nc.getVariables(); + if(variables != null) { - if (v.isCoordinateVariable() - && LATITUDE_VARIABLE_NAME.equals(v.getName())) + for (Variable v : variables) { - return v.read(); + if (v.isCoordinateVariable() + && LATITUDE_VARIABLE_NAME.equals(v.getName())) + { + return v.read(); + } } } LOG.error("Could not find coordinate variable: " @@ -620,12 +658,16 @@ private static Variable getTimeVariable(NetcdfFile nc) throws IllegalArgumentException { - for (Variable v : nc.getVariables()) + List<Variable> variables = nc.getVariables(); + if(variables != null) { - if (v.isCoordinateVariable() - && TIME_VARIABLE_NAME.equals(v.getName())) + for (Variable v : variables) { - return v; + if (v.isCoordinateVariable() + && TIME_VARIABLE_NAME.equals(v.getName())) + { + return v; + } } } LOG.error("Could not find coordinate variable: " + TIME_VARIABLE_NAME); @@ -648,16 +690,21 @@ StringBuffer strBuf = new StringBuffer(); DateFormatter dateFormatter = new DateFormatter(); - Date epoc; + Date epocDate; try { - epoc = dateFormatter.dateOnlyFormat(EPOC); + Variable time = getTimeVariable(nc); + + String timeUnits = getVariablesUnits(time); + String epocString = timeUnits.substring(timeUnits.indexOf("days since") + 11); // we expect the time value to be in units of: "days since yyyy-mm-dd h:m:s" + + epocDate = dateFormatter.dateOnlyFormat(epocString); strBuf.append("Date,"); - long timeVariableSize = getTimeVariable(nc).getSize(); + long timeVariableSize = time.getSize(); for (int i = 0; i < timeVariableSize; i++) { - strBuf.append(dateFormatter.toDateOnlyString(new Date(epoc + strBuf.append(dateFormatter.toDateOnlyString(new Date(epocDate .getTime() + (i * MILLISECONDS_IN_A_DAY))).trim()); @@ -674,8 +721,34 @@ pe.printStackTrace(); LOG.error("Error parsing date", pe); } - } return DATE_COLUMN_TEXT; } + + /** + * Finds the string value of the attribute that is used to store a variable's type. + * + * @param variable + * a variable {@link Variable} + * @return the string value of the variable's type. + */ + private static String getVariablesUnits(Variable variable) + { + List<Attribute> attributes = variable.getAttributes(); + if(attributes != null) + { + for(Attribute attribute : attributes) + { + if(UNITS.equals(attribute.getName())) + { + return attribute.getStringValue(); + } + } + } + LOG + .error("Could not find the value for the variable: " + variable.getName() + " -\"" + UNITS + + "\" attribute."); + throw new IllegalStateException("Could not find the value for the variable: " + variable.getName() + " -\"" + + UNITS + "\" attribute."); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-08 09:35:52
|
Revision: 70 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=70&view=rev Author: jdempsey Date: 2010-07-08 09:35:45 +0000 (Thu, 08 Jul 2010) Log Message: ----------- ANDSWRON-737 - Add CRS metadata to comply with CF Conventions Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java trunk/src/test/java/au/csiro/netcdf/TestNcDefineVariable.java Modified: trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java 2010-07-08 09:32:13 UTC (rev 69) +++ trunk/src/main/java/au/csiro/netcdf/NcDefineVariable.java 2010-07-08 09:35:45 UTC (rev 70) @@ -459,8 +459,8 @@ .isRequired(false).withLongOpt(VARIABLE_ATTRIBUTES).create("a"); Option dimensionNames = OptionBuilder.withArgName("text").hasArg().withDescription( - "7: a comma separated list of the variable's dimensions, e.g. date,latitude,longitude.").isRequired( - true).withLongOpt(DIMENSION_NAMES).create("d"); + "7: OPTIONAL, a comma separated list of the variable's dimensions, e.g. date,latitude,longitude.") + .isRequired(false).withLongOpt(DIMENSION_NAMES).create("d"); Option largeFileSupport = OptionBuilder.withDescription( "8: OPTIONAL, set if more than 2 GB of data will need to be stored in this file.").isRequired(false) Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-08 09:32:13 UTC (rev 69) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-08 09:35:45 UTC (rev 70) @@ -133,6 +133,7 @@ DataType.FLOAT, DataType.FLOAT, DataType.FLOAT, DataType.FLOAT, DataType.FLOAT, DataType.FLOAT, DataType.FLOAT }; static final int numVariables = variableNames.length; + private static final String GRID_MAPPING = "crs"; // time constants private static final String TIME = "time"; @@ -190,6 +191,12 @@ private static String REPORTING_REGION_LONG_NAME = "MDB Reporting Region Id"; private static final float REPORTING_REGION_MISSING_VALUE = 0f; + // crs constants + private static String CRS_GRID_MAPPING_NAME = "latitude_longitude"; + private static float CRS_LONGITUDE_OF_PRIME_MERIDIAN = 0.0f; + private static float CRS_SEMI_MAJOR_AXIS = 6378137.0f; + private static float CRS_INVERSE_FLATTENING = 298.257222101f; + // cell id private static final int CELL_ID_COLUMN_INDEX = 0; @@ -601,6 +608,11 @@ TIME_BOUNDS)), TIME, false /* isLargeFileSupport */, false/* fillValue */); command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, new ArrayList<Attribute>(), TIME + " " + NV, false /* isLargeFileSupport */, false/* fillValue */); + command.execute(new File(outputFileName), GRID_MAPPING, DataType.INT, Arrays.asList(new Attribute( + "grid_mapping_name", CRS_GRID_MAPPING_NAME), new Attribute("longitude_of_prime_meridian", + CRS_LONGITUDE_OF_PRIME_MERIDIAN), new Attribute("semi_major_axis", CRS_SEMI_MAJOR_AXIS), + new Attribute("inverse_flattening", CRS_INVERSE_FLATTENING)), "", + false /* isLargeFileSupport */, true/* fillValue */); } /** @@ -618,13 +630,16 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", - ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -647,7 +662,8 @@ .valueOf(variableMissingValues[variableIndex])), new Attribute("_FillValue", Float .valueOf(variableFillValues[variableIndex])), new Attribute("valid_min", Float .valueOf(variableMinValues[variableIndex])), new Attribute("valid_max", Float - .valueOf(variableMaxValues[variableIndex]))), dimensions, + .valueOf(variableMaxValues[variableIndex])), new Attribute("grid_mapping", + GRID_MAPPING)), dimensions, false /* isLargeFileSupport */, false/* fillValue */); } Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-08 09:32:13 UTC (rev 69) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-08 09:35:45 UTC (rev 70) @@ -123,6 +123,7 @@ private static final String[] variableMissingValues = variableFillValues; private static final DataType[] variableDataTypes = new DataType[] { DataType.FLOAT, DataType.FLOAT }; static final int numVariables = variableNames.length; + private static final String GRID_MAPPING = "crs"; // time constants private static final String TIME = "time"; @@ -180,6 +181,12 @@ private static String REPORTING_REGION_LONG_NAME = "MDB Reporting Region Id"; private static final float REPORTING_REGION_MISSING_VALUE = 0f; + // crs constants + private static String CRS_GRID_MAPPING_NAME = "latitude_longitude"; + private static float CRS_LONGITUDE_OF_PRIME_MERIDIAN = 0.0f; + private static float CRS_SEMI_MAJOR_AXIS = 6378137.0f; + private static float CRS_INVERSE_FLATTENING = 298.257222101f; + // cell id private static final int CELL_ID_COLUMN_INDEX = 0; @@ -595,6 +602,11 @@ TIME_BOUNDS)), TIME, false /* isLargeFileSupport */, false/* fillValue */); command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, new ArrayList<Attribute>(), TIME + " " + NV, false /* isLargeFileSupport */, false/* fillValue */); + command.execute(new File(outputFileName), GRID_MAPPING, DataType.INT, Arrays.asList(new Attribute( + "grid_mapping_name", CRS_GRID_MAPPING_NAME), new Attribute("longitude_of_prime_meridian", + CRS_LONGITUDE_OF_PRIME_MERIDIAN), new Attribute("semi_major_axis", CRS_SEMI_MAJOR_AXIS), + new Attribute("inverse_flattening", CRS_INVERSE_FLATTENING)), "", + false /* isLargeFileSupport */, true/* fillValue */); } /** @@ -612,13 +624,16 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", - ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE), new Attribute( + "grid_mapping", GRID_MAPPING)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -638,7 +653,8 @@ Arrays.asList(new Attribute("units", variableUnits[variableIndex]), new Attribute("long_name", variableLongNames[variableIndex]), new Attribute("missing_value", Float .valueOf(variableMissingValues[variableIndex])), new Attribute("_FillValue", Float - .valueOf(variableFillValues[variableIndex]))), dimensions, false /* isLargeFileSupport */, + .valueOf(variableFillValues[variableIndex])), new Attribute("grid_mapping", + GRID_MAPPING)), dimensions, false /* isLargeFileSupport */, false/* fillValue */); } Modified: trunk/src/test/java/au/csiro/netcdf/TestNcDefineVariable.java =================================================================== --- trunk/src/test/java/au/csiro/netcdf/TestNcDefineVariable.java 2010-07-08 09:32:13 UTC (rev 69) +++ trunk/src/test/java/au/csiro/netcdf/TestNcDefineVariable.java 2010-07-08 09:35:45 UTC (rev 70) @@ -441,9 +441,6 @@ errors = ncDefineVariable.validCommand(invalidVariableAttributesArgs); assertTrue("Command with invalid variableAttributes option should return an error", !errors.isEmpty()); - - errors = ncDefineVariable.validCommand(missingDimensionNamesArgs); - assertTrue("Command without dimensionNames option should return an error", !errors.isEmpty()); errors = ncDefineVariable.validCommand(invalidVariableDataTypeArgs); assertTrue("Command with invalid variableDataType option should return an error", !errors.isEmpty()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-08 09:32:22
|
Revision: 69 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=69&view=rev Author: jdempsey Date: 2010-07-08 09:32:13 +0000 (Thu, 08 Jul 2010) Log Message: ----------- ANDSWRON-668 - Update metadata to match CF Conventions Modified Paths: -------------- trunk/attributes.txt Modified: trunk/attributes.txt =================================================================== --- trunk/attributes.txt 2010-07-08 02:17:50 UTC (rev 68) +++ trunk/attributes.txt 2010-07-08 09:32:13 UTC (rev 69) @@ -1,5 +1,7 @@ +Conventions=CF-1.4, PID=http://hdl.handle.net/10378.3/7023, -Dataset Name=MDB SY Scenario A (Historical Data), +Title=MDB SY Scenario A (Historical Data), +Institution=CSIRO Australia, +References=http://hdl.handle.net/10378.3/7023, Coordinate System=GDA94, Licence=CSIRO makes the datasets from the Murray Darling Basin Sustainable Yields project available under the Creative Commons: Attribution v3.0 license. You are free to copy\, distribute\, transmit and adapt the work provided the work is attributed as follows: Dataset created by Jai Vaze (CSIRO) . You must attribute this work to Commonwealth Science and Industrial Research Organisation (CSIRO) (www.csiro.au) - \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-08 02:17:56
|
Revision: 68 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=68&view=rev Author: robertbridle Date: 2010-07-08 02:17:50 +0000 (Thu, 08 Jul 2010) Log Message: ----------- ANDSWRON-703 - Fix usage text. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-08 02:05:42 UTC (rev 67) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-08 02:17:50 UTC (rev 68) @@ -129,7 +129,7 @@ .withArgName("dir") .hasArg() .withDescription( - "1. the directory path containing the netCDF files to be converted.") + "1. the directory path containing the netCDF files (split by latitude) to be converted into csv.") .isRequired(true).withLongOpt(INPUT_DIR).create("i"); Option outputDirectoryName = OptionBuilder @@ -139,20 +139,8 @@ "2: the directory path to place the new csv files.") .isRequired(true).withLongOpt(OUTPUT_DIR).create("o"); - Option pattern = OptionBuilder - .withArgName("filename pattern") - .hasArg() - .withDescription( - "3: OPTIONAL, a pattern to match multiple existing files, where multiple files should be " - + "processed. If this option is present the outputFilename is expected to be a directory " - + "containing the files to be processed. The wildcard characters * and ? are supported but " - + "may need to be escaped by a \\ to avoid processing by the shell. e.g. \\*.nc ") - .isRequired(false).withLongOpt(FILENAME_PATTERN) - .create("p"); - options.addOption(inputDirectoryName); options.addOption(outputDirectoryName); - options.addOption(pattern); // parse the command line arguments CommandLine parsedCommandLine = new GnuParser() @@ -174,8 +162,8 @@ // generate the help/usage statement String header = "Recreate "; - String footer = "\nExample: netcdf2csv -inputDirPath \"C:\\input\" -outputDirPath \"C:\\output\" \n" - + "Will convert the netCDF files in the input directory to csv file in the output directory."; + String footer = "\nExample: --inputDir \"C:\\input\" --outputDir \"C:\\output\" \n" + + "Will convert the netCDF files (which are split by latitude) in the input directory to csv files in the output directory."; StringWriter sw = new StringWriter(); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new CommandLineOptionsComparator()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-07-08 02:05:49
|
Revision: 67 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=67&view=rev Author: robertbridle Date: 2010-07-08 02:05:42 +0000 (Thu, 08 Jul 2010) Log Message: ----------- ANDSWRON-703 - Created a program to convert netCDF files (split by latitude) into csv files. Added Paths: ----------- trunk/launch/NetCDF2CSVConverter.launch trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java Added: trunk/launch/NetCDF2CSVConverter.launch =================================================================== --- trunk/launch/NetCDF2CSVConverter.launch (rev 0) +++ trunk/launch/NetCDF2CSVConverter.launch 2010-07-08 02:05:42 UTC (rev 67) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/netcdf-tools/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="au.csiro.netcdf.wron.MdbsyNetCDF2CSVConverter"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--inputDir "C:\test\netcdf\\" -outputDir "C:\test\csv\\""/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="netcdf-tools"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/> +</launchConfiguration> Added: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java (rev 0) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyNetCDF2CSVConverter.java 2010-07-08 02:05:42 UTC (rev 67) @@ -0,0 +1,693 @@ +package au.csiro.netcdf.wron; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.RandomAccessFile; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.MissingOptionException; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.log4j.Logger; + +import ucar.ma2.Array; +import ucar.ma2.InvalidRangeException; +import ucar.nc2.NetcdfFile; +import ucar.nc2.Variable; +import ucar.nc2.units.DateFormatter; +import au.csiro.netcdf.cli.CommandLineOptionsComparator; +import au.csiro.netcdf.util.CSVTokenizer; +import au.csiro.netcdf.util.Util; + +/** + * The class is a converter control class to convert Murray Darling Basin Sustainable Yields netCDF files into CSV + * files. + * + * Copyright 2010, CSIRO Australia + * + * @author Robert Bridle on 07/07/2010 + * @version $Revision: {revision} $ $Date: 2008-10-31 11:24:49 +1100 (Fri, 31 Oct 2008) $ + */ +public class MdbsyNetCDF2CSVConverter +{ + private static final String EPOC = "1895-01-01"; + + /** + * Constant that defines the logger to be used. + */ + private static final Logger LOG = Logger + .getLogger(MdbsyNetCDF2CSVConverter.class.getName()); + + /** + * The latitude variable name used in the netCDF files. + */ + private static final String LATITUDE_VARIABLE_NAME = "lat"; + + /** + * The longitude variable name used in the netCDF files. + */ + private static final String LONGITUDE_VARIABLE_NAME = "long"; + + /** + * The time variable name used in the netCDF files. + */ + private static final String TIME_VARIABLE_NAME = "time"; + + /** + * The number of milliseconds in a 24 hours. + */ + private static final Long MILLISECONDS_IN_A_DAY = new Long("86400000"); // milliseconds in a day. + + /** + * The date column text that is found in all csv files. + */ + // private static final String DATE_COLUMN_TEXT = writeOutDateColumn(); + + /** + * The name of the command line option used for specifying the input directory containing the netCDF files. + */ + public static final String INPUT_DIR = "inputDir"; + + /** + * The name of the command line option used for specifying the directory to create the csv files in. + */ + public static final String OUTPUT_DIR = "outputDir"; + + /** + * The pattern for accepted file names where multiple files are accepted. + */ + public static final String FILENAME_PATTERN = "pattern"; + + /** + * The column that the variable name is stored in the csv file. + */ + private static final int VARIABLE_COLUMN = 0; + + /** + * The only variables that we are interested in writing out to csv files are those that are in three dimensions + * (i.e. rank=3) + */ + private static final int RANK_THREE = 3; + + /** + * NetCDf file extension. + */ + private static final Object CSV_FILE_EXTENSION = ".csv"; + + /** + * CSV file extension. + */ + private static final Object NETCDF_FILE_EXTENSION = ".nc"; + + /** + * A string containing the date column text to be written out as the first column in all the csv files. + */ + private static String DATE_COLUMN_TEXT = null; + + /** + * @param args + */ + @SuppressWarnings("static-access") + public static void main(String[] args) throws ParseException, IOException, + InvalidRangeException, java.text.ParseException + { + Options options = new Options(); + try + { + Option inputDirectoryName = OptionBuilder + .withArgName("dir") + .hasArg() + .withDescription( + "1. the directory path containing the netCDF files to be converted.") + .isRequired(true).withLongOpt(INPUT_DIR).create("i"); + + Option outputDirectoryName = OptionBuilder + .withArgName("dir") + .hasArg() + .withDescription( + "2: the directory path to place the new csv files.") + .isRequired(true).withLongOpt(OUTPUT_DIR).create("o"); + + Option pattern = OptionBuilder + .withArgName("filename pattern") + .hasArg() + .withDescription( + "3: OPTIONAL, a pattern to match multiple existing files, where multiple files should be " + + "processed. If this option is present the outputFilename is expected to be a directory " + + "containing the files to be processed. The wildcard characters * and ? are supported but " + + "may need to be escaped by a \\ to avoid processing by the shell. e.g. \\*.nc ") + .isRequired(false).withLongOpt(FILENAME_PATTERN) + .create("p"); + + options.addOption(inputDirectoryName); + options.addOption(outputDirectoryName); + options.addOption(pattern); + + // parse the command line arguments + CommandLine parsedCommandLine = new GnuParser() + .parse(options, args); + + String inputDir = parsedCommandLine.getOptionValue(INPUT_DIR); + String outputDir = parsedCommandLine.getOptionValue(OUTPUT_DIR); + + MdbsyNetCDF2CSVConverter converter = new MdbsyNetCDF2CSVConverter(); + + long start = System.currentTimeMillis(); + converter.execute(inputDir, outputDir); + long end = System.currentTimeMillis() - start; + LOG.warn("Successfully converted all netcdf files to csv files in: " + end + " ms."); + } + catch (MissingOptionException moe) + { + LOG.error(moe.getMessage()); + + // generate the help/usage statement + String header = "Recreate "; + String footer = "\nExample: netcdf2csv -inputDirPath \"C:\\input\" -outputDirPath \"C:\\output\" \n" + + "Will convert the netCDF files in the input directory to csv file in the output directory."; + StringWriter sw = new StringWriter(); + HelpFormatter formatter = new HelpFormatter(); + formatter.setOptionComparator(new CommandLineOptionsComparator()); + formatter.printHelp(new PrintWriter(sw), 80, "-", header, options, + 0, 1, footer); + System.out.println(sw.toString()); + } + } + + /** + * Performs the conversion. + * + * @param inputDir + * the directory containing the Scenario A or C netCDF files. + * @param outputDir + * the directory in which the csv file will be placed. + * @throws InvalidRangeException + * thrown if an invalid range is attempted to be read from a netCDf variable. + * @throws IOException + */ + public void execute(String inputDir, String outputDir) throws IOException, + InvalidRangeException + { + // perform an initial conversion from netCDF to csv, the csv file will look like this: + // Date, 1985-01-01, 1895-01-02, 1985-01-03, ... + // APET, 0.1, 0.3, 0.0, .... + // rainfall,0.0, 0.4, 0.1, ... + writeCSVFiles(inputDir, outputDir); + + // transpose the csv files so the will look like this: + // Date, APET, rainfall + // 1895-01-01, 0.1, 0.0 + // 1895-01-02, 0.3, 0.4 + // 1895-01-03, 0.0, 0.1 + transposeCSVFiles(outputDir); + } + + /** + * For each netCDF file in the input directory: + * <p> + * Create a csv file for every latitude and longitude position. + * <p> + * Write out the value of a variable at every time interval, at a specific latitude and longitude position. + * + * @param inputDir + * the directory containing the Scenario A or C netCDF files. + * @param outputDir + * the directory in which the csv file will be placed. + * @throws InvalidRangeException + * thrown if an invalid range is attempted to be read from a netCDf variable. + * @throws IOException + */ + private void writeCSVFiles(String inputDir, String outputDir) + throws IOException, InvalidRangeException + { + File dir = new File(inputDir); + File[] files = dir.listFiles(); + if(files == null) + { + System.out.println("The input directory does not exist: " + inputDir); + LOG.error("The input directory does not exist: " + inputDir); + return; + } + + for (int fileIndex = 0; fileIndex < files.length; fileIndex++) + { + if (files[fileIndex].isFile() && NETCDF_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) + { + NetcdfFile nc = null; + try + { + nc = NetcdfFile.open(files[fileIndex].getAbsolutePath()); + + Array latitudes = getLatitudeValues(nc); + Array longitudes = getLongitudeValues(nc); + + LOG.info("latitude coordinate variable size: " + + latitudes.getSize()); + LOG.info("longitude coordinate variable size: " + + longitudes.getSize()); + + for (int latIndex = 0; latIndex < latitudes.getSize(); latIndex++) + { + for (int longIndex = 0; longIndex < longitudes + .getSize(); longIndex++) + { + String fileName = createFileNameBasedOnLatLong(nc, + latIndex, longIndex); + String filePath = outputDir + + System.getProperty("file.separator") + + fileName + ".csv"; + + // if the csv file already exists, then append the next variable. + if (Util.fileExists(filePath)) + { + File file = new File(filePath); + PrintWriter out = new PrintWriter( + new BufferedWriter(new FileWriter(file, + true /* append mode */))); + + List<String> variablesAlreadyWrittenOut = getVariablesAlreadyWrittenOut(file); + List<String> variablesThatCanBeWrittenOut = getVariablesThatCanBeWrittenOut(nc); + + variablesThatCanBeWrittenOut + .removeAll(variablesAlreadyWrittenOut); + + try + { + writeOutVariable(nc, out, + variablesThatCanBeWrittenOut, + latIndex, longIndex); + } + finally + { + if (out != null) + out.close(); + } + } + else + // if the csv file does not exist, create a new csv file and write all available variables. + { + PrintWriter out = new PrintWriter(new BufferedWriter( + new FileWriter(new File(filePath), + false /* append mode */))); + + List<String> variablesThatCanBeWrittenOut = getVariablesThatCanBeWrittenOut(nc); + + try + { + out.println(writeOutDateColumn(nc)); + + writeOutVariable(nc, out, + variablesThatCanBeWrittenOut, + latIndex, longIndex); + } + finally + { + if (out != null) + out.close(); + } + } + } + } + } + catch (java.io.FileNotFoundException fnfe) + { + System.out.println("file not found= " + files[fileIndex]); + LOG.error(fnfe); + } + finally + { + if (nc != null) + nc.close(); + } + } + } + } + + /** + * Writes out the value of a variable at every time interval, at a specific latitude and longitude position. + * + * @throws InvalidRangeException + * @throws IOException + * + */ + private void writeOutVariable(NetcdfFile nc, PrintWriter out, + List<String> variablesThatCanBeWrittenOut, int latIndex, + int longIndex) throws IOException, InvalidRangeException + { + for (String variableName : variablesThatCanBeWrittenOut) + { + Array subsection = getVariableAcrossTime(nc, variableName, + latIndex, longIndex); + out.println(variableName + "," + + subsection.toString().replaceAll(" ", ",")); + } + } + + /** + * Transpose the csv files so that columns represent a variable's value over time. + * + * @param outputDir + * the directory in which the csv file will be placed. + * @throws IOException + */ + private void transposeCSVFiles(String outputDir) throws IOException + { + File dir = new File(outputDir); + File[] files = dir.listFiles(); + if(files == null) + { + System.out.println("The output directory does not exist: " + outputDir); + LOG.error("The output directory does not exist: " + outputDir); + return; + } + + for (int fileIndex = 0; fileIndex < files.length; fileIndex++) + { + if (files[fileIndex].isFile() && CSV_FILE_EXTENSION.equals(Util.getFileExtension(files[fileIndex].getName()))) + { + String[][] matrix = readLookupFile(files[fileIndex]); + + // write over-the-top of the csv file. + PrintWriter out = new PrintWriter( + new BufferedWriter(new FileWriter(files[fileIndex], + false /* append mode */))); + + // transpose String[][] matrix and write back out to csv + String[][] transposed = transpose(matrix); + + try + { + for (int row = 0; row < transposed.length; row++) + { + for (int col = 0; col < transposed[0].length; col++) + { + out.print(transposed[row][col]); + if(col < (transposed[0].length-1)) + { + out.print(", "); + } + } + out.println(); + } + } + finally + { + if (out != null) + out.close(); + } + } + } + } + + /** + * Returns the names of the variables in the netCDF file that we need to write out for a given latitude x longitude + * position. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @return the names of the variables in the netCDF file that we need to write out for a given latitude x longitude + * position. + */ + private List<String> getVariablesThatCanBeWrittenOut(NetcdfFile nc) + { + List<String> variablesThatCanBeWrittenOut = new ArrayList<String>(); + + for (Variable variable : nc.getVariables()) + { + if (variable.getRank() == RANK_THREE) + { + variablesThatCanBeWrittenOut.add(variable.getName().trim()); + } + } + + return variablesThatCanBeWrittenOut; + } + + /** + * Returns the name of the variables that have already be written out to a csv file. + * + * @param file + * the csv file being written out too. + * @return the name of the variables that have already be written out to a csv file. + * @throws IOException + */ + private List<String> getVariablesAlreadyWrittenOut(File file) + throws IOException + { + List<String> variablesAlreadyWrittenOut = new ArrayList<String>(); + + String[][] matrix = readLookupFile(file); + for (int rows = 0; rows < matrix.length; rows++) + { + variablesAlreadyWrittenOut.add(matrix[rows][VARIABLE_COLUMN].trim()); + } + + return variablesAlreadyWrittenOut; + } + + /** + * Creates a file name based on a given latitude and longitude. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @param latIndex + * the latitude index. + * @param longIndex + * the longitude index. + * @return a file name based on latitude and longitude position. + * @throws InvalidRangeException + * @throws IOException + */ + private String createFileNameBasedOnLatLong(NetcdfFile nc, int latIndex, + int longIndex) throws IOException, InvalidRangeException + { + return "region_" + + nc.readSection("lat(" + latIndex + ":" + latIndex + ")") + .toString().trim() + + "_" + + nc.readSection("long(" + longIndex + ":" + longIndex + ")") + .toString().trim(); + } + + /** + * Parses a csv file into an row-by-column string matrix. + * + * @param file + * a csv file. + * @return row-by-column string matrix of the csv file. + * @throws IOException + */ + public static String[][] readLookupFile(File file) throws IOException + { + RandomAccessFile raf = new RandomAccessFile(file, "r"); + List<String[]> lineList = new ArrayList<String[]>(); + + try + { + String line = raf.readLine(); + while (line != null) + { + String[] cols = new CSVTokenizer(line).getAllColumns(); + lineList.add(cols); + line = raf.readLine(); + } + } + finally + { + raf.close(); + } + + String[][] lineCols = lineList.toArray(new String[][] {}); + return lineCols; + } + + /** + * Transpose a matrix, e.g. [a][b] -> [b][a] + * + * @param values a String[][] matrix. + */ + private String[][] transpose(String[][] values) + { + if(values.length == 0) + { + return new String[0][0]; + } + + String[][] transposed = new String[values[0].length][values.length]; + for (int row = 0; row < values.length; row++) + { + for (int col = 0; col < values[0].length; col++) + { + transposed[col][row] = values[row][col]; + } + } + return transposed; + } + + /** + * Returns the value of a variable at every time interval, at a specific latitude and longitude position. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @param variableName + * the variable whose values are to be read. + * @param latIndex + * the latitude index. + * @param longIndex + * the longitude index. + * @return the value of a variable at every time interval, at a specific latitude and longitude position. + * @throws IOException + * @throws InvalidRangeException + */ + private Array getVariableAcrossTime(NetcdfFile nc, String variableName, + int latIndex, int longIndex) throws IOException, + InvalidRangeException + { + try + { + return nc.readSection(variableName + "(" + latIndex + ":" + + latIndex + "," + longIndex + ":" + longIndex + ",:)"); + } + catch (InvalidRangeException ire) + { + ire.printStackTrace(); + LOG.error("Could not read section: " + variableName + "(" + + latIndex + ":" + latIndex + "," + longIndex + ":" + + longIndex + ",:)", ire); + } + return null; + } + + /** + * Returns the longitude coordinate variable values. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @return the longitude coordinate variable values. + * @throws IOException + * @throws IllegalArgumentException + */ + private Array getLongitudeValues(NetcdfFile nc) throws IOException, + IllegalArgumentException + { + for (Variable v : nc.getVariables()) + { + if (v.isCoordinateVariable() + && LONGITUDE_VARIABLE_NAME.equals(v.getName())) + { + return v.read(); + } + } + LOG.error("Could not find coordinate variable: " + + LONGITUDE_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + + LONGITUDE_VARIABLE_NAME); + } + + /** + * Returns the latitude coordinate variable values. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @return the latitude coordinate variable values. + * @throws IOException + * @throws IllegalArgumentException + */ + private Array getLatitudeValues(NetcdfFile nc) throws IOException, + IllegalArgumentException + { + for (Variable v : nc.getVariables()) + { + if (v.isCoordinateVariable() + && LATITUDE_VARIABLE_NAME.equals(v.getName())) + { + return v.read(); + } + } + LOG.error("Could not find coordinate variable: " + + LATITUDE_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + + LATITUDE_VARIABLE_NAME); + } + + /** + * Returns the time variable. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @return the time variable. + * @throws IllegalArgumentException + */ + private static Variable getTimeVariable(NetcdfFile nc) + throws IllegalArgumentException + { + for (Variable v : nc.getVariables()) + { + if (v.isCoordinateVariable() + && TIME_VARIABLE_NAME.equals(v.getName())) + { + return v; + } + } + LOG.error("Could not find coordinate variable: " + TIME_VARIABLE_NAME); + throw new IllegalStateException("Could not find coordinate variable: " + + TIME_VARIABLE_NAME); + } + + /** + * Converts a "days since" time coordinate variable into a list of formatted dates. + * + * @param nc + * a netCDF file {@link NetcdfFile} + * @return a list of formatted dates. + */ + private static String writeOutDateColumn(NetcdfFile nc) + { + // we only need to create the date column text once, it is the same for all csv files. + if (DATE_COLUMN_TEXT == null) + { + StringBuffer strBuf = new StringBuffer(); + + DateFormatter dateFormatter = new DateFormatter(); + Date epoc; + try + { + epoc = dateFormatter.dateOnlyFormat(EPOC); + strBuf.append("Date,"); + + long timeVariableSize = getTimeVariable(nc).getSize(); + for (int i = 0; i < timeVariableSize; i++) + { + strBuf.append(dateFormatter.toDateOnlyString(new Date(epoc + .getTime() + + (i * MILLISECONDS_IN_A_DAY))).trim()); + + if(i < (timeVariableSize-1)) + { + strBuf.append(","); + } + } + + DATE_COLUMN_TEXT = strBuf.toString(); + } + catch (java.text.ParseException pe) + { + pe.printStackTrace(); + LOG.error("Error parsing date", pe); + } + + } + return DATE_COLUMN_TEXT; + } +} Added: trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java =================================================================== --- trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java (rev 0) +++ trunk/src/test/java/au/csiro/netcdf/wron/TestMdbsyNetCDF2CSVConverter.java 2010-07-08 02:05:42 UTC (rev 67) @@ -0,0 +1,227 @@ +package au.csiro.netcdf.wron; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; + +import au.csiro.netcdf.NcWriteVariable; +import au.csiro.netcdf.util.Util; + +import ucar.ma2.DataType; +import ucar.nc2.Dimension; +import ucar.nc2.NCdumpW; +import ucar.nc2.NetcdfFile; +import ucar.nc2.NetcdfFileWriteable; +import ucar.nc2.Variable; +import junit.framework.TestCase; + +/** + * This class is a unit test suite to verify that the {@link MdbsyNetCDF2CSVConverter} operates correctly. + * + * Copyright 2010, CSIRO Australia + * + * @author Robert Bridle on 08/07/2010 + * @version $Revision: {revision} $ $Date: 2008-10-31 11:24:49 +1100 (Fri, 31 Oct 2008) $ + */ +public class TestMdbsyNetCDF2CSVConverter extends TestCase +{ + /** + * The testing value for the latitude coordinate dimension. + */ + private static final String DIM_LATITUDE = "lat"; + private static final String VAR_LATITUDE = DIM_LATITUDE; + private static final String VAR_LATITUDE_VALUE = "-24.25"; + + /** + * The testing value for the longitude coordinate dimension. + */ + private static final String DIM_LONGITUDE = "long"; + private static final String VAR_LONGITUDE = DIM_LONGITUDE; + private static final String VAR_LONGITUDE_VALUE = "138.10"; + + /** + * The expected name of the converted csv file. + */ + private static final String CONVERTED_CSV_FILE_NAME = System.getProperty("user.dir") + "\\region_-24.25_138.1.csv"; + + /** + * The testing value for the time coordinate dimension. + */ + private static final String DIM_TIME = "time"; + private static final String VAR_TIME = DIM_TIME; + private static final String VAR_TIME_VALUES = "0" + System.getProperty("line.separator") + "1" + + System.getProperty("line.separator") + "2" + System.getProperty("line.separator") + "3" + + System.getProperty("line.separator") + "4" + System.getProperty("line.separator") + "5" + + System.getProperty("line.separator") + "6" + System.getProperty("line.separator") + "7" + + System.getProperty("line.separator") + "8" + System.getProperty("line.separator") + "9"; + + /** + * The testing value for a variable defined over three coordinate dimensions (lat, long, time). + */ + private static final String VAR_APET = "APET"; + private static final String VAR_APET_VALUES = "0.000" + System.getProperty("line.separator") + "0.111" + + System.getProperty("line.separator") + "0.222" + System.getProperty("line.separator") + "0.333" + + System.getProperty("line.separator") + "0.444" + System.getProperty("line.separator") + "0.555" + + System.getProperty("line.separator") + "0.666" + System.getProperty("line.separator") + "0.777" + + System.getProperty("line.separator") + "0.888" + System.getProperty("line.separator") + "0.999"; + + + /** + * The expected output converted csv structure. + */ + private static String[] EXPECTED_CSV_FILE = { "Date, APET", + "1895-01-01, 0.0", + "1895-01-02, 0.111", + "1895-01-03, 0.222", + "1895-01-04, 0.333", + "1895-01-05, 0.444", + "1895-01-06, 0.555", + "1895-01-07, 0.666", + "1895-01-08, 0.777", + "1895-01-09, 0.888", + "1895-01-10, 0.999" }; + + /** + * The testing value for the dimension sizes. + */ + private static final int LAT_DIM_SIZE = 1; + private static final int LONG_DIM_SIZE = 1; + private static final int TIME_DIM_SIZE = 10; + + /** + * The testing value for the netCDF file to write to. + */ + private static final String NC_FILE_NAME = System.getProperty("user.dir") + "\\ABC.nc"; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // create dummy netCDF file with content. + createDummyNCFile(NC_FILE_NAME); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + + System.setOut(null); + + // delete dummy netCDF file + File ncFile = new File(NC_FILE_NAME); + if (ncFile.exists()) + { + NetcdfFile netcdfFile = NetcdfFile.open(NC_FILE_NAME); + netcdfFile.close(); + ncFile.delete(); + } + + // delete converted csv file + File csvFile = new File(CONVERTED_CSV_FILE_NAME); + if (csvFile.exists()) + { + csvFile.delete(); + } + } + + /** + * Test execute a valid NcWriteVariable command using Double datatype + */ + public final void testNetCDF2CSVConversion() throws Exception + { + MdbsyNetCDF2CSVConverter.main(new String[] { "-i", System.getProperty("user.dir"), "-o", + System.getProperty("user.dir") }); + + // check that the converted csv file was created. + assertTrue("The expected converted csv file does not exist: " + CONVERTED_CSV_FILE_NAME, Util + .fileExists(CONVERTED_CSV_FILE_NAME)); + + String[][] csvMatrix = MdbsyNetCDF2CSVConverter.readLookupFile(new File(CONVERTED_CSV_FILE_NAME)); + + for (int row = 0; row < csvMatrix.length; row++) + { + StringBuffer line = new StringBuffer(); + for (int col = 0; col < csvMatrix[0].length; col++) + { + line.append(csvMatrix[row][col]); + if(col < (csvMatrix[0].length-1)) + { + line.append(", "); + } + } + + assertEquals("The expected csv output is not correct.", EXPECTED_CSV_FILE[row], line.toString()); + } + } + + /** + * Makes a dummy netCDF file with known contents. + */ + private void createDummyNCFile(String outputFilename) throws IOException + { + NetcdfFileWriteable ncFile = null; + + ncFile = NetcdfFileWriteable.createNew(outputFilename, true); + try + { + Dimension dimension = new Dimension(DIM_LATITUDE, LAT_DIM_SIZE, true /* isShared */, + false /* isUnlimited */, false /* isVariableLength */); + ncFile.addDimension(null, dimension); + + dimension = new Dimension(DIM_LONGITUDE, LONG_DIM_SIZE, true /* isShared */, false /* isUnlimited */, false /* isVariableLength */); + ncFile.addDimension(null, dimension); + + dimension = new Dimension(DIM_TIME, TIME_DIM_SIZE, true /* isShared */, false /* isUnlimited */, false /* isVariableLength */); + ncFile.addDimension(null, dimension); + + // define coordinate variables. + ncFile.addVariable(VAR_LATITUDE, DataType.FLOAT, DIM_LATITUDE); + ncFile.addVariable(VAR_LONGITUDE, DataType.FLOAT, DIM_LONGITUDE); + ncFile.addVariable(VAR_TIME, DataType.INT, DIM_TIME); + + // variable is defined over three coordinates dimensions. + ncFile.addVariable(VAR_APET, DataType.FLOAT, DIM_LATITUDE + " " + DIM_LONGITUDE + " " + DIM_TIME); + ncFile.create(); + } + finally + { + ncFile.close(); + } + + // populate the coordinate variables with string of int values. + NcWriteVariable command = new NcWriteVariable(); + command.execute(new File(outputFilename), VAR_LATITUDE, "0-" + String.valueOf(LAT_DIM_SIZE - 1), + new ByteArrayInputStream(VAR_LATITUDE_VALUE.getBytes("UTF-8")), false); + command.execute(new File(outputFilename), VAR_LONGITUDE, "0-" + String.valueOf(LONG_DIM_SIZE - 1), + new ByteArrayInputStream(VAR_LONGITUDE_VALUE.getBytes("UTF-8")), false); + command.execute(new File(outputFilename), VAR_TIME, "0-" + String.valueOf(TIME_DIM_SIZE - 1), + new ByteArrayInputStream(VAR_TIME_VALUES.getBytes("UTF-8")), false); + + try + { + command.execute(new File(outputFilename), VAR_APET, "0-" + String.valueOf(LAT_DIM_SIZE - 1) + ", 0-" + + String.valueOf(LONG_DIM_SIZE - 1) + ", 0-" + String.valueOf(TIME_DIM_SIZE - 1), + new ByteArrayInputStream(VAR_APET_VALUES.getBytes("UTF-8")), false); + } + catch (IllegalArgumentException iae) + { + iae.printStackTrace(); + fail("could not create file: " + outputFilename + " to being testing of netCDF 2 CSV converter"); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-07 00:40:06
|
Revision: 66 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=66&view=rev Author: jdempsey Date: 2010-07-07 00:40:00 +0000 (Wed, 07 Jul 2010) Log Message: ----------- ANDSWRON-668 - Update metadata to match CF Conventions Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-07 00:21:41 UTC (rev 65) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-07 00:40:00 UTC (rev 66) @@ -219,7 +219,7 @@ */ @SuppressWarnings("static-access") public static void main(String[] args) throws Exception - { + { Options options = new Options(); try { @@ -618,13 +618,13 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", - ELEVATION_LONG_NAME), new Attribute("missing_value", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("missing_value", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", REPORTING_REGION_LONG_NAME), new Attribute("missing_value", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -1136,6 +1136,10 @@ for (CellData triple : triples) { latitudes.add(triple.getLatitude()); +// if (latitudes.size() >= LAT_SIZE) +// { +// break; +// } } return latitudes; } @@ -1152,6 +1156,10 @@ for (CellData triple : triples) { longitudes.add(triple.getLongitude()); +// if (longitudes.size() >= LONG_SIZE) +// { +// break; +// } } return longitudes; } Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-07 00:21:41 UTC (rev 65) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-07 00:40:00 UTC (rev 66) @@ -166,16 +166,19 @@ private static final String ELEVATION_UNITS = "m"; private static final String ELEVATION_STANDARD_NAME = "altitude"; private static final String ELEVATION_LONG_NAME = "Elevation above sea level"; + private static final float ELEVATION_MISSING_VALUE = -999.99f; // catchment id constants private static String CATCHMENT_ID = "catchmentId"; private static int CATCHMENT_ID_COLUMN_INDEX = 4; private static final String CATCHMENT_ID_LONG_NAME = "MDB Catchment Id"; + private static final float CATCHMENT_ID_MISSING_VALUE = 0f; // reporting region id constants private static String REPORTING_REGION = "repRegionId"; private static int REPORTING_REGION_ID_COLUMN_INDEX = 5; private static String REPORTING_REGION_LONG_NAME = "MDB Reporting Region Id"; + private static final float REPORTING_REGION_MISSING_VALUE = 0f; // cell id private static final int CELL_ID_COLUMN_INDEX = 0; @@ -609,13 +612,13 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", - ELEVATION_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_LONG_NAME), new Attribute("_FillValue", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", CATCHMENT_ID_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("_FillValue", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "long_name", REPORTING_REGION_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME), new Attribute("_FillValue", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -712,7 +715,7 @@ .toString().getBytes(ENCODING)), false); // call command to actually perform fill the file - command.execute(new File(outputFileName), TIME_BOUNDS, TIME_RANGE+","+NV_RANGE, new ByteArrayInputStream( + command.execute(new File(outputFileName), TIME_BOUNDS, timeRange+","+NV_RANGE, new ByteArrayInputStream( timeBoundsStringBuffer.toString().getBytes(ENCODING)), false); } @@ -1124,6 +1127,10 @@ for (CellData triple : triples) { latitudes.add(triple.getLatitude()); +// if (latitudes.size() >= LAT_SIZE) +// { +// break; +// } } return latitudes; } @@ -1140,6 +1147,10 @@ for (CellData triple : triples) { longitudes.add(triple.getLongitude()); +// if (longitudes.size() >= LONG_SIZE) +// { +// break; +// } } return longitudes; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-07 00:21:50
|
Revision: 65 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=65&view=rev Author: jdempsey Date: 2010-07-07 00:21:41 +0000 (Wed, 07 Jul 2010) Log Message: ----------- ANDSWRON-668 - Update metadata to match CF Conventions Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-05 04:25:18 UTC (rev 64) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-07-07 00:21:41 UTC (rev 65) @@ -14,9 +14,6 @@ * limitations under the License. */ -/** - * - */ package au.csiro.netcdf.wron; import java.io.BufferedReader; @@ -30,7 +27,9 @@ import java.io.RandomAccessFile; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.text.DateFormat; import java.text.NumberFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -138,7 +137,7 @@ // time constants private static final String TIME = "time"; private static final String TIME_RANGE = "0-43097"; - private static final int TIME_SIZE = 43098; + private static final int TIME_SIZE = 43098; // 365 private static final String TIME_LONG_NAME = "reference time"; private static final String TIME_STANDARD_NAME = "time"; private static final String TIME_UNITS = "days since 1889-01-01 0:0:0"; @@ -174,18 +173,22 @@ // elevation constants private static String ELEVATION = "elev"; private static int ELEVATION_COLUMN_INDEX = 3; - private static final String ELEVATION_UNITS = "metres above Sea level"; - private static final String ELEVATION_STANDARD_NAME = "Elevation"; + private static final String ELEVATION_UNITS = "m"; + private static final String ELEVATION_STANDARD_NAME = "altitude"; + private static final String ELEVATION_LONG_NAME = "Elevation above sea level"; + private static final float ELEVATION_MISSING_VALUE = -999.99f; // catchment id constants private static String CATCHMENT_ID = "catchmentId"; private static int CATCHMENT_ID_COLUMN_INDEX = 4; - private static final String CATCHMENT_ID_STANDARD_NAME = "MDB Catchment Id"; + private static final String CATCHMENT_ID_LONG_NAME = "MDB Catchment Id"; + private static final float CATCHMENT_ID_MISSING_VALUE = 0f; // reporting region id constants private static String REPORTING_REGION = "repRegionId"; private static int REPORTING_REGION_ID_COLUMN_INDEX = 5; - private static String REPORTING_REGION_STANDARD_NAME = "MDB Reporting Region Id"; + private static String REPORTING_REGION_LONG_NAME = "MDB Reporting Region Id"; + private static final float REPORTING_REGION_MISSING_VALUE = 0f; // cell id private static final int CELL_ID_COLUMN_INDEX = 0; @@ -520,8 +523,9 @@ this.defineSpatialVariables(outputFileName); // Add attributes - Attribute converter = new Attribute("Converted to netCDF by", - "$Id: MdbsyScenarioAConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); + DateFormat utcDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + Attribute converter = new Attribute("History", utcDateTime.format(new Date()) + " Converted to netCDF by " + + "$Id: MdbsyScenarioAConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); List<Attribute> globalAttrs = new ArrayList<Attribute>(); globalAttrs.add(converter); if (METADATA_FILE.length() > 0) @@ -595,9 +599,8 @@ new Attribute("long_name", TIME_LONG_NAME), new Attribute("standard_name", TIME_STANDARD_NAME), new Attribute("axis", TIME_AXIS), new Attribute("calendar", TIME_CALENDAR), new Attribute("bounds", TIME_BOUNDS)), TIME, false /* isLargeFileSupport */, false/* fillValue */); - command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, Arrays.asList(new Attribute("units", - TIME_UNITS), new Attribute("calendar", TIME_CALENDAR)), NV, false /* isLargeFileSupport */, - false/* fillValue */); + command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, new ArrayList<Attribute>(), TIME + " " + + NV, false /* isLargeFileSupport */, false/* fillValue */); } /** @@ -614,14 +617,14 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", - ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME)), spatialDim, - false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", + ELEVATION_LONG_NAME), new Attribute("missing_value", ELEVATION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "standard_name", CATCHMENT_ID_STANDARD_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME), new Attribute("missing_value", CATCHMENT_ID_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "standard_name", REPORTING_REGION_STANDARD_NAME)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME), new Attribute("missing_value", REPORTING_REGION_MISSING_VALUE)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -698,25 +701,30 @@ .toString().getBytes(ENCODING)), false); // /////////////////////////////////////////////////////////////////////////////////////////// - // fill time variable + // fill time and time_bnds variables + StringBuffer timeBoundsStringBuffer = new StringBuffer(); StringBuffer dateStringBuffer = new StringBuffer(); + boolean first = true; for (String date : dates) { dateStringBuffer.append(date).append(System.getProperty("line.separator")); + if (!first) + { + timeBoundsStringBuffer.append(date).append(System.getProperty("line.separator")); + } + timeBoundsStringBuffer.append(date).append(System.getProperty("line.separator")); + first = false; } + int dayAfterLastDay = Integer.parseInt(dates.get(dates.size()-1)) +1; + String finalString = String.valueOf(dayAfterLastDay); + timeBoundsStringBuffer.append(finalString).append(System.getProperty("line.separator")); // call command to actually perform fill the file command.execute(new File(outputFileName), TIME, timeRange, new ByteArrayInputStream(dateStringBuffer .toString().getBytes(ENCODING)), false); - // /////////////////////////////////////////////////////////////////////////////////////////// - // Fill time_bnds variable - StringBuffer timeBoundsStringBuffer = new StringBuffer(); - timeBoundsStringBuffer.append(dates.get(0)).append(System.getProperty("line.separator")); - timeBoundsStringBuffer.append(dates.get(dates.size()-1)).append(System.getProperty("line.separator")); - // call command to actually perform fill the file - command.execute(new File(outputFileName), TIME_BOUNDS, NV_RANGE, new ByteArrayInputStream( + command.execute(new File(outputFileName), TIME_BOUNDS, timeRange+","+NV_RANGE, new ByteArrayInputStream( timeBoundsStringBuffer.toString().getBytes(ENCODING)), false); } Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-05 04:25:18 UTC (rev 64) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-07-07 00:21:41 UTC (rev 65) @@ -14,9 +14,6 @@ * limitations under the License. */ -/** - * - */ package au.csiro.netcdf.wron; import java.io.BufferedReader; @@ -30,7 +27,9 @@ import java.io.RandomAccessFile; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.text.DateFormat; import java.text.NumberFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -75,7 +74,7 @@ * Copyright 2010, CSIRO Australia * All rights reserved. * - * @author $Author: dem040 $ on 17/04/2010 + * @author Robert Bridle on 17/04/2010 * @version $Revision: 7155 $ $Date: 2010-06-10 12:51:25 +1000 (Thu, 10 Jun 2010) $ */ public class MdbsyScenarioCConverter @@ -164,18 +163,19 @@ // elevation constants private static String ELEVATION = "elev"; private static int ELEVATION_COLUMN_INDEX = 3; - private static final String ELEVATION_UNITS = "metres above Sea level"; - private static final String ELEVATION_STANDARD_NAME = "Elevation"; + private static final String ELEVATION_UNITS = "m"; + private static final String ELEVATION_STANDARD_NAME = "altitude"; + private static final String ELEVATION_LONG_NAME = "Elevation above sea level"; // catchment id constants private static String CATCHMENT_ID = "catchmentId"; private static int CATCHMENT_ID_COLUMN_INDEX = 4; - private static final String CATCHMENT_ID_STANDARD_NAME = "MDB Catchment Id"; + private static final String CATCHMENT_ID_LONG_NAME = "MDB Catchment Id"; // reporting region id constants private static String REPORTING_REGION = "repRegionId"; private static int REPORTING_REGION_ID_COLUMN_INDEX = 5; - private static String REPORTING_REGION_STANDARD_NAME = "MDB Reporting Region Id"; + private static String REPORTING_REGION_LONG_NAME = "MDB Reporting Region Id"; // cell id private static final int CELL_ID_COLUMN_INDEX = 0; @@ -514,8 +514,9 @@ this.defineSpatialVariables(outputFileName); // Add attributes - Attribute converter = new Attribute("Converted to netCDF by", - "$Id: MdbsyScenarioCConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); + DateFormat utcDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + Attribute converter = new Attribute("History", utcDateTime.format(new Date()) + " Converted to netCDF by " + + "$Id: MdbsyScenarioCConverter.java 7155 2010-06-10 02:51:25Z dem040 $"); List<Attribute> globalAttrs = new ArrayList<Attribute>(); globalAttrs.add(converter); if (METADATA_FILE.length() > 0) @@ -589,9 +590,8 @@ new Attribute("long_name", TIME_LONG_NAME), new Attribute("standard_name", TIME_STANDARD_NAME), new Attribute("axis", TIME_AXIS), new Attribute("calendar", TIME_CALENDAR), new Attribute("bounds", TIME_BOUNDS)), TIME, false /* isLargeFileSupport */, false/* fillValue */); - command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, Arrays.asList(new Attribute("units", - TIME_UNITS), new Attribute("calendar", TIME_CALENDAR)), NV, false /* isLargeFileSupport */, - false/* fillValue */); + command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, new ArrayList<Attribute>(), TIME + " " + + NV, false /* isLargeFileSupport */, false/* fillValue */); } /** @@ -608,14 +608,14 @@ String spatialDim = LAT + " " + LONG; command.execute(new File(outputFileName), ELEVATION, DataType.FLOAT, Arrays.asList(new Attribute("units", - ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME)), spatialDim, - false /* isLargeFileSupport */, false/* fillValue */); + ELEVATION_UNITS), new Attribute("standard_name", ELEVATION_STANDARD_NAME), new Attribute("long_name", + ELEVATION_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), CATCHMENT_ID, DataType.FLOAT, Arrays.asList(new Attribute( - "standard_name", CATCHMENT_ID_STANDARD_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); + "long_name", CATCHMENT_ID_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); command .execute(new File(outputFileName), REPORTING_REGION, DataType.FLOAT, Arrays.asList(new Attribute( - "standard_name", REPORTING_REGION_STANDARD_NAME)), spatialDim, false /* isLargeFileSupport */, + "long_name", REPORTING_REGION_LONG_NAME)), spatialDim, false /* isLargeFileSupport */, false/* fillValue */); } @@ -689,25 +689,30 @@ .toString().getBytes(ENCODING)), false); // /////////////////////////////////////////////////////////////////////////////////////////// - // fill time variable + // fill time and time_bnds variables + StringBuffer timeBoundsStringBuffer = new StringBuffer(); StringBuffer dateStringBuffer = new StringBuffer(); + boolean first = true; for (String date : dates) { dateStringBuffer.append(date).append(System.getProperty("line.separator")); + if (!first) + { + timeBoundsStringBuffer.append(date).append(System.getProperty("line.separator")); + } + timeBoundsStringBuffer.append(date).append(System.getProperty("line.separator")); + first = false; } + int dayAfterLastDay = Integer.parseInt(dates.get(dates.size()-1)) +1; + String finalString = String.valueOf(dayAfterLastDay); + timeBoundsStringBuffer.append(finalString).append(System.getProperty("line.separator")); // call command to actually perform fill the file command.execute(new File(outputFileName), TIME, timeRange, new ByteArrayInputStream(dateStringBuffer .toString().getBytes(ENCODING)), false); - // /////////////////////////////////////////////////////////////////////////////////////////// - // Fill time_bnds variable - StringBuffer timeBoundsStringBuffer = new StringBuffer(); - timeBoundsStringBuffer.append(dates.get(0)).append(System.getProperty("line.separator")); - timeBoundsStringBuffer.append(dates.get(dates.size()-1)).append(System.getProperty("line.separator")); - // call command to actually perform fill the file - command.execute(new File(outputFileName), TIME_BOUNDS, NV_RANGE, new ByteArrayInputStream( + command.execute(new File(outputFileName), TIME_BOUNDS, TIME_RANGE+","+NV_RANGE, new ByteArrayInputStream( timeBoundsStringBuffer.toString().getBytes(ENCODING)), false); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-07-05 04:25:25
|
Revision: 64 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=64&view=rev Author: jdempsey Date: 2010-07-05 04:25:18 +0000 (Mon, 05 Jul 2010) Log Message: ----------- ANDSWRON-732 - Add licence info to the netCDF files Modified Paths: -------------- trunk/attributes.txt Modified: trunk/attributes.txt =================================================================== --- trunk/attributes.txt 2010-06-28 00:22:57 UTC (rev 63) +++ trunk/attributes.txt 2010-07-05 04:25:18 UTC (rev 64) @@ -1,3 +1,5 @@ PID=http://hdl.handle.net/10378.3/7023, Dataset Name=MDB SY Scenario A (Historical Data), -Coordinate System=GDA94 +Coordinate System=GDA94, +Licence=CSIRO makes the datasets from the Murray Darling Basin Sustainable Yields project available under the Creative Commons: Attribution v3.0 license. You are free to copy\, distribute\, transmit and adapt the work provided the work is attributed as follows: Dataset created by Jai Vaze (CSIRO) . You must attribute this work to Commonwealth Science and Industrial Research Organisation (CSIRO) (www.csiro.au) + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2010-06-28 00:23:06
|
Revision: 63 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=63&view=rev Author: robertbridle Date: 2010-06-28 00:22:57 +0000 (Mon, 28 Jun 2010) Log Message: ----------- ANDSWRON-664 - Review - Add period after degrees "N" when creating filenames for split by latitude. Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-25 11:58:44 UTC (rev 62) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-28 00:22:57 UTC (rev 63) @@ -1251,7 +1251,7 @@ } else { - filename += latitudeDegree + "N"; + filename += latitudeDegree + "N."; } filename += "Var-" + variable + NETCDF_FILE_EXTENSION; return filename; Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-25 11:58:44 UTC (rev 62) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-28 00:22:57 UTC (rev 63) @@ -1242,7 +1242,7 @@ } else { - filename += latitudeDegree + "N"; + filename += latitudeDegree + "N."; } filename += "Var-" + variable + NETCDF_FILE_EXTENSION; return filename; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-06-25 11:58:51
|
Revision: 62 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=62&view=rev Author: jdempsey Date: 2010-06-25 11:58:44 +0000 (Fri, 25 Jun 2010) Log Message: ----------- ANDSWRON-715 - Add indicator for Variable in file name Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-25 11:30:12 UTC (rev 61) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-25 11:58:44 UTC (rev 62) @@ -1244,7 +1244,16 @@ { filename += CASE + "."; } - filename += "Latitude-" + latitudeDegree + "S.S-" + variable + NETCDF_FILE_EXTENSION; + filename += "Latitude-"; + if (latitudeDegree.startsWith("-")) + { + filename += latitudeDegree.substring(1) + "S."; + } + else + { + filename += latitudeDegree + "N"; + } + filename += "Var-" + variable + NETCDF_FILE_EXTENSION; return filename; } @@ -1259,7 +1268,7 @@ { filename += CASE + "."; } - filename += "Decade-" + decadeStr + "S.S-" + variable + NETCDF_FILE_EXTENSION; + filename += "Decade-" + decadeStr + ".Var-" + variable + NETCDF_FILE_EXTENSION; return filename; } Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-25 11:30:12 UTC (rev 61) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-25 11:58:44 UTC (rev 62) @@ -1235,7 +1235,16 @@ { filename += CASE + "."; } - filename += "Latitude-" + latitudeDegree + "S.S-" + variable + NETCDF_FILE_EXTENSION; + filename += "Latitude-"; + if (latitudeDegree.startsWith("-")) + { + filename += latitudeDegree.substring(1) + "S."; + } + else + { + filename += latitudeDegree + "N"; + } + filename += "Var-" + variable + NETCDF_FILE_EXTENSION; return filename; } @@ -1250,7 +1259,7 @@ { filename += CASE + "."; } - filename += "Decade-" + decadeStr + "S.S-" + variable + NETCDF_FILE_EXTENSION; + filename += "Decade-" + decadeStr + ".Var-" + variable + NETCDF_FILE_EXTENSION; return filename; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2010-06-25 11:30:18
|
Revision: 61 http://netcdftools.svn.sourceforge.net/netcdftools/?rev=61&view=rev Author: jdempsey Date: 2010-06-25 11:30:12 +0000 (Fri, 25 Jun 2010) Log Message: ----------- ANDSWRON-664 - Add time_bnds variable Modified Paths: -------------- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-25 04:37:57 UTC (rev 60) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioAConverter.java 2010-06-25 11:30:12 UTC (rev 61) @@ -368,7 +368,7 @@ for (int i = 0; i < filenames.length; i++) { filenames[i] = this.generateLatitudeFilename(latitudeDegree, variableNames[i]); - this.createVariableFile(filenames[i], Arrays.asList(LAT, LONG, TIME, NV), i, TIME_SIZE, blockLatSize, + this.createVariableFile(filenames[i], Arrays.asList(LAT, LONG, TIME), i, TIME_SIZE, blockLatSize, blockLongSize); this.fillCoordinateVariables(filenames[i], sortedLongitudes, sortedLatitudes, dates, blockLatRange, blockLongRange, TIME_RANGE); @@ -425,6 +425,10 @@ int blockTimeSize = dates.size(); String blockTimeRange = "0-" + String.valueOf(dates.size() - 1); +// if (decadeKey > 189) +// { +// continue; +// } // create file names String decadeStr = String.valueOf(decadeKey + "0"); @@ -435,7 +439,7 @@ filenames[i] = this.generateDecadeFilename(decadeStr, variableNames[i]); if ("".equals(startingLatitude)) { - this.createVariableFile(filenames[i], Arrays.asList(TIME, LAT, LONG, NV), i, blockTimeSize, + this.createVariableFile(filenames[i], Arrays.asList(TIME, LAT, LONG), i, blockTimeSize, LAT_SIZE, LONG_SIZE); this.fillCoordinateVariables(filenames[i], sortedLongitudes, sortedLatitudes, dates, blockLatRange, blockLongRange, blockTimeRange); @@ -562,11 +566,10 @@ { command.execute(outputFileName, LONG, blockLongSize, false /* isUnlimited */, false/* fillValue */); } - else if (dimName.equals(NV)) - { - command.execute(outputFileName, NV, NV_SIZE, false /* isUnlimited */, false/* fillValue */); - } } + + // Add NV as the final dimension + command.execute(outputFileName, NV, NV_SIZE, false /* isUnlimited */, false/* fillValue */); } /** @@ -707,7 +710,7 @@ .toString().getBytes(ENCODING)), false); // /////////////////////////////////////////////////////////////////////////////////////////// - // File time_bnds variable + // Fill time_bnds variable StringBuffer timeBoundsStringBuffer = new StringBuffer(); timeBoundsStringBuffer.append(dates.get(0)).append(System.getProperty("line.separator")); timeBoundsStringBuffer.append(dates.get(dates.size()-1)).append(System.getProperty("line.separator")); Modified: trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java =================================================================== --- trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-25 04:37:57 UTC (rev 60) +++ trunk/src/main/java/au/csiro/netcdf/wron/MdbsyScenarioCConverter.java 2010-06-25 11:30:12 UTC (rev 61) @@ -155,7 +155,12 @@ private static final String LAT_STANDARD_NAME = "latitude"; private static final String LAT_AXIS = "Y"; private static final String LAT_LONG_NAME = "latitude"; - + + // num values constants + private static final String NV = "nv"; + private static final String NV_RANGE = "0-1"; + private static final int NV_SIZE = 2; + // elevation constants private static String ELEVATION = "elev"; private static int ELEVATION_COLUMN_INDEX = 3; @@ -556,6 +561,9 @@ command.execute(outputFileName, LONG, blockLongSize, false /* isUnlimited */, false/* fillValue */); } } + + // Add NV as the final dimension + command.execute(outputFileName, NV, NV_SIZE, false /* isUnlimited */, false/* fillValue */); } /** @@ -581,6 +589,9 @@ new Attribute("long_name", TIME_LONG_NAME), new Attribute("standard_name", TIME_STANDARD_NAME), new Attribute("axis", TIME_AXIS), new Attribute("calendar", TIME_CALENDAR), new Attribute("bounds", TIME_BOUNDS)), TIME, false /* isLargeFileSupport */, false/* fillValue */); + command.execute(new File(outputFileName), TIME_BOUNDS, DataType.INT, Arrays.asList(new Attribute("units", + TIME_UNITS), new Attribute("calendar", TIME_CALENDAR)), NV, false /* isLargeFileSupport */, + false/* fillValue */); } /** @@ -688,6 +699,17 @@ // call command to actually perform fill the file command.execute(new File(outputFileName), TIME, timeRange, new ByteArrayInputStream(dateStringBuffer .toString().getBytes(ENCODING)), false); + + // /////////////////////////////////////////////////////////////////////////////////////////// + // Fill time_bnds variable + StringBuffer timeBoundsStringBuffer = new StringBuffer(); + timeBoundsStringBuffer.append(dates.get(0)).append(System.getProperty("line.separator")); + timeBoundsStringBuffer.append(dates.get(dates.size()-1)).append(System.getProperty("line.separator")); + + // call command to actually perform fill the file + command.execute(new File(outputFileName), TIME_BOUNDS, NV_RANGE, new ByteArrayInputStream( + timeBoundsStringBuffer.toString().getBytes(ENCODING)), false); + } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |