ucar.ma2.DataType Java Examples

The following examples show how to use ucar.ma2.DataType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VariableSimpleImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public VariableSimpleImpl(String name, String desc, String units, DataType dt, List<Dimension> dims) {
  this.name = name;
  this.desc = desc;
  this.units = units;
  this.dt = dt;

  if (dims == null) {
    this.dims = new ArrayList<>();
    this.shape = new int[0];
  } else {
    this.dims = dims;
    this.shape = new int[dims.size()];
    int count = 0;
    for (Dimension d : dims)
      this.shape[count++] = d.getLength();
  }

  if (units != null)
    atts.add(new Attribute(CDM.UNITS, units));
  if (desc != null)
    atts.add(new Attribute(CDM.LONG_NAME, desc));
}
 
Example #2
Source File: H4header.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addGlobalAttributes(TagVGroup group) throws IOException {
  // look for attributes
  for (int i = 0; i < group.nelems; i++) {
    Tag tag = tagMap.get(tagid(group.elem_ref[i], group.elem_tag[i]));
    if (tag == null)
      throw new IllegalStateException();
    if (tag.code == 1962) {
      TagVH vh = (TagVH) tag;
      if (vh.className.startsWith("Att")) {
        String lowername = vh.name.toLowerCase();
        if ((vh.nfields == 1) && (H4type.setDataType(vh.fld_type[0], null) == DataType.CHAR)
            && ((vh.fld_isize[0] > 4000) || lowername.startsWith("archivemetadata")
                || lowername.startsWith("coremetadata") || lowername.startsWith("productmetadata")
                || lowername.startsWith("structmetadata"))) {
          root.addVariable(makeVariable(vh)); // // large EOS metadata - make into variable in root group
        } else {
          Attribute att = makeAttribute(vh);
          if (null != att)
            root.addAttribute(att); // make into attribute in root group
        }
      }
    }
  }

  group.used = true;
}
 
Example #3
Source File: GridHorizCoordSys.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Add coordinate system variable
 *
 * @param ncfile netCDF file
 * @param name name of the variable
 * @param dims dimensions
 */
private void addCoordSystemVariable(NetcdfFile ncfile, String name, String dims) {
  Variable v = new Variable(ncfile, g, null, name);
  v.setDataType(DataType.CHAR);
  v.setDimensions(""); // scalar
  Array dataArray = Array.factory(DataType.CHAR, new int[0], new char[] {'0'});
  v.setCachedData(dataArray, false);
  v.addAttribute(new Attribute(_Coordinate.Axes, dims));
  if (isLatLon())
    v.addAttribute(new Attribute(_Coordinate.Transforms, "")); // to make sure its identified as a Coordinate System
                                                               // Variable
  else
    v.addAttribute(new Attribute(_Coordinate.Transforms, getGridName()));
  addGDSparams(v);
  ncfile.addVariable(g, v);
}
 
Example #4
Source File: WriterCFStationCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeRecord(String stnName, double timeCoordValue, CalendarDate obsDate, StructureData sdata)
    throws IOException {
  trackBB(null, obsDate);

  Integer parentIndex = stationIndexMap.get(stnName);
  if (parentIndex == null)
    throw new RuntimeException("Cant find station " + stnName);

  StructureMembers.Builder smb = StructureMembers.builder().setName("Coords");
  smb.addMemberScalar(timeName, null, null, DataType.DOUBLE, timeCoordValue);
  smb.addMemberScalar(stationIndexName, null, null, DataType.INT, parentIndex);
  StructureData coords = new StructureDataFromMember(smb.build());

  // coords first so it takes precedence
  StructureDataComposite sdall = StructureDataComposite.create(ImmutableList.of(coords, sdata));
  obsRecno = super.writeStructureData(obsRecno, record, sdall, dataMap);
}
 
Example #5
Source File: OpendapServlet.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
long computeArraySize(SDArray da) throws Exception {
  assert (da.getContainerVar() instanceof DPrimitive);
  BaseType base = da.getPrimitiveVector().getTemplate();
  DataType dtype = DODSNetcdfFile.convertToNCType(base, false);
  int elemSize = dtype.getSize();
  int n = da.numDimensions();
  List<Range> ranges = new ArrayList<>(n);
  long size = 0;
  for (int i = 0; i < n; i++) {
    ranges.add(new Range(da.getStart(i), da.getStop(i), da.getStride(i)));
  }
  Section s = new Section(ranges);
  size += s.computeSize() * elemSize;

  return size;
}
 
