static void addrtype_print_v1(const void *ip, const struct xt_entry_match *match,
                              int numeric)
{
    const struct ipt_addrtype_info_v1 *info =
        (struct ipt_addrtype_info_v1 *) match->data;

    printf(" ADDRTYPE match");
    if (info->source) {
        printf(" src-type ");
        if (info->flags & IPT_ADDRTYPE_INVERT_SOURCE)
            printf("!");
        print_types(info->source);
    }
    if (info->dest) {
        printf(" dst-type ");
        if (info->flags & IPT_ADDRTYPE_INVERT_DEST)
            printf("!");
        print_types(info->dest);
    }
    if (info->flags & IPT_ADDRTYPE_LIMIT_IFACE_IN) {
        printf(" limit-in");
    }
    if (info->flags & IPT_ADDRTYPE_LIMIT_IFACE_OUT) {
        printf(" limit-out");
    }
}
示例#2
0
static void pkttype_help(void)
{
	printf(
"pkttype match options:\n"
"[!] --pkt-type packettype    match packet type\n");
	print_types();
}
示例#3
0
static void
dccp_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
	const struct xt_dccp_info *einfo =
		(const struct xt_dccp_info *)match->data;

	printf(" dccp");

	if (einfo->flags & XT_DCCP_SRC_PORTS) {
		print_ports("spt", einfo->spts[0], einfo->spts[1],
			einfo->invflags & XT_DCCP_SRC_PORTS,
			numeric);
	}

	if (einfo->flags & XT_DCCP_DEST_PORTS) {
		print_ports("dpt", einfo->dpts[0], einfo->dpts[1],
			einfo->invflags & XT_DCCP_DEST_PORTS,
			numeric);
	}

	if (einfo->flags & XT_DCCP_TYPE) {
		print_types(einfo->typemask,
			   einfo->invflags & XT_DCCP_TYPE,
			   numeric);
	}

	if (einfo->flags & XT_DCCP_OPTION) {
		print_option(einfo->option,
			     einfo->invflags & XT_DCCP_OPTION, numeric);
	}
}
static void addrtype_save_v0(const void *ip, const struct xt_entry_match *match)
{
	const struct xt_addrtype_info *info = (const void *)match->data;

	if (info->source) {
		if (info->invert_source)
			printf(" !");
		printf(" --src-type ");
		print_types(info->source);
	}
	if (info->dest) {
		if (info->invert_dest)
			printf(" !");
		printf(" --dst-type ");
		print_types(info->dest);
	}
}
static void addrtype_print_v0(const void *ip, const struct xt_entry_match *match,
                              int numeric)
{
	const struct xt_addrtype_info *info = (const void *)match->data;

	printf(" ADDRTYPE match");
	if (info->source) {
		printf(" src-type ");
		if (info->invert_source)
			printf("!");
		print_types(info->source);
	}
	if (info->dest) {
		printf(" dst-type");
		if (info->invert_dest)
			printf("!");
		print_types(info->dest);
	}
}
示例#6
0
static void save(const struct ipt_ip *ip, 
		const struct ipt_entry_match *match)
{
	const struct ipt_addrtype_info *info =
		(struct ipt_addrtype_info *) match->data;

	if (info->source) {
		printf("--src-type ");
		if (info->invert_source)
			printf("! ");
		print_types(info->source);
	}
	if (info->dest) {
		printf("--dst-type ");
		if (info->invert_dest)
			printf("! ");
		print_types(info->dest);
	}
}
static void addrtype_save_v1(const void *ip, const struct xt_entry_match *match)
{
	const struct xt_addrtype_info_v1 *info = (const void *)match->data;

	if (info->source) {
		if (info->flags & XT_ADDRTYPE_INVERT_SOURCE)
			printf(" !");
		printf(" --src-type ");
		print_types(info->source);
	}
	if (info->dest) {
		if (info->flags & XT_ADDRTYPE_INVERT_DEST)
			printf(" !");
		printf(" --dst-type ");
		print_types(info->dest);
	}
	if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN)
		printf(" --limit-iface-in");
	if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT)
		printf(" --limit-iface-out");
}
示例#8
0
文件: genheader.c 项目: Preetam/ponyc
bool genheader(compile_t* c)
{
  // Open a header file.
  const char* file_h = suffix_filename(c->opt->output, "", c->filename, ".h");
  FILE* fp = fopen(file_h, "wt");

  if(fp == NULL)
  {
    errorf(NULL, "couldn't write to %s", file_h);
    return false;
  }

  fprintf(fp,
    "#ifndef pony_%s_h\n"
    "#define pony_%s_h\n"
    "\n"
    "/* This is an auto-generated header file. Do not edit. */\n"
    "\n"
    "#include <stdint.h>\n"
    "#include <stdbool.h>\n"
    "\n"
    "#ifdef __cplusplus\n"
    "extern \"C\" {\n"
    "#endif\n"
    "\n"
    "#ifdef _MSC_VER\n"
    "typedef struct __int128_t { uint64_t low; int64_t high; } __int128_t;\n"
    "typedef struct __uint128_t { uint64_t low; uint64_t high; } "
      "__uint128_t;\n"
    "#endif\n"
    "\n",
    c->filename,
    c->filename
    );

  printbuf_t* buf = printbuf_new();
  print_types(c, fp, buf);
  fwrite(buf->m, 1, buf->offset, fp);
  printbuf_free(buf);

  fprintf(fp,
    "\n"
    "#ifdef __cplusplus\n"
    "}\n"
    "#endif\n"
    "\n"
    "#endif\n"
    );

  fclose(fp);
  return true;
}
示例#9
0
static void mh_print(const void *ip, const struct xt_entry_match *match,
                     int numeric)
{
	const struct ip6t_mh *mhinfo = (struct ip6t_mh *)match->data;

	printf(" mh");
	print_types(mhinfo->types[0], mhinfo->types[1],
		    mhinfo->invflags & IP6T_MH_INV_TYPE,
		    numeric);
	if (mhinfo->invflags & ~IP6T_MH_INV_MASK)
		printf(" Unknown invflags: 0x%X",
		       mhinfo->invflags & ~IP6T_MH_INV_MASK);
}
示例#10
0
static void
test_types(void)
{
	print_macros();
	print_types();
	test_config();
	test_types32();
#if SPH_64
	test_types64();
#else
	printf("warning: no 64-bit type defined\n");
#endif
}
示例#11
0
void *
tiz_os_get_type (const tiz_os_t * ap_os, const char * a_type_name)
{
  void * res = NULL;
  assert (ap_os);
  assert (ap_os->p_map);
  assert (a_type_name);
  res = tiz_map_find (ap_os->p_map, (OMX_PTR) a_type_name);
  TIZ_TRACE (ap_os->p_hdl, "Get type [%s]->[%p] - total types [%d]",
             a_type_name, res, tiz_map_size (ap_os->p_map));
  if (!res)
    {
      if (OMX_ErrorNone
          == register_additional_type ((tiz_os_t *) ap_os, a_type_name))
        {
          print_types (ap_os);
          res = tiz_map_find (ap_os->p_map, (OMX_PTR) a_type_name);
        }
    }
  assert (res);
  return res;
}
示例#12
0
/* Saves the union ipt_matchinfo in parsable form to stdout. */
static void
save(const struct ipt_ip *ip, 
     const struct ipt_entry_match *match)
{
	const struct ipt_dccp_info *einfo =
		(const struct ipt_dccp_info *)match->data;

	if (einfo->flags & IPT_DCCP_SRC_PORTS) {
		if (einfo->invflags & IPT_DCCP_SRC_PORTS)
			printf("! ");
		if (einfo->spts[0] != einfo->spts[1])
			printf("--sport %u:%u ", 
			       einfo->spts[0], einfo->spts[1]);
		else
			printf("--sport %u ", einfo->spts[0]);
	}

	if (einfo->flags & IPT_DCCP_DEST_PORTS) {
		if (einfo->invflags & IPT_DCCP_DEST_PORTS)
			printf("! ");
		if (einfo->dpts[0] != einfo->dpts[1])
			printf("--dport %u:%u ",
			       einfo->dpts[0], einfo->dpts[1]);
		else
			printf("--dport %u ", einfo->dpts[0]);
	}

	if (einfo->flags & IPT_DCCP_TYPE) {
		printf("--dccp-type ");
		print_types(einfo->typemask, einfo->invflags & IPT_DCCP_TYPE,0);
	}

	if (einfo->flags & IPT_DCCP_OPTION) {
		printf("--dccp-option %s%u ", 
			einfo->typemask & IPT_DCCP_OPTION ? "! " : "",
			einfo->option);
	}
}
int gmx_sgangle(int argc,char *argv[])
{
  static char *desc[] = {
    "Compute the angle and distance between two groups. ",
    "The groups are defined by a number of atoms given in an index file and",
    "may be two or three atoms in size.",
    "If -one is set, only one group should be specified in the index",
    "file and the angle between this group at time 0 and t will be computed.",
    "The angles calculated depend on the order in which the atoms are ",
    "given. Giving for instance 5 6 will rotate the vector 5-6 with ",
    "180 degrees compared to giving 6 5. [PAR]If three atoms are given, ",
    "the normal on the plane spanned by those three atoms will be",
    "calculated, using the formula  P1P2 x P1P3.",
    "The cos of the angle is calculated, using the inproduct of the two",
    "normalized vectors.[PAR]",
    "Here is what some of the file options do:[BR]",
    "-oa: Angle between the two groups specified in the index file. If a group contains three atoms the normal to the plane defined by those three atoms will be used. If a group contains two atoms, the vector defined by those two atoms will be used.[BR]",
    "-od: Distance between two groups. Distance is taken from the center of one group to the center of the other group.[BR]",
    "-od1: If one plane and one vector is given, the distances for each of the atoms from the center of the plane is given seperately.[BR]",
    "-od2: For two planes this option has no meaning."
  };

  char	    *fna, *fnd, *fnd1, *fnd2;		
  char      *grpname[2];          		/* name of the two groups */
  int       gnx[2];               		/* size of the two groups */
  t_topology *top;                		/* topology 		*/ 
  int       ePBC;
  atom_id   *index[2];            		
  static bool bOne = FALSE, bZ=FALSE;
  t_pargs pa[] = {
    { "-one", FALSE, etBOOL, {&bOne},
      "Only one group compute angle between vector at time zero and time t"},
    { "-z", FALSE, etBOOL, {&bZ},
        "Use the Z-axis as reference" }
  };
#define NPA asize(pa)

  t_filenm  fnm[] = {             		/* files for g_sgangle 	*/
    { efTRX, "-f", NULL,  ffREAD },    		/* trajectory file 	*/
    { efNDX, NULL, NULL,  ffREAD },    		/* index file 		*/
    { efTPX, NULL, NULL,  ffREAD },    		/* topology file 	*/
    { efXVG,"-oa","sg_angle",ffWRITE },		/* xvgr output file 	*/
    { efXVG, "-od","sg_dist",ffOPTWR }, 	/* xvgr output file 	*/
    { efXVG, "-od1", "sg_dist1",ffOPTWR }, 	/* xvgr output file 	*/
    { efXVG, "-od2", "sg_dist2",ffOPTWR } 	/* xvgr output file 	*/
  };

#define NFILE asize(fnm)

  CopyRight(stderr,argv[0]);
  parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE,
		    NFILE,fnm,NPA,pa,asize(desc),desc,0,NULL);
  

  top = read_top(ftp2fn(efTPX,NFILE,fnm),&ePBC);     /* read topology file */

  fna = opt2fn("-oa",NFILE,fnm);
  fnd = opt2fn_null("-od",NFILE,fnm);
  fnd1 = opt2fn_null("-od1",NFILE,fnm);
  fnd2 = opt2fn_null("-od2",NFILE,fnm);
  
  /* read index file. */
  if(bOne) {
    rd_index(ftp2fn(efNDX,NFILE,fnm),1,gnx,index,grpname); 
    print_types(index[0],gnx[0],grpname[0],    
 		index[0],gnx[0],grpname[0],top); 

    sgangle_plot_single(ftp2fn(efTRX,NFILE,fnm), fna, fnd, fnd1, fnd2,
			index[0],gnx[0],grpname[0],
			index[0],gnx[0],grpname[0],
			top,ePBC);
  }  else {
    rd_index(ftp2fn(efNDX,NFILE,fnm),bZ ? 1 : 2,gnx,index,grpname);
    if (!bZ)
      print_types(index[0],gnx[0],grpname[0],
		index[1],gnx[1],grpname[1],top); 
    else {
      gnx[1] = 0;
      grpname[1] = "Z-axis";
    }  
    sgangle_plot(ftp2fn(efTRX,NFILE,fnm), fna, fnd, fnd1, fnd2,
		 index[0],gnx[0],grpname[0],
		 index[1],gnx[1],grpname[1],
		 top,ePBC);
  }

  do_view(fna,"-nxy");     /* view xvgr file */
  do_view(fnd,"-nxy");     /* view xvgr file */
  do_view(fnd1,"-nxy");     /* view xvgr file */
  do_view(fnd2,"-nxy");     /* view xvgr file */

  thanx(stderr);
  return 0;
}
示例#14
0
文件: debug.c 项目: k0kubun/clannad
void
dump_node(int indent, Node *node)
{
  switch (node->kind) {
    case NODE_ROOT:
    case NODE_DECLN:
    case NODE_COMPOUND_STMT:
      indented_puts(indent, kind_label(node->kind));
      dump_vector(indent + 1, node->children);
      break;
    case NODE_PTR:
    case NODE_RETURN:
      indented_puts(indent, kind_label(node->kind));
      if (node->param) dump_node(indent + 1, node->param);
      break;
    case NODE_FUNC:
      indented_puts(indent, kind_label(node->kind));
      dump_nodes(indent + 1, 3, node->type, node->spec, node->stmts);
      break;
    case NODE_PARAM_DECL:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->type);
      if (node->spec) dump_node(indent + 1, node->spec);
      break;
    case NODE_FUNC_DECL:
    case NODE_VAR_DECL:
      indented_puts(indent, kind_label(node->kind));
      dump_nodes(indent + 1, 2, node->type, node->spec);
      break;
    case NODE_FUNCALL:
    case NODE_FUNC_SPEC:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->func);
      dump_vector(indent + 1, node->params);
      break;
    case NODE_TYPE:
      indented_printf(indent, "%s", kind_label(node->kind));
      print_types(node);
      printf("\n");
      if (node->fields) dump_vector(indent + 1, node->fields);
      break;
    case NODE_FIELD:
      indented_printf(indent, "%s\n", kind_label(node->kind));
      dump_node(indent + 1, node->field_type);
      dump_vector(indent + 1, node->fields);
      break;
    case NODE_IDENTIFIER:
    case NODE_SPEC:
    case NODE_STRING:
    case NODE_DEFINED:
      indented_printf(indent, "%s id=%s\n", kind_label(node->kind), node->id);
      break;
    case NODE_INTEGER:
      indented_printf(indent, "%s ival=%d\n", kind_label(node->kind), node->ival);
      break;
    case NODE_BINOP:
      indented_printf(indent, "%s '%c'\n", kind_label(node->kind), node->op);
      dump_node(indent + 1, node->lhs);
      dump_node(indent + 1, node->rhs);
      break;
    case NODE_UNARY:
      if ((int)node->op >= 256) {
        indented_printf(indent, "%s token %d\n", kind_label(node->kind), (int)node->op);
      } else {
        indented_printf(indent, "%s %c\n", kind_label(node->kind), node->op);
      }
      if (node->lhs) dump_node(indent + 1, node->lhs);
      if (node->rhs) dump_node(indent + 1, node->rhs);
      break;
    case NODE_IF:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->cond);
      dump_node(indent + 1, node->if_stmt);
      if (node->else_stmt) dump_node(indent + 1, node->else_stmt);
      break;
    case NODE_ARRAY_SPEC:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->lhs);
      dump_node(indent + 1, node->rhs);
      break;
    default:
      indented_puts(indent, kind_label(node->kind));
      break;
  }
}
示例#15
0
int gmx_order(int argc, char *argv[])
{
    const char        *desc[] = {
        "[THISMODULE] computes the order parameter per atom for carbon tails. For atom i the",
        "vector i-1, i+1 is used together with an axis. ",
        "The index file should contain only the groups to be used for calculations,",
        "with each group of equivalent carbons along the relevant acyl chain in its own",
        "group. There should not be any generic groups (like System, Protein) in the index",
        "file to avoid confusing the program (this is not relevant to tetrahedral order",
        "parameters however, which only work for water anyway).[PAR]",
        "[THISMODULE] can also give all",
        "diagonal elements of the order tensor and even calculate the deuterium",
        "order parameter Scd (default). If the option [TT]-szonly[tt] is given, only one",
        "order tensor component (specified by the [TT]-d[tt] option) is given and the",
        "order parameter per slice is calculated as well. If [TT]-szonly[tt] is not",
        "selected, all diagonal elements and the deuterium order parameter is",
        "given.[PAR]"
        "The tetrahedrality order parameters can be determined",
        "around an atom. Both angle an distance order parameters are calculated. See",
        "P.-L. Chau and A.J. Hardwick, Mol. Phys., 93, (1998), 511-518.",
        "for more details."
    };

    static int         nslices       = 1;     /* nr of slices defined       */
    static gmx_bool    bSzonly       = FALSE; /* True if only Sz is wanted  */
    static gmx_bool    bUnsat        = FALSE; /* True if carbons are unsat. */
    static const char *normal_axis[] = { NULL, "z", "x", "y", NULL };
    static gmx_bool    permolecule   = FALSE; /*compute on a per-molecule basis */
    static gmx_bool    radial        = FALSE; /*compute a radial membrane normal */
    static gmx_bool    distcalc      = FALSE; /*calculate distance from a reference group */
    t_pargs            pa[]          = {
        { "-d",      FALSE, etENUM, {normal_axis},
          "Direction of the normal on the membrane" },
        { "-sl",     FALSE, etINT, {&nslices},
          "Calculate order parameter as function of box length, dividing the box"
          " into this number of slices." },
        { "-szonly", FALSE, etBOOL, {&bSzonly},
          "Only give Sz element of order tensor. (axis can be specified with [TT]-d[tt])" },
        { "-unsat",  FALSE, etBOOL, {&bUnsat},
          "Calculate order parameters for unsaturated carbons. Note that this can"
          "not be mixed with normal order parameters." },
        { "-permolecule", FALSE, etBOOL, {&permolecule},
          "Compute per-molecule Scd order parameters" },
        { "-radial", FALSE, etBOOL, {&radial},
          "Compute a radial membrane normal" },
        { "-calcdist", FALSE, etBOOL, {&distcalc},
          "Compute distance from a reference" },
    };

    rvec              *order;                         /* order par. for each atom   */
    real             **slOrder;                       /* same, per slice            */
    real               slWidth = 0.0;                 /* width of a slice           */
    char             **grpname;                       /* groupnames                 */
    int                ngrps,                         /* nr. of groups              */
                       i,
                       axis = 0;                      /* normal axis                */
    t_topology       *top;                            /* topology         */
    int               ePBC;
    atom_id          *index,                          /* indices for a              */
    *a;                                               /* atom numbers in each group */
    t_blocka         *block;                          /* data from index file       */
    t_filenm          fnm[] = {                       /* files for g_order    */
        { efTRX, "-f", NULL,  ffREAD },               /* trajectory file              */
        { efNDX, "-n", NULL,  ffREAD },               /* index file           */
        { efNDX, "-nr", NULL,  ffREAD },              /* index for radial axis calculation	  */
        { efTPR, NULL, NULL,  ffREAD },               /* topology file                */
        { efXVG, "-o", "order", ffWRITE },            /* xvgr output file     */
        { efXVG, "-od", "deuter", ffWRITE },          /* xvgr output file           */
        { efPDB, "-ob", NULL, ffWRITE },              /* write Scd as B factors to PDB if permolecule           */
        { efXVG, "-os", "sliced", ffWRITE },          /* xvgr output file           */
        { efXVG, "-Sg", "sg-ang", ffOPTWR },          /* xvgr output file           */
        { efXVG, "-Sk", "sk-dist", ffOPTWR },         /* xvgr output file           */
        { efXVG, "-Sgsl", "sg-ang-slice", ffOPTWR },  /* xvgr output file           */
        { efXVG, "-Sksl", "sk-dist-slice", ffOPTWR }, /* xvgr output file           */
    };
    gmx_bool          bSliced = FALSE;                /* True if box is sliced      */
#define NFILE asize(fnm)
    real            **distvals = NULL;
    const char       *sgfnm, *skfnm, *ndxfnm, *tpsfnm, *trxfnm;
    gmx_output_env_t *oenv;

    if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME,
                           NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv))
    {
        return 0;
    }
    if (nslices < 1)
    {
        gmx_fatal(FARGS, "Can not have nslices < 1");
    }
    sgfnm  = opt2fn_null("-Sg", NFILE, fnm);
    skfnm  = opt2fn_null("-Sk", NFILE, fnm);
    ndxfnm = opt2fn_null("-n", NFILE, fnm);
    tpsfnm = ftp2fn(efTPR, NFILE, fnm);
    trxfnm = ftp2fn(efTRX, NFILE, fnm);

    /* Calculate axis */
    GMX_RELEASE_ASSERT(normal_axis[0] != NULL, "Options inconsistency; normal_axis[0] is NULL");
    if (std::strcmp(normal_axis[0], "x") == 0)
    {
        axis = XX;
    }
    else if (std::strcmp(normal_axis[0], "y") == 0)
    {
        axis = YY;
    }
    else if (std::strcmp(normal_axis[0], "z") == 0)
    {
        axis = ZZ;
    }
    else
    {
        gmx_fatal(FARGS, "Invalid axis, use x, y or z");
    }

    switch (axis)
    {
        case 0:
            fprintf(stderr, "Taking x axis as normal to the membrane\n");
            break;
        case 1:
            fprintf(stderr, "Taking y axis as normal to the membrane\n");
            break;
        case 2:
            fprintf(stderr, "Taking z axis as normal to the membrane\n");
            break;
    }

    /* tetraheder order parameter */
    if (skfnm || sgfnm)
    {
        /* If either of theoptions is set we compute both */
        sgfnm = opt2fn("-Sg", NFILE, fnm);
        skfnm = opt2fn("-Sk", NFILE, fnm);
        calc_tetra_order_parm(ndxfnm, tpsfnm, trxfnm, sgfnm, skfnm, nslices, axis,
                              opt2fn("-Sgsl", NFILE, fnm), opt2fn("-Sksl", NFILE, fnm),
                              oenv);
        /* view xvgr files */
        do_view(oenv, opt2fn("-Sg", NFILE, fnm), NULL);
        do_view(oenv, opt2fn("-Sk", NFILE, fnm), NULL);
        if (nslices > 1)
        {
            do_view(oenv, opt2fn("-Sgsl", NFILE, fnm), NULL);
            do_view(oenv, opt2fn("-Sksl", NFILE, fnm), NULL);
        }
    }
    else
    {
        /* tail order parameter */

        if (nslices > 1)
        {
            bSliced = TRUE;
            fprintf(stderr, "Dividing box in %d slices.\n\n", nslices);
        }

        if (bSzonly)
        {
            fprintf(stderr, "Only calculating Sz\n");
        }
        if (bUnsat)
        {
            fprintf(stderr, "Taking carbons as unsaturated!\n");
        }

        top = read_top(ftp2fn(efTPR, NFILE, fnm), &ePBC); /* read topology file */

        block = init_index(ftp2fn(efNDX, NFILE, fnm), &grpname);
        index = block->index;                   /* get indices from t_block block */
        a     = block->a;                       /* see block.h                    */
        ngrps = block->nr;

        if (permolecule)
        {
            nslices = index[1] - index[0]; /*I think this assumes contiguous lipids in topology*/
            fprintf(stderr, "Calculating Scd order parameters for each of %d molecules\n", nslices);
        }

        if (radial)
        {
            fprintf(stderr, "Calculating radial distances\n");
            if (!permolecule)
            {
                gmx_fatal(FARGS, "Cannot yet output radial distances without permolecule\n");
            }
        }

        /* show atomtypes, to check if index file is correct */
        print_types(index, a, ngrps, grpname, top);

        calc_order(ftp2fn(efTRX, NFILE, fnm), index, a, &order,
                   &slOrder, &slWidth, nslices, bSliced, bUnsat,
                   top, ePBC, ngrps, axis, permolecule, radial, distcalc, opt2fn_null("-nr", NFILE, fnm), &distvals, oenv);

        if (radial)
        {
            ngrps--; /*don't print the last group--was used for
                               center-of-mass determination*/

        }
        order_plot(order, slOrder, opt2fn("-o", NFILE, fnm), opt2fn("-os", NFILE, fnm),
                   opt2fn("-od", NFILE, fnm), ngrps, nslices, slWidth, bSzonly, permolecule, distvals, oenv);

        if (opt2bSet("-ob", NFILE, fnm))
        {
            if (!permolecule)
            {
                fprintf(stderr,
                        "Won't write B-factors with averaged order parameters; use -permolecule\n");
            }
            else
            {
                write_bfactors(fnm, NFILE, index, a, nslices, ngrps, slOrder, top, distvals, oenv);
            }
        }


        do_view(oenv, opt2fn("-o", NFILE, fnm), NULL);  /* view xvgr file */
        do_view(oenv, opt2fn("-os", NFILE, fnm), NULL); /* view xvgr file */
        do_view(oenv, opt2fn("-od", NFILE, fnm), NULL); /* view xvgr file */
    }

    if (distvals != NULL)
    {
        for (i = 0; i < nslices; ++i)
        {
            sfree(distvals[i]);
        }
        sfree(distvals);
    }

    return 0;
}
示例#16
0
int main()
{
    using types = meta::typelist<std::vector<int>, int, double>;

    types::visit(print_types());
}
示例#17
0
int main(int argc, char **argv) {

	#define HEADER_SIZE 22
	#define DEFAULT_DELAY 8000
	#define DEFAULT_VOLUME 4

	FILE *f, *g, *f_copy; // Input, output, and copy of the input files, respectively
	int delay = DEFAULT_DELAY, volume_scale = DEFAULT_VOLUME;
	short *orig_buffer; // Declare two buffers, one that lags behind the first
	short *echo_buffer;
	short header[HEADER_SIZE]; // Store the header here
	char *endptr; // This is for storing result of strtol, it is unused
	int opt;
	int dflag = 0, vflag = 0;
	int start_delay = 0; // Keeps track if the echo has started or not, initially set to false
	int elem_copied; // Keeps track of number of elements copied to the output file
	int j; // Counter variable

	/*
	* Loops through all optional args, setting up the appropriate variables.
	*/
	while((opt = getopt(argc, argv, "d:v:")) != -1) {
		switch(opt) {
			case 'd': // Handle the delay optional argument
				if (dflag) {
					print_usage(argv); // Can't have two "-d's" 
				}
				delay = strtol(optarg, &endptr, 10); // Convert argument to long in base 10
				if (!delay)
					print_types("-d"); // We require a positive integer
				dflag++;
				break;
			case 'v': // Handled the same way as above
				if (vflag) {
					print_usage(argv);
				}
				volume_scale = strtol(optarg, &endptr, 10);
				if (!volume_scale) 
					print_types("-v");
				vflag++;
				break;
			default: // '?'
				print_usage(argv); // Only -d and -v are valid optional args
		}
	}

	if  (argc != 3 + (dflag + vflag)*2) {
		print_usage(argv); // Need either 3, 5, or 7 arguments
	}

	if ((orig_buffer = malloc(delay * sizeof(short))) == NULL || (echo_buffer = malloc(delay * sizeof(short))) == NULL) {
		fprintf(stderr, "Memory allocation error\n");
		exit(1);
	}
	
	if ((f = fopen(argv[(dflag + vflag)*2 + 1], "r")) == NULL || (g = fopen(argv[(dflag + vflag)*2 + 2], "w")) == NULL) {
		fprintf(stderr, "Opening one or more of the given files resulted in an error\n");
		exit(1);
	}
	else {
		f_copy = fopen(argv[(dflag + vflag)*2 + 1], "r"); // Open the copy otherwise
	}

	if (fread(header, sizeof(short), HEADER_SIZE, f) != HEADER_SIZE) {
		fprintf(stderr, "The file %s does not contain an appropriate header\n", argv[(dflag + vflag)*2 + 1]);
		exit(1);
	}

	if (fseek(f_copy, HEADER_SIZE * sizeof(short), SEEK_SET) != 0) { // skip ahead in the copy past the header
		fprintf(stderr, "Unable to skip past header in the file: %s\n", argv[(dflag + vflag)*2 + 1]);
		exit(1);
	} 
	
	unsigned int *sizeptr1 = (unsigned int *)(header + 2);
	*sizeptr1 += delay * sizeof(short); // Modify the header to specify the correct size
	unsigned int *sizeptr2 = (unsigned int *)(header + 20);
	*sizeptr2 += delay * sizeof(short); // Modify the header to specify the correct size

	if (fwrite(header, sizeof(short), HEADER_SIZE, g) != HEADER_SIZE) {
		perror(argv[(dflag + vflag)*2 + 2]); // Error writing to the file, so print a message and exit
		exit(1);
	}

	/*
	* Loop over the input file so long as delay amount of samples are read,
	* and copy the original file and the echo to the output file appropriately.
	*/
	while ((elem_copied = fread(orig_buffer, sizeof(short), delay, f)) == delay) {
		
		if (start_delay) { // If we started echoing then start mixing the samples appropriately
			if (fread(echo_buffer, sizeof(short), delay, f_copy) != delay) {
				fprintf(stderr, "Error reading from file: %s\n", argv[(dflag + vflag)*2 + 1]);
				exit(1);
			}
			for(j = 0; j < delay; j++) {
				orig_buffer[j] += echo_buffer[j]/volume_scale;
			}
		}
		else { // If we haven't started echoing, then we will during the next loop iteration
			start_delay = 1;
		}

		// Write the buffer to the file
		if (fwrite(orig_buffer, sizeof(short), delay, g) != delay) {
			fprintf(stderr, "Error writing to file: %s\n", argv[(dflag + vflag)*2 + 2]);
			exit(1);
		}
	}

	/*
	* We want to ensure that our loop ended because of an end of file error,
	* rather than some arbitrary error. So we need to check ferror.
	*/
	if (ferror(f)) {
		fprintf(stderr, "Error reading from file: %s\n", argv[(dflag + vflag)*2 + 1]);
		exit(1);
	}

	/*
	* The idea here is that we want to check whether or not we actually started echoing or not.
	* This way, we will know if the file was shorter than delay in which case we need to add 0's to the file.
	*/
	if (start_delay) {

		if (fread(echo_buffer, sizeof(short), delay, f_copy) != delay) {
			fprintf(stderr, "Error reading from file: %s\n", argv[(dflag + vflag)*2 + 1]);
			exit(1);
		}

		// Add the remaining mixed samples
		for (j = 0; j < elem_copied; j++) {
			orig_buffer[j] += echo_buffer[j]/volume_scale;
		}

		// Add the remaining echoes
		for (j = elem_copied; j < delay; j++) {
			orig_buffer[j] = echo_buffer[j]/volume_scale;
		}

		// Write the remaining mixed samples
		if (fwrite(orig_buffer, sizeof(short), delay, g) != delay) {
			fprintf(stderr, "Error writing to file: %s\n", argv[(dflag + vflag)*2 + 2]);
			exit(1);
		}

		free(orig_buffer); // Free the allocated memory, don't need it anymore

		if ((echo_buffer = realloc(echo_buffer, elem_copied * sizeof(short))) == NULL) {
			fprintf(stderr, "Memory allocation error\n");
			exit(1);
		}

		if (fread(echo_buffer, sizeof(short), elem_copied, f_copy) != elem_copied) {
			fprintf(stderr, "Error reading from file: %s\n", argv[(dflag + vflag)*2 + 1]);
			exit(1);
		}

		for (j = 0; j < elem_copied; j++) {
			echo_buffer[j] /= volume_scale;
		}

		// Write the remaining echoes
		if (fwrite(echo_buffer, sizeof(short), elem_copied, g) != elem_copied) {
			fprintf(stderr, "Error writing to file: %s\n", argv[(dflag + vflag)*2 + 2]);
			exit(1);
		}

		free(echo_buffer); // Free the allocated memory, don't need it anymore
	}
	else {

		// Add a bunch of zeros
		for (j = elem_copied; j < delay; j++) {
			orig_buffer[j] = 0;
		}

		// Write the samples
		if (fwrite(orig_buffer, sizeof(short), delay, g) != delay) {
			fprintf(stderr, "Error writing to file: %s\n", argv[(dflag + vflag)*2 + 2]);
			exit(1);
		}

		free(orig_buffer); // Free the allocated memory, don't need it anymore

		if ((echo_buffer = realloc(echo_buffer, elem_copied * sizeof(short))) == NULL) {
			fprintf(stderr, "Memory allocation error\n");
			exit(1);
		}

		if (fread(echo_buffer, sizeof(short), elem_copied, f_copy) != elem_copied) {
			fprintf(stderr, "Error reading from file: %s\n", argv[(dflag + vflag)*2 + 1]);
			exit(1);
		}

		for (j = 0; j < elem_copied; j++) {
			echo_buffer[j] /= volume_scale;
		}

		// Write the remaining echoes
		if (fwrite(echo_buffer, sizeof(short), elem_copied, g) != elem_copied) {
			fprintf(stderr, "Error writing to file: %s\n", argv[(dflag + vflag)*2 + 2]);
			exit(1);
		}

		free(echo_buffer); // Free the allocated memory, don't need it anymore
	}

	fclose(f);
	fclose(g);

	return 0;
}