Package codec.x501

Examples of codec.x501.Attribute


     * @throws IOException _more_
     */
    public void augmentDataset(NetcdfDataset ds,
                               CancelTask cancelTask) throws IOException {

        Attribute leoAtt = ds.findGlobalAttribute("leoId");

        if (leoAtt == null) {
            if (ds.findVariable("time") == null) {
                // create a time variable - assume its linear along the vertical dimension
                double start = ds.readAttributeDouble(null, "start_time",
                                   Double.NaN);
                double stop = ds.readAttributeDouble(null, "stop_time",
                                  Double.NaN);

                if (Double.isNaN(start) && Double.isNaN(stop)) {
                    double top = ds.readAttributeDouble(null, "toptime",
                                     Double.NaN);
                    double bot = ds.readAttributeDouble(null, "bottime",
                                     Double.NaN);

                    this.conventionName = "Cosmic2";
                    if (top > bot) {
                        stop  = top;
                        start = bot;
                    } else {
                        stop  = bot;
                        start = top;
                    }

                }

                Dimension dim       = ds.findDimension("MSL_alt");
                Variable  dimV      = ds.findVariable("MSL_alt");
                Array     dimU      = dimV.read();
                int       inscr = (dimU.getFloat(1) - dimU.getFloat(0)) > 0
                                  ? 1
                                  : 0;
                int       n         = dim.getLength();
                double    incr      = (stop - start) / n;

                String    timeUnits = "seconds since 1980-01-06 00:00:00";
                Variable timeVar = new VariableDS(ds, null, null, "time",
                                       DataType.DOUBLE, dim.getName(),
                                       timeUnits, null);
                ds.addVariable(null, timeVar);
                timeVar.addAttribute(new Attribute("units", timeUnits));
                timeVar.addAttribute(new Attribute(_Coordinate.AxisType,
                        AxisType.Time.toString()));
                int dir = ds.readAttributeInteger(null, "irs", 1);
                ArrayDouble.D1 data =
                    (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                        new int[] { n });
                if (inscr == 0) {
                    if (dir == 1) {
                        for (int i = 0; i < n; i++) {
                            data.set(i, start + i * incr);
                        }
                    } else {
                        for (int i = 0; i < n; i++) {
                            data.set(i, stop - i * incr);
                        }
                    }
                } else {
                    for (int i = 0; i < n; i++) {
                        data.set(i, stop - i * incr);
                    }
                }
                timeVar.setCachedData(data, false);
            }

            Variable v = ds.findVariable("Lat");
            if (v == null) {
                v = ds.findVariable("GEO_lat");
            }
            v.addAttribute(new Attribute(_Coordinate.AxisType,
                                         AxisType.Lat.toString()));
            Variable v1 = ds.findVariable("Lon");
            if (v1 == null) {
                v1 = ds.findVariable("GEO_lon");
            }
            v1.addAttribute(new Attribute(_Coordinate.AxisType,
                                          AxisType.Lon.toString()));
        } else {
            Dimension dim = ds.findDimension("time");
            int       n   = dim.getLength();
            Variable latVar = new VariableDS(ds, null, null, "Lat",
                                             DataType.FLOAT, dim.getName(),
                                             "degree", null);
            latVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Lat.toString()));
            ds.addVariable(null, latVar);
            Variable lonVar = new VariableDS(ds, null, null, "Lon",
                                             DataType.FLOAT, dim.getName(),
                                             "degree", null);
            lonVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Lon.toString()));
            ds.addVariable(null, lonVar);
            Variable altVar = new VariableDS(ds, null, null, "MSL_alt",
                                             DataType.FLOAT, dim.getName(),
                                             "meter", null);
            altVar.addAttribute(new Attribute(_Coordinate.AxisType,
                    AxisType.Height.toString()));
            ds.addVariable(null, altVar);

            // cal data array
            ArrayFloat.D1 latData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayFloat.D1 lonData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayFloat.D1 altData =
                (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                    new int[] { n });
            ArrayDouble.D1 timeData =
                (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                    new int[] { n });
            this.conventionName = "Cosmic3";

            int iyr  = ds.readAttributeInteger(null, "year", 2009);
            int mon  = ds.readAttributeInteger(null, "month", 0);
            int iday = ds.readAttributeInteger(null, "day", 0);
            int ihr  = ds.readAttributeInteger(null, "hour", 0);
            int min  = ds.readAttributeInteger(null, "minute", 0);
            int sec  = ds.readAttributeInteger(null, "second", 0);

            double start = ds.readAttributeDouble(null, "startTime",
                               Double.NaN);
            double stop = ds.readAttributeDouble(null, "stopTime",
                              Double.NaN);
            double incr = (stop - start) / n;
            int    t    = 0;
            // double julian = juday(mon, iday, iyr);
            // cal the dtheta based pm attributes
            double   dtheta = gast(iyr, mon, iday, ihr, min, sec, t);

            Variable tVar   = ds.findVariable("time");
            String timeUnits = "seconds since 1980-01-06 00:00:00"//dtime.getUnit().toString();
            tVar.removeAttributeIgnoreCase("valid_range");
            tVar.removeAttributeIgnoreCase("units");
            tVar.addAttribute(new Attribute("units", timeUnits));
            tVar.addAttribute(new Attribute(_Coordinate.AxisType,
                                            AxisType.Time.toString()));

            Variable v    = ds.findVariable("xLeo");
            Array    xLeo = v.read();
            v = ds.findVariable("yLeo");
