Пример #1
0
int main(void)
{
    naive((int *)arr1, 5, 3);
    naive((int *)arr2, 3, 2);
    dynamic((int *)arr1, 5, 3);
    dynamic((int *)arr2, 3, 2);
	return 0;
}
Пример #2
0
bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
    GrAssert(fBufferID);
    GrAssert(!isLocked());
    if (srcSizeInBytes > this->sizeInBytes()) {
        return false;
    }
    this->bind();
    GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
#if !GR_GL_USE_BUFFER_DATA_NULL_HINT
    // Note that we're cheating on the size here. Currently no methods
    // allow a partial update that preserves contents of non-updated
    // portions of the buffer (and lock() does a glBufferData(..size, NULL..))
    GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
#else
    if (this->sizeInBytes() == srcSizeInBytes) {
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
    } else {
        // Before we call glBufferSubData we give the driver a hint using
        // glBufferData with NULL. This makes the old buffer contents
        // inaccessible to future draws. The GPU may still be processing draws
        // that reference the old contents. With this hint it can assign a
        // different allocation for the new contents to avoid flushing the gpu
        // past draws consuming the old contents.
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, 
                           this->sizeInBytes(), NULL, usage));
        GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
    }
#endif
    return true;
}
Пример #3
0
void MSWidget::set(MSAttrValueList& avList_)
{
  MSIndexVector index;
  for (unsigned i=0;i<avList_.length();i++)
   {
     if (avList_[i].attribute()=="foreground")
      foreground(avList_[i].value()),index<<i;
     else if (avList_[i].attribute()=="background")
      background(avList_[i].value()),index<<i;
     else if (avList_[i].attribute()=="font")
      font(avList_[i].value()),index<<i;
     else if (avList_[i].attribute()=="acceptFocus")
      acceptFocus(avList_[i].value().asBoolean()),index<<i;
     else if (avList_[i].attribute()=="dynamic")
      dynamic(avList_[i].value().asBoolean()),index<<i;
     else if (avList_[i].attribute()=="sensitive")
      sensitive(avList_[i].value().asBoolean()),index<<i;
     else if (avList_[i].attribute()=="readOnly")
      readOnly(avList_[i].value().asBoolean()),index<<i;
     else if (avList_[i].attribute()=="at")
      at(At(avList_[i].value())),index<<i;
     else if (avList_[i].attribute()=="resizeConstraints")
      resizeConstraints(avList_[i].value()),index<<i;
   } 
  avList_.remove(index);
}
Пример #4
0
int main()
{
    int input;
    scanf("%d",&input);

    printf("%d\n",dynamic(input));
    return 0;
}
Пример #5
0
void WideString::allocate(size_t size) {
	if(!dynamic() && size <= capacity()) {
		m_static[size] = L'\0';
		m_size = size;
	} else {
		allocateDynamic(size);
	}
}
Пример #6
0
void WideString::resize(size_t newSize) {
	size_t oldSize = size();
	if(newSize != oldSize) {
		allocate(newSize);
		if(!dynamic() && newSize > oldSize) {
			std::fill(m_static + oldSize, m_static + newSize, L'\0');
		}
	}
}
Пример #7
0
int dynamic(int input)
{
    if(input == 1)
    {
        memo[input] = 1;
        return memo[input];
    }
    if(input == 2)
    {
        memo[input] =2;
        return memo[input];
    }

    if(memo[input] > 0)
        return memo[input]%10007;
    memo[input] = dynamic(input-1) + dynamic(input-2);
    
    return memo[input]%10007;;
}
Пример #8
0
void WideString::allocateDynamic(size_t size) {
	if(dynamic()) {
		str().resize(size, L'\0');
	} else {
		WCHAR backup[ARRAY_SIZE(m_static)];
		std::copy(m_static, m_static + m_size, backup);
		new (reinterpret_cast<char *>(&m_dynamic)) DynamicType(size, L'\0');
		std::copy(backup, backup + m_size, str().begin());
		m_size = size_t(-1);
	}
}
void* GrGLVertexBuffer::lock() {
    GrAssert(fBufferID);
    GrAssert(!isLocked());
    if (GPUGL->supportsBufferLocking()) {
        this->bind();
        // Let driver know it can discard the old data
        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, size(), NULL,
                         dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
        fLockPtr = GR_GL(MapBuffer(GR_GL_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
        return fLockPtr;
    }
    return NULL;
}
Пример #10
0
ValueType BandedScore <Src1SymbolType, Src2SymbolType, DestSymbolType, ValueType, AveType, GapType>
::eval (const Src1SymbolType* seq1, unsigned len1, const Src2SymbolType* seq2, unsigned len2, unsigned len, unsigned dev)
{
    seq1_ = seq1;
    seq2_ = seq2;
    len1_ = len1;
    len2_ = len2;
    len_  = len ? len : std::max (len1_, len2_);
    dev_  = dev ? dev : (diff__ (len1_, len2_) + DEF_MIN_DEV);
    wid_ = wid ();
    dynamic ();
    return bestWeight_;
}
Пример #11
0
void WideString::assign(const char * utf8, size_t utf8_length) {
	if(!dynamic() && utf8_length <= capacity()) {
		// Optimistically assume that the wide length is not longer than the utf8 length
		INT length = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8_length, m_static, capacity());
		if(length || !utf8_length) {
			m_static[length] = L'\0';
			m_size = length;
			return;
		}
	}
	INT length = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8_length, NULL, 0);
	allocate(length);
	MultiByteToWideChar(CP_UTF8, 0, utf8, utf8_length, data(), length);
}
bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
    GrAssert(fBufferID);
    GrAssert(!isLocked());
    if (srcSizeInBytes > this->sizeInBytes()) {
        return false;
    }
    this->bind();
    GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;

