Esempio n. 1
0
File: dir.c Progetto: crossmeta/sgi
#include "field.h"
#include "dir.h"
#include "io.h"
#include "data.h"
#include "mount.h"

static int	dir_leaf_entries_count(void *obj, int startoff);
static int	dir_leaf_hdr_count(void *obj, int startoff);
static int	dir_leaf_name_count(void *obj, int startoff);
static int	dir_leaf_namelist_count(void *obj, int startoff);
static int	dir_leaf_namelist_offset(void *obj, int startoff, int idx);
static int	dir_node_btree_count(void *obj, int startoff);
static int	dir_node_hdr_count(void *obj, int startoff);

const field_t	dir_hfld[] = {
	{ "", FLDT_DIR, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	LOFF(f)	bitize(offsetof(xfs_dir_leafblock_t, f))
#define	NOFF(f)	bitize(offsetof(xfs_da_intnode_t, f))
const field_t	dir_flds[] = {
	{ "lhdr", FLDT_DIR_LEAF_HDR, OI(LOFF(hdr)), dir_leaf_hdr_count,
	  FLD_COUNT, TYP_NONE },
	{ "nhdr", FLDT_DIR_NODE_HDR, OI(NOFF(hdr)), dir_node_hdr_count,
	  FLD_COUNT, TYP_NONE },
	{ "entries", FLDT_DIR_LEAF_ENTRY, OI(LOFF(entries)),
	  dir_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
	{ "btree", FLDT_DIR_NODE_ENTRY, OI(NOFF(btree)),
	  dir_node_btree_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
	{ "namelist", FLDT_DIR_LEAF_NAME, dir_leaf_namelist_offset,
Esempio n. 2
0
#include "field.h"
#include "io.h"
#include "bit.h"
#include "output.h"
#include "init.h"
#include "agi.h"

static int agi_f(int argc, char **argv);
static void agi_help(void);

static const cmdinfo_t agi_cmd =
	{ "agi", NULL, agi_f, 0, 1, 1, N_("[agno]"),
	  N_("set address to agi header"), agi_help };

const field_t	agi_hfld[] = {
	{ "", FLDT_AGI, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	OFF(f)	bitize(offsetof(xfs_agi_t, agi_ ## f))
const field_t	agi_flds[] = {
	{ "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
	{ "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE },
	{ "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
	{ "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE },
	{ "count", FLDT_AGINO, OI(OFF(count)), C1, 0, TYP_NONE },
	{ "root", FLDT_AGBLOCK, OI(OFF(root)), C1, 0, TYP_INOBT },
	{ "level", FLDT_UINT32D, OI(OFF(level)), C1, 0, TYP_NONE },
	{ "freecount", FLDT_AGINO, OI(OFF(freecount)), C1, 0, TYP_NONE },
	{ "newino", FLDT_AGINO, OI(OFF(newino)), C1, 0, TYP_INODE },
	{ "dirino", FLDT_AGINO, OI(OFF(dirino)), C1, 0, TYP_INODE },
Esempio n. 3
0
	{ "version", NULL, version_f, 0, -1, 1, N_("[feature | [vnum fnum]]"),
	  N_("set feature bit(s) in the sb version field"), version_help };

void
sb_init(void)
{
	add_command(&sb_cmd);
	add_command(&uuid_cmd);
	add_command(&label_cmd);
	add_command(&version_cmd);
}

#define	OFF(f)	bitize(offsetof(xfs_sb_t, sb_ ## f))
#define	SZC(f)	szcount(xfs_sb_t, sb_ ## f)
const field_t	sb_flds[] = {
	{ "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
	{ "blocksize", FLDT_UINT32D, OI(OFF(blocksize)), C1, 0, TYP_NONE },
	{ "dblocks", FLDT_DRFSBNO, OI(OFF(dblocks)), C1, 0, TYP_NONE },
	{ "rblocks", FLDT_DRFSBNO, OI(OFF(rblocks)), C1, 0, TYP_NONE },
	{ "rextents", FLDT_DRTBNO, OI(OFF(rextents)), C1, 0, TYP_NONE },
	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
	{ "logstart", FLDT_DFSBNO, OI(OFF(logstart)), C1, 0, TYP_LOG },
	{ "rootino", FLDT_INO, OI(OFF(rootino)), C1, 0, TYP_INODE },
	{ "rbmino", FLDT_INO, OI(OFF(rbmino)), C1, 0, TYP_INODE },
	{ "rsumino", FLDT_INO, OI(OFF(rsumino)), C1, 0, TYP_INODE },
	{ "rextsize", FLDT_AGBLOCK, OI(OFF(rextsize)), C1, 0, TYP_NONE },
	{ "agblocks", FLDT_AGBLOCK, OI(OFF(agblocks)), C1, 0, TYP_NONE },
	{ "agcount", FLDT_AGNUMBER, OI(OFF(agcount)), C1, 0, TYP_NONE },
	{ "rbmblocks", FLDT_EXTLEN, OI(OFF(rbmblocks)), C1, 0, TYP_NONE },
	{ "logblocks", FLDT_EXTLEN, OI(OFF(logblocks)), C1, 0, TYP_NONE },
	{ "versionnum", FLDT_UINT16X, OI(OFF(versionnum)), C1, 0, TYP_NONE },
Esempio n. 4
0
/*
 * opts_init --
 *	Initialize some of the options.
 *
 * PUBLIC: int opts_init __P((SCR *, int *));
 */
int
opts_init(SCR *sp, int *oargs)
{
	ARGS *argv[2], a, b;
	OPTLIST const *op;
	u_long isset, v;
	int cnt, optindx = 0;
	char *s;
	CHAR_T b2[1024];

	if (sizeof optlist / sizeof optlist[0] - 1 != O_OPTIONCOUNT) {
		fprintf(stderr, "vi: option table size error (%d != %d)\n",
		    (int)(sizeof optlist / sizeof optlist[0] - 1),
		    O_OPTIONCOUNT);
		exit(1);
	}

	a.bp = b2;
	b.bp = NULL;
	a.len = b.len = 0;
	argv[0] = &a;
	argv[1] = &b;

	/* Set numeric and string default values. */
#define	OI(indx, str) {							\
	a.len = STRLEN(str);						\
	if ((const CHAR_T*)str != b2)/* GCC puts strings in text-space. */\
		(void)MEMCPY(b2, str, a.len+1);				\
	if (opts_set(sp, argv, NULL)) {					\
		 optindx = indx;					\
		goto err;						\
	}								\
}
	/*
	 * Indirect global options to global space.  Specifically, set up
	 * terminal, lines, columns first, they're used by other options.
	 * Note, don't set the flags until we've set up the indirection.
	 */
	if (o_set(sp, O_TERM, 0, NULL, GO_TERM))
		goto err;
	F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
	if (o_set(sp, O_LINES, 0, NULL, GO_LINES))
		goto err;
	F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
	if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS))
		goto err;
	F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
	if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE))
		goto err;
	F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);

	/* Initialize string values. */
	(void)SPRINTF(b2, SIZE(b2),
	    L("cdpath=%s"), (s = getenv("CDPATH")) == NULL ? ":" : s);
	OI(O_CDPATH, b2);

	/*
	 * !!!
	 * Vi historically stored temporary files in /var/tmp.  We store them
	 * in /tmp by default, hoping it's a memory based file system.  There
	 * are two ways to change this -- the user can set either the directory
	 * option or the TMPDIR environmental variable.
	 */
	(void)SPRINTF(b2, SIZE(b2),
	    L("directory=%s"), (s = getenv("TMPDIR")) == NULL ? _PATH_TMP : s);
	OI(O_TMP_DIRECTORY, b2);
	OI(O_ESCAPETIME, L("escapetime=1"));
	OI(O_KEYTIME, L("keytime=6"));
	OI(O_MATCHCHARS, L("matchchars=()[]{}<>"));
	OI(O_MATCHTIME, L("matchtime=7"));
	(void)SPRINTF(b2, SIZE(b2), L("msgcat=%s"), _PATH_MSGCAT);
	OI(O_MSGCAT, b2);
	OI(O_REPORT, L("report=5"));
	OI(O_PARAGRAPHS, L("paragraphs=IPLPPPQPP LIpplpipbp"));
	(void)SPRINTF(b2, SIZE(b2), L("path=%s"), "");
	OI(O_PATH, b2);
	(void)SPRINTF(b2, SIZE(b2), L("recdir=%s"), _PATH_PRESERVE);
	OI(O_RECDIR, b2);
	OI(O_SECTIONS, L("sections=NHSHH HUnhsh"));
	(void)SPRINTF(b2, SIZE(b2),
	    L("shell=%s"), (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
	OI(O_SHELL, b2);
	OI(O_SHELLMETA, L("shellmeta=~{[*?$`'\"\\"));
	OI(O_SHIFTWIDTH, L("shiftwidth=8"));
	OI(O_SIDESCROLL, L("sidescroll=16"));
	OI(O_TABSTOP, L("tabstop=8"));
	(void)SPRINTF(b2, SIZE(b2), L("tags=%s"), _PATH_TAGS);
	OI(O_TAGS, b2);

	/*
	 * XXX
	 * Initialize O_SCROLL here, after term; initializing term should
	 * have created a LINES/COLUMNS value.
	 */
	if ((v = (O_VAL(sp, O_LINES) - 1) / 2) == 0)
		v = 1;
	(void)SPRINTF(b2, SIZE(b2), L("scroll=%ld"), v);
	OI(O_SCROLL, b2);

	/*
	 * The default window option values are:
	 *		8 if baud rate <=  600
	 *	       16 if baud rate <= 1200
	 *	LINES - 1 if baud rate  > 1200
	 *
	 * Note, the windows option code will correct any too-large value
	 * or when the O_LINES value is 1.
	 */
	if (sp->gp->scr_baud(sp, &v))
		return (1);
	if (v <= 600)
		v = 8;
	else if (v <= 1200)
		v = 16;
	else if ((v = O_VAL(sp, O_LINES) - 1) == 0)
		v = 1;

	(void)SPRINTF(b2, SIZE(b2), L("window=%lu"), v);
	OI(O_WINDOW, b2);

	/*
	 * Set boolean default values, and copy all settings into the default
	 * information.  OS_NOFREE is set, we're copying, not replacing.
	 */
	for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt)
		switch (op->type) {
		case OPT_0BOOL:
			break;
		case OPT_1BOOL:
			O_SET(sp, cnt);
			O_D_SET(sp, cnt);
			break;
		case OPT_NUM:
			o_set(sp, cnt, OS_DEF, NULL, O_VAL(sp, cnt));
			break;
		case OPT_STR:
			if (O_STR(sp, cnt) != NULL && o_set(sp, cnt,
			    OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0))
				goto err;
			break;
		default:
			abort();
		}

	/*
	 * !!!
	 * Some options can be initialized by the command name or the
	 * command-line arguments.  They don't set the default values,
	 * it's historic practice.
	 */
	for (; *oargs != -1; ++oargs)
		OI(*oargs, optlist[*oargs].name);
#undef OI

	/*
	 * Inform the underlying screen of the initial values of the
	 * edit options.
	 */
	for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt) {
		isset = O_ISSET(sp, cnt);
		(void)sp->gp->scr_optchange(sp, cnt, O_STR(sp, cnt), &isset);
	}
	return (0);

err:	msgq_wstr(sp, M_ERR, optlist[optindx].name,
	    "031|Unable to set default %s option");
	return (1);
}
Esempio n. 5
0
 static void
my_findopt(void *v, Optimizer1 *D, char *options)
{
	Dakota_probsize *ps;
	Opt_Info OI(options);
	RealMatrix const *RMe, *RMi;
	RealVector const *Ru,  *Rv;
	Snopt_Details *T, *T0;
	char *cu, *cw, *ve;
	double *A, *bl, *bu, f, objadd, *pi, *rc, *ru, *rw, sinf, t, *x;
	int co, i, i1, inform, j, k, k1, lencu, lencw, leniu, leniw, lenru, lenrw;
	int m, mincw, miniw, minrw, n, ninf, nlc, nlce, nlci, nlnz;
	int nm, nname, nnjac, nnlc, nnobj, ns, nz;
	int *hs, *ind, *iu, *iw, *loc;
	size_t L, Lc, Li;
	ftnlen cu_len, cw_len, prob_len, start_len;

	T0 = snopt_details;
	snopt_details = T = (Snopt_Details *)v;
	T->D = D;	//should be unnecessary
	ps = DF->ps;
	T->nf = 0;
	T->n = n = ps->n_var;
	T->nnlc = nnlc = ps->n_nlinc;
	T->co = co = ps->n_obj;
	T->numgflag = ps->numgflag;
	T->maxfe = ps->maxfe;
	nlc = ps->n_linc;
	T->m = m = nlc + nnlc;
	// Since Dakota does not provide sparsity information,
	// we simply assume all variables are nonlinear and
	// involved with every nonlinear function.
	nlnz = nnlc * n;
	loc = new int[n + 1];
	memset(loc, 0, n*sizeof(int));
	RMe = linear_eq_constraint_coeffs(D);
	nlce = RMe->numRows();
	for(i = 0; i < nlce; i++) {
		for(j = 0; j < n; j++)
			if ((*RMe)[i][j] != 0.)
				++loc[j];
		}
	RMi = linear_ineq_constraint_coeffs(D);
	nlci = RMi->numRows();
	for(i = 0; i < nlci; i++) {
		for(j = 0; j < n; j++)
			if ((*RMi)[i][j] != 0.)
				++loc[j];
		}
	for(i = nz = 0; i < n; i++) {
		j = loc[i];
		loc[i] = nz;
		nz += j + nnlc;
		}
	ind = new int[nz];
	A = new double[nz];
	memset(A, 0, nz*sizeof(double));
	for(i = 0; i < n; i++) {
		j = loc[i];
		for(k = 1; k <= nnlc; k++)
			ind[j++] = k;
		loc[i] = j;
		}
	for(i = 0; i < nlce; ++i) {
		i1 = i + nnlc + 1;
		for(j = 0; j < n; j++)
			if ((t = (*RMe)[i][j]) != 0.) {
				k = loc[j]++;
				ind[k] = i1;
				A[k] = t;
				}
		}
	for(i = 0; i < nlci; ++i) {
		i1 = i + nnlc + 1;
		for(j = 0; j < n; j++)
			if ((t = (*RMi)[i][j]) != 0.) {
				k = loc[j]++;
				ind[k] = i1;
				A[k] = t;
				}
		}
	for(i = n; i > 0; --i)
		loc[i] = loc[i-1] + 1;
	loc[0] = 1;

	lencw = leniw = lenrw = 500;
	rw = new double[lenrw];
	iw = new int[leniw];
	cw = new char[lencw*8];
	mincw = miniw = minrw = -1;
	cu_len = cw_len = prob_len = 8;
	nnjac = nnobj = n;	//snmemb_ may clobber nnjac and nnobj if nnlc == 0
	i = j = 0;
	sninit_(&i, &j, cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	snmemb_(&m, &n, &nz, &nlnz, &nnlc, &nnjac, &nnobj, &mincw, &miniw, &minrw,
		cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	delete[] cw;
	delete[] iw;
	delete[] rw;
	i = 20 * (m + n);
	leniw = miniw + i;
	lenrw = minrw + i;
	lencw = mincw;
	nm = n + m;
	L = lenrw + 3*nm + 2*n + m + 1;
	rw = new double[L];
	memset(rw, 0, L*sizeof(double));
	bl = rw + lenrw;
	bu = bl + nm;
	rc = bu + nm;
	pi = rc + nm;
	x = pi + m;
	T->Lastx = x + n;
	ru = T->Lastx + n;
	Li = leniw + 1 + nm;
	iw = new int[Li];
	memset(iw, 0, Li*sizeof(int));
	hs = iw + leniw;
	iu = hs + nm;
	Lc = lencw*8;
	cw = new char[Lc + 8];
	memset(cw, 0, Lc + 8);
	cu = cw + Lc;
	start_len = 4;
	lencu = leniu = lenru = 1;
	i = 6;	// detailed output
	j = 0;	// no summary output
	// Look for initial outlev = n:
	// n & 1 ==> want detailed output; n & 2 ==> summary output
	if (dlsolver_option(&OI)) {
		if (!strncmp(OI.name, "outlev", OI.name_len)) {
			k = (int)strtol(OI.val, &ve, 10);
			if (ve > OI.val) {
				i = k & 1 ? 6 : 0;
				j = k & 2 ? 6 : 0;
				}
			}
		else
			OI.begin = options;	// reset
		}
	sninit_(&i, &j, cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	Rv = continuous_lower_bounds(D);
	Ru = continuous_upper_bounds(D);
	k = Rv->length();
	for(i = 0; i < k; i++) {
		bl[i] = (*Rv)[i];
		bu[i] = (*Ru)[i];
		}
	Rv = nonlinear_ineq_constraint_lower_bounds(D);
	Ru = nonlinear_ineq_constraint_upper_bounds(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i) {
		bl[i] = (*Rv)[j];
		bu[i] = (*Ru)[j];
		}
	Rv = nonlinear_eq_constraint_targets(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i)
		bl[i] = bu[i] = (*Rv)[j];
	Rv = linear_eq_constraint_targets(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i)
		bl[i] = bu[i] = (*Rv)[j];
	Rv = linear_ineq_constraint_lower_bounds(D);
	Ru = linear_ineq_constraint_upper_bounds(D);
	k = Rv->length();
	for(j = 0; j < k; j++, i++) {
		bl[i] = (*Rv)[j];
		bu[i] = (*Ru)[j];
		}
	j = 0;
	while(dlsolver_option(&OI)) {
		inform = 0;
		snset_(OI.name, &j, &j, &inform, cw, &lencw, iw, &leniw, rw, &lenrw,
			(ftnlen)OI.all_len, cw_len);
		printf(inform	? "\n**** Rejecting \"%.*s\"****\n"
				: "accepted snopt option: %.*s\n", OI.all_len, OI.name);
		}
	GetContVars(D, n, x);
	f = std::numeric_limits<double>::infinity();
	nname = 1;	// no names
	objadd = sinf = 0.;
	inform = ns = ninf = 0;
	if (x[0] == 0.)
		T->Lastx[0] = 1.; // ensure Lastx != x;
	snopt_("Cold", &m, &n, &nz, &nname, &nnlc, &nnobj, &nnjac, &m, &objadd,
		"dakotapr", funcon, funobj, A, ind, loc,
		bl, bu, cu, hs, x, pi, rc, &inform, &mincw, &miniw,
		&minrw, &ns, &ninf, &sinf, &f, cu, &lencu,
		iu, &leniu, ru, &lenru, cw, &lencw, iw, &leniw,
		rw, &lenrw, start_len, prob_len, cu_len,
		cu_len, cw_len);
	flush_();	// flush Fortran buffers
	if (inform > 1) {
		f = std::numeric_limits<double>::infinity();
		printf("snopt returned inform = %d\n", inform);
		}
	SetBestContVars(D, n, x);
	if (!ps->multiobj) {
		Real bestf[m+1];
		bestf[0] = f;
		for (i = 0; i < m; i++)
			bestf[i+1] = x[i];
		SetBestRespFns(D, m+1, bestf);
		}
	delete[] cw;
	delete[] iw;
	delete[] rw;
	delete[] A;
	delete[] ind;
	delete[] loc;
	}
Esempio n. 6
0
#include "field.h"
#include "io.h"
#include "bit.h"
#include "output.h"
#include "init.h"
#include "agf.h"

static int agf_f(int argc, char **argv);
static void agf_help(void);

static const cmdinfo_t agf_cmd =
	{ "agf", NULL, agf_f, 0, 1, 1, N_("[agno]"),
	  N_("set address to agf header"), agf_help };

const field_t	agf_hfld[] = {
	{ "", FLDT_AGF, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	OFF(f)	bitize(offsetof(xfs_agf_t, agf_ ## f))
#define	SZ(f)	bitszof(xfs_agf_t, agf_ ## f)
const field_t	agf_flds[] = {
	{ "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
	{ "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE },
	{ "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
	{ "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE },
	{ "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF),
	  FLD_ARRAY|FLD_SKIPALL, TYP_NONE },
	{ "bnoroot", FLDT_AGBLOCK,
	  OI(OFF(roots) + XFS_BTNUM_BNO * SZ(roots[XFS_BTNUM_BNO])), C1, 0,
	  TYP_BNOBT },
Esempio n. 7
0
static int	inode_u_offset(void *obj, int startoff, int idx);
static int	inode_u_bmbt_count(void *obj, int startoff);
static int	inode_u_bmx_count(void *obj, int startoff);
static int	inode_u_c_count(void *obj, int startoff);
static int	inode_u_dev_count(void *obj, int startoff);
static int	inode_u_muuid_count(void *obj, int startoff);
static int	inode_u_sfdir2_count(void *obj, int startoff);
static int	inode_u_sfdir3_count(void *obj, int startoff);
static int	inode_u_symlink_count(void *obj, int startoff);

static const cmdinfo_t	inode_cmd =
	{ "inode", NULL, inode_f, 0, 1, 1, "[inode#]",
	  "set current inode", NULL };

const field_t	inode_hfld[] = {
	{ "", FLDT_INODE, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};
const field_t	inode_crc_hfld[] = {
	{ "", FLDT_INODE_CRC, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

/* XXX: fix this up! */
#define	OFF(f)	bitize(offsetof(xfs_dinode_t, di_ ## f))
const field_t	inode_flds[] = {
	{ "core", FLDT_DINODE_CORE, OI(OFF(magic)), C1, 0, TYP_NONE },
	{ "next_unlinked", FLDT_AGINO, OI(OFF(next_unlinked)), C1, 0,
	  TYP_INODE },
	{ "u", FLDT_DINODE_U, inode_u_offset, C1, FLD_OFFSET, TYP_NONE },
	{ "a", FLDT_DINODE_A, inode_a_offset, inode_a_count,
Esempio n. 8
0
#include "io.h"
#include "init.h"
#include "output.h"
#include "dquot.h"

static int	dquot_f(int argc, char **argv);
static void	dquot_help(void);

static const cmdinfo_t	dquot_cmd = {
	"dquot", NULL, dquot_f, 1, 2, 1, N_("[-g|-p|-u] id"),
N_("set current address to a group, project or user quota block for given ID"),
	dquot_help,
};

const field_t	dqblk_hfld[] = {
	{ "", FLDT_DQBLK, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	DDOFF(f)	bitize(offsetof(xfs_dqblk_t, dd_ ## f))
#define	DDSZC(f)	szcount(xfs_dqblk_t, dd_ ## f)
const field_t	dqblk_flds[] = {
	{ "diskdq", FLDT_DISK_DQUOT, OI(DDOFF(diskdq)), C1, 0, TYP_NONE },
	{ "fill", FLDT_CHARS, OI(DDOFF(fill)), CI(DDSZC(fill)), FLD_SKIPALL,
	  TYP_NONE },
	{ "crc", FLDT_CRC, OI(DDOFF(crc)), C1, 0, TYP_NONE },
	{ "lsn", FLDT_UINT64X, OI(DDOFF(lsn)), C1, 0, TYP_NONE },
	{ "uuid", FLDT_UUID, OI(DDOFF(uuid)), C1, 0, TYP_NONE },
	{ NULL }
};
Esempio n. 9
0
#include "field.h"
#include "bnobt.h"
#include "io.h"
#include "print.h"
#include "bit.h"
#include "mount.h"

static int	bnobt_key_count(void *obj, int startoff);
static int	bnobt_key_offset(void *obj, int startoff, int idx);
static int	bnobt_ptr_count(void *obj, int startoff);
static int	bnobt_ptr_offset(void *obj, int startoff, int idx);
static int	bnobt_rec_count(void *obj, int startoff);
static int	bnobt_rec_offset(void *obj, int startoff, int idx);

const field_t	bnobt_hfld[] = {
	{ "", FLDT_BNOBT, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	OFF(f)	bitize(offsetof(xfs_alloc_block_t, bb_ ## f))
const field_t	bnobt_flds[] = {
	{ "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
	{ "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
	{ "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
	{ "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_BNOBT },
	{ "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_BNOBT },
	{ "recs", FLDT_BNOBTREC, bnobt_rec_offset, bnobt_rec_count,
	  FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
	{ "keys", FLDT_BNOBTKEY, bnobt_key_offset, bnobt_key_count,
	  FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
	{ "ptrs", FLDT_BNOBTPTR, bnobt_ptr_offset, bnobt_ptr_count,
Esempio n. 10
0
#include "faddr.h"
#include "fprint.h"
#include "field.h"
#include "bit.h"
#include "dir2sf.h"

static int	dir2_inou_i4_count(void *obj, int startoff);
static int	dir2_inou_i8_count(void *obj, int startoff);
static int	dir2_sf_entry_inumber_offset(void *obj, int startoff, int idx);
static int	dir2_sf_entry_name_count(void *obj, int startoff);
static int	dir2_sf_list_count(void *obj, int startoff);
static int	dir2_sf_list_offset(void *obj, int startoff, int idx);

#define	OFF(f)	bitize(offsetof(xfs_dir2_sf_t, f))
const field_t	dir2sf_flds[] = {
	{ "hdr", FLDT_DIR2_SF_HDR, OI(OFF(hdr)), C1, 0, TYP_NONE },
	{ "list", FLDT_DIR2_SF_ENTRY, dir2_sf_list_offset, dir2_sf_list_count,
	  FLD_ARRAY|FLD_COUNT|FLD_OFFSET, TYP_NONE },
	{ NULL }
};

#define UOFF(f)	bitize(offsetof(xfs_dir2_inou_t, f))
const field_t	dir2_inou_flds[] = {
	{ "i8", FLDT_DIR2_INO8, OI(UOFF(i8)), dir2_inou_i8_count, FLD_COUNT,
	  TYP_INODE },
	{ "i4", FLDT_DIR2_INO4, OI(UOFF(i4)), dir2_inou_i4_count, FLD_COUNT,
	  TYP_INODE },
	{ NULL }
};

#define	HOFF(f)	bitize(offsetof(xfs_dir2_sf_hdr_t, f))
Esempio n. 11
0
int
symlink_size(
	void	*obj,
	int	startoff,
	int	idx)
{
	struct xfs_dsymlink_hdr	*hdr = obj;

	ASSERT(startoff == 0);
	if (hdr->sl_magic != cpu_to_be32(XFS_SYMLINK_MAGIC))
		return 0;
	return be32_to_cpu(hdr->sl_bytes) + sizeof(*hdr);
}

const struct field	symlink_crc_hfld[] = {
	{ "", FLDT_SYMLINK_CRC, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

#define	OFF(f)	bitize(offsetof(struct xfs_dsymlink_hdr, sl_ ## f))
#define	SZOF(f)	bitize(sizeof(struct xfs_dsymlink_hdr))
const struct field	symlink_crc_flds[] = {
	{ "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
	{ "offset", FLDT_UINT32D, OI(OFF(offset)), C1, 0, TYP_NONE },
	{ "bytes", FLDT_UINT32D, OI(OFF(bytes)), C1, 0, TYP_NONE },
	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
	{ "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE },
	{ "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD },
	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
	{ "data", FLDT_CHARNS, OI(bitize(sizeof(struct xfs_dsymlink_hdr))),
Esempio n. 12
0
int
btblock_size(
	void	*obj,
	int	startoff,
	int	idx)
{
	return bitize(mp->m_sb.sb_blocksize);
}


/*
 * Bmap btree.
 */

const field_t	bmapbta_hfld[] = {
	{ "", FLDT_BMAPBTA, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};
const field_t	bmapbtd_hfld[] = {
	{ "", FLDT_BMAPBTD, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};

const field_t	bmapbta_crc_hfld[] = {
	{ "", FLDT_BMAPBTA_CRC, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};
const field_t	bmapbtd_crc_hfld[] = {
	{ "", FLDT_BMAPBTD_CRC, OI(0), C1, 0, TYP_NONE },
	{ NULL }
};
Esempio n. 13
0
#include "type.h"
#include "faddr.h"
#include "fprint.h"
#include "field.h"
#include "bit.h"
#include "attrshort.h"

static int	attr_sf_entry_name_count(void *obj, int startoff);
static int	attr_sf_entry_value_count(void *obj, int startoff);
static int	attr_sf_entry_value_offset(void *obj, int startoff, int idx);
static int	attr_shortform_list_count(void *obj, int startoff);
static int	attr_shortform_list_offset(void *obj, int startoff, int idx);

#define	OFF(f)	bitize(offsetof(xfs_attr_shortform_t, f))
const field_t	attr_shortform_flds[] = {
	{ "hdr", FLDT_ATTR_SF_HDR, OI(OFF(hdr)), C1, 0, TYP_NONE },
	{ "list", FLDT_ATTR_SF_ENTRY, attr_shortform_list_offset,
	  attr_shortform_list_count, FLD_ARRAY|FLD_COUNT|FLD_OFFSET, TYP_NONE },
	{ NULL }
};

#define	HOFF(f)	bitize(offsetof(xfs_attr_sf_hdr_t, f))
const field_t	attr_sf_hdr_flds[] = {
	{ "totsize", FLDT_UINT16D, OI(HOFF(totsize)), C1, 0, TYP_NONE },
	{ "count", FLDT_UINT8D, OI(HOFF(count)), C1, 0, TYP_NONE },
	{ NULL }
};

#define	EOFF(f)	bitize(offsetof(xfs_attr_sf_entry_t, f))
const field_t	attr_sf_entry_flds[] = {
	{ "namelen", FLDT_UINT8D, OI(EOFF(namelen)), C1, 0, TYP_NONE },
Esempio n. 14
0
int main(int argc, char *argv[]) 
{ 
#ifdef __linux
	feenableexcept(2);
	feenableexcept(3);
#endif

	FILE * matrici_iniziali=fopen("Matrici_Iniziali.txt","w");
	FILE * posizionePart=fopen("Posizione_Particelle.txt","w");
	FILE * ellissi=fopen("Parametri_Ellissi_Funz_Ottiche.txt","w");
	FILE * funzioni_ottiche=fopen("Funzioni_Ottiche.txt","w");
	FILE * confronti=fopen("Math_rilevati.txt","w");
#ifdef TEST_OPTICAL_FUNCTIONS
	FILE * funzioni_ottiche_t=fopen("Funzioni_Ottiche_T.txt","w");
	FILE * ellissi_t=fopen("Parametri_Ellissi_Funz_Ottiche_T.txt","w");
	FILE * confronti_t=fopen("Math_rilevati_T.txt","w");
#endif

#ifdef DEBUG
	FILE * outputDEBUG=fopen("DEBUG.txt","w");
#endif

	bool fallita_lettura_parametri = true;
	bool fallita_lettura_inputdistr = true;
	bool do_transport = false;
	bool do_optics = false;
	bool posso_fare_funzioni_ottiche = false;
	ifstream parametri;
	ifstream inputdistr;
	int nstep = 1;

	double gnuplot_ymax_opt=0.;
	bool calcola_ymax_opt = true;
#ifdef TEST_OPTICAL_FUNCTIONS
	double gnuplot_ymax_opt_T=0.;
	bool calcola_ymax_opt_T = true;
#endif
	double gnuplot_ymax_pos=0.;
	bool calcola_ymax_pos = true;
	double gnuplot_xmax_opt=0.;
	double gnuplot_xmax_pos=0.;
	bool calcola_ymax_ell = true;
	double gnuplot_ymax_ell=0.;
	double percentuale=0.03;
	int conto_per_confronto=0;

	double *compare_x=new double[2];
	double *compare_y=new double[2];
	bool confronto_pos_x=false;
	bool confronto_pos_y=false;

	double *paramIniz_X=new double[2];
	double *paramIniz_Y=new double[2];

#ifdef TEST_OPTICAL_FUNCTIONS
	int conto_per_confronto_t_x=0;
	int conto_per_confronto_t_y=0;
	bool confronto_pos_t_y=false;
	bool confronto_pos_t_x=false;
	bool fai_da_te_x=false;
	bool fai_da_te_y=false;
#endif

	for (int i = 1; i < argc; i++)
	{
		if (string(argv[i]) == "-p")
		{
			parametri.open(argv[i+1]);
			fallita_lettura_parametri=parametri.fail();
			i++;
		}
		else if (string(argv[i]) == "-i")
		{
			inputdistr.open(argv[i+1]);
			fallita_lettura_inputdistr=inputdistr.fail();
			i++;
		}
		else if (string(argv[i]) == "-transport")
		{
			do_transport=true;
		}
		else if (string(argv[i]) == "-xmax_opt")
		{
			gnuplot_xmax_opt=atof(argv[i+1]);
			i++;
		}
		else if (string(argv[i]) == "-xmax_pos")
		{
			gnuplot_xmax_pos=atof(argv[i+1]);
			i++;
		}
		else if (string(argv[i]) == "-ymax_opt")
		{
			gnuplot_ymax_opt=atof(argv[i+1]);
			calcola_ymax_opt = false;
			i++;
		}
#ifdef TEST_OPTICAL_FUNCTIONS
		else if (string(argv[i]) == "-ymax_opt_T")
		{
			gnuplot_ymax_opt_T=atof(argv[i+1]);
			calcola_ymax_opt_T = false;
			i++;
		}
#endif
		else if (string(argv[i]) == "-ymax_pos")
		{
			gnuplot_ymax_pos=atof(argv[i+1]);
			calcola_ymax_pos = false;
			i++;
		}
		else if (string(argv[i]) == "-ymax_ell")
		{
			gnuplot_ymax_ell=atof(argv[i+1]);
			calcola_ymax_ell = false;
			i++;
		}
		else if (string(argv[i]) == "-compare_X")
		{
			compare_x[0]=atof(argv[i+1]);
			compare_x[1]=atof(argv[i+2]);
			i+=2;
		}
		else if (string(argv[i]) == "-compare_Y")
		{
			compare_y[0]=atof(argv[i+1]);
			compare_y[1]=atof(argv[i+2]);

			i+=2;
		}
		else if (string(argv[i]) == "-perc")
		{
			percentuale=atof(argv[i+1]);
			fprintf(matrici_iniziali,"\n%f\n",percentuale);
			i++;
		}
		else if (string(argv[i]) == "-optics")
		{
			do_optics=true;
		}
		else if (string(argv[i]) == "-nstep")
		{
			nstep = atoi(argv[i+1]);
			i++;
		}
#ifdef TEST_OPTICAL_FUNCTIONS
		else if (string(argv[i]) == "-paramIniz_X")
		{
			paramIniz_X[0] = atoi(argv[i+1]);
			paramIniz_X[1] = atoi(argv[i+2]);
			fai_da_te_x=true;
			i+=2;
		}
		else if (string(argv[i]) == "-paramIniz_Y")
		{
			paramIniz_Y[0] = atoi(argv[i+1]);
			paramIniz_Y[1] = atoi(argv[i+2]);
			fai_da_te_y=true;
			i+=2;
		}
#endif
		else
		{
			printf("Impossibile riconoscere il parametro %s\n",argv[i]);
		}
	}

	string utile_per_contare;
	int conta_righe_parametri = 0;
	if (fallita_lettura_parametri || fallita_lettura_inputdistr)
	{
		printf("Impossibile aprire (o non definito) il file contenente i parametri\no il file contenente la distribuzione/particella iniziale\n");
		exit(204);
	}

	double * dati_iniziali = new double[6];	// emittanza, energia, x, y, px, py
	for (int i = 0; i < 6; i++)
	{
		if(inputdistr.eof())
		{
			printf("Mancano dei dati iniziali!\n");
			exit(123);
		}
		inputdistr >> dati_iniziali[i];
	}
	inputdistr.clear();
	inputdistr.seekg(0,std::ios::beg);

	double emittanza = dati_iniziali[0];
	double energia = dati_iniziali[1];
	double *vett_i=new double[4];
	vett_i[0]=dati_iniziali[2];
	vett_i[1]=dati_iniziali[4];
	vett_i[2]=dati_iniziali[3];
	vett_i[3]=dati_iniziali[5];

	do
	{
		parametri >> utile_per_contare;
		if(parametri.eof()) break;
		parametri.ignore(1000, '\n');
		conta_righe_parametri++;
	}
	while(!parametri.eof());
	parametri.clear();
	parametri.seekg(0,std::ios::beg);

	// qui di leggono tutti i dati
//	char *elemento=new char[conta_righe_parametri];
	string *elemento=new string[conta_righe_parametri];
	double * lunghezza= new double[conta_righe_parametri];
	double * gradiente= new double[conta_righe_parametri];
	int contatore=0;
	for (int i = 0; i < conta_righe_parametri; i++)
	{
		parametri >> elemento[i];
		parametri >> gradiente[i];
		parametri >> lunghezza[i];
#ifdef DEBUG
		cout << "Tipo elemento: " << elemento[i] << ", gradiente: " << gradiente[i] << ", lunghezza: " << lunghezza[i] << endl;
#endif
		contatore++;
	}

#ifdef DEBUG
	printf("contatore: %d",contatore);
#endif

	vector <vector <double> > I(4,vector<double>(4,0.0));
	vector <vector <double> > K(4,vector<double>(4,0.0));
	vector <vector <double> > F(4,vector<double>(4,0.0));
	vector <vector <vector <double> > > Fx(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));
	vector <vector <vector <double> > > Dx(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));
	vector <vector <vector <double> > > OI(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));
	vector <vector <vector <double> > > FxI(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));
	vector <vector <vector <double> > > DxI(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));
	vector <vector <vector <double> > > O(contatore,vector <vector <double> > (4, vector <double> (4,0.0)));

	double *alpha = new double[2];
	double *beta = new double[2];
	double *aminmax = new double[2];
	double *bminmax = new double[2];
	bool alpha_calcolato_con_successo=false;
	bool beta_calcolato_con_successo=false;

#ifdef TEST_OPTICAL_FUNCTIONS
	double *ottiche_x_t = new double[2];
	double *ottiche_y_t = new double[2];
	double *aminmax_x_t = new double[2];
	double *bminmax_y_t = new double[2];
	for (int i = 0; i < 2; i++) ottiche_x_t[i] = ottiche_y_t[i] = aminmax_x_t[i] = bminmax_y_t[i] = 0.;
#endif


	double gamma_beta=sqrt(2.0*energia/MP_MEV);
	double gamma_v=gamma_beta*SPEED_OF_LIGHT;
	double *f1 =new double [contatore];
	double *d1 =new double [contatore];
	for (int i=0;i<contatore;i++)
	{
		if (elemento[i]=="F")
			f1[i]=sqrt(gradiente[i]*CHARGE/(MP_KG*gamma_v));
		if (elemento[i]=="D")
			d1[i]=sqrt(gradiente[i]*CHARGE/(MP_KG*gamma_v));
	}

#ifdef DEBUG
	for (int i=0;i<contatore;i++)
	{
		fprintf(outputDEBUG,"\ngrad. foc.    %+20.10f ", f1[i]*f1[i]);
		fprintf(outputDEBUG,"\ngrad. defoc.  %+20.10f ", d1[i]*d1[i]);
	}
#endif

	for (int i=0;i<contatore;i++)
	{
#ifdef DEBUG
		if (elemento[i]=="F")
			Fx[i]=focusing(Fx[i],f1[i],lunghezza[i],matrici_iniziali,i);
		else if (elemento[i]=="D")
			Dx[i]=defocusing(Dx[i],d1[i],lunghezza[i],matrici_iniziali,i);
		else if (elemento[i]=="O")
			O[i]=drift(O[i],lunghezza[i],matrici_iniziali,i);
		else
			fprintf(outputDEBUG,"Elemento[%d] non riconosciuto\n", i);
#else
		if (elemento[i]=="F")
			Fx[i]=focusing(Fx[i],f1[i],lunghezza[i]);
		else if (elemento[i]=="D")
			Dx[i]=defocusing(Dx[i],d1[i],lunghezza[i]);
		else if (elemento[i]=="O")
			O[i]=drift(O[i],lunghezza[i]);
#endif
	}

#ifdef DEBUG

	for (int i=0;i<contatore;i++)
	{
		if (elemento[i]=="O")
		{
//			if (O[i][0][0] == 0.0) continue;
			fprintf(matrici_iniziali,"\nMATRICE DRIFT");
			scrivimatr2D(O[i],matrici_iniziali);
			fprintf(matrici_iniziali,"\n");
		}
		else if (elemento[i]=="F")
		{
//			if (Fx[i][0][0] == 0.0) continue;
			fprintf(matrici_iniziali,"\nMATRICE FOC.");
			scrivimatr2D(Fx[i],matrici_iniziali);
			fprintf(matrici_iniziali,"\n");
		}
		else if (elemento[i]=="D")
		{
//			if (Dx[i][0][0] == 0.0) continue;
			fprintf(matrici_iniziali,"\nMATRICE DEFOC.");
			scrivimatr2D(Dx[i],matrici_iniziali);
			fprintf(matrici_iniziali,"\n");
		}

	}

#endif	

/************************************************************************/
	
	if (do_optics)
	{
		vector <vector <double> > compos(4,vector<double>(4,0));

		if (elemento[0]=="O")
		{
			for (int k=0; k<4; k++)
				for (int j=0; j<4; j++)
					compos[k][j]=O[0][k][j];
		}
		else if (elemento[0]=="F")
		{
			for (int k=0; k<4; k++)
				for (int j=0; j<4; j++)
					compos[k][j]=Fx[0][k][j];
		}
		else if (elemento[0]=="D")
		{
			for (int k=0; k<4; k++)
				for (int j=0; j<4; j++)
					compos[k][j]=Dx[0][k][j];
		}

		for (int i=1;i<contatore;i++)
		{
			if (elemento[i]=="O")
				compos=prodo(O[i],compos,4);
			else if (elemento[i]=="F")
				compos=prodo(Fx[i],compos,4);
			else if (elemento[i]=="D")
				compos=prodo(Dx[i],compos,4);
		}
	
		for (int i=0;i<4;i++)
			for(int a=0;a<4;a++)
				F[i][a]=compos[i][a];

//		Calcolo Funzioni OTTICHE

		for (int i = 0; i < 2; i++) alpha[i] = beta[i] = aminmax[i] = bminmax[i] = 0.;

		if ( (fabs((F[FOC][FOC]+F[FOC+1][FOC+1])*0.5) <= 1.) && (fabs((F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])*0.5) <= 1.))
			posso_fare_funzioni_ottiche = true;
		else cout << "Impossibile calcolare le funzioni ottiche!" << endl;
		//cout << "posso_fare_funzioni_ottiche="<<posso_fare_funzioni_ottiche<<endl;

		//if ((((F[FOC][FOC]+F[FOC+1][FOC+1])*(F[FOC][FOC]+F[FOC+1][FOC+1])-4)<=0) && (((F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])*(F[DEFOC][DEFOC]+F[DEFOC+1][DEFOC+1])-4)<=0) )
		//		posso_fare_funzioni_ottiche = true;
		//else cout << "Impossibile calcolare le funzioni ottiche!" << endl;
		if (posso_fare_funzioni_ottiche)
		{
			alpha=optics(F,FOC,&alpha_calcolato_con_successo);
			beta=optics(F,DEFOC,&beta_calcolato_con_successo);
			aminmax = assi_ellissi(alpha, emittanza);
			bminmax = assi_ellissi(beta, emittanza);

			if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt);
			if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos);
			if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell);
			fprintf(funzioni_ottiche,"# alpha_successo %d beta_successo %d\n",(int)(alpha_calcolato_con_successo),(int)(beta_calcolato_con_successo));
			if (alpha_calcolato_con_successo&&beta_calcolato_con_successo)
			{
				fprintf(funzioni_ottiche,"\n#%7c",'S');
				fprintf(funzioni_ottiche,"%10.8s","Alpha x");
				fprintf(funzioni_ottiche,"%10.7s","Beta x");
				fprintf(funzioni_ottiche,"%12.8s","Alpha y");
				fprintf(funzioni_ottiche,"%10.7s","Beta y");
				fprintf(ellissi,"%10s","x");
				fprintf(ellissi,"%11s","p_x");
				fprintf(ellissi,"%11s","y");
				fprintf(ellissi,"%11s","p_y");
			}

			scrividati(0.0,alpha,beta,funzioni_ottiche);
			scrividati_ellissi(0.0,aminmax,bminmax,ellissi);


#ifdef TEST_OPTICAL_FUNCTIONS
			for (int i=0;i<2;i++)
			{
				if (fai_da_te_x&&fai_da_te_y)
				{
					ottiche_x_t[i]=paramIniz_X[i];
					ottiche_y_t[i]=paramIniz_Y[i];
				}
				else if (fai_da_te_x)
				{
					ottiche_x_t[i]=paramIniz_X[i];
					ottiche_y_t[i]=paramIniz_X[i];

				}
				else if (fai_da_te_y)
				{
					ottiche_x_t[i]=paramIniz_Y[i];
					ottiche_y_t[i]=paramIniz_Y[i];
				}
				else
				{
					ottiche_x_t[i]=alpha[i];
					ottiche_y_t[i]=beta[i];
				}
			}
			aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza);
			bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza);
			scrividati(0.0,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t);
			scrividati_ellissi(0.0,aminmax_x_t,bminmax_y_t,ellissi_t);
			if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T);
#endif
		}
	}

	if(do_transport)
	{
		fprintf(posizionePart," %+10.5f",0.0);
		fprintf(posizionePart," %+10.5f",vett_i[0]);
		fprintf(posizionePart," %+10.5f",vett_i[1]);
		fprintf(posizionePart," %+10.5f",vett_i[2]);
		fprintf(posizionePart," %+10.5f\n",vett_i[3]);
	}
#ifdef DEBUG
		fprintf(outputDEBUG, "\nFODO:");
		scrivimatr2D(F,outputDEBUG);
#endif

/************************************************************************/

//ora primi dell'iterazione mi calcolo le micromappe Li di lunghezza S=L/n

	double lunghezzatotale=0.;
	for (int i = 0 ;i < contatore;i++)
		lunghezzatotale+=lunghezza[i];

#ifdef DEBUG
	for (int i=0; i < contatore; i++)
	{
		fprintf(outputDEBUG,"\n#step in elemento %d = %d",i, dsMap(lunghezza[i],lunghezzatotale,nstep));
	}
	fprintf(outputDEBUG,"\n");
#endif

	double S = 0.;
	//Calcolo MICROMAPPE per il Drift
	for (int i=0; i < contatore; i++)
	{
		S=lunghezza[i]/dsMap(lunghezza[i],lunghezzatotale,nstep);
#ifdef DEBUG
		if (elemento[i] == "O")
		{
			O[i]=drift(O[i],S,matrici_iniziali,i);
			OI[i]=drift(OI[i],-S,matrici_iniziali,i);
		}
		else if (elemento[i] == "F")
		{
			Fx[i]=focusing(Fx[i],f1[i],S,matrici_iniziali,i);
			FxI[i]=focusing(FxI[i],f1[i],-S,matrici_iniziali,i);
		}
		else if (elemento[i] == "D")
		{
			Dx[i]=defocusing(Dx[i],d1[i],S,matrici_iniziali,i);
			DxI[i]=defocusing(DxI[i],d1[i],-S,matrici_iniziali,i);
		}
#else
		if (elemento[i] == "O")
		{
			O[i]=drift(O[i],S);
			OI[i]=drift(OI[i],-S);
		}
		else if (elemento[i] == "F")
		{
			Fx[i]=focusing(Fx[i],f1[i],S);
			FxI[i]=focusing(FxI[i],f1[i],-S);
		}
		else if (elemento[i] == "D")
		{
			Dx[i]=defocusing(Dx[i],d1[i],S);
			DxI[i]=defocusing(DxI[i],d1[i],-S);
		}
#endif
	}

/***********************************************************************/


	double dl=0.;
	double lunghezza_accumulata=0.0;

	for (int i=0;i<contatore;i++)
	{
		dl=lunghezza[i]/dsMap(lunghezza[i],lunghezzatotale,nstep);
		if (elemento[i]=="O")
		{
			fprintf(matrici_iniziali,"\n#Drift #%d, dl = %f",i,dl);
			fprintf(funzioni_ottiche,"\n#Drift #%d, dl = %f",i,dl);
			while(S<=(lunghezza_accumulata+lunghezza[i]))
			{
				fprintf(matrici_iniziali,"\n\n Num_Step %f", S);
				scrivimatr2D(F,matrici_iniziali);
				if (do_transport)
				{
#ifdef DEBUG
					prod(vett_i,O[i],S);
#else
					prod(vett_i,O[i]);
#endif
					if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos);
					scrivi_pos_part(posizionePart,vett_i,S);
				}
				if (do_optics)
				{
					F=simil(F,OI[i],O[i]);
					if (posso_fare_funzioni_ottiche)
					{	
					alpha=optics(F,FOC,&alpha_calcolato_con_successo);
					beta=optics(F,DEFOC,&beta_calcolato_con_successo);
					aminmax = assi_ellissi(alpha, emittanza);
					bminmax = assi_ellissi(beta, emittanza);
					confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto);
					confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto);
					scrividati(S,alpha,beta,funzioni_ottiche);
					scrividati_ellissi(S,aminmax,bminmax,ellissi);
					if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell);
					if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt);
#ifdef TEST_OPTICAL_FUNCTIONS
					ottiche_x_t=optics_T(ottiche_x_t,FOC,O[i]);
					ottiche_y_t=optics_T(ottiche_y_t,DEFOC,O[i]);
					aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza);
					bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza);
					confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x);
					confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y);
					scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t);
					scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t);	
					if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T);
#endif
					}
				}
				S+=dl;
			}
			lunghezza_accumulata+=lunghezza[i];
		}
		else if (elemento[i]=="F")
		{
			fprintf(matrici_iniziali,"\n#Foc. #%d, dl = %f",i,dl);			
			fprintf(funzioni_ottiche,"\n#Foc. #%d, dl = %f",i,dl);
			while(S<=(lunghezza_accumulata+lunghezza[i]))
			{
				fprintf(matrici_iniziali,"\n\n Num_Step %f", S);
				scrivimatr2D(F,matrici_iniziali);
				if (do_transport)
				{
#ifdef DEBUG
					prod(vett_i,Fx[i],S);
#else
					prod(vett_i,Fx[i]);
#endif
					if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos);
					scrivi_pos_part(posizionePart,vett_i,S);
				}
				if (do_optics)
				{
					if (posso_fare_funzioni_ottiche)
					{
						F=simil(F,FxI[i],Fx[i]);
						alpha=optics(F,FOC,&alpha_calcolato_con_successo);
						beta=optics(F,DEFOC,&beta_calcolato_con_successo);		
						aminmax = assi_ellissi(alpha, emittanza);
						bminmax = assi_ellissi(beta, emittanza);
						confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto);
						confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto);
						scrividati(S,alpha,beta,funzioni_ottiche);
						scrividati_ellissi(S,aminmax,bminmax,ellissi);
						if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell);
						if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt);
#ifdef TEST_OPTICAL_FUNCTIONS
						ottiche_x_t=optics_T(ottiche_x_t,FOC,Fx[i]);
						ottiche_y_t=optics_T(ottiche_y_t,DEFOC,Fx[i]);
						aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza);
						bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza);
						confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x);
						confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y);
						scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t);
						scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t);
						if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T);
#endif
					}
				}
				S+=dl;
			}
			lunghezza_accumulata+=lunghezza[i];
		}
		else if (elemento[i]=="D")
		{
			fprintf(matrici_iniziali,"\n#Defoc. #%d, dl = %f",i,dl);
			fprintf(funzioni_ottiche,"\n#Defoc. #%d, dl = %f",i,dl);
			while (S<=(lunghezza_accumulata+lunghezza[i]))
			{
				fprintf(matrici_iniziali,"\n\n Num_Step %f", S);
				scrivimatr2D(F,matrici_iniziali);
				if (do_transport)
				{
#ifdef DEBUG
					prod(vett_i,Dx[i],S);
#else
					prod(vett_i,Dx[i]);
#endif
					if (calcola_ymax_pos) massimo_pos(vett_i,&gnuplot_ymax_pos);
					scrivi_pos_part(posizionePart,vett_i,S);
				}
				if (do_optics)
				{
					if (posso_fare_funzioni_ottiche)
					{
						F=simil(F,DxI[i],Dx[i]);
						alpha=optics(F,FOC,&alpha_calcolato_con_successo);
						beta=optics(F,DEFOC,&beta_calcolato_con_successo);
						aminmax = assi_ellissi(alpha, emittanza);
						bminmax = assi_ellissi(beta, emittanza);
						confronto(compare_x,aminmax,S,percentuale,confronti,&confronto_pos_x,&conto_per_confronto);
						confronto(compare_y,bminmax,S,percentuale,confronti,&confronto_pos_y,&conto_per_confronto);
						scrividati(S,alpha,beta,funzioni_ottiche);
						scrividati_ellissi(S,aminmax,bminmax,ellissi);
						if (calcola_ymax_ell) massimo_opt(aminmax,bminmax,&gnuplot_ymax_ell);
						if (calcola_ymax_opt) massimo_opt(alpha,beta,&gnuplot_ymax_opt);
#ifdef TEST_OPTICAL_FUNCTIONS
						ottiche_x_t=optics_T(ottiche_x_t,FOC,Dx[i]);
						ottiche_y_t=optics_T(ottiche_y_t,DEFOC,Dx[i]);
						aminmax_x_t = assi_ellissi(ottiche_x_t, emittanza);
						bminmax_y_t = assi_ellissi(ottiche_y_t, emittanza);
						confronto(paramIniz_X,aminmax_x_t,S,percentuale,confronti_t,&confronto_pos_t_x,&conto_per_confronto_t_x);
						confronto(paramIniz_Y,bminmax_y_t,S,percentuale,confronti_t,&confronto_pos_t_y,&conto_per_confronto_t_y);
						scrividati(S,ottiche_x_t,ottiche_y_t,funzioni_ottiche_t);
						scrividati_ellissi(S,aminmax_x_t,bminmax_y_t,ellissi_t);
						if (calcola_ymax_opt_T) massimo_opt(ottiche_x_t,ottiche_y_t,&gnuplot_ymax_opt_T);
#endif
						}
					}
				S+=dl;
			}
			lunghezza_accumulata+=lunghezza[i];
		}
	}

	fclose(funzioni_ottiche);
	fclose(matrici_iniziali);
	fclose(posizionePart);
	fclose(ellissi);
	fclose(confronti);
	parametri.close();
	inputdistr.close();

#ifdef TEST_OPTICAL_FUNCTIONS
	fclose(funzioni_ottiche_t);
	fclose(ellissi_t);
#endif

	string *etichette_posizione = new string[8];
	string *etichette_ottiche = new string[8];
	string *etichette_ellissi = new string[8];
#ifdef TEST_OPTICAL_FUNCTIONS
	string *etichette_ottiche_T = new string[8];
	string *etichette_ellissi_T = new string[8];
#endif

	etichette_posizione[0] = "Posizione_Particelle";
	etichette_posizione[1] = "Posizione Particelle";
	etichette_posizione[2] = "z (m)";
	etichette_posizione[3] = "x/y (m), p_x/p_y";
	etichette_posizione[4] = "x";
	etichette_posizione[5] = "y";
	etichette_posizione[6] = "p_x";
	etichette_posizione[7] = "p_y";

	etichette_ottiche[0] = "Funzioni_Ottiche";
	etichette_ottiche[1] = "Funzioni Ottiche";
	etichette_ottiche[2] = "z (m)";
#if defined (CREATE_EPS)
	etichette_ottiche[3] = "{/Symbol a}, {/Symbol b}";
	etichette_ottiche[4] = "{/Symbol a}_x";
	etichette_ottiche[5] = "{/Symbol a}_y";
	etichette_ottiche[6] = "{/Symbol b}_x";
	etichette_ottiche[7] = "{/Symbol b}_y";
#else
	etichette_ottiche[3] = "Alpha, Beta";
	etichette_ottiche[4] = "Alpha_x";
	etichette_ottiche[5] = "Alpha_y";
	etichette_ottiche[6] = "Beta_x";
	etichette_ottiche[7] = "Beta_y";
#endif

	etichette_ellissi[0] = "Parametri_Ellissi_Funz_Ottiche";
	etichette_ellissi[1] = "Parametri Ellissi Funz Ottiche";
	etichette_ellissi[2] = "z (m)";
	etichette_ellissi[3] = "X , P";
	etichette_ellissi[4] = "Xmax";
	etichette_ellissi[5] = "Pmax_x";
	etichette_ellissi[6] = "Ymax";
	etichette_ellissi[7] = "Pmax_y";

#ifdef TEST_OPTICAL_FUNCTIONS
	etichette_ottiche_T[0] = "Funzioni_Ottiche_T";
	etichette_ottiche_T[1] = "Funzioni ottiche test";
	etichette_ottiche_T[2] = "z (m)";
#if defined (CREATE_EPS)
	etichette_ottiche_T[3] = "{/Symbol a}, {/Symbol b}";
	etichette_ottiche_T[4] = "{/Symbol a}_x";
	etichette_ottiche_T[5] = "{/Symbol a}_y";
	etichette_ottiche_T[6] = "{/Symbol b}_x";
	etichette_ottiche_T[7] = "{/Symbol b}_y";
#else
	etichette_ottiche_T[3] = "Alpha, Beta";
	etichette_ottiche_T[4] = "Alpha_x";
	etichette_ottiche_T[5] = "Alpha_y";
	etichette_ottiche_T[6] = "Beta_x";
	etichette_ottiche_T[7] = "Beta_y";
#endif

	etichette_ellissi_T[0] = "Parametri_Ellissi_Funz_Ottiche_T";
	etichette_ellissi_T[1] = "Parametri Ellissi Funz Ottiche_T";
	etichette_ellissi_T[2] = "z (m)";
	etichette_ellissi_T[3] = "X , P";
	etichette_ellissi_T[4] = "Xmax";
	etichette_ellissi_T[5] = "Pmax_x";
	etichette_ellissi_T[6] = "Ymax";
	etichette_ellissi_T[7] = "Pmax_y";
#endif

/***********************************************************/

	//cout << "conto_per_confronto= "<<conto_per_confronto;
	double *dati_rilevati=new double [conto_per_confronto];
	for (int a=0;a<conto_per_confronto;a++)
		dati_rilevati[a]=0.;
	if (confronto_pos_x||confronto_pos_y)
	{
		ifstream confro;
		confro.open("Math_rilevati.txt");
		for (int i=0;i<conto_per_confronto;i++)
		{
			confro >> dati_rilevati[i];
		}
	}