Example #1
0
//prints everything located at the pathname
//Calls printdir which calls printinfo for a given pathname
//The main function of ls is to get the pathname and check for certain cases
//Finds the ino of the pathname
void ls(char *pathname)
{
	int ino, offset;
	MINODE *mip = running->cwd;
	char name[64][64], temp[64];
	char buf[1024];

	//ls cwd
	if(!strcmp(pathname, ""))
	{
		//print_dir(mip->INODE);
		print_dir(mip);
		return;
	}

	//ls root dir
	if(!strcmp(pathname, "/"))
	{
		//print_dir(root->INODE);
		print_dir(root);
		return;
	}

	//if there's a pathname, ls pathname
	if(pathname)
	{
		//check if path starts at root
		if(pathname[0] == '/')
		{
			mip = root;
		}

		//search for path to print
		ino = getino(mip, pathname);
		if(ino == 0)
		{
			return;
		}

		mip = iget(dev, ino);
		if(!S_ISDIR(mip->INODE.i_mode))
		{
			printf("%s is not a directory!\n", pathname);
			strcpy(teststr, pathname);
			strcat(teststr, " is not a directory!");
			iput(mip);
			return;
		}

		//print_dir(mip->INODE);
		print_dir(mip);
		iput(mip);
	}
	else
	{
		//print root dir
		//print_dir(root->INODE);
		print_dir(root);
	}
}
//prints everything located at the pathname
void ls(char *pathname)
{
	int ino, offset;
	MINODE *mip = running->cwd;
	char name[64][64], temp[64];
	char buf[1024];

	//ls cwd
	if(!strcmp(pathname, ""))
	{
		print_dir(mip->INODE);
		return;
	}

	//ls root dir
	if(!strcmp(pathname, "/"))
	{
		print_dir(root->INODE);
		return;
	}

	//if there's a pathname, ls pathname
	if(pathname)
	{
		//check if path starts at root
		if(pathname[0] == '/')
		{
			mip = root;
		}

		//search for path to print
		ino = getino(mip, pathname);
		if(ino == 0)
		{
			return;
		}
		printf("%d %d\n", ino, dev);
		if(iget(dev, ino) != NULL)
			mip = iget(dev, ino);
		else
		{
			printf("ERROR: cannot ls a file\n");
			return;
		}
		print_dir(mip->INODE);
	}
	else
	{
		//print root dir
		print_dir(root->INODE);
	}
}
Example #3
0
void print_dir(char *path)
{
	DIR                *dir=NULL;
	struct dirent      *ptr;
	char               filenames[2000];
	int                len=0;
	len=strlen(path);

	dir=opendir(path);
	if(dir==NULL){
	   return ;
	}
	while((ptr=readdir(dir)) !=NULL )
	{
		strncpy(filenames, path, len);
		filenames[len]='\0';
		strcat(filenames, ptr->d_name);
		filenames[len+strlen(ptr->d_name)]='\0';

		if(ptr->d_type==8){
			printf("%s  \n",ptr->d_name);
			}

		else if(ptr->d_type == 4){
			printf("%s  \n",ptr->d_name);
			print_dir(filenames);
		}

	}


}
Example #4
0
void			ft_ls(int print, int *option, t_list **directory, int mode)
{
	t_list		*elem;
	t_dlist		*data;

	if (mode)
		ft_ls_args(option, directory);
	elem = *directory;
	while (elem != NULL)
	{
		data = NULL;
		print_dir(&print, NAME);
		if (ft_lsgetdatadir(option, NAME, &data) != -1)
		{
			ft_lssortdata(option, &data);
			ft_lsprintdata(option, &data, link_or_dir(NAME));
			if (option[0] && !option[7])
				ft_lsrecursive(++print, option, NAME, &data);
			else if (*directory != NULL && data != NULL)
				ft_lscleardlist(&data);
		}
		elem = elem->next;
	}
	if (directory != NULL)
		ft_lstclear(directory);
}
Example #5
0
static svn_error_t *
directory_dump_old(struct directory_walk_baton *bt,
                   const char *dir_abspath,
                   apr_pool_t *scratch_pool)
{
  apr_hash_t *entries;
  apr_hash_index_t *hi;

  SVN_ERR(svn_wc__read_entries_old(&entries, dir_abspath,
                                   scratch_pool, scratch_pool));
  for (hi = apr_hash_first(scratch_pool, entries); hi; hi = apr_hash_next(hi))
    {
      const svn_wc_entry_t *entry = apr_hash_this_val(hi);
      const char *local_abspath;

      if (entry->deleted || entry->absent || entry->kind != svn_node_dir)
        continue;

      local_abspath = svn_dirent_join(dir_abspath, entry->name, scratch_pool);
      if (strcmp(entry->name, SVN_WC_ENTRY_THIS_DIR))
        SVN_ERR(directory_dump_old(bt, local_abspath, scratch_pool));
      else
        SVN_ERR(print_dir(local_abspath, entry->kind, bt, scratch_pool));
    }
  return SVN_NO_ERROR;
}
Example #6
0
void cgit_print_plain(struct cgit_context *ctx)
{
	const char *rev = ctx->qry.sha1;
	unsigned char sha1[20];
	struct commit *commit;
	const char *paths[] = {ctx->qry.path, NULL};

	if (!rev)
		rev = ctx->qry.head;

	if (get_sha1(rev, sha1)) {
		html_status(404, "Not found", 0);
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit || parse_commit(commit)) {
		html_status(404, "Not found", 0);
		return;
	}
	if (!paths[0]) {
		paths[0] = "";
		match_baselen = -1;
		print_dir(commit->tree->object.sha1, "", "");
	}
	else
		match_baselen = basedir_len(paths[0]);
	read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL);
	if (!match)
		html_status(404, "Not found", 0);
	else if (match == 2)
		print_dir_tail();
}
Example #7
0
File: ls.c Project: imbyungjun/TIL
int my_ls(const char *name, int opt) {
	struct stat stat_buf;
	struct passwd *pw;
	struct group *gr;
	struct tm *tm;
	char *perm;
	int cnt = 0;

	if (lstat(name, &stat_buf) < 0) {
		warn("%s", name);
		return -1;
	}


	if (start_flag & (opt & FLAG_R)) {				/* option -R */
		/* 아직 구현 못함 */
	}
	else if (!(start_flag++) && S_ISDIR(stat_buf.st_mode)) {
		print_dir(name, opt);
	} else if (opt & FLAG_L) {		/* option -l */
		perm = get_perm(name);
		pw = getpwuid(stat_buf.st_uid);
		gr = getgrgid(stat_buf.st_gid);
		tm = localtime(&stat_buf.st_mtime);

		printf("%s %2d %s  %s  %4d %02d %02d %02d:%02d %s\n",
				perm, stat_buf.st_nlink, pw->pw_name, gr->gr_name, stat_buf.st_size,
				tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, name);
		free(perm);
	} else {				/* default option */
		printf("%s\t", name);
	}

	return 0;
}
Example #8
0
void print_AllDir(director_t *director, int size)
{
    for(int i = 0; i < size; i++)
    {
        printf("%i.", (i+1));
        print_dir(&director[i]);
        printf("");
    }
}
Example #9
0
//DONEDONEDONEDONEDONEDONEDONE///////////////////////////////////////
void fn_ls (inode_state& state, const wordvec& words){
   bool r = false;
   string orig = pathname(state.get_contents().at("."),
                  state.get_root()->get_inode_nr());
   if (words.size() > 1) {
      for(auto word = words.begin()+1; word != words.end(); word++) {
         if((*word)[0] == '/') r = true;
         state.set_cwd(split(*word,"/"), r);
         print_dir(state);
         state.set_cwd(split(orig,"/"),true);
      }
   }
   else
      print_dir(state);         

   DEBUGF ('c', state);
   DEBUGF ('c', words);
}
Example #10
0
File: ls.c Project: akat1/impala
void
print_path(const char *file)
{
    struct stat st;
    lstat(file, &st);
    if (S_ISDIR(st.st_mode))
        print_dir(file);
        else print_file(file);
}
Example #11
0
void
init_dir(PNO * H, char *path, PNO * p_ini, PNO * p_pos, PNO * p_fim, int ini,
		 int *pos, int fim)
{
	desaloca(&(*H));
	carrega(path, &(*H));
	(*p_ini) = (*p_pos) = (*p_fim) = (*H);
	(*pos) = ini;
	inc_tela(&(*p_fim), ini, fim - 1);
	print_dir(p_ini, path, ini, pos, fim);
}
Example #12
0
std::string write_ledger_as_pdf(Ledger const& ledger, fs::path const& filepath)
{
    throw_if_interdicted(ledger);

    fs::path print_dir(configurable_settings::instance().print_directory());

    fs::path real_filepath(orthodox_filename(filepath.leaf()));
    LMI_ASSERT(fs::portable_name(real_filepath.string()));

    if(contains(global_settings::instance().pyx(), "xml"))
        {
        fs::path xml_file = unique_filepath(print_dir / real_filepath, ".xml");

        fs::ofstream ofs(xml_file, ios_out_trunc_binary());
        ledger.write(ofs);
        ofs.close();
        if(!ofs.good())
            {
            fatal_error()
                << "Unable to write output file '"
                << xml_file
                << "'."
                << LMI_FLUSH
                ;
            }
        }

    fs::path xml_fo_file = unique_filepath(print_dir / real_filepath, ".fo.xml");

    fs::ofstream ofs(xml_fo_file, ios_out_trunc_binary());
    ledger.write_xsl_fo(ofs);
    ofs.close();
    if(!ofs.good())
        {
        fatal_error()
            << "Unable to write output file '"
            << xml_fo_file
            << "'."
            << LMI_FLUSH
            ;
        }

    fs::path pdf_out_file = unique_filepath(print_dir / real_filepath, ".pdf");

    std::ostringstream oss;
    oss
        << configurable_settings::instance().xsl_fo_command()
        << " -fo "  << '"' << xml_fo_file  << '"'
        << " -pdf " << '"' << pdf_out_file << '"'
        ;
    system_command(oss.str());
    return pdf_out_file.string();
}
Example #13
0
int main(int argc, char *argv[])
{
    struct winsize ws;
    int ret, c, socket = 0, show_perm = 0;
    struct xs_handle *xsh;

#define PAD 2

    memset(&ws, 0, sizeof(ws));
    ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
    if (!ret)
        max_width = ws.ws_col - PAD;

    while (0 < (c = getopt(argc, argv, "pswf"))) {
        switch (c) {
        case 'w':
            max_width= STRING_MAX - PAD;
            desired_width = 0;
            break;
        case 'p':
            show_perm = 1;
            break;
        case 's':
            socket = 1;
            break;
        case 'f':
            max_width = INT_MAX/2;
            desired_width = 0;
            show_whole_path = 1;
            break;
        case ':':
        case '?':
        default:
            usage(argc, argv);
            return 0;
        }
    }

    /* Adjust the width here to avoid argument order dependency */
    if ( show_perm ) {
        max_width -= 16;
    }

    xsh = socket ? xs_daemon_open() : xs_domain_open();
    if (xsh == NULL)
        err(1, socket ? "xs_daemon_open" : "xs_domain_open");

    print_dir(xsh, (argc - optind) == 1 ? argv[optind] : "/", 0, show_perm);

    return 0;
}
Example #14
0
File: ls.c Project: akat1/impala
int
main(int argc, char **argv)
{
    char ch;
    progopt.all = 0;
    progopt.serial = 0;
    progopt.output_is_tty = isatty(1);
    progopt.graph = (progopt.output_is_tty)? 1 : 0;
    progopt.print = short_entry;
    progopt.ender = 0;
    while ( (ch = getopt(argc, argv, "1ailFG")) != -1 )
    switch (ch) {
        case '1':
            break;
        case 'a':
            progopt.all = 1;
            break;
        case 'i':
            progopt.serial = 1;
            break;
        case 'l':
            progopt.print = long_entry;
            break;
        case 'F':
            progopt.ender = 1;
            break;
        case 'G':
            progopt.graph = 0;
            break;
    }
    if (!progopt.output_is_tty) progopt.graph = 0;
    argv += optind;
    argc -= optind;
    if (argc < 2) {
        progopt.many = 0;
        const char *name = (argc==0) ? "." : argv[0];
        print_path(name);
    } else {
        progopt.many = 1;
        // zgodnie z standardem, najpierw drukowane są niekatalogi
        for (int i = 0; i < argc; i++) {
            print_file(argv[i]);
        }
        for (int i = 0; i < argc; i++) {
            print_dir(argv[i]);
        }
    }
    return 0;
}
Example #15
0
void
funcao_conf(PNO * p_ini, char *path, int ini, int *pos, int fim)
{
	STRING s[4];
	PTELA tela;
	tela = salva_tela(); // salva janela
	strcpy(s[0], "letra normal");
	strcpy(s[1], "letra ativa");
	strcpy(s[2], "fundo normal");
	strcpy(s[3], "fundo ativo");
	apaga_tela();
	seleciona_menu(ini, 0, 15);
	conf(funcao_menu(s, 4, ini, 6, 0, 15)); // abremenu
	restaura_tela(tela); // restaura tel
	print_dir(p_ini, path, ini, pos, fim);
}
Example #16
0
void		data_proc(t_file *dir)
{
	dir->next = NULL;
	dir = rewind_lst(dir);
	if (no_perm(dir) && g_flags[FLAG_R] == 1 && g_flags[FLAG_T] == 1)
		rsort_date(dir);
	else if (g_flags[FLAG_R] == 1 && g_flags[FLAG_T] != 1)
		rsort_dir(dir);
	else if (no_perm(dir) && g_flags[FLAG_R] != 1 && g_flags[FLAG_T] == 1)
		sort_date(dir);
	else
		sort_dir(dir);
	if (g_flags[FLAG_RR] != 1)
		print_dir(dir, 0);
	else
		ft_recurs(dir);
	ft_free_dir_lst(dir);
}
Example #17
0
static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
		     const char *pathname, unsigned mode, int stage,
		     void *cbdata)
{
	if (baselen == match_baselen) {
		if (S_ISREG(mode))
			print_object(sha1, pathname);
		else if (S_ISDIR(mode)) {
			print_dir(sha1, pathname, base);
			return READ_TREE_RECURSIVE;
		}
	}
	else if (baselen > match_baselen)
		print_dir_entry(sha1, pathname, mode);
	else if (S_ISDIR(mode))
		return READ_TREE_RECURSIVE;

	return 0;
}
Example #18
0
File: ui-plain.c Project: ifzz/cgit
void cgit_print_plain(void)
{
	const char *rev = ctx.qry.sha1;
	unsigned char sha1[20];
	struct commit *commit;
	struct pathspec_item path_items = {
		.match = ctx.qry.path,
		.len = ctx.qry.path ? strlen(ctx.qry.path) : 0
	};
	struct pathspec paths = {
		.nr = 1,
		.items = &path_items
	};
	struct walk_tree_context walk_tree_ctx = {
		.match = 0
	};

	if (!rev)
		rev = ctx.qry.head;

	if (get_sha1(rev, sha1)) {
		cgit_print_error_page(404, "Not found", "Not found");
		return;
	}
	commit = lookup_commit_reference(sha1);
	if (!commit || parse_commit(commit)) {
		cgit_print_error_page(404, "Not found", "Not found");
		return;
	}
	if (!path_items.match) {
		path_items.match = "";
		walk_tree_ctx.match_baselen = -1;
		print_dir(commit->tree->object.sha1, "", 0, "");
		walk_tree_ctx.match = 2;
	}
	else
		walk_tree_ctx.match_baselen = basedir_len(path_items.match);
	read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
	if (!walk_tree_ctx.match)
		cgit_print_error_page(404, "Not found", "Not found");
	else if (walk_tree_ctx.match == 2)
		print_dir_tail();
}
Example #19
0
File: ls.c Project: otto-peep/ft_ls
void	ls_rec2(t_mem *s, t_fil **list, char *path)
{
	if (s->only == 1)
	{
		if (ft_extract(list, s->oldpath) == 0)
		{
			ls_rec(s, s->oldpath);
			return ;
		}
	}
	if (s->r == 1)
		flag_r(list);
	print_dir(*list, s, path, s->only);
	if (s->only == 1)
	{
		s->only = 0;
		return ;
	}
	if (s->rec == 1)
		parse_for_rec(s, *list);
}
Example #20
0
 * produce_files() 测试程序。
 */
