📄 doconfig.c
字号:
/*********************************************************
OPEN AND READ THE INPUT FILE
Returns non-zero on error
1 -> File error (can't open file, unexpected EOF, etc.)
2 -> Invalid input parameter
3 -> System error (out of memory, etc.)
*********************************************************/
/*
* This file is part of tMCimg.
*
* tMCimg is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mcparse.h"
#include "tMCimg.h"
#if (HAVE_ASSERT_H)
#include <assert.h>
#endif
void initialize_config(struct Config *p)
{
#if (HAVE_ASSERT)
assert(p != NULL);
#endif
memset(p, 0, sizeof(struct Config));
/* Defaults */
p->flags.gen_twopt = 1;
p->flags.matlab_order = 1;
p->flags.source_move = 1;
p->flags.detector_move = 1;
p->flags.exiting_move = 0; /* Buggy right now */
p->flags.exact_exit_time = 0;
p->flags.mirror = 0;
p->flags.vary_courant = 0;
p->flags.fd_method = 0; /* FORWARD_EULER=0 */
p->flags.bcs = 0; /* DIRICHLET=0 */
p->flags.box_bcs = 0; /* BOX_CANT_TOUCH=0 */;
p->flags.grad_optode = 1;
return;
}
int loadconfig(struct Config *p, const char *filename)
{
char filenm[FILENMLEN];
FILE *fp;
int i, n;
#if (HAVE_ASSERT)
assert(p != NULL);
#endif
/* Initialize the config structure */
p->Ntissue = 0;
for (i = 0; i < MAXTISSUE; i++)
{
p->tmus[i] = MUS_AIR;
p->tmua[i] = MUA_AIR;
p->tg[i] = G_AIR;
p->tn[i] = IDX_AIR;
}
p->nDets = 0;
for (i = 0; i < MAXDET; i++)
{
p->detLoc[i][0] = p->detLoc[i][1] = p->detLoc[i][2] = -1;
p->detDir[i][0] = p->detDir[i][1] = p->detDir[i][2] = -1;
p->detRad[i] = -1;
p->detNA[i] = -1;
}
p->nSrcs = 0;
for (i = 0; i < MAXDET; i++)
{
p->srcLoc[i][0] = p->srcLoc[i][1] = p->srcLoc[i][2] = -1;
p->srcDir[i][0] = p->srcDir[i][1] = p->srcDir[i][2] = -1;
p->srcRad[i] = -1;
p->srcNA[i] = -1;
}
/* Open input file */
#if (HAVE_SNPRINTF)
snprintf(filenm, FILENMLEN, "%s.cfg", filename);
#else
sprintf(filenm, "%s.cfg", filename);
#endif
if ((fp = fopen(filenm, "rt")) == NULL)
{
fprintf(stderr,
"input_file \"%s\" not found, assuming you meant \"%s\"\n",
filenm, filename);
if ((fp = fopen(filename, "rt")) == NULL)
{
fprintf(stderr, "usage: tMCimg input_file (.cfg assumed)\n");
fprintf(stderr, "input_file = %s does not exist.\n", filenm);
return 1;
}
else
{
/* chop off the extension */
#if (HAVE_RINDEX)
char *q;
if ((q = rindex(filenm, '.')) != NULL)
*q = '\0';
#else
char *s, *q = NULL;
for (s = filenm; *s != '\0'; s++)
if (*s == '.')
q = s;
if (q != NULL)
*q = '\0';
#endif
}
}
/* READ THE INPUT FILE */
n = parseconfig(p, fp);
/* CLOSE FILE AND RETURN */
fclose(fp);
return n;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -