本文整理汇总了Java中ucar.ma2.DataType.FLOAT属性的典型用法代码示例。如果您正苦于以下问题:Java DataType.FLOAT属性的具体用法?Java DataType.FLOAT怎么用?Java DataType.FLOAT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ucar.ma2.DataType
的用法示例。
在下文中一共展示了DataType.FLOAT属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
int varIdx = this._fieldList.indexOf(varName);
if (varIdx < 0) {
return null;
}
int[] shape = new int[1];
shape[0] = this.stNum;
DataType dt = DataType.FLOAT;
if (varName.equals("Stid"))
dt = DataType.STRING;
Array r = Array.factory(dt, shape);
List<String> dataList;
for (int i = 0; i < _dataList.size(); i++) {
dataList = _dataList.get(i);
r.setFloat(i, Float.parseFloat(dataList.get(varIdx)));
}
return r;
}
示例2: arrayRange1
/**
* Array range
*
* @param start Start value
* @param length Length
* @param step Step value
* @return Array
*/
public static Array arrayRange1(Number start, final int length, final Number step) {
DataType dataType = ArrayUtil.objectsToType(new Object[]{
start,
step});
double startv = start.doubleValue();
double stepv = step.doubleValue();
Array a = Array.factory(dataType, new int[]{length});
if (dataType == DataType.FLOAT || dataType == DataType.DOUBLE) {
for (int i = 0; i < length; i++) {
a.setObject(i, BigDecimalUtil.add(BigDecimalUtil.mul(i, stepv), startv));
}
} else {
for (int i = 0; i < length; i++) {
a.setObject(i, i * stepv + startv);
}
}
return a;
}
示例3: netcdfTypeFromJDBCType
public DataType netcdfTypeFromJDBCType(int col, ResultSetMetaData resultSetMetadata) throws SQLException {
int columnType = resultSetMetadata.getColumnType(col);
if (columnType == Types.DOUBLE) {
return DataType.DOUBLE;
} else if ( columnType == Types.FLOAT) {
return DataType.FLOAT;
} else if ( columnType == Types.REAL) {
return DataType.FLOAT;
} else if ( columnType == Types.INTEGER) {
return DataType.INT;
} else if ( columnType == Types.DECIMAL) {
return DataType.FLOAT;
} else if ( columnType == Types.SMALLINT) {
return DataType.SHORT;
} else if ( columnType == Types.TINYINT) {
return DataType.BYTE;
} else if ( columnType == Types.NUMERIC) {
if ( resultSetMetadata.getScale(col) < 0) {
return DataType.DOUBLE;
}
else if ( resultSetMetadata.getScale(col) > 0 &&
resultSetMetadata.getPrecision(col) > 0 ) {
return DataType.DOUBLE;
} else if ( resultSetMetadata.getScale(col) == 0 &&
resultSetMetadata.getPrecision(col) > 0 ) {
return DataType.INT;
} else {
return DataType.DOUBLE;
}
} else if ( columnType == Types.CHAR || columnType == Types.VARCHAR) {
return DataType.CHAR;
} else {
return DataType.CHAR;
}
}
示例4: arrayRange
/**
* Array range
*
* @param start Start value
* @param stop Stop value
* @param step Step value
* @return Array
*/
public static Array arrayRange(Number start, Number stop, final Number step) {
if (stop == null) {
stop = start;
start = 0;
}
DataType dataType = ArrayUtil.objectsToType(new Object[]{
start,
stop,
step});
double startv = start.doubleValue();
double stopv = stop.doubleValue();
double stepv = step.doubleValue();
List<Object> data = new ArrayList<>();
if (dataType == DataType.FLOAT || dataType == DataType.DOUBLE) {
while (startv < stopv) {
data.add(startv);
startv = BigDecimalUtil.add(startv, stepv);
}
} else {
while (startv < stopv) {
data.add(startv);
startv += stepv;
}
}
int length = data.size();
Array a = Array.factory(dataType, new int[]{length});
for (int i = 0; i < length; i++){
a.setObject(i, data.get(i));
}
return a;
}
示例5: arrayRange_bak
/**
* Array range
*
* @param start Start value
* @param stop Stop value
* @param step Step value
* @return Array
*/
public static Array arrayRange_bak(Number start, Number stop, final Number step) {
if (stop == null) {
stop = start;
start = 0;
}
DataType dataType = ArrayUtil.objectsToType(new Object[]{
start,
stop,
step});
double startv = start.doubleValue();
double stopv = stop.doubleValue();
double stepv = step.doubleValue();
final int length = Math.max(0, (int) Math.ceil((stopv
- startv) / stepv));
Array a = Array.factory(dataType, new int[]{length});
if (dataType == DataType.FLOAT || dataType == DataType.DOUBLE) {
for (int i = 0; i < length; i++) {
a.setObject(i, BigDecimalUtil.add(BigDecimalUtil.mul(i, stepv), startv));
}
} else {
for (int i = 0; i < length; i++) {
a.setObject(i, i * stepv + startv);
}
}
return a;
}
示例6: toDataType
/**
* To data type - ucar.ma2
*
* @param dt Data type string
* @return Data type
*/
public static DataType toDataType(String dt) {
if (dt.contains("%")) {
dt = dt.split("%")[1];
}
switch (dt.toLowerCase()) {
case "c":
case "s":
case "string":
return DataType.STRING;
case "b":
case "byte":
return DataType.BYTE;
case "short":
return DataType.SHORT;
case "i":
case "int":
return DataType.INT;
case "f":
case "float":
return DataType.FLOAT;
case "d":
case "double":
return DataType.DOUBLE;
default:
return DataType.OBJECT;
}
}
示例7: getDataType
/**
* Get data type
*
* @param o Object
* @return Data type
*/
public static DataType getDataType(Object o) {
if (o instanceof Integer) {
return DataType.INT;
} else if (o instanceof Float) {
return DataType.FLOAT;
} else if (o instanceof Double) {
return DataType.DOUBLE;
} else {
return DataType.OBJECT;
}
}
示例8: read
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
int varIdx = this._fieldList.indexOf(varName);
if (varIdx < 0) {
return null;
}
DataType dt = DataType.FLOAT;
switch (varName) {
case "Stid":
dt = DataType.STRING;
break;
case "Grade":
dt = DataType.INT;
break;
}
int[] shape = new int[1];
shape[0] = this.stNum;
Array r = Array.factory(dt, shape);
int i;
float v;
List<String> dataList;
//List<List<String>> allDataList = this.readData();
for (i = 0; i < this.stNum; i++) {
dataList = this._dataList.get(i);
switch (dt) {
case STRING:
r.setObject(i, dataList.get(varIdx));
break;
case INT:
int vi = Integer.parseInt(dataList.get(varIdx));
r.setInt(i, vi);
break;
case FLOAT:
v = Float.parseFloat(dataList.get(varIdx));
r.setFloat(i, v);
break;
}
}
return r;
}
示例9: read
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
int varIdx = this._fieldList.indexOf(varName);
if (varIdx < 0)
return null;
DataType dt = DataType.FLOAT;
switch (varName){
case "Stid":
dt = DataType.STRING;
break;
case "Grade":
dt = DataType.INT;
break;
}
int[] shape = new int[1];
shape[0] = this.stNum;
Array r = Array.factory(dt, shape);
int i;
float v;
List<String> dataList;
for (i = 0; i < _dataList.size(); i++) {
dataList = _dataList.get(i);
switch (dt) {
case STRING:
r.setObject(i, dataList.get(varIdx));
break;
case INT:
int vi = Integer.parseInt(dataList.get(varIdx));
r.setInt(i, vi);
break;
case FLOAT:
v = Float.parseFloat(dataList.get(varIdx));
r.setFloat(i, v);
break;
}
}
return r;
}
示例10: read
/**
* Read array data of the variable
*
* @param varName Variable name
* @param origin The origin array
* @param size The size array
* @param stride The stride array
* @return Array data
*/
@Override
public Array read(String varName, int[] origin, int[] size, int[] stride) {
int varIdx = this._fieldList.indexOf(varName);
if (varIdx < 0) {
return null;
}
DataType dt = DataType.FLOAT;
switch (varName) {
case "Stid":
dt = DataType.STRING;
break;
case "Grade":
case "CloudCover":
case "WeatherPast1":
case "WeatherPast2":
case "WeatherNow":
case "MiddleCloudShape":
case "HighCloudShape":
dt = DataType.INT;
break;
}
int[] shape = new int[1];
shape[0] = this._stNum;
Array r = Array.factory(dt, shape);
int i;
float v;
List<String> dataList;
List<List<String>> allDataList = this.readData();
for (i = 0; i < allDataList.size(); i++) {
dataList = allDataList.get(i);
switch (dt) {
case STRING:
r.setObject(i, dataList.get(varIdx));
break;
case INT:
int vi = Integer.parseInt(dataList.get(varIdx));
r.setInt(i, vi);
break;
case FLOAT:
v = Float.parseFloat(dataList.get(varIdx));
if (varIdx == 8) //Pressure
{
if (!MIMath.doubleEquals(v, this.getMissingValue())) {
if (v > 800) {
v = v / 10 + 900;
} else {
v = v / 10 + 1000;
}
}
}
r.setFloat(i, v);
break;
}
}
try {
r = r.section(origin, shape, stride);
} catch (InvalidRangeException ex) {
Logger.getLogger(MICAPS1DataInfo.class.getName()).log(Level.SEVERE, null, ex);
}
return r;
}