Example #1
0
int main()
{
	DataMap sightings;
	generate_n(
		inserter(sightings, sightings.begin()),
		50, SightingGen(animals));
	// Print everything:
	copy(sightings.begin(), sightings.end(),
		ostream_iterator<Sighting>(cout, "\n"));

	// Print sightings for selected animal:
	while (true) {
		cout << "select an animal or 'q' to quit: ";
		for (int i = 0; i < animals.size(); i++)
			cout << '[' << i << ']' << animals[i] << ' ';
		cout << endl;
		string reply;
		cin >> reply;
		if (reply.at(0) == 'q') return 0;
		istringstream r(reply);
		int i;
		r >> i;	// Convert to int
		i %= animals.size();
		
		// Iterators in "range" denote begin, one
		// past end of matching range:
		pair<DMIter, DMIter> range =
			sightings.equal_range(animals[i]);
		copy(range.first, range.second,
			ostream_iterator<Sighting>(cout, "\n"));
	}
} ///:~
Example #2
0
bool CacheManagerI::load(const KeySeq& keys, const std::string& namespaceId, const std::string& businessId, 
                long expiredTime, bool useMaster, const Ice::Current& current) {
    std::ostringstream os;
    os<<"Key : ";
    for(KeySeq::const_iterator it = keys.begin(); it != keys.end(); ++it) {
        os<<*it<<" ";
    }
    os<<" namespaceId :"<<namespaceId;
    os<<" businessId :"<<businessId;
    os<<" expiredTime :"<<expiredTime;
    os<<" useMaster :"<<useMaster;
    MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
    ProducerManagerClientPtr producer = getProducer();
    if(producer == NULL) {
        return false;
    }
    
    bool sucFlag = true;

    KeySeq inputKeys(keys.begin(), keys.end());
    KeySeq lockedKeys;
    KeySeq failedLockedKeys;
    DataMap res;
    
    while(true) {
        xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, inputKeys, lockedKeys, failedLockedKeys);
        if(!lockedKeys.empty()) {
            DataMap singleRes = producer->produce(keys, businessId, useMaster, 1000);
            if(!singleRes.empty()) {
                res.insert(singleRes.begin(), singleRes.end());
            }
        
            CacheClientPtr cache = getCache();
            if(cache != NULL) {
                for(DataMap::const_iterator it = singleRes.begin(); it != singleRes.end(); ++it) {
                    sucFlag &= cache->set(it->first, it->second, namespaceId, businessId, expiredTime, 1000);
                }
            }
            if(failedLockedKeys.empty()) {
                break;
            }
        }
        inputKeys.swap(failedLockedKeys);
        lockedKeys.clear();
        failedLockedKeys.clear();
    }

    return sucFlag;
}
Example #3
0
/*
*Function:
*Inputs:noneSeekMaxMinTimeLine
*Outputs:none
*Returns:none
*/
void Graph::SeekMaxMinTimeLine(DataMap &l)  // seek max and min in a line
{
	IT_IT("Graph::SeekMaxMinTimeLine");
	
	if(l.size() > 0)
	{  
		if(minTime > (*l.begin()).first)
		{
			minTime = (*l.begin()).first;
		}; 
		if(maxTime < (*l.rbegin()).first)
		{
			maxTime = (*l.rbegin()).first;
		};
	}; 
};
Example #4
0
void writeout_file(char *time_peroid){
	char sql[1024];
	int retcode;
	
	sprintf(sql, "SELECT * FROM history");
	retcode = sqlite3_exec(pDB, sql, &sqlite3_exec_callback, time_peroid, &errmsg);
	if(SQLITE_OK!=retcode){
		printf("retcode of sqlite3_exec():%d description:%s", retcode, errmsg);
		sqlite3_free(errmsg);
	}
	
	char filename[1024];
	sprintf(filename, "%s.csv", time_peroid);
	FILE *fp = fopen(filename, "wt");
	if(NULL!=fp){
		printf("\nWriting file:%s...", filename);
		for(DataMap::iterator it = dataMap.begin(); it != dataMap.end(); it++){
			struct tm *st = localtime(&(it->second.timestamp));
			fprintf(fp, "%04d.%02d.%02d,%02d:%02d,%lf,%lf,%lf,%lf,%lf\n", 
				st->tm_year+1900, st->tm_mon+1, st->tm_mday, st->tm_hour, st->tm_min,
				it->second.open, it->second.high, it->second.low, it->second.close,
				it->second.amount);
				/*
				printf("timestamp:%s open:%lf high:%lf low:%lf close:%lf amount:%lf\n",
				ctime(&(it->second.timestamp)), it->second.open, it->second.high,
				it->second.low, it->second.close, it->second.amount);
			*/
			
		}
		printf("done", filename);
		fclose(fp);
	}
	
	dataMap.clear(); // clear all the data in map
}
Example #5
0
bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& business_id, bool use_master, const Ice::Current& current) {
  std::ostringstream otem;
  otem << "CacheManageI::loadListCache() key:" << key
       << "\tnamespace_id:" << namespace_id 
       << "\tbusiness_id:" << business_id;
  MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, otem.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
  ProducerManagerClientPtr producer = getProducer();
  if(producer == NULL) {
      return false;
  }
  KeySeq keys;
  keys.push_back(key);
  DataMap data = producer->produce(keys, business_id, use_master, 0);
  if (data.empty()) {
    return true;
  } 
  std::string list_key;
  StrList list_value;
  DataMap::const_iterator iter = data.begin();
  list_key = iter->second;
  for (; iter != data.end(); ++iter) {
    list_value.push_back(iter->first);
  }
  RedisCacheClientPtr redis_client = GetRedisCache(); 
  redis_client->Set(list_key, list_value, namespace_id, business_id);
  return true;
}
Example #6
0
    void CsvFile::write(const HeaderList& header, const  DataMap& data)  throw (FileException)
    {
        std::ofstream file(filename.c_str()); 
        if (!file)  throw FileException("Cannot open file", filename, __FUNCTION_NAME__);
	
	
        // Print raw  of headers 
        for (HeaderList::const_iterator it = header.begin(); it != header.end(); ++it)
            {
                file << separator << *it;
            }
        // End of line
        file << std::endl;	
	
        // Print all data raws
        for (DataMap::const_iterator rawit = data.begin() ; rawit != data.end(); ++rawit)
            {
	    
                file<< rawit->first;
                for (DataRaw::const_iterator it = rawit->second.begin(); it != rawit->second.end(); ++it)
                    {
                        if (*it > 0) 
                            file << separator << *it;
                        else
                            file << separator;
		  
                    }

                // End of line
                file << std::endl;
            }
	
    };