Example #6
Source File: HdfEosModisConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean addTimeCoordinate() {
  // add time coordinate by parsing the filename, of course.
  CalendarDate cd = parseFilenameForDate(datasetBuilder.orgFile.getLocation());
  if (cd == null) {
    return false;
  }

  rootGroup.addAttribute(new Attribute("_MODIS_Date", cd.toString()));

  // add the time dimension
  rootGroup.addDimension(new Dimension(TIME_NAME, 1));

  // add the coordinate variable
  String units = "seconds since " + cd;
  CoordinateAxis.Builder timeCoord = CoordinateAxis1D.builder().setName(TIME_NAME).setDataType(DataType.DOUBLE)
      .setParentGroupBuilder(rootGroup).setDimensionsByName("").setUnits(units).setDesc("time coordinate");
  timeCoord.setAutoGen(0, 0);
  timeCoord.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.Time.toString()));
  datasetBuilder.replaceCoordinateAxis(rootGroup, timeCoord);

  return true;
}
 
Example #7
Source File: NcDDS.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private BaseType createVariable(NetcdfFile ncfile, Variable v) {
  BaseType bt;
  if (v.getRank() == 0) // scalar
    bt = createScalarVariable(ncfile, v);

  else if (v.getDataType() == DataType.CHAR) {
    if (v.getRank() > 1)
      bt = new NcSDCharArray(v);
    else
      bt = new NcSDString(v);

  } else if (v.getDataType() == DataType.STRING) {
    if (v.getRank() == 0)
      bt = new NcSDString(v);
    else
      bt = new NcSDArray(v, new NcSDString(v));

  } else // non-char multidim array
    bt = createArray(ncfile, v);

  return bt;

}
 
Example #8
Source File: TestUnsigned.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testAttWithUnsignedType() throws IOException {
  String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n"
      + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"
      + TestDir.cdmLocalTestDataDir + "testWrite.nc'>\n" + "  <attribute name='gatt' type='ubyte'>1 0 -1</attribute>"
      + "</netcdf>";

  try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null);
      NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) {

    Attribute att = ncd.findGlobalAttribute("gatt");
    Assert.assertNotNull(att);
    Assert.assertEquals(DataType.UBYTE, att.getDataType());

    Assert.assertEquals(3, att.getLength());
    Array gattValues = att.getValues();

    boolean hasSigned = false;
    while (gattValues.hasNext()) {
      short b = gattValues.nextShort();
      if (b < 0)
        hasSigned = true;
    }
    Assert.assertTrue(!hasSigned);
  }
}
 
Example #9
Source File: PointStream.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
ProtobufPointFeatureMaker(PointStreamProto.PointFeatureCollection pfc) {
  try {
    // LOOK No calendar
    dateUnit = CalendarDateUnit.of(null, pfc.getTimeUnit());
  } catch (Exception e) {
    e.printStackTrace();
    dateUnit = CalendarDateUnit.unixDateUnit;
  }

  StructureMembers.Builder builder = StructureMembers.builder().setName(pfc.getName());
  for (PointStreamProto.PointFeatureMember m : pfc.getMembersList()) {
    String name = m.getName();
    String desc = !m.getDesc().isEmpty() ? m.getDesc() : null;
    String units = !m.getUnits().isEmpty() ? m.getUnits() : null;
    DataType dtype = NcStream.convertDataType(m.getDataType());
    int[] shape = NcStream.decodeSection(m.getSection()).getShape();

    builder.addMember(name, desc, units, dtype, shape);
  }
  sm = builder.build();
  ArrayStructureBB.setOffsets(sm);
}
 
Example #10
Source File: CFPointObWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String args[]) throws IOException {

    List<PointObVar> dataVars = new ArrayList<PointObVar>();
    dataVars.add(new PointObVar("test1", "units1", "desc1", DataType.CHAR, 4));
    dataVars.add(new PointObVar("test2", "units2", "desc3", DataType.CHAR, 4));

    // public CFPointObWriter(DataOutputStream stream, List<Attribute> globalAtts, String altUnits, List<PointObVar>
    // dataVars) throws IOException {

    FileOutputStream fos = new FileOutputStream("C:/temp/test.out");
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fos, 10000));

    CFPointObWriter writer = new CFPointObWriter(out, new ArrayList<Attribute>(), "meters", dataVars, 1);

    double[] dvals = new double[0];
    String[] svals = new String[] {"valu", "value"};
    writer.addPoint(1.0, 2.0, 3.0, new Date(), dvals, svals);
    writer.finish();

  }
 
