Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ParseOptions Class Reference

#include <ParseOptions.h>

List of all members.

Public Member Functions

 ParseOptions (void)
 ~ParseOptions (void)
int require (const char *newname, const char *parent, const char *msg, BigReal *ptr, BigReal defalt)
int require (const char *newname, const char *parent, const char *msg, BigReal *ptr)
int require (const char *newname, const char *parent, const char *msg, Vector *ptr, Vector defalt)
int require (const char *newname, const char *parent, const char *msg, Vector *ptr)
int require (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int require (const char *newname, const char *parent, const char *msg, int *ptr)
int require (const char *newname, const char *parent, const char *msg, unsigned int *ptr, unsigned int defalt)
int require (const char *newname, const char *parent, const char *msg, unsigned int *ptr)
int requireB (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int requireB (const char *newname, const char *parent, const char *msg, int *ptr)
int require (const char *newname, const char *parent, const char *msg, StringList **ptr=NULL, int many_allowed=FALSE)
int require (const char *newname, const char *parent, const char *msg, char *ptr)
int optional (const char *newname, const char *parent, const char *msg, BigReal *ptr, BigReal defalt)
int optional (const char *newname, const char *parent, const char *msg, BigReal *ptr)
int optional (const char *newname, const char *parent, const char *msg, Vector *ptr, Vector defalt)
int optional (const char *newname, const char *parent, const char *msg, Vector *ptr)
int optional (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int optional (const char *newname, const char *parent, const char *msg, int *ptr)
int optional (const char *newname, const char *parent, const char *msg, unsigned int *ptr, unsigned int defalt)
int optional (const char *newname, const char *parent, const char *msg, unsigned int *ptr)
int optionalB (const char *newname, const char *parent, const char *msg, int *ptr, int defalt)
int optionalB (const char *newname, const char *parent, const char *msg, int *ptr)
int optional (const char *newname, const char *parent, const char *msg, StringList **ptr=NULL, int many_allowed=FALSE)
int optional (const char *newname, const char *parent, const char *msg, char *ptr)
Range range (const char *name)
void range (const char *name, Range newrange)
Bool check_consistancy (void)
Bool set (const ConfigList &configlist)
Bool get (const char *name, int *val)
Bool get (const char *name, BigReal *val)
Bool get (const char *name, Vector *val)
Bool get (const char *name, StringList **val)
Bool get (const char *name, char *val, int n=0)
int num (const char *name)
Bool defined (const char *name)
Bool exists (const char *name)
Bool units (const char *name, Units units)
Bool units (const char *name, Units *units)


Constructor & Destructor Documentation

ParseOptions::ParseOptions void   ) 
 

Definition at line 195 of file ParseOptions.C.

References TRUE, and ParseOptions::DataElement::type.

00195                                {
00196    configList = NULL;
00197    array_size = 0;
00198    array_max_size = 20;
00199    data_array = new DataElement*[array_max_size];
00200    DataElement *tmp = new DataElement("main", "main", TRUE,
00201                                       "Error in ParseOptions",
00202                                       (int *) NULL,  0);
00203    tmp->type = DataElement::UNDEF;
00204    add_element(tmp);
00205 }

ParseOptions::~ParseOptions void   ) 
 

Definition at line 208 of file ParseOptions.C.

00208                                 {
00209    for (int i=0; i<array_size; i++) {
00210       delete data_array[i];
00211    }
00212    delete [] data_array;
00213 }


Member Function Documentation

Bool ParseOptions::check_consistancy void   ) 
 

Definition at line 387 of file ParseOptions.C.

References Bool, iERROR(), iout, ParseOptions::DataElement::name, ParseOptions::DataElement::parent, and ParseOptions::DataElement::parent_ptr.

Referenced by SimParameters::initialize_config_data().

