问题描述
HI-我有一个vb.net应用程序,需要读取超立方体"数据文件-格式为标头(32768 char),然后是数组(640,640,120)UShort.读取此内容的C代码运行得非常快:
void CCubeReader7Dlg::OnBnClickedOk()
{
FILE *F_IN, *F_OUT;
char* header;
unsigned short* data;
unsigned short* value;
unsigned short* out;
data = (unsigned short*)malloc(520*sizeof(short)); // dimension single row of data array
out = (unsigned short*)malloc(2*696*128*sizeof(short)); // dimension output storage arrage
header = (char*)malloc(32768); // dimension header
// Open and input and output file
fopen_s(&F_IN,"C:\\Documents and Settings\\Leif Hendricks\\Desktop\\xyzzy.cube","rb");
fopen_s(&F_OUT,"C:\\Documents and Settings\\Leif Hendricks\\Desktop\\xyzzy.out","wb");
// Read past the 32768 byte header
fread(header,sizeof(char),32768,F_IN);
// Loop over the columns, bands, reading a row at a time (visually rows and cols are reveresed)
for(int i=0;i<696;i++)
for(int b=0;b<128;b++){
fread(data,sizeof(short),520,F_IN);
out[i+b*696] = data[519]; // store data from column 519
out[i+b*696+696*128] = data[204]; // store data from column 204
}
// Write the stored data out to a file
fwrite(out,sizeof(short),696*128*2,F_OUT);
// Close the output file
fclose(F_IN);
我已经在vb.net上编写了此文件(获得了Microsoft技术支持超过一个星期的帮助)-但是运行速度非常慢-我认为流阅读器是问题所在.简而言之,我想读取一个记录文件,然后能够快速扫描3维数组以查找选定的单元格值,然后将索引位置记录在一个单独的文件中.帮助将不胜感激.
谢谢
鲍勃
I have written this in vb.net (with more than a weeks worth of help from Microsoft technical support) - but this runs really slow - I believe the streamreader is the problem. In short, I want to read a one record file, and then be able to quickly scan the 3 dimentional array for selected cell values, and then record the index locations in a separate file. Help woule be really appreciated.
Thanks
Bob
Sub LoadCubeData()
Dim MaxRows As Integer = 640
Dim MaxColumns As Integer = 640
Dim MaxBands As Integer = 120
Dim r As Integer = 0
Dim b As Integer = 0
Dim c As Integer = 0
Dim array3D(MaxRows, MaxColumns, MaxBands) As UShort '49152000
Dim arraysize As Integer = MaxBands * MaxRows * MaxColumns * 4 + 32768
Dim myString As String = "No Data"
Dim myCharString As Char() = ""
Dim StringLength As Integer = 0
Dim rowbuffer(4) As Char
Dim colbuffer(4) As Char
Dim linebuffer(4) As Char
Dim returnValue As Integer = 0
Dim currentPosition As Integer = 0
Dim HeaderCharString(32768) As Char
Dim CellValue(arraysize) As Char
Dim CellValuePosition As Integer = 0
Dim sr As StreamReader = New StreamReader(InputImageName)
returnValue = sr.Read(HeaderCharString, currentPosition, HeaderCharString.Length)
myString = HeaderCharString.ToString
currentPosition = returnValue
Dim iter As Integer
iter = 0
For c = 0 To MaxColumns
For r = 0 To MaxRows
For b = 0 To MaxBands
array3D(c, r, b) = 0
sr.ReadBlock(CellValue, currentPosition, 2)
array3D(c, r, b) = Convert.ToInt32(CellValue.GetValue(currentPosition))
currentPosition = currentPosition + 2
iter = iter + 1
Trace.WriteLine("brc" & "," & b & "," & r & "," & c & "'" & iter)
XPositionOut.Clear()
XPositionOut.AppendText(c)
YPositionOut.Clear()
YPositionOut.AppendText(r)
BandPositionOut.Clear()
BandPositionOut.AppendText(b)
CellValueOut.AppendText(Convert.ToString(array3D(c, r, b)))
Next
Next
Next
sr.Close()
End Sub
推荐答案
Trace.WriteLine("brc" & "," & b & "," & r & "," & c & "''" & iter)
XPositionOut.Clear()
XPositionOut.AppendText(c)
YPositionOut.Clear()
YPositionOut.AppendText(r)
BandPositionOut.Clear()
BandPositionOut.AppendText(b)
CellValueOut.AppendText(Convert.ToString(array3D(c, r, b)))
只需声明三个整数r,b和c-在vb代码中似乎没有其他理由,因为数据的最终目标似乎是CellValueOut和内部循环内的朋友.
>>微软技术支持提供了超过一周的帮助
我衷心希望您不必为此付费
问候
Espen Harlinn
just declare three integers r, b and c - there seems to be no reason in your vb code for all the other stuff since the final destination for the data seems to be CellValueOut, and friends, inside the inner loop.
>> with more than a weeks worth of help from Microsoft technical support
I sincerely hope you don''t have to pay for this
Regards
Espen Harlinn
这篇关于如何将fread转换为vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!