#if GR_GL_USE_BUFFER_DATA_NULL_HINT
    if (this->sizeInBytes() == srcSizeInBytes) {
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
    } else {
        // Before we call glBufferSubData we give the driver a hint using
        // glBufferData with NULL. This makes the old buffer contents
        // inaccessible to future draws. The GPU may still be processing
        // draws that reference the old contents. With this hint it can
        // assign a different allocation for the new contents to avoid
        // flushing the gpu past draws consuming the old contents.
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER,
                           this->sizeInBytes(), NULL, usage));
        GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
    }
#else
    // Note that we're cheating on the size here. Currently no methods
    // allow a partial update that preserves contents of non-updated
    // portions of the buffer (lock() does a glBufferData(..size, NULL..))
    bool doSubData = false;
#if GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND
    static int N = 0;
    // 128 was chosen experimentally. At 256 a slight hitchiness was noticed
    // when dragging a Chromium window around with a canvas tab backgrounded.
    doSubData = 0 == (N % 128);
    ++N;
#endif
    if (doSubData) {
        // The workaround is to do a glBufferData followed by glBufferSubData.
        // Chromium's command buffer may turn a glBufferSubData where the size
        // exactly matches the buffer size into a glBufferData. So we tack 1
        // extra byte onto the glBufferData.
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes + 1,
                           NULL, usage));
        GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
    } else {
        GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
    }
#endif
    return true;
}
bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
    GrAssert(fBufferID);
    GrAssert(!isLocked());
    if (srcSizeInBytes > size()) {
        return false;
    }
    this->bind();
    GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
    if (size() == srcSizeInBytes) {
        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
    } else {
        GR_GL(BufferData(GR_GL_ARRAY_BUFFER, size(), NULL, usage));
        GR_GL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
    }
    return true;
}
Пример #14
0
MSAttrValueList& MSWidget::get(MSAttrValueList& avList_)
{
  MSStringVector aStringVector("MSFalse\nMSTrue");
  
  avList_<<MSAttrValue("foreground",_server->colorName(foreground()),MSAttrValue::Color);
  avList_<<MSAttrValue("background",_server->colorName(background()),MSAttrValue::Color);  
  avList_<<MSAttrValue("font",_server->fontName(font()),MSAttrValue::Font); 
  avList_<<MSAttrValue("acceptFocus",aStringVector(acceptFocus()),aStringVector);
  avList_<<MSAttrValue("sensitive",aStringVector(sensitive()),aStringVector);
  avList_<<MSAttrValue("readOnly",aStringVector(readOnly()),aStringVector);
  avList_<<MSAttrValue("dynamic",aStringVector(dynamic()),aStringVector);
  At aAt=at();
  avList_<<MSAttrValue("resizeConstraints",aAt.parsedConstraints(),MSAttrValue::String);  
  avList_<<MSAttrValue("at",aAt.asString(),MSAttrValue::String);
  avList_<<MSAttrValue("destroy","",MSAttrValue::Callback);
  avList_<<MSAttrValue("takefocus","",MSAttrValue::Callback);  
  return avList_;
}
Пример #15
0
void oneMinuteExample()
{
	TH0 = (65536 - myTIME) / 256;
	TL0 = (65536 - myTIME) % 256;

	IE = 0x82;
	TMOD = 0X01;
	TCON = 0x10;

	for (;;)
	{
		if (num >= 20)
		{
			num = 0;
			count++;
			if (count >= 60)
				count = 0;
			cha[6] = count / 10;
			cha[7] = count % 10;
		}
		dynamic(cha, boo);
	}
}
Пример #16
0
/**
 * Program entry point. Constructs and launches the main program object.
 */
