void ConfigDialog::on_removeProfilePushButton_clicked() { if (ui->profilesComboBox->count() < 2) return; QString profile = ui->profilesComboBox->currentText(); if (!getProfiles(m_strIniPath).contains(profile)) return; QString msg(tr("Are you sure you want to remove profile \"")); msg += profile + "\""; QMessageBox msgBox(QMessageBox::Warning, tr("Remove profile"), msg, QMessageBox::Yes | QMessageBox::Cancel, this); msgBox.setDefaultButton(QMessageBox::Cancel); msgBox.setButtonText(QMessageBox::Yes, tr("Yes")); msgBox.setButtonText(QMessageBox::Cancel, tr("Cancel")); if (msgBox.exec() == QMessageBox::Yes) { removeProfile(m_strIniPath, profile); ui->profilesComboBox->blockSignals(true); ui->profilesComboBox->removeItem(ui->profilesComboBox->currentIndex()); changeProfile(m_strIniPath, ui->profilesComboBox->itemText(ui->profilesComboBox->currentIndex())); ui->profilesComboBox->blockSignals(false); _init(); ui->removeProfilePushButton->setDisabled(ui->profilesComboBox->count() < 2); } }
void ConfigDialog::on_addProfilePushButton_clicked() { QString profile = ui->profilesComboBox->currentText(); if (profile.isEmpty()) { QMessageBox msgBox(QMessageBox::Warning, tr("Cannot add profile"), tr("Empty profile name."), QMessageBox::Ok, this ); msgBox.exec(); return; } if (getProfiles(m_strIniPath).contains(profile)) { QString msg(tr("Profile \"")); msg += profile + tr("\" already exists."); QMessageBox msgBox(QMessageBox::Warning, tr("Cannot add profile"), msg, QMessageBox::Ok, this); msgBox.exec(); return; } addProfile(m_strIniPath, profile); ui->profilesComboBox->addItem(profile); for (int i = 0; i < ui->profilesComboBox->count(); ++i) { if (ui->profilesComboBox->itemText(i) == profile) { ui->profilesComboBox->setCurrentIndex(i); break; } } ui->removeProfilePushButton->setDisabled(false); }
void ConfigDialog::setIniPath(const QString & _strIniPath) { m_strIniPath = _strIniPath; QStringList translationFiles; _getTranslations(translationFiles); const QString currentTranslation = getTranslationFile(); int listIndex = 0; QStringList translationLanguages("English"); for (int i = 0; i < translationFiles.size(); ++i) { // get locale extracted by filename QString locale = translationFiles[i]; // "TranslationExample_de.qm" const bool bCurrent = locale == currentTranslation; locale.truncate(locale.lastIndexOf('.')); // "TranslationExample_de" locale.remove(0, locale.indexOf('_') + 1); // "de" QString language = QLocale(locale).nativeLanguageName(); language = language.left(1).toUpper() + language.remove(0, 1); if (bCurrent) { listIndex = i + 1; } translationLanguages << language; } ui->translationsComboBox->insertItems(0, translationLanguages); ui->translationsComboBox->setCurrentIndex(listIndex); // Profile ui->profilesComboBox->blockSignals(true); const QStringList aProfiles = getProfiles(m_strIniPath); ui->profilesComboBox->addItems(aProfiles); ui->profilesComboBox->setCurrentIndex(aProfiles.indexOf(getCurrentProfile(m_strIniPath))); ui->profilesComboBox->blockSignals(false); ui->removeProfilePushButton->setEnabled(ui->profilesComboBox->count() > 1); }
char *filterPro(double pi, double inclFract) { Profile *profiles; int i, numProfiles; double *lOnes, *lTwos; double *lik, *originalLik, piComp, sum; double minLik, minSum; char *incl; numProfiles = getNumProfiles(); incl = (char *)emalloc(numProfiles*sizeof(char)); if(inclFract == 1.0) { for(i=0; i<numProfiles; i++) incl[i] = 1; return incl; } profiles = getProfiles(); lOnes = getLones(); lTwos = getLtwos(); lik = (double *)emalloc(numProfiles*sizeof(double)); originalLik = (double *)emalloc(numProfiles*sizeof(double)); piComp = 1. - pi; sum = 0.0; for(i=0; i<numProfiles; i++) { lik[i] = -log(lOnes[i]*piComp + lTwos[i]*pi) * profiles[i].n; originalLik[i] = lik[i]; sum += lik[i]; } qsort(lik,numProfiles,sizeof(double),compDouble); minSum = sum * inclFract; sum = 0; i = 0; while(sum < minSum) sum += lik[i++]; minLik = lik[i-1]; for(i=0; i<numProfiles; i++) if(originalLik[i] >= minLik) incl[i] = 1; else incl[i] = 0; return incl; }
int clearDeleteQueue(void) { char strQueuePath[PATH_LENGTH]; char strMsgProfilePath[PATH_LENGTH],strMsgListPath[PATH_LENGTH]; struct f_info fileInfo; int handle,ret; int found,i,lineCount,linesCounted; char buffer[READ_LENGTH+1],*packageName, *cursor; ProfileData *pd; // For each string in DELETE_QUEUE_FILENAME, look for references in all message list files. If none found, delete. // When finished, delete DELETE_QUEUE_FILENAME. // Look at all message files, not just the ones in current profile or even only the ones that are active lists, // because a category that lists the message could later be activated. strcpy(strQueuePath,SYSTEM_PATH); strcat(strQueuePath,(char *)DELETE_QUEUE_FILENAME); pd = getProfiles(); linesCounted = 0; handle=tbOpen((LPSTR)strQueuePath,O_RDONLY); if (handle < 0) { logString(strQueuePath,ASAP,LOG_DETAIL); return -1; //no queue } do { getLine(-1,0); // reset from prior use lineCount = 0; while ((packageName = getLine(handle,buffer)) && ++lineCount <= linesCounted) {} // This lineCount and linesCounted skips previously processed lines in this loop. // This is necessary because findDeleteStringFromFile() also calls getLine and resets everything. (TODO:not optimal) if (!*packageName) break; // blank line at end of file getLine(handle,0); //reset file cursor to beginning of file linesCounted++; found = 0; if (DEBUG_MODE) { logString((char *)"DELETE QUEUE: Looking for references to ",BUFFER,LOG_DETAIL); logString(packageName,ASAP,LOG_DETAIL); } for (i=0;i<pd->intTotalMessageLists;i++) { strcpy(strMsgProfilePath,LISTS_PATH); strcat(strMsgProfilePath,pd->ptrProfileMessageLists[i]); strcat(strMsgProfilePath,"/*"); ret = _findfirst((LPSTR)strMsgProfilePath, &fileInfo,D_FILE); strcpy(strMsgListPath,strMsgProfilePath); while (ret >=0) { if (!strstr(fileInfo.f_name,LIST_MASTER)) { // don't search _activeLists.txt cursor = strrchr(strMsgListPath, '/') + 1; *cursor = 0; //remove *.* or previous filename strcat(strMsgListPath,fileInfo.f_name); logString(strMsgListPath,BUFFER,LOG_DETAIL); if (-1 != findDeleteStringFromFile(NULL,strMsgListPath,packageName,FALSE)) { found = 1; if (DEBUG_MODE) logString((char *)"Found another reference - will not delete package.",BUFFER,LOG_NORMAL); break; } } ret = _findnext(&fileInfo); } if (found) break; } if (!found) deletePackage(packageName); } while (packageName); close(handle); unlink((LPSTR)strQueuePath); }
int main(int argc, char *argv[]) { register int n, k; char rayFileName[14], inputLine[MAX_LINE_SIZE]; bool_t result, exit_on_EOF, to_obs, initialize, crosscoupling, analyze_output, equilibria_only; int Nspect, Nread, Nrequired, checkPoint, *wave_index = NULL; double muz, *S, *chi, *J; FILE *fp_out, *fp_ray, *fp_stokes; XDR xdrs; ActiveSet *as; setOptions(argc, argv); getCPU(0, TIME_START, NULL); SetFPEtraps(); /* --- Read input data and initialize -- -------------- */ readInput(); spectrum.updateJ = FALSE; /* --- Read input data for atmosphere -- -------------- */ getCPU(1, TIME_START, NULL); MULTIatmos(&atmos, &geometry); /* --- Read direction cosine for ray -- -------------- */ if ((fp_ray = fopen(RAY_INPUT_FILE, "r")) == NULL) { sprintf(messageStr, "Unable to open inputfile %s", RAY_INPUT_FILE); Error(ERROR_LEVEL_2, argv[0], messageStr); } getLine(fp_ray, COMMENT_CHAR, inputLine, exit_on_EOF=TRUE); Nread = sscanf(inputLine, "%lf", &muz); checkNread(Nread, Nrequired=1, argv[0], checkPoint=1); if (muz <= 0.0 || muz > 1.0) { sprintf(messageStr, "Value of muz = %f does not lie in interval <0.0, 1.0]\n", muz); Error(ERROR_LEVEL_2, argv[0], messageStr); } if (input.StokesMode == FIELD_FREE || input.StokesMode == POLARIZATION_FREE) { input.StokesMode = FULL_STOKES; } /* --- redefine geometry for just this one ray -- -------------- */ atmos.Nrays = geometry.Nrays = 1; geometry.muz[0] = muz; geometry.mux[0] = sqrt(1.0 - SQ(geometry.muz[0])); geometry.muy[0] = 0.0; geometry.wmu[0] = 1.0; if (atmos.Stokes) Bproject(); input.startJ = OLD_J; readAtomicModels(); readMolecularModels(); SortLambda(); getBoundary(&geometry); /* --- Open file with background opacities -- -------------- */ if (atmos.moving || input.StokesMode) { strcpy(input.background_File, "background.ray"); Background(analyze_output=FALSE, equilibria_only=FALSE); } else { Background(analyze_output=FALSE, equilibria_only=TRUE); if ((atmos.fd_background = open(input.background_File, O_RDONLY, 0)) == -1) { sprintf(messageStr, "Unable to open inputfile %s", input.background_File); Error(ERROR_LEVEL_2, argv[0], messageStr); } readBRS(); } convertScales(&atmos, &geometry); getProfiles(); initSolution(); initScatter(); getCPU(1, TIME_POLL, "Total initialize"); /* --- Solve radiative transfer equations -- -------------- */ solveSpectrum(FALSE, FALSE); /* --- Write emergent spectrum to output file -- -------------- */ sprintf(rayFileName, "spectrum_%4.2f", muz); if ((fp_out = fopen(rayFileName, "w" )) == NULL) { sprintf(messageStr, "Unable to open output file %s", rayFileName); Error(ERROR_LEVEL_2, argv[0], messageStr); } xdrstdio_create(&xdrs, fp_out, XDR_ENCODE); result = xdr_double(&xdrs, &muz); result = xdr_vector(&xdrs, (char *) spectrum.I[0], spectrum.Nspect, sizeof(double), (xdrproc_t) xdr_double); /* --- Read wavelength indices for which chi and S are to be written out for the specified direction -- -------------- */ Nread = fscanf(fp_ray, "%d", &Nspect); checkNread(Nread, 1, argv[0], checkPoint=2); if (Nspect > 0) { wave_index = (int *) malloc(Nspect * sizeof(int)); Nread = 0; while (fscanf(fp_ray, "%d", &wave_index[Nread]) != EOF) Nread++; checkNread(Nread, Nspect, argv[0], checkPoint=3); fclose(fp_ray); chi = (double *) malloc(atmos.Nspace * sizeof(double)); if (atmos.Stokes) S = (double *) malloc(4 * atmos.Nspace * sizeof(double)); else S = (double *) malloc(atmos.Nspace * sizeof(double)); } result = xdr_int(&xdrs, &Nspect); /* --- Go through the list of wavelengths -- -------------- */ if (Nspect > 0 && input.limit_memory) J = (double *) malloc(atmos.Nspace * sizeof(double)); for (n = 0; n < Nspect; n++) { if (wave_index[n] < 0 || wave_index[n] >= spectrum.Nspect) { sprintf(messageStr, "Illegal value of wave_index[n]: %4d\n" "Value has to be between 0 and %4d\n", wave_index[n], spectrum.Nspect); Error(ERROR_LEVEL_2, argv[0], messageStr); continue; } sprintf(messageStr, "Processing n = %4d, lambda = %9.3f [nm]\n", wave_index[n], spectrum.lambda[wave_index[n]]); Error(MESSAGE, NULL, messageStr); as = &spectrum.as[wave_index[n]]; alloc_as(wave_index[n], crosscoupling=FALSE); Opacity(wave_index[n], 0, to_obs=TRUE, initialize=TRUE); readBackground(wave_index[n], 0, to_obs=TRUE); if (input.limit_memory) { readJlambda(wave_index[n], J); } else J = spectrum.J[wave_index[n]]; /* --- Add the continuum opacity and emissivity -- -------------- */ for (k = 0; k < atmos.Nspace; k++) { chi[k] = as->chi[k] + as->chi_c[k]; S[k] = (as->eta[k] + as->eta_c[k] + as->sca_c[k]*J[k]) / chi[k]; } result = xdr_int(&xdrs, &wave_index[n]); result = xdr_vector(&xdrs, (char *) chi, atmos.Nspace, sizeof(double), (xdrproc_t) xdr_double); result = xdr_vector(&xdrs, (char *) S, atmos.Nspace, sizeof(double), (xdrproc_t) xdr_double); free_as(wave_index[n], crosscoupling=FALSE); } /* --- If magnetic fields are present -- -------------- */ if (atmos.Stokes || input.backgr_pol) { result = xdr_vector(&xdrs, (char *) spectrum.Stokes_Q[0], spectrum.Nspect, sizeof(double), (xdrproc_t) xdr_double); result = xdr_vector(&xdrs, (char *) spectrum.Stokes_U[0], spectrum.Nspect, sizeof(double), (xdrproc_t) xdr_double); result = xdr_vector(&xdrs, (char *) spectrum.Stokes_V[0], spectrum.Nspect, sizeof(double), (xdrproc_t) xdr_double); } if (Nspect > 0 && input.limit_memory) free(J); xdr_destroy(&xdrs); fclose(fp_out); printTotalCPU(); }
int main(int argc, char *argv[]) { bool_t analyze_output, equilibria_only; int niter, nact; Atom *atom; Molecule *molecule; /* --- Read input data and initialize -- -------------- */ setOptions(argc, argv); getCPU(0, TIME_START, NULL); SetFPEtraps(); readInput(); spectrum.updateJ = TRUE; getCPU(1, TIME_START, NULL); readAtmos(&atmos, &geometry); if (atmos.Stokes) Bproject(); fillMesh(&geometry); readAtomicModels(); readMolecularModels(); SortLambda(); getBoundary(&atmos, &geometry); Background(analyze_output=TRUE, equilibria_only=FALSE); getProfiles(); initSolution(); initScatter(); getCPU(1, TIME_POLL, "Total initialize"); /* --- Solve radiative transfer for active ingredients -- --------- */ Iterate(input.NmaxIter, input.iterLimit); adjustStokesMode(atom); niter = 0; while (niter < input.NmaxScatter) { if (solveSpectrum(FALSE, FALSE) <= input.iterLimit) break; niter++; } /* --- Write output files -- ------------------ */ getCPU(1, TIME_START, NULL); writeInput(); writeAtmos(&atmos); writeGeometry(&geometry); writeSpectrum(&spectrum); writeFlux(FLUX_DOT_OUT); for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; writeAtom(atom); writePopulations(atom); writeRadRate(atom); writeCollisionRate(atom); writeDamping(atom); } for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; writeMolPops(molecule); } writeOpacity(); getCPU(1, TIME_POLL, "Write output"); printTotalCPU(); }