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