一、运行EES_Test
- 原始的输入方式
a. 首先进入可执行文件所在的目录
cd /home/lihaoliang/eclipse-workspace/NicheBreadth/Default
b. 执行可执行文件,并附带参数
./NicheBreadth /home/lihaoliang/EES_Test scenario.seed_1.dispersal_good.nb_medium /home/lihaoliang/EES_Test/Results 64000 1 1 1
表1: 参数列表
| Num | Para | value |
|---|---|---|
| 1 | base_folder | /home/lihaoliang/EES_Test |
| 2 | scenario_config | scenario.seed_1.dispersal_good.nb_medium |
| 3 | result_folder | /home/lihaoliang/EES_Test/Results |
| 4 | memory_limit(in M) | 64000 |
| 5 | is_overwrite | 1 |
| 6 | with_detail | 1 |
| 7 | is_SQLite | 1 |
- 使用get_optlong()函数
| Num | Para | value | 缺省值 |
|---|---|---|---|
| 1 | base_folder | b | /home/lihaoliang/EES_Test |
| 2 | scenario_config | e | scenario.seed_1.dispersal_good.nb_medium |
| 3 | result_folder | r | /home/lihaoliang/EES_Test/Results |
| 4 | memory_limit(in M) | m | 64000 |
| 5 | is_overwrite | v | 1 |
| 6 | with_detail | d | 1 |
| 7 | is_SQLite | s | 1 |
- code
int main( int argc, char *argv[] )
{
int opt;
int digit_optind = 0;
int option_index = 0;
static const char *optString = "b:e:r:m:v:d:s:?h";
static const struct option longOpts[] = {
{ "base_folder", required_argument, NULL, 'b' }, // 1
{ "scenario_config", required_argument, NULL, 'e' }, // 2
{ "result_folder", required_argument, NULL, 'r' }, // 3
{ "memory_limit", optional_argument, NULL, 'm' }, // 4
{ "is_overwrite", optional_argument, NULL, 'v' }, // 5
{ "with_detail", optional_argument, NULL, 'd' }, // 6
{ "is_SQLite", optional_argument, NULL, 's' }, // 7
{ "help", no_argument, NULL, 'h' },
{ NULL, no_argument, NULL, 0 }
};
char base_folder[100];
char scenario_id[100];
char result_folder[100];
unsigned long memory_limit = 64000;
bool is_overwrite = 1;
bool with_detail = 1;
bool is_sqlite = 1;
while((opt = getopt_long(argc,argv,optString,longOpts,&option_index))!= -1)
{
char temp;
if(*optarg == '-') {
printf("please enter right argv\r\n");
printf("you can enter -h --help -? to get help\r\n");
exit( EXIT_FAILURE );
}
switch( opt ) {
case 'b':
strcpy(base_folder, optarg);
// later to determine wheather the argv is right
break;
case 'i':
strcpy(scenario_id, optarg);
// later to determine wheather the argv is right
break;
case 'r':
strcpy(result_folder, optarg);
// later to determine wheather the argv is right
break;
case 'm': // memory_limit
{
unsigned long memory_limit_temp = atoi(optarg);
// if no argv -- NULL && atoi(optarg)!=0 then memory_limit=1
// else memory_limit=0
if(memory_limit_temp >= 0) {
memory_limit = memory_limit_temp;
}
else
{
printf("please enter memory_limit in range [100, +]\r\n");
printf("you can enter -h --help -? to get help\r\n");
}
break;
}
case 'v': // is_overwrite
printf("optarg=%s\n",optarg );
temp = atoi(optarg);
printf("temp=%d\n", temp);
if(temp == 0) {
is_overwrite = 0;
}
break;
case 'd': // with_detail
temp = atoi(optarg);
if(temp == 0) {
with_detail = 0;
}
break;
case 's': // is_SQLite
temp = atoi(optarg);
if(temp == 0) {
is_sqlite = 0;
}
break;
case 'h': /* fall-through is intentional */
case '?':
display_usage();
break;
case 0: /* long option without a short arg */
printf("err!\n");
break;
default:
/* You won't actually get here. */
break;
}
}
printf("\n*\nresult\n*\n");
printf( "base_folder: %s\n", base_folder );
printf( "scenario_config: %s\n", scenario_id );
printf( "result_folder: %s\n", result_folder );
printf( "memory_limit: %ld\n", memory_limit );
printf( "is_overwrite: %d\n", is_overwrite );
printf( "with_detail: %d\n", with_detail );
printf( "is_SQLite: %d\n", is_sqlite );
return EXIT_SUCCESS;
}
先定框架,在不断细节化!
改变后指令
./NicheBreadth ./NicheBreadth -b /home/lihaoliang/EES_Test -e scenario.seed_1.dispersal_good.nb_medium -r /home/lihaoliang/EES_Test/Results -m 64000 -v 1 -d 1 -s 1

本文详细介绍了如何通过命令行参数配置并运行EES_Test程序。解释了每个参数的作用,如base_folder指定基础文件夹路径,scenario_config指定场景配置文件,result_folder设定结果输出目录等,并展示了使用get_optlong()函数进行参数解析的具体代码实现。
849

被折叠的 条评论
为什么被折叠?