void produce_files_test(void)
{
	char ascfile[30] = "/readelf_test.txt";/* 文本文件名--add_data目录 */
	char buff[512+1] = {0};			/* 512+1 */
	FILEDESC desc;
	int count = 0, size = 0;
	unsigned short oldfs;

	print_dir("/");

	/* 读取生成的文件数据并打印 */
	oldfs = set_fs_kernel();
	if(-1 == (desc=sys_open(ascfile, O_RW))) {
		set_fs(oldfs);
		k_printf("produce_files_test: Open file failed!");
		return;
	}
	set_fs(oldfs);
	/* 最多只读取一块数据,测试嘛 :-) */
	oldfs = set_fs_kernel();
	if(-1 == (count=sys_read(desc, buff, sizeof(buff)-1))) {
		set_fs(oldfs);
		k_printf("produce_files_test: Read file failed!");
		return;
	}
	set_fs(oldfs);
	buff[count] = 0;
	if(-1 == (size=sys_lseek(desc, 0, SEEK_END))) {
		k_printf("produce_files_test: Lseek file failed!");
		return;
	}
	if(-1 == sys_close(desc)) {
		k_printf("produce_files_test: Close file failed!");
		return;
	}

	_k_printf("File-size is: %d bytes.\n", size);
Example #21
0
File: ui-plain.c Project: ifzz/cgit
static int walk_tree(const unsigned char *sha1, struct strbuf *base,
		const char *pathname, unsigned mode, int stage, void *cbdata)
{
	struct walk_tree_context *walk_tree_ctx = cbdata;

	if (base->len == walk_tree_ctx->match_baselen) {
		if (S_ISREG(mode)) {
			if (print_object(sha1, pathname))
				walk_tree_ctx->match = 1;
		} else if (S_ISDIR(mode)) {
			print_dir(sha1, base->buf, base->len, pathname);
			walk_tree_ctx->match = 2;
			return READ_TREE_RECURSIVE;
		}
	} else if (base->len > walk_tree_ctx->match_baselen) {
		print_dir_entry(sha1, base->buf, base->len, pathname, mode);
		walk_tree_ctx->match = 2;
	} else if (S_ISDIR(mode)) {
		return READ_TREE_RECURSIVE;
	}

	return 0;
}
Example #22
0
int face(int argc, char ** argv)
{

	
   	int i, j=0, k, num=0;
	char path[PATH_MAX+1];
	char param[32];            //保存命令行参数,目标文件和目录名不在此列
	int flag_param=PARAM_NONE;  //参数种类,即是否有-l和-a存在
	struct stat buf;
	int time=0;
	int file=0;
	int sT_INO=0;
    
	for(i=1; i<argc; i++){
		if(argv[i][0]=='-'){
			for(k=1; k<strlen(argv[i]); k++, j++){
				param[j]=argv[i][k];  //获取-后面的参数保存到param中
			}

			num++;                    //保存-的个数
		}
	}

	
	//只支持参数a和l如果有其他参数就报错
	for(i=0; i<j; i++){
		if(param[i]=='a'){
			flag_param |= PARAM_A;
			continue;
		}else if(param[i]=='l'){
			file=1;
			flag_param |= PARAM_L;
			continue;

		}else if(param[i]=='i'){
			sT_INO=1;
			continue;
		}else if(param[i]=='t'){
			time=1;
          continue;
		}
		else if(param[i]=='r'){
			file=2;
		}else if(param[i]=='R'){
			print_dir("./\0");
			return 0;
		}
		else{
			printf("my_ls:invalid optio -%c\n", param[1]);
			exit(1);
		}
	}

	param[j]='\0';
	//如果没有输入文件名或目录就显示当前目录
	if( argc==2){
		strcpy(path, "./");
		path[2]='\0';
		display_dir(flag_param, path,time, file, sT_INO );

		return 0;
	}
	i=1;
	do{//如果不是目标文件或目录,解析下一个命令参数
		if(argv[i][0]=='-'){
			i++;
			continue;
		}else{
			strcpy(path, argv[i]);
			//如果目标文件或目录不存在,则报错并退出程序
			if(  stat(path, &buf)==-1  ){
				my_err("stat",__LINE__);
			}
			if(S_ISDIR(buf.st_mode)){  //argv[i]是一个目录
				                       //如果目录的最后一个字符不是'/'就加上'/'
				if(  path[strlen(argv[i])-1] != '/'){
					path[strlen(argv[i])]='/';
					path[strlen(argv[i])+1]='\0';
				}
				else 

					path[ strlen(argv[i])] ='\0';
				display_dir(flag_param, path,time, file, sT_INO);
				i++;
			}else{   //argv[i]是一个文件
				display(flag_param, path,sT_INO);
				i++;
			}
		};

	}while(i<argc);

	return 0;
}
Example #23
0
}

