summaryrefslogtreecommitdiff
path: root/src/main/ProcessParameterDatabase.c
blob: fe6cb274a4ec078c90e1d217025b0775dd32bc57 (plain)
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
 /*@@
   @file      ProcessParameterDatabase.c
   @date      Thu Sep 24 10:34:46 1998
   @author    Tom Goodale
   @desc 
              Routines to determine the parameters and store them.
   @enddesc 
   @version   $Id$
 @@*/

#include <stdio.h>
#include <string.h>

#include "cctk_Flesh.h"
#include "cctk_Parameter.h"
#include "cctk_WarnLevel.h"

#include "cctki_Parameter.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(main_ProcessParameterDatabase_c)

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/
int ParseFile (FILE *ifp, 
               int (*set_function) (const char *, const char *, int),
               tFleshConfig *ConfigData);
void CCTKi_SetParameterSetMask (int mask);


/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    CCTKi_ProcessParameterDatabase
   @date       Thu Sep 24 10:37:07 1998
   @author     Tom Goodale
   @desc 
   
   @enddesc 
   @calls      CCTKi_SetParameterSetMask
               CCTKi_NumParameterFileErrors
               ParseFile
 
   @var        ConfigData
   @vdesc      Flesh configuration data
   @vtype      tFleshConfig *
   @vio        inout
   @endvar 

   @returntype int
   @returndesc
                0 - success, or<BR>
               -1 - unable to open parameter file
   @endreturndesc
@@*/
int CCTKi_ProcessParameterDatabase (tFleshConfig *ConfigData)
{
  int parse_errors;
  FILE *parameter_file;


  CCTKi_SetParameterSetMask (PARAMETER_RECOVERY_PRE);

  if (! strcmp (ConfigData->parameter_file_name, "-"))
  {
    parameter_file = stdin;
  }
  else
  {
    parameter_file = fopen (ConfigData->parameter_file_name, "r");
  }

  if (parameter_file)
  {
    parse_errors = ParseFile (parameter_file, CCTKi_SetParameter, ConfigData);

    if (strcmp (ConfigData->parameter_file_name, "-"))
    {
      fclose (parameter_file);
    }

    if (parse_errors)
    {
      CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
                  "CCTKi_SetParameterSetMask: %d parsing errors in "
                  "parameter file", parse_errors);
    }      

    if (CCTKi_NumParameterFileErrors (1))
    {
      CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
                  "CCTKi_SetParameterSetMask: %d level 1 errors in "
                  "parameter file", CCTKi_NumParameterFileErrors (1));
    }

    if (CCTKi_NumParameterFileErrors (0))
    {
      CCTK_VWarn (0, __LINE__, __FILE__, "Cactus",
                  "CCTKi_SetParameterSetMask: %d level 0 errors in "
                  "parameter file", CCTKi_NumParameterFileErrors (0));
    }
  }
  else
  {
    fprintf (stderr, "Unable to open parameter file '%s'\n", 
             ConfigData->parameter_file_name);
  }
      
  return (parameter_file ? 0 : -1);
}