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. |