Ignore:
Timestamp:
Feb 26, 2008, 3:24:46 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Improved memory usage of BaseFileConverter?. Previous implementation was not flattering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/se/lu/thep/wenni/base/base1/BaseFileConverter/Data.cc

    r95 r594  
    33/*
    44  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2008 Jari Häkkinen
    56
    67  This file is part of WeNNI,
     
    5556    }
    5657    total_nof_columns_= column_offset_ + nof_fields_per_assay_*nof_assays_;
     58
     59    os_=new std::ofstream(output_file_.c_str());
    5760  }
    5861
    5962
     63  Data::~Data(void)
     64  {
     65    os_->close();
     66    delete os_;
     67  }
    6068
    61   void Data::push_back(const std::vector<std::string>& vals)
     69
     70  void Data::write(const std::vector<std::string>& vals)
    6271  {
    63     data_.push_back(std::vector<std::string>(nof_assays_));
    64     for(int i=0; i<nof_assays_; i++){
    65       if(vals[column_offset_+nof_fields_per_assay_*i+column_number_].empty()){
     72    for (int i=0; i<nof_assays_; i++) {
     73      if (vals[column_offset_+nof_fields_per_assay_*i+column_number_].empty())
    6674        // In a Base File missing values are given by a blank. To be
    6775        // able to load the data into a gsl matrix missing values are
    6876        // changed to NaNs.
    69         (*data_.rbegin())[i]="NaN";
    70       }
     77        *os_ << "NaN";
    7178      else
    72         (*data_.rbegin())[i]=vals[column_offset_ + nof_fields_per_assay_ * i +
    73                                   column_number_];
     79        *os_ << vals[column_offset_ + nof_fields_per_assay_ * i +column_number_];
     80      *os_ << (i==(nof_assays_-1) ? '\n' : '\t');
    7481    }
    7582  }
    7683
    7784
    78 
    79   void Data::write_matrix(void)
    80   {
    81     std::filebuf fb;
    82     fb.open (output_file_.c_str(),std::ios::out);
    83     std::ostream s(&fb);
    84     for (size_t i=0; i<data_.size(); i++) {
    85       for (size_t j=0; j<data_[i].size()-1; j++)
    86         s << data_[i][j] << "\t";
    87       s << data_[i][data_[i].size()-1] << std::endl;
    88     }
    89     fb.close();
    90   }
    91 
    92 
    9385}} // of namespace wenni and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.