本文整理汇总了Java中ucar.nc2.Attribute.isString方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.isString方法的具体用法?Java Attribute.isString怎么用?Java Attribute.isString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ucar.nc2.Attribute
的用法示例。
在下文中一共展示了Attribute.isString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStringValue
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* Reads the value of an attribute of a variable and returns its value as a string.
*
* @param attribute a NetCDF attribute.
* @param variable a NetCDF variable.
*
* @return value of the attribute
*
* @throws NetCdfAttributeException invalid request (see error message).
*/
public static String getStringValue(Variable variable, Attribute attribute) throws NetCdfAttributeException {
String value = null;
if (attribute == null) {
return value;
}
if (!attribute.isString()) {
throw new NetCdfAttributeException(
variable,
attribute,
String.format("Error in getStringValue - Unable to get string value from attribute - Attribute type (%s) is not STRING ",
attribute.getDataType().toString()));
}
value = attribute.getStringValue();
if (value == null) {
throw new NetCdfAttributeException(variable, attribute, "Error in getStringValue - Unable to get string value from attribute");
}
return value;
}
示例2: isUgrid
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* Looks inside a NetCDF dataset to determine whether it follows the UGRID
* conventions.
*
* @param nc
* The dataset
* @return <code>true</code> if this is a UGRID dataset
*/
private static boolean isUgrid(NetcdfDataset nc) {
/*
* First find the variable containing the "cf_role = mesh_topology"
* attribute. This is what defines that we are working with a UGRID
* dataset.
*/
List<Variable> variables = nc.getVariables();
Variable meshTopology = null;
for (Variable var : variables) {
Attribute cfRole = var.findAttribute("cf_role");
if (cfRole != null && cfRole.isString()
&& cfRole.getStringValue().equalsIgnoreCase("mesh_topology")) {
meshTopology = var;
break;
}
}
return meshTopology != null;
}
示例3: isSgrid
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* Looks inside a NetCDF dataset to determine whether it follows the SGRID
* conventions.
*
* @param nc
* The dataset
* @return <code>true</code> if this is a SGRID dataset
*/
private static boolean isSgrid(NetcdfDataset nc) {
/*
* First find the variable containing the "cf_role = grid_topology"
* attribute. This is what defines that we are working with a UGRID
* dataset.
*/
List<Variable> variables = nc.getVariables();
Variable gridTopology = null;
for (Variable var : variables) {
Attribute cfRole = var.findAttribute("cf_role");
if (cfRole != null && cfRole.isString()
&& cfRole.getStringValue().equalsIgnoreCase("grid_topology")) {
gridTopology = var;
break;
}
}
return gridTopology != null;
}
示例4: writeGlobalAttribute
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* Write a global attribute to the file.
*
* @param att take attribute name, value, from here
*/
public void writeGlobalAttribute(Attribute att) {
if (att.isArray()) {
ncfile.addGlobalAttribute(att.getName(), att.getValues());
} else if (att.isString()) {
ncfile.addGlobalAttribute(att.getName(), att.getStringValue());
} else {
ncfile.addGlobalAttribute(att.getName(), att.getNumericValue());
}
}
示例5: writeAttribute
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* Write a Variable attribute to the file.
*
* @param varName name of variable to attach attribute to
* @param att take attribute name, value, from here
*/
public void writeAttribute(String varName, Attribute att) {
long d1 = System.nanoTime();
if (att.isArray()) {
ncfile.addVariableAttribute(varName, att.getName(), att.getValues());
} else if (att.isString()) {
ncfile.addVariableAttribute(varName, att.getName(), att.getStringValue());
} else {
ncfile.addVariableAttribute(varName, att.getName(), att.getNumericValue());
}
long d2 = System.nanoTime();
this.writingTime += (d2 - d1);
}
示例6: getFileMetadata
import ucar.nc2.Attribute; //导入方法依赖的package包/类
/**
* <p>
* Devuelve la información obtenida de los atributos del archivo
* NetCDF
* </p>
* .
*
* @return información de metadatos
*/
public String[] getFileMetadata() {
if (fileDataSet == null)
return new String[0];
// Crea la lista de metadatos
ArrayList<String> metadata = new ArrayList<String>();
// Toma todos los atributos del archivo NetCDF
List<Attribute> attrs = fileDataSet.getGlobalAttributes();
// Recorre todos los atributos del archivo
for (Attribute attr : attrs) {
// Nombre del atributo
StringBuilder sb = new StringBuilder();
sb.append(attr.getName());
sb.append("=");
// El valor del atributo es de tipo cadena
if (attr.isString()) {
sb.append(attr.getStringValue(0));
// Verifica si el valor del atributo es un arreglo
for (int i = 0; i < attr.getLength(); ++i) {
sb.append(",");
sb.append(attr.getStringValue(i));
}
// El valor del atributo es de tipo numérico
} else {
sb.append(attr.getNumericValue(0).doubleValue());
// Verifica si el valor del atributo es un arreglo
for (int i = 0; i < attr.getLength(); ++i) {
sb.append(",");
sb.append(attr.getNumericValue(i).doubleValue());
}
}
metadata.add(sb.toString());
}
return metadata.toArray(new String[0]);
}