コード例 #1
0
ファイル: renewal1.cpp プロジェクト: pradal/StructureAnalysis
Renewal* Renewal::ascii_read(StatError &error , const string path ,
                             process_type type , int time , double cumul_threshold)

{
    RWLocaleSnapshot locale("en");
    RWCString buffer , token;
    size_t position;
    bool status;
    int line;
    DiscreteParametric *inter_event;
    Renewal *renew;
    ifstream in_file(path.c_str());


    renew = NULL;
    error.init();

    if (!in_file) {
        error.update(STAT_error[STATR_FILE_NAME]);
    }

    else {
        status = true;
        line = 0;

        inter_event = DiscreteParametric::parsing(error , in_file , line ,
                      NEGATIVE_BINOMIAL , cumul_threshold , 1);

        if (!inter_event) {
            status = false;
        }

        else {
            if (time < MAX(inter_event->offset , 2)) {
                status = false;
                error.update(SEQ_error[SEQR_SHORT_OBSERVATION_TIME]);
            }
            if (time > MAX_TIME) {
                status = false;
                error.update(SEQ_error[SEQR_LONG_OBSERVATION_TIME]);
            }
        }

        while (buffer.readLine(in_file , false)) {
            line++;

#     ifdef DEBUG
            cout << line << " " << buffer << endl;
#     endif

            position = buffer.first('#');
            if (position != RW_NPOS) {
                buffer.remove(position);
            }
            if (!(buffer.isNull())) {
                status = false;
                error.update(STAT_parsing[STATP_FORMAT] , line);
            }
        }

        if (status) {
            DiscreteParametric dtime(UNIFORM , time , time , D_DEFAULT , D_DEFAULT);
            renew = new Renewal(type , dtime , *inter_event);
        }

        delete inter_event;
    }

    return renew;
}
コード例 #2
0
ファイル: compound.cpp プロジェクト: pradal/StructureAnalysis
Compound* Compound::ascii_read(StatError &error , const string path , double cumul_threshold)

{
  RWCString buffer , token;

  size_t position;
  bool status;
  register int i;
  int line , read_line;
  DiscreteParametric *sum_dist , *dist;
  Compound *compound;
  ifstream in_file(path.c_str());


  compound = NULL;
  error.init();

  if (!in_file) {
    error.update(STAT_error[STATR_FILE_NAME]);
  }

  else {
    status = true;
    line = 0;
    read_line = 0;

    sum_dist = NULL;
    dist = NULL;

    while (buffer.readLine(in_file , false)) {
      line++;

#     ifdef DEBUG
      cout << line << "  " << buffer << endl;
#     endif

      position = buffer.first('#');
      if (position != RW_NPOS) {
        buffer.remove(position);
      }
      i = 0;

      RWCTokenizer next(buffer);

      while (!((token = next()).isNull())) {

        // test COMPOUND_DISTRIBUTION/SUM_DISTRIBUTION/ELEMENTARY_DISTRIBUTION keywords

        if (i == 0) {
          switch (read_line) {

          case 0 : {
            if (token != STAT_word[STATW_COMPOUND]) {
              status = false;
              error.correction_update(STAT_parsing[STATP_KEYWORD] , STAT_word[STATW_COMPOUND] , line);
            }
            break;
          }

          case 1 : {
            if (token != STAT_word[STATW_SUM]) {
              status = false;
              error.correction_update(STAT_parsing[STATP_KEYWORD] , STAT_word[STATW_SUM] , line);
            }
            break;
          }

          case 2 : {
            if (token != STAT_word[STATW_ELEMENTARY]) {
              status = false;
              error.correction_update(STAT_parsing[STATP_KEYWORD] , STAT_word[STATW_ELEMENTARY] , line);
            }
            break;
          }
          }
        }

        i++;
      }

      if (i > 0) {
        if (i != 1) {
          status = false;
          error.update(STAT_parsing[STATP_FORMAT] , line);
        }

        switch (read_line) {

        case 1 : {
          sum_dist = DiscreteParametric::parsing(error , in_file , line ,
                                                 NEGATIVE_BINOMIAL , CUMUL_THRESHOLD);
          if (!sum_dist) {
            status = false;
          }
          break;
        }

        case 2 : {
          dist = DiscreteParametric::parsing(error , in_file , line ,
                                             NEGATIVE_BINOMIAL , cumul_threshold);
          if (!dist) {
            status = false;
          }
          break;
        }
        }

        read_line++;
        if (read_line == 3) {
          break;
        }
      }
    }

    if (read_line != 3) {
      status = false;
      error.update(STAT_parsing[STATP_FORMAT] , line);
    }

    while (buffer.readLine(in_file , false)) {
      line++;

#     ifdef DEBUG
      cout << line << "  " << buffer << endl;
#     endif

      position = buffer.first('#');
      if (position != RW_NPOS) {
        buffer.remove(position);
      }

      if (!(buffer.isNull())) {
        status = false;
        error.update(STAT_parsing[STATP_FORMAT] , line);
      }
    }

    if (status) {
      compound = new Compound(*sum_dist , *dist , cumul_threshold);
    }

    delete sum_dist;
    delete dist;
  }

  return compound;
}