Example #11
Source File: CdmrfReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public GeoReferencedArray decodeGeoReferencedArray(CoverageDataResponse dataResponse,
    CdmrFeatureProto.GeoReferencedArray parray) {
  DataType dataType = NcStream.convertDataType(parray.getDataType());
  ByteOrder byteOrder = parray.getBigend() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
  boolean deflate = parray.getCompress() == NcStreamProto.Compress.DEFLATE;
  long uncompressedSize = parray.getUncompressedSize();

  int[] shape = new int[parray.getShapeCount()];
  for (int i = 0; i < parray.getShapeCount(); i++)
    shape[i] = parray.getShape(i);

  ByteBuffer bb = parray.getPrimdata().asReadOnlyByteBuffer();
  bb.order(byteOrder);
  Array data = Array.factory(dataType, shape, bb);

  CoverageCoordSys csys = dataResponse.findCoordSys(parray.getCoordSysName());
  if (csys == null)
    throw new IllegalStateException("Misformed response - no coordsys");

  return new GeoReferencedArray(parray.getCoverageName(), dataType, data, csys);
}
 
Example #12
Source File: CoverageCoordAxisBuilder.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CoverageCoordAxisBuilder(String name, String units, String description, DataType dataType, AxisType axisType,
    AttributeContainer atts, CoverageCoordAxis.DependenceType dependenceType, String dependsOnS,
    CoverageCoordAxis.Spacing spacing, int ncoords, double startValue, double endValue, double resolution,
    double[] values, CoordAxisReader reader) {
  this.name = name;
  this.units = units;
  this.description = description;
  this.dataType = dataType;
  this.axisType = axisType;
  this.attributes = AttributeContainerMutable.copyFrom(atts);
  this.dependenceType = dependenceType;
  this.setDependsOn(dependsOnS);
  this.spacing = spacing;
  this.ncoords = ncoords;
  this.startValue = startValue;
  this.endValue = endValue;
  this.resolution = resolution;
  this.values = values;
  this.reader = reader;
}
 
Example #13
Source File: TestUnsigned.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testUnsignedWrap() throws IOException {
  String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n"
      + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' location='"
      + TestDir.cdmLocalTestDataDir + "testWrite.nc'>\n" + "  <variable name='bvar' shape='lat' type='byte'>\n"
      + "    <attribute name='_Unsigned' value='true' />\n"
      + "    <attribute name='scale_factor' type='float' value='2.0' />\n" + "   </variable>\n" + "</netcdf>";

  try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), null);
      NetcdfFile ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getEnhanceAll())) {

    Variable v = ncd.findVariable("bvar");
    Assert.assertNotNull(v);
    Assert.assertEquals(DataType.FLOAT, v.getDataType());

    boolean hasSigned = false;
    Array data = v.read();
    while (data.hasNext()) {
      float b = data.nextFloat();
      if (b < 0)
        hasSigned = true;
    }
    Assert.assertTrue(!hasSigned);
  }
}
 
Example #14
Source File: AggregationOuter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected Array read(AggDatasetOuter dset, NetcdfFile ncfile) {
  Array data = getData(dset.getId());
  if (data != null)
    return data;

  Attribute att = ncfile.findGlobalAttribute(gattName);
  if (att == null)
    throw new IllegalArgumentException("Unknown attribute name= " + gattName);
  data = att.getValues();
  if (dtype == null)
    dtype = DataType.getType(data);

  if (dset.ncoord == 1) // LOOK ??
    putData(dset.getId(), data);
  else {
    // duplicate the value to each of the coordinates
    Array allData = Array.factory(dtype, new int[] {dset.ncoord});
    for (int i = 0; i < dset.ncoord; i++)
      Array.arraycopy(data, 0, allData, i, 1); // LOOK generalize to vectors ??
    putData(dset.getId(), allData);
    data = allData;
  }
  return data;
}
 
Example #15
Source File: CFPointWriterUtils.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Array getArrayFromMember(Variable var, Member m) {

    // DataType m_dt = writer.findVariable(m.getName()).getDataType();
    DataType v_dt = var.getDataType();
    // DataType m_dt = m.getDataType();

    // Writes one single data
    // int[] shape = writer.findVariable(m.getName()).getShape();
    int[] shape = var.getShape();

    // Set the shape we really want
    for (int i = 0; i < shape.length; i++) {
      shape[i] = 1;
    }

    Array arr = Array.factory(v_dt, shape);
    setDataArray(v_dt, arr, m);

    return arr;

  }
 
