void FieldManager::start(std::string fileName, int numberOfThreads) { currentIteration = 0; stopped = false; numberOfiterations = LONG_MAX; this->numberOfThreads = numberOfThreads; parseCSV(fileName); }
std::vector<std::vector<std::string>> CSVParser::tableRows(bool reparse) { if (_cachedResult.size() == 0 || reparse) parseCSV(); std::vector<std::vector<std::string>> returnVec; for (unsigned int i = 1; i < _cachedResult.size(); i++) returnVec.push_back(_cachedResult[i]); return returnVec; }
void TestParse::testParse() { QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0); fprintf(stderr, "number of dives %d \n", dive_table.nr); QCOMPARE(parseDivingLog(), 0); fprintf(stderr, "number of dives %d \n", dive_table.nr); QCOMPARE(parseV2NoQuestion(), 0); fprintf(stderr, "number of dives %d \n", dive_table.nr); QCOMPARE(parseV3(), 0); fprintf(stderr, "number of dives %d \n", dive_table.nr); QCOMPARE(save_dives("./testout.ssrf"), 0); FILE_COMPARE("./testout.ssrf", SUBSURFACE_TEST_DATA "/dives/test40-42.xml"); }
std::vector<std::string> CSVParser::tableHeader(bool reparse) { if (_cachedResult.size() == 0 || reparse) parseCSV(); return _cachedResult[0]; }
void FieldManager::start(std::string fileName, int numberOfThreads) { this->numberOfThreads = numberOfThreads; stopped = true; parseCSV(fileName); sendInitialParts(); }
int main() { FILE *fp = fopen("BigShips_1280x720_60Hz_i420_part1_result.csv","w"); double sheet1[600][3]; //用于存储600条QP、Bits、Y PSNR数据 double sheet2[600][3]; double sheet3[600][3]; double sheet4[600][3]; double QP[8]; double R[8]; double D[8]; double lambda[8]; double alpha[4]; double beta[4]; double c[4]; double k[4]; double Rbudget = 2000.0; //2000kb/s double u; //u=1/μ double low = -10000.0; //二分法求公式(10)的解,区间下限 double high = 20000.0; //二分法求公式(10)的解,区间上限 int framerate = 60; int imageWidth = 1280; int imageHeight = 720; parseCSV("BigShips_1280x720_60Hz_i420_part1.csv", sheet1, framerate, imageWidth, imageHeight); //解析CSV文件,将600行R、D、QP存入sheet数组 parseCSV("BigShips_1280x720_60Hz_i420_part2.csv", sheet2, framerate, imageWidth, imageHeight); parseCSV("City_corr_1280x720_60Hz_i420_part1.csv", sheet3, framerate, imageWidth, imageHeight); parseCSV("City_corr_1280x720_60Hz_i420_part2.csv", sheet4, framerate, imageWidth, imageHeight); for (int i = 0; i < 600; i ++) { for (int j = 0; j < 2; j++) { QP[j] = sheet1[i + j][0]; R[j] = sheet1[i + j][1]; D[j] = sheet1[i + j][2]; QP[j+2] = sheet2[i + j][0]; R[j+2] = sheet2[i + j][1]; D[j+2] = sheet2[i + j][2]; QP[j+4] = sheet3[i + j][0]; R[j+4] = sheet3[i + j][1]; D[j+4] = sheet3[i + j][2]; QP[j+6] = sheet4[i + j][0]; R[j+6] = sheet4[i + j][1]; D[j+6] = sheet4[i + j][2]; } for (int j = 0; j < 4; j++) { lambda[j * 2] = exp((QP[j * 2] - 13.7122) / 4.2005); //用两个QP(对应两个Lamda), 编码出两个R,对应两个D(R) lambda[j * 2 + 1] = exp((QP[j * 2 + 1] - 13.7122) / 4.2005); beta[j] = log(R[j * 2] / R[j * 2 + 1]) / log(lambda[j * 2] / lambda[j * 2 + 1]); //把 α 和 β 求解出来 alpha[j] = R[j * 2] / pow(lambda[j * 2], beta[j]); k[j] = -log(D[j * 2] / D[j * 2 + 1]) / log(R[j * 2] / R[j * 2 + 1]); //把c k 求解出来 c[j] = D[j * 2] / pow(R[j * 2], -k[j]); } u = bisection(Rbudget, high, low, c, k); //二分法求公式10的解 fprintf(fp, "R,lambda,QP\n"); //即将保存的数据的表头:R lambda QP for (int j = 0; j < 4; j++) { R[j] = pow(k[j] * c[j] * u, 1 / (k[j] + 1)); //利用Mu把各对c_i k_i 的 R_i算出来 lambda[j] = pow(R[j] / alpha[j], 1 / beta[j]); //利用R_i, 重新求解出λ_i QP[j] = 4.2005*log(lambda[j]) + 13.7122; //利用λ_i重新求解出QP_i fprintf(fp, "%lf,%lf,%lf\n", R[j], lambda[j], QP[j]); //保存数据 } } return 0; }
void GenVector_ReadCSV(denseType * vector, long length, long num_cols, char* rhsFile, int myid, int numprocs) { long idx; long local_length, local_length_normal; int ierr; double * Total_data_buffer; int sendCount[numprocs]; int sendDispls[numprocs]; long procCounter; double normel_ele_num; ierr = MPI_Bcast((void*) &length, 1, MPI_LONG, 0, MPI_COMM_WORLD); #ifdef GETRHS_DEBUG printf("in GetRHS.c, myid=%d, length=%d\n", myid, length); #endif local_length_normal = length / numprocs; if (myid == numprocs - 1) local_length = length - (numprocs - 1) * local_length_normal; else local_length = local_length_normal; normel_ele_num = local_length_normal * num_cols; for (procCounter = 0; procCounter < numprocs; procCounter++) { sendCount[procCounter] = (int)normel_ele_num; sendDispls[procCounter] = (int)procCounter * normel_ele_num; } sendCount[numprocs - 1] = (int)((length - (numprocs - 1) * local_length_normal) * num_cols); #ifdef GETRHS_DEBUG printf("in GetRHS.c, myid = %d, local_length=%d\n", myid, local_length); #endif vector->local_num_row = local_length; vector->local_num_col = num_cols; // only consider vector->global_num_row = length; vector->global_num_col = num_cols; #ifdef GETRHS_DEBUG #endif vector->data = (double *) calloc(vector->local_num_row * vector->local_num_col, sizeof (double)); long local_num_element = vector->local_num_row * vector->local_num_col; // rank 0 read CSV if (myid == 0) { printf("Reading MRHS data from %s ... ...\n", rhsFile); parseCSV(rhsFile, &Total_data_buffer, length, num_cols); printf("Reading MRHS data from %s done.\n", rhsFile); #ifdef GenVector_ReadCSV_DB //check_csv_array_print(Total_data_buffer, length, num_cols, myid); // exit(0); #endif } // // Scatter data // int MPI_Scatterv(const void *sendbuf, const int *sendcounts, const int *displs, // MPI_Datatype sendtype, void *recvbuf, int recvcount, // MPI_Datatype recvtype, // int root, MPI_Comm comm) ierr = MPI_Scatterv((void*) Total_data_buffer, (int*)sendCount, (int*)sendDispls, MPI_DOUBLE, vector->data, (int)local_num_element, MPI_DOUBLE, 0, MPI_COMM_WORLD); // // // based on the assumption of equal division of rows among processes vector->start_idx = myid * vector->global_num_col * local_length_normal; #ifdef GenVector_ReadCSV_DB // if (myid == 0){ // check_csv_array_print(vector->data, vector->local_num_row, vector->global_num_col, myid); // printf ("local rows:%d, local cols %d, local nnz:%d\n", vector->local_num_row, vector->local_num_col,local_num_element); // } if (myid == numprocs-1) { local_dense_mat_print(*vector, myid); } exit(0); #endif if (myid == 0) { free(Total_data_buffer); } }
PatientT * fetchPatient(char * uuid) { fprintf(stderr,"Fetching Patient INFO\n"); if(patientCache == NULL) { patientCache = malloc(sizeof(PatientCacheT)); if(patientCache == NULL) { //malloc error } else { patientCache->item = NULL; patientCache->next = NULL; } } //First we need to search the cache for a proper user PatientCacheT * currentRecord = patientCache; while(true) { if(currentRecord->item == NULL) { //There is no record, ayyyyy break; } //Match found if(strncmp(currentRecord->item->uuid, uuid, 33)) { return currentRecord->item; } else { currentRecord = currentRecord->next; } } //No record :c fprintf(stderr,"NO RECORD SEARCHING FILE\n"); char fileName[45]; initializeString(fileName, 45); strncat(fileName, "records/", 8); strncat(fileName, uuid, 32); FILE * userRecords = fopen(fileName, "r"); char line[500]; initializeString(line, 500); //First thing we wanna read in is the basic information about the user fprintf(stderr,"Reading Basic info\n"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } PatientT * patient = malloc(sizeof(PatientT)); if(patient == NULL) { //Error during malloc } initializePatient(patient); if(feof(userRecords) && (line[0] == '\0' || line[0] == ' ' || line[1] == '\0')) { fclose(userRecords); return patient; } char csvData[10][50]; parseCSV(line, csvData); strncpy(patient->uuid, uuid, 33); strncpy(patient->firstName, csvData[0], 29); strncpy(patient->lastName, csvData[1], 29); patient->smokes = (strncmp(csvData[2], "1", 1) == 0) ? true : false; strncpy(patient->race, csvData[3], 29); strncpy(patient->gender, csvData[4], 29); int age = (int) strtol(csvData[5], NULL, 10); if(age == 0) { //Errored out during conversion printf("System errored during age import. Setting age to -1\n"); age = -1; } patient->age = age; strncpy(patient->ssn, csvData[6], 10); strncpy(patient->dateOfBirth, csvData[7], 10); fprintf(stderr,"Read basic info\n"); fprintf(stderr,"Reading insuracne info"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); InsuranceT * insurance = malloc(sizeof(InsuranceT)); if(insurance == NULL) { //Malloc error } strncpy(insurance->name, csvData[0], 40); strncpy(insurance->policyNumber, csvData[1], 30); patient->insurance = insurance; //-------------------------------------------------------------------------------- //Immunization data fprintf(stderr,"Read Immunization"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); int numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System errored during Immunization import. Ignoring."); numberOfRecords = 0; } int i = 0; ImmunizationListT * lastRecordImmu = malloc(sizeof(ImmunizationListT)); if(lastRecordImmu == NULL) { //Malloc error } ImmunizationListT * firstRecordImmu = lastRecordImmu; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); ImmunizationT * record = malloc(sizeof(ImmunizationT)); if(record == NULL) { //Malloc error } initializeString(record->name, 40); initializeString(record->datePerformed, 20); initializeString(record->performingPerson, 33); strncpy(record->name, csvData[0], 40); strncpy(record->datePerformed, csvData[1], 20); strncpy(record->performingPerson, csvData[2], 33); lastRecordImmu->item = record; if(i + 1 >= numberOfRecords) { lastRecordImmu->next = NULL; break; } lastRecordImmu->next = malloc(sizeof(ImmunizationListT)); if(lastRecordImmu->next == NULL) { //Malloc error } lastRecordImmu = lastRecordImmu->next; lastRecordImmu->next = NULL; } patient->immunizations = firstRecordImmu; //-------------------------------------------------------------------------------- //Medication data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System errored during Medication import. Ignoring."); numberOfRecords = 0; } MedicationListT * lastRecordMedi = malloc(sizeof(MedicationListT)); if(lastRecordMedi == NULL) { //Malloc error } MedicationListT * firstRecordMedi = lastRecordMedi; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); MedicationT * record = malloc(sizeof(MedicationT)); if(record == NULL) { //Malloc error } initializeString(record->prescribingPerson, 33); strncpy(record->name, csvData[0], 40); const int dosage = (int) strtol(csvData[1], NULL, 10); if(dosage == 0) { printf("System error during Medication import."); record->dosage = -1; } else { record->dosage = dosage; } strncpy(record->prescribingPerson, csvData[2], 33); lastRecordMedi->item = record; if(i + 1 >= numberOfRecords) { lastRecordMedi->next = NULL; break; } lastRecordMedi->next = malloc(sizeof(MedicationListT)); if(lastRecordMedi->next == NULL) { //Malloc error } lastRecordMedi = lastRecordMedi->next; lastRecordMedi->next = NULL; } patient->medications = firstRecordMedi; //--------------------------------------------------------------------------------- //Visits data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System error during Visits import. Ignoring."); numberOfRecords = 0; } VisitListT * lastVisitRecord = malloc(sizeof(VisitListT)); if(lastVisitRecord == NULL) { //Malloc error } VisitListT * firstVisitRecord = lastVisitRecord; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); VisitT * record = malloc(sizeof(VisitT)); if(record == NULL) { //Malloc error } initializeString(record->visitDateTime, 19); initializeString(record->personSeen, 33); const int heartRate = (int) strtol(csvData[0], NULL, 10); if(heartRate == 0) { printf("System error during Visit import"); record->heartRate = -1; } else { record->heartRate = heartRate; } const int bloodPressure = (int) strtol(csvData[1], NULL, 10); if(bloodPressure == 0) { printf("System error during Visit import"); record->bloodPressure = -1; } else { record->bloodPressure = bloodPressure; } strncpy(record->visitDateTime, csvData[2], 19); strncpy(record->personSeen, csvData[3], 33); lastVisitRecord->item = record; if(i + 1 >= numberOfRecords) { lastVisitRecord->next = NULL; break; } lastVisitRecord->next = malloc(sizeof(VisitT)); if(lastVisitRecord->next == NULL) { //Malloc error } lastVisitRecord = lastVisitRecord->next; lastVisitRecord->next = NULL; } patient->visits = firstVisitRecord; //--------------------------------------------------------------------------------- //Test Result data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System error during Test Results import. Ignoring."); numberOfRecords = 0; } TestResultListT * lastTestRecord = malloc(sizeof(TestResultListT)); if(lastTestRecord == NULL) { //Malloc error; } TestResultListT * firstTestRecord = lastTestRecord; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); TestResultT * record = malloc(sizeof(TestResultT)); if(record == NULL) { //Malloc error } initializeString(record->testName, 30); initializeString(record->testResults, 120); strncpy(record->testName, csvData[0], 30); strncpy(record->testResults, csvData[1], 120); lastTestRecord->item = record; if(i + 1 >= numberOfRecords) { lastTestRecord->next = NULL; break; } lastTestRecord->next = malloc(sizeof(TestResultT)); if(lastTestRecord->next == NULL) { //Malloc error; } lastTestRecord = lastTestRecord->next; lastTestRecord->next = NULL; } patient->testResults = firstTestRecord; //I think we're done here. patientCache->item = patient; patientCache->next = malloc(sizeof(PatientCacheT)); if(patientCache->next == NULL) { //Error; } fclose(userRecords); return patient; }
int main(int argc, char** argv) { // TODO: Dodelat nacitani parametru z prikazovy radky parseCSV(); evolution(); return (EXIT_SUCCESS); }