Ejemplo n.º 1
0
bool ConvexPolygon::isConvex() const
// Algorithme
// effectue le produit vectoriel de tous les cotes
// adjacents
// si ils ont tous le meme signe retourner true
// sinon retourner false
{
    Vect start1(pointList[size-1]);
    start1 -= pointList[0];

    Vect start2(pointList[1]);
    start2 -= pointList[0];

    double firstProd = start1.x*start2.y - start1.y*start2.x;

    for(int i(1); i<size; i++)
    {
        Vect vect1(pointList[i-1]);
        vect1 -= pointList[i];

        Vect vect2(pointList[i+1]);
        vect2 -= pointList[i];

        double prod = vect1.x*vect2.y - vect1.y*vect2.x;

        if(prod*firstProd < 0)
        {
            return false;
        }
    }

    return true;
}
Ejemplo n.º 2
0
void MonitorBar::calculate_VM_stats() {
  calculateVMRegion(int32(start1()), used1(), in_core_percentage_1, old_len_1);
  assert(in_core_percentage_1 >= 0 && in_core_percentage_1 <= 100,
         "wrong percentage");
  if (start2() != NULL) {
    calculateVMRegion(int32(start2()), used2(), in_core_percentage_2, old_len_2);
    assert(in_core_percentage_2 >= 0 && in_core_percentage_2 <= 100,
           "wrong percentage");
  }
}
 static date_type local_dst_start_day(year_type year)
 {
   if (year < 2007) {
     start_rule_functor_pre2007 start1(start_day(year), 
                                       start_month(year));
     return start1.get_date(year);
   }
   start_rule_functor start(start_rule_functor::second,
                            start_day(year), 
                            start_month(year));
   return start.get_date(year);
    
 }
Ejemplo n.º 4
0
void TestChainElement::TestNoShortMoves()
{
	ComparisonContext cContext;
	MockStringWithKnownWeighting start1(&cContext, Original, 0.8);
	start1.Append(new MockStringWithKnownWeighting(&cContext, Original, 3.0));

	MockStringWithKnownWeighting start2(&cContext, Modified, 3.0);
	start2.Append(new MockStringWithKnownWeighting(&cContext, Modified, 0.8));

	start1.Bridge(start2.GetNext());
	start2.Bridge(start1.GetNext());

	start1.FindMoves(&start2);

	assertTest(!start1.IsMoved());
	assertTest(!start2.IsMoved());
	assertTest(start2.GetBridge());
	assertTest(!start1.GetBridge());
}
START_MACHDEP
#define _start _start0
#endif

void
_start (START_ARGS)
{
  SNARF_ARGS (start_argc, start_argv, __environ);

  __mach_init ();

  if (_cthread_init_routine != NULL)
    CALL_WITH_SP (start1, (*_cthread_init_routine) ());
  else
    start1 ();

  /* Should never get here.  */
  LOSE;
}
Ejemplo n.º 6
0
    bool CPolygon::intersert(const Vector2& lineStart, const Vector2& lineEnd, Point2DList& pointList) const
    {
        bool intersected = false;
        for (EdgeIterator p1ei = mCGALPolygon.edges_begin(); p1ei != mCGALPolygon.edges_end(); ++p1ei)
        {
            Vector2 start1((*p1ei).source().x(), (*p1ei).source().y());
            Vector2 end1((*p1ei).target().x(), (*p1ei).target().y());

            float crossx, crossy;

            if ( intersectWith(start1, end1, lineStart, lineEnd, crossx, crossy) )
            {
                pointList.push_back(Vector2(crossx,crossy));

                intersected = true;
            }
        }

        return intersected;
    }
