public RafTrajectoryObsDataset( NetcdfDataset ncf) throws IOException
{
super( ncf );
Attribute conventionsAtt = ncf.findGlobalAttribute( "Conventions" );
if ( conventionsAtt == null )
conventionsAtt = ncf.findGlobalAttributeIgnoreCase( "Conventions" );
if ( conventionsAtt == null)
throw new IllegalArgumentException( "File <" + ncf.getId() + "> not a \"NCAR-RAF/nimbus\" convention file." );
if ( ! conventionsAtt.getStringValue().equals( "NCAR-RAF/nimbus" ) )
throw new IllegalArgumentException( "File <" + ncf.getId() + "> not a \"NCAR-RAF/nimbus\" convention file." );
Attribute versionAtt = ncf.findGlobalAttributeIgnoreCase( "Version" );
if ( versionAtt.getStringValue().equals( "1.2"))
{
timeDimName = "Time";
timeVarName = "time_offset";
latVarName = "LAT";
lonVarName = "LON";
elevVarName = "ALT";
// Determine and set the units (base time) for the time variable.
String baseTimeVarName = "base_time";
Variable baseTimeVar = ncfile.findVariable( baseTimeVarName );
int baseTime = baseTimeVar.readScalarInt();
Date baseTimeDate;
if ( baseTime != 0 )
{
String baseTimeString = baseTime + " seconds since 1970-01-01T00:00:00";
baseTimeDate = DateUnit.getStandardDate( baseTimeString );
}
else
{
Calendar calendar = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
// Read in start point date/time information and create java.util.Date
Array yearArray, monthArray, dayArray, hourArray, minuteArray, secondArray, tmpTimeArray;
try
{
yearArray = ncf.findVariable( "YEAR" ).read( "0" );
monthArray = ncf.findVariable( "MONTH" ).read( "0" );
dayArray = ncf.findVariable( "DAY" ).read( "0" );
hourArray = ncf.findVariable( "HOUR" ).read( "0" );
minuteArray = ncf.findVariable( "MINUTE" ).read( "0" );
secondArray = ncf.findVariable( "SECOND" ).read( "0" );
tmpTimeArray = ncf.findVariable( timeVarName).read( "0" );
}
catch ( InvalidRangeException e )
{
throw new IOException( "Failed while reading first value of YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, or time_offset: " + e.getMessage() );
}
calendar.clear();
calendar.set( Calendar.YEAR, (int) yearArray.getFloat( yearArray.getIndex() ) );
calendar.set( Calendar.MONTH, (int) monthArray.getFloat( monthArray.getIndex() ) );
calendar.set( Calendar.DAY_OF_MONTH, (int) dayArray.getFloat( dayArray.getIndex() ) );
calendar.set( Calendar.HOUR_OF_DAY, (int) hourArray.getFloat( hourArray.getIndex() ) );
calendar.set( Calendar.MINUTE, (int) minuteArray.getFloat( minuteArray.getIndex() ) );
calendar.set( Calendar.SECOND, (int) secondArray.getFloat( secondArray.getIndex() ) );
calendar.set( Calendar.MILLISECOND, 0 );
// Calculating base time so subtract seconds in time variable first value.
calendar.add( Calendar.SECOND, - (int) tmpTimeArray.getFloat( tmpTimeArray.getIndex() ));
baseTimeDate = calendar.getTime();
}
DateFormatter formatter = new DateFormatter();
String timeUnitsString = "seconds since " + formatter.toDateTimeStringISO( baseTimeDate );
ncfile.findVariable( timeVarName ).addAttribute( new Attribute( "units", timeUnitsString ) );
// Make sure alt units are "meters" convertible.
String elevVarUnitsString = ncfile.findVariable( elevVarName ).findAttribute( "units").getStringValue();
if ( ! SimpleUnit.isCompatible( elevVarUnitsString, "meters"))
{
if ( elevVarUnitsString.equals( "M"))
ncfile.findVariable( elevVarName ).addAttribute( new Attribute( "units", "meters"));
}
}
else if ( versionAtt.getStringValue().equals( "1.3" ) )
{
// Set default dimension and variable names.
timeDimName = "Time";
timeVarName = "Time";
latVarName = "LAT";
lonVarName = "LON";
elevVarName = "ALT";
// Set dimension and variable names as indicated by global attribute "coordinates".
Attribute coordsAttrib = ncfile.findGlobalAttribute( "coordinates");
if ( coordsAttrib != null )
{
String coordsAttribValue = coordsAttrib.getStringValue();
if ( coordsAttribValue != null)
{
String[] varNames = coordsAttribValue.split( " ");
latVarName = varNames[ 1];
lonVarName = varNames[0];