int main(int argc, char *argv[])
{
    Pool pool = pool_init(0x10000); /* 64K block size */
    Options opt = options_init();
    Source *in;
    Scope *scope = scope_new(&pool, 0);
    ListBuilder code = list_builder_init(&pool);

    /* Read the options: */
    if (!options_parse(&opt, argc, argv)) {
        options_usage(argv[0]);
        goto error;
    }

    /* Determine output file name: */
    if (!string_size(opt.name_out)) {
        if (string_rmatch(opt.name_in, string_from_k(".ol")) != 3) {
            fprintf(stderr, "error: If no output file is specified, the input file name must end with \".ol\".\n");
            goto error;
        }
        opt.name_out = string(opt.name_in.p, opt.name_in.end - 3);
    }

    /* Input stream: */
    in = source_load(&pool, opt.name_in);
    if (!in) {
        fprintf(stderr, "error: Could not open source file \"%s\"\n", opt.name_in.p);
        goto error;
    }

    /* Keywords: */
    scope_add(scope, &pool, string_from_k("macro"), dynamic(type_keyword,
              keyword_new(&pool, parse_macro)));
    scope_add(scope, &pool, string_from_k("outline"), dynamic(type_keyword,
              keyword_new(&pool, parse_outline)));
    scope_add(scope, &pool, string_from_k("union"), dynamic(type_keyword,
              keyword_new(&pool, parse_union)));
    scope_add(scope, &pool, string_from_k("map"), dynamic(type_keyword,
              keyword_new(&pool, parse_map)));
    scope_add(scope, &pool, string_from_k("for"), dynamic(type_keyword,
              keyword_new(&pool, parse_for)));
    scope_add(scope, &pool, string_from_k("include"), dynamic(type_keyword,
              keyword_new(&pool, parse_include)));

    /* Do outline2c stuff: */
    if (!parse_code(&pool, in, scope, out_list_builder(&code))) goto error;
    if (opt.debug) {
        printf("--- AST: ---\n");
        dump_code(code.first, 0);
        printf("\n");
    }
    if (!main_generate(&pool, code.first, &opt)) goto error;

    /* Clean up: */
    pool_free(&pool);
    return 0;

error:
    pool_free(&pool);
    return 1;
}
Пример #17
0
int
main(int argc, char** argv)
{
	register char*		s;
	register Rule_t*	r;
	register List_t*	p;
	int			i;
	int			args;
	int			trace;
	char*			t;
	char*			buf;
	char*			tok;
	Var_t*			v;
	Stat_t			st;
	Stat_t			ds;
	Sfio_t*			tmp;

	/*
	 * initialize dynamic globals
	 */

	version = strdup(fmtident(version));
	setlocale(LC_ALL, "");
	error_info.id = idname;
	error_info.version = version;
	error_info.exit = finish;
	error_info.auxilliary = intercept;
	if (pathcheck(PATHCHECK, error_info.id, NiL))
		return 1;
	error(-99, "startup");
	settypes("*?[]", C_MATCH);
	settypes("+-|=", C_OPTVAL);
	settypes(" \t\n", C_SEP);
	settype(0, C_SEP);
	settypes(" \t\v\n:+&=;\"\\", C_TERMINAL);
	settype(0, C_TERMINAL);
	settypes("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", C_ID1|C_ID2|C_VARIABLE1|C_VARIABLE2);
	settypes(".", C_VARIABLE1|C_VARIABLE2);
	settypes("0123456789", C_ID2|C_VARIABLE2);

	/*
	 * close garbage fd's -- we'll be tidy from this point on
	 * 3 may be /dev/tty on some systems
	 * 0..9 for user redirection in shell
	 * 10..19 left open by bugs in some shells
	 * error_info.fd interited from parent
	 * any close-on-exec fd's must have been done on our behalf
	 */

	i = 3;
	if (isatty(i))
		i++;
	for (; i < 20; i++)
		if (i != error_info.fd && !fcntl(i, F_GETFD, 0))
			close(i);

	/*
	 * allocate the very temporary buffer streams
	 */

	internal.met = sfstropen();
	internal.nam = sfstropen();
	internal.tmp = sfstropen();
	internal.val = sfstropen();
	internal.wrk = sfstropen();
	tmp = sfstropen();
	sfstrrsrv(tmp, 2 * MAXNAME);

	/*
	 * initialize the code and hash tables
	 */

	initcode();
	inithash();

	/*
	 * set the default state
	 */

	state.alias = 1;
	state.exec = 1;
	state.global = 1;
	state.init = 1;
#if DEBUG
	state.intermediate = 1;
#endif
	state.io[0] = sfstdin;
	state.io[1] = sfstdout;
	state.io[2] = sfstderr;
	state.jobs = 1;
	state.pid = getpid();
	state.readstate = MAXVIEW;
	state.scan = 1;
	state.start = CURTIME;
	state.stateview = -1;
	state.tabstops = 8;
	state.targetview = -1;
#if BINDINDEX
	state.view[0].path = makerule(".");
#else
	state.view[0].path = ".";
#endif
	state.view[0].pathlen = 1;
	state.writeobject = state.writestate = "-";

	/*
	 * pwd initialization
	 *
	 * for project management, if . is group|other writeable
	 * then change umask() for similar write protections
	 */

	buf = sfstrbase(tmp);
	internal.pwd = (s = getcwd(buf, MAXNAME)) ? strdup(s) : strdup(".");
	internal.pwdlen = strlen(internal.pwd);
	if (stat(".", &st))
		error(3, "cannot stat .");
	if (S_ISDIR(st.st_mode) && (st.st_mode & (S_IWGRP|S_IWOTH)))
		umask(umask(0) & ~(st.st_mode & (S_IWGRP|S_IWOTH)));

	/*
	 * set some variable default values
	 */

	hashclear(table.var, HASH_ALLOCATE);
	setvar(external.make, argv[0], V_import);
	t = "lib/make";
	setvar(external.lib, strdup((s = pathpath(t, argv[0], PATH_EXECUTE, buf, SF_BUFSIZE)) ? s : t), V_import);
	setvar(external.pwd, internal.pwd, V_import);
	setvar(external.version, version, V_import);
	hashset(table.var, HASH_ALLOCATE);

	/*
	 * read the environment
	 */

	readenv();
	if (v = getvar(external.nproc))
		state.jobs = (int)strtol(v->value, NiL, 0);
	if ((v = getvar(external.pwd)) && !streq(v->value, internal.pwd))
	{
		if (!stat(v->value, &st) && !stat(internal.pwd, &ds) && st.st_ino == ds.st_ino && st.st_dev == ds.st_dev)
		{
			free(internal.pwd);
			internal.pwd = strdup(v->value);
			internal.pwdlen = strlen(v->value);
		}
		else
		{
			v->property &= ~V_import;
			v->property |= V_free;
			v->value = strdup(internal.pwd);
		}
	}

	/*
	 * initialize the internal rule pointers
	 */

	initrule();

	/*
	 * read the static initialization script
	 */

	sfputr(tmp, initstatic, -1);
	parse(NiL, sfstruse(tmp), "initstatic", NiL);

	/*
	 * check and read the args file
	 */

	if (s = colonlist(tmp, external.args, 1, ' '))
	{
		i = fs3d(0);
		tok = tokopen(s, 1);
		while (s = tokread(tok))
			if (vecargs(vecfile(s), &argc, &argv) >= 0)
				break;
			else if (errno != ENOENT)
				error(1, "cannot read args file %s", s);
		tokclose(tok);
		fs3d(i);
	}
	state.argf = newof(0, int, argc, 0);

	/*
	 * set the command line options
	 * read the command line assignments
	 * mark the command line scripts and targets
	 */

	state.init = 0;
	state.readonly = 1;
	state.argv = argv;
	state.argc = argc;
	if ((args = scanargs(state.argc, state.argv, state.argf)) < 0)
		return 1;
	state.readonly = 0;
	state.init = 1;
	if (state.base)
		state.readstate = 0;
	if (state.compileonly)
	{
		state.forceread = 1;
		state.virtualdot = 0;
	}

	/*
	 * tone down the bootstrap noise
	 */

	if ((trace = error_info.trace) == -1)
		error_info.trace = 0;

	/*
	 * check explicit environment overrides
	 */

	if (s = colonlist(tmp, external.import, 1, ' '))
	{
		tok = tokopen(s, 1);
		while (s = tokread(tok))
		{
			if (i = *s == '!')
				s++;
			if (v = getvar(s))
			{
				if (i)
					v->property &= ~V_import;
				else
					v->property |= V_readonly;
			}
		}
		tokclose(tok);
	}

	/*
	 * set up the traps
	 */

	inittrap();

	/*
	 * announce the version
	 */

	if (error_info.trace < 0)
	{
		errno = 0;
		error(error_info.trace, "%s [%d %s]", version, state.pid, timestr(state.start));
	}

	/*
	 * initialize the views
	 */

	state.global = 0;
	state.user = 1;
	initview();

	/*
	 * check for mam
	 */

	if (state.mam.out)
	{
		if (!state.mam.statix || *state.mam.label)
			error_info.write = mamerror;
		if (state.mam.regress || state.regress)
		{
			sfprintf(state.mam.out, "%sinfo mam %s %05d\n", state.mam.label, state.mam.type, state.mam.parent);
			if (state.mam.regress)
				sfprintf(state.mam.out, "%sinfo start regression\n", state.mam.label);
		}
		else
		{
			sfprintf(state.mam.out, "%sinfo mam %s %05d 1994-07-17 %s\n", state.mam.label, state.mam.type, state.mam.parent, version);
			if (!state.mam.statix || *state.mam.label)
			{
				sfprintf(state.mam.out, "%sinfo start %lu\n", state.mam.label, CURTIME);
				if (!state.mam.root || streq(state.mam.root, internal.pwd))
					sfprintf(state.mam.out, "%sinfo pwd %s\n", state.mam.label, internal.pwd);
				else
					sfprintf(state.mam.out, "%sinfo pwd %s %s\n", state.mam.label, state.mam.root, mamname(makerule(internal.pwd)));
				buf = sfstrbase(tmp);
				if (state.fsview && !mount(NiL, buf, FS3D_GET|FS3D_ALL|FS3D_SIZE(sfstrsize(tmp)), NiL))
					sfprintf(state.mam.out, "%sinfo view %s\n", state.mam.label, buf);
			}
		}
	}

	/*
	 * read the dynamic initialization script
	 */

	if ((i = error_info.trace) > -20)
		error_info.trace = 0;
	sfputr(tmp, initdynamic, -1);
	parse(NiL, sfstruse(tmp), "initdynamic", NiL);
	error_info.trace = i;
	state.user = 0;
	state.init = 0;

	/*
	 * read the explicit makefiles
	 * readfile() handles the base and global rules
	 *
	 * NOTE: internal.tmplist is used to handle the effects of
	 *	 load() on internal list pointers
	 */

	compref(NiL, 0);
	if (p = internal.makefiles->prereqs)
	{
		p = internal.tmplist->prereqs = listcopy(p);
		for (; p; p = p->next)
			readfile(p->rule->name, COMP_FILE, NiL);
		freelist(internal.tmplist->prereqs);
		internal.tmplist->prereqs = 0;
	}

	/*
	 * if no explicit makefiles then try external.{convert,files}
	 */

	if (!state.makefile)
	{
		int	sep;
		Sfio_t*	exp;
		Sfio_t*	imp;

		exp = 0;
		imp = sfstropen();
		sep = 0;
		s = 0;
		if (*(t = getval(external.convert, VAL_PRIMARY)))
		{
			sfputr(tmp, t, 0);
			sfstrrsrv(tmp, MAXNAME);
			tok = tokopen(sfstrbase(tmp), 0);
			while (s = tokread(tok))
			{
				if (!exp)
					exp = sfstropen();
				if (t = colonlist(exp, s, 0, ' '))
				{
					t = tokopen(t, 0);
					while (s = tokread(t))
					{
						if (readfile(s, COMP_INCLUDE|COMP_DONTCARE, NiL))
							break;
						if (sep)
							sfputc(imp, ',');
						else
							sep = 1;
						sfputr(imp, s, -1);
					}
					tokclose(t);
					if (s)
						break;
				}
				if (!(s = tokread(tok)))
					break;
			}
			tokclose(tok);
			sfstrseek(tmp, 0, SEEK_SET);
		}
		if (!s && (s = colonlist(tmp, external.files, 1, ' ')))
		{
			tok = tokopen(s, 1);
			while (s = tokread(tok))
			{
				if (readfile(s, COMP_INCLUDE|COMP_DONTCARE, NiL))
					break;
				if (sep)
					sfputc(imp, ',');
				else
					sep = 1;
				sfputr(imp, s, -1);
			}
			tokclose(tok);
		}
		if (!s)
		{
			/*
			 * this readfile() pulls in the default base rules
			 * that might resolve any delayed self-documenting
			 * options in optcheck()
			 */

			if (readfile("-", COMP_FILE, NiL))
				optcheck(1);
			if (*(s = sfstruse(imp)))
				error(state.errorid ? 1 : 3, "a makefile must be specified when %s omitted", s);
			else
				error(state.errorid ? 1 : 3, "a makefile must be specified");
		}
		sfstrclose(imp);
		if (exp)
			sfstrclose(exp);
	}

	/*
	 * validate external command line options
	 */

	optcheck(1);

	/*
	 * check for listing of variable and rule definitions
	 */

	if (state.list)
	{
		dump(sfstdout, 0);
		return 0;
	}

	/*
	 * check if makefiles to be compiled
	 */

	if (state.compile && !state.virtualdot && state.writeobject)
	{
		/*
		 * make the compinit trap
		 */

		if (r = getrule(external.compinit))
		{
			state.reading = 1;
			maketop(r, P_dontcare|P_foreground, NiL);
			state.reading = 0;
		}
		if (state.exec && state.objectfile)
		{
			message((-2, "compiling makefile input into %s", state.objectfile));
			compile(state.objectfile, NiL);
		}

		/*
		 * make the compdone trap
		 */

		if (r = getrule(external.compdone))
		{
			state.reading = 1;
			maketop(r, P_dontcare|P_foreground, NiL);
			state.reading = 0;
		}
	}

	/*
	 * makefile read cleanup
	 */

	if (state.compileonly)
		return 0;
	compref(NiL, 0);
	sfstrclose(tmp);
	state.compile = COMPILED;
	if (state.believe)
	{
		if (!state.maxview)
			state.believe = 0;
		else if (state.fsview)
			error(3, "%s: option currently works in 2d only", optflag(OPT_believe)->name);
	}

	/*
	 * read the state file
	 */

	readstate();

	/*
	 * place the command line targets in internal.args
	 */

	if (internal.main->dynamic & D_dynamic)
		dynamic(internal.main);
	internal.args->prereqs = p = 0;
	for (i = args; i < state.argc; i++)
		if (state.argf[i] & ARG_TARGET)
		{
			List_t*		q;

			q = cons(makerule(state.argv[i]), NiL);
			if (p)
				p = p->next = q;
			else
				internal.args->prereqs = p = q;
		}

	/*
	 * the engine bootstrap is complete -- start user activities
	 */

	state.user = 1;

	/*
	 * make the makeinit trap
	 */

	if (r = getrule(external.makeinit))
		maketop(r, P_dontcare|P_foreground, NiL);

	/*
	 * read the command line scripts
	 */

	for (i = args; i < state.argc; i++)
		if (state.argf[i] & ARG_SCRIPT)
		{
			state.reading = 1;
			parse(NiL, state.argv[i], "command line script", NiL);
			state.reading = 0;
		}

	/*
	 * freeze the parameter files and candidate state variables
	 */

	state.user = 2;
	candidates();

	/*
	 * make the init trap
	 */

	if (r = getrule(external.init))
		maketop(r, P_dontcare|P_foreground, NiL);

	/*
	 * internal.args default to internal.main
	 */

	if (!internal.args->prereqs && internal.main->prereqs)
		internal.args->prereqs = listcopy(internal.main->prereqs);

	/*
	 * turn up the volume again
	 */

	if (!error_info.trace)
		error_info.trace = trace;

	/*
	 * make the prerequisites of internal.args
	 */

	if (internal.args->prereqs)
		while (internal.args->prereqs)
		{
			/*
			 * we explicitly allow internal.args modifications
			 */

			r = internal.args->prereqs->rule;
			internal.making->prereqs = internal.args->prereqs;
			internal.args->prereqs = internal.args->prereqs->next;
			internal.making->prereqs->next = 0;
			maketop(r, 0, NiL);
		}
	else if (state.makefile)
		error(3, "%s: a main target must be specified", state.makefile);

	/*
	 * finish up
	 */

	finish(0);
	return 0;
}
Пример #18
0
void Func::args(short nargs, short nargnames, short* argnames, int each) {
	Value* args = GETSP() - nargs + 1;
	short unamed = nargs - nargnames - (each == -1 ? 0 : 1);
	short i, j;

	if (!rest && unamed > nparams)
		except("too many arguments to " << this);

	verify(!rest || nparams == 1);    // rest must be only param
	verify(each == -1 || nargs == 1); // each must be only arg

	if (nparams > nargs)
		// expand stack (before filling it)
		SETSP(GETSP() + nparams - nargs);

	if (each != -1 && rest) {
		args[0] = args[0].object()->slice(each);
	} else if (rest) {
		// put args into object
		SuObject* ob = new SuObject();
		// un-named
		for (i = 0; i < unamed; ++i)
			ob->add(args[i]);
		// named
		for (j = 0; i < nargs; ++i, ++j)
			ob->put(symbol(argnames[j]), args[i]);
		args[0] = ob;
	} else if (each != -1) {
		SuObject* ob = args[0].object();

		if (ob->vecsize() > nparams + each)
			except("too many arguments to " << this << " vecsize "
											<< ob->vecsize() << " each " << each
											<< " nparams " << nparams);

		// un-named members
		for (i = 0; i < nparams; ++i)
			args[i] = ob->get(i + each);
		// named members
		verify(locals);
		for (i = 0; i < nparams; ++i)
			if (Value x = ob->get(symbol(locals[i])))
				args[i] = x;
	} else if (nargnames > 0) {
		// shuffle named args to match params
		const int maxargnames = 100;
		Value tmp[maxargnames];

		// move named args aside
		verify(nargnames < maxargnames);
		for (i = 0; i < nargnames; ++i)
			tmp[i] = args[unamed + i];

		// initialized remaining params
		for (i = unamed; i < nparams; ++i)
			args[i] = Value();

		// fill in params with named args
		verify(locals);
		for (i = 0; i < nparams; ++i)
			for (j = 0; j < nargnames; ++j)
				if (locals[i] == argnames[j])
					args[i] = tmp[j];
	} else {
		// initialized remaining params
		for (i = unamed; i < nparams; ++i)
			args[i] = Value();
	}

	// fill in dynamic implicits
	if (flags) {
		for (i = 0; i < nparams; ++i)
			if (!args[i] && (flags[i] & DYN)) {
				int sn = ::symnum(CATSTRA("_", symstr(locals[i])));
				args[i] = dynamic(sn);
			}
	}

	// fill in defaults
	if (ndefaults > 0) {
		verify(literals);
		for (j = nparams - ndefaults, i = 0; i < ndefaults; ++i, ++j)
			if (!args[j])
				args[j] = literals[i];
	}

	if (nargs > nparams)
		// shrink stack (after processing args)
		SETSP(GETSP() + nparams - nargs);

	// check that all parameters now have values
	verify(locals);
	for (i = 0; i < nparams; ++i)
		if (!args[i])
			except("missing argument(s) to " << this);
}
/*
 Inherits from : -
======================================================================*/
fmiStatus fmiInitialize(fmiComponent component_,
                        fmiBoolean toleranceControlled,
                        fmiReal relativeTolerance,
                        fmiEventInfo* eventInfo)
{
   /* Declaration of internal variables */
   int i; /* Loop variable */
   int ip[11]; /* Integer parameters */
   int n; /* Size variable */
   fmiStatus old_status;
   double rp[7]; /* Real parameters */
   char* tp[1]; /* Text parameters */

   /* Convert the memory slot 'component_' to an fmiComponentStructure (fmiComponent is void*) */
   fmiComponentStructure* component = component_;
   AMESIMSYSTEM *amesystem = InitGlobalSystem(0, 0, 0, 0);
   amesystem->AmeExit = ModelAmeExit;
   SetGlobalSystem(amesystem);
   ValidateRuntype(8);

   /* Initialize real parameters */
   rp[0] = component->realSVar[0];
   rp[1] = component->realSVar[1];
   rp[2] = component->realSVar[2];
   rp[3] = component->realSVar[3];
   rp[4] = component->realSVar[4];
   rp[5] = component->realSVar[5];
   rp[6] = component->realSVar[6];

   /* Initialize integer parameters */
   ip[0] = component->intSVar[0];
   ip[1] = component->intSVar[1];
   ip[2] = component->intSVar[2];
   ip[3] = component->intSVar[3];
   ip[4] = component->intSVar[4];
   ip[5] = component->intSVar[5];
   ip[6] = component->intSVar[6];
   ip[7] = component->intSVar[7];
   ip[8] = component->intSVar[8];
   ip[9] = component->intSVar[9];
   ip[10] = component->intSVar[10];

   /* Initialize text parameters */
   tp[0] = (char*)component->stringSVar[0];

   /* Set nominal values for continuous states */
   for (i = 0 ; i < component->nb_state_var ; ++i)
   {
      component->nominalContinuousStates[i] = component->realSVar[component->idx_of_state_var[i]] != 0.0 ? component->realSVar[component->idx_of_state_var[i]] : 1.0;
      component->state_var_deriv[i] = 0;
   }
   component->time_or_state_event = fmiFalse;

   /* Finish component initialization */
   if (toleranceControlled)
   {
      relativeTolerance = 1.*relativeTolerance;
   }
   n = 1; /* Initialize instantiation number */
   if ((component->status == fmiFatal) || (component->status == fmiError))
   {
      AME_status = fmiError;
   }
   if (!component_ok(component)) /* Test component */
   {
      return fmiFatal;
   }
   if (update_state(component, T_fmiInitialize, "fmiInitialize", __FILE__, __LINE__) == fmiFalse) /* Update current state (state machine) */
   {
      return fmiError;
   }

   /* Call submodel's 'init' function */
   shuntdcmotorwithstartingresistorin_(&n,                        /* Instance number */
                                       rp,                        /* Real parameters */
                                       ip,                        /* Integer parameters */
                                       tp,                        /* Text parameters */
                                       component->ps,             /* Pointer stores */
                                       &(component->realSVar[7]), /* ifield (ifield - Field current) */
                                       &(component->realSVar[8])  /* speed (speed - Rotary speed) */);

   /* Retrieve real parameters */
   component->realSVar[0] = rp[0];
   component->realSVar[1] = rp[1];
   component->realSVar[2] = rp[2];
   component->realSVar[3] = rp[3];
   component->realSVar[4] = rp[4];
   component->realSVar[5] = rp[5];
   component->realSVar[6] = rp[6];

   /* Retrieve integer parameters */
   component->intSVar[0] = ip[0];
   component->intSVar[1] = ip[1];
   component->intSVar[2] = ip[2];
   component->intSVar[3] = ip[3];
   component->intSVar[4] = ip[4];
   component->intSVar[5] = ip[5];
   component->intSVar[6] = ip[6];
   component->intSVar[7] = ip[7];
   component->intSVar[8] = ip[8];
   component->intSVar[9] = ip[9];
   component->intSVar[10] = ip[10];

   /* Retrieve text parameters */
   component->stringSVar[0] = tp[0];

   /* Call dynamic */
   component->first_call = fmiTrue;
   amesystem->first_call = 1;
   old_status = component->status;
   dynamic(component);
   amesystem->first_call = 0;
   if ((AME_status != fmiOK) && (component->status != fmiFatal))
   {
      component->status = fmiError;
   }
   if (component->status != old_status)
   {
      component->memory.logger(component, component->instanceName, fmiWarning, "fmiInitialize", "Variable AME_status was changed by submodel.");
   }

   /* Fill in event information */
   eventInfo->iterationConverged = fmiTrue;
   eventInfo->stateValueReferencesChanged = fmiFalse;
   eventInfo->stateValuesChanged = fmiTrue;
   eventInfo->terminateSimulation = fmiFalse;
   eventInfo->upcomingTimeEvent = fmiFalse;
   if (GetFutureTimeDiscon() < getfinaltime_()) /* Get first time event */
   {
      eventInfo->upcomingTimeEvent = fmiTrue;
      eventInfo->nextEventTime = GetFutureTimeDiscon();
   }
   component->eventInfo = *eventInfo;

   /* Model has been evaluated */
   component->evaluated = fmiTrue;

   /* All went smoothly */
   return component->status;
}
Пример #20
0
void abcSaf2::algoJoint(double **liks,char *anc,int nsites,int numInds,int underFlowProtect, int fold,int *keepSites,realRes2 *r,int noTrans) {
  //fprintf(stderr,"[%s]\n",__FUNCTION__);
    int myCounter =0;
    if(anc==NULL||liks==NULL){
        fprintf(stderr,"problems receiving data in [%s] will exit (likes=%p||ancestral=%p)\n",__FUNCTION__,liks,anc);
        exit(0);
    }
    double sumMinors[2*numInds+1];  //the sum of the 3 different minors

    for(int it=0; it<nsites; it++) {//loop over sites
        double *like = liks[it]; //[EJ]
        int major_offset = anc[it];
        if(major_offset==4||(keepSites[it]==0)){//skip of no ancestral information
            //      r->oklist is zero no need to update
            continue;
        }
        //set the resultarray to zeros
        for(int sm=0 ; sm<(2*numInds+1) ; sm++ )
            sumMinors[sm] = 0;

        //loop through the 3 different minors
        for(int minor_offset=0;minor_offset<4;minor_offset++) {
            if(minor_offset == major_offset)
                continue;
            if(noTrans){
                if((major_offset==2&&minor_offset==0)||(major_offset==0&&minor_offset==2))
                    continue;
                if((major_offset==1&&minor_offset==3)||(major_offset==3&&minor_offset==1))
                    continue;
            }

            //hook for only calculating one minor
            int Aa_offset = angsd::majorminor[minor_offset][major_offset];//0-9
            int AA_offset = angsd::majorminor[minor_offset][minor_offset];//0-9
            int aa_offset = angsd::majorminor[major_offset][major_offset];//0-9

            //fprintf(stderr,"%d:%d\t%d\t%d\n",major_offset,Aa_offset,AA_offset,aa_offset);

            //--------------part two ------------------------//
            if(mode==0)  dynamicAdaptiveK(like,sumMinors,numInds,AA_offset,Aa_offset,aa_offset,underFlowProtect,r,it);        //[EJ]
	    else if(mode==1) rescaledDynamic(like,sumMinors,numInds,AA_offset,Aa_offset,aa_offset,underFlowProtect,r,it);  //[EJ]
	    else if(mode==2) adaptiveK(like,sumMinors,numInds,AA_offset,Aa_offset,aa_offset,underFlowProtect,r,it);        //[EJ]
            else if(mode==3) dynamic(like,sumMinors,numInds,AA_offset,Aa_offset,aa_offset,underFlowProtect,r,it); // Original DP[EJ]
            // Note: ordering reset by JN such that default is mode 0, but modes
            // 1,2,3 are "easter eggs"

            //------------- end of part two -----------------------------------------------//
#if 0
            for(int ii=0;ii<1*numInds;ii++) fprintf(stdout,"%f\t",liks[it][ii]);
#endif
        }

        //sumMinors is in normal space, not log
        /*
         we do 3 things.
         1. log scaling everyting
         2. rescaling to the most likely in order to avoid underflows in the optimization
         3. we might do a fold also.

         */

        //fprintf(stderr,"it: %d\n",it);

        if(fold) {
            int newDim = numInds+1;

            for(int i=0;i<newDim-1;i++)// we shouldn't touch the last element
                sumMinors[i] = log(sumMinors[i] + sumMinors[2*numInds-i]);//THORFINN NEW
            sumMinors[newDim-1] = log(sumMinors[newDim-1])+log(2.0);
            angsd::logrescale(sumMinors,newDim);
            if(std::isnan(sumMinors[0]))
                r->oklist[it] = 2;
            else{
                r->oklist[it] = 1;

                if(outputBanded){
                  // [JN] For banded output format we need not use as
                  // much memory.  This is compact version.
                  // Declare mem for only Kval worth values
                  // Copy only banded area of sumMinors over
                  r->pLikes[myCounter] = new double[(r->Kval[it])];
                  memcpy(r->pLikes[myCounter],&sumMinors[r->offset[it]],sizeof(double)*(r->Kval[it]));
                }else{ // original
                  r->pLikes[myCounter] =new double[numInds+1];
                  memcpy(r->pLikes[myCounter],sumMinors,sizeof(double)*(numInds+1));
                }
                myCounter++;
            }
        }else{
            for(int i=0;i<2*numInds+1;i++)
                sumMinors[i] = log(sumMinors[i]);
            angsd::logrescale(sumMinors,2*numInds+1);
            if(std::isnan(sumMinors[0]))
                r->oklist[it] = 2;
            else{
                r->oklist[it] = 1;

                if(outputBanded){ // See note above in folded section
                  r->pLikes[myCounter] = new double[(r->Kval[it])];
                  memcpy(r->pLikes[myCounter],&sumMinors[r->offset[it]],sizeof(double)*(r->Kval[it]));
                }else{ // original
                  r->pLikes[myCounter] =new double[2*numInds+1];
                  memcpy(r->pLikes[myCounter],sumMinors,sizeof(double)*(2*numInds+1));
                }
                myCounter++;
            }

	    #if 0
            // [EJ] Print output to STD ERR
            fprintf(stdout,"%d\t",it+1);//[EJ]
            for(int i=0;i<(2*numInds+1);i++) fprintf(stdout,"%f\t",(sumMinors[i])); //[EJ]
            fprintf(stdout,"\n"); //[EJ]
	    exit(0);
	    #endif
	}
    }

}
Пример #21
0
//This is the backend functions, set up to run in a seperate thread
UINT FoldProc( LPVOID pParam ){    
	CFoldObject* pObject = (CFoldObject*) pParam;
	CFoldView* pView = (CFoldView*) pObject->parent; 
	int i,bases;
	char *ctname,buffer[7];
	double time,currenttime;
	
    
	

	if (pObject->subfold) {
		//fold each fragment of sequence that has the common 5' end, i.e. whittle way the 3' end
		bases=pObject->ct->numofbases;

		pObject->ctoutfile[strlen(pObject->ctoutfile)-3]='\0';
		ctname=new char[strlen(pObject->ctoutfile)+10]; //allocate enough space for sequences of length 999,999 nucs.
		time=0;
		currenttime=0;
		for (i=bases;i>minloop+1;i--) {
			time+=pow((double) i,3.0);	
		}
		

		

		for (i=bases;i>minloop+1;i--) {
			
			pObject->ct->numofbases=i;
			dynamic(pObject->ct,pObject->data,pObject->dynnumber,pObject->dynpercent,
				pObject->dynwindow,0,false,0,pObject->maximuminternalloopsize);
			
			strcpy(ctname,pObject->ctoutfile);
			strcat(ctname,"_");
			sprintf(buffer,"%u",i);
			strcat(ctname,buffer);
			strcat(ctname,".ct");
	
			ctout (pObject->ct,ctname);

			currenttime+=pow((double) i,3.0);
			pObject->progress->update(100.0*currenttime/time);

		}
		
		pObject->ct->numofbases=bases;
		delete[] ctname;
	}
	else {
		dynamic(pObject->ct,pObject->data,pObject->dynnumber,pObject->dynpercent,
			pObject->dynwindow,pObject->progress,false,pObject->savefile,pObject->maximuminternalloopsize);

	
		ctout (pObject->ct,pObject->ctoutfile);

	}
      
	::PostMessage(pView->m_hWnd,ID_FOLDDONE,0,0);
	

	return 0;   // thread completed successfully
}