00387                                          {
00388    int i;
00389    // check for lack of parent
00390    {
00391       int has_error = FALSE;
00392       for(i=1; i<array_size; i++) {
00393          if (!data_array[i]->parent_ptr) {
00394             // missing a parent
00395             iout << iERROR << "Configuration element '" << data_array[i]->name
00396                     << "' defined, but the parent element" << "\n" << endi;
00397             iout << iERROR << "  '" << data_array[i]->parent << "' is nowhere "
00398                     << "to be found" << "\n" << endi;
00399             has_error = TRUE;
00400          }
00401       }
00402       if (has_error) return 0;
00403    }
00404 
00405    // check for loop constructs in the "main" heirarchy
00406    int *arr = new int[array_size];
00407    for (i=0; i<array_size; i++) {  // initialize it
00408       arr[i] = 0;
00409    }
00410    if (!check_children(0, arr)) {
00411       // a loop was found
00412       iout << iERROR << "Loop found in ParseOptions data" << "\n" << endi;
00413       delete [] arr;
00414       return 0;
00415    }
00416 
00417    // check for elements inaccessible to "main"
00418    {
00419       int has_error = FALSE;
00420       for (i=1; i<array_size; i++) {
00421          if (arr[i] == 0) {
00422             // found an inaccesible element
00423             if (has_error == FALSE) { // first time, so print message
00424                iout << iERROR 
00425                    << "Found data in ParseOptions which are inaccessible "
00426                    << "to" << "\n" << endi;
00427                iout << iERROR 
00428                   << "the main data heirarchy.  Errors in:" << "\n" << endi;
00429                has_error = TRUE;
00430             }
00431             iout << iERROR << "   '" << data_array[i]->name << "' depends on '"
00432                     << data_array[i]->parent << "'" << "\n" << endi;
00433          }
00434       }
00435       if (has_error) {
00436          delete [] arr;
00437          return 0;
00438       }
00439    }
00440    // looks like everything went well
00441    delete [] arr;
00442    return 1;
00443 }

Bool ParseOptions::defined const char *  name  ) 
 

Definition at line 893 of file ParseOptions.C.

References Bool, and ParseOptions::DataElement::is_defined.

00894 {
00895    if (!name) return FALSE;
00896    DataElement *tmp = internal_find(name);
00897    if (!tmp) return FALSE;
00898    if (tmp->is_defined) {
00899       return TRUE;
00900    }
00901    return FALSE;
00902 }

Bool ParseOptions::exists const char *  name  ) 
 

Definition at line 884 of file ParseOptions.C.

References Bool.

Referenced by set().

00885 {
00886    if (!name) return 0;
00887    if (internal_find(name)) {
00888       return 1;
00889    }
00890    return 0;
00891 }

Bool ParseOptions::get const char *  name,
char *  val,
int  n = 0
 

Definition at line 1044 of file ParseOptions.C.

References Bool, StringList::data, get(), and StringList::next.

01045 {
01046    if (!val || n<0) {return FALSE;}
01047    StringList *tmp;
01048    if (!get(name, &tmp)) {val[0]=STRINGNULL; return FALSE; }
01049    int i=n;
01050    while (i>0 && tmp) { // search for the nth element
01051       tmp=tmp->next;
01052       i--;
01053    }
01054    if (tmp) {  // if it was long enough, return it
01055       strcpy(val, tmp->data);
01056       return TRUE;
01057    }
01058    val[0] = STRINGNULL;
01059    return FALSE;
01060 }

Bool ParseOptions::get const char *  name,
StringList **  val
 

Definition at line 1029 of file ParseOptions.C.

References Bool, ConfigList::find(), and ParseOptions::DataElement::is_defined.

01029                                                          {
01030    if (!val) return FALSE;
01031    DataElement *el = internal_find(name); // first check it is internally valid
01032    if (el == NULL || !el->is_defined) {
01033       return FALSE;
01034    }
01035    // then simply ask the configList itself for the answer
01036    // (while I do keep the information internally, in sldata, why bother?
01037    if (!configList) { return FALSE; }
01038    *val = configList->find(name);
01039    if (!*val) { return FALSE; }  // paranoia, I know...
01040    return TRUE;
01041 }

Bool ParseOptions::get const char *  name,
Vector val
 

Definition at line 986 of file ParseOptions.C.

References Bool, StringList::data, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), Vector::set(), ParseOptions::DataElement::sldata, ParseOptions::DataElement::type, and ParseOptions::DataElement::vdata.

