int main(int argc, char **argv) { if (argc != 2) { std::cout << "Usage: HitoriSolver <table.txt>\n"; return 0; } std::ifstream in(argv[1]); if (!in.good()) { std::cout << "Unable to open " << argv[1] << " for reading\n"; return 1; } try { Table t = readTable(in); std::cout << solve(t); } catch (std::exception e) { std::cout << e.what() << std::endl; return 2; } in.close(); return 0; }
QueryEngine::QueryEngine(const char * filepath){ //Create filepaths std::string basepath(filepath); std::string path_to_hashtable = basepath + "/probing_hash.dat"; std::string path_to_data_bin = basepath + "/binfile.dat"; std::string path_to_vocabid = basepath + "/vocabid.dat"; //Read config file std::string line; std::ifstream config ((basepath + "/config").c_str()); getline(config, line); int tablesize = atoi(line.c_str()); //Get tablesize. getline(config, line); largest_entry = atoi(line.c_str()); //Set largest_entry. config.close(); //Mmap binary table struct stat filestatus; stat(path_to_data_bin.c_str(), &filestatus); binary_filesize = filestatus.st_size; binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize); //Read hashtable size_t table_filesize = Table::Size(tablesize, 1.2); mem = readTable(path_to_hashtable.c_str(), table_filesize); Table table_init(mem, table_filesize); table = table_init; //Read vocabid read_map(&vocabids, path_to_vocabid.c_str()); std::cout << "Initialized successfully! " << std::endl; }
QueryEngine::QueryEngine(const char * filepath) : decoder(filepath){ //Create filepaths std::string basepath(filepath); std::string path_to_hashtable = basepath + "/probing_hash.dat"; std::string path_to_data_bin = basepath + "/binfile.dat"; std::string path_to_source_vocabid = basepath + "/source_vocabids"; ///Source phrase vocabids read_map(&source_vocabids, path_to_source_vocabid.c_str()); //Target phrase vocabIDs vocabids = decoder.get_target_lookup_map(); //Read config file std::string line; std::ifstream config ((basepath + "/config").c_str()); getline(config, line); int tablesize = atoi(line.c_str()); //Get tablesize. config.close(); //Mmap binary table struct stat filestatus; stat(path_to_data_bin.c_str(), &filestatus); binary_filesize = filestatus.st_size; binary_mmaped = read_binary_file(path_to_data_bin.c_str(), binary_filesize); //Read hashtable size_t table_filesize = Table::Size(tablesize, 1.2); mem = readTable(path_to_hashtable.c_str(), table_filesize); Table table_init(mem, table_filesize); table = table_init; std::cerr << "Initialized successfully! " << std::endl; }
void NetworkClient::init(char* address) { open(address); writeHeader(1, 0x0); writeBuffer(); readTable(); }
void TestApplication::SetUp() { table_.clear(); std::stringstream ss; ss << kTableSource; readTable(&ss); }
int SP_NKEndPointTableConfig :: init( SP_NKIniFile * iniFile ) { if( NULL != mTable ) delete mTable, mTable = NULL; mTable = readTable( iniFile ); return NULL != mTable ? 0 : -1; }
Foam::interpolationTable<Type>::interpolationTable(const dictionary& dict) : List<Tuple2<scalar, Type> >(), boundsHandling_(wordToBoundsHandling(dict.lookup("outOfBounds"))), fileName_(dict.lookup("fileName")), reader_(tableReader<Type>::New(dict)) { readTable(); }
Foam::interpolationTable<Type>::interpolationTable(const fileName& fName) : List<Tuple2<scalar, Type> >(), boundsHandling_(interpolationTable::WARN), fileName_(fName), reader_(new openFoamTableReader<Type>()) { readTable(); }
SP_NKEndPointTable * SP_NKEndPointTableConfig :: readTable( const char * configFile ) { SP_NKEndPointTable * table = NULL; SP_NKIniFile iniFile; if( 0 == iniFile.open( configFile ) ) table = readTable( &iniFile ); return table; }
void medXMLToLUTReaderPrivate::readLUT() { Q_ASSERT(xml.isStartElement() && xml.name() == "medLUTs"); while (xml.readNextStartElement()) { if (xml.name() == "table") readTable(); else xml.skipCurrentElement(); } }
void DummyBird::initParameters() { if (!nh_private_.getParam("gravity_constant", g)) g = 9.81; if (!nh_private_.getParam("heli_mass",heli_mass)) heli_mass = 615; if (!nh_private_.getParam("ROS_thrust_cmd_table",strThrustCmd)) strThrustCmd = "0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5"; if (!nh_private_.getParam("actual_thrust_table",strActThrust)) strActThrust = "57.8 95.3 138.3 192.3 265.3 350.3 430.3 540.3 665.3 790.3 932.3"; if (!nh_private_.getParam("quadrotor_type",quadrotorType)) quadrotorType = "Hummingbird"; thrustCmd = readTable(strThrustCmd); actualThrust = readTable(strActThrust); ROS_INFO("Gravity constant initialized %.3f",g); ROS_INFO("Helicopter mass initialized %.3f",heli_mass); ROS_INFO("Quadrotor Type %s",quadrotorType.c_str()); ROS_INFO("Thrust table: "); for (int i = 0; (unsigned)i<thrustCmd.size(); i++) ROS_INFO("%.3f : %.3f",thrustCmd[i],actualThrust[i]); }
int TLKFile::init(int n) { if(n == -1) n = initstages; if((n > 0) && !inited[0] && readHeader()) return errcode; if((n > 1) && !inited[1] && readTable()) return errcode; if((n > 2) && !inited[2] && readStrings()) return errcode; if((n > 3) && !inited[3]) { close(); inited.set(3); } return errcode = 0; }
int Decoder(List* head, char* filename, char* outname) { FILE* fIn = NULL; FILE* fOut = NULL; Node* node = NULL; char chname[128] = {0, }; char inname[128] = {0, }; char line_buffer[256] = {0, }; char* line_ptr = NULL; int len = 0; int i; readTable(head, filename); for(i=0; filename[i]!='.'; i++) chname[i] = filename[i]; sprintf(inname, "%s_encoded.txt", chname); if((fIn = fopen(inname, "rt")) == NULL) return -1; sprintf(outname, "%s_decoded.txt", chname); if((fOut = fopen(outname, "wt")) == NULL) return -1; while(feof(fIn) == 0) { fgets(line_buffer, 256, fIn); line_ptr = line_buffer; node = head->pHead; while(node) { len = strlen(node->Code); if(strncmp(line_ptr, node->Code, len) == 0) { fprintf(fOut, "%c", node->ascii); line_ptr += len; node = head->pHead; } else node = node->pNext; } } Destroy(head); fclose(fIn); fclose(fOut); return 1; }
/** Reads a file containing a list of Julian days and measurements * * @param[in] fileName the name of a file to be read. The file * is assumed to be formatted as a 2xN comma-delimited table, * with the first column a floating point Julian date and the second * a floating point measurement. The file may also contain comment lines * preceded by '#'. * @param[out] timeVec a vector containing the times of each * observation * @param[out] dataVec a vector containing the measurement (typically flux * or magnitude) observed at each time * * @post @p timeVec is sorted in ascending order * @post @p timeVec.size() = @p dataVec.size() * @post for all i, @p dataVec[i] is the measurement taken at @p timeVec[i] * * @exception std::bad_alloc Thrown if there is not enough memory to store * the data. * @exception kpfutils::except::FileIo Thrown if any file operation fails. * * @exceptsafe The function arguments are unchanged in the event of an exception. */ void readCsvLightCurve(const string& fileName, DoubleVec &timeVec, DoubleVec &dataVec) { // copy-and-swap vector<double> tempTimes, tempData; boost::shared_ptr<FILE> hInput = fileCheckOpen(fileName, "r"); readTable(hInput.get(), " %lf , %lf", tempTimes, tempData); sortByTime(tempTimes, tempData); // IMPORTANT: no exceptions beyond this point swap(timeVec, tempTimes); swap(dataVec, tempData ); }
/** Reads a file containing a list of obsids, Julian days, measurements, errors, and limits * * @param[in] fileName the name of a file to be read. The file * is assumed to be formatted as a 5xN space-delimited table, with * the first column a running index, the second a floating point * Julian date, the third a floating point measurement, the fourth * a floating point error, and the fifth a detection limit in the same * units as the measurement. The file may also contain comment lines * preceded by '#'. * @param[in] errMax the maximum error to tolerate in a data point. Any * points with an error exceeding @p errMax are ignored. * @param[out] timeVec a vector containing the times of each * observation * @param[out] dataVec a vector containing the measurement (typically flux * or magnitude) observed at each time * @param[out] errVec a vector containing the error on each measurement * * @post @p timeVec is sorted in ascending order * @post @p timeVec.size() = @p dataVec.size() = @p errVec.size() * @post for all i, @p dataVec[i] ± @p errVec[i] is the * measurement taken at @p timeVec[i] * @post for all i, @p errVec[i] ≤ @p errMax * * @exception std::bad_alloc Thrown if there is not enough memory to store * the data. * @exception kpfutils::except::FileIo Thrown if any file operation fails. * * @exceptsafe The function arguments are unchanged in the event of an exception. * * @bug Current implementation ignores limits. */ void readWg2LightCurve(const string& fileName, double errMax, DoubleVec &timeVec, DoubleVec &dataVec, DoubleVec &errVec) { // copy-and-swap vector<double> tempTimes, tempData, tempErrs; boost::shared_ptr<FILE> hInput = fileCheckOpen(fileName, "r"); readTable(hInput.get(), " %*i %lf %lf %lf %*lf", tempTimes, tempData, tempErrs); errorFilter(errMax, tempTimes, tempData, tempErrs); sortByTime(tempTimes, tempData, tempErrs); // IMPORTANT: no exceptions beyond this point swap(timeVec, tempTimes); swap(dataVec, tempData ); swap( errVec, tempErrs ); }
int main(void) { DIR *dir = opendir("/sys/acpi"); if(!dir) error("Unable to open /sys/acpi"); size_t i = 0; struct dirent e; while(readdirto(dir,&e)) { sRSDT table; if(strcmp(e.d_name,".") == 0 || strcmp(e.d_name,"..") == 0) continue; readTable(e.d_name,&table); printf("ACPI Table %zu:\n",i); printf("\tSignature: %.4s\n",(char*)&table.signature); printf("\tLength: %u\n",table.length); printf("\tRevision: %u\n",table.revision); printf("\tOEMID: %.6s\n",table.oemId); printf("\tOEMTableID: %.8s\n",table.oemTableId); i++; } closedir(dir); return EXIT_SUCCESS; }
void initwwwPot(struct parameters *par,struct systemPos pos){ int error,i,j,k; char filename[20]; struct bondList *blist; getBondList(&blist); strcpy(filename,"wwwPot.par"); openParameterFile(filename); error=0; error+=getParValue("includeKeatingPot",&wwwPar.includeKeatingPot,"%d"); error+=getParValue("includeRepPot",&wwwPar.includeRepPot,"%d"); error+=getParValue("includeSnnRep",&wwwPar.includeSnnRep,"%d"); error+=getParValue("includeSuboxidePot",&wwwPar.includeSuboxidePot,"%d"); error+=getParValue("includeDanglbondPot",&wwwPar.includeDanglbondPot,"%d"); error+=getParValue("includeRingPot",&wwwPar.includeRingPot,"%d"); if(wwwPar.includeKeatingPot==1){/*original keatin */ error+=getParValue("okp1_kStretch_SiSi",&wwwPar.kStretch[1][1],"%lf"); error+=getParValue("okp1_kStretch_SiO",&wwwPar.kStretch[1][0],"%lf"); error+=getParValue("okp1_kBend_SiSiSi",&wwwPar.kBend[1][1][1],"%lf"); error+=getParValue("okp1_kBend_SiOSi",&wwwPar.kBend[1][0][1],"%lf"); error+=getParValue("okp1_kBend_OSiO",&wwwPar.kBend[0][1][0],"%lf"); error+=getParValue("okp1_r0_SiSi",&wwwPar.r0[1][1],"%lf"); error+=getParValue("okp1_r0_SiO",&wwwPar.r0[1][0],"%lf"); error+=getParValue("okp1_cos0_Si",&wwwPar.cos0[1],"%lf"); error+=getParValue("okp1_cos0_O",&wwwPar.cos0[0],"%lf"); } else { /*simplified keatin */ error+=getParValue("skp2_kStretch_SiSi",&wwwPar.kStretch[1][1],"%lf"); error+=getParValue("skp2_kStretch_SiO",&wwwPar.kStretch[1][0],"%lf"); error+=getParValue("skp2_kBend_SiSiSi",&wwwPar.kBend[1][1][1],"%lf"); error+=getParValue("skp2_kBend_SiOSi",&wwwPar.kBend[1][0][1],"%lf"); error+=getParValue("skp2_kBend_OSiO",&wwwPar.kBend[0][1][0],"%lf"); error+=getParValue("skp2_r0_SiSi",&wwwPar.r0[1][1],"%lf"); error+=getParValue("skp2_r0_SiO",&wwwPar.r0[1][0],"%lf"); error+=getParValue("skp2_cos0_Si",&wwwPar.cos0[1],"%lf"); error+=getParValue("skp2_cos0_O",&wwwPar.cos0[0],"%lf"); } if(wwwPar.includeKeatingPot==3){/*stixrudes potential, no keating at all...*/ error+=getParValue("stix_D",&wwwPar.stix_D,"%lf"); error+=getParValue("stix_beta",&wwwPar.stix_beta,"%lf"); error+=getParValue("stix_r0",&wwwPar.stix_r0,"%lf"); error+=getParValue("stix_galpha",&wwwPar.stix_galpha,"%lf"); error+=getParValue("stix_alpha0",&wwwPar.stix_alpha0,"%lf"); error+=getParValue("stix_gL",&wwwPar.stix_gL,"%lf"); error+=getParValue("stix_L0",&wwwPar.stix_L0,"%lf"); error+=getParValue("stix_A",&wwwPar.stix_A,"%lf"); error+=getParValue("stix_b",&wwwPar.stix_b,"%lf"); error+=getParValue("stix_rc",&wwwPar.stix_rc,"%lf"); error+=getParValue("stix_gamma",&wwwPar.stix_gamma,"%lf"); } error+=getParValue("repulsive_r0",&wwwPar.repR0,"%lf"); error+=getParValue("repulsive_k",&wwwPar.repK,"%lf"); error+=getParValue("ringPenalty3",&wwwPar.ringPenalty3,"%lf"); error+=getParValue("ringPenalty2",&wwwPar.ringPenalty2,"%lf"); error+=getParValue("SubOxidePenalty+0",&wwwPar.subOxidePenalty[0],"%lf"); error+=getParValue("SubOxidePenalty+1",&wwwPar.subOxidePenalty[1],"%lf"); error+=getParValue("SubOxidePenalty+2",&wwwPar.subOxidePenalty[2],"%lf"); error+=getParValue("SubOxidePenalty+3",&wwwPar.subOxidePenalty[3],"%lf"); error+=getParValue("SubOxidePenalty+4",&wwwPar.subOxidePenalty[4],"%lf"); closeParameterFile(); for(i=0;i<2;i++) for(j=0;j<2;j++){ wwwPar.kStretch[i][j]*=0.5; for(k=0;k<2;k++) wwwPar.kBend[i][j][k]*=0.5; } wwwPar.repK*=0.5; wwwPar.kBend[1][1][0]=sqrt(wwwPar.kBend[1][1][1]*wwwPar.kBend[0][1][0]); wwwPar.kBend[0][1][1]=wwwPar.kBend[1][1][0]; /*make the matrices symmetric*/ wwwPar.kStretch[0][1]=wwwPar.kStretch[1][0]; wwwPar.r0[0][1]=wwwPar.r0[1][0]; for(i=0;i<2;i++) for(j=0;j<2;j++) wwwPar.r02[i][j]=POW2(wwwPar.r0[i][j]); /*change the units*/ for(i=0;i<2;i++) for(j=0;j<2;j++){ wwwPar.kStretch[i][j]*=EV; for(k=0;k<2;k++) wwwPar.kBend[i][j][k]*=EV; } for(i=0;i<5;i++) wwwPar.subOxidePenalty[i]*=EV; wwwPar.ringPenalty3*=EV; wwwPar.ringPenalty2*=EV; wwwPar.repK*=EV; wwwPar.stix_D*=EV; wwwPar.stix_A*=EV; wwwPar.stix_galpha*=EV; wwwPar.stix_gL*=EV; if(wwwPar.includeKeatingPot==3) readTable("stixrep.dat",&wwwPar.stix_repTable); wwwPar.rcut=wwwPar.repR0; wwwPar.rcut2=POW2(wwwPar.rcut); wwwPar.repR02=POW2(wwwPar.repR0); if(wwwPar.includeSnnRep){ readTable("ooPottable.dat",&wwwPar.ooPottable); readTable("ssPottable.dat",&wwwPar.ssPottable); readTable("soPottable.dat",&wwwPar.soPottable); } if(error!=0){ if(getRank()==0) printf("could not read the required parameters from file %s\n",filename); exit(0); } if(wwwPar.includeRepPot && wwwPar.includeKeatingPot==3){ printf("stix and reppot cannot be on at the same time"); exit(0); } /*init ngbrs */ initNgbrs(&nd,pos,par,wwwPar.rcut); initNgbrs(&ndLastStep,pos,par,wwwPar.rcut); updateNgbrs(&nd,pos,par); if(wwwPar.includeRepPot) nonNnNgbrs(&nd,pos.nAtoms); prevInteractionHead=malloc(sizeof(int)*pos.nAtoms); prevInteractionList=malloc(sizeof(int)*pos.nAtoms*(blist->nMax+nd.nMax)); /* if these lists are later on larger there might occur a sigsegv */ reinitWwwAfterBondChange(par, pos); reinitWwwPotAfterStep(par,pos,1); /* this updates some stuff.. (prevInteractionHead,prevInteractionList,ndLastStep) */ }
TEST_F(TestApplication, can_read_table_from_nullptr_source) { // Arrange, Act, Assert ASSERT_NO_THROW(readTable(nullptr)); }
void THDMcache::read(){ std::string tablepath="/Users/Roma1/Desktop/HEPfit/THDM/tabs/"; std::stringstream br1,br2,br3,br4,br5,br6,br7; std::stringstream pc1,pc2,pc3,pc4,pc5; std::stringstream dw1; std::stringstream cs1,cs2,cs3,cs4,cs5,cs6; std::stringstream ex1,ex2,ex3,ex4,ex5,ex6,ex7,ex8,ex9,ex10,ex11,ex12,ex13,ex14,ex15,ex16; std::cout<<"reading tables"<<std::endl; br1 << tablepath << "GridSM1.dat"; array1 = readTable(br1.str(),19861); br2 << tablepath << "GridSM2.dat"; array2 = readTable(br2.str(),19861); br3 << tablepath << "GridSM3.dat"; array3 = readTable(br3.str(),19861); br4 << tablepath << "GridSM4.dat"; array4 = readTable(br4.str(),19861); br5 << tablepath << "GridSM5.dat"; array5 = readTable(br5.str(),19861); br6 << tablepath << "GridSM6.dat"; array6 = readTable(br6.str(),19861); br7 << tablepath << "GridSM7.dat"; array7 = readTable(br7.str(),19861); pc1 << tablepath << "GridSM11.dat"; array11 = readTable(pc1.str(),1971); pc2 << tablepath << "GridSM12.dat"; array12 = readTable(pc2.str(),1971); pc3 << tablepath << "GridSM13.dat"; array13 = readTable(pc3.str(),1971); pc4 << tablepath << "GridSM14.dat"; array14 = readTable(pc4.str(),1971); pc5 << tablepath << "GridSM15.dat"; array15 = readTable(pc5.str(),1971); ex1 << tablepath << "GridSM16.dat"; array16 = readTable(ex1.str(),9851); ex2 << tablepath << "GridSM17.dat"; array17 = readTable(ex2.str(),9851); dw1 << tablepath << "GridSM18.dat"; array18 = readTable(dw1.str(),19861); cs1 << tablepath << "GridSM19.dat"; array19 = readTable(cs1.str(),186); cs2 << tablepath << "GridSM20.dat"; array20 = readTable(cs2.str(),186); cs3 << tablepath << "GridSM21.dat"; array21 = readTable(cs3.str(),186); cs4 << tablepath << "GridSM22.dat"; array22 = readTable(cs4.str(),186); cs5 << tablepath << "GridSM26.dat"; array26 = readTable(cs5.str(),992); cs6 << tablepath << "GridSM27.dat"; array27 = readTable(cs6.str(),185); ex3 << tablepath << "GridSM29.dat"; array29 = readTable(ex3.str(),986); ex4 << tablepath << "GridSM31.dat"; array31 = readTable(ex4.str(),985); ex5 << tablepath << "GridSM32.dat"; array32 = readTable(ex5.str(),496); ex6 << tablepath << "GridSM33.dat"; array33 = readTable(ex6.str(),496); ex7 << tablepath << "GridSM34.dat"; array34 = readTable(ex7.str(),991); ex8 << tablepath << "GridSM35.dat"; array35 = readTable(ex8.str(),496); ex9 << tablepath << "GridSM36.dat"; array36 = readTable(ex9.str(),496); ex10 << tablepath << "GridSM37.dat"; array37 = readTable(ex10.str(),100); ex11 << tablepath << "GridSM38.dat"; array38 = readTable(ex11.str(),100); ex12 << tablepath << "GridSM39.dat"; array39 = readTable(ex12.str(),986); ex13 << tablepath << "GridSM44.dat"; array44 = readTable(ex13.str(),986); ex14 << tablepath << "GridSM45.dat"; array45 = readTable(ex14.str(),986); ex15 << tablepath << "Grid_X_bb.dat"; arrayX_bb = readTable(ex15.str(),199); ex16 << tablepath << "Grid_X_tt.dat"; arrayX_tt = readTable(ex16.str(),198); }
// This is the first prototype version of HSpiceRead function for reading HSpice // output files. // TODO: // ascii format support // different vector types support (like voltage, current ..., although I do not // know what it would be good for) // scale monotonity check static PyObject *HSpiceRead(PyObject *self, PyObject *args) { const char *fileName; char *token, *buf = NULL, **name = NULL; int debugMode, num, numOfVectors, numOfVariables, type, sweepSize = 1, i = dateStartPosition - 1, offset = 0; struct FastArray faSweep, *faPtr = NULL; int postVersion = 0; FILE *f = NULL; PyObject *date = NULL, *title = NULL, *scale = NULL, *sweep = NULL, *sweepValues = NULL, *dataList = NULL, **tmpArray = NULL, *sweeps = NULL, *tuple = NULL, *list = NULL; // Get hspice_read() arguments. if(!PyArg_ParseTuple(args, "si", &fileName, &debugMode)) return Py_None; if(debugMode) fprintf(debugFile, "HSpiceRead: reading file %s.\n", fileName); f = fopen(fileName, "rb"); // Open the file. if(f == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: cannot open file %s.\n", fileName); goto failed; } num = getc(f); ungetc(num, f); if(num == EOF) // Test if there is data in the file. { if(debugMode) fprintf(debugFile, "HSpiceRead: file %s is empty.\n", fileName); goto failed; } if((num & 0x000000ff) >= ' ') // Test if the file is in binary format. { if(debugMode) fprintf(debugFile, "HSpiceRead: file %s is in ascii format.\n", fileName); goto failed; } // Read file header blocks. do num = readHeaderBlock(f, debugMode, fileName, &buf, &offset); while(num == 0); if(num > 0) goto failed; if(strncmp(&buf[postStartPosition1], "9007", numOfPostCharacters) == 0) postVersion = 9007; else if(strncmp(&buf[postStartPosition1], "9601", numOfPostCharacters) == 0) postVersion = 9601; else if(strncmp(&buf[postStartPosition2], "2001", numOfPostCharacters) == 0) postVersion = 2001; else { if(debugMode) fprintf(debugFile, "HSpiceRead: unknown post format.\n"); goto failed; } if(debugMode) fprintf(debugFile, "POST_VERSION=%d\n", postVersion); buf[dateEndPosition] = 0; date = PyString_FromString(&buf[dateStartPosition]); // Get creation date. if(date == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create date string.\n"); goto failed; } while(buf[i] == ' ') i--; buf[i + 1] = 0; title = PyString_FromString(&buf[titleStartPosition]); // Get title. if(title == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create title string.\n"); goto failed; } buf[numOfSweepsEndPosition] = 0; // Check number of sweep parameters. num = atoi(&buf[numOfSweepsPosition]); if(num < 0 || num > 1) { if(debugMode) fprintf(debugFile, "HSpiceRead: only onedimensional sweep supported.\n"); goto failed; } buf[numOfSweepsPosition] = 0; // Get number of vectors (variables and probes). numOfVectors = atoi(&buf[numOfProbesPosition]); buf[numOfProbesPosition] = 0; numOfVariables = atoi(&buf[numOfVariablesPosition]); // Scale included. numOfVectors = numOfVectors + numOfVariables; // Get type of variables. Scale is always real. token = strtok(&buf[vectorDescriptionStartPosition], " \t\n"); type = atoi(token); if(type == frequency) type = complex_var; else type = real_var; for(i = 0; i < numOfVectors; i++) token = strtok(NULL, " \t\n"); if(token == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to extract independent variable name.\n"); goto failed; } scale = PyString_FromString(token); // Get independent variable name. if(scale == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create independent variable name string.\n"); goto failed; } // Allocate space for pointers to vector names. name = (char **)PyMem_Malloc((numOfVectors - 1) * sizeof(char *)); if(name == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: cannot allocate pointers to vector names.\n"); goto failed; } for(i = 0; i < numOfVectors - 1; i++) // Get vector names. { name[i] = strtok(NULL, " \t\n"); if(name[i] == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to extract vector names.\n"); goto failed; } } // Process vector names: make name lowercase, remove v( in front of name for(i=0; i < numOfVectors - 1; i++) { int j; for(j=0;name[i][j];j++) { if (name[i][j]>='A' && name[i][j]<='Z') { name[i][j]-='A'-'a'; } } if (name[i][0]=='v' && name[i][1]=='(') { for(j=2;name[i][j];j++) { name[i][j-2]=name[i][j]; } name[i][j-2]=0; } } if(num == 1) // Get sweep information. { int num = getSweepInfo(debugMode, postVersion, &sweep, buf, &sweepSize, &sweepValues, &faSweep); if(num) goto failed; } dataList = PyList_New(0); // Create an empty list for data dictionaries. if(dataList == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create data list.\n"); goto failed; } // Allocate space for pointers to arrays. tmpArray = (PyObject **)PyMem_Malloc(numOfVectors * sizeof(PyObject *)); if(tmpArray == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: cannot allocate pointers to arrays.\n"); goto failed; } // Allocate space for fast array pointers. faPtr = (struct FastArray *)PyMem_Malloc(numOfVectors * sizeof(struct FastArray)); if(faPtr == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create array.\n"); goto failed; } if(debugMode) fprintf(debugFile,"numOfVectors=%d\n", numOfVectors); for(i = 0; i < sweepSize; i++) // Read i-th table. { num = readTable(f, debugMode, postVersion, fileName, sweep, numOfVariables, type, numOfVectors, &faSweep, tmpArray, faPtr, token, name, dataList); if(num) goto failed; } fclose(f); f = NULL; PyMem_Free(faPtr); faPtr = NULL; PyMem_Free(buf); buf = NULL; PyMem_Free(name); name = NULL; PyMem_Free(tmpArray); tmpArray = NULL; // Create sweeps tuple. if(sweep == NULL) sweeps = PyTuple_Pack(3, Py_None, Py_None, dataList); else sweeps = PyTuple_Pack(3, sweep, sweepValues, dataList); if(sweeps == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create tuple with sweeps.\n"); goto failed; } Py_XDECREF(sweep); Py_XDECREF(sweepValues); Py_XDECREF(dataList); // Prepare return tuple. tuple = PyTuple_Pack(6, sweeps, scale, Py_None, title, date, Py_None); if(tuple == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create tuple with read data.\n"); goto failed; } Py_XDECREF(date); date = NULL; Py_XDECREF(title); title = NULL; Py_XDECREF(scale); scale = NULL; Py_XDECREF(sweeps); sweeps = NULL; list = PyList_New(0); // Create an empty list. if(list == NULL) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to create return list.\n"); goto failed; } num = PyList_Append(list, tuple); // Insert tuple into return list. if(num) { if(debugMode) fprintf(debugFile, "HSpiceRead: failed to append tuple to return list.\n"); goto failed; } Py_XDECREF(tuple); return list; failed: // Error occured. Close open file, relese memory and python references. if (f) fclose(f); PyMem_Free(buf); Py_XDECREF(date); Py_XDECREF(title); Py_XDECREF(scale); PyMem_Free(name); Py_XDECREF(sweep); Py_XDECREF(sweepValues); Py_XDECREF(dataList); PyMem_Free(tmpArray); PyMem_Free(faPtr); Py_XDECREF(sweeps); Py_XDECREF(tuple); Py_XDECREF(list); return Py_None; }
int videoGetRects(lua_State *L, int index, Array *rects) { return readTable(L, index, rects, sizeof (SDL_Rect), readRects); }
bool Archive::open( const char * archivePath, Access access ) { lock(); // close this archive if previously open close(); // set the access m_Access = access; // attempt to open the file if (! m_pFile->open( archivePath, access == READ ? FileDisk::READ : FileDisk::READ_WRITE ) || !readTable() ) { unlock(); return false; // failed } m_Open = true; unlock(); // success return true; }
int videoGetPoints(lua_State *L, int index, Array *points) { return readTable(L, index, points, sizeof (SDL_Point), readPoints); }
Decoder::Decoder(const char filename[], double prune_threshold, unsigned int prune_count): flex(new Lexicon(french)), elex(new Lexicon(english)), schwarz(new PTree<PTree<Cost>>){ readTable(filename, prune_threshold, prune_count); }