Ejemplo n.º 7
0
//------------------------------------------------------------------------
int notmain ( void )
{
    unsigned int ra;
    unsigned int rb;

    uart_init();
    hexstring(0x12345678);

    PUT32(0x40,0);
    ra=GET32(0x40);
    start1();
    start2();
    start3();
    while(1)
    {
        rb=GET32(0x40);
        if(rb!=ra)
        {
            ra=rb;
            hexstring(ra);
        }
    }
    return(0);
}
Ejemplo n.º 8
0
void displayPlotN(char * title, double xMin, double xMax,  char*xName,  int dim, int N, double**f,double**ff,char**Y)
{ int pid;
  
  if(First) { First=0;   signal(SIGUSR1, disconnect);}  
  
  pid=fork();
  if(pid==0) 
  {  int err,i;
     va_list ap;   
     
     blind=0; 
     err=start1("micrOMEGAs Plot",NULL ,"calchep.ini",NULL);
     if(err) 
     { printf("Can not display plot because micromegas is compiled without X11\n");
       exit(0);
     }
     sprintf(pathtocalchep,"%s/",calchepDir);
     sprintf(pathtohelp,"%s/help/",pathtocalchep);
     clearTypeAhead();     
     plot_Nar(title,xMin,xMax,xName, dim, N, f,ff,Y);
     finish();
     exit(0);
  } else pidList[newPID++]=pid;
}
Ejemplo n.º 9
0
int main(int argc,char** argv)
{  
 char   procName[100],xName[60],yName[60],buff[200];
 double xMin,xMax;
 int xDim=1;
 double yMin,yMax;
 int yDim=1;
 int ptype=-1; 
 double *f=NULL, *df=NULL;

 int i; 
 int n;
 char icon_name[STRSIZ];
 blind=0;

 strcpy(pathtocomphep,argv[0]);
 n = strlen(pathtocomphep)-1;
 while (n>=0 &&  pathtocomphep[n] != f_slash) n--;
 pathtocomphep[n-3]=0;
 sprintf(pathtohelp,"%shelp%c",pathtocomphep,f_slash);

 while(1==fscanf(stdin,"%[^\n]%*c",  buff))
 { char word[40];
   if(buff[0]!='#') break;
   if(1==sscanf(buff+1,"%s",word))
   {      if(strcmp(word,"type")==0)   sscanf(buff+1,"%*s %d",&ptype);  
     else if(strcmp(word,"type")==0)   sscanf(buff+1,"%*s %d",&ptype);  
     else if(strcmp(word,"xMin")==0)   sscanf(buff+1,"%*s %lf",&xMin);  
     else if(strcmp(word,"xMax")==0)   sscanf(buff+1,"%*s %lf",&xMax);  
     else if(strcmp(word,"yMin")==0)   sscanf(buff+1,"%*s %lf",&yMin);  
     else if(strcmp(word,"yMax")==0)   sscanf(buff+1,"%*s %lf",&yMax);  
     else if(strcmp(word,"xDim")==0)   sscanf(buff+1,"%*s %d",&xDim);  
     else if(strcmp(word,"yDim")==0)   sscanf(buff+1,"%*s %d",&yDim);    
     else if(strcmp(word,"title")==0)  
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",procName);  
     }
     else if(strcmp(word,"xName")==0) 
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",xName);  
     }   
     else if(strcmp(word,"yName")==0) 
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",yName);  
     }
   } else break;
   
 }  
  
 f=(double*)malloc(xDim*yDim*sizeof(double));   
 if(ptype)
 { 
   df=(double*)malloc(xDim*yDim*sizeof(double)); 
   sscanf(buff,"%lf  %lf",f,df);  
   for(i=1;i<xDim*yDim;i++) fscanf(stdin,"%lf  %lf",f+i,df+i);
   for(i=1;i<xDim*yDim;i++) if( !finite(f[i])|| !finite(df[i]) )
      { printf(" NAN in table %s\n",procName); return 0;}
 }
 else 
 { 
   sscanf(buff,"%lf",f);
   for(i=1;i<xDim*yDim;i++) fscanf(stdin,"%lf",f+i);
   for(i=1;i<xDim*yDim;i++) if( !finite(f[i])){ printf(" NAN in table %s\n",procName); return 0;} 
 }             
 sprintf(icon_name,"%sicon",pathtocomphep);
 start1(version,icon_name,"calchep.ini;../calchep.ini",NULL);  
 clearTypeAhead();
 if(ptype==2) plot_2(xMin,xMax,xDim,yMin,yMax,yDim,f,df,procName,xName,yName);
 else plot_1(xMin,xMax,xDim,f,df,procName, xName, yName);
 finish();
 return 0;
}
Ejemplo n.º 10
0
void MobileSimulator::MouseMotionEvent(Vec2i screenCoordinates)
{
	Vector2 pos = MathUtil::ScreenToWorld(screenCoordinates);
	_fingerGhost1->SetPosition(pos);
	_fingerGhost2->SetPosition(-pos);

	if (_mouseDown)
	{
		//move touch(es)
		TouchList *tl = &TouchListener::GetTouchList();
		if (tl->size() > 0)
		{
			(*tl)[0]->CurrentPoint = screenCoordinates;
			if ( (*tl)[0]->MotionStartTime < 0.0f )
			{
				(*tl)[0]->MotionStartTime = theWorld.GetCurrentTimeSeconds();
			}
		}
		if (tl->size() > 1)
		{
			Vector2 negCoordsVec = MathUtil::WorldToScreen(-pos);
			Vec2i negCoords(negCoordsVec.X, negCoordsVec.Y);
			(*tl)[1]->CurrentPoint = negCoords;
			if ( (*tl)[1]->MotionStartTime < 0.0f )
			{
				(*tl)[1]->MotionStartTime = theWorld.GetCurrentTimeSeconds();
			}

			Touch* t1 = (*tl)[0];
			Touch* t2 = (*tl)[1];

			Vector2 start1(t1->StartingPoint);
			Vector2 current1(t1->CurrentPoint);
			Vector2 start2(t2->StartingPoint);
			Vector2 current2(t2->CurrentPoint);

			Vector2 initialVector = start2 - start1;
			Vector2 currentVector = current2 - current1;

			Vector2 initNorm = Vector2::Normalize(initialVector);
			Vector2 currentNorm = Vector2::Normalize(currentVector);
			float radiansRotated = acos(Vector2::Dot(initNorm, currentNorm));

			if (!_multiGestureOngoing)
			{					
				Vector2 motion = current1 - start1;

				if (motion.LengthSquared() >= (MULTI_MIN_DISTANCE * MULTI_MIN_DISTANCE) )
				{
					_multiGestureOngoing = true;
					
					// figure out if it's a rotate or a pinch
					if (radiansRotated > MULTI_ROTATE_ANGLE)
					{
						_gestureType = ROTATE;
					}
					else
					{
						_gestureType = PINCH;
					}
				}
			}

			if (_multiGestureOngoing)
			{
				GestureData gd;
				gd.Velocity = 0.0f; // don't want to store all the extra datums
									//  needed to actually calculate this

				if      (_gestureType == ROTATE)
				{
					float cross = Vector2::Cross(initNorm, currentNorm);
					if (cross > 0.0f)
					{
						radiansRotated = -radiansRotated;
					}
					gd.GestureMagnitude = radiansRotated;
					theSwitchboard.Broadcast(new TypedMessage<GestureData>("MultiTouchRotate", gd));
				}
				else if (_gestureType == PINCH)
				{
					gd.GestureMagnitude = currentVector.Length() / initialVector.Length();
					theSwitchboard.Broadcast(new TypedMessage<GestureData>("MultiTouchPinch", gd));	
				}
			}
		}
	}
}
/* N.B.: It is important that this be the first function.
   This file is the first thing in the text section.  */