00986                                                     {
00987    if (!val) return FALSE;
00988    DataElement *el = internal_find(name);
00989    if (el == NULL || !el->is_defined) {
00990       return FALSE;
00991    }
00992    switch (el -> type) {
00993     case DataElement::FLOAT:
00994       iout << iERROR 
00995          << "ParseOptions cannot convert from float to Vector for '"
00996          << name << "'" << "\n" << endi;
00997       return FALSE;
00998     case DataElement::INT:
00999       iout << iERROR 
01000          << "ParseOptions cannot convert from int to Vector for '"
01001          << name << "'" << "\n" << endi;
01002       return FALSE;
01003     case DataElement::STRING:
01004     case DataElement::STRINGLIST:{
01005       iout << iWARN 
01006          << "ParseOptions doing a conversion from StringList[0] to "
01007          << "Vector for '" << name << "'" << "\n" << endi;
01008       Vector v;
01009       if (!v.set(el->sldata->data)) {
01010          iout << iERROR 
01011             << "Could not convert '" << el->sldata->data
01012             << "' to a Vector";
01013          return FALSE;
01014       }
01015       *val = v;
01016       return TRUE;
01017      }
01018      case DataElement::VECTOR : 
01019       *val = el->vdata;
01020       return TRUE;
01021     default:
01022       iout << iERROR 
01023          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
01024          << "\n" << endi;
01025 
01026    }
01027    return FALSE;
01028 }

Bool ParseOptions::get const char *  name,
BigReal val
 

Definition at line 945 of file ParseOptions.C.

References Bool, StringList::data, ParseOptions::DataElement::fdata, ParseOptions::DataElement::idata, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, and ParseOptions::DataElement::type.

00945                                                      {
00946    if (!val) return FALSE;
00947    DataElement *el = internal_find(name);
00948    if (el == NULL || !el->is_defined) {
00949       return FALSE;
00950    }
00951    switch (el -> type) {
00952     case DataElement::FLOAT: 
00953       *val =  el->fdata;
00954       return TRUE;
00955     case DataElement::INT:
00956       iout << iWARN 
00957          << "ParseOptions doing a conversion from int to float '"
00958          << name << "'" << "\n" << endi;
00959       *val = (BigReal) el->idata;
00960       return TRUE;
00961     case DataElement::BOOL:
00962       iout << iWARN 
00963          << "ParseOptions doing a conversion from boolean to float for '"
00964          << name << "'" << "\n" << endi;
00965       *val = (BigReal) el->idata;
00966       return TRUE;
00967     case DataElement::STRING:
00968     case DataElement::STRINGLIST:
00969      iout << iWARN 
00970         << "ParseOptions doing a conversion from StringList[0] to float "
00971         << "for '" << name << "'" << "\n" << endi;
00972       *val = atof(el->sldata->data);
00973       return TRUE;
00974     case DataElement::VECTOR :
00975        iout << iERROR 
00976           << "ParseOptions cannot convert from Vector to float for '"
00977           << name << "'" << "\n" << endi;
00978        return FALSE;
00979     default:
00980       iout << iERROR 
00981          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
00982          << "\n" << endi;
00983    }
00984    return FALSE;
00985 }

Bool ParseOptions::get const char *  name,
int *  val
 

Definition at line 908 of file ParseOptions.C.

References Bool, StringList::data, ParseOptions::DataElement::fdata, ParseOptions::DataElement::idata, iERROR(), iout, ParseOptions::DataElement::is_defined, iWARN(), ParseOptions::DataElement::sldata, and ParseOptions::DataElement::type.

Referenced by get(), and num().

00908                                                  {
00909    if (!val) return FALSE;
00910    DataElement *el = internal_find(name);
00911    if (el == NULL || !el->is_defined) {
00912       return FALSE;
00913    }
00914    switch (el->type) {
00915     case DataElement::FLOAT :
00916       iout << iWARN 
00917          << "ParseOptions doing a conversion from float to int for '"
00918          << name << "'" << "\n" << endi;
00919       *val = (int) el->fdata;
00920       return TRUE;
00921     case DataElement::INT:
00922     case DataElement::BOOL:
00923       *val = el->idata;
00924       return TRUE;
00925     case DataElement::STRINGLIST :
00926     case DataElement::STRING :
00927       iout << iWARN 
00928          << "ParseOptions doing a conversion from StringList[0] to int "
00929          << "for '" << name << "'" << "\n" << endi;
00930       *val = atoi(el->sldata->data);
00931       return TRUE;
00932     case DataElement::VECTOR :
00933        iout << iERROR 
00934           << "ParseOptions cannot convert from Vector to int for '"
00935           << name << "'" << "\n" << endi;
00936        return FALSE;
00937     default:
00938       iout << iERROR 
00939          << "Unknown data type " << (int)(el->type) << " for '" << name << "'"
00940          << "\n" << endi;
00941    }
00942    return FALSE;
00943 }

int ParseOptions::num const char *  name  ) 
 

Definition at line 1063 of file ParseOptions.C.

References get(), ParseOptions::DataElement::is_defined, ParseOptions::DataElement::many_allowed, and StringList::next.

