問題:
下載的開源代碼按照要求格式輸入檔案后,就提示“按任意鍵繼續。。。”,或者cmd命令窗直接就自動退出了。

具體:
設定斷點單步除錯發現,程式應該是沒讀到我的輸入命令列,argc=1直接按照程式輸出文字就直接退出進行了,細看代碼感覺很奇怪,這是一個很老的模型,內部代碼因該是肯定沒錯的,不需要修改,不知道哪里出問題了。代碼段如下:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "config.h"
#include "tMCimg.h"
#include "mccore.h"
#define USAGE printf("options: if string contains...\n"\
"\t? - display the option help (this)\n"\
"\tn - inhibit .2pt file storage and dump\n"\
"\tR - Use normal C ordering for segmentation/.2pt files\n"\
"\ts - don't move sources to the boundary\n"\
"\td - don't move detectors to the boundary\n"\
"\tt - write exact exit time to .his.t instead of tgate # to .his\n"\
"\tm - make tissue-air boundaries perfectly mirrored\n\n")
/*********************************************************************
Function prototypes 函式原型
*********************************************************************/
static void run_simulation(const struct Config *, const TISSUE ***,
TWOPT_T *, TWOPT_T *, const char *);
extern void run_photon(const struct Config *, int, const TISSUE ***,
TWOPT_T *, TWOPT_T *, FILE *, int *);
void write_photon(const struct Config *, FILE *, double, double, double,
double, double, double, double, float *);
/*********************************************************************
BEGIN PROGRAM CODE
*********************************************************************/
int main(int argc, char *argv[])
{
struct Config syscfg; /* System configuration, constructed
* from the .cfg file */
TWOPT_T *II, *JJ; /* FOR STORING THE 2-PT FLUENCE */
TISSUE ***tissueType; /* STORE THE IMAGE FILE */
int i, j, n, nvox;
/* Initialize the configuration structure's memory */
initialize_config(&syscfg);
/* GET THE COMMAND LINE ARGUMENT(S) */
if (argc == 1)
{
printf("tMCimg version 8.0%c\n", 'A' + 0);
printf("USAGE:: tMCimg [-opts] input_file (.cfg assumed)\n");
USAGE;
printf("Default options:\n");
printf("\t2pt files %s be generated\n",
(syscfg.flags.gen_twopt != 0) ? "will" : "will not");
printf("\t%s-ordered data files\n",
(syscfg.flags.matlab_order != 0) ? "Matlab" : "C");
printf("\tSources %s to interface\n",
(syscfg.flags.source_move != 0) ? "moved" : "not moved");
printf("\tDetectors %s to interface\n",
(syscfg.flags.detector_move != 0) ? "moved" : "not moved");
printf("\tExiting photons %s to interface\n",
(syscfg.flags.exiting_move != 0) ? "moved" : "not moved");
printf("\t%s recorded in history file\n",
(syscfg.flags.exact_exit_time != 0) ?
"Exact exit times" : "Time indices");
if (syscfg.flags.mirror != 0)
printf("\tMirrored air boundaries\n");
printf("\n");
getchar();
return 1;
}
這段代碼最后的getchar();是我后加上去的,要不然命令窗就會一閃而過,不給輸入檔案的機會。
單步除錯程式運行到return 1;就會跳出整個int,退出行程結束運行了。
但正常這個程式運行程序應該是讀取我輸入的字串然后進行下面的程式,現在是根本沒進入程式就結束了,實在搞不懂了,求路過大神。
后面的程式是這樣的,我沒有看懂他那里識別我輸入的命令列
else
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-') /* introduces option flags */
{
/* search through command line option words to find
* meaningful chars... */
for (j = 1; argv[i][j] != '\0'; j++)
switch (argv[i][j])
{
case 'm':
syscfg.flags.mirror = !syscfg.flags.mirror;
printf("Tissue-air boundaries %s be mirrored.\n",
(syscfg.flags.mirror ? "will" : "will not"));
break;
case 'n':
syscfg.flags.gen_twopt = !syscfg.flags.gen_twopt;
printf("The .2pt file %s be generated.\n",
(syscfg.flags.gen_twopt ? "will" : "will not"));
break;
case 'R':
syscfg.flags.matlab_order = !syscfg.flags.matlab_order;
printf("Data %s be saved in matlab order.\n",
(syscfg.flags.matlab_order ? "will" : "will not"));
break;
case 'd':
syscfg.flags.detector_move = !syscfg.flags.detector_move;
printf("Detectors %s be moved to interface.\n",
(syscfg.flags.detector_move ? "will" : "will not"));
break;
case 's':
syscfg.flags.source_move = !syscfg.flags.source_move;
printf("Source %s be moved to interface.\n",
(syscfg.flags.source_move ? "will" : "will not"));
break;
case 'e':
syscfg.flags.exiting_move = !syscfg.flags.exiting_move;
printf("Exiting photons %s be moved to boundary.\n",
(syscfg.flags.exiting_move ? "will" : "will not"));
break;
case 't':
syscfg.flags.exact_exit_time = !syscfg.flags.exact_exit_time;
printf("History file %s record exact exit times.\n",
(syscfg.flags.exact_exit_time ? "will" : "will not"));
break;
case 'h':
case '?':
USAGE;
return 0;
default:
printf("Unknown option -%c ignored\n", argv[i][j]);
}
}
else
{
/* Assume that since it isn't a command-line flag that it's
* the name of the configuration file. Diddle the argument
* vector to fool the parser into doing the right thing.
*/
argv[1] = argv[i];
argv[2] = NULL; /* may or may not be necessary */
argc = 2;
break;
}
}
/* PARSE THE INPUT FILE */
if ((n = loadconfig(&syscfg, argv[1])) != 0)
exit(n);
if (syscfg.NT < 1)
{
fprintf(stderr, "Error: total number of photons must be >1\n");
exit(1);
}
rescale_system(&syscfg);
/* SUMMARY OF EXTANT OPTIONS */
if (syscfg.flags.gen_twopt)
printf("...2pt files will be generated\n");
if (syscfg.flags.matlab_order)
printf("...Matlab-ordered data files\n");
if (syscfg.flags.source_move)
printf("...Sources moved to interface\n");
if (syscfg.flags.detector_move)
printf("...Detectors moved to interface\n");
if (syscfg.flags.exiting_move)
printf("...Exiting photons moved to interface\n");
if (syscfg.flags.exact_exit_time)
printf("...Exact exit times recorded in history file\n");
if (syscfg.flags.mirror)
printf("...Mirrored air boundaries\n");
/* READ IN THE SEGMENTED DATA FILE */
if ((n = loadsegments(&syscfg, &tissueType)) != 0)
exit(n);
/* ALLOCATE SPACE FOR AND INITIALIZE THE PHOTON FLUENCE TO 0 分配空間并初始化光子通量為0 */
nvox = syscfg.nIxstep * syscfg.nIystep * syscfg.nIzstep * syscfg.nTstep;
II = NULL;
JJ = NULL;
if (syscfg.flags.gen_twopt)
{
if ((II = alloc_1d_array(nvox,sizeof(TWOPT_T))) == NULL)
exit(1);
/* CW/TD don't need this. Hopefully, the viewer etc. will be
* smart enought to know the difference */
if (syscfg.frequency != 0.0)
if ((JJ = alloc_1d_array(nvox,sizeof(TWOPT_T))) == NULL)
exit(1);
/* INITIALIZE THE FLUENCE DATA */
if (II != NULL)
for (i = 0; i < nvox; i++)
II[i] = 0.0;
if (JJ != NULL)
for (i = 0; i < nvox; i++)
JJ[i] = 0.0;
}
/* SET UP THE FLOATING POINT CO-PROCESSOR */
fpusetup();
/* MAKE SURE THE SOURCES ARE AT INTERFACES */
if (syscfg.flags.source_move)
move_sources(&syscfg, (const TISSUE ***)tissueType);
/* MAKE SURE THE DETECTORS ARE AT INTERFACES */
if (syscfg.flags.detector_move)
move_detectors(&syscfg, (const TISSUE ***)tissueType);
/* RUN THE MONTE CARLO SIMULATION */
run_simulation(&syscfg, (const TISSUE ***)tissueType, II, JJ, argv[1]);
/* DONE */
nvox = syscfg.nIxstep * syscfg.nIystep * syscfg.nIzstep * syscfg.nTstep;
free_1d_array(II, nvox);
free_1d_array(JJ, nvox);
/*getchar();*/
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/278592.html
標籤:C++ 語言
上一篇:mysql原始碼編輯報錯
