bool KMLpdManager::savePrinterDriver(KMPrinter *printer, DrMain *driver) { // To be able to save a printer driver, a printcap entry MUST exist. // We can then retrieve the spool directory from it. QString spooldir; PrintcapEntry *ent = findPrintcapEntry(printer->printerName()); if (!ent) return false; spooldir = ent->arg("sd"); if (driver->get("drtype") == "printtool" && !spooldir.isEmpty()) { QMap<QString,QString> options; driver->getOptions(options,true); // add some standard options options["DESIRED_TO"] = "ps"; options["PRINTER_TYPE"] = ent->comment(2); // get type from printcap entry (works in anycases) options["PS_SEND_EOF"] = "NO"; if (!checkGsDriver(options["GSDEVICE"])) return false; QString resol(options["RESOLUTION"]), color(options["COLOR"]); // update entry comment to make printtool happy and save printcap file ent->m_comment = QString::fromLatin1("##PRINTTOOL3## %1 %2 %3 %4 {} {%5} %6 {}").arg(options["PRINTER_TYPE"]).arg(options["GSDEVICE"]).arg((resol.isEmpty() ? QString::fromLatin1("NAxNA") : resol)).arg(options["PAPERSIZE"]).arg(driver->name()).arg((color.isEmpty() ? QString::fromLatin1("Default") : color.right(color.length()-15))); ent->m_args["if"] = spooldir+QString::fromLatin1("/filter"); if (!writePrinters()) return false; // write various driver files using templates QCString cmd = "cp "; cmd += QFile::encodeName(KProcess::quote(driverDirectory()+"/master-filter")); cmd += " "; cmd += QFile::encodeName(KProcess::quote(spooldir + "/filter")); if (system(cmd.data()) == 0 && savePrinttoolCfgFile(driverDirectory()+"/general.cfg.in",spooldir,options) && savePrinttoolCfgFile(driverDirectory()+"/postscript.cfg.in",spooldir,options) && savePrinttoolCfgFile(driverDirectory()+"/textonly.cfg.in",spooldir,options)) return true; setErrorMsg(i18n("Unable to write driver associated files in spool directory.")); } return false; }
int main(int argc, char** argv) { if (argc != 3) { cerr << "Usage: tensorCurvature InputFile OutputFile" << endl ; exit(1) ; } VectorMap eig1 ; SymmetricTensorField DTI ; vector<double> resol(3) ; Vector res, fa, trc, scurv ; char path[256] ; for (int k=0; k<3; k++) resol[k] = 1 ; cout << "reading file" << endl ; DTI.readTensorField(argv[1]) ; cout << DTI.d << endl ; // cout << sizeof(SymmetricTensor) * DTI.d.length << endl ; // VectorMap id ; // Ivector I(3), J(3); // I[0] = -50; I[1] = -50; I[2] = -50 ; // J[0] = 50; J[1] = 50; J[2] = 50 ; // Domain D(I,J) ; // id.idMap(D) ; DTI.computeTrace(trc) ; sprintf(path, "%s_tr", argv[2]) ; trc.write_imagesc(path) ; cout << "Inverting tensor " << endl; DTI.inverseTensor() ; sprintf(path, "%s_det0", argv[2]) ; DTI.determinant().write(path) ; // DTI.inverseTensor(pow(DTI.determinant().max(.01),.33)/100) ; // // DTI.pruneOutliers() ; // sprintf(path, "%s_det", argv[2]) ; // DTI.determinant().write_imagesc(path) ; // DTI.determinant().write(path) ; cout <<"censoring data" << endl ; DTI.censorTensor(0) ; sprintf(path, "%s_mask", argv[2]) ; // DTI.Mask.write_imagesc(path) ; DTI.Mask.write(path) ; cout << "Computing Fractional Anisotropy" << endl ; DTI.computeFractionalAnisotropy(fa) ; cout << "average anisotropy: " << fa.mean() << endl ; sprintf(path, "%s_fa", argv[2]) ; // fa.censor(DTI.Mask, .005) ; fa.write_imagesc(path) ; fa.write(path) ; cout << "Computing principal eigenvector" << endl ; DTI.computeFirstEigenvector(eig1) ; sprintf(path, "%s_eig", argv[2]) ; eig1.write(path) ; // DTI.normalizeByTrace() ; DTI.smoothTensor(2, .9) ; // DTI.censorTensor(1) ; DTI.swapMetric() ; cout << "Computing symbols" << endl ; DTI.computeChristoffelSymbols(resol) ; cout << "computing curvature" << endl ; DTI.computeScalarCurvature(scurv, resol) ; sprintf(path, "%s_curv", argv[2]) ; scurv *= -1 ; res.copy(scurv) ; trc += 1e-8; res /= trc ; scurv.censor(DTI.Mask, .05) ; scurv.writeZeroCentered(path) ; scurv.write(path) ; sprintf(path, "%s_curvtr", argv[2]) ; res.censor(DTI.Mask, .05) ; res.writeZeroCentered(path) ; res.write(path) ; sprintf(path, "%s_curvfa", argv[2]) ; res *= fa ; res.censor(DTI.Mask, .05) ; res.writeZeroCentered(path) ; SymmetricTensorField Ric ; cout << "computing Ricci curvature" << endl ; DTI.computeRicciCurvature(Ric, resol) ; Ric.computeFirstEigenvector(eig1) ; sprintf(path, "%s_eigRicci", argv[2]) ; eig1.write(path) ; }
int menuResolution() { Matrix m,result; int action,i,j; int dim=0; action=-1; while(action!=0) { for(i=0;i<40;i++) printf("-"); printf("\n\nRESOLUTION : \n"); for(i=0;i<2;i++) { printf("\t%d./ ",i); switch(i) { case 0: printf("Retourner au menu ;\n"); break; case 1: printf("Resolution par le pivot de gauss ;\n"); break; default: break; } } printf("\n\n"); for(i=0;i<40;i++) printf("-"); printf("\n\n"); printf("Que voulez-vous faire?\n"); scanf("%d",&action); printf("\n\n"); if(action==1) { printf("Donnez la dimension de la matrice.\n"); scanf("%d",&dim); printf("\n"); printf("Souhaitez-vous remplir la matrice ou la créer aléatoirement?\n"); printf("\t1./ Je remplis la matrice moi-même\n"); printf("\t2./ Je fais confiance au hasard\n"); scanf("%d",&action); printf("\n\n"); if((dim>=0)&&(action>0)&&(action<3)) { result=newMatrix(dim,1); m=newMatrix(dim,dim); if(action==1) { for(i=0;i<dim;i++) { for(j=0;j<dim;j++) { printf("Donnez le %dème coefficient pour l'équation %d: ",j,i); scanf("%f",&m->mat[i*dim+j]); } printf("Donnez le résultat pour l'équation %d: ",i); scanf("%f",&result->mat[i]); } } if(action==2) { fillMatrix(m); fillMatrix(result); } printf("\nVoici les matrices:\n"); afficheMatrice(m); afficheMatrice(result); printf("\n"); result=resol(m,result); printf("On obtient: \n"); for(i=0;i<dim;i++) printf("x%d = %f; \n",i,result->mat[i]); printf("\n\n\n"); deleteMatrix(m); deleteMatrix(result); } } else { break; } } return action; }
int main (void){ int i, j, n, res, *p, cont = 0; double *b, **mat, **L, **U; printf("Introdueix la dimensio desitjada \n"); scanf(" %d", &n); //Control d'errors, si la dimensio es negativa o 0, hi ha un error. if (n <= 0){ printf("La dimensio introduida no es valida \n"); exit(-1); } /** -----------------------------------------INICIALITZACIONS DELS VECTORS ----------------------------------------------------**/ /** Guardam memoria per la matriu inicial que volem. Per la matriu U que despres necessitarem. Pel vector b de termes indepentents. Pel vector p que ens controla les permutacions **/ //Guardam memoria primer per cada fila de la matriu i despres per cada columna. mat = (double **)malloc(n*sizeof(double *)); U = (double **)malloc(n*sizeof(double *)); if (mat == NULL){ printf("Error a l'assignar memoria de la matriu \n"); exit(1); } if (U == NULL){ printf("Error a l'assignar memoria \n"); } for(i = 0; i < n; i++){ mat[i] = (double *)malloc(n*sizeof(double)); U[i] = (double *)malloc(n*sizeof(double)); if (mat == NULL || U == NULL){ printf("Error a l'assignar memoria de la matriu \n "); exit(1); } } //Guardam memoria per el vector de termes independents de la matriu. p = (int *) malloc(n*sizeof(int)); b = (double *)malloc(n*sizeof(double)); if (p == NULL || b == NULL){ printf("Error a l'assignar memoria del vector \n"); exit(1); } //Inicialitzam els valors de b a 0. for (i = 0; i < n; i++){ p[i] = i+1; b[i] = 0.0; } /** ---------------------------------------------------GENERACIO DE LA MATRIU I DELS TERMES INDEPENTENTS ------------------------------------------------ **/ /* //Generacio de la matriu de Hilbert i del vector de termes independents: for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ mat[i][j] = (double) 1/(i + j + 1); b[i] += mat[i][j]; } } */ for(i = 0; i < n; i ++){ printf("Introdueix els nombres de la fila \n"); for (j = 0; j < n; j++){ scanf("%le", &mat[i][j]); } } //Generam una matriu la solucio del sistema de la qual sigui 1. for (i = 0; i < n; i++){ b[i] = 0; for (j = 0; j < n; j++){ b[i] += mat[i][j]; } } printVect(b, n); /** ----------------------------------------------------OPERACIONS NECESSARIES DEL PROGRAMA ------------------------------------------ **/ //Imprimim la matriu i el seu vector de termes independents per informar a l'usuari: //printf("Matriu generada: \n"); //printMat(mat, n, n); //1. APLICAM ELIMINACIO GAUSSIANA AMB PIVOTATGE: //Resolem pel metode de palu. Si el resultat ens dona -1 vol dir que hem fet algun error. Sortim. res = palu(n, mat, p, TOL, &cont); if (res == -1){ exit(-1); } //2. COMPROVACIO DE QUE L'ELIMINACIO GAUSSIANA HA FUNCIONAT CORRECTAMENT: printf("Matriu obtinguda despres d'haver fet el metode PALU \n"); printMat(mat, n, n); printf("Vector de trasposicions \n"); printVectint(p, n); //3. CONTROL DE QUANTES PERMUTACIONS HEM FET: printf("Hem fet %d permutacions \n", cont); //4. SEPARAM LES MATRIUS L i U PER PODER CALCULAR EL DETERMINANT: L = separateLU(mat, U, n); //printf("La matriu L queda: \n"); //printMat(L, n, n); //printf("La matriu U queda: \n"); //printMat(U, n, n); printf("El determinant de la matriu es %le \n", detPALU(U, n, cont)); //5: RESOLEM EL SISTEMA SEGONS ELS TERMES INDEPENTENTS b I LA MATRIU QUE ENS HAVIEN DONAT (ara modificada): res = resol(n, mat, b, p); //Si el resultat es > 0 hem d'acabar perque vol dir que hi ha hagut algun problema if (res > 0){ exit(1); } //6. DONAM LA SOLUCIO DEL SISTEMA: printf("Vector solucio del sistema: \n"); printVect(b, n); //printf("Matriu resultat de multiplicar L * U \n"); //printMat(matrixProduct(L, U, n, n, n), n, n); /** -------------------------------------------- OPERACIONS D'ALLIBERACIO DE MEMORIA ----------------------------------- **/ //Alliberam memoria. free(p); free(b); for (i = 0; i < n; i++){ free(mat[i]); } free(mat); return 0; }