View Full Code Here


    this.dodsfile = dodsfile;
    this.dodsShortName = dodsShortName;

    setDataType( DODSNetcdfFile.convertToNCType( dodsScalar));
    if (DODSNetcdfFile.isUnsigned( dodsScalar)) {
      addAttribute(new Attribute("_Unsigned", "true"));
    }

    // check for netcdf char array
    Dimension strlenDim;
    if ((dataType == DataType.STRING) && (null != (strlenDim = dodsfile.getNetcdfStrlenDim( this)))) {
View Full Code Here

    this.dodsfile = dodsfile;
    this.dodsShortName = dodsShortName;

    setDataType( DODSNetcdfFile.convertToNCType( elemType));
    if (DODSNetcdfFile.isUnsigned( elemType)) {
      addAttribute(new Attribute("_Unsigned", "true"));
    }

    List<Dimension> dims = dodsfile.constructDimensions( parentGroup, dodsArray);

    // check for netcdf char array
View Full Code Here

     * @param attName  the attribute name
     *
     * @return the int array
     */
    private int[] getIntArray(Variable ctv, String attName) {
        Attribute att = ctv.findAttribute(attName);
        if (att == null) {
            throw new IllegalArgumentException(
                "McIDASArea coordTransformVariable " + ctv.getFullName()
                + " must have " + attName + " attribute");
        }

        Array arr = att.getValues();
        return (int[]) arr.get1DJavaArray(int.class);
    }
View Full Code Here

    }

    if (v != null) {
      v.setDataType(dt);
      if (unsigned)
         v.addAttribute(new Attribute("_Unsigned", "true"));
    }

    return dt;
  }
View Full Code Here

  }

  public void testVlengthAttribute() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/vlstra.h5");

    Attribute att = ncfile.findGlobalAttribute("test_scalar");
    assert (null != att);
    assert (!att.isArray());
    assert (att.isString());
    assert (att.getStringValue().equals("This is the string for the attribute"));
    ncfile.close();
  }
View Full Code Here

     * _more_
     *
     * @return _more_
     */
    public String getRadarID() {
        Attribute ga = ds.findGlobalAttribute("Station");
        if (ga != null) {
            return ga.getStringValue();
        } else {
            return "XXXX";
        }
    }
View Full Code Here

     * _more_
     *
     * @return _more_
     */
    public String getRadarName() {
        Attribute ga = ds.findGlobalAttribute("StationName");
        if (ga != null) {
            return ga.getStringValue();
        } else {
            return "Unknown Station";
        }
    }
View Full Code Here

  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];
View Full Code Here

    return (v == null) ? null : v.getShortName();
  }

  static public String getNameOfVariableWithAttribute(Structure struct, String attName, String attValue) {
    for (Variable v : struct.getVariables()) {
      Attribute att = v.findAttributeIgnoreCase(attName);
      if ((att != null) && att.getStringValue().equals(attValue))
        return v.getShortName();
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of codec.x501.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.