Example #7
0
void writeVtkData(const std::array<int, 3>& dims,
                  const std::array<double, 3>& cell_size,
                  const DataMap& data,
                  std::ostream& os)
{
    // Dimension is hardcoded in the prototype and the next two lines,
    // but the rest is flexible (allows dimension == 2 or 3).
    int dimension = 3;
    int num_cells = dims[0]*dims[1]*dims[2];

    assert(dimension == 2 || dimension == 3);
    assert(num_cells == dims[0]*dims[1]* (dimension == 2 ? 1 : dims[2]));

    os << "# vtk DataFile Version 2.0\n";
    os << "Structured Grid\n \n";
    os << "ASCII \n";
    os << "DATASET STRUCTURED_POINTS\n";

    os << "DIMENSIONS "
       << dims[0] + 1 << " "
       << dims[1] + 1 << " ";
    if (dimension == 3) {
        os << dims[2] + 1;
    } else {
        os << 1;
    }
    os << "\n";

    os << "ORIGIN " << 0.0 << " " << 0.0 << " " << 0.0 << "\n";

    os << "SPACING " << cell_size[0] << " " << cell_size[1];
    if (dimension == 3) {
        os << " " << cell_size[2];
    } else {
        os << " " << 0.0;
    }
    os << "\n";

    os << "\nCELL_DATA " << num_cells << '\n';
    for (DataMap::const_iterator dit = data.begin(); dit != data.end(); ++dit) {
        std::string name = dit->first;
        os << "SCALARS " << name << " float" << '\n';
        os << "LOOKUP_TABLE " << name << "_table " << '\n';
        const std::vector<double>& field = *(dit->second);
        // We always print only the first data item for every
        // cell, using 'stride'.
        // This is a hack to get water saturation nicely.
        // \TODO: Extend to properly printing vector data.
        const int stride = field.size()/num_cells;
        const int num_per_line = 5;
        for (int c = 0; c < num_cells; ++c) {
            os << field[stride*c] << ' ';
            if (c % num_per_line == num_per_line - 1
                    || c == num_cells - 1) {
                os << '\n';
            }
        }
    }
}
Example #8
0
DataMap TripodClient::getWithMissed(const KeySeq& keys, long expiredTime, bool useMaster, const long timeout) {
    KeySeq missedKeys;
    DataMap res = get(keys, missedKeys, timeout);

    if(!missedKeys.empty()) {
        DataMap missedRes = getMissed(missedKeys, expiredTime, useMaster, timeout);
        res.insert(missedRes.begin(), missedRes.end());
    }
    return res;
}
Example #9
0
void WAbstractItemModel::copyData(const WAbstractItemModel *source,
				  const WModelIndex& sIndex,
				  WAbstractItemModel *destination,
				  const WModelIndex& dIndex)
{
  DataMap values = destination->itemData(dIndex);
  for (DataMap::const_iterator i = values.begin(); i != values.end(); ++i)
    destination->setData(dIndex, boost::any(), i->first);
  
  destination->setItemData(dIndex, source->itemData(sIndex));
}
Example #10
0
map<string, MenuTripodDataPtr> MenuCacheManagerI::getWithKeys(const KeySeq& keys) {
  map<string, MenuTripodDataPtr> result;
  KeySeq missedKeys;
  DataMap dataMap = tripodClient_->get(keys, missedKeys);
  for (DataMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it) {
    string byteArray(it->second.begin(), it->second.end());
    MenuTripodDataPtr ptr = new MenuTripodData(byteArray);
    result.insert(make_pair<string, MenuTripodDataPtr>(it->first, ptr));
  }
  return result;
}
int main() {
  DataMap sightings;
  generate_n(
    inserter(sightings, sightings.begin()),
    50, SightingGen(animals));
  // Print everything:
  copy(sightings.begin(), sightings.end(),
    ostream_iterator<Sighting>(cout, ""));
  // Print sightings for selected animal:
  for(int count = 1; count < 10; count++) {
    // Use menu to get selection:
    // int i = menu();
    // Generate randomly (for automated testing):
    int i = rand() % animals.size();
    // Iterators in "range" denote begin, one 
    // past end of matching range:
    pair<DMIter, DMIter> range = 
      sightings.equal_range(animals[i]);
    copy(range.first, range.second,
      ostream_iterator<Sighting>(cout, ""));
  }
} ///:~
Example #12
0
/*
*Function:SeekMaxMinYLine
*Inputs:none
*Outputs:none
*Returns:none
*/
void Graph::SeekMaxMinYLine(DataMap &l)
{
	IT_IT("Graph::SeekMaxMinYLine");
	
	for(DataMap::iterator j = l.begin(); !(j == l.end());j++)
	{
		if(minY > (*j).second) 
		{
			minY = (*j).second;
		}
		else if(maxY < (*j).second)
		{
			maxY = (*j).second;
		};
	};
};
Example #13
0
bool CacheManagerI::loadListCache(const std::string& key, const std::string& namespace_id, const std::string& biz_id, bool use_master, const Ice::Current& current) {
  std::ostringstream os;
  os << "key :" << key;
  os << " namespaceId :" << namespace_id;
  os << " businessId :" << biz_id;
  os << " use_master :" << use_master;
  MyUtil::InvokeClient ic = MyUtil::InvokeClient::create(current, os.str(), MyUtil::InvokeClient::INVOKE_LEVEL_INFO);
  ProducerManagerClientPtr producer = getProducer();
  if(!producer) {
    MCE_ERROR("CacheManagerI::loadListCache() getProducer() return NULL!!!");
    return false;
  }

  KeySeq input_keys;
  input_keys.push_back(key);
  KeySeq locked_keys;
  KeySeq failed_locked_keys;
  bool result = false;
  while(true) {
    xce::tempmutext::Locks<std::string> locks(&tempMutexManager_, input_keys, locked_keys, failed_locked_keys);
    if(!locked_keys.empty()) {
      DataMap data;
      try {
        data = producer->produce(locked_keys, biz_id, use_master, 10000);
      } catch (Ice::Exception& e) {
        MCE_ERROR("CacheManagerI::loadListCache() rpc call produce() " << e.what());
      }
      DataMap::const_iterator iter = data.begin();
      for (; iter != data.end(); ++iter) {
        if (!iter->second.empty()) {
          ListOrHashValue list_value;
          list_value.ParseFromArray(iter->second.data(), iter->second.size());
          if (list_value.values_size() > 0) {
            StrList str_list;
            BOOST_FOREACH(const std::string& v, list_value.values()) {
              str_list.push_back(v);
            }
            RedisCacheClientPtr cache = GetRedisCache();
            if (!cache) {
              MCE_ERROR("CacheManagerI::loadListCache() GetRedisCache() return NULL !!!");
              continue;
            }
            result = cache->SetList(key, str_list, namespace_id, biz_id);
          }
        }
      }
Example #14
0
bool WAbstractItemModel::setItemData(const WModelIndex& index,
				     const DataMap& values)
{
  bool result = true;

  bool wasBlocked = dataChanged().isBlocked();
  dataChanged().setBlocked(true);

  for (DataMap::const_iterator i = values.begin(); i != values.end(); ++i)
    // if (i->first != EditRole)
      if (!setData(index, i->second, i->first))
	result = false;

  dataChanged().setBlocked(wasBlocked);
  dataChanged().emit(index, index);

  return result;
}
Example #15
0
void WeatherScreen::newData(QString loc, units_t units, DataMap data)
{
    (void) loc;
    (void) units;

    DataMap::iterator itr = data.begin();
    while (itr != data.end())
    {
        setValue(itr.key(), *itr);
        ++itr;
    }

    // This may seem like overkill, but it is necessary to actually update the
    // static and animated maps when they are redownloaded on an update
    if (!prepareScreen())
        LOG(VB_GENERAL, LOG_ERR, "Theme is missing a required widget!");

    emit screenReady(this);
}
Example #16
0
int main(int argc, char* argv[]) {
  if (argc < 3) {
    std::cout << "Usage: TestTripodSearchGet logPath userId1 [userId2, ...]" << std::endl;
    return 1;
  }
  ostringstream oss;
  com::xiaonei::xce::ConnectionPoolManager::instance();
  oss << argv[1] << "/TripodSearchGet.log";
  std::vector<std::string> keys;
  std::vector<std::string> missedKeys;
  std::string logPath = oss.str();
  MyUtil::init_logger("Mce", logPath, "DEBUG");
  for (int i = 2; i < argc; i++) {
    std::string userId = boost::lexical_cast<std::string>(argv[i]);
    MCE_WARN("logPath:" << logPath << " userId:" << userId);
    keys.push_back(userId);
  }
  TripodClient* testClient = new TripodClient("UserZooKeeper1:2181,UserZooKeeper2:2181,UserZooKeeper3:2181,UserZooKeeper4:2181,UserZooKeeper5:2181/Tripod", "ne0", "SearchCache"); 
  DataMap result;
  try {
    result = testClient->get(keys, missedKeys);
  } catch (Ice::Exception& e) {
    MCE_ERROR("get Error :" << e.what());
  }
  MCE_WARN("result.size:" << result.size());
  for (std::map<std::string, Data>::iterator it = result.begin(); it != result.end(); it++) {
    MCE_WARN("result key:" << it->first);
    TripodCacheDataPtr tmp = new TripodCacheData;
    string dataStr((it->second).begin(), (it->second).end());
    tmp->ParseFromString(dataStr);
    show(it->first, tmp);
    std::cout << "---------------------------------------" <<  std::endl;
  }
  std::cout << "result.size:" << result.size() << std::endl;
  delete testClient;
  return 0;

}
vector<MenuTripodDataPtr> MenuCacheManagerI::getWithUserId(int userId, const CacheTypeSeq& types) {
  vector<MenuTripodDataPtr> result;
  for (CacheTypeSeq::const_iterator it = types.begin(); it != types.end(); ++it) {
    int category = getObjCacheCategoryWithCacheType(*it);
    if (category == -1) {
      continue;
    }
    string cacheTypeStr = TripodHelper::getCacheTypeStr(*it);
    MenuTripodDataPtr ptr = ServiceI::instance().findObject<MenuTripodDataPtr>(category, userId);
    if (ptr != 0) {
      //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " <<  cacheTypeStr
      //    << " found in ObjectCache");
      result.push_back(ptr);
    } else {
      TripodClient* tripodClient = getTripodClientWithCacheType(*it);
      KeySeq missedKeys, keys;
      keys.push_back(boost::lexical_cast<string>(userId));
      DataMap dataMap = tripodClient->get(keys, missedKeys);
      if (!missedKeys.empty()) {
        addKeysToLoad(missedKeys, *it);
      }
      if (dataMap.empty()) {
        //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " << cacheTypeStr
        //    << ", not found in TripodCache");
        result.push_back(new MenuTripodData(userId, *it));
      } else {
        //MCE_INFO("[MenuCacheManagerI::getWithUserId] userId = " << userId << ", cacheType = " << cacheTypeStr
        //    << ", found in TripodCache");
        for (DataMap::const_iterator itx = dataMap.begin(); itx != dataMap.end(); ++itx) {
          string byteArray(itx->second.begin(), itx->second.end());
          MenuTripodDataPtr tempPtr = new MenuTripodData(byteArray);
          result.push_back(tempPtr);
        }
      }
    }
  }
  return result;
}
Example #18
0
File: t_hash.cpp Project: cvan/ardb
OP_NAMESPACE_BEGIN

    int Ardb::HashMultiSet(Context& ctx, ValueObject& meta, DataMap& fs)
    {
        if (meta.meta.encoding != COLLECTION_ECODING_ZIPMAP)
        {
            bool multi_write = fs.size() > 1;
            bool set_meta = meta.meta.len != -1;

            if (meta.meta.Length() > 0)
            {
                multi_write = true;
            }
            BatchWriteGuard guard(GetKeyValueEngine(), multi_write);
            DataMap::iterator it = fs.begin();
            while (it != fs.end())
            {
                ValueObject v(HASH_FIELD);
                v.element = it->second;
                v.key.type = HASH_FIELD;
                v.key.db = meta.key.db;
                v.key.key = meta.key.key;
                v.key.element = it->first;
                SetKeyValue(ctx, v);
                it++;
            }
            if (set_meta)
            {
                meta.meta.len = -1;
                SetKeyValue(ctx, meta);
            }
            fill_int_reply(ctx.reply, fs.size());
        }
        else
        {
            int64 oldlen = meta.meta.Length();
            DataMap::iterator it = fs.begin();
            bool zipsave = true;
            while (it != fs.end())
            {
                const Data& field = it->first;
                Data& value = it->second;
                meta.meta.zipmap[field] = value;
                it++;
                if (!meta.attach.force_zipsave
                        && (field.StringLength() > m_cfg.hash_max_ziplist_value
                                || value.StringLength() > m_cfg.hash_max_ziplist_value))
                {
                    zipsave = false;
                }
            }
            if (meta.meta.zipmap.size() > m_cfg.hash_max_ziplist_entries)
            {
                zipsave = false;
            }
            BatchWriteGuard guard(GetKeyValueEngine(), !zipsave);
            if (!zipsave)
            {
                /*
                 * convert to non zipmap encoding
                 */
                DataMap::iterator fit = meta.meta.zipmap.begin();
                while (fit != meta.meta.zipmap.end())
                {
                    ValueObject v(HASH_FIELD);
                    v.element = fit->second;
                    v.key.type = HASH_FIELD;
                    v.key.db = meta.key.db;
                    v.key.key = meta.key.key;
                    v.key.element = fit->first;
                    SetKeyValue(ctx, v);
                    fit++;
                }
                meta.meta.len = meta.meta.zipmap.size();
                meta.meta.zipmap.clear();
                meta.meta.encoding = COLLECTION_ECODING_RAW;
            }
            SetKeyValue(ctx, meta);
            fill_int_reply(ctx.reply, meta.meta.Length() - oldlen);
        }

        return 0;
    }
Example #19
0
void writeVtkData(const UnstructuredGrid& grid,
                  const DataMap& data,
                  std::ostream& os)
{
    if (grid.dimensions != 3) {
        OPM_THROW(std::runtime_error, "Vtk output for 3d grids only");
    }
    os.precision(12);
    os << "<?xml version=\"1.0\"?>\n";
    PMap pm;
    pm["type"] = "UnstructuredGrid";
    Tag vtkfiletag("VTKFile", pm, os);
    Tag ugtag("UnstructuredGrid", os);
    int num_pts = grid.number_of_nodes;
    int num_cells = grid.number_of_cells;
    pm.clear();
    pm["NumberOfPoints"] = boost::lexical_cast<std::string>(num_pts);
    pm["NumberOfCells"] = boost::lexical_cast<std::string>(num_cells);
    Tag piecetag("Piece", pm, os);
    {
        Tag pointstag("Points", os);
        pm.clear();
        pm["type"] = "Float64";
        pm["Name"] = "Coordinates";
        pm["NumberOfComponents"] = "3";
        pm["format"] = "ascii";
        Tag datag("DataArray", pm, os);
        for (int i = 0; i < num_pts; ++i) {
            Tag::indent(os);
            os << grid.node_coordinates[3*i + 0] << ' '
               << grid.node_coordinates[3*i + 1] << ' '
               << grid.node_coordinates[3*i + 2] << '\n';
        }
    }
    {
        Tag cellstag("Cells", os);
        pm.clear();
        pm["type"] = "Int32";
        pm["NumberOfComponents"] = "1";
        pm["format"] = "ascii";
        std::vector<int> cell_numpts;
        cell_numpts.reserve(num_cells);
        {
            pm["Name"] = "connectivity";
            Tag t("DataArray", pm, os);
            int hf = 0;
            for (int c = 0; c < num_cells; ++c) {
                std::set<int> cell_pts;
                for (; hf < grid.cell_facepos[c+1]; ++hf) {
                    int f = grid.cell_faces[hf];
                    const int* fnbeg = grid.face_nodes + grid.face_nodepos[f];
                    const int* fnend = grid.face_nodes + grid.face_nodepos[f+1];
                    cell_pts.insert(fnbeg, fnend);
                }
                cell_numpts.push_back(cell_pts.size());
                Tag::indent(os);
                std::copy(cell_pts.begin(), cell_pts.end(),
                          std::ostream_iterator<int>(os, " "));
                os << '\n';
            }
        }
        {
            pm["Name"] = "offsets";
            Tag t("DataArray", pm, os);
            int offset = 0;
            const int num_per_line = 10;
            for (int c = 0; c < num_cells; ++c) {
                if (c % num_per_line == 0) {
                    Tag::indent(os);
                }
                offset += cell_numpts[c];
                os << offset << ' ';
                if (c % num_per_line == num_per_line - 1
                        || c == num_cells - 1) {
                    os << '\n';
                }
            }
        }
        std::vector<int> cell_foffsets;
        cell_foffsets.reserve(num_cells);
        {
            pm["Name"] = "faces";
            Tag t("DataArray", pm, os);
            const int* fp = grid.cell_facepos;
            int offset = 0;
            for (int c = 0; c < num_cells; ++c) {
                Tag::indent(os);
                os << fp[c+1] - fp[c] << '\n';
                ++offset;
                for (int hf = fp[c]; hf < fp[c+1]; ++hf) {
                    int f = grid.cell_faces[hf];
                    const int* np = grid.face_nodepos;
                    int f_num_pts = np[f+1] - np[f];
                    Tag::indent(os);
                    os << f_num_pts << ' ';
                    ++offset;
                    std::copy(grid.face_nodes + np[f],
                              grid.face_nodes + np[f+1],
                              std::ostream_iterator<int>(os, " "));
                    os << '\n';
                    offset += f_num_pts;
                }
                cell_foffsets.push_back(offset);
            }
        }
        {
            pm["Name"] = "faceoffsets";
            Tag t("DataArray", pm, os);
            const int num_per_line = 10;
            for (int c = 0; c < num_cells; ++c) {
                if (c % num_per_line == 0) {
                    Tag::indent(os);
                }
                os << cell_foffsets[c] << ' ';
                if (c % num_per_line == num_per_line - 1
                        || c == num_cells - 1) {
                    os << '\n';
                }
            }
        }
        {
            pm["type"] = "UInt8";
            pm["Name"] = "types";
            Tag t("DataArray", pm, os);
            const int num_per_line = 10;
            for (int c = 0; c < num_cells; ++c) {
                if (c % num_per_line == 0) {
                    Tag::indent(os);
                }
                os << "42 ";
                if (c % num_per_line == num_per_line - 1
                        || c == num_cells - 1) {
                    os << '\n';
                }
            }
        }
    }
    {
        pm.clear();
        if (data.find("saturation") != data.end()) {
            pm["Scalars"] = "saturation";
        } else if (data.find("pressure") != data.end()) {
            pm["Scalars"] = "pressure";
        }
        Tag celldatatag("CellData", pm, os);
        pm.clear();
        pm["NumberOfComponents"] = "1";
        pm["format"] = "ascii";
        pm["type"] = "Float64";
        for (DataMap::const_iterator dit = data.begin(); dit != data.end(); ++dit) {
            pm["Name"] = dit->first;
            const std::vector<double>& field = *(dit->second);
            const int num_comps = field.size()/grid.number_of_cells;
            pm["NumberOfComponents"] = boost::lexical_cast<std::string>(num_comps);
            Tag ptag("DataArray", pm, os);
            const int num_per_line = num_comps == 1 ? 5 : num_comps;
            for (int item = 0; item < num_cells*num_comps; ++item) {
                if (item % num_per_line == 0) {
                    Tag::indent(os);
                }
                double value = field[item];
                if (std::fabs(value) < std::numeric_limits<double>::min()) {
                    // Avoiding denormal numbers to work around
                    // bug in Paraview.
                    value = 0.0;
                }
                os << value << ' ';
                if (item % num_per_line == num_per_line - 1
                        || item == num_cells - 1) {
                    os << '\n';
                }
            }
        }
    }
}