void creat_lseek_read_write_open_close_file_test(void)
{
	int count = 0;
	char buff_in[100] = "Hello world!\nI'm writing a small OS.\nThanks.";
	char buff_out[100] = {0};
	char filename[50] = {0};
	unsigned short oldfs;

	/* 已创建了内核默认的最多磁盘存储文件数,则停止 */
	while((++count) < NR_D_INODE) {

		_k_printf("This is the content will be written: \n%s\n\n", buff_in);

		
		sprintf(filename, "/hello--%d.txt", count);
		_k_printf("%s\n", filename);
		/* 创建文件并写入 */
		oldfs = set_fs_kernel();
		FILEDESC desc = sys_creat(filename, FILE_FILE | FILE_RW);
		set_fs(oldfs);
		if(-1 == desc) {
			k_printf("creat_lseek_...: Create file failed!");
			return;
		}
		d_printf("Create file return.\n");
		if(-1 == sys_lseek(desc, 995920, SEEK_SET)) {
			k_printf("creat_lseek_...: Lseek file failed!");
			return;
		}
		d_printf("Lseek file return.\n");
		oldfs = set_fs_kernel();
		if(-1 == sys_write(desc, buff_in, 1 + strlen(buff_in))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Write file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Write file return.\n");
		if(-1 == sys_close(desc)) {
			k_printf("creat_lseek_...: Close file failed!");
			return;
		}
		d_printf("Close file return.\n");


		/* 打印根目录含有的文件 */
		print_dir("/");

		/* 打开之前创建的文件,读取 */
		oldfs = set_fs_kernel();
		if(-1 == (desc = sys_open(filename, O_RW))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Open file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Open file return.\n");
		if(-1 == sys_lseek(desc, 995920, SEEK_SET)) {
			k_printf("creat_lseek_...: Lseek file failed!");
			return;
		}
		d_printf("Lseek file return.\n");
		oldfs = set_fs_kernel();
		if(-1 == sys_read(desc, buff_out, 1 + strlen(buff_in))) {
			set_fs(oldfs);
			k_printf("creat_lseek_...: Read file failed!");
			return;
		}
		set_fs(oldfs);
		d_printf("Read file return.\n");
		if(-1 == sys_close(desc)) {
			k_printf("creat_lseek_...: Close file failed!");
			return;
		}
		d_printf("Close file return.\n");

		
		_k_printf("This is the content of READ file: \n%s\n\n", buff_out);
Example #24
0
void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms)
{
    static struct expanding_buffer ebuf;
    char **e;
    char newpath[STRING_MAX], *val;
    int newpath_len;
    int i;
    unsigned int num, len;

    e = xs_directory(h, XBT_NULL, path, &num);
    if (e == NULL)
        err(1, "xs_directory (%s)", path);

    for (i = 0; i<num; i++) {
        char buf[MAX_STRLEN(unsigned int)+1];
        struct xs_permissions *perms;
        unsigned int nperms;
        int linewid;

        /* Compose fullpath */
        newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path, 
                path[strlen(path)-1] == '/' ? "" : "/", 
                e[i]);

        /* Print indent and path basename */
        linewid = 0;
        if (show_whole_path) {
            fputs(newpath, stdout);
        } else {
            for (; linewid<cur_depth; linewid++) {
                putchar(' ');
            }
            linewid += printf("%.*s",
                              (int) (max_width - TAG_LEN - linewid), e[i]);
        }

	/* Fetch value */
        if ( newpath_len < sizeof(newpath) ) {
            val = xs_read(h, XBT_NULL, newpath, &len);
        }
        else {
            /* Path was truncated and thus invalid */
            val = NULL;
            len = 0;
        }

        /* Print value */
        if (val == NULL) {
            printf(":\n");
        }
        else {
            if (max_width < (linewid + len + TAG_LEN)) {
                printf(" = \"%.*s\\...\"",
                       (int)(max_width - TAG_LEN - linewid),
		       sanitise_value(&ebuf, val, len));
            }
            else {
                linewid += printf(" = \"%s\"",
				  sanitise_value(&ebuf, val, len));
                if (show_perms) {
                    putchar(' ');
                    for (linewid++;
                         linewid < MIN(desired_width, max_width);
                         linewid++)
                        putchar((linewid & 1)? '.' : ' ');
                }
            }
        }
        free(val);

        if (show_perms) {
            perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
            if (perms == NULL) {
                warn("\ncould not access permissions for %s", e[i]);
            }
            else {
                int i;
                fputs("  (", stdout);
                for (i = 0; i < nperms; i++) {
                    if (i)
                        putchar(',');
                    xs_perm_to_string(perms+i, buf, sizeof(buf));
                    fputs(buf, stdout);
                }
                putchar(')');
            }
        }

        putchar('\n');
            
        print_dir(h, newpath, cur_depth+1, show_perms); 
    }
    free(e);
}
Example #25
0
int gmx_rmsf(int argc,char *argv[])
{
  static char *desc[] = {
    "g_rmsf computes the root mean square fluctuation (RMSF, i.e. standard ",
    "deviation) of atomic positions ",
    "after (optionally) fitting to a reference frame.[PAR]",
    "With option [TT]-oq[tt] the RMSF values are converted to B-factor",
    "values, which are written to a pdb file with the coordinates, of the",
    "structure file, or of a pdb file when [TT]-q[tt] is specified.",
    "Option [TT]-ox[tt] writes the B-factors to a file with the average",
    "coordinates.[PAR]",
    "With the option [TT]-od[tt] the root mean square deviation with",
    "respect to the reference structure is calculated.[PAR]",
    "With the option [TT]aniso[tt] g_rmsf will compute anisotropic",
    "temperature factors and then it will also output average coordinates",
    "and a pdb file with ANISOU records (corresonding to the [TT]-oq[tt]",
    "or [TT]-ox[tt] option). Please note that the U values",
    "are orientation dependent, so before comparison with experimental data",
    "you should verify that you fit to the experimental coordinates.[PAR]",
    "When a pdb input file is passed to the program and the [TT]-aniso[tt]",
    "flag is set",
    "a correlation plot of the Uij will be created, if any anisotropic",
    "temperature factors are present in the pdb file.[PAR]",
    "With option [TT]-dir[tt] the average MSF (3x3) matrix is diagonalized.",
    "This shows the directions in which the atoms fluctuate the most and",
    "the least."
  };
  static bool bRes=FALSE,bAniso=FALSE,bdevX=FALSE,bFit=TRUE;
  t_pargs pargs[] = { 
    { "-res", FALSE, etBOOL, {&bRes},
      "Calculate averages for each residue" },
    { "-aniso",FALSE, etBOOL, {&bAniso},
      "Compute anisotropic termperature factors" },
    { "-fit", FALSE, etBOOL, {&bFit},
      "Do a least squares superposition before computing RMSF. Without this you must make sure that the reference structure and the trajectory match." }
  };
  int          step,nre,natom,natoms,i,g,m,teller=0;
  real         t,lambda,*w_rls,*w_rms;
  
  t_tpxheader  header;
  t_inputrec   ir;
  t_topology   top;
  int          ePBC;
  t_atoms      *pdbatoms,*refatoms;
  bool         bCont;

  matrix       box,pdbbox;
  rvec         *x,*pdbx,*xref;
  int          status,npdbatoms,res0;
  char         buf[256],*label;
  char         title[STRLEN];
  
  FILE         *fp;               /* the graphics file */
  char         *devfn,*dirfn;
  int          resnr;

  bool         bReadPDB;  
  atom_id      *index;
  int          isize;
  char         *grpnames;

  real         bfac,pdb_bfac,*Uaver;
  double       **U,*xav;
  atom_id      aid;
  rvec         *rmsd_x=NULL;
  real         *rmsf,invcount,totmass;
  int          d;
  real         count=0;
  rvec         xcm;

  char         *leg[2] = { "MD", "X-Ray" };

  t_filenm fnm[] = {
    { efTRX, "-f",  NULL,     ffREAD  },
    { efTPS, NULL,  NULL,     ffREAD  },
    { efNDX, NULL,  NULL,     ffOPTRD },
    { efPDB, "-q",  NULL,     ffOPTRD },
    { efPDB, "-oq", "bfac",   ffOPTWR },
    { efPDB, "-ox", "xaver",  ffOPTWR },
    { efXVG, "-o",  "rmsf",   ffWRITE },
    { efXVG, "-od", "rmsdev", ffOPTWR },
    { efXVG, "-oc", "correl", ffOPTWR },
    { efLOG, "-dir", "rmsf",  ffOPTWR }
  };
#define NFILE asize(fnm)
 
  CopyRight(stderr,argv[0]);
  parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_BE_NICE ,
		    NFILE,fnm,asize(pargs),pargs,asize(desc),desc,0,NULL);

  bReadPDB = ftp2bSet(efPDB,NFILE,fnm);
  devfn    = opt2fn_null("-od",NFILE,fnm);
  dirfn    = opt2fn_null("-dir",NFILE,fnm);

  read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&xref,NULL,box,TRUE);
  snew(w_rls,top.atoms.nr);

  fprintf(stderr,"Select group(s) for root mean square calculation\n");
  get_index(&top.atoms,ftp2fn_null(efNDX,NFILE,fnm),1,&isize,&index,&grpnames);

  /* Set the weight */
  for(i=0; i<isize; i++) 
    w_rls[index[i]]=top.atoms.atom[index[i]].m;

  /* Malloc the rmsf arrays */
  snew(xav,isize*DIM);
  snew(U,isize);
  for(i=0; i<isize; i++)
    snew(U[i],DIM*DIM);
  snew(rmsf,isize);
  if (devfn)
    snew(rmsd_x, isize);
  
  if (bReadPDB) {
    get_stx_coordnum(opt2fn("-q",NFILE,fnm),&npdbatoms);
    snew(pdbatoms,1);
    snew(refatoms,1);
    init_t_atoms(pdbatoms,npdbatoms,TRUE);
    init_t_atoms(refatoms,npdbatoms,TRUE);
    snew(pdbx,npdbatoms);
    /* Read coordinates twice */
    read_stx_conf(opt2fn("-q",NFILE,fnm),title,pdbatoms,pdbx,NULL,NULL,pdbbox);
    read_stx_conf(opt2fn("-q",NFILE,fnm),title,refatoms,pdbx,NULL,NULL,pdbbox);
  } else {
    pdbatoms  = &top.atoms;
    refatoms  = &top.atoms;
    pdbx      = xref;
    npdbatoms = pdbatoms->nr;
    snew(pdbatoms->pdbinfo,npdbatoms);
    copy_mat(box,pdbbox);
  }
  
  if (bFit)
    sub_xcm(xref,isize,index,top.atoms.atom,xcm,FALSE);
  
  natom = read_first_x(&status,ftp2fn(efTRX,NFILE,fnm),&t,&x,box);
    
  /* Now read the trj again to compute fluctuations */
  teller = 0;
  do {
    if (bFit) {
      /* Remove periodic boundary */
      rm_pbc(&(top.idef),ePBC,natom,box,x,x);
      
      /* Set center of mass to zero */
      sub_xcm(x,isize,index,top.atoms.atom,xcm,FALSE);
      
      /* Fit to reference structure */
      do_fit(natom,w_rls,xref,x);
    }
     
    /* Calculate Anisotropic U Tensor */  
    for(i=0; i<isize; i++) {
      aid = index[i];
      for(d=0; d<DIM; d++) {
	xav[i*DIM + d] += x[aid][d];
	for(m=0; m<DIM; m++)
	  U[i][d*DIM + m] += x[aid][d]*x[aid][m];
      }
    }
    
    if (devfn) {
      /* Calculate RMS Deviation */
      for(i=0;(i<isize);i++) {
	aid = index[i];
	for(d=0;(d<DIM);d++) {
	  rmsd_x[i][d] += sqr(x[aid][d]-xref[aid][d]);
	}
      }
    } 
    count += 1.0;
    teller++;
  } while(read_next_x(status,&t,natom,x,box));
  close_trj(status);
  
  invcount = 1.0/count;
  snew(Uaver,DIM*DIM);
  totmass = 0;
  for(i=0; i<isize; i++) {
    for(d=0; d<DIM; d++)
      xav[i*DIM + d] *= invcount;
    for(d=0; d<DIM; d++)
      for(m=0; m<DIM; m++) {
	U[i][d*DIM + m] = U[i][d*DIM + m]*invcount 
	  - xav[i*DIM + d]*xav[i*DIM + m];
	Uaver[3*d+m] += top.atoms.atom[index[i]].m*U[i][d*DIM + m];
      }
    totmass += top.atoms.atom[index[i]].m;
  }
  for(d=0; d<DIM*DIM; d++)
    Uaver[d] /= totmass;

  if (bAniso) {
    for(i=0; i<isize; i++) {
      aid = index[i];
      pdbatoms->pdbinfo[aid].bAnisotropic = TRUE;
      pdbatoms->pdbinfo[aid].uij[U11] = 1e6*U[i][XX*DIM + XX];
      pdbatoms->pdbinfo[aid].uij[U22] = 1e6*U[i][YY*DIM + YY];
      pdbatoms->pdbinfo[aid].uij[U33] = 1e6*U[i][ZZ*DIM + ZZ];
      pdbatoms->pdbinfo[aid].uij[U12] = 1e6*U[i][XX*DIM + YY];
      pdbatoms->pdbinfo[aid].uij[U13] = 1e6*U[i][XX*DIM + ZZ];
      pdbatoms->pdbinfo[aid].uij[U23] = 1e6*U[i][YY*DIM + ZZ];
    }
  }
  if (bRes) {
    average_residues(rmsf,isize,index,w_rls,&top.atoms);
    label = "Residue";
  } else
    label = "Atom";

  for(i=0; i<isize; i++)
    rmsf[i] = U[i][XX*DIM + XX] + U[i][YY*DIM + YY] + U[i][ZZ*DIM + ZZ];
  
  if (dirfn) {
    fprintf(stdout,"\n");
    print_dir(stdout,Uaver);
    fp = ffopen(dirfn,"w");
    print_dir(fp,Uaver);
    fclose(fp);
  }

  for(i=0; i<isize; i++)
    sfree(U[i]);
  sfree(U);

  /* Write RMSF output */
  if (bReadPDB) {
    bfac = 8.0*M_PI*M_PI/3.0*100;
    fp   = xvgropen(ftp2fn(efXVG,NFILE,fnm),"B-Factors",
		    label,"(A\\b\\S\\So\\N\\S2\\N)");
    xvgr_legend(fp,2,leg);
    for(i=0;(i<isize);i++) {
      if (!bRes || i+1==isize ||
	  top.atoms.atom[index[i]].resnr!=top.atoms.atom[index[i+1]].resnr) {
	resnr    = top.atoms.atom[index[i]].resnr;
	pdb_bfac = find_pdb_bfac(pdbatoms,*(top.atoms.resname[resnr]),resnr,
				 *(top.atoms.atomname[index[i]]));
	
	fprintf(fp,"%5d  %10.5f  %10.5f\n",
		bRes ? top.atoms.atom[index[i]].resnr+1 : i+1,rmsf[i]*bfac,
		pdb_bfac);
      }
    }
    fclose(fp);
  } else {
    fp = xvgropen(ftp2fn(efXVG,NFILE,fnm),"RMS fluctuation",label,"(nm)");
    for(i=0; i<isize; i++)
      if (!bRes || i+1==isize ||
	  top.atoms.atom[index[i]].resnr!=top.atoms.atom[index[i+1]].resnr)
	fprintf(fp,"%5d %8.4f\n",
		bRes ? top.atoms.atom[index[i]].resnr+1 : i+1,sqrt(rmsf[i]));
    fclose(fp);
  }
  
  for(i=0; i<isize; i++)
    pdbatoms->pdbinfo[index[i]].bfac = 800*M_PI*M_PI/3.0*rmsf[i];

  if (devfn) {
    for(i=0; i<isize; i++)
      rmsf[i] = (rmsd_x[i][XX]+rmsd_x[i][YY]+rmsd_x[i][ZZ])/count;
    if (bRes)
      average_residues(rmsf,isize,index,w_rls,&top.atoms); 
    /* Write RMSD output */
    fp = xvgropen(devfn,"RMS Deviation",label,"(nm)");
    for(i=0; i<isize; i++)
      if (!bRes || i+1==isize ||
	  top.atoms.atom[index[i]].resnr!=top.atoms.atom[index[i+1]].resnr)
	fprintf(fp,"%5d %8.4f\n",
		bRes ? top.atoms.atom[index[i]].resnr+1 : i+1,sqrt(rmsf[i]));
    fclose(fp);
  }

  if (opt2bSet("-oq",NFILE,fnm)) {
    /* Write a pdb file with B-factors and optionally anisou records */
    for(i=0; i<isize; i++)
      rvec_inc(xref[index[i]],xcm);
    write_sto_conf_indexed(opt2fn("-oq",NFILE,fnm),title,pdbatoms,pdbx,
			   NULL,ePBC,pdbbox,isize,index);
  }
  if (opt2bSet("-ox",NFILE,fnm)) {
    /* Misuse xref as a temporary array */
    for(i=0; i<isize; i++)
      for(d=0; d<DIM; d++)
	xref[index[i]][d] = xcm[d] + xav[i*DIM + d];
    /* Write a pdb file with B-factors and optionally anisou records */
    write_sto_conf_indexed(opt2fn("-ox",NFILE,fnm),title,pdbatoms,xref,NULL,
			   ePBC,pdbbox,isize,index);
  }
  if (bAniso) { 
    correlate_aniso(opt2fn("-oc",NFILE,fnm),refatoms,pdbatoms);
    do_view(opt2fn("-oc",NFILE,fnm),"-nxy");
  }
  do_view(opt2fn("-o",NFILE,fnm),"-nxy");
  if (devfn)
    do_view(opt2fn("-od",NFILE,fnm),"-nxy");
    
  thanx(stderr);
  
  return 0;
}
Example #26
0
int gmx_rmsf(int argc, char *argv[])
{
    const char       *desc[] = {
        "[THISMODULE] computes the root mean square fluctuation (RMSF, i.e. standard ",
        "deviation) of atomic positions in the trajectory (supplied with [TT]-f[tt])",
        "after (optionally) fitting to a reference frame (supplied with [TT]-s[tt]).[PAR]",
        "With option [TT]-oq[tt] the RMSF values are converted to B-factor",
        "values, which are written to a [REF].pdb[ref] file with the coordinates, of the",
        "structure file, or of a [REF].pdb[ref] file when [TT]-q[tt] is specified.",
        "Option [TT]-ox[tt] writes the B-factors to a file with the average",
        "coordinates.[PAR]",
        "With the option [TT]-od[tt] the root mean square deviation with",
        "respect to the reference structure is calculated.[PAR]",
        "With the option [TT]-aniso[tt], [THISMODULE] will compute anisotropic",
        "temperature factors and then it will also output average coordinates",
        "and a [REF].pdb[ref] file with ANISOU records (corresonding to the [TT]-oq[tt]",
        "or [TT]-ox[tt] option). Please note that the U values",
        "are orientation-dependent, so before comparison with experimental data",
        "you should verify that you fit to the experimental coordinates.[PAR]",
        "When a [REF].pdb[ref] input file is passed to the program and the [TT]-aniso[tt]",
        "flag is set",
        "a correlation plot of the Uij will be created, if any anisotropic",
        "temperature factors are present in the [REF].pdb[ref] file.[PAR]",
        "With option [TT]-dir[tt] the average MSF (3x3) matrix is diagonalized.",
        "This shows the directions in which the atoms fluctuate the most and",
        "the least."
    };
    static gmx_bool   bRes    = FALSE, bAniso = FALSE, bFit = TRUE;
    t_pargs           pargs[] = {
        { "-res", FALSE, etBOOL, {&bRes},
          "Calculate averages for each residue" },
        { "-aniso", FALSE, etBOOL, {&bAniso},
          "Compute anisotropic termperature factors" },
        { "-fit", FALSE, etBOOL, {&bFit},
          "Do a least squares superposition before computing RMSF. Without this you must make sure that the reference structure and the trajectory match." }
    };
    int               natom;
    int               i, m, teller = 0;
    real              t, *w_rls;

    t_topology        top;
    int               ePBC;
    t_atoms          *pdbatoms, *refatoms;

    matrix            box, pdbbox;
    rvec             *x, *pdbx, *xref;
    t_trxstatus      *status;
    const char       *label;

    FILE             *fp;         /* the graphics file */
    const char       *devfn, *dirfn;
    int               resind;

    gmx_bool          bReadPDB;
    int              *index;
    int               isize;
    char             *grpnames;

    real              bfac, pdb_bfac, *Uaver;
    double          **U, *xav;
    int               aid;
    rvec             *rmsd_x = nullptr;
    double           *rmsf, invcount, totmass;
    int               d;
    real              count = 0;
    rvec              xcm;
    gmx_rmpbc_t       gpbc = nullptr;

    gmx_output_env_t *oenv;

    const char       *leg[2] = { "MD", "X-Ray" };

    t_filenm          fnm[] = {
        { efTRX, "-f",  nullptr,     ffREAD  },
        { efTPS, nullptr,  nullptr,     ffREAD  },
        { efNDX, nullptr,  nullptr,     ffOPTRD },
        { efPDB, "-q",  nullptr,     ffOPTRD },
        { efPDB, "-oq", "bfac",   ffOPTWR },
        { efPDB, "-ox", "xaver",  ffOPTWR },
        { efXVG, "-o",  "rmsf",   ffWRITE },
        { efXVG, "-od", "rmsdev", ffOPTWR },
        { efXVG, "-oc", "correl", ffOPTWR },
        { efLOG, "-dir", "rmsf",  ffOPTWR }
    };
#define NFILE asize(fnm)

    if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_CAN_VIEW,
                           NFILE, fnm, asize(pargs), pargs, asize(desc), desc, 0, nullptr,
                           &oenv))
    {
        return 0;
    }

    bReadPDB = ftp2bSet(efPDB, NFILE, fnm);
    devfn    = opt2fn_null("-od", NFILE, fnm);
    dirfn    = opt2fn_null("-dir", NFILE, fnm);

    read_tps_conf(ftp2fn(efTPS, NFILE, fnm), &top, &ePBC, &xref, nullptr, box, TRUE);
    const char *title = *top.name;
    snew(w_rls, top.atoms.nr);

    fprintf(stderr, "Select group(s) for root mean square calculation\n");
    get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &isize, &index, &grpnames);

    /* Set the weight */
    for (i = 0; i < isize; i++)
    {
        w_rls[index[i]] = top.atoms.atom[index[i]].m;
    }

    /* Malloc the rmsf arrays */
    snew(xav, isize*DIM);
    snew(U, isize);
    for (i = 0; i < isize; i++)
    {
        snew(U[i], DIM*DIM);
    }
    snew(rmsf, isize);
    if (devfn)
    {
        snew(rmsd_x, isize);
    }

    if (bReadPDB)
    {
        t_topology *top_pdb;
        snew(top_pdb, 1);
        /* Read coordinates twice */
        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, nullptr, nullptr, nullptr, pdbbox, FALSE);
        snew(pdbatoms, 1);
        *pdbatoms = top_pdb->atoms;
        read_tps_conf(opt2fn("-q", NFILE, fnm), top_pdb, nullptr, &pdbx, nullptr, pdbbox, FALSE);
        /* TODO Should this assert that top_pdb->atoms.nr == top.atoms.nr?
         * See discussion at https://gerrit.gromacs.org/#/c/6430/1 */
        title = *top_pdb->name;
        snew(refatoms, 1);
        *refatoms = top_pdb->atoms;
        sfree(top_pdb);
    }
    else
    {
        pdbatoms  = &top.atoms;
        refatoms  = &top.atoms;
        pdbx      = xref;
        snew(pdbatoms->pdbinfo, pdbatoms->nr);
        pdbatoms->havePdbInfo = TRUE;
        copy_mat(box, pdbbox);
    }

    if (bFit)
    {
        sub_xcm(xref, isize, index, top.atoms.atom, xcm, FALSE);
    }

    natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);

    if (bFit)
    {
        gpbc = gmx_rmpbc_init(&top.idef, ePBC, natom);
    }

    /* Now read the trj again to compute fluctuations */
    teller = 0;
    do
    {
        if (bFit)
        {
            /* Remove periodic boundary */
            gmx_rmpbc(gpbc, natom, box, x);

            /* Set center of mass to zero */
            sub_xcm(x, isize, index, top.atoms.atom, xcm, FALSE);

            /* Fit to reference structure */
            do_fit(natom, w_rls, xref, x);
        }

        /* Calculate Anisotropic U Tensor */
        for (i = 0; i < isize; i++)
        {
            aid = index[i];
            for (d = 0; d < DIM; d++)
            {
                xav[i*DIM + d] += x[aid][d];
                for (m = 0; m < DIM; m++)
                {
                    U[i][d*DIM + m] += x[aid][d]*x[aid][m];
                }
            }
        }

        if (devfn)
        {
            /* Calculate RMS Deviation */
            for (i = 0; (i < isize); i++)
            {
                aid = index[i];
                for (d = 0; (d < DIM); d++)
                {
                    rmsd_x[i][d] += gmx::square(x[aid][d]-xref[aid][d]);
                }
            }
        }
        count += 1.0;
        teller++;
    }
    while (read_next_x(oenv, status, &t, x, box));
    close_trx(status);

    if (bFit)
    {
        gmx_rmpbc_done(gpbc);
    }


    invcount = 1.0/count;
    snew(Uaver, DIM*DIM);
    totmass = 0;
    for (i = 0; i < isize; i++)
    {
        for (d = 0; d < DIM; d++)
        {
            xav[i*DIM + d] *= invcount;
        }
        for (d = 0; d < DIM; d++)
        {
            for (m = 0; m < DIM; m++)
            {
                U[i][d*DIM + m] = U[i][d*DIM + m]*invcount
                    - xav[i*DIM + d]*xav[i*DIM + m];
                Uaver[3*d+m] += top.atoms.atom[index[i]].m*U[i][d*DIM + m];
            }
        }
        totmass += top.atoms.atom[index[i]].m;
    }
    for (d = 0; d < DIM*DIM; d++)
    {
        Uaver[d] /= totmass;
    }

    if (bRes)
    {
        for (d = 0; d < DIM*DIM; d++)
        {
            average_residues(nullptr, U, d, isize, index, w_rls, &top.atoms);
        }
    }

    if (bAniso)
    {
        for (i = 0; i < isize; i++)
        {
            aid = index[i];
            pdbatoms->pdbinfo[aid].bAnisotropic = TRUE;
            pdbatoms->pdbinfo[aid].uij[U11]     = static_cast<int>(1e6*U[i][XX*DIM + XX]);
            pdbatoms->pdbinfo[aid].uij[U22]     = static_cast<int>(1e6*U[i][YY*DIM + YY]);
            pdbatoms->pdbinfo[aid].uij[U33]     = static_cast<int>(1e6*U[i][ZZ*DIM + ZZ]);
            pdbatoms->pdbinfo[aid].uij[U12]     = static_cast<int>(1e6*U[i][XX*DIM + YY]);
            pdbatoms->pdbinfo[aid].uij[U13]     = static_cast<int>(1e6*U[i][XX*DIM + ZZ]);
            pdbatoms->pdbinfo[aid].uij[U23]     = static_cast<int>(1e6*U[i][YY*DIM + ZZ]);
        }
    }
    if (bRes)
    {
        label = "Residue";
    }
    else
    {
        label = "Atom";
    }

    for (i = 0; i < isize; i++)
    {
        rmsf[i] = U[i][XX*DIM + XX] + U[i][YY*DIM + YY] + U[i][ZZ*DIM + ZZ];
    }

    if (dirfn)
    {
        fprintf(stdout, "\n");
        print_dir(stdout, Uaver);
        fp = gmx_ffopen(dirfn, "w");
        print_dir(fp, Uaver);
        gmx_ffclose(fp);
    }

    for (i = 0; i < isize; i++)
    {
        sfree(U[i]);
    }
    sfree(U);

    /* Write RMSF output */
    if (bReadPDB)
    {
        bfac = 8.0*M_PI*M_PI/3.0*100;
        fp   = xvgropen(ftp2fn(efXVG, NFILE, fnm), "B-Factors",
                        label, "(A\\b\\S\\So\\N\\S2\\N)", oenv);
        xvgr_legend(fp, 2, leg, oenv);
        for (i = 0; (i < isize); i++)
        {
            if (!bRes || i+1 == isize ||
                top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
            {
                resind    = top.atoms.atom[index[i]].resind;
                pdb_bfac  = find_pdb_bfac(pdbatoms, &top.atoms.resinfo[resind],
                                          *(top.atoms.atomname[index[i]]));

                fprintf(fp, "%5d  %10.5f  %10.5f\n",
                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, rmsf[i]*bfac,
                        pdb_bfac);
            }
        }
        xvgrclose(fp);
    }
    else
    {
        fp = xvgropen(ftp2fn(efXVG, NFILE, fnm), "RMS fluctuation", label, "(nm)", oenv);
        for (i = 0; i < isize; i++)
        {
            if (!bRes || i+1 == isize ||
                top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
            {
                fprintf(fp, "%5d %8.4f\n",
                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
            }
        }
        xvgrclose(fp);
    }

    for (i = 0; i < isize; i++)
    {
        pdbatoms->pdbinfo[index[i]].bfac = 800*M_PI*M_PI/3.0*rmsf[i];
    }

    if (devfn)
    {
        for (i = 0; i < isize; i++)
        {
            rmsf[i] = (rmsd_x[i][XX]+rmsd_x[i][YY]+rmsd_x[i][ZZ])/count;
        }
        if (bRes)
        {
            average_residues(rmsf, nullptr, 0, isize, index, w_rls, &top.atoms);
        }
        /* Write RMSD output */
        fp = xvgropen(devfn, "RMS Deviation", label, "(nm)", oenv);
        for (i = 0; i < isize; i++)
        {
            if (!bRes || i+1 == isize ||
                top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
            {
                fprintf(fp, "%5d %8.4f\n",
                        bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
            }
        }
        xvgrclose(fp);
    }

    if (opt2bSet("-oq", NFILE, fnm))
    {
        /* Write a .pdb file with B-factors and optionally anisou records */
        for (i = 0; i < isize; i++)
        {
            rvec_inc(pdbx[index[i]], xcm);
        }
        write_sto_conf_indexed(opt2fn("-oq", NFILE, fnm), title, pdbatoms, pdbx,
                               nullptr, ePBC, pdbbox, isize, index);
    }
    if (opt2bSet("-ox", NFILE, fnm))
    {
        rvec *bFactorX;
        snew(bFactorX, top.atoms.nr);
        for (i = 0; i < isize; i++)
        {
            for (d = 0; d < DIM; d++)
            {
                bFactorX[index[i]][d] = xcm[d] + xav[i*DIM + d];
            }
        }
        /* Write a .pdb file with B-factors and optionally anisou records */
        write_sto_conf_indexed(opt2fn("-ox", NFILE, fnm), title, pdbatoms, bFactorX, nullptr,
                               ePBC, pdbbox, isize, index);
        sfree(bFactorX);
    }
    if (bAniso)
    {
        correlate_aniso(opt2fn("-oc", NFILE, fnm), refatoms, pdbatoms, oenv);
        do_view(oenv, opt2fn("-oc", NFILE, fnm), "-nxy");
    }
    do_view(oenv, opt2fn("-o", NFILE, fnm), "-nxy");
    if (devfn)
    {
        do_view(oenv, opt2fn("-od", NFILE, fnm), "-nxy");
    }

    return 0;
}
Example #27
0
void pick_and_load_rom()
{
	int cont = 0;
	int cdiv = 3;
	file_descr_t *entries,*top_of_screen,*current;

	entries = fat_open_root_directory();
	if (entries==0) {
		console_puts("Error reading root directory");
		return;
	}

	top_of_screen = entries;
	current = entries;
	for (;;) {
		int key;
		print_dir(top_of_screen,current);
		//key = wait_key();
		key = read_joypad1();
		//switch (key) {
		//case JOY_UP:
		cont++;
		if (cont>20)
		   cdiv= 3;
		if ((key & JOY_UP) && (cont%cdiv==0)) {
			if (current!=entries) {
				current--;
				cdiv = 8;
				if (current<top_of_screen) {
					top_of_screen = current;
				}
			}
		cont = 0;
		}	//break;
		if ((key & JOY_DOWN) && (cont%cdiv==0)) {
		//case JOY_DOWN:
			if (current[1].type!=0) {
				current++;
				cdiv = 8;
				if ((current-top_of_screen)>19) {
					top_of_screen++;
				}
			}
		cont = 0;
		}	//break;
		//case JOY_LEFT:
		if ((key & JOY_LEFT) && (cont%(cdiv)==0)) {
			if ((current!=entries) && current>(entries+4)) {
				current = current-5;
				cdiv = 8;
				if (current<top_of_screen) {
					top_of_screen = current;
				}
			} else {
			   current = entries;
			   top_of_screen = current;
			}
		cont = 0;
		}	//break;
		//case JOY_RIGHT:
		if ((key & JOY_RIGHT) && (cont%(cdiv)==0)) {
			if (current[5].type!=0 && current[4].type!=0 && current[3].type!=0 && current[2].type!=0 && current[1].type!=0) {
				current = current + 5;
				cdiv = 8;
				if ((current-top_of_screen)>19) {
					top_of_screen = top_of_screen + 5;
				}
			}
			else {
				if (current[1].type == 0)			
					current = current;
				else if (current[2].type == 0)			
					current = current+1;
				else if (current[3].type == 0)			
					current = current+2;
				else if (current[4].type == 0)			
					current = current+3;
				else if (current[5].type == 0)			
					current = current+4;
				//top_of_screen = current;
			cdiv = 8;
			     }
		cont = 0;
		}	//break;
		//case JOY_FIREA:
		//case JOY_FIREB:
		if ((key & (JOY_FIREA | JOY_FIREB)) && (cont%cdiv==0)) {
			if ((current->type&0x10)==0) {
				entries = fat_open_directory(current->cluster);
				if (entries==0) {
					console_puts("Error while reading directory");
					return;
				}
				top_of_screen = entries;
				current = entries;
				cdiv = 12;
			} else {
				load_rom(current);
				start_rom();
				return;
			}
		cont = 0;
		}	//break;
		//}
	}
}