-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fh.cpp
217 lines (190 loc) · 6.25 KB
/
Fh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC SUBROUTINES MADE BY FAN HUA. //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "3dfstbrk.h"
#include "fh.h"
int AskSwathNumber() // 询问线束号.
{
CDSwNum dlg;
dlg.m_SwathNumber=1;
if(dlg.DoModal()==IDOK){
return dlg.m_SwathNumber;
}
return -1;
}
CString IntToName(int Swath) // 变线束号为以0打头的三位字符串.
{
char a[10];
_itoa(Swath,a,10);
CString s1('0',3-strlen(a));
CString FileName=s1+a;
return FileName;
}
CString STR(float Value)// 变数值为字符串
{
char a[30];
sprintf(a,"%f",Value);
return CString(a);
}
CString STR(int Value) // 变数值为字符串
{
char a[30];
sprintf(a,"%d",Value);
return CString(a);
}
CString STR(double Value)// 变数值为字符串
{
char a[30];
sprintf(a,"%f",Value);
return CString(a);
}
CString STR(long Value) // 变数值为字符串
{
char a[30];
sprintf(a,"%ld",Value);
return CString(a);
}
BOOL CLS(CDC *pDC) //清屏幕.
{
CRect ClientRect;
CWnd *cw=pDC->GetWindow();
cw->GetClientRect(ClientRect); // get current window size.
pDC->FillRect(&ClientRect,&CBrush(RGB(255,255,255))); // 清屏幕.
return TRUE;
}
long RevByte(long id)
{
id = ((id & 0xff) << 24) | ((id & 0xff00) << 8)
| ((id & 0xff0000) >> 8) | ((id & 0xff000000) >> 24);
return id;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Name : IntegrateCFbkDoc
// Function : Integrare the single first breal files , to one ultimate file.
// Date : 1997.9.8
// Programer : FAN HUA. -- 范 华 --
#include "svsys.h"
#include "swathpar.h"
#include "equation.h"
#include "progdlg.h"
#include "fbkdoc.h"
BOOL IntegrateFstBrk()
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 询问用户所要合并的线束号.
int i,j;
CDSwNum dlg1;
dlg1.m_SwathNumber=1;
if(dlg1.DoModal()==IDCANCEL)return FALSE;
int SwathNumber=dlg1.m_SwathNumber;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 建立一个文件打开窗口, 以获得用户所要合并的文件名.
char ff[]="初至文件(*.fbk)|*.fbk||";
CFileDialog dlg(TRUE,NULL,"*.*",OFN_ALLOWMULTISELECT,ff);
char s[300]={0};
dlg.m_ofn.lpstrFile=s;
dlg.m_ofn.nMaxFile=300;
if(dlg.DoModal()==IDCANCEL){
AfxMessageBox("输入文件名称失败!");
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// 将存有文件名的内存区域转化为文件名数组.
char file[20][13];
int row=0,col=0;
for(i=0;i<240;i++){
file[row][col]=s[i];
col++;
if(iscntrl(s[i])){
row++;
col=0;
if(iscntrl(s[i+1]))break;
}
}
int NumberOfFile;
if(row==1){
NumberOfFile=1; // 如果只有一个文件被选中, 则只有一个文件名.
strcpy(file[1],(LPCTSTR)dlg.GetFileName());
}
else
NumberOfFile=row-1; // 若有多个文件被选中, 则第一个文件名是路径名,其次才是各个文件名.
//////////////////////////////////////////////////////////////////////////////////////////////////
// 读入所有初至文件的第一个点的文件号.
FILE *fp;
int* filenumber=new int[NumberOfFile];
for(i=0;i<NumberOfFile;i++){
fp=fopen(file[i+1],"rb"); //第一个文件名是 路径名.
if(!fp){
AfxMessageBox("无法打开初至文件"+CString(file[i])+"!",MB_OK);
return FALSE;
}
fseek(fp,0,SEEK_SET); // because this is first break file , so 0 position is the fst brk
fread(&filenumber[i],sizeof(long),1,fp);
fclose(fp);
}
////////////////////////////////////////////////////////////////////////////////////////
// 合并初至文件.
// ------------------------------------------------------------------------------------
// 打开最终文件.
// Here do not consider if Equation has been successfully made,
//because we need only the ultimate first break file name.
Equation equa;
if(!equa.Set(SwathNumber))return false;
CString UltiFstBrkFile=equa.m_FileSwathFirstBreak;
fp=fopen(UltiFstBrkFile,"wb");
if(!fp){
AfxMessageBox("无法建立最终初至文件!",MB_OK); // Can not make first break file.
return FALSE;
}
// 建立一个进程条.
CProgressDlg dlg3;
dlg3.Create();
dlg3.SetStatus("正在合并第 "+STR(SwathNumber)+" 束线的初至文件:");
dlg3.SetWindowText("合并初至文件");
long RoomSize=500,nRead,nWrite,MinN,MinF;
float n=0.0;
FILE *fpSeperate;
DataInFstBrkFile *data=new DataInFstBrkFile[RoomSize];
// 对所有文件循环.
while(TRUE){
n++;
dlg3.SetPos(n/NumberOfFile*100);
// 寻找最小文件号的文件名.
MinN=10000000,MinF=100000;
for(j=0;j<NumberOfFile;j++){
if(filenumber[j]<MinN){
MinN=filenumber[j];
MinF=j+1; // 第一个文件名是路径名.
}
}
if(MinF>=100000)break; // 所有文件均已被合并.
filenumber[MinF-1]=10000000;
// 打开该文件.
fpSeperate=fopen(file[MinF],"rb");
if(!fpSeperate){
AfxMessageBox("不能打开初至文件"+CString(file[i])+"!");
return FALSE;
}
// 读该文件至最终文件中.
while(!feof(fpSeperate)){ // Loop for the seperate file.
nRead=fread(data,sizeof(DataInFstBrkFile),RoomSize,fpSeperate);
nWrite=fwrite(data,sizeof(DataInFstBrkFile),nRead,fp);
if(nWrite<nRead){
AfxMessageBox("当向最终初至文件"+UltiFstBrkFile+"中写数据时出错!");
return FALSE;
}
}
fclose(fpSeperate); // Loop for the seperate file.
} // Loop for all first break files.
fclose(fp);
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tell the user that all have been done.
dlg3.DestroyWindow();
AfxMessageBox("最终初至文件"+UltiFstBrkFile+"已经合并完成!",MB_OK);
////////////////////////////////////////////////////////////////////////////////////////////////////////
// 返回.
return TRUE;
}
// Name : IntegrateCFbkDoc
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////