Java Code Examples for ucar.nc2.NetcdfFile#findGlobalAttribute()

The following examples show how to use ucar.nc2.NetcdfFile#findGlobalAttribute() . 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: AggregationOuterDimension.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected Array read(DatasetOuterDimension 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 2
Source File: AggregationOuterDimension.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected Array read(DatasetOuterDimension dset, NetcdfFile ncfile) {
  Array data = getData(dset.getId());
  if (data != null)
    return data;

  List<Object> vals = new ArrayList<>();
  for (String gattName : gattNames) {
    Attribute att = ncfile.findGlobalAttribute(gattName);
    if (att == null)
      throw new IllegalArgumentException("Unknown attribute name= " + gattName);
    vals.add(att.getValue(0));
  }

  Formatter f = new Formatter();
  f.format(format, vals.toArray());
  String result = f.toString();

  Array allData = Array.factory(dtype, new int[] {dset.ncoord});
  for (int i = 0; i < dset.ncoord; i++)
    allData.setObject(i, result);
  putData(dset.getId(), allData);
  return allData;
}
 
Example 3
Source File: Suomi.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param ncfile the NetcdfFile to test
 * @return true if we think this is a Zebra file.
 */
public static boolean isMine(NetcdfFile ncfile) {

  Variable v = ncfile.findVariable("time_offset");
  if (v == null || !v.isCoordinateVariable())
    return false;
  String desc = v.getDescription();
  if (desc == null || (!desc.equals("Time delta from start_time")
      && !desc.equals("PWV window midpoint time delta from start_time")))
    return false;

  if (null == ncfile.findGlobalAttribute("start_date"))
    return false;
  return null != ncfile.findGlobalAttribute("start_time");

}
 
Example 4
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 5
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;

  List<Object> vals = new ArrayList<>();
  for (String gattName : gattNames) {
    Attribute att = ncfile.findGlobalAttribute(gattName);
    if (att == null)
      throw new IllegalArgumentException("Unknown attribute name= " + gattName);
    vals.add(att.getValue(0));
  }

  Formatter f = new Formatter();
  f.format(format, vals.toArray());
  String result = f.toString();

  Array allData = Array.factory(dtype, new int[] {dset.ncoord});
  for (int i = 0; i < dset.ncoord; i++)
    allData.setObject(i, result);
  putData(dset.getId(), allData);
  return allData;
}
 
Example 6
Source File: WRFConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean isMine(NetcdfFile ncfile) {
  if (null == ncfile.findDimension("south_north"))
    return false;

  // ARW only
  int dynOpt = ncfile.getRootGroup().attributes().findAttributeInteger("DYN_OPT", -1);
  if (dynOpt != -1 && dynOpt != 2) { // if it exists, it must equal 2.
    return false;
  } else {
    String gridType = ncfile.getRootGroup().findAttributeString("GRIDTYPE", "null");
    if (!gridType.equalsIgnoreCase("null") && !gridType.equalsIgnoreCase("C") && !gridType.equalsIgnoreCase("E"))
      return false;
  }
  return ncfile.findGlobalAttribute("MAP_PROJ") != null;
}
 
Example 7
Source File: AWIPSSatConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isMine(NetcdfFile ncfile) {
  return (null != ncfile.findGlobalAttribute("projName")) && (null != ncfile.findGlobalAttribute("lon00"))
      && (null != ncfile.findGlobalAttribute("lat00")) && (null != ncfile.findGlobalAttribute("lonNxNy"))
      && (null != ncfile.findGlobalAttribute("latNxNy")) && (null != ncfile.findGlobalAttribute("centralLon"))
      && (null != ncfile.findGlobalAttribute("centralLat")) && (null != ncfile.findDimension("x"))
      && (null != ncfile.findDimension("y")) && (null != ncfile.findVariable("image"));
}
 
Example 8
Source File: Suomi.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isMine(NetcdfFile ncfile) {
  Variable v = ncfile.findVariable("time_offset");
  if (v == null || !v.isCoordinateVariable())
    return false;
  String desc = v.getDescription();
  if (desc == null || (!desc.equals("Time delta from start_time")
      && !desc.equals("PWV window midpoint time delta from start_time")))
    return false;

  if (null == ncfile.findGlobalAttribute("start_date"))
    return false;
  return null != ncfile.findGlobalAttribute("start_time");
}
 
Example 9
Source File: BufrConfig.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void scanBufrFile(RandomAccessFile raf) throws Exception {
  NetcdfFile ncd = null;
  countObs = 0;

  try {
    MessageScanner scanner = new MessageScanner(raf);
    Message protoMessage = scanner.getFirstDataMessage();
    if (protoMessage == null)
      throw new IOException("No message found!");

    messHash = protoMessage.hashCode();
    standardFields = StandardFields.extract(protoMessage);
    rootConverter = new FieldConverter(protoMessage.ids.getCenterId(), protoMessage.getRootDataDescriptor());

    if (standardFields.hasStation()) {
      hasStations = true;
      map = new HashMap<>(1000);
    }
    featureType = guessFeatureType(standardFields);
    hasDate = standardFields.hasTime();

    ncd = NetcdfFiles.open(raf.getLocation()); // LOOK opening another raf
    Attribute centerAtt = ncd.findGlobalAttribute(BufrIosp2.centerId);
    int center = (centerAtt == null) ? 0 : centerAtt.getNumericValue().intValue();

    Sequence seq = (Sequence) ncd.getRootGroup().findVariableLocal(BufrIosp2.obsRecordName);
    extract = new StandardFields.StandardFieldsFromStructure(center, seq);

    StructureDataIterator iter = seq.getStructureIterator();
    processSeq(iter, rootConverter, true);

    setStandardActions(rootConverter);

  } finally {
    if (ncd != null)
      ncd.close();
  }
}
 
Example 10
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param ncfile the NetcdfFile to test
 * @return true if we think this is a AWIPS file.
 */
public static boolean isMine(NetcdfFile ncfile) {
  return (null != ncfile.findGlobalAttribute("projName")) && (null != ncfile.findDimension("charsPerLevel"))
      && (null != ncfile.findDimension("x")) && (null != ncfile.findDimension("y"));
}
 
Example 11
Source File: AWIPSConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean isMine(NetcdfFile ncfile) {
  return (null != ncfile.findGlobalAttribute("projName")) && (null != ncfile.findDimension("charsPerLevel"))
      && (null != ncfile.findDimension("x")) && (null != ncfile.findDimension("y"));
}
 
Example 12
Source File: M3IOConvention.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean isMine(NetcdfFile ncfile) {
  return (null != ncfile.findGlobalAttribute("XORIG")) && (null != ncfile.findGlobalAttribute("YORIG"))
      && (null != ncfile.findGlobalAttribute("XCELL")) && (null != ncfile.findGlobalAttribute("YCELL"))
      && (null != ncfile.findGlobalAttribute("NCOLS")) && (null != ncfile.findGlobalAttribute("NROWS"));
}