Ejemplo n.º 1
0
void val(const adstring& s, int& v, int& code)
{
  int z;
  if ( (s.size() > 2) && (s(1,2) == adstring("0x") ))
    z = sscanf((const char*)s,"%x",&v);
  else
    z = sscanf((const char*)s,"%d",&v);

  if (z != 1)
    code = 1;
  else
    code = 0;
}
Ejemplo n.º 2
0
/**
 * Parse the string str1 as an index block. 
 * String str1 must start with "[" and end with "]".
 * Individual ranges are separated using a semi-colon (";").
 * Individual ranges have the form "x:y" or "x".
 * 
 * An example is "[1962:2000;2005;-1:1959]". In this example, the 
 * "-1" would be replaced by the specified minimum range for the block.
 * 
 * @param str1 - adstring to parse
 */
void IndexBlock::parse(adstring str1){
    if (debug) cout<<"Parsing '"<<str1<<"'"<<endl;
    if (!(str1(1,1)=="[")) {
        cout<<"Error parsing index block '"<<str1<<"'."<<endl;
        cout<<"Expected 1st character to be '[' but got '"<<str1(1,1)<<endl;
        cout<<"Aborting..."<<endl;
        exit(-1);
    }
    adstring str2 = str1(2,str1.size()-1);
    int k = 0; 
    int p=str2.pos(";");
    if (debug) cout<<"k,p,str = "<<k<<tb<<p<<tb<<str2<<endl;
    while(p){ 
        k++;
        str2 = str2(p+1,str2.size());
        p = str2.pos(";");
        if (debug) cout<<"k,p,str = "<<k<<tb<<p<<tb<<str2<<endl;
    }
    k++;
    if (debug) cout<<"Found "<<k<<" intervals"<<endl;
    
    nRCs = k;
    str2 = str1(2,str1.size()-1);
    ppIRs = new IndexRange*[nRCs];
    for (k=1;k<nRCs;k++){
        p = str2.pos(";");
        ppIRs[k-1] = new IndexRange(modMin,modMax);
        ppIRs[k-1]->parse(str2(1,p-1));
        str2 = str2(p+1,str2.size());
    }
    ppIRs[nRCs-1] = new IndexRange(modMin,modMax);
    ppIRs[nRCs-1]->parse(str2);
    if (debug) {
        cout<<"IndexBlock = "<<(*this)<<endl;
        cout<<"Enter 1 to contiinue > ";
        cin>>debug;
    }
    createIndexVectors();
}
Ejemplo n.º 3
0
/**
 * Parse a range string ("x:y" or "y") to obtain actual min, max for range.
 * If result finds x (y) < 0, then x (y) will be substituted using
 *  if x<0, x = modMin+1+x (so x=-1->x=modMin, x=-2->x=modMin-1, etc)
 *  if y<0, y = modMax-1-y (so y=-1->y=modMax, y=-2->y=modMax+1, etc)
 * @param str
 */
void IndexRange::parse(adstring str){
    if (debug) cout<<"IndexRange parse("<<str<<")"<<endl;
    int i = str.pos(":");
    if (debug) cout<<"':' located at position "<<i<<endl;
    if (i){
        mn = ::atoi(str(1,i-1));          
        if (mn<0){mn=modMin+1+mn;} else
        if (mn<modMin){mn=modMin;} else
        if (mn>modMax){mn=modMax;}
        mx = ::atoi(str(i+1,str.size())); 
        if (mx<0){mx=modMax-1-mx;} else
        if (mx<modMin){mx=modMin;} else
        if (mx>modMax){mx=modMax;}
    } else {
        mx = ::atoi(str);
        if (mx<0){mx=modMax-1-mx;} else
        if (mx<modMin){mx=modMin;} else
        if (mx>modMax){mx=modMax;}
        mn=mx;
    }
    if (debug) cout<<"mn,mx = "<<mn<<cc<<mx<<endl;
    createRangeVector(mn,mx);
}
Ejemplo n.º 4
0
int val(const adstring& s)
{
  int code;
  int v;
  int z;
  if ( (s.size() > 2) && (s(1,2) == adstring("0x") ))
    z = sscanf((const char*)s,"%x",&v);
  else
    z = sscanf((const char*)s,"%d",&v);

  if (z != 1)
    code = 1;
  else
    code = 0;

  return v;
}
Ejemplo n.º 5
0
/**
 * Sets the dimension type for this IndexBlockSet.
 * @param theType
 */
void IndexBlockSet::setType(adstring theType){
    type = theType;
    int p = theType.pos("_");
    if (p)  type = theType(1,p-1);//strip off type
    if (type==tcsam::STR_YEAR){
        modMin = ModelConfiguration::mnYr;
        modMax = ModelConfiguration::mxYr;
    } else
    if (type==tcsam::STR_SEX){
        modMin = 1;
        modMax = tcsam::nSXs;
    } else
    if (type==tcsam::STR_MATURITY_STATE){
        modMin = 1;
        modMax = tcsam::nMSs;
    } else
    if (type==tcsam::STR_SHELL_CONDITION){
        modMin = 1;
        modMax = tcsam::nSCs;
    } else 
    if (type==tcsam::STR_SIZE){
        modMin = 1;
        modMax = ModelConfiguration::nZBs;
    } else 
    if (type==tcsam::STR_FISHERY){
        modMin = 1;
        modMax = ModelConfiguration::nFsh;
    } else 
    if (type==tcsam::STR_SURVEY){
        modMin = 1;
        modMax = ModelConfiguration::nSrv;
    } else 
    {
        cout<<"WARNING...WARNING...WARNING..."<<endl;
        cout<<"Defining non-standard index type '"<<type<<"'."<<endl;
        cout<<"Make sure this is what you want."<<endl;
        cout<<"WARNING...WARNING...WARNING..."<<endl;
    }
    if (debug) cout<<"modMin = "<<modMin<<tb<<"modMax = "<<modMax<<endl;
}