Example #16
Source File: DatasetEnhancer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void enhanceVariable(VariableDS.Builder vb) {
  Set<Enhance> varEnhance = EnumSet.copyOf(wantEnhance);

  // varEnhance will only contain enhancements not already applied to orgVar.
  if (vb.orgVar instanceof VariableDS) {
    for (Enhance orgVarEnhancement : ((VariableDS) vb.orgVar).getEnhanceMode()) {
      varEnhance.remove(orgVarEnhancement);
    }
  }

  // enhance() may have been called previously, with a different enhancement set.
  // So, we need to reset to default before we process this new set.
  if (vb.orgDataType != null) {
    vb.setDataType(vb.orgDataType);
  }

  if (varEnhance.contains(Enhance.ConvertEnums) && vb.dataType.isEnum()) {
    vb.setDataType(DataType.STRING);
  }

  vb.addEnhanceMode(varEnhance);
}
 
Example #17
Source File: EnumTypedef.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Make an EnumTypedef setting the base type (must be ENUM1, ENUM2, ENUM4). */
public EnumTypedef(String name, Map<Integer, String> map, DataType basetype) {
  super(name);
  Preconditions.checkArgument(validateMap(map, basetype));
  this.map = ImmutableMap.copyOf(map);

  enumStrings = ImmutableList.sortedCopyOf(map.values());

  assert basetype == DataType.ENUM1 || basetype == DataType.ENUM2 || basetype == DataType.ENUM4;
  this.basetype = basetype;
}
 
Example #18
Source File: TestDataTemplate.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testPngBitmap() throws IOException {
  final String testfile = "../grib/src/test/data/HLYA10.grib2";
  try (NetcdfFile nc = NetcdfFiles.open(testfile)) {
    Variable var = nc.findVariable("VAR0-19-223_FROM_7-212--1_isobaric");
    float[] data = (float[]) var.read().get1DJavaArray(DataType.FLOAT);

    Assert.assertEquals(0.36976, data[13], 1e-5);
    Assert.assertTrue(Double.isNaN(data[15]));
  }
}
 
Example #19
Source File: StringIndex.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Equal operation
 * @param v The value
 * @return Boolean array
 */
public Array equal(String v) {
    Array r = Array.factory(DataType.BOOLEAN, new int[]{this.size()});
    int i = 0;
    for (String d : this.data) {
        r.setBoolean(i, d.equals(v));
        i += 1;
    }
    
    return r;
}
 
Example #20
Source File: WriterCFStationProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void makeFeatureVariables(StructureData stnData, boolean isExtended) {
  // add the dimensions : extended model can use an unlimited dimension
  Dimension stationDim = writerb.addDimension(stationDimName, stnList.size());

  List<VariableSimpleIF> stnVars = new ArrayList<>();
  stnVars.add(VariableSimpleBuilder.makeScalar(latName, "station latitude", CDM.LAT_UNITS, DataType.DOUBLE).build());
  stnVars.add(VariableSimpleBuilder.makeScalar(lonName, "station longitude", CDM.LON_UNITS, DataType.DOUBLE).build());

  if (useAlt) {
    stnVars.add(VariableSimpleBuilder.makeScalar(stationAltName, "station altitude", altUnits, DataType.DOUBLE)
        .addAttribute(CF.STANDARD_NAME, CF.SURFACE_ALTITUDE)
        .addAttribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)).build());
  }

  stnVars.add(VariableSimpleBuilder.makeString(stationIdName, "station identifier", null, id_strlen)
      .addAttribute(CF.CF_ROLE, CF.TIMESERIES_ID).build()); // station_id:cf_role = "timeseries_id";

  if (useDesc)
    stnVars.add(VariableSimpleBuilder.makeString(descName, "station description", null, desc_strlen)
        .addAttribute(CF.STANDARD_NAME, CF.PLATFORM_NAME).build());

  if (useWmoId)
    stnVars.add(VariableSimpleBuilder.makeString(wmoName, "station WMO id", null, wmo_strlen)
        .addAttribute(CF.STANDARD_NAME, CF.PLATFORM_ID).build());

  for (StructureMembers.Member m : stnData.getMembers()) {
    if (findDataVar(m.getName()) != null)
      stnVars.add(VariableSimpleBuilder.fromMember(m).build());
  }

  if (isExtended) {
    Structure.Builder structb = writerb.addStructure(stationStructName, stationDimName);
    addCoordinatesExtended(structb, stnVars);
  } else {
    addCoordinatesClassic(stationDim, stnVars, stationVarMap);
  }

}
 