void
_start ()
{
  start1 ();
}
Ejemplo n.º 12
0
int ll_daemon_start(const char *lockfile)
{
pid_t	p;
int	pipefd[2];
char	c;
int	i;

	/*
	** Close any open file descriptors.
	*/

	for (i=3; i < 256; i++)
		close(i);

	/*
	** We fork, and set up a pipe from the child process.  If we read
	** a single 0 byte from the pipe, it means that the child has
	** succesfully initialized, and will return to main, so we exit(0).
	** If we do not read a single 0 byte from the pipe, it means that
	** there was an initialization error, so we return -1 to main.
	*/

	if (pipe(pipefd) < 0)
	{
		perror("pipe");
		return (-1);
	}

	if ((p=fork()) == -1)
	{
		close(pipefd[0]);
		close(pipefd[1]);
		perror("fork");
		return (-1);
	}

	if (p == 0)
	{
		close(pipefd[0]);

		/*
		** We fork once more, so that the daemon process will not
		** be the child process of anyone.
		*/

		p=fork();
		if (p == -1)
		{
			perror("fork");
			exit(0);
		}
		if (p)
			exit(0);

		/*
		** Continue initialization in start1()
		*/
		return (start1(lockfile, pipefd[1]));
	}

	close(pipefd[1]);
	if (read(pipefd[0], &c, 1) <= 0)
		c=1;
	close(pipefd[0]);
	if (c == 0)
		exit (0);	/* Successful start of daemon */
	errno=EAGAIN;
	return (-1);
}
Ejemplo n.º 13
0
_start ()
{
/* On vax, nothing is pushed here  */
  start1 ();
}
Ejemplo n.º 14
0
int main(int argc,char** argv)
{   

/*===================================
0 - First start.
1 - Model menu.
2 - Enter process menu.
3 - Feynman diagrams menu; squaring.
4 - Squared diagram menu; symbolic calculation.                        
5 - Write results; new process.
10 -Restart symbolic calculations
==========================================================*/

/* 0-Start; 1-Restart; 2-Heap Error,3-Edit Model,4-UserBreak */

  void *pscr1=NULL,*pscr2=NULL,*pscr3=NULL,*pscr4=NULL,*pscr5=NULL;
  int   k1=1,k2=1,k3=1,k4=1,k5=1;

  int n;
  int pid=0;
  char LOCKtxt[]="Directory 'results/' contains the .lock file created by n_calchep.\n"
                 "To continue you may a)Close the n_calchep session, or b)Rename 'results/',\n";
  blind=0;
  strcpy(pathtocomphep,argv[0]);
  for(n=strlen(pathtocomphep)-1; n && pathtocomphep[n]!=f_slash; n--);
  pathtocomphep[n-3]=0;                                         
     
   for ( n=1;n<argc;n++) 
   { if (strcmp(argv[n],"-blind")==0 && n<argc-1 )
     {  blind=1;
        inkeyString=argv[++n];
     }
     if (strcmp(argv[n],"+blind")==0 )  blind=2;                                     
   }    

   if(!writeLockFile(".lock")) 
   { fprintf(stderr,"locked by other s_calchep. See .lock file\n");
      exit(100);
   }
   strcpy(pathtouser,"");  
   sprintf(pathtohelp,"%shelp%c",pathtocomphep,f_slash);
   outputDir="results/";        
   { char * icon=(char *) malloc(strlen(pathtocomphep)+10);
     int err;
     sprintf(icon,"%sicon",pathtocomphep);
     err=start1("CalcHEP/symb",icon,"calchep.ini",&xw_error);
     if(err && blind==0)
     { printf("Error:You have launched interactive session for version compiled  without X11 library.\n");
       printf("Options: a) Use blind session; b) Recompile CalcHEP with X11\n");
       exit(66);
     }      
     free(icon);
   }
   fillModelMenu();
   
   f3_key[0]=f3_key_prog;   f3_mess[0]="Model"; 
   f3_key[1]=f4_key_prog;   f3_mess[1]="Diagrams"; 
   f3_key[2]=f5_key_prog;   f3_mess[2]="Switches";
   f3_key[3]=f6_key_prog;   f3_mess[3]="Results"; 
                            f3_mess[4]="Del"; 
                            f3_mess[5]="UnDel";
   f3_key[6]=f9_key_prog;   f3_mess[6]="Ref";    
   f3_key[7]=f10_key_prog;  f3_mess[7]="Quit";

   restoreent(&menulevel);

   if(!blind && menulevel<2) cheplabel(); 

   switch (menulevel)
   {
      case 10: 
      case 6:
      case 5: 
      case 4:
      case 3: readModelFiles("./models",n_model); 
              modelinfo();
              loadModel(0,forceUG);
              processinfo();
              diagramsinfo();
      case 2: k1=n_model;

      case 1: break;
   }

   switch (menulevel)
   {
      case 2:  menuhelp();
               goto label_20;
      case 3:  goto label_31;
      case 4:  goto label_40;
      case 5:  goto label_50;
      case 6:  
      case 10: goto restart2;
   }
        
label_10:   /*   Menu2(ModelMenu): */
   f3_key[0]=NULL; /*models*/ 
   f3_key[1]=NULL; /*diagrams*/
   menulevel = 1;
   forceUG=0;
   menuhelp();
   for(;;)
   { 
      showheap();
      k1=n_model;
      menu1(56,4,"",modelmenu,"s_1",&pscr1,&k1);
      n_model=k1;
      if(n_model == 0)
      {
	if( mess_y_n(56,4,"Quit session")) {  saveent(menulevel); goto exi; }         
      }
      else  if(n_model == maxmodel+1)
      {
         clrbox(1,4,55,18);
         makenewmodel();
         menuhelp();
      }
      else if (n_model > 0)
      { 
	put_text(&pscr1);
	goto label_20;
      }
   }

label_20:   /*  Menu3:Enter Process  */
   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel = 2;
   saveent(menulevel);
   readModelFiles("./models",n_model);
   modelinfo();
   k2 = 1;
   do
   {  char strmen[]="\026"
        " Enter Process        "
        " Force Unit.Gauge OFF "
        " Edit model           "
        " Delete model         ";

      if(forceUG)improveStr(strmen,"OFF","ON");
      menu1(56,4,"",strmen,"s_2_*",&pscr2,&k2);
      switch (k2)
      {
         case 0:  goto_xy(1,1); clr_eol(); goto label_10;
         case 2:  forceUG=!forceUG;   modelinfo(); break;
	 case 3:  editModel(1); break;
         case 4: 
	    if ( deletemodel(n_model) )
            {
               goto_xy(1,1);
               clr_eol();
               n_model=1;
               fillModelMenu();
               goto label_10;
            }
            else   readModelFiles("./models",n_model);
      }
   }  while (k2 != 1);

   loadModel(0,forceUG);
label_21:

   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel=2;
   errorcode=enter();   /*  Enter a process  */
   newCodes=0;
   showheap();
   if (errorcode)   /*  'Esc' pressed  */ { menuhelp(); goto label_20;}
   errorcode=construct();          /*  unSquared diagrams  */
   if (errorcode) 
   {  if(blind)
      {  printf("Processes of this type are absent\n"); sortie(111); } 
      else 
      { messanykey(5,22,"Processes of this type are absent");  
        clrbox(1,19,80,24); 
        goto label_21;
      }
   }
   else if(!blind)
   { int dirStat=checkDir("results"); 
     if(dirStat!=0)
     {  messanykey( 10,10,"There are files in directory 'results/'.\n"  
                          "To continue you has to clean or rename this directory.");
        viewresults();
        if(checkDir("results")!=0)  goto label_21;                   
     }
     clr_scr(FGmain,BGmain);
     modelinfo();
     processinfo();
     diagramsinfo();
     goto label_31;	
   }
   
label_30: /*  Menu4: Squaring,...*/
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
label_31: 

   f3_key[0]=f3_key_prog; 
   f3_key[1]=NULL; 

   menulevel=3;  
   k3 = 1;
   do
   {
      menu1(56,4,"","\026"
         " View diagrams        "
/*         " Amplitude calculation" */
         " Squaring technique   "
         " Write down processes ","s_squa_*",&pscr3,&k3);
      switch (k3)
      {
         case 0: clrbox(1,2,55,11); menuhelp(); goto label_20;
         case 1: viewfeyndiag(1);   break;
         case 3: { FILE*f=fopen("results/list_prc.txt","w");
                   int k,ndel,ncalc,nrest;
                   char process[100];
                   long recpos; 
                   menup=fopen(MENUP_NAME,"r");
                   for(k=1;;k++) 
                   { int err=rd_menu(1,k,process,&ndel,&ncalc,&nrest,&recpos);
                     if(!err) break;
                     trim(process);
                     fprintf(f,"%s\n",process);
                   } 
                   fclose(f);
                   fclose(menup);
                    messanykey(20,14,"See file 'results/list_prc.txt'");
 
                 } break; 

/*       case 2: messanykey(10,10,"Not implemented yet"); Amplitudes(); */
      }
   }  while (k3 != 2);      

   if (!squaring()) goto label_30;  /*  process is absent  */

   clear_tmp();

   saveent(menulevel);
   restoreent(&menulevel);  

label_40:   /*  Menu5: View squared diagrams.....   */

   f3_key[0]=f3_key_prog; 
   f3_key[1]=f4_key_prog; 

   menulevel=4;
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
   sq_diagramsinfo(); /*   ????????   */

   k4=1;
   saveent(menulevel);
   pscr4=NULL;
   for(;;)   
   {  int res;
      menu1(56,4,"","\026"
         " View squared diagrams"
         " Symbolic calculations"
         " Make&Launch n_calchep"        
         " Make n_calchep       "
         " REDUCE program       "
         ,"s_calc_*",&pscr4,&k4);

      res=checkDir("results");
      if(res==1)
      {
        int  n_calchep_id=setLockFile("results/.lock");
        if(n_calchep_id) unLockFile(n_calchep_id); else res=2;                          
      }
      switch (k4)
      {  case 0:
            if (mess_y_n(50,3,"Return to previous menu?"))goto label_30;
         break;

         case 1:
            viewsqdiagr();  break;

         case 2:     /*  Compute all diagrams   */
restart2:
            f3_key[0]=f3_key_prog; 
            f3_key[1]=f4_key_prog; 

            menulevel=4;
            calcallproc();
            sq_diagramsinfo();

            if(!continuetest()) break; 
            showheap();  
            put_text(&pscr4);
         break;
         case 3:
            { static char keystr[12]="]{{[{";
              if(res==2) messanykey(3,10,LOCKtxt); else inkeyString=keystr;
            }
            break;
         case 4:
            if(res==2) messanykey(3,10,LOCKtxt); else
            { char command[100];
              FILE *f=fopen("results/EXTLIB","w");
              fprintf(f,"EXTLIB=\"%s\"\nexport EXTLIB\n",EXTLIB);
              fclose(f); 
              saveent(menulevel);
{ char command[100];
  sprintf(command,"cd results; $CALCHEP/bin/make_VandP  ../models  %d",n_model);
  system(command);
}                 
              finish();
              sortie(22);
            }
         case 5:  mk_reduceprograms();  break;
      }
      if(k4==2 && continuetest()) { put_text(&pscr4); break; }
   }

label_50:
   k5=1;
   pscr5=NULL;
   menulevel=5;
   saveent(menulevel);
   
   for(;;)  
   {  int n_calchep_id;   
      menu1(56,4,"","\026"
         " C code               "
         "     C-compiler       "
         "     Edit Linker      "
         " REDUCE code          "
         " MATHEMATICA code     "
         " FORM code            "
         " Enter new process    " ,"s_out_*",&pscr5,&k5);
         
      if((k5==1||k5==2)&&pid) 
      { int epid=waitpid(pid,NULL,WNOHANG);
        if(epid) pid=0; else
        { 
          messanykey(3,10,"This option is frozen while n_calchep runs or is compiled");
          continue;
        }
      }  

      switch (k5)
      {  case 0: goto label_40;  break;
         case 1:
           c_prog(); newCodes=0; saveent(menulevel);
           break;
         case 2:
           if(newCodes) { c_prog(); newCodes=0; saveent(menulevel);} 
           pid=fork();
           if(pid==0)
           { 
             char * command;
             n_calchep_id=setLockFile("results/.lock"); 
             if(n_calchep_id)
             {  
               command=(char*)malloc(strlen(pathtocomphep)+strlen(EXTLIB)+100);
               sprintf(command,"EXTLIB=\"%s\"\n"
                               "export EXTLIB\n"
                               "cd results\n"
                               "xterm -e %s/make__n_calchep %d",
                               EXTLIB,pathtocomphep,n_model);                                 
               system(command);
               sprintf(command,"cd results; ./n_calchep"); 
               unLockFile(n_calchep_id);
               system(command); 
               free(command);
             }
             exit(0);
           }
           break;
         case 3: if(edittable(1,1,&modelTab[4],1," ",0))
                 {  char fName[STRSIZ];
                    readEXTLIB();
                    sprintf(fName,"%smodels%c%s%d.mdl",pathtouser,f_slash,mdFls[4],n_model);
                    writetable( &modelTab[4],fName); 
                 }
                 break;
         case 4: makeReduceOutput(); break;
         case 5: makeMathOutput();   break; 
	 case 6: makeFormOutput();   break;
   
         case 7:
            put_text(&pscr5);
            clrbox(1,2,55,11);
            menuhelp();
            goto label_20;
      }
   }

exi:
   finish();
   sortie(0);
   return 0;
}
Ejemplo n.º 15
0
int main(int argc,char** argv)
{   

/*===================================
0 - First start.
1 - Model menu.
2 - Enter process menu.
3 - Feynman diagrams menu; squaring.
4 - Squared diagram menu; symbolic calculation.                        
5 - Write results; new process.
10 -Restart symbolic calculations
==========================================================*/

/* 0-Start; 1-Restart; 2-Heap Error,3-Edit Model,4-UserBreak */

  void *pscr1=NULL,*pscr2=NULL,*pscr3=NULL,*pscr4=NULL,*pscr5=NULL;
  int   k1=1,k2=1,k3=1,k4=1,k5=1;

  int n;
  int pid=0;
  char LOCKtxt[]="Directory 'results/' contains the .lock file created by n_calchep.\n"
                 "To continue you may a)Close the n_calchep session, or b)Rename 'results/',\n";


  blind=0;
  strcpy(pathtocalchep,argv[0]);
  for(n=strlen(pathtocalchep)-1; n && pathtocalchep[n]!=f_slash; n--);
  pathtocalchep[n-3]=0;                                         
     
   for ( n=1;n<argc;n++) 
   { if (strcmp(argv[n],"-blind")==0 && n<argc-1 )
     {  blind=1;
        inkeyString=argv[++n];
     }
     if (strcmp(argv[n],"+blind")==0 )  blind=2;                                     
     if (strcmp(argv[n],"--version")==0 ) { printf("%s\n", VERSION_); exit(0);}
   }    

   if(!writeLockFile(".lock")) 
   { fprintf(stderr,"locked by other s_calchep. See .lock file\n");
      exit(100);
   }
   strcpy(pathtouser,"");  
   sprintf(pathtohelp,"%shelp%c",pathtocalchep,f_slash);
   outputDir="results/";        
   { char * icon=(char *) malloc(strlen(pathtocalchep)+20);
     char  title[30];
     int err;
     sprintf(icon,"%s/include/icon",pathtocalchep);
     sprintf(title,"CalcHEP_%s/symb", VERSION);
     err=start1(title,icon,"calchep.ini",&xw_error);
     if(err && blind==0)
     { printf("Error:You have launched interactive session for version compiled  without X11 library.\n");
       printf(" Presumably X11 development package is not installed in your computer.\n");
       printf(" In this case directory /usr/include/X11/ is empty.\n");       
       printf("Options: a) Use blind session; b) Update Linux and recompile CalcHEP \n");
       printf("Name of needed package\n");
       printf("     libX11-devel      Fedora/Scientific Linux/CYGWIN/Darwin(MAC)\n");
       printf("     libX11-dev        Ubuntu/Debian\n");
       printf("     xorg-x11-devel    SUSE\n");

       exit(66);
     }      
     free(icon);
   }
   fillModelMenu();
   
   f3_key[0]=f3_key_prog;   f3_mess[0]="Model"; 
   f3_key[1]=f4_key_prog;   f3_mess[1]="Diagrams"; 
   f3_key[2]=f5_key_prog;   f3_mess[2]="Switches";
   f3_key[3]=f6_key_prog;   f3_mess[3]="Results"; 
                            f3_mess[4]="Del"; 
                            f3_mess[5]="UnDel";
   f3_key[6]=f9_key_prog;   f3_mess[6]="Ref";    
   f3_key[7]=f10_key_prog;  f3_mess[7]="Quit";

   restoreent(&menulevel);

   if(!blind && menulevel<2) cheplabel(); 

   switch (menulevel)
   {
      case 10: 
      case 6:
      case 5: 
      case 4:
      case 3: readModelFiles("./models",n_model); 
              modelinfo();
              loadModel(0,forceUG);
              processinfo();
              diagramsinfo();
              k1=n_model;
              break;
      case 2: k1=n_model;
              readModelFiles("./models",n_model);
              break; 
   }

   switch (menulevel)
   {
      case 2:  menuhelp();
               goto label_20;
      case 3:  goto label_31;
      case 4:  goto label_40;
      case 5:  goto label_50;
      case 6:  
      case 10: goto restart2;
   }
        
label_10:   /*   Menu2(ModelMenu): */
   f3_key[0]=NULL; /*models*/ 
   f3_key[1]=NULL; /*diagrams*/
   menulevel = 1;
   forceUG=0;
   menuhelp();
   for(;;)
   { 
      showheap();
      k1=n_model;
      menu1(56,4,"",modelmenu,"s_1",&pscr1,&k1);
      if(k1 == 0)
      {  
	if( mess_y_n(56,4,"Quit session")) {n_model=0;   saveent(menulevel); goto exi; }         
      }
      else  if(k1 == maxmodel+1)
      {
         clrbox(1,4,55,18);
         makenewmodel();
         menuhelp();
      }
      else if (k1 > 0)
      { int err=0;
        put_text(&pscr1);
        if(k1!=n_model || ldModelStatus==0) { err=readModelFiles("./models",k1);}
        n_model=k1;
        if(err){ if(blind) sortie(133); else  goto label_10;} else goto label_20;
      }
   }

label_20:   /*  Menu3:Enter Process  */
   f3_key[0]=NULL; 
   f3_key[1]=NULL; 

   menulevel = 2;
   saveent(menulevel);
   
   modelinfo();
   k2 = 1;
   
   do
   {  char strmen[]="\026"
        " Enter Process        "
        " Force Unit.Gauge= OFF"
        " Edit model           "
        " Numerical Evaluation "
        "======================"
        " Delete model         ";

      if(forceUG)improveStr(strmen,"OFF","ON");
      menu1(56,4,"",strmen,"s_2_*",&pscr2,&k2);
      switch (k2)
      {
         case 0:  goto_xy(1,1); clr_eol(); goto label_10;
         case 2:  forceUG=!forceUG;   modelinfo(); break;
	 case 3:  editModel(1); break;
	 case 4:  numcheck();   
	 case 5:  break;
         case 6: 
	    if(deletemodel(n_model))
            {
               goto_xy(1,1);
               clr_eol();
               n_model=1;
               ldModelStatus=0;
               fillModelMenu();
               goto label_10;
            }
      }
   }  while (k2 != 1);

   if(!loadModel(0,forceUG)) goto  label_20;
   
label_21:

   f3_key[0]=NULL; 
   f3_key[1]=NULL; 
   
   menulevel=2;
   checkAuxDir(n_model);
   errorcode=enter();   /*  Enter a process  */
   newCodes=0;
   showheap();
   if (errorcode)   /*  'Esc' pressed  */ { menuhelp(); goto label_20;}
   errorcode=construct();          /*  unSquared diagrams  */
   if (errorcode) 
   {  if(blind)
      {  printf("Processes of this type are absent\n"); sortie(111); } 
      else 
      { messanykey(5,22,"Processes of this type are absent");  
        clrbox(1,19,80,24); 
        goto label_21;
      }
   }
   else if(!blind)
   { int dirStat=checkDir("results"); 
     if(dirStat!=0)
     {  messanykey( 10,10,"There are files in directory 'results/'.\n"  
                          "To continue you has to clean or rename this directory.");
        viewresults();
        if(checkDir("results")!=0)  goto label_21;                   
     }
     clr_scr(FGmain,BGmain);
     modelinfo();
     processinfo();
     diagramsinfo();
     goto label_31;	
   }
   
label_30: /*  Menu4: Squaring,...*/
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
label_31: 

   f3_key[0]=f3_key_prog; 
   f3_key[1]=NULL; 

   menulevel=3;  
   k3 = 1;
   do
   {
      menu1(56,4,"","\026"
         " View diagrams        "
/*         " Amplitude calculation" */
         " Square diagrams      "
         " Write down processes ","s_squa_*",&pscr3,&k3);
      switch (k3)
      {
         case 0: clrbox(1,2,55,11); menuhelp(); goto label_20;
         case 1: viewfeyndiag(1);   break;
         case 3: { FILE*f=fopen("results/list_prc.txt","w");
                   int k,ndel,ncalc,nrest;
                   char process[100];
                   long recpos; 
                   menup=fopen(MENUP_NAME,"r");
                   for(k=1;;k++) 
                   { int err=rd_menu(1,k,process,&ndel,&ncalc,&nrest,&recpos);
                     if(!err) break;
                     trim(process);
                     fprintf(f,"%s\n",process);
                   } 
                   fclose(f);
                   fclose(menup);
                    messanykey(20,14,"See file 'results/list_prc.txt'");
 
                 } break; 

/*       case 2: messanykey(10,10,"Not implemented yet"); Amplitudes(); */
      }
   }  while (k3 != 2);      

   if (!squaring()) goto label_30;  /*  process is absent  */

   clear_tmp();

   saveent(menulevel);
   restoreent(&menulevel);  

label_40:   /*  Menu5: View squared diagrams.....   */

   f3_key[0]=f3_key_prog; 
   f3_key[1]=f4_key_prog; 

   menulevel=4;
   clr_scr(FGmain,BGmain);
   modelinfo();
   processinfo();
   diagramsinfo();
   sq_diagramsinfo(); /*   ????????   */

   k4=1;
   saveent(menulevel);
   pscr4=NULL;
   for(;;)   
   {  int res;
      menu1(56,4,"","\026"
         " View squared diagrams"
         " Symbolic calculations"
         " Make&Launch n_calchep"        
         " Make n_calchep       "
         " REDUCE program       "
         ,"s_calc_*",&pscr4,&k4);

      res=checkDir("results");
      if(res==1)
      {
        int  n_calchep_id=setLockFile("results/.lock");
        if(n_calchep_id) unLockFile(n_calchep_id); else res=2;                          
      }
      switch (k4)
      {  case 0:
            if (mess_y_n(50,3,"Return to previous menu?"))goto label_30;
         break;

         case 1:
            viewsqdiagr();  break;

         case 2:     /*  Compute all diagrams   */
restart2:
            f3_key[0]=f3_key_prog; 
            f3_key[1]=f4_key_prog; 

            menulevel=4;
                        
            if(!nPROCSS ) calcallproc(); else 
            { int *pids=malloc(sizeof(int)*nPROCSS);
              int *pipes=malloc(2*sizeof(int)*nPROCSS);
              int **qd=malloc(sizeof(int*)*nPROCSS);
              int totD=sqDiagList(qd, nPROCSS);
              int totC,nProc;
              int k;
              
              fflush(NULL);
              for(k=0;k<nPROCSS;k++) 
              { int* kpipe=pipes+2*k;
                pipe(kpipe);
                pids[k]=fork();
                if(pids[k]==0)
                { 
                  close(kpipe[0]);
                  calcWithFork(k,qd[k],kpipe[1]);
                  exit(0);
                }
              }
              for(k=0;k<nPROCSS;k++) close(pipes[2*k+1]);
              infoLine(0.);
              for(nProc=nPROCSS,totC=0;nProc;)
              { int one;
                int err;
                nProc=0;
                for(k=0;k<nPROCSS;k++) if(pids[k])
                { if(waitpid(pids[k],NULL,WNOHANG)==0)
                  {  nProc++; 
                     if(read(pipes[2*k],&one,sizeof(int)))totC+=one;
                  } else 
                  { for(;read(pipes[2*k],&one,sizeof(int))>0;) totC+=one;
                     pids[k]=0;
                  }
                }  
                if(infoLine((double)totC/(double)totD)) for(k=0;k<nPROCSS;k++) if(pids[k]) kill(pids[k],SIGUSR1);   
              }  
              infoLine(2);
              for(k=0;k<nPROCSS;k++)
              { char ctlgName[100];
                char command[200];
                sprintf(ctlgName,"%s_%d",CATALOG_NAME,k);
                if(access(ctlgName,R_OK)==0)
                { sprintf(command," cat %s >> %s", ctlgName,CATALOG_NAME);
                  system(command);
                  unlink(ctlgName);   
                }
              }
              if(totC)  newCodes=1;  
              updateMenuQ();
              
              for(k=0;k<nPROCSS;k++) close(pipes[2*k]);
              free(pids);   
              free(pipes);
              for(k=0;k<nPROCSS;k++) free(qd[k]);
              free(qd);   
            }
            
            sq_diagramsinfo();

            if(!continuetest()) break; 
            showheap();  
            put_text(&pscr4);
         break;
         case 3:
            { static char keystr[12]="]{{[{";
              if(res==2) messanykey(3,10,LOCKtxt); else inkeyString=keystr;
            }
            break;
         case 4:
            if(res==2) messanykey(3,10,LOCKtxt); else
            { char command[100];
              saveent(menulevel);
              chdir("results");
              makeVandP(0,"../models",n_model,2,pathtocalchep);
              finish();
              sortie(22);
            }
         case 5:  mk_reduceprograms();  break;
      }
      if(k4==2 && continuetest()) { put_text(&pscr4); break; }
   }

label_50:
   k5=1;
   pscr5=NULL;
   menulevel=5;
   saveent(menulevel);
   sq_diagramsinfo();
      
   for(;;)  
   {  int n_calchep_id;   
      menu1(56,4,"","\026"
         " C code               "
         "     C-compiler       "
         "     Edit Linker      "
         " REDUCE code          "
         " MATHEMATICA code     "
         " FORM code            "
         " Enter new process    " ,"s_out_*",&pscr5,&k5);
          
      if((k5==1||k5==2)&&pid) 
      { int epid=waitpid(pid,NULL,WNOHANG);
        if(epid) pid=0; else
        { 
          messanykey(3,10,"This option is frozen while n_calchep runs or is compiled");
          continue;
        }
      }  

      switch (k5)
      {  case 0: goto label_40;  break;
         case 1:
           c_prog(); newCodes=0; saveent(menulevel);
           break;
         case 2:
           if(newCodes) { c_prog(); newCodes=0; saveent(menulevel);}
          n_calchep_id=setLockFile("results/.lock"); 
           if(n_calchep_id)
           {
             if(nPROCSS)
             { chdir("results"); 
                makeVandP(0,"../models",n_model,2,pathtocalchep);
               pCompile();
               if(access("./n_calchep",X_OK)==0)
               { 
                  fflush(NULL); 
                  pid=fork();   
                  if(pid==0) 
                  {
                    system("./n_calchep");
                    exit(0);
                  }    
               } else messanykey(15,15,"n_calchep is not generated");
               chdir("../");
             } else                       
             { fflush(NULL); 
               pid=fork();
               if(pid==0)
               {  if(chdir("results")==0)
                  {   char*command=malloc(100+strlen(pathtocalchep));
                      makeVandP(0,"../models",n_model,2,pathtocalchep); 
                      sprintf(command,"xterm -e %s/sbin/make__n_calchep %d", pathtocalchep,n_model);                                 
                      system(command);
                      free(command);
                      system("./n_calchep");                     
                   }
                   exit(0);    
               }
             }
             unLockFile(n_calchep_id); 
           } 
           break;
         case 3: if(edittable(1,1,&modelTab[4],1," ",0))
                 {  char fName[STRSIZ];
                    sprintf(fName,"%smodels%c%s%d.mdl",pathtouser,f_slash,mdFls[4],n_model);
                    writetable( &modelTab[4],fName); 
                 }
                 break;
         case 4: makeReduceOutput(); break;
         case 5: makeMathOutput();   break; 
	 case 6: makeFormOutput();   break;
   
         case 7:
            put_text(&pscr5);
            clrbox(1,2,55,11);
            menuhelp();
            goto label_20;
      }
   }

exi:
   finish();
   sortie(0);
   return 0;
}
Ejemplo n.º 16
0
int main(int argc,char** argv)
{
  int n;
  char icon[200];
  char title[30];

  blind=0;
  for( n=1;n<argc;n++) 
  {
    if(strcmp(argv[n],"--version")==0)  {  printf("%s\n",VERSION_); exit(0); }
    if(strcmp(argv[n],"-blind")==0&& n<argc-1 )
    { blind=1;     
      inkeyString=argv[++n];
    } else  if (strcmp(argv[n],"+blind")==0 ) blind=2;
  }

  if(!writeLockFile(".lock"))
  { fprintf(stderr,"locked by other n_calchep. See .lock\n");
    exit(100);
  }
                 
  setenv("CALCHEP",rootDir,0);
  sprintf(pathtocalchep,"%s%c",rootDir,f_slash);
  sprintf(pathtohelp,"%shelp%c",pathtocalchep,f_slash);
  sprintf(icon,"%s/include/icon",pathtocalchep);
  sprintf(title,"CalcHEP_%s/num", VERSION);

  f3_key[2]=f5_key_prog;   f3_mess[2]="Options";
  f3_key[3]=f6_key_prog;   f3_mess[3]="Results";
  f3_key[5]=f8_key_prog;   f3_mess[5]="Calc";
  f3_key[6]=f9_key_prog;   f3_mess[6]="Ref";
  f3_key[7]=f10_key_prog;  f3_mess[7]="Quit";
  
  { int size=100;
     for(;;)
     {  compDir=realloc(compDir,size+20);
        if(getcwd(compDir,size)) break; else size*=2;
     }
     strcat(compDir,"/aux");
     libDir=malloc(strlen(compDir)+20);
     sprintf(libDir,"%s/so_generated",compDir);
     modelNum=1;
     calchepDir=getenv("CALCHEP");
     if(!calchepDir) calchepDir=interface_ext.CALCHEP;
     ForceUG=interface_ext.forceUG;
  }
  

/* **  initialization of the session */
  link_process(PtrInterface_ext);  


  start1(title,icon,"calchep.ini;../calchep.ini",&xw_error);
  nPROCSS=sysconf(_SC_NPROCESSORS_ONLN); 

  if(r_sess__(NULL)==-1)
  { 
     char buff[200];
     int pdg[11]={21,1,-1,2,-2,3,-3,4,-4,5,-5};  
     int k,ok=0;
     strcpy(buff,"{p*\\09");
     for(k=0;k<11;k++)
     {  char*ch=pdg2name(pdg[k]);
        if(ch)
        {  if(ok) strcat(buff,",");
           strcat(buff,ch);
           ok=1;
        }   
     }
     strcat(buff,"}");
     if(ok)
     {  int  blind0=blind;
        char*inkeyString0=inkeyString;    
        inkeyString=buff;
        blind=1;
        edittable(1,4,&compTab,1,"n_comp",0);
        blind=blind0;
        inkeyString=inkeyString0;
        fillCompositeArray();
        
        strcpy(buff,"{%\\09T(p*)\\09 50{%\\09J(p*,p*)\\09 0.5}");
        inkeyString=buff;
        blind=1;
        edittable(1,4,&cutTab,1,"n_cut",0);
        blind=blind0;
        inkeyString=inkeyString0;
     }   
  }
  { char *ch=getenv("nParProc");
    if(ch) sscanf(ch,"%d",&nPROCSS);
  }  
  goto_xy(10,10); print("Calculation of constraints.  Please, be patient.");
  escpressed();
  n_comphep();
  finish();  
  sortie(0);
}