コード例 #1
0
ファイル: RangeUtil.cpp プロジェクト: shouldmakemusic/wii2osc
void RangeUtil::test()
{
    RangeUtil ru;
    printf("sourcemin: %f, sourcemax: %f, targetmin: %f, targetmax: %f\n", ru.sourcemin, ru.sourcemax, ru.targetmin, ru.targetmax);
    
    for(double i = 0; i <= 10; ++i)
    {
        printf("%f gets %f\n", i/10, ru.getValue(i/10));
    }
    
    RangeUtil ru2(0, 10, 4, 6);
    printf("sourcemin: %f, sourcemax: %f, targetmin: %f, targetmax: %f\n", 0.0, 10.0, 4.0, 6.0);
    
    for(double i = 0; i <= 10; ++i)
    {
        printf("%f gets %f\n", i, ru2.getValue(i));
    }
    
    RangeUtil ru3(-10, 10, 4, 6);
    printf("sourcemin: %f, sourcemax: %f, targetmin: %f, targetmax: %f\n", -10.0, 10.0, 4.0, 6.0);
    
    for(double i = -10; i <= 10; ++i)
    {
        printf("%f gets %f\n", i, ru3.getValue(i));
    }
    
}
コード例 #2
0
ファイル: srun.c プロジェクト: jrwebb56/OPEN-DESIRE
void srun() {                              /*  simulation RUN routine */

    int  lj, dcounter ; double  tmm ;   /* dcounter for MM displays <***/

    runf=1 ;              /* to keep display label in command mode */

    if (relval[mmm+15]<1) relval[mmm+15]=1 ;  /* MM must be >=1    */
       
    if (relval[mmm+1]<=1) relval[mmm+1]=251 ; /* AN=NN output pts. */
    if (relval[mmm+4]<=0) {                                /* TMAX */
	if (size) derror(87) ;
	else relval[mmm+4]=relval[mmm+1]-1 ;             /* irule 0 */
    }
    zCOMINT=relval[mmm+4]/(relval[mmm+1]-1) ; /* COMINT =TMAX/(NN-1)   <*****/

    if (INITE1>0) ICOM=1 ;   /* initially, ICOM>0 only if INITE1>0 */
    else ICOM= -1 ;             /* for "continued-run" store, etc. */

    if (size) {                              /* "true" integration */
	if (relval[mmm+5]==1.1E-275) relval[mmm+5]=0 ; /**!!**//* t */
	if (relval[mmm+3]<=0) relval[mmm+3]=zCOMINT/2 ;    /*default DT <****/
	if (relval[mmm+3]>zCOMINT) derror(110) ;    
/*   <**** DT is too large *******/
	/***         since          
		     DT <=TMAX/(NN-1)=COMINT ,   
		     NN <= (TMAX/DT) + 1            ***/         
	relval[mmm-3]=relval[mmm+3] ;          /* save DT for reset */
	for (lj=1 ; lj<= nn1 ; lj++)
	    storesv[lj]=dpsv[lj]=relval[lj] ;       
/* save state vars. for reset, make duplicates for integration */
	hdt=relval[mmm+3]/2 ;                         /* DT/2 */

	if ((size>3)&&(size!=5)) { /* prepare for variable-step integration */
	    if (relval[mmm+9]<=0) relval[mmm+9]=0.001 ;     /* ERMAX */
	    if (size<9) {
                if (relval[mmm+7]<=0 || relval[mmm+7]>zCOMINT)  
		    relval[mmm+7]=zCOMINT ;        /* DTMAX      <****/
                          
                if (relval[mmm+8]<=0 || relval[mmm+8]>relval[mmm+7])
		    relval[mmm+8]=relval[mmm+3]/16 ;   /* DTMIN */
                if (relval[mmm+10]<=0 || relval[mmm+10]>relval[mmm+9])
		    relval[mmm+10]=0.01*relval[mmm+9] ;   /* ERMIN */
                if (relval[mmm+2]>nn1) derror(93) ; /*CHECKN too large*/
	    }                          /* 3 < irule < 9 and not 5 */
	    else if (jcstart==0 && (size==10 || size==14))
		derror(229) ;     /* missing JACOBIAN */
	}                                 /* irule > 3 and not 5 */
    }                                             /* irule != 0 */
          
    else if (relval[mmm+5]==1.1E-275) relval[mmm+5]=1 ; 
    /***!!!***/ /* irule 0 */
                                               
    t0=relval[mmm-2]=relval[mmm+5] ;        /* save t0=t for reset */
    tmm=t0+relval[mmm+4] ;                        /* tmm = t0+TMAX */
    ztnext=t0+zCOMINT ;                /* tnext = t0 + COMINT <*****/

    dflag=dispp && dbegin ; sflag=disk && sbegin ;

/* ------------------------------------------------------------------ */

    if (dflag) {                          /* start display, if any */

	lj=dbegin ;               /* start of display label, if any */

	if (dmode<0) {                   /* "type"; do header label */
	    if (!typeflg) {                  /* ## suppresses header */
                WRITELN ; 
                fprintf(outptr,"\n\nt,   ") ;
                if (ferror(outptr)) derror(106) ;
                while (warea[lj]!=lf && warea[lj]!='|') 
		    putc(warea[lj++],outptr) ;      
	    }
	    fprintf(outptr,"\n\n") ;     /* could be printer or file */
	}                                           /* if "type" */

	else if (dispp>0) drstart() ;  /* dmode>=0, start CRT graph */
    }                               /* unless we have display 2 */             
/* ------------------------------------------------------------------ */

    if (rbegin) {
	if (fd[maxchan-1]==NULL) { chanlno=maxchan-1 ; derror(64) ; }
    }                                               /* not open */
    if (sflag) {                           /* connect .TIM file(s) */
	strcpy(fname,pname) ;
	lj=0 ;
	if (fname[lj]=='.') lj++ ; if (fname[lj]=='.') lj++ ;
	do lj++ ; while (fname[lj]!='.') ;         /* get extension */
	fname[lj+1]='T' ; fname[lj+2]='I' ; fname[lj+3]='M' ;
	fname[lj+4]=0 ;

	if (fd[maxchan]!=NULL)
	{ chanlno=maxchan ; derror(63) ; }               /* busy */

	if ((fd[maxchan]=fopen(fname,"w"))==NULL) derror(11) ; 
    }
/* ------------------------------------------------------------------ */
    /* communication loop */

    /*  NOTE: on "continued" runs, displays and stash files
	DUPLICATE the last point of a run as the first point
	of the "continued" run. "Continued" runs reproduced
	from .RCV files necessarily have THE SAME t0, TMAX,
	and NN as the original runs, so that the duplicated
	points are reproduced correctly.

	Time histories reproduced from STORE or DELAY arrays,
	however, do NOT contain duplicated points and can be
	used anywhere in a subsequent run.                  */

/*  ------------------------------------------------------------------ */
    IDERIV=1 ;           /* IDERIV>0, state variables valid */
    dcounter=0 ;                                /* initialize dcounter  <*****/

    /* initially, ICOM>0 only if INITE1>0;  otherwise, for continued-run
       STORE etc., ICOM<0, so the duplicate endpoints are not stored.
       Now make the initial derivative call; this scheme ensures that
       defined variables can be computed for output */

/*  ------------------------------------ */

    if (size>8) {        /* use GEAR module, initialize if INITE1>0 */

	if (nn1>EQUMAX) derror(100) ;    /* too many state variables */
	TOUT=ztnext ;                  /* tnext for GEARER.C */
	if (INITE1>0) aINDEX=1 ;   /* ** was in gearstart ** */

	do {   /* because of duplicate derve1, ICOM, INITE1 are OFF! */

	    if (rbegin) { recovr() ; if (errnum) goto L5 ; }
	    drun00(2) ; if (errnum) goto L5 ;
             
	    if (dcounter == 0) {  
/*  display only once in MM communication points <***/
		if (dflag) { if (dmode>=0) disply() ; else typex() ; }
		if (sflag) dstor() ;
	    }                                     
	    if (++dcounter==relval[mmm+15]) dcounter=0 ;    /*   <*****/
	    
	    ICOM=INITE1= -1 ;     /* ICOM<0, INITE1<0 for store, etc. */

	    DRIVE(); if (errnum) goto L5 ;    
/* driver routine in GEAR also increments TOUT by COMINT */
	    ICOM=1 ;                /* ICOM>0, mark next output point */
	    if (spare1) {                       /* look at ctl-c flag */
                spare1=0 ;
                if (lj=getchar()!=lf) {errnum=306 ; goto L55 ; }
	    }

	} while (relval[mmm+5]-tmm<0) ;    /* t - (t0 + TMAX) < 0 */
    }                                           /* if Gear module */

    else do {             /* NOT Gear module; ICOM, INITE1 are OFF! */
	if (rbegin) { recovr() ; if (errnum) goto L5 ; }
	drun00(2) ; if (errnum) goto L5 ; 
/* initial values of defined variables */
	if (dcounter == 0) {  
/*  display only once in MM communication points <***/
	    if (dflag) { if (dmode>=0) disply() ; else typex() ; }
	    if (sflag) dstor() ;
	}                                     
	if (++dcounter==relval[mmm+15]) dcounter=0 ;          /*   <*****/   
         
	ICOM=INITE1= -1 ;    /* ICOM<0, INITE1<0
				for store, etc. */
	switch(size) {
	    case 0 : relval[mmm+5]=ztnext ; break ;  
/* dummy integrator: t=tnext */
	    case 1 : ru1() ; break ;       /* integration loops */
	    case 2 : ru2() ; break ;
	    case 3 : ru3() ; break ;
	    case 4 : ru4() ; break ;
	    case 5 : ru5() ; break ;
	    case 6 : ru6() ; break ;
	    case 7 : ru7() ; break ;
	    case 8 : ru8() ; break ;

	} if (errnum) goto L5 ;

	ztnext+=zCOMINT ;          /* tnext=tnext+COMINT <*****/
	ICOM=1 ;                   /* ICOM>0, mark next output point */
  
	if (spare1) {                          /* look at ctl-c flag */
	    spare1=0 ;
	    if (lj=getchar()!=lf) {errnum=306 ; goto L55 ; }
	}

    } while (relval[mmm+5]-tmm<0) ;       /* t - (t0 + TMAX) < 0 */

/* ------------------------------------------------------------------- */
    /* last point */
    if (rbegin) { recovr() ; if (errnum) goto L5 ; }
    drun00(2) ; if (!errnum) goto L6 ;

    /* clean up; some of those errors are not errors! */

    L5 :   if (errnum==303) { errnum=0 ; goto L6 ; } /* derve1 terminated */
    if (errnum==305) {
	printf("\n Warning: END OF FILE or error on recover -    ") ;
	errnum=0 ;                        /* EOF or error on recover */
    }
    if (errnum>=304) errnum=0 ;                              /* eof */
    goto L55 ;         /* close stash and/or recovr file(s), if any */

    L6 :   if (dflag) { if (dmode>=0) disply() ; else typex() ; } /* last */
    if (sflag) dstor() ;                                   /* point */

    L55 :  if (sflag) {                        /* close stash file, if any */
	if (fclose(fd[maxchan])==EOF)  derror(95) ;
	fd[maxchan]=NULL ;
    }
    if (rbegin) {                     /* close recover file, if any */
	if (fclose(fd[maxchan-1])==EOF) derror(95) ;
	fd[maxchan-1]=NULL ;
    }
    if (!dflag || dmode<0) WRITELN ; else dflush() ;
    if (errnum) derror(errnum) ;
}                                                       /* srun */