01064 {
01065    DataElement *el = internal_find(name);
01066    if (!el || !el ->is_defined) {
01067       return 0;
01068    }
01069    if (!el->many_allowed) {
01070       return 1;
01071    }
01072    StringList *tmp;
01073    if (!get(name, &tmp)) { return 0; }
01074    int i=0;
01075    while (tmp) {
01076       i++;
01077       tmp=tmp->next;
01078    }
01079    return i;
01080 }

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
char *  ptr
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
StringList **  ptr = NULL,
int  many_allowed = FALSE
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr,
unsigned int  defalt
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr,
Vector  defalt
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr
 

int ParseOptions::optional const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr,
BigReal  defalt
 

int ParseOptions::optionalB const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr
 

int ParseOptions::optionalB const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt
 

void ParseOptions::range const char *  name,
Range  newrange
 

Definition at line 1084 of file ParseOptions.C.

References iERROR(), iout, and ParseOptions::DataElement::range.

01085 {
01086    DataElement *el = internal_find(name);
01087    if (!el) {
01088       iout << iERROR 
01089          << "Trying to set the range of undefined variable '"
01090          << name << "'" << "\n" << endi;
01091       return;
01092    }
01093    el->range = newrange;
01094    
01095 }

Range ParseOptions::range const char *  name  ) 
 

Definition at line 1096 of file ParseOptions.C.

References iERROR(), iout, ParseOptions::DataElement::range, and Range.

01097 {
01098    DataElement *el = internal_find(name);
01099    if (!el) {
01100       iout << iERROR 
01101          << "Trying to get the range of undefined variable '"
01102          << name << "'" << "\n" << endi;
01103       return FREE_RANGE;
01104    }
01105    return el->range;
01106 }

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
char *  ptr
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
StringList **  ptr = NULL,
int  many_allowed = FALSE
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
unsigned int *  ptr,
unsigned int  defalt
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
Vector ptr,
Vector  defalt
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr
 

int ParseOptions::require const char *  newname,
const char *  parent,
const char *  msg,
BigReal ptr,
BigReal  defalt
 

int ParseOptions::requireB const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr
 

int ParseOptions::requireB const char *  newname,
const char *  parent,
const char *  msg,
int *  ptr,
int  defalt
 

Bool ParseOptions::set const ConfigList configlist  ) 
 

Definition at line 628 of file ParseOptions.C.

References Bool, StringList::data, ParseOptions::DataElement::error_message, exists(), ParseOptions::DataElement::fdata, ParseOptions::DataElement::fdef, ConfigList::find(), ParseOptions::DataElement::has_default, ConfigList::head(), ParseOptions::DataElement::idata, ParseOptions::DataElement::idef, iERROR(), ParseOptions::DataElement::index, iout, ParseOptions::DataElement::is_defined, ParseOptions::DataElement::is_optional, iWARN(), ParseOptions::DataElement::many_allowed, ParseOptions::DataElement::name, StringList::next, ParseOptions::DataElement::parent_ptr, ParseOptions::DataElement::sldata, ParseOptions::DataElement::type, ParseOptions::DataElement::uidata, ParseOptions::DataElement::uidef, ParseOptions::DataElement::vdata, and ParseOptions::DataElement::vdef.

Referenced by SimParameters::initialize_config_data().

