示例#1
0
文件: machine.c 项目: ranxian/cwam
int try_me_else(wam_t *wam, int next)
{
	choicepoint_t *cp = cp_init(wam->args, wam->trail->n, wam->ctnptr);
	cp->lastcp = wam->cp;
	wam->cp = cp;
	cp->nextclause = next;
	cp->lastenv = wam->env;
	wam->pc += 1;
	return 0;
}
示例#2
0
文件: xt-lua.c 项目: xtforever/xtcw
/* returns socket fd */
int xtlua_init( Widget w, char *host, char *port )
{
    int sln = sln_init();
    
    /* init commands */
    cp_init();
    cp_add( "PUT:", cmd_put );
    cp_add( "EXIT", cmd_exit );
    cp_add( "CIRCLE:", cmd_circle );    

    int fd = sln_connect(sln, host, port, process_new_packet, w );
    if(fd < 0 ) ERR("server not found");

    return fd;
}
示例#3
0
文件: output.c 项目: Cappar/bard
void out_init(jmp_buf jmpBuf, struct Output* output, char* configDir) {
	struct ConfigParser parser;
	struct ConfigParserEntry entry[] = {
		StringConfigEntry("display:separator", separator, NULL),
		IntConfigEntry("display:monitors", monitors, 1),
		EndConfigEntry(),
	};
	cp_init(jmpBuf, &parser, entry);
	char* path = pathAppend(configDir, "bard.conf");
	cp_load(jmpBuf, &parser, path, output);
	free(path);
	cp_kill(&parser);
	
	for(int i = ALIGN_FIRST; i <= ALIGN_LAST; i++) {
		vector_init(jmpBuf, &output->out[i], sizeof(struct Unit*), 10);
	}
}
示例#4
0
文件: testmain.c 项目: 070499/xbmc
CP_HIDDEN cp_context_t *init_context(cp_log_severity_t min_disp_sev, int *error_counter) {
	cp_context_t *ctx;
	cp_status_t status;
	
	check(cp_init() == CP_OK);
	check((ctx = cp_create_context(&status)) != NULL && status == CP_OK);
	if (error_counter != NULL) {
		*error_counter = 0;
	}
	if (error_counter != NULL || min_disp_sev <= CP_LOG_ERROR) {
		if (min_disp_sev <= CP_LOG_ERROR) {
			check(cp_register_logger(ctx, full_logger, error_counter, min_disp_sev) == CP_OK);
		} else {
			check(cp_register_logger(ctx, counting_logger, error_counter, CP_LOG_ERROR) == CP_OK);
		}
	}
	return ctx;
}
示例#5
0
void
ft_cpinit(void)
{
    bool found = FALSE, t = TRUE;
    char buf[BSIZE_SP], **x, *s, *r, *copys;
    struct comm *c;
    int i;
    FILE *fp;

    static char *predefs[] = {
        "yes",      "1",
        "TRUE",     "1",
        "no",       "0",
        "FALSE",    "0",
        "pi",       "3.14159265358979323846",
        "e",        "2.71828182845904523536",
        "c",        "2.997925e8",
        "i",        "0,1",
        "kelvin",   "-273.15",
        "echarge",  "1.60219e-19",
        "boltz",    "1.38062e-23",
        "planck",   "6.62620e-34"
    };

    static char *udfs[] = {
        "max(x,y)", "(x gt y) * x + (x le y) * y",
        "min(x,y)", "(x lt y) * x + (x ge y) * y",
        "vdb(x)",   "db(v(x))",
        "vdb(x,y)", "db(v(x) - v(y))",
        "vi(x)",    "im(v(x))",
        "vi(x,y)",  "im(v(x) - v(y))",
        "vm(x)",    "mag(v(x))",
        "vm(x,y)",  "mag(v(x) - v(y))",
        "vg(x)",    "group_delay(v(x))", //A.Rroldan 10/06/05 group delay new function
        "gd(x)",    "group_delay(v(x))", //A.Rroldan 10/06/05 group delay new function
        "vp(x)",    "ph(v(x))",
        "vp(x,y)",  "ph(v(x) - v(y))",
        "vr(x)",    "re(v(x))",
        "vr(x,y)",  "re(v(x) - v(y))"
    };

    /* if TIOCSTI is defined (not available in MS Windows:
       Make escape the break character.
       So the user can type ahead...
       fcn defined in complete.c. */
    cp_ccon(TRUE);

    /* Initialize io, cp_chars[], variable "history" in init.c. */
    cp_init();

    /* If command completion is available (global variable cp_nocc
       set in main.c by command line option -q)   */
    if (!cp_nocc) {

        /* Add commands... */
        for (c = cp_coms; c->co_func; c++) {
            if (c->co_spiceonly && ft_nutmeg)
                continue;
            cp_addcomm(c->co_comname,
                       c->co_cctypes[0], c->co_cctypes[1],
                       c->co_cctypes[2], c->co_cctypes[3]);
            cp_addkword(CT_COMMANDS, c->co_comname);
        }

        /* And keywords... These are the ones that are constant... */
        if (!ft_nutmeg) {
            cp_addkword(CT_LISTINGARGS, "deck");
            cp_addkword(CT_LISTINGARGS, "logical");
            cp_addkword(CT_LISTINGARGS, "physical");
            cp_addkword(CT_LISTINGARGS, "expand");

            cp_addkword(CT_STOPARGS, "when");
            cp_addkword(CT_STOPARGS, "after");
        }

        cp_addkword(CT_PLOT, "new");

        cp_addkword(CT_PLOTKEYWORDS, "xlimit");
        cp_addkword(CT_PLOTKEYWORDS, "ylimit");
        cp_addkword(CT_PLOTKEYWORDS, "vs");
        cp_addkword(CT_PLOTKEYWORDS, "xindices");
        cp_addkword(CT_PLOTKEYWORDS, "xcompress");
        cp_addkword(CT_PLOTKEYWORDS, "xdelta");
        cp_addkword(CT_PLOTKEYWORDS, "ydelta");
        cp_addkword(CT_PLOTKEYWORDS, "lingrid");
        cp_addkword(CT_PLOTKEYWORDS, "loglog");
        cp_addkword(CT_PLOTKEYWORDS, "linear");
        cp_addkword(CT_PLOTKEYWORDS, "xlog");
        cp_addkword(CT_PLOTKEYWORDS, "ylog");
        cp_addkword(CT_PLOTKEYWORDS, "polar");
        cp_addkword(CT_PLOTKEYWORDS, "smith");
        cp_addkword(CT_PLOTKEYWORDS, "smithgrid");
        cp_addkword(CT_PLOTKEYWORDS, "nointerp");
        cp_addkword(CT_PLOTKEYWORDS, "title");
        cp_addkword(CT_PLOTKEYWORDS, "xlabel");
        cp_addkword(CT_PLOTKEYWORDS, "ylabel");
        cp_addkword(CT_PLOTKEYWORDS, "linplot");
        cp_addkword(CT_PLOTKEYWORDS, "combplot");
        cp_addkword(CT_PLOTKEYWORDS, "pointplot");

        cp_addkword(CT_RUSEARGS, "time");
        cp_addkword(CT_RUSEARGS, "space");
        cp_addkword(CT_RUSEARGS, "faults");
        cp_addkword(CT_RUSEARGS, "elapsed");
        cp_addkword(CT_RUSEARGS, "totiter");
        cp_addkword(CT_RUSEARGS, "traniter");
        cp_addkword(CT_RUSEARGS, "tranpoints");
        cp_addkword(CT_RUSEARGS, "accept");
        cp_addkword(CT_RUSEARGS, "rejected");
        cp_addkword(CT_RUSEARGS, "time");
        cp_addkword(CT_RUSEARGS, "trantime");
        cp_addkword(CT_RUSEARGS, "lutime");
        cp_addkword(CT_RUSEARGS, "solvetime");
        cp_addkword(CT_RUSEARGS, "transolvetime");
        cp_addkword(CT_RUSEARGS, "loadtime");
        cp_addkword(CT_RUSEARGS, "all");

        cp_addkword(CT_VECTOR, "all");

        for (x = ft_setkwords; *x; x++)
            cp_addkword(CT_VARIABLES, *x);
        for (i = 0; ; i++) {
            if ((s = ft_typenames(i)) == NULL)
                break;
            cp_addkword(CT_TYPENAMES, s);
        }
    }

    cp_vset("program", CP_STRING, cp_program);

    /* Make the prompt use only the last component of the path... */

    if (DIR_TERM) {
        for (s = cp_program; s && *s; s++)
            ;
        s--;
        while ((s > cp_program) && (*s != DIR_TERM))
            s--;
        if (*s == DIR_TERM)
            s++;
        (void) strcpy(buf, s);
        for (s = buf; *s && (*s != '.'); s++)
            ;
        *s = '\0';
        (void) strcat(buf, " ! -> ");

    } else {
        (void) sprintf(buf, "%s ! -> ", cp_program);
    }

    cp_vset("prompt", CP_STRING, buf);
    cp_vset("noglob", CP_BOOL, &t);
    cp_vset("brief", CP_BOOL, &t);

    /* Make vectors from values in predefs[] for the current plot.
       Define functions from entries in udfs[] (like user defined functions).
    */

    {
        wordlist wl1, wl2, wl3;
        wl1.wl_next = &wl2;
        wl1.wl_prev = NULL;
        wl2.wl_next = NULL;
        wl2.wl_prev = &wl1;
        wl1.wl_word = "if";
        wl2.wl_word = "1";
        cp_setalias("begin", &wl1);
        wl1.wl_next = NULL;
        wl1.wl_word = "end";
        cp_setalias("endif", &wl1);
        cp_setalias("endwhile", &wl1);
        cp_setalias("endforeach", &wl1);
        cp_setalias("endrepeat", &wl1);
        cp_setalias("enddowhile", &wl1);
        wl1.wl_word = "help";
        cp_setalias("?", &wl1);

        wl1.wl_next = &wl2;
        wl2.wl_next = &wl3;
        wl2.wl_prev = &wl1;
        wl3.wl_prev = &wl2;
        wl3.wl_next = NULL;
        wl2.wl_word = "=";
        for (i = 0; (size_t) i < NUMELEMS(predefs); i += 2) {
            wl1.wl_word = predefs[i];
            wl3.wl_word = predefs[i + 1];
            com_let(&wl1);
        }

        wl2.wl_next = NULL;
        for (i = 0; (size_t) i < NUMELEMS(udfs); i += 2) {
            wl1.wl_word = udfs[i];
            wl2.wl_word = udfs[i + 1];
            com_define(&wl1);
        }
    }

    /* Reset this for the front end. */
    cp_hash = '*';

    /* NGSPICEDATADIR has been set to path "$dprefix/share/ngspice" in configure.ac,
       Spice_Lib_Dir has been set to NGSPICEDATADIR in conf.c,
       may be overridden by environmental variable SPICE_LIB_DIR in ivars().
       Lib_Path has been set to Spice_Lib_Dir adding /scripts in ivars() */
    if (Lib_Path && *Lib_Path) {
        /* set variable 'sourcepath' */
        if (Inp_Path && *Inp_Path)
            (void) sprintf(buf, "sourcepath = ( %s %s %s )", DIR_CWD, Lib_Path, Inp_Path);
        else
            (void) sprintf(buf, "sourcepath = ( %s %s )", DIR_CWD, Lib_Path);

        {
            wordlist *wl;
            wl = cp_doglob(cp_lexer(buf));
            cp_striplist(wl);
            com_set(wl);
            wl_free(wl);
        }

        /* Now source the standard startup file spinit or tclspinit. */

        /* jump over leading spaces */
        for (copys = s = cp_tildexpand(Lib_Path); copys && *copys; ) {
            while (isspace(*s))
                s++;
            /* copy s into buf until space is seen, r is the actual position */
            for (r = buf; *s && !isspace(*s); r++, s++)
                *r = *s;
            tfree(copys);
            /* add a path separator to buf at actual position */
            (void) strcpy(r, DIR_PATHSEP);
#ifdef TCL_MODULE
            /* add "tclspinit" to buf after actual position */
            (void) strcat(r, "tclspinit");
#else
            /* add "spinit" to buf after actual position */
            (void) strcat(r, "spinit");
#endif
            if ((fp = fopen(buf, "r")) != NULL) {

                cp_interactive = FALSE;
                inp_spsource(fp, TRUE, buf, FALSE);
                cp_interactive = TRUE;
                found = TRUE;
                break;

#if defined(HAS_WINGUI) || defined(__MINGW32__) || defined(_MSC_VER)
                /* search in local directory where ngspice.exe resides */
#if defined TCL_MODULE
            } else if ((fp = fopen("./tclspinit", "r")) != NULL) {
#else
            } else if ((fp = fopen("./spinit", "r")) != NULL) {
#endif
                cp_interactive = FALSE;
                inp_spsource(fp, TRUE, buf, FALSE);
                cp_interactive = TRUE;
                found = TRUE;
                break;
#endif
            } else if (ft_controldb) {
                fprintf(cp_err, "Note: can't open \"%s\".\n", buf);
            }
        }

        if (!found)
            fprintf(cp_err, "Note: can't find init file.\n");
    }

    tcap_init();
}
示例#6
0
GList * calc_w_phi_coeffs (const ThreeVector * kperp, const ThreeVector * direction) {
    if(!cptimer) {  /* optimization timer */
        cptimer = g_timer_new();
        g_timer_start(cptimer);
    }
    else {
        g_timer_continue(cptimer);
    }
    
    cp_init();

    g_message ("starting calc_w_phi: {%1.2e, %1.2e}", kperp->x[0], kperp->x[1]);

    if (model->total_bands == 2) /* for checking the two-band PBA model */
        return calc_w_phi_constP (kperp);
    
    double te, he, kc;
    
    size_t qq;
    
	gboolean failed = FALSE;
	
	size_t NB = model->total_bands;
	size_t N2 = (model->total_bands)*(model->total_bands);
	
	pert_ode * po = pert_ode_init (NB);
	
	// generate basis vectors e, f, g
	
	const ThreeVector *g = direction;
	const ThreeVector *e = three_vector_e (g);
	const ThreeVector *f = three_vector_f (g, e);
	
	g_message ("e is %1.2e, %1.2e, %1.2e", e->x[0], e->x[1], e->x[2]);
	g_message ("f is %1.2e, %1.2e, %1.2e", f->x[0], f->x[1], f->x[2]);
	g_message ("g is %1.2e, %1.2e, %1.2e", g->x[0], g->x[1], g->x[2]);
	
	// get kperp in basis x, y, z
	ThreeVector *kperp2 = three_vector_new (0,0,0);
	kperp2->x[0] = kperp->x[0]*e->x[0] + kperp->x[1]*f->x[0] + kperp->x[2]*g->x[0];
	kperp2->x[1] = kperp->x[0]*e->x[1] + kperp->x[1]*f->x[1] + kperp->x[2]*g->x[1];
	kperp2->x[2] = kperp->x[0]*e->x[2] + kperp->x[1]*f->x[2] + kperp->x[2]*g->x[2];
	
    if (trajectory_intersects_bad (kperp2, direction)) {
        g_timer_stop(cptimer);
        return NULL;
    }
	
	complex double * H;
	
	// set up ODE solver
	
	po->syse.function = cfuncall;
	
    odeparams params;
    po->syse.params = (void *) &params;
	
    te = 0.0;//, kc1 = KCMAX/5;
    he = 5e-7;
    
    double * call;
    complex double *callc;
	
    H = model->H(kperp2);
    double * eigval = eigenvalues_herm (H, model->total_bands);
    gsl_matrix_complex * eigvec = eigenvectors_herm (H, model->total_bands);
    m_free(H);
    size_t m, n;
    call = double_array_calloc (2*NB*NB+NB);
    callc = (complex double*) call;
    for (m=0;m<NB;m++) {
        for (n=0;n<NB;n++) {
            callc[m*NB+n]=*(complex double *)(eigvec->data + 2*(m * eigvec->tda + n));
        }
        call[2*NB*NB+m]=eigval[m];
    }
        
    d_free(eigval);
    gsl_matrix_complex_free(eigvec);
        
    params.kperp = *three_vector_copy (kperp2);
    po->syse.params = (void *) &params;
    
	params.pos = TRUE;
	params.dir = *g;
	
	/* make a copy of the initial condition because we will need it to go negative */
	
	double * cinit = double_array_clone(call,2*N2+NB);
	
	// make list of points, add first point
    
    GList * pointlist = g_list_append (NULL, matrix_element_create_from_coeffs(kperp, callc, 0.0));
	
    // evolve in positive g direction
    
    g_message("going in g direction");
	
    te = 0.0;//, kc1 = KCMAX/5;
    he = 5e-7;
    
    qq=1;
    double dkc=5e-5;
    
	for (kc=dkc*COARSENESS;kc<=KCMAX;kc=kc+dkc*COARSENESS) {  // coarse loop for ODE solver for W - positive kc
	  while (te < kc && !failed) {
	    pert_ode_evolve (po, &te, kc, &he, call);
      ThreeVector *kpar = three_vector_copy(direction);
      three_vector_scale(kpar,te);
      ThreeVector *kval = three_vector_add(kperp2,kpar);
      pointlist = g_list_prepend (pointlist, matrix_element_create_from_coeffs(kval, callc, te));
      
      if (qq>100000) {  /* danger with adaptive solver is it might get stuck */
        failed=TRUE;  /* this detects whether the number of points is getting too high */
        g_warning("calc_w_phi_coeffs:  ode solver ran away, positive direction");
      }
      qq++;
	  }
	}
	
	pointlist = g_list_reverse (pointlist); // reverse list
	
	pert_ode_reset(po);  // reset the ode solver, initial condition
	
	d_free(call);
	call = cinit;
	callc = (complex double*) call;
	
	// evolve in negative g direction
	
    params.pos = FALSE;

    qq=0;
    te=0;
    he=5e-7;
    
    for (kc=dkc*COARSENESS;kc<=KCMAX;kc=kc+dkc*COARSENESS) {
	    while (te < kc && !failed) {
    	 	pert_ode_evolve (po, &te, kc, &he, call);
    	 	ThreeVector *kpar = three_vector_copy(direction);
            three_vector_scale(kpar,-te);
            ThreeVector *kval = three_vector_add(kperp2,kpar);
            pointlist = g_list_prepend (pointlist, matrix_element_create_from_coeffs(kval, callc, -te));
    	 	
    	 	if (qq>100000) {
	        	failed=TRUE;
	    	    g_warning("calc_w_phi_coeffs:  ode solver ran away, negative direction");
	    	}
	    	qq++;
    	}
    }
	
	pert_ode_free(po);
	
	d_free(call);
	
    g_timer_stop(cptimer);  /* optimization timer */
	
    m_free(wc);
    if(dHx)
      m_free(dHx);
    if(dHy)
      m_free(dHy);
    if(dHz)
      m_free(dHz);

	return pointlist;
}
示例#7
0
文件: cwnet.c 项目: xtforever/xtcw
/******************************************************************************
*   MAIN function
******************************************************************************/
int main ( int argc, char **argv )
{
    trace_main = TRACE_MAIN;

    XtAppContext app;
    m_init();
    XtSetLanguageProc (NULL, NULL, NULL);
    XawInitializeWidgetSet();

    /*  --  Intialize Toolkit creating the application shell
     */
    Widget appShell = XtOpenApplication (&app, APP_NAME,
             /* resources: can be set from argv */
             options, XtNumber(options),
	     &argc, argv,
	     fallback_resources,
	     sessionShellWidgetClass,
	     NULL, 0
	   );
    load_icon(XtDisplay(appShell));
    //    load_icon_default();

    /*  --  Enable Editres support
     */
    XtAddEventHandler(appShell, (EventMask) 0, True, _XEditResCheckMessages, NULL);

    XtAddCallback( appShell, XtNdieCallback, quit_cb, NULL );

    /*  --  not parsed options are removed by XtOpenApplication
            the only entry left should be the program name
    */
    if (argc != 1) { m_destruct(); syntax(); exit(1); }
    TopLevel = appShell;


    /*  --  Register all application specific
            callbacks and widget classes
    */
    RegisterApplication ( appShell );

    /*  --  Register all Athena and Public
            widget classes, CBs, ACTs
    */
    XpRegisterAll ( app );

    /*  --  Create widget tree below toplevel shell
            using Xrm database
    */
    WcWidgetCreation ( appShell );


    /*  -- Get application resources and widget ptrs
     */
    XtGetApplicationResources(	appShell, (XtPointer)&CWNET,
				CWNET_CONFIG_RES,
				XtNumber(CWNET_CONFIG_RES),
				(ArgList)0, 0 );

    InitializeApplication(appShell);

    /*  --  Realize the widget tree and enter
            the main application loop  */
    XtRealizeWidget ( appShell );
    /*  --  Set Icon for Window */
    set_app_icon(appShell);

    grab_window_quit( appShell );


    /*------------------------------------------------------------------------*/
    CWNET.lgfx = lgfx_init( CWNET.widget_draw1 );

    /* init commands */
    cp_init();
    cp_add( "PUT:", cmd_put );
    cp_add( "EXIT", cmd_exit );
    cp_add( "CIRCLE:", cmd_circle );
    cp_add( "CLRSCR", cmd_clrscr );
    cp_add( "RECT:", cmd_rect );
    cp_add( "MEASURE", cmd_measure );
    int sln = sln_init();
    CWNET.sln = sln;
    XtAppAddTimeOut(app , 1000, try_connect, (XtPointer) (intptr_t) sln );
    /*------------------------------------------------------------------------*/

    
    XtAppMainLoop ( app ); /* use XtAppSetExitFlag */
    XtDestroyWidget(appShell);

    sln_destruct();
    m_destruct();

    return EXIT_SUCCESS;
}