Example #21
Source File: H5headerNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Variable.Builder makeVariableMember(Group.Builder parentGroup, String name, long dataPos, MessageDatatype mdt)
    throws IOException {

  Vinfo vinfo = new Vinfo(mdt, null, dataPos); // LOOK need mds
  if (vinfo.getNCDataType() == null) {
    log.debug("SKIPPING DataType= " + vinfo.typeInfo.hdfType + " for variable " + name);
    return null;
  }

  if (mdt.type == 6) {
    Structure.Builder sb = Structure.builder().setName(name).setParentGroupBuilder(parentGroup);
    makeVariableShapeAndType(parentGroup, sb, mdt, null, vinfo, null);
    addMembersToStructure(parentGroup, sb, mdt);
    sb.setElementSize(mdt.byteSize);

    sb.setSPobject(vinfo);
    vinfo.setOwner(sb);
    return sb;

  } else {
    Variable.Builder vb = Variable.builder().setName(name).setParentGroupBuilder(parentGroup);
    makeVariableShapeAndType(parentGroup, vb, mdt, null, vinfo, null);

    // special case of variable length strings
    if (vb.dataType == DataType.STRING)
      vb.setElementSize(16); // because the array has elements that are HeapIdentifier
    else if (vb.dataType == DataType.OPAQUE) // special case of opaque
      vb.setElementSize(mdt.getBaseSize());

    vb.setSPobject(vinfo);
    vinfo.setOwner(vb);
    return vb;
  }
}
 
Example #22
Source File: StandardFields.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void extract(StructureData sdata) {
  StructureMembers sm = sdata.getStructureMembers();
  for (Field fld : map.values()) {
    StructureMembers.Member m = sm.findMember(fld.memberName);
    DataType dtype = m.getDataType();
    if (dtype.isString())
      fld.valueS = sdata.getScalarString(m).trim();
    else if (dtype.isIntegral()) {
      fld.value = sdata.convertScalarInt(m);
      fld.valueD = fld.value;
    } else if (dtype.isNumeric())
      fld.valueD = sdata.convertScalarDouble(m);
  }
}
 
Example #23
Source File: AggregationOuterDimension.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void promoteGlobalAttributes(DatasetOuterDimension typicalDataset) throws IOException {

    for (CacheVar cv : cacheList) {
      if (!(cv instanceof PromoteVar))
        continue;
      PromoteVar pv = (PromoteVar) cv;

      Array data = pv.read(typicalDataset);
      if (data == null)
        throw new IOException("cant read " + typicalDataset);

      pv.dtype = DataType.getType(data);
      VariableDS promotedVar = new VariableDS(ncDataset, null, null, pv.varName, pv.dtype, dimName, null, null);
      /*
       * if (data.getSize() > 1) { // LOOK case of non-scalar global attribute not delat with
       * Dimension outer = ncDataset.getRootGroup().findDimension(dimName);
       * Dimension inner = new Dimension("", (int) data.getSize(), false); //anonymous
       * List<Dimension> dims = new ArrayList<Dimension>(2);
       * dims.add(outer);
       * dims.add(inner);
       * promotedVar.setDimensions(dims);
       * }
       */

      ncDataset.addVariable(null, promotedVar);
      promotedVar.setProxyReader(this);
      promotedVar.setSPobject(pv);
    }
  }
 
Example #24
Source File: Giniheader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private double readScaledInt(ByteBuffer buf) {
  // Get the first two bytes
  short s1 = buf.getShort();

  // And the last one as unsigned
  short s2 = DataType.unsignedByteToShort(buf.get());

  // Get the sign bit, converting from 0 or 2 to +/- 1.
  int posneg = 1 - ((s1 & 0x8000) >> 14);

  // Combine the first two bytes (without sign bit) with the last byte.
  // Multiply by proper factor for +/-
  int nn = (((s1 & 0x7FFF) << 8) | s2) * posneg;
  return (double) nn / 10000.0;
}
 