00629 {
00630    // the algorithm is easy, though it looks scary
00631    int cont = TRUE, i;  // do some initialization
00632    StringList *slptr;
00633    DataElement *data;
00634    int has_error = FALSE;
00635    int *checked = new int[array_size];
00636    configList = &clist;
00637 
00638    // I make here a list of element I have already checked, starting
00639    // at the head.  I check only children of those that have already
00640    // been defined and add it to the checked list
00641    for (i=0; i<array_size; i++) 
00642    {
00643       checked[i] = FALSE;
00644    }
00645 
00646    //   make "main" 'defined' (at this point, nothing else should be defined)
00647    data_array[0]->is_defined = TRUE;
00648    checked[0] = TRUE;  // and make "main" checked
00649    
00650    // while there is still data which hasn't been defined
00651    while (cont) 
00652    {
00653       cont = FALSE;
00654       for (i=1; i<array_size; i++) 
00655       {  // check each element
00656          data = data_array[i];
00657 
00658          // find unchecked data which has a parent which was checked
00659          // and defined
00660          if (!checked[data->index] &&
00661              checked[data-> parent_ptr -> index] &&
00662              data -> parent_ptr -> is_defined) 
00663          {
00664             cont = TRUE;
00665             checked[data->index] = TRUE;  // so I don't check again
00666 
00667             // check to see if data is available in the StringList
00668             slptr = clist.find(data->name);
00669 
00670             if (slptr != NULL) 
00671             {  // it is 
00672 
00673                // most data types allow only 1 item, so check if that is
00674                // a problem.  (some StringLists, like 'parameters', allow
00675                // multiple strings)
00676                if (!data->many_allowed && slptr->next != NULL) 
00677                {
00678                   iout << iERROR << "Multiple definitions of '" << data->name << "'" << "\n" << endi;
00679                   iout << iERROR << "  in the configuration file are not allowed" << "\n" << endi;
00680                   has_error = TRUE;
00681                }
00682 
00683                data->is_defined = TRUE;
00684 
00685                // set the appropriate data field
00686                if (data->type == DataElement::FLOAT) 
00687                {
00688                   if (!scan_float(data, slptr->data)) 
00689                         has_error = TRUE;
00690                } 
00691                else if (data->type == DataElement::VECTOR) 
00692                {
00693                   if (!scan_vector(data, slptr->data)) 
00694                         has_error = TRUE;
00695                } 
00696                else if (data->type == DataElement::INT) 
00697                {
00698                   if (!scan_int(data, slptr->data)) 
00699                         has_error = TRUE;
00700                } 
00701                else if (data->type == DataElement::UINT) 
00702                {
00703                   if (!scan_uint(data, slptr->data)) 
00704                         has_error = TRUE;
00705                } 
00706                else if (data->type == DataElement::BOOL) 
00707                {
00708                   if (!scan_bool(data, slptr->data)) 
00709                         has_error = TRUE;
00710                } 
00711                else if (data->type == DataElement::STRINGLIST ||
00712                           data->type == DataElement::STRING ) 
00713                {
00714                   data->sldata = slptr;
00715                } 
00716                else 
00717                {
00718                   iout << iERROR << "Unknown ParseOption data type " << (int)(data->type) << " for "
00719                           << "variable " << data->name << "\n" << endi;
00720                }
00721             } 
00722             else 
00723             {  // no definition; is there a default?
00724                if (data->has_default) 
00725                {
00726                   data->is_defined = TRUE;
00727 
00728                   if (data->type == DataElement::FLOAT) 
00729                   {
00730                      data->fdata = data->fdef;
00731                   } 
00732                   else if (data->type == DataElement::VECTOR) 
00733                   {
00734                      data->vdata = data->vdef;
00735                   } 
00736                   else if (data->type == DataElement::UINT) 
00737                   {
00738                      data->uidata = data->uidef;
00739                   } 
00740                   else if (data->type == DataElement::INT ||
00741                              data->type == DataElement::BOOL) 
00742                   {
00743                      data->idata = data->idef;
00744                   } 
00745                   else 
00746                   {
00747                         iout << iERROR << "Unknown ParseOption data type " << (int)(data->type) << " for "
00748                                 << "variable " << data->name << "\n" << endi;
00749                   }
00750                }
00751             }
00752 
00753             // at this point we should have gotten data from the file or the defaults,
00754             // or it hasn't yet been defined.  If it still isn't defined, check
00755             // to see if it is optional
00756             if (!data->is_defined) 
00757             { // if still not defined,
00758                if (!data->is_optional) 
00759                { // it is it required
00760                   has_error = TRUE;
00761                   iout << iERROR << "'" << data->name << "' is a required configuration option" << "\n" << endi;
00762 
00763                   // print some helpful information if this isn't a "main" option
00764                   if (data->parent_ptr != data_array[0]) 
00765                   {
00766                         iout << iERROR << "  when '" << data->parent_ptr -> name << "' is set" << "\n" << endi;
00767                   }  // printed parent info
00768 
00769                   iout << iERROR << data->name << " defines:   " << data->error_message << "\n" << endi;
00770 
00771                }  // printed error message
00772             }  
00773             else 
00774             { // there was a definition, so assign to the variable
00775                if (data->type ==  DataElement::FLOAT) 
00776                {
00777                   if (!set_float(data)) 
00778                         has_error = TRUE;
00779                } 
00780                else if ( data -> type == DataElement::VECTOR) 
00781                {
00782                   set_vector(data);
00783                } 
00784                else if ( data -> type == DataElement::INT) 
00785                {
00786                   if (!set_int(data)) 
00787                         has_error = TRUE;
00788                } 
00789                else if ( data -> type == DataElement::UINT) 
00790                {
00791                   if (!set_uint(data)) 
00792                         has_error = TRUE;
00793                } 
00794                else if ( data -> type == DataElement::BOOL) 
00795                {
00796                   set_bool(data);
00797 
00798                   if (is_parent_node(data)) 
00799                   {
00800                         // this makes the boolean variable undefined if it is 'off'
00801                         // _and_ it is a parent; this makes it agree with namd's
00802                         // configuration option semantics
00803                         data->is_defined = data->idata;
00804                   }
00805                } 
00806                else if ( data -> type == DataElement::STRINGLIST) 
00807                {
00808                   set_stringlist(data);
00809                } 
00810                else if ( data -> type == DataElement::STRING) 
00811                {
00812                   set_string(data);
00813                } 
00814                else 
00815                {
00816                   // already printed the error message
00817                }
00818             }
00819          }  // end of checking the available variables
00820       } // end of pass through the list
00821    } // end of finding data in the ConfigList
00822 
00823 
00824    // and now print the warning messages
00825 
00826    // first, find elements which are in the configuration file and are
00827    // valid, but which were not needed (ie, the checked array wasn''t set)
00828    {
00829       int flg = 0;
00830 
00831       for (int i=1; i<array_size; i++) 
00832       {
00833          if (!checked[i]) { // wasn't needed
00834             data = data_array[i];
00835             if (clist.find(data->name)) {
00836                if (flg == 0) {
00837                   flg = 1;
00838                   iout << iWARN 
00839                     << "The following variables were set in the\n";
00840                   iout << iWARN 
00841                     << "configuation file but were not needed" << "\n" << endi;
00842                }
00843                iout << iWARN << "   " << data->name << "\n" << endi;
00844             }
00845          }
00846       }
00847    }
00848    // and now look for names which are in the config list but which
00849    // are not in the parseoptions list
00850    {
00851       int flg = 0;
00852       ConfigList::ConfigListNode const *ptr;
00853       for (ptr = clist.head(); ptr != NULL; ptr = ptr -> next) {
00854          if (!exists(ptr -> name)) {
00855             if (flg == 0) {
00856                flg = 1;
00857                has_error = TRUE;
00858                iout << iERROR
00859                   << "The following variables were set in the\n";
00860                iout << iERROR
00861                   << "configuration file but are NOT VALID\n" << endi;
00862             }
00863             iout << iERROR << "   " << ptr -> name << "\n" << endi;
00864          }
00865       }
00866    }
00867       
00868    delete [] checked;
00869    return !has_error;
00870 }

