int main(int argc, char *argv[]) { if (argc < 2) { printf("usage: rta [IVXLCDM]\r\n"); return 0; } int psum = 0, tsum = 0; //partial sum and total sum int i,n = strlen(argv[1]); char lastletter = 0; for (i=0;i<n;i++) { int letter_value = rta(argv[1][i]); if (lastletter != argv[1][i]) { if (rta(lastletter) > letter_value) { tsum += psum; } else { tsum -= psum; } psum = 0; } psum += letter_value; lastletter = argv[1][i]; } tsum += psum; printf("Roman: %s\r\nArabic: %d\r\n",argv[1],tsum); return 0; }
void DRP2FD(SCAN *s, XSCAN *x, FDATA *fd) { int i, odin=0; double *pa, cp, sp, sqrBt; #ifdef SISYFOS int arr_no=0; double NorthAz, RAOffset, DecOffset; #endif #ifdef ONTHEFLY double NorthAz, RAOffset, DecOffset; #endif double *CheckPosAngle(); void SetCoordType(); int CheckCRVALType(); void GetEquOffsets(DATE *, double, double, double, double, double, double, double *, double *); if (strncmp(s->Project, "Odin", 4)==0) odin=1; strncpy(fd->sname, s->Name, 12); fd->sname[12] = '\0'; strip_trailing_spaces(fd->sname); strncpy(fd->molecule, s->Molecule, 18); fd->molecule[18] = '\0'; strip_trailing_spaces(fd->molecule); fd->n = (int)x->NChannel; fd->sno = (int)s->ScanNo; fd->subno = (int)s->SubScan; fd->coordType = s->CSystem; SetCoordType(s->CSystem); if ((pa = CheckPosAngle())) fd->posang = (*pa)*PI/180.0; else fd->posang = (double)s->PosAngle; cp = cos(fd->posang); sp = sin(fd->posang); fd->xoff = rta(s->LMapOff)*cp - rta(s->BMapOff)*sp; fd->yoff = rta(s->BMapOff)*cp + rta(s->LMapOff)*sp; fd->equinox = s->Equinox; if (fd->equinox <= 1950.1) { fd->epoch = 'B'; } else { fd->epoch = 'J'; } fd->y0 = s->Latitude; fd->x0 = s->Longitude; if (CheckCRVALType()) { fd->y0 -= s->BMapOff; fd->x0 -= s->LMapOff/cos(fd->y0); } fd->scanType = s->ObsMode; fd->tsys = (double)s->Tsys; fd->tau = (double)s->Tau; fd->int_time = (double)s->IntTime; fd->vlsr = s->VSource; fd->date.Year = s->Year; fd->date.Month = s->Month; fd->date.Day = s->Day; fd->date.Hour = s->UTHour; fd->date.Min = s->UTMin; fd->date.Sec = s->UTSec; fd->LST = fd->date; fd->LST.Hour = s->STHour; fd->LST.Min = s->STMin; fd->LST.Sec = s->STSec; fd->az = s->Azimuth * RADTODEG; fd->el = s->Elevation * RADTODEG; fd->aoff = rta(s->AzMapOff)*cp - rta(s->ElMapOff)*sp; fd->eoff = rta(s->ElMapOff)*cp + rta(s->AzMapOff)*sp; #ifdef SISYFOS if (sscanf(s->Program, "COR%d", &arr_no) == 1) { if (arr_no >=1 && arr_no <= 4) { fd->aoff += (SisyfosAz[arr_no] - SisyfosAz[0]); fd->eoff += (SisyfosEl[arr_no] - SisyfosEl[0]); NorthAz = s->Azimuth + PI; GetEquOffsets(&(fd->LST), NorthAz, s->Elevation, fd->aoff, fd->eoff, s->Longitude, s->Latitude, &RAOffset, &DecOffset); fd->xoff += RAOffset; fd->yoff += DecOffset; } } #endif #ifdef ONTHEFLY NorthAz = s->Azimuth + PI; GetEquOffsets(&(fd->LST), NorthAz, s->Elevation, fd->aoff, fd->eoff, s->Longitude, s->Latitude, &RAOffset, &DecOffset); fd->xoff += RAOffset; fd->yoff += DecOffset; #endif fd->b.maj = s->StepX; fd->b.min = s->StepY; fd->b.PA = s->ParAngle; fd->beameff = s->RefCorr; fd->pol = s->flag[0]; fd->TAir = s->AirTemp; fd->PAir = s->Pressure; fd->RAir = s->Humidity; fd->firstIF = s->FirstIF/1000.0; if (x) { fd->lofreq = x->LOFreq/1000.0; } else { /* Assume OSO */ if (s->RestFreq < 105000.0) { fd->lofreq = (s->RestFreq + s->FirstIF)/1000.0; } else { fd->lofreq = (s->RestFreq - s->FirstIF)/1000.0; } } fd->skyfreq = s->SkyFreq/1000.0; if (s->FreqRes < 0.0) { fd->f0 = Frequency(x->NChannel-1, s, x)/1000.; fd->fn = Frequency(0, s, x)/1000.; /* printf("f0, fn=%f,%f RF=%f res=%f\n", fd->f0, fd->fn, s->RestFreq, s->FreqRes); */ if (odin) { fd->v0 = VelOdin(x->NChannel-1, s, x); } else { fd->v0 = Velocity(x->NChannel-1, s, x); } fd->fres = -s->FreqRes; fd->vres = -s->VelRes; sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0; for (i=x->NChannel-1; i>=0; i--) { fd->d[x->NChannel-1-i] = (double)(s->c[i]); if (sqrBt > 0.0 && fd->tsys > 0.0) fd->e[x->NChannel-1-i] = 2.0*fd->tsys/sqrBt; else fd->e[x->NChannel-1-i] = 1.0; } } else { fd->fn = Frequency(x->NChannel-1, s, x)/1000.; fd->f0 = Frequency(0, s, x)/1000.; if (odin) { fd->v0 = VelOdin(0, s, x); } else { fd->v0 = Velocity(0, s, x); } fd->fres = s->FreqRes; fd->vres = s->VelRes; sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0; for (i=0; i<x->NChannel; i++) { fd->d[i] = (double)(s->c[i]); if (sqrBt > 0.0 && fd->tsys > 0.0) fd->e[i] = 2.0*fd->tsys/sqrBt; else fd->e[i] = 1.0; } } }
int main(int argc, char *argv[]) { NRTSimulator::TCmdArgParser argParser(argc, argv); std::vector<std::shared_ptr<NRTSimulator::TTask>> tasks = NRTSimulator::TTaskFileParser(!argParser.IsCountingUsed()).Parse( argParser.GetTaskSpecFileName()); if (argParser.IsCountingUsed()) { std::cout << "Estimate convert rate for counting task..." << std::endl; NRTSimulator::TCountingTask::EstimateConvertRate(); } std::cout << "Responce time analysis..." << std::endl; NRTSimulator::TRTA rta(tasks); rta.Compute(); for (size_t taskNumber = 0; taskNumber < tasks.size(); ++ taskNumber) { if (rta.CheckIsShedulable(taskNumber)) { std::cout << tasks[taskNumber]->GetName() << ": worst case response time " << rta.GetWorstCaseResponceTime(taskNumber) << std::endl; } else { std::cout << tasks[taskNumber]->GetName() << ": is not schedulable" << std::endl; } } std::cout << "Simulation..." << std::endl; auto start = std::chrono::high_resolution_clock::now() + TASK_OFFSET; auto end = start + std::chrono::seconds(argParser.GetSimulationTime()); std::vector<pthread_t> threads(tasks.size()); std::cout << "Run real time tasks..." << std::endl; for (size_t i = 0; i < tasks.size(); ++i) { tasks[i]->Run(std::chrono::duration_cast<std::chrono::nanoseconds> (start.time_since_epoch()).count(), std::chrono::duration_cast<std::chrono::nanoseconds> (end.time_since_epoch()).count()); } std::cout << "Wait while simulation running..." << std::endl; for (size_t i = 0; i < threads.size(); ++i) { tasks[i]->Join(); std::cout << tasks[i]->GetName() << ": worst case response time " << tasks[i]->GetWorstCaseResponceTime() << std::endl; } if (argParser.IsPlotNeeded()) { std::cout << "Ploting..." << std::endl; for (const auto & task : tasks) { NRTSimulator::TCDFPlot().Plot(task->GetResponceTimes(), task->GetName()); } } std::cout << "Worst case kernel latency: " << rta.EstimateWorstCaseKernellLatency() << std::endl; if (!argParser.GetOutputDirectory().empty()) { std::cout << "Output result in '" << argParser.GetOutputDirectory() << "' directory..." << std::endl; NRTSimulator::TOutput(argParser.GetOutputDirectory()).Write(tasks); } return 0; }