Example #25
Source File: WriterCFProfileCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void makeFeatureVariables(StructureData featureData, boolean isExtended) {

  // LOOK why not unlimited here ?
  Dimension profileDim = writerb.addDimension(profileDimName, nfeatures);

  // add the profile Variables using the profile dimension
  List<VariableSimpleIF> profileVars = new ArrayList<>();
  profileVars
      .add(VariableSimpleBuilder.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE).build());
  profileVars
      .add(VariableSimpleBuilder.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE).build());
  profileVars.add(VariableSimpleBuilder.makeString(profileIdName, "profile identifier", null, id_strlen)
      .addAttribute(CF.CF_ROLE, CF.PROFILE_ID).build()); // profileId:cf_role = "profile_id";

  profileVars
      .add(VariableSimpleBuilder.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT)
          .addAttribute(CF.SAMPLE_DIMENSION, recordDimName).build()); // rowSize:sample_dimension = "obs"

  profileVars.add(VariableSimpleBuilder
      .makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE)
      .addAttribute(CF.CALENDAR, timeUnit.getCalendar().toString()).build());


  for (StructureMembers.Member m : featureData.getMembers()) {
    VariableSimpleIF dv = findDataVar(m.getName());
    if (dv != null)
      profileVars.add(dv);
  }

  if (isExtended) {
    Structure.Builder structb = writerb.addStructure(profileStructName, profileDimName);
    addCoordinatesExtended(structb, profileVars);
  } else {
    addCoordinatesClassic(profileDim, profileVars, featureVarMap);
  }
}
 
Example #26
Source File: GeoReferencedArray.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GeoReferencedArray(String coverageName, DataType dataType, Array data, CoverageCoordSys csSubset) {
  this.coverageName = coverageName;
  this.dataType = dataType;
  this.data = data;
  this.csSubset = csSubset;
  this.axes = csSubset.getAxes();
  this.transforms = csSubset.getTransforms();
}
 
Example #27
Source File: NetcdfCopier.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Array convertDataToChar(Variable newVar, Array oldData) {
  ArrayChar newData = (ArrayChar) Array.factory(DataType.CHAR, newVar.getShape());
  Index ima = newData.getIndex();
  IndexIterator ii = oldData.getIndexIterator();
  while (ii.hasNext()) {
    String s = (String) ii.getObjectNext();
    int[] c = ii.getCurrentCounter();
    for (int i = 0; i < c.length; i++) {
      ima.setDim(i, c[i]);
    }
    newData.setString(ima, s);
  }
  return newData;
}
 
Example #28
Source File: Grib2DataPanel.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void toRawPdsString(Formatter f) {
  byte[] bytes = gr.getPDSsection().getRawBytes();
  int count = 1;
  for (byte b : bytes) {
    short s = DataType.unsignedByteToShort(b);
    f.format(" %d : %d%n", count++, s);
  }
}
 
Example #29
Source File: FmrcDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private VariableDS makeRunTimeCoordinate(NetcdfDataset result, Group group, String dimName, CalendarDate base,
    double[] values) {
  DataType dtype = DataType.DOUBLE;
  VariableDS timeVar = new VariableDS(result, group, null, dimName + "_run", dtype, dimName, null, null); // LOOK
                                                                                                          // could
                                                                                                          // just make
                                                                                                          // a
                                                                                                          // CoordinateAxis1D
  timeVar.addAttribute(new Attribute(CDM.LONG_NAME, "run times for coordinate = " + dimName));
  timeVar.addAttribute(new ucar.nc2.Attribute("standard_name", "forecast_reference_time"));
  timeVar.addAttribute(new ucar.nc2.Attribute(CF.CALENDAR, base.getCalendar().name()));
  // timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base));
  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.UNITS, "hours since " + base.getTimeUnits()));

  timeVar.addAttribute(new ucar.nc2.Attribute(CDM.MISSING_VALUE, Double.NaN));
  timeVar.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, AxisType.RunTime.toString())); // if theres
                                                                                                   // already a time
                                                                                                   // coord, dont put
                                                                                                   // in coordSys -
                                                                                                   // too complicated

  // construct the values
  int ntimes = values.length;
  ArrayDouble.D1 timeCoordVals = (ArrayDouble.D1) Array.factory(DataType.DOUBLE, new int[] {ntimes}, values);
  timeVar.setCachedData(timeCoordVals);
  group.addVariable(timeVar);

  return timeVar;
}
 
Example #30
Source File: Coverage.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Coverage(String name, DataType dataType, Iterable<Attribute> atts, String coordSysName, String units,
    String description, CoverageReader reader, Object user) {
  this.name = name;
  this.dataType = dataType;
  this.atts = new AttributeContainerMutable(name, atts);
  this.coordSysName = coordSysName;
  this.units = units;
  this.description = description;
  this.reader = reader;
  this.user = user;
}