Bool ParseOptions::units const char *  name,
Units units
 

Definition at line 1129 of file ParseOptions.C.

References Bool, iERROR(), iout, and ParseOptions::DataElement::units.

01130 {
01131    DataElement *tmp = internal_find(name);
01132    *units = N_UNIT;
01133    if (!tmp) {
01134       iout << iERROR 
01135          << "'" << name << "' doesn't exist so cannot get its units"
01136          << "\n" << endi;
01137       return FALSE;
01138    }
01139    if (tmp -> type != DataElement::INT && 
01140        tmp -> type != DataElement::FLOAT) {
01141       iout << iERROR 
01142          << "Can only get units for FLOAT and INT variables, and '"
01143          << name << "' isn't one of those" << "\n" << endi;
01144       return FALSE;
01145    }
01146    *units = tmp->units;
01147    return TRUE;
01148 }

Bool ParseOptions::units const char *  name,
Units  units
 

Definition at line 1109 of file ParseOptions.C.

References Bool, iERROR(), iout, and ustring().

01110 {
01111   DataElement *tmp = internal_find(name);
01112   if (!tmp) {
01113      iout << iERROR 
01114         << name << " not found so units not set" << "\n" << endi;
01115      return FALSE;
01116   }
01117   if ((tmp -> type == DataElement::INT && units != N_UNIT) ||
01118       (tmp -> type != DataElement::INT && 
01119        tmp -> type != DataElement::FLOAT)) {
01120      iout << iERROR 
01121         << "Cannot set units '" << ustring(units) << "' for option '"
01122         << name << "'; wrong data type" << "\n" << endi;
01123      return FALSE;
01124   }
01125   tmp -> units = units;
01126   return TRUE;
01127 }


The documentation for this class was generated from the following files:
Generated on Tue Nov 24 04:07:50 2009 for NAMD by  doxygen 1.3.9.1