mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
support MatLab data file
This commit is contained in:
parent
bf9560c197
commit
21b0e80ffd
14
.idea/inspectionProfiles/Project_Default.xml
generated
14
.idea/inspectionProfiles/Project_Default.xml
generated
@ -507,7 +507,9 @@
|
||||
<inspection_tool class="AtomicFieldUpdaterIssues" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="AtomicFieldUpdaterNotStaticFinal" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="AutoBoxing" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,us.hebi.matlab.mat.format.Mat5,readFromFile,us.hebi.matlab.mat.format.Mat5Reader,readMat" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="AutoUnboxing" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="AwaitNotInLoop" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="AwaitWithoutCorrespondingSignal" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
@ -582,6 +584,7 @@
|
||||
<inspection_tool class="CheckForOutOfMemoryOnLargeArrayAllocation" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="CheckImageSize" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="CheckNodeTest" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CheckStyle" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="CheckTagEmptyBody" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CheckValidXmlInScriptTagBody" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
<inspection_tool class="CheckXmlFileWithXercesValidator" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
@ -879,6 +882,7 @@
|
||||
<inspection_tool class="FieldNotUsedInToString" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="FileEqualsUsage" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="FillPermitsList" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||
<inspection_tool class="FilterIsInstanceCallWithClassLiteralArgument" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="FinalClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="FinalMethod" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="FinalMethodInFinalClass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
@ -1748,10 +1752,12 @@
|
||||
<inspection_tool class="PyMissingTypeHintsInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyNamedTupleInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyNestedDecoratorsInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyNewStyleGenericSyntaxInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyNonAsciiCharInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyNoneFunctionAssignmentInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyOldStyleClassesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyOverloadsInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyOverridesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
@ -1789,6 +1795,7 @@
|
||||
<inspection_tool class="PyStubPackagesCompatibilityInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PySuperArgumentsInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTestParametrizedInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTestUnpassedFixtureInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTrailingSemicolonInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTupleAssignmentBalanceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTupleItemAssignmentInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
@ -1806,6 +1813,7 @@
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnusedLocalInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyVulnerableApiCodeInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyprojectInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="QodanaSanity" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
<inspection_tool class="QodanaServiceMessage" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
@ -1837,6 +1845,7 @@
|
||||
<inspection_tool class="RedundantConstructorKeyword" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="RedundantElseInIf" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||
<inspection_tool class="RedundantElvisReturnNull" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="RedundantEmbeddedExpression" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="RedundantEmptyInitializerBlock" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="RedundantEnumConstructorInvocation" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="RedundantEscapeInRegexReplacement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
@ -1996,6 +2005,7 @@
|
||||
<inspection_tool class="SecondUnsafeCall" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SelfAssignment" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SelfReferenceConstructorParameter" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SequencedCollectionMethodCanBeUsed" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SerialAnnotationUsedOnWrongMember" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="SerialPersistentFieldsWithWrongSignature" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SerialVersionUIDNotStaticFinal" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
@ -2095,6 +2105,7 @@
|
||||
<inspection_tool class="StringOperationCanBeSimplified" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringRepeatCanBeUsed" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringReplaceableByStringBuffer" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringTemplateMigration" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringToUpperWithoutLocale" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringTokenizer" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="StringTokenizerDelimiter" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
@ -2158,6 +2169,7 @@
|
||||
<inspection_tool class="SyntaxError" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
<inspection_tool class="SystemExit" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SystemGC" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SystemGetProperty" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SystemGetenv" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SystemOutErr" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SystemProperties" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
|
||||
@ -2010,6 +2010,7 @@ public class GLPlot extends Plot {
|
||||
}
|
||||
float x1 = (xMin + xMax) / 2;
|
||||
drawString(gl, label, x1, y1, zMin, XAlign.CENTER, yAlign, angle, 0, yShift);
|
||||
//drawString(gl, label, x1, y1, zMin, XAlign.CENTER, yAlign, 0, yShift);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2097,6 +2098,7 @@ public class GLPlot extends Plot {
|
||||
}
|
||||
float y1 = (yMin + yMax) / 2;
|
||||
drawString(gl, label, x1, y1, zMin, XAlign.CENTER, yAlign, angle, 0, yShift);
|
||||
//drawString(gl, label, x1, y1, zMin, XAlign.CENTER, yAlign, 0, yShift);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2556,7 +2558,7 @@ public class GLPlot extends Plot {
|
||||
TeXFormula formula = new TeXFormula(str);
|
||||
|
||||
// render the formula to an icon of the same size as the formula.
|
||||
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, font.getSize());
|
||||
TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_TEXT, font.getSize2D());
|
||||
|
||||
// insert a border
|
||||
icon.setInsets(new Insets(5, 5, 5, 5));
|
||||
|
||||
@ -68,6 +68,11 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.hebi.matlab.mat</groupId>
|
||||
<artifactId>mfl-core</artifactId>
|
||||
<version>0.5.15</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -29,6 +29,7 @@ import org.meteoinfo.data.meteodata.grads.GrADSDataInfo;
|
||||
import org.meteoinfo.data.meteodata.hysplit.HYSPLITConcDataInfo;
|
||||
import org.meteoinfo.data.meteodata.hysplit.HYSPLITPartDataInfo;
|
||||
import org.meteoinfo.data.meteodata.hysplit.HYSPLITTrajDataInfo;
|
||||
import org.meteoinfo.data.meteodata.matlab.MatLabDataInfo;
|
||||
import org.meteoinfo.data.meteodata.micaps.*;
|
||||
import org.meteoinfo.data.meteodata.netcdf.NetCDFDataInfo;
|
||||
import java.io.IOException;
|
||||
@ -474,6 +475,8 @@ public class MeteoDataInfo {
|
||||
RandomAccessFile raf = new RandomAccessFile(fileName, "r");
|
||||
if (GrADSDataInfo.class.getDeclaredConstructor().newInstance().isValidFile(raf)) {
|
||||
di = new GrADSDataInfo();
|
||||
} else if (MatLabDataInfo.class.getDeclaredConstructor().newInstance().isValidFile(raf)) {
|
||||
di = new MatLabDataInfo();
|
||||
} else if (NetcdfFiles.canOpen(fileName)) {
|
||||
di = new NetCDFDataInfo();
|
||||
} else if (ARLDataInfo.class.getDeclaredConstructor().newInstance().isValidFile(raf)) {
|
||||
@ -735,33 +738,6 @@ public class MeteoDataInfo {
|
||||
_infoText = aDataInfo.generateInfoText();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Open HYSPLIT traject data
|
||||
// *
|
||||
// * @param trajFiles File paths
|
||||
// */
|
||||
// public void openHYSPLITTrajData(String[] trajFiles) {
|
||||
// try {
|
||||
// //Read data info
|
||||
// HYSPLITTrajDataInfo aDataInfo = new HYSPLITTrajDataInfo();
|
||||
// aDataInfo.readDataInfo(trajFiles);
|
||||
// dataInfo = aDataInfo;
|
||||
// _infoText = aDataInfo.generateInfoText();
|
||||
// } catch (IOException ex) {
|
||||
// Logger.getLogger(MeteoDataInfo.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Open HYSPLIT traject data
|
||||
// *
|
||||
// * @param trajFiles File paths
|
||||
// */
|
||||
// public void openHYSPLITTrajData(List<String> trajFiles) {
|
||||
// String[] files = trajFiles.toArray(new String[0]);
|
||||
// openHYSPLITTrajData(files);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Open HYSPLIT particle data
|
||||
*
|
||||
@ -897,6 +873,17 @@ public class MeteoDataInfo {
|
||||
_infoText = dataInfo.generateInfoText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open MatLab data file
|
||||
*
|
||||
* @param fileName File path
|
||||
*/
|
||||
public void openMatLabData(String fileName) {
|
||||
dataInfo = new MatLabDataInfo();
|
||||
dataInfo.readDataInfo(fileName);
|
||||
_infoText = dataInfo.generateInfoText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open MICAPS data
|
||||
*
|
||||
|
||||
@ -285,9 +285,6 @@ public class GrADSDataInfo extends DataInfo implements IGridDataInfo, IStationDa
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (FileNotFoundException ex) {
|
||||
Logger.getLogger(GrADSDataInfo.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
|
||||
@ -0,0 +1,203 @@
|
||||
package org.meteoinfo.data.meteodata.matlab;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
|
||||
import org.meteoinfo.common.DataConvert;
|
||||
import org.meteoinfo.data.GridArray;
|
||||
import org.meteoinfo.data.GridData;
|
||||
import org.meteoinfo.data.dimarray.Dimension;
|
||||
import org.meteoinfo.data.meteodata.Attribute;
|
||||
import org.meteoinfo.data.meteodata.DataInfo;
|
||||
import org.meteoinfo.data.meteodata.IGridDataInfo;
|
||||
import org.meteoinfo.data.meteodata.Variable;
|
||||
import org.meteoinfo.ndarray.Array;
|
||||
import org.meteoinfo.ndarray.InvalidRangeException;
|
||||
import us.hebi.matlab.mat.format.CharEncoding;
|
||||
import us.hebi.matlab.mat.format.Mat5;
|
||||
import us.hebi.matlab.mat.format.Mat5File;
|
||||
import us.hebi.matlab.mat.types.*;
|
||||
import us.hebi.matlab.mat.util.Bytes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MatLabDataInfo extends DataInfo implements IGridDataInfo {
|
||||
|
||||
private static final String MAT5_IDENTIFIER = "MATLAB 5.0 MAT-file";
|
||||
|
||||
@Override
|
||||
public boolean isValidFile(RandomAccessFile raf) {
|
||||
try {
|
||||
byte[] bytes = new byte[116];
|
||||
raf.seek(0);
|
||||
raf.read(bytes);
|
||||
String magic = MatLabDataInfo.parseAsciiString(bytes);
|
||||
if (magic.startsWith(MAT5_IDENTIFIER)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test can open or not
|
||||
* @param fileName Data file name
|
||||
* @return Can open or not
|
||||
*/
|
||||
public static boolean canOpen(String fileName) {
|
||||
try {
|
||||
byte[] bytes = new byte[116];
|
||||
RandomAccessFile raf = new RandomAccessFile(fileName, "r");
|
||||
raf.seek(0);
|
||||
raf.read(bytes);
|
||||
raf.close();
|
||||
String magic = MatLabDataInfo.parseAsciiString(bytes);
|
||||
if (magic.startsWith(MAT5_IDENTIFIER)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static String parseAsciiString(byte[] buffer) {
|
||||
return parseAsciiString(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
static String parseAsciiString(byte[] buffer, int offset, int maxLength) {
|
||||
// Stop at String end character
|
||||
int length = Bytes.findFirst(buffer, offset, maxLength, (byte) '\0', maxLength);
|
||||
|
||||
// Remove right-side trailing spaces
|
||||
while (length > 0 && buffer[length - 1] == ' ') {
|
||||
length--;
|
||||
}
|
||||
|
||||
// Convert to String
|
||||
return length == 0 ? "" : new String(buffer, offset, length, Charsets.US_ASCII);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDataInfo(String fileName) {
|
||||
// Iterate over all entries in the mat file
|
||||
try (Source source = Sources.openFile(fileName)){
|
||||
this.setFileName(fileName);
|
||||
MatFile mat = Mat5.newReader(source).readMat();
|
||||
this.addAttribute(new Attribute("File type", "MatLab"));
|
||||
for (MatFile.Entry entry : mat.getEntries()) {
|
||||
Matrix array = (Matrix) entry.getValue();
|
||||
int[] dimensions = array.getDimensions();
|
||||
List<Dimension> dimensionList = new ArrayList<>();
|
||||
for (int i = 0; i < dimensions.length; i++) {
|
||||
Dimension dimension = new Dimension("dim_" + entry.getName() + "_" + String.valueOf(i + 1), dimensions[i]);
|
||||
this.addDimension(dimension);
|
||||
dimensionList.add(dimension);
|
||||
}
|
||||
Variable variable = new Variable();
|
||||
variable.setName(entry.getName());
|
||||
variable.setDataType(MatLabUtil.fromMatLabDataType(array.getType()));
|
||||
variable.addAttribute("Name", entry.getName());
|
||||
for (Dimension dimension : dimensionList) {
|
||||
variable.addDimension(dimension);
|
||||
}
|
||||
variable.setCachedData(MatLabUtil.fromMatLabArray(array));
|
||||
this.addVariable(variable);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array read(String varName) {
|
||||
Variable var = this.getVariable(varName);
|
||||
int n = var.getDimNumber();
|
||||
int[] origin = new int[n];
|
||||
int[] size = new int[n];
|
||||
int[] stride = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
origin[i] = 0;
|
||||
size[i] = var.getDimLength(i);
|
||||
stride[i] = 1;
|
||||
}
|
||||
|
||||
Array r = read(varName, origin, size, stride);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array read(String varName, int[] origin, int[] size, int[] stride) {
|
||||
try {
|
||||
Variable variable = this.getVariable(varName);
|
||||
return variable.getCachedData().section(origin, size, stride).copy();
|
||||
} catch (InvalidRangeException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridArray getGridArray(String varName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_LonLat(int timeIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_TimeLat(int lonIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_TimeLon(int latIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_LevelLat(int lonIdx, String varName, int timeIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_LevelLon(int latIdx, String varName, int timeIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_LevelTime(int latIdx, String varName, int lonIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_Time(int lonIdx, int latIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_Level(int lonIdx, int latIdx, String varName, int timeIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_Lon(int timeIdx, int latIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridData getGridData_Lat(int timeIdx, int lonIdx, String varName, int levelIdx) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package org.meteoinfo.data.meteodata.matlab;
|
||||
|
||||
import org.meteoinfo.ndarray.Array;
|
||||
import org.meteoinfo.ndarray.DataType;
|
||||
import org.meteoinfo.ndarray.Index;
|
||||
import us.hebi.matlab.mat.types.MatlabType;
|
||||
import us.hebi.matlab.mat.types.Matrix;
|
||||
|
||||
public class MatLabUtil {
|
||||
|
||||
/**
|
||||
* Convert MatLab data type to MeteoInfo data type
|
||||
* @param matlabType MatLab data type
|
||||
* @return MeteoInfo data type
|
||||
*/
|
||||
public static DataType fromMatLabDataType(MatlabType matlabType) {
|
||||
switch (matlabType) {
|
||||
case Int8:
|
||||
case Int16:
|
||||
case Int32:
|
||||
return DataType.INT;
|
||||
case Int64:
|
||||
return DataType.LONG;
|
||||
case UInt8:
|
||||
case UInt16:
|
||||
case UInt32:
|
||||
return DataType.UINT;
|
||||
case UInt64:
|
||||
return DataType.ULONG;
|
||||
case Single:
|
||||
return DataType.FLOAT;
|
||||
case Double:
|
||||
return DataType.DOUBLE;
|
||||
default:
|
||||
return DataType.OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert MatLab array to MeteoInfo array
|
||||
* @param matArray MatLab array
|
||||
* @return MeteoInfo Array
|
||||
*/
|
||||
public static Array fromMatLabArray(Matrix matArray) {
|
||||
DataType dataType = fromMatLabDataType(matArray.getType());
|
||||
int[] shape = matArray.getDimensions();
|
||||
int ndim = shape.length;
|
||||
Array array = Array.factory(dataType, shape);
|
||||
Index index = array.getIndex();
|
||||
int[] current;
|
||||
switch (dataType) {
|
||||
case INT:
|
||||
case UINT:
|
||||
for (int i = 0; i < array.getSize(); i++) {
|
||||
current = index.getCurrentCounter();
|
||||
for (int j = 0; j < ndim; j++) {
|
||||
if (current[j] < shape[j] - 1) {
|
||||
current[j] = current[j] + 1;
|
||||
break;
|
||||
} else {
|
||||
current[j] = 0;
|
||||
}
|
||||
}
|
||||
index.set(current);
|
||||
array.setInt(index, matArray.getInt(i));
|
||||
}
|
||||
break;
|
||||
case LONG:
|
||||
case ULONG:
|
||||
for (int i = 0; i < matArray.getNumElements(); i++) {
|
||||
array.setLong(i, matArray.getLong(i));
|
||||
}
|
||||
break;
|
||||
case FLOAT:
|
||||
for (int i = 0; i < matArray.getNumElements(); i++) {
|
||||
array.setFloat(i, matArray.getFloat(i));
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
for (int i = 0; i < matArray.getNumElements(); i++) {
|
||||
array.setDouble(i, matArray.getDouble(i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@ -1,32 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\axis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\matlab">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\city"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj\calculate"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\LaSW\airship"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\matlab"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot\plot3_multi_color_chinese.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text\text3_3d_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text\text_latex.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\matlab\test_mfl_lizard_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\matlab\mat_lizard_1.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot\plot3_multi_color_chinese.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text\text3_3d_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\text\text_latex.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\matlab\test_mfl_lizard_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\matlab\mat_lizard_1.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -34,5 +34,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-7,0" MainFormSize="1379,769"/>
|
||||
<Startup MainFormLocation="-7,0" MainFormSize="1405,788"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -32,9 +32,9 @@ import mipylib.migl as migl
|
||||
__all__ = [
|
||||
'addfile','addfiles','addfile_arl','addfile_ascii_grid','addfile_awx','addfile_geotiff',
|
||||
'addfile_grads','addfile_hyconc','addfile_hytraj','addfile_hypart','addfile_lonlat',
|
||||
'addfile_micaps','addfile_mm5','addfile_nc','addfile_grib','addfile_surfer','add_bufr_lookup',
|
||||
'addtimedim','joinncfile','asciiread','asciiwrite','bincreate','binread','binwrite',
|
||||
'numasciicol','numasciirow','readtable','convert2nc','grads2nc','ncwrite'
|
||||
'addfile_matlab','addfile_micaps','addfile_mm5','addfile_nc','addfile_grib','addfile_surfer',
|
||||
'add_bufr_lookup', 'addtimedim','joinncfile','asciiread','asciiwrite','bincreate','binread',
|
||||
'binwrite', 'numasciicol','numasciirow','readtable','convert2nc','grads2nc','ncwrite'
|
||||
]
|
||||
|
||||
def isgriddata(gdata):
|
||||
@ -269,6 +269,22 @@ def addfile_mm5(fname, getfn=True, reffile=None):
|
||||
meteodata.openMM5Data(fname, reffile)
|
||||
datafile = DimDataFile(meteodata)
|
||||
return datafile
|
||||
|
||||
def addfile_matlab(fname, getfn=True):
|
||||
"""
|
||||
Add a MatLab data file.
|
||||
|
||||
:param fname: (*string*) The MatLab file name.
|
||||
:param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
|
||||
|
||||
:returns: (*DimDataFile*) Opened file object.
|
||||
"""
|
||||
if getfn:
|
||||
fname, isweb = __getfilename(fname)
|
||||
meteodata = MeteoDataInfo()
|
||||
meteodata.openMatLabData(fname)
|
||||
datafile = DimDataFile(meteodata)
|
||||
return datafile
|
||||
|
||||
def addfile_lonlat(fname, getfn=True, missingv=-9999.0):
|
||||
"""
|
||||
|
||||
@ -650,7 +650,7 @@ public abstract class Array {
|
||||
|
||||
/**
|
||||
* Get an index iterator for traversing the array in arbitrary order. Use
|
||||
* this if you dont care what order the elements are returned, eg if you are
|
||||
* this if you don't care what order the elements are returned, eg if you are
|
||||
* summing an Array. To get an iteration in order, use getIndexIterator(),
|
||||
* which returns a fast iterator if possible.
|
||||
*
|
||||
|
||||
@ -204,7 +204,7 @@ public class ArrayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get row number of a ASCII file
|
||||
* Get row number of an ASCII file
|
||||
*
|
||||
* @param fileName File name
|
||||
* @param delimiter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user