📄 load.java
字号:
// read dimensions length
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read next tag");
swap(b, 4, swapEndian);
// check length of dimensions
if (b[0]!=0 || b[1]!=0 || b[2]!=0 || b[3]!=8)
throwMathLibException("load: miMATRIX: dimensions should be 8");
////// read array flags /////
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read array flags");
swap(b, 4, swapEndian);
// check if complex bit is set
boolean complexFlag = false;
if ((b[3]& 0x08) != 0) complexFlag = true;
System.out.println("load: miMATRIX: complex flag "+complexFlag);
// check if global bit is set
boolean globalFlag = false;
if ((b[3]& 0x04) != 0) globalFlag = true;
System.out.println("load: miMATRIX: global flag "+globalFlag);
// check if logical bit is set
boolean logicalFlag = false;
if ((b[3]& 0x02) != 0) logicalFlag = true;
System.out.println("load: miMATRIX: logical flag "+logicalFlag);
// read class of data of matrix
int arrayClassType = b[3];
System.out.println("load: miMATRIX: array class type "+ arrayClassType);
// read unused array flags
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read array flags unused");
swap(b, 4, swapEndian);
/////// dimensions array ////////
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read type of dimensions array");
swap(b, 4, swapEndian);
if (b[0]!=0 || b[1]!=0 || b[2]!=0 || b[3]!=0x05)
throwMathLibException("load: miMATRIX: data type of dimensions array is not INT32");
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read value of array dimensions");
swap(b, 4, swapEndian);
if (b[0]!=0 || b[1]!=0 || b[2]!=0 || b[3]!=8)
throwMathLibException("load: miMATRIX: data length of dimensions array is not 8");
// read length first axis
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read length of first axis");
swap(b, 4, swapEndian);
int xLength = b[3]; // !?!maybe check all four bytes
System.out.println("load: miMATRIX x="+xLength);
// read length second axis
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read length of second axis");
swap(b, 4, swapEndian);
int yLength = b[3]; // !?!maybe check all four bytes
System.out.println("load: miMATRIX y="+yLength);
//////// read array name ////////
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read name of array");
swap(b, 4, swapEndian);
if (b[0]!=0 || b[1]!=0 || b[2]!=0 || b[3]!=1)
throwMathLibException("load: miMATRIX: data type of array name is not INT8");
// length array name
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read length of name of array");
swap(b, 4, swapEndian);
int nameLength = b[3]; //?!?! maybe take all 4 bytes
byte[] nameB = new byte[nameLength];
if ( dataStream.read(nameB,0,nameLength) != nameLength)
throwMathLibException("load: could not read name of array");
String arrayName = new String(nameB);
System.out.println("load: miMATRIX array name: "+arrayName);
// read bytes up to the next 8 Byte border
int stuffLength = 8* ((nameLength/8) + 1) - nameLength ;
System.out.println("load: miMATRIX stufflength: "+stuffLength);
if ( dataStream.read(b,0,stuffLength) != stuffLength )
throwMathLibException("load: could not read stuff bytes");
//////// read real data ////////
double[][] data = new double[yLength][xLength];
// read type of data
if ( dataStream.read(b,0,4) != 4)
throwMathLibException("load: could not read type of data");
swap(b, 4, swapEndian);
int realDataType = b[3]; //?!?! maybe take all 4 bytes
int realDataLength = miLength[realDataType];
for (int xi=0; xi<xLength; xi++)
{
for (int yi=0; yi<yLength; yi++)
{
if ( dataStream.read(b,0,realDataLength) != realDataLength)
throwMathLibException("load: could not read real data");
swap(b, stuffLength, swapEndian);
// fill array
// ???? data[yi][xi] = b[]; // ????
}
}
//////// read imaginary data ////////
break;
}
//case miINT8:
//case miINT16;
//....
// more to come
default:
{
throwMathLibException("load: data type not yet supported");
}
}
result = new DoubleNumberToken(5555);
}
catch(Exception e)
{
throwMathLibException("load" + e.getMessage());
}
fileStream.close();
}
catch (Exception e)
{
throwMathLibException("load" + e.getMessage());
}
return result;
}
/**
* swap bytes if type of endian coding is necessary
* @param c
* @param len
*/
private void swap(byte[] c, int len, boolean _swapEndian)
{
byte d = 0;
if (_swapEndian)
{
for (int i=0; i<len/2; i++)
{
d = c[len-1-i];
c[len-1-i] = c[i];
c[i] = d;
}
}
}
}
/*
@GROUP
IO
@SYNTAX
load(file)
@DOC
Reads in a matrix from a comma seperated value file.
@EXAMPLES
<programlisting>
load
</programlisting>
@SEE
csvread, csvwrite
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -