/** * Saves new battle data to a YAML file. * @param filename YAML filename. */ void NewBattleState::save(const std::string &filename) { std::string s = Options::getMasterUserFolder() + filename + ".cfg"; std::ofstream sav(s.c_str()); if (!sav) { Log(LOG_WARNING) << "Failed to save " << filename << ".cfg"; return; } YAML::Emitter out; YAML::Node node; node["mission"] = _cbxMission->getSelected(); node["craft"] = _cbxCraft->getSelected(); node["darkness"] = _slrDarkness->getValue(); node["terrain"] = _cbxTerrain->getSelected(); node["alienRace"] = _cbxAlienRace->getSelected(); node["difficulty"] = _cbxDifficulty->getSelected(); node["alienTech"] = _slrAlienTech->getValue(); node["base"] = _game->getSavedGame()->getBases()->front()->save(); out << node; sav << out.c_str(); sav.close(); if (!sav) { Log(LOG_WARNING) << "Failed to save " << filename << ".cfg"; } }
void Map::loadMap(char fileName[64]) { std::string line = ""; char file_name[256]; sprintf_s(file_name, "Levels/Level1.txt"); std::ifstream sav (file_name); int i = 0; int k = 0; std::string temp; if (sav.is_open()) { while (sav.good()) { getline (sav, line); if (k >= 64) break; while (!line.empty()) { if (i >= 64) break; temp = line.substr(0, 1); if (temp == "0") { map[i][k] = 0; } else if (temp == "1") { map[i][k] = 1; } i++; line.erase(0, 1); } k++; i = 0; } sav.close(); } }
/// saving data base void save_operator() { ofstream sav("admin.dat"); sav<<admin.get_user()<<"\t"; sav<<admin.get_pass()<<"\n"; sav<<foperator.get_user()<<"\t"; sav<<foperator.get_pass()<<"\n"; sav.close();///admin save finished }
int main(const int argc, const char** argv) { if (argc != 2) LFATAL("USAGE: %s <image.pgm>", argv[0]); // let's start by trying out a single model: it starts with our // initial conditions and we give it a steady input of 255: SurpriseModelSP m(UPDFAC, INIVAL, VARIANCE); // the model SurpriseModelSP s(UPDFAC, 255.0f, VARIANCE); // the sample for (int i = 0; i < NITER; i ++) LINFO("iter = %d, mean = %f, stdev = %f, surprise = %f", i, m.getMean(), sqrt(m.getVar()), m.surprise(s)); // get the input feature map: Image<byte> input = Raster::ReadGray(argv[1]); // convert to double: Image<double> in(input); // create sample variances: Image<double> invar(input.getDims(), NO_INIT); invar.clear(VARIANCE); // create SurpriseImage from our samples and their variances: SurpriseImage<SurpriseModelSP> sample(UPDFAC, in, invar); // create an ImageCache to accumulate our results: ImageCacheMinMax<float> cache; // create a surprise map: SurpriseMap<SurpriseModelSP> smap; smap.init(QLEN, UPDFAC, NUPDFAC, INIVAL, VARIANCE, NEIGHSIGMA, LOCSIGMA); // let's do it! for (int i = 0; i < NITER; i ++) { // get the surprise: Image<float> surp = smap.surprise(sample); float mi, ma; getMinMax(surp, mi, ma); LINFO("Done %d/%d: [%f .. %f]", i+1, NITER, mi, ma); // cache it: cache.push_back(surp); } // ok, let's save the results. First find the global max: Image<float> imax = cache.getMax(); float mi, ma; getMinMax(imax, mi, ma); LINFO("Global max is %f", ma); for (int i = 0; i < NITER; i ++) { Image<byte> sav(cache.pop_front() * 255.0f / ma); Raster::WriteGray(sav, sformat("SURP%03d%s", i, argv[1])); } return 0; }
///--------SAVE TIME!!!!------------ void save_setting() { ofstream sav("setting.dat"); colour[5] = ':'; sav<<colour<<"\n"; sav<<screensav<<"\n"; sav<<log_out_time<<"\n"; sav<<screen_saver_wait_time<<"\n"; sav.close(); }
void Area::load() { Aurora::GFF3File are(_resRef, Aurora::kFileTypeARE, MKTAG('A', 'R', 'E', ' ')); loadARE(are.getTopLevel()); loadResources(); Aurora::GFF3File sav(_resRef, Aurora::kFileTypeSAV, MKTAG('S', 'A', 'V', ' ')); loadSAV(sav.getTopLevel()); loadLYT(); // Room layout loadVIS(); // Room visibilities loadRooms(); }
SAbundVector ListVector::getSAbundVector() { try { SAbundVector sav(maxRank+1); for(int i=0; i<data.size(); i++) { int binSize = m->getNumNames(data[i]); sav.set(binSize, sav.get(binSize) + 1); } sav.set(0, 0); sav.setLabel(label); return sav; } catch(exception& e) { m->errorOut(e, "ListVector", "getSAbundVector"); exit(1); } }
//Constructor //This constructor is used to perform Dynaligh refolding. Dynalign_object::Dynalign_object(const char* filename, const short maxtrace, const short bpwin, const short awin, const short percent): TwoRNA() { int i; CommonConstructor(); //Make sure the filename exists: if ((fopen(filename, "r"))== NULL) { //the file is not found ErrorCodeTwo=106; return; } //open the save file to peek at the sizes needed to allocate arrays: std::ifstream sav(filename,std::ios::binary); read(&sav, &modificationflag); //start with structure information read(&sav,&GetRNA1()->GetStructure()->numofbases); read(&sav,&GetRNA2()->GetStructure()->numofbases); sav.close(); //allocate space for the alignment align = new short *[maxtrace];//maximum number of tracebacks and next line and below at delete for (i=0;i<maxtrace;i++) align[i] = new short [GetRNA1()->GetStructure()->numofbases+1]; refolddynalign(filename,GetRNA1()->GetStructure(),GetRNA2()->GetStructure(),align,maxtrace,bpwin,awin,percent); //No errors encountered. ErrorCodeTwo=0; return; }
/** * Saves a saved game's contents to a YAML file. * @param filename YAML filename. */ void SavedGame::save(const std::string &filename) const { std::string s = Options::getUserFolder() + filename + ".sav"; std::ofstream sav(s.c_str()); if (!sav) { throw Exception("Failed to save savegame"); } YAML::Emitter out; // Saves the brief game info used in the saves list out << YAML::BeginDoc; out << YAML::BeginMap; out << YAML::Key << "version" << YAML::Value << Options::getVersion(); out << YAML::Key << "time" << YAML::Value; _time->save(out); out << YAML::EndMap; // Saves the full game data to the save out << YAML::BeginDoc; out << YAML::BeginMap; out << YAML::Key << "difficulty" << YAML::Value << _difficulty; out << YAML::Key << "funds" << YAML::Value << _funds; out << YAML::Key << "countries" << YAML::Value; out << YAML::BeginSeq; for (std::vector<Country*>::const_iterator i = _countries.begin(); i != _countries.end(); ++i) { (*i)->save(out); } out << YAML::EndSeq; out << YAML::Key << "regions" << YAML::Value; out << YAML::BeginSeq; for (std::vector<Region*>::const_iterator i = _regions.begin(); i != _regions.end(); ++i) { (*i)->save(out); } out << YAML::EndSeq; out << YAML::Key << "bases" << YAML::Value; out << YAML::BeginSeq; for (std::vector<Base*>::const_iterator i = _bases.begin(); i != _bases.end(); ++i) { (*i)->save(out); } out << YAML::EndSeq; out << YAML::Key << "ufos" << YAML::Value; out << YAML::BeginSeq; for (std::vector<Ufo*>::const_iterator i = _ufos.begin(); i != _ufos.end(); ++i) { (*i)->save(out); } out << YAML::EndSeq; out << YAML::Key << "craftId" << YAML::Value << _craftId; out << YAML::Key << "waypoints" << YAML::Value; out << YAML::BeginSeq; for (std::vector<Waypoint*>::const_iterator i = _waypoints.begin(); i != _waypoints.end(); ++i) { (*i)->save(out); } out << YAML::EndSeq; out << YAML::Key << "discovered" << YAML::Value; out << YAML::BeginSeq; for (std::vector<const RuleResearchProject *>::const_iterator i = _discovered.begin(); i != _discovered.end(); ++i) { out << (*i)->getName (); } out << YAML::EndSeq; out << YAML::Key << "ufoId" << YAML::Value << _ufoId; out << YAML::Key << "waypointId" << YAML::Value << _waypointId; out << YAML::Key << "soldierId" << YAML::Value << _soldierId; if (_battleGame != 0) { out << YAML::Key << "battleGame" << YAML::Value; _battleGame->save(out); } out << YAML::EndMap; sav << out.c_str(); sav.close(); }
//Constructor for reading a dynalign save file. Dynalign_object::Dynalign_object(const char filename[]): TwoRNA() { //Open the save file, make the output file int ir,ip,jp,kp,cp; short i,j,k,l; integersize en1; short maxsep; integersize crit; dynalignheap heap; //Do some initializations CommonConstructor(); //Make sure the filename exists: if ((fopen(filename, "r"))== NULL) { //the file is not found ErrorCodeTwo=106; return; } data = new datatable; bool singleinsert,local; bool **allowed_alignments; //indicate that a save file was read so that the destructor can do the cleanup savefileread=true; //open the save file to peek at the sizes needed to allocate arrays: std::ifstream sav(filename,std::ios::binary); read(&sav, &modificationflag); //start with structure information read(&sav,&(GetRNA1()->GetStructure()->numofbases)); read(&sav,&(GetRNA2()->GetStructure()->numofbases)); read(&sav,&maxsep); sav.close(); if (maxsep<0) { //This means that the allowed alignments were constrained by the HMM alignment //probs and not by the traditional M parameter. //Therefore, space must be allocated for the allowed_alignment arrays. allowed_alignments=new bool *[GetRNA1()->GetStructure()->numofbases+1]; for (i=0;i<=GetRNA1()->GetStructure()->numofbases;i++) allowed_alignments[i]=new bool [GetRNA2()->GetStructure()->numofbases+1]; } else allowed_alignments=NULL; //fill the low and highend arrays: //allocate space: lowend = new short [2*GetRNA1()->GetStructure()->numofbases]; highend = new short [2*GetRNA1()->GetStructure()->numofbases]; if (modificationflag==1) { vmod = new dynalignarray(); } else vmod=NULL; v = new varray(); w = new dynalignarray(); w3 = new wendarray(); w5 = new wendarray(); opendynalignsavefile(filename, GetRNA1()->GetStructure(), GetRNA2()->GetStructure(), v, w, vmod, w3, w5, data, &singleinsert, &maxsep, &gap, &lowest, &local, allowed_alignments,lowend,highend); if (maxsep<0) { for (i=0;i<=GetRNA1()->GetStructure()->numofbases;i++) delete[] allowed_alignments[i]; delete[] allowed_alignments; } //delete[] pair[0]; //delete[] pair[1]; //delete[] pair; //No errors encounted ErrorCodeTwo=0; return; }