int execute_commands(StringList commands, StringList arguments){ FILE *file; int ret = 0; background = 0; String command = new_string(); int position; String tmp; //verifica se o ultimo caracter do comand PATH é & se for remove e seta flag background pra 1 if(list_find_char_at_last(commands, '&') != -1){ while((tmp = list_next(&commands))){ remove_last_char(&tmp); } background = 1; //verifica se omultimo caractere dos comandos é & se sim remove e seta a flag background pra 1 }if((position = list_find_char_at_last(arguments, '&'))){ if(position != -1){ remove_last_char(&arguments.string[position]); background = 1; } } reset_index(&commands); // abre o arquivo a partir do comand PATH, se encontrar o arquivo tenta executar o comando while((command = list_next(&commands))){ file = fopen(command, "r"); if(!file) continue; fclose(file); ret = try_execute(command, arguments); } dispose_string(&command); return ret; }
//remove da lista strings vazias void trim_string_list(StringList *list, char element){ String tmp; while((tmp = list_next(list))){ if(is_empty_string(tmp)){ list_remove(list, --list->index); } } reset_index(list); }
int list_find_char_at_last(StringList list, char element){ String tmp; reset_index(&list); while((tmp = list_next(&list))){ if(find_char_at_last(tmp, element)) return list.index - 1; } return -1; }
void myprint(char* pb) { if(index == 1023) reset_index(); while(*pb != 0) { dump_buffer[index++] = *(pb++); } }
t_mat *init_mat(int n1, gmx_bool b1D) { t_mat *m; snew(m, 1); m->n1 = n1; m->nn = 0; m->b1D = b1D; m->maxrms = 0; m->minrms = 1e20; m->sumrms = 0; m->mat = mk_matrix(n1, n1, b1D); snew(m->erow, n1); snew(m->m_ind, n1); reset_index(m); return m; }
int query1() { int maxano, minano, npublics, nomes; char filename[40]; char *linha; maxano = minano = npublics = nomes = 0; printf("Ficheiro para leitura: "); if (fgets(filename, 40, stdin) != NULL) { linha = newline(filename); reset_index(); reset_stats(); reset_lista(); reset_length(); reset_catalogo(); if (parser_file(linha) == 0) { printf("Erro na abertura do ficheiro(Talvez ficheiro não exista ou tenha outro nome?)\n"); } else { maxano = getMaxAno(); minano = getMinAno(); npublics = getNPublics(); nomes = getNomes(); printf("Ficheiro lido: %s\n", linha); printf("Nº publicacoes: %d\n", npublics); printf("Anos: [%d a %d]\n", minano, maxano); printf("Nº de nomes lidos: %d\n", nomes); } } else { printf("Erro na abertura do ficheiro"); } return 1; }
int cmd_reset(int argc, const char **argv, const char *prefix) { int reset_type = NONE, update_ref_status = 0, quiet = 0; int patch_mode = 0, unborn; const char *rev; unsigned char sha1[20]; const char **pathspec = NULL; const struct option options[] = { OPT__QUIET(&quiet, N_("be quiet, only report errors")), OPT_SET_INT(0, "mixed", &reset_type, N_("reset HEAD and index"), MIXED), OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT), OPT_SET_INT(0, "hard", &reset_type, N_("reset HEAD, index and working tree"), HARD), OPT_SET_INT(0, "merge", &reset_type, N_("reset HEAD, index and working tree"), MERGE), OPT_SET_INT(0, "keep", &reset_type, N_("reset HEAD but keep local changes"), KEEP), OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")), OPT_END() }; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, git_reset_usage, PARSE_OPT_KEEP_DASHDASH); pathspec = parse_args(argv, prefix, &rev); unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", sha1); if (unborn) { /* reset on unborn branch: treat as reset to empty tree */ hashcpy(sha1, EMPTY_TREE_SHA1_BIN); } else if (!pathspec) { struct commit *commit; if (get_sha1_committish(rev, sha1)) die(_("Failed to resolve '%s' as a valid revision."), rev); commit = lookup_commit_reference(sha1); if (!commit) die(_("Could not parse object '%s'."), rev); hashcpy(sha1, commit->object.sha1); } else { struct tree *tree; if (get_sha1_treeish(rev, sha1)) die(_("Failed to resolve '%s' as a valid tree."), rev); tree = parse_tree_indirect(sha1); if (!tree) die(_("Could not parse object '%s'."), rev); hashcpy(sha1, tree->object.sha1); } if (patch_mode) { if (reset_type != NONE) die(_("--patch is incompatible with --{hard,mixed,soft}")); return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", pathspec); } /* git reset tree [--] paths... can be used to * load chosen paths from the tree into the index without * affecting the working tree nor HEAD. */ if (pathspec) { if (reset_type == MIXED) warning(_("--mixed with paths is deprecated; use 'git reset -- <paths>' instead.")); else if (reset_type != NONE) die(_("Cannot do %s reset with paths."), _(reset_type_names[reset_type])); } if (reset_type == NONE) reset_type = MIXED; /* by default */ if (reset_type != SOFT && reset_type != MIXED) setup_work_tree(); if (reset_type == MIXED && is_bare_repository()) die(_("%s reset is not allowed in a bare repository"), _(reset_type_names[reset_type])); /* Soft reset does not touch the index file nor the working tree * at all, but requires them in a good order. Other resets reset * the index file to the tree object we are switching to. */ if (reset_type == SOFT || reset_type == KEEP) die_if_unmerged_cache(reset_type); if (reset_type != SOFT) { struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); int newfd = hold_locked_index(lock, 1); if (reset_type == MIXED) { if (read_from_tree(pathspec, sha1)) return 1; } else { int err = reset_index(sha1, reset_type, quiet); if (reset_type == KEEP && !err) err = reset_index(sha1, MIXED, quiet); if (err) die(_("Could not reset index file to revision '%s'."), rev); } if (reset_type == MIXED) { /* Report what has not been updated. */ int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); } if (write_cache(newfd, active_cache, active_nr) || commit_locked_index(lock)) die(_("Could not write new index file.")); } if (!pathspec && !unborn) { /* Any resets without paths update HEAD to the head being * switched to, saving the previous head in ORIG_HEAD before. */ update_ref_status = update_refs(rev, sha1); if (reset_type == HARD && !update_ref_status && !quiet) print_new_head_line(lookup_commit_reference(sha1)); } if (!pathspec) remove_branch_state(); return update_ref_status; }
int Asset::init_values() { path[0] = 0; awindow_folder = AW_MEDIA_FOLDER; // format = FILE_MOV; // Has to be unknown for file probing to succeed format = FILE_UNKNOWN; channels = 0; sample_rate = 0; bits = 0; byte_order = 0; signed_ = 0; header = 0; dither = 0; audio_data = 0; video_data = 0; audio_length = 0; video_length = 0; layers = 0; frame_rate = 0; width = 0; height = 0; strcpy(vcodec, QUICKTIME_YUV2); strcpy(acodec, QUICKTIME_TWOS); jpeg_quality = 100; aspect_ratio = -1; interlace_autofixoption = BC_ILACE_AUTOFIXOPTION_AUTO; interlace_mode = BC_ILACE_MODE_UNDETECTED; interlace_fixmethod = BC_ILACE_FIXMETHOD_NONE; ampeg_bitrate = 256; ampeg_derivative = 3; vorbis_vbr = 0; vorbis_min_bitrate = -1; vorbis_bitrate = 128000; vorbis_max_bitrate = -1; theora_fix_bitrate = 1; theora_bitrate = 860000; theora_quality = 16; theora_sharpness = 2; theora_keyframe_frequency = 64; theora_keyframe_force_frequency = 64; mp3_bitrate = 256000; mp4a_bitrate = 256000; mp4a_quantqual = 100; // mpeg parameters vmpeg_iframe_distance = 45; vmpeg_pframe_distance = 0; vmpeg_progressive = 0; vmpeg_denoise = 1; vmpeg_bitrate = 1000000; vmpeg_derivative = 1; vmpeg_quantization = 15; vmpeg_cmodel = 0; vmpeg_fix_bitrate = 0; vmpeg_seq_codes = 0; vmpeg_preset = 0; vmpeg_field_order = 0; // Divx parameters. BC_Hash from encore2 divx_bitrate = 2000000; divx_rc_period = 50; divx_rc_reaction_ratio = 45; divx_rc_reaction_period = 10; divx_max_key_interval = 250; divx_max_quantizer = 31; divx_min_quantizer = 1; divx_quantizer = 5; divx_quality = 5; divx_fix_bitrate = 1; divx_use_deblocking = 1; h264_bitrate = 2000000; h264_quantizer = 5; h264_fix_bitrate = 0; ms_bitrate = 1000000; ms_bitrate_tolerance = 500000; ms_quantization = 10; ms_interlaced = 0; ms_gop_size = 45; ms_fix_bitrate = 1; ac3_bitrate = 128; png_use_alpha = 0; exr_use_alpha = 0; exr_compression = 0; tiff_cmodel = 0; tiff_compression = 0; use_header = 1; reset_index(); id = EDL::next_id(); pipe[0] = 0; use_pipe = 0; reset_timecode(); return 0; }
int gmx_cluster(int argc,char *argv[]) { static char *desc[] = { "g_cluster can cluster structures with several different methods.", "Distances between structures can be determined from a trajectory", "or read from an XPM matrix file with the [TT]-dm[tt] option.", "RMS deviation after fitting or RMS deviation of atom-pair distances", "can be used to define the distance between structures.[PAR]", "single linkage: add a structure to a cluster when its distance to any", "element of the cluster is less than [TT]cutoff[tt].[PAR]", "Jarvis Patrick: add a structure to a cluster when this structure", "and a structure in the cluster have each other as neighbors and", "they have a least [TT]P[tt] neighbors in common. The neighbors", "of a structure are the M closest structures or all structures within", "[TT]cutoff[tt].[PAR]", "Monte Carlo: reorder the RMSD matrix using Monte Carlo.[PAR]", "diagonalization: diagonalize the RMSD matrix.[PAR]" "gromos: use algorithm as described in Daura [IT]et al.[it]", "([IT]Angew. Chem. Int. Ed.[it] [BB]1999[bb], [IT]38[it], pp 236-240).", "Count number of neighbors using cut-off, take structure with", "largest number of neighbors with all its neighbors as cluster", "and eleminate it from the pool of clusters. Repeat for remaining", "structures in pool.[PAR]", "When the clustering algorithm assigns each structure to exactly one", "cluster (single linkage, Jarvis Patrick and gromos) and a trajectory", "file is supplied, the structure with", "the smallest average distance to the others or the average structure", "or all structures for each cluster will be written to a trajectory", "file. When writing all structures, separate numbered files are made", "for each cluster.[PAR]" "Two output files are always written:[BR]", "[TT]-o[tt] writes the RMSD values in the upper left half of the matrix", "and a graphical depiction of the clusters in the lower right half", "When [TT]-minstruct[tt] = 1 the graphical depiction is black", "when two structures are in the same cluster.", "When [TT]-minstruct[tt] > 1 different colors will be used for each", "cluster.[BR]", "[TT]-g[tt] writes information on the options used and a detailed list", "of all clusters and their members.[PAR]", "Additionally, a number of optional output files can be written:[BR]", "[TT]-dist[tt] writes the RMSD distribution.[BR]", "[TT]-ev[tt] writes the eigenvectors of the RMSD matrix", "diagonalization.[BR]", "[TT]-sz[tt] writes the cluster sizes.[BR]", "[TT]-tr[tt] writes a matrix of the number transitions between", "cluster pairs.[BR]", "[TT]-ntr[tt] writes the total number of transitions to or from", "each cluster.[BR]", "[TT]-clid[tt] writes the cluster number as a function of time.[BR]", "[TT]-cl[tt] writes average (with option [TT]-av[tt]) or central", "structure of each cluster or writes numbered files with cluster members", "for a selected set of clusters (with option [TT]-wcl[tt], depends on", "[TT]-nst[tt] and [TT]-rmsmin[tt]).[BR]", }; FILE *fp,*log; int i,i1,i2,j,nf,nrms; matrix box; rvec *xtps,*usextps,*x1,**xx=NULL; char *fn,*trx_out_fn; t_clusters clust; t_mat *rms; real *eigval; t_topology top; int ePBC; t_atoms useatoms; t_matrix *readmat; real *tmp; int isize=0,ifsize=0,iosize=0; atom_id *index=NULL, *fitidx, *outidx; char *grpname; real rmsd,**d1,**d2,*time,time_invfac,*mass=NULL; char buf[STRLEN],buf1[80],title[STRLEN]; bool bAnalyze,bUseRmsdCut,bJP_RMSD=FALSE,bReadMat,bReadTraj; int method,ncluster=0; static char *methodname[] = { NULL, "linkage", "jarvis-patrick","monte-carlo", "diagonalization", "gromos", NULL }; enum { m_null, m_linkage, m_jarvis_patrick, m_monte_carlo, m_diagonalize, m_gromos, m_nr }; /* Set colors for plotting: white = zero RMS, black = maximum */ static t_rgb rlo_top = { 1.0, 1.0, 1.0 }; static t_rgb rhi_top = { 0.0, 0.0, 0.0 }; static t_rgb rlo_bot = { 1.0, 1.0, 1.0 }; static t_rgb rhi_bot = { 0.0, 0.0, 1.0 }; static int nlevels=40,skip=1; static real scalemax=-1.0,rmsdcut=0.1,rmsmin=0.0; static bool bRMSdist=FALSE,bBinary=FALSE,bAverage=FALSE,bFit=TRUE; static int niter=10000,seed=1993,write_ncl=0,write_nst=1,minstruct=1; static real kT=1e-3; static int M=10,P=3; t_pargs pa[] = { { "-dista", FALSE, etBOOL, {&bRMSdist}, "Use RMSD of distances instead of RMS deviation" }, { "-nlevels",FALSE,etINT, {&nlevels}, "Discretize RMSD matrix in # levels" }, { "-cutoff",FALSE, etREAL, {&rmsdcut}, "RMSD cut-off (nm) for two structures to be neighbor" }, { "-fit", FALSE, etBOOL, {&bFit}, "Use least squares fitting before RMSD calculation" }, { "-max", FALSE, etREAL, {&scalemax}, "Maximum level in RMSD matrix" }, { "-skip", FALSE, etINT, {&skip}, "Only analyze every nr-th frame" }, { "-av", FALSE, etBOOL, {&bAverage}, "Write average iso middle structure for each cluster" }, { "-wcl", FALSE, etINT, {&write_ncl}, "Write all structures for first # clusters to numbered files" }, { "-nst", FALSE, etINT, {&write_nst}, "Only write all structures if more than # per cluster" }, { "-rmsmin",FALSE, etREAL, {&rmsmin}, "minimum rms difference with rest of cluster for writing structures" }, { "-method",FALSE, etENUM, {methodname}, "Method for cluster determination" }, { "-minstruct", FALSE, etINT, {&minstruct}, "Minimum number of structures in cluster for coloring in the xpm file" }, { "-binary",FALSE, etBOOL, {&bBinary}, "Treat the RMSD matrix as consisting of 0 and 1, where the cut-off " "is given by -cutoff" }, { "-M", FALSE, etINT, {&M}, "Number of nearest neighbors considered for Jarvis-Patrick algorithm, " "0 is use cutoff" }, { "-P", FALSE, etINT, {&P}, "Number of identical nearest neighbors required to form a cluster" }, { "-seed", FALSE, etINT, {&seed}, "Random number seed for Monte Carlo clustering algorithm" }, { "-niter", FALSE, etINT, {&niter}, "Number of iterations for MC" }, { "-kT", FALSE, etREAL, {&kT}, "Boltzmann weighting factor for Monte Carlo optimization " "(zero turns off uphill steps)" } }; t_filenm fnm[] = { { efTRX, "-f", NULL, ffOPTRD }, { efTPS, "-s", NULL, ffOPTRD }, { efNDX, NULL, NULL, ffOPTRD }, { efXPM, "-dm", "rmsd", ffOPTRD }, { efXPM, "-o", "rmsd-clust", ffWRITE }, { efLOG, "-g", "cluster", ffWRITE }, { efXVG, "-dist", "rmsd-dist", ffOPTWR }, { efXVG, "-ev", "rmsd-eig", ffOPTWR }, { efXVG, "-sz", "clust-size", ffOPTWR}, { efXPM, "-tr", "clust-trans",ffOPTWR}, { efXVG, "-ntr", "clust-trans",ffOPTWR}, { efXVG, "-clid", "clust-id.xvg",ffOPTWR}, { efTRX, "-cl", "clusters.pdb", ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_TIME_UNIT | PCA_BE_NICE, NFILE,fnm,asize(pa),pa,asize(desc),desc,0,NULL); /* parse options */ bReadMat = opt2bSet("-dm",NFILE,fnm); bReadTraj = opt2bSet("-f",NFILE,fnm) || !bReadMat; if ( opt2parg_bSet("-av",asize(pa),pa) || opt2parg_bSet("-wcl",asize(pa),pa) || opt2parg_bSet("-nst",asize(pa),pa) || opt2parg_bSet("-rmsmin",asize(pa),pa) || opt2bSet("-cl",NFILE,fnm) ) trx_out_fn = opt2fn("-cl",NFILE,fnm); else trx_out_fn = NULL; if (bReadMat && time_factor()!=1) { fprintf(stderr, "\nWarning: assuming the time unit in %s is %s\n", opt2fn("-dm",NFILE,fnm),time_unit()); } if (trx_out_fn && !bReadTraj) fprintf(stderr,"\nWarning: " "cannot write cluster structures without reading trajectory\n" " ignoring option -cl %s\n", trx_out_fn); method=1; while ( method < m_nr && strcasecmp(methodname[0], methodname[method])!=0 ) method++; if (method == m_nr) gmx_fatal(FARGS,"Invalid method"); bAnalyze = (method == m_linkage || method == m_jarvis_patrick || method == m_gromos ); /* Open log file */ log = ftp2FILE(efLOG,NFILE,fnm,"w"); fprintf(stderr,"Using %s method for clustering\n",methodname[0]); fprintf(log,"Using %s method for clustering\n",methodname[0]); /* check input and write parameters to log file */ bUseRmsdCut = FALSE; if (method == m_jarvis_patrick) { bJP_RMSD = (M == 0) || opt2parg_bSet("-cutoff",asize(pa),pa); if ((M<0) || (M == 1)) gmx_fatal(FARGS,"M (%d) must be 0 or larger than 1",M); if (M < 2) { sprintf(buf1,"Will use P=%d and RMSD cutoff (%g)",P,rmsdcut); bUseRmsdCut = TRUE; } else { if (P >= M) gmx_fatal(FARGS,"Number of neighbors required (P) must be less than M"); if (bJP_RMSD) { sprintf(buf1,"Will use P=%d, M=%d and RMSD cutoff (%g)",P,M,rmsdcut); bUseRmsdCut = TRUE; } else sprintf(buf1,"Will use P=%d, M=%d",P,M); } ffprintf1(stderr,log,buf,"%s for determining the neighbors\n\n",buf1); } else /* method != m_jarvis */ bUseRmsdCut = ( bBinary || method == m_linkage || method == m_gromos ); if (bUseRmsdCut && method != m_jarvis_patrick) fprintf(log,"Using RMSD cutoff %g nm\n",rmsdcut); if ( method==m_monte_carlo ) fprintf(log,"Using %d iterations\n",niter); if (skip < 1) gmx_fatal(FARGS,"skip (%d) should be >= 1",skip); /* get input */ if (bReadTraj) { /* don't read mass-database as masses (and top) are not used */ read_tps_conf(ftp2fn(efTPS,NFILE,fnm),buf,&top,&ePBC,&xtps,NULL,box, bAnalyze); fprintf(stderr,"\nSelect group for least squares fit%s:\n", bReadMat?"":" and RMSD calculation"); get_index(&(top.atoms),ftp2fn_null(efNDX,NFILE,fnm), 1,&ifsize,&fitidx,&grpname); if (trx_out_fn) { fprintf(stderr,"\nSelect group for output:\n"); get_index(&(top.atoms),ftp2fn_null(efNDX,NFILE,fnm), 1,&iosize,&outidx,&grpname); /* merge and convert both index groups: */ /* first copy outidx to index. let outidx refer to elements in index */ snew(index,iosize); isize = iosize; for(i=0; i<iosize; i++) { index[i]=outidx[i]; outidx[i]=i; } /* now lookup elements from fitidx in index, add them if necessary and also let fitidx refer to elements in index */ for(i=0; i<ifsize; i++) { j=0; while (j<isize && index[j]!=fitidx[i]) j++; if (j>=isize) { /* slow this way, but doesn't matter much */ isize++; srenew(index,isize); } index[j]=fitidx[i]; fitidx[i]=j; } } else { /* !trx_out_fn */ isize = ifsize; snew(index, isize); for(i=0; i<ifsize; i++) { index[i]=fitidx[i]; fitidx[i]=i; } } } /* Initiate arrays */ snew(d1,isize); snew(d2,isize); for(i=0; (i<isize); i++) { snew(d1[i],isize); snew(d2[i],isize); } if (bReadTraj) { /* Loop over first coordinate file */ fn = opt2fn("-f",NFILE,fnm); xx = read_whole_trj(fn,isize,index,skip,&nf,&time); convert_times(nf, time); if (!bRMSdist || bAnalyze) { /* Center all frames on zero */ snew(mass,isize); for(i=0; i<ifsize; i++) mass[fitidx[i]] = top.atoms.atom[index[fitidx[i]]].m; if (bFit) for(i=0; i<nf; i++) reset_x(ifsize,fitidx,isize,NULL,xx[i],mass); } } if (bReadMat) { fprintf(stderr,"Reading rms distance matrix "); read_xpm_matrix(opt2fn("-dm",NFILE,fnm),&readmat); fprintf(stderr,"\n"); if (readmat[0].nx != readmat[0].ny) gmx_fatal(FARGS,"Matrix (%dx%d) is not square", readmat[0].nx,readmat[0].ny); if (bReadTraj && bAnalyze && (readmat[0].nx != nf)) gmx_fatal(FARGS,"Matrix size (%dx%d) does not match the number of " "frames (%d)",readmat[0].nx,readmat[0].ny,nf); nf = readmat[0].nx; sfree(time); time = readmat[0].axis_x; time_invfac = time_invfactor(); for(i=0; i<nf; i++) time[i] *= time_invfac; rms = init_mat(readmat[0].nx,method == m_diagonalize); convert_mat(&(readmat[0]),rms); nlevels = readmat[0].nmap; } else { /* !bReadMat */ rms = init_mat(nf,method == m_diagonalize); nrms = (nf*(nf-1))/2; if (!bRMSdist) { fprintf(stderr,"Computing %dx%d RMS deviation matrix\n",nf,nf); snew(x1,isize); for(i1=0; (i1<nf); i1++) { for(i2=i1+1; (i2<nf); i2++) { for(i=0; i<isize; i++) copy_rvec(xx[i1][i],x1[i]); if (bFit) do_fit(isize,mass,xx[i2],x1); rmsd = rmsdev(isize,mass,xx[i2],x1); set_mat_entry(rms,i1,i2,rmsd); } nrms -= (nf-i1-1); fprintf(stderr,"\r# RMSD calculations left: %d ",nrms); } } else { /* bRMSdist */ fprintf(stderr,"Computing %dx%d RMS distance deviation matrix\n",nf,nf); for(i1=0; (i1<nf); i1++) { calc_dist(isize,xx[i1],d1); for(i2=i1+1; (i2<nf); i2++) { calc_dist(isize,xx[i2],d2); set_mat_entry(rms,i1,i2,rms_dist(isize,d1,d2)); } nrms -= (nf-i1-1); fprintf(stderr,"\r# RMSD calculations left: %d ",nrms); } } fprintf(stderr,"\n\n"); } ffprintf2(stderr,log,buf,"The RMSD ranges from %g to %g nm\n", rms->minrms,rms->maxrms); ffprintf1(stderr,log,buf,"Average RMSD is %g\n",2*rms->sumrms/(nf*(nf-1))); ffprintf1(stderr,log,buf,"Number of structures for matrix %d\n",nf); ffprintf1(stderr,log,buf,"Energy of the matrix is %g nm\n",mat_energy(rms)); if (bUseRmsdCut && (rmsdcut < rms->minrms || rmsdcut > rms->maxrms) ) fprintf(stderr,"WARNING: rmsd cutoff %g is outside range of rmsd values " "%g to %g\n",rmsdcut,rms->minrms,rms->maxrms); if (bAnalyze && (rmsmin < rms->minrms) ) fprintf(stderr,"WARNING: rmsd minimum %g is below lowest rmsd value %g\n", rmsmin,rms->minrms); if (bAnalyze && (rmsmin > rmsdcut) ) fprintf(stderr,"WARNING: rmsd minimum %g is above rmsd cutoff %g\n", rmsmin,rmsdcut); /* Plot the rmsd distribution */ rmsd_distribution(opt2fn("-dist",NFILE,fnm),rms); if (bBinary) { for(i1=0; (i1 < nf); i1++) for(i2=0; (i2 < nf); i2++) if (rms->mat[i1][i2] < rmsdcut) rms->mat[i1][i2] = 0; else rms->mat[i1][i2] = 1; } snew(clust.cl,nf); switch (method) { case m_linkage: /* Now sort the matrix and write it out again */ gather(rms,rmsdcut,&clust); break; case m_diagonalize: /* Do a diagonalization */ snew(eigval,nf); snew(tmp,nf*nf); memcpy(tmp,rms->mat[0],nf*nf*sizeof(real)); eigensolver(tmp,nf,0,nf,eigval,rms->mat[0]); sfree(tmp); fp = xvgropen(opt2fn("-ev",NFILE,fnm),"RMSD matrix Eigenvalues", "Eigenvector index","Eigenvalues (nm\\S2\\N)"); for(i=0; (i<nf); i++) fprintf(fp,"%10d %10g\n",i,eigval[i]); ffclose(fp); break; case m_monte_carlo: mc_optimize(log,rms,niter,&seed,kT); swap_mat(rms); reset_index(rms); break; case m_jarvis_patrick: jarvis_patrick(rms->nn,rms->mat,M,P,bJP_RMSD ? rmsdcut : -1,&clust); break; case m_gromos: gromos(rms->nn,rms->mat,rmsdcut,&clust); break; default: gmx_fatal(FARGS,"DEATH HORROR unknown method \"%s\"",methodname[0]); } if (method == m_monte_carlo || method == m_diagonalize) fprintf(stderr,"Energy of the matrix after clustering is %g nm\n", mat_energy(rms)); if (bAnalyze) { if (minstruct > 1) { ncluster = plot_clusters(nf,rms->mat,&clust,nlevels,minstruct); } else { mark_clusters(nf,rms->mat,rms->maxrms,&clust); } init_t_atoms(&useatoms,isize,FALSE); snew(usextps, isize); useatoms.resname=top.atoms.resname; for(i=0; i<isize; i++) { useatoms.atomname[i]=top.atoms.atomname[index[i]]; useatoms.atom[i].resnr=top.atoms.atom[index[i]].resnr; useatoms.nres=max(useatoms.nres,useatoms.atom[i].resnr+1); copy_rvec(xtps[index[i]],usextps[i]); } useatoms.nr=isize; analyze_clusters(nf,&clust,rms->mat,isize,&useatoms,usextps,mass,xx,time, ifsize,fitidx,iosize,outidx, bReadTraj?trx_out_fn:NULL, opt2fn_null("-sz",NFILE,fnm), opt2fn_null("-tr",NFILE,fnm), opt2fn_null("-ntr",NFILE,fnm), opt2fn_null("-clid",NFILE,fnm), bAverage, write_ncl, write_nst, rmsmin, bFit, log, rlo_bot,rhi_bot); } ffclose(log); if (bBinary && !bAnalyze) /* Make the clustering visible */ for(i2=0; (i2 < nf); i2++) for(i1=i2+1; (i1 < nf); i1++) if (rms->mat[i1][i2]) rms->mat[i1][i2] = rms->maxrms; fp = opt2FILE("-o",NFILE,fnm,"w"); fprintf(stderr,"Writing rms distance/clustering matrix "); if (bReadMat) { write_xpm(fp,0,readmat[0].title,readmat[0].legend,readmat[0].label_x, readmat[0].label_y,nf,nf,readmat[0].axis_x,readmat[0].axis_y, rms->mat,0.0,rms->maxrms,rlo_top,rhi_top,&nlevels); } else { sprintf(buf,"Time (%s)",time_unit()); sprintf(title,"RMS%sDeviation / Cluster Index", bRMSdist ? " Distance " : " "); if (minstruct > 1) { write_xpm_split(fp,0,title,"RMSD (nm)",buf,buf, nf,nf,time,time,rms->mat,0.0,rms->maxrms,&nlevels, rlo_top,rhi_top,0.0,(real) ncluster, &ncluster,TRUE,rlo_bot,rhi_bot); } else { write_xpm(fp,0,title,"RMSD (nm)",buf,buf, nf,nf,time,time,rms->mat,0.0,rms->maxrms, rlo_top,rhi_top,&nlevels); } } fprintf(stderr,"\n"); ffclose(fp); /* now show what we've done */ do_view(opt2fn("-o",NFILE,fnm),"-nxy"); do_view(opt2fn_null("-sz",NFILE,fnm),"-nxy"); if (method == m_diagonalize) do_view(opt2fn_null("-ev",NFILE,fnm),"-nxy"); do_view(opt2fn("-dist",NFILE,fnm),"-nxy"); if (bAnalyze) { do_view(opt2fn_null("-tr",NFILE,fnm),"-nxy"); do_view(opt2fn_null("-ntr",NFILE,fnm),"-nxy"); do_view(opt2fn_null("-clid",NFILE,fnm),"-nxy"); } /* Thank the user for her patience */ thanx(stderr); return 0; }
int cmd_reset(int argc, const char **argv, const char *prefix) { int reset_type = NONE, update_ref_status = 0, quiet = 0; int patch_mode = 0, nul_term_line = 0, read_from_stdin = 0, unborn; char **stdin_paths = NULL; int stdin_nr = 0, stdin_alloc = 0; const char *rev; struct object_id oid; struct pathspec pathspec; int intent_to_add = 0; const struct option options[] = { OPT__QUIET(&quiet, N_("be quiet, only report errors")), OPT_SET_INT(0, "mixed", &reset_type, N_("reset HEAD and index"), MIXED), OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT), OPT_SET_INT(0, "hard", &reset_type, N_("reset HEAD, index and working tree"), HARD), OPT_SET_INT(0, "merge", &reset_type, N_("reset HEAD, index and working tree"), MERGE), OPT_SET_INT(0, "keep", &reset_type, N_("reset HEAD but keep local changes"), KEEP), { OPTION_CALLBACK, 0, "recurse-submodules", NULL, "reset", "control recursive updating of submodules", PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")), OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that removed paths will be added later")), OPT_BOOL('z', NULL, &nul_term_line, N_("EXPERIMENTAL: paths are separated with NUL character")), OPT_BOOL(0, "stdin", &read_from_stdin, N_("EXPERIMENTAL: read paths from <stdin>")), OPT_END() }; git_config(git_reset_config, NULL); argc = parse_options(argc, argv, prefix, options, git_reset_usage, PARSE_OPT_KEEP_DASHDASH); parse_args(&pathspec, argv, prefix, patch_mode, &rev); if (read_from_stdin) { strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; int flags = PATHSPEC_PREFER_FULL; struct strbuf buf = STRBUF_INIT; struct strbuf unquoted = STRBUF_INIT; if (patch_mode) die(_("--stdin is incompatible with --patch")); if (pathspec.nr) die(_("--stdin is incompatible with path arguments")); while (getline_fn(&buf, stdin) != EOF) { if (!nul_term_line && buf.buf[0] == '"') { strbuf_reset(&unquoted); if (unquote_c_style(&unquoted, buf.buf, NULL)) die(_("line is badly quoted")); strbuf_swap(&buf, &unquoted); } ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc); stdin_paths[stdin_nr++] = xstrdup(buf.buf); strbuf_reset(&buf); } strbuf_release(&unquoted); strbuf_release(&buf); ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc); stdin_paths[stdin_nr++] = NULL; flags |= PATHSPEC_LITERAL_PATH; parse_pathspec(&pathspec, 0, flags, prefix, (const char **)stdin_paths); } else if (nul_term_line) die(_("-z requires --stdin")); unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid); if (unborn) { /* reset on unborn branch: treat as reset to empty tree */ hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN); } else if (!pathspec.nr) { struct commit *commit; if (get_oid_committish(rev, &oid)) die(_("Failed to resolve '%s' as a valid revision."), rev); commit = lookup_commit_reference(&oid); if (!commit) die(_("Could not parse object '%s'."), rev); oidcpy(&oid, &commit->object.oid); } else { struct tree *tree; if (get_oid_treeish(rev, &oid)) die(_("Failed to resolve '%s' as a valid tree."), rev); tree = parse_tree_indirect(&oid); if (!tree) die(_("Could not parse object '%s'."), rev); oidcpy(&oid, &tree->object.oid); } if (patch_mode) { if (reset_type != NONE) die(_("--patch is incompatible with --{hard,mixed,soft}")); return run_add_interactive(rev, "--patch=reset", &pathspec); } /* git reset tree [--] paths... can be used to * load chosen paths from the tree into the index without * affecting the working tree nor HEAD. */ if (pathspec.nr) { if (reset_type == MIXED) warning(_("--mixed with paths is deprecated; use 'git reset -- <paths>' instead.")); else if (reset_type != NONE) die(_("Cannot do %s reset with paths."), _(reset_type_names[reset_type])); } if (reset_type == NONE) reset_type = MIXED; /* by default */ if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree())) setup_work_tree(); if (reset_type == MIXED && is_bare_repository()) die(_("%s reset is not allowed in a bare repository"), _(reset_type_names[reset_type])); if (intent_to_add && reset_type != MIXED) die(_("-N can only be used with --mixed")); /* Soft reset does not touch the index file nor the working tree * at all, but requires them in a good order. Other resets reset * the index file to the tree object we are switching to. */ if (reset_type == SOFT || reset_type == KEEP) die_if_unmerged_cache(reset_type); if (reset_type != SOFT) { struct lock_file lock = LOCK_INIT; hold_locked_index(&lock, LOCK_DIE_ON_ERROR); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; if (read_from_tree(&pathspec, &oid, intent_to_add)) return 1; if (get_git_work_tree()) refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); } else { int err = reset_index(&oid, reset_type, quiet); if (reset_type == KEEP && !err) err = reset_index(&oid, MIXED, quiet); if (err) die(_("Could not reset index file to revision '%s'."), rev); } if (write_locked_index(&the_index, &lock, COMMIT_LOCK)) die(_("Could not write new index file.")); } if (!pathspec.nr && !unborn) { /* Any resets without paths update HEAD to the head being * switched to, saving the previous head in ORIG_HEAD before. */ update_ref_status = reset_refs(rev, &oid); if (reset_type == HARD && !update_ref_status && !quiet) print_new_head_line(lookup_commit_reference(&oid)); } if (!pathspec.nr) remove_branch_state(); if (stdin_paths) { while (stdin_nr) free(stdin_paths[--stdin_nr]); free(stdin_paths); } return update_ref_status; }