
static void getExternalMoment(int i, int j, vampl * v, char * list )
{
  if(v->vertlist[i][j].nextvert.edno==nullvert) 
  { list[0]=v->vertlist[i][j].moment;
    list[1]=0;
  }else
  { int ii=v->vertlist[i][j].nextvert.vno-1;
    int jj=v->vertlist[i][j].nextvert.edno-1;
    int k=0;
    int lpos=0;
      
    for(k=0;k<v->valence[ii];k++)
    if(k!=jj) 
    { 
      getExternalMoment(ii,k,v,list+lpos);
      lpos=strlen(list);
    }
  }  
}



static int  fermLines[MAXINOUT];

static void sCalcAmpl(vampl * v)
{ int nmom=v->outno, nlor=0;
  int i,j;
   for(i=0;i<v->size;i++)
   for(j=0;j<v->valence[i];j++) 
   {edgeinvert *  ln=&v->vertlist[i][j];
      if(ln->nextvert.vno == nullvert)   
      { ln->moment=ln->nextvert.edno;
        if(vectorp(ln->partcl))  ln->lorentz=++nlor;
      }  
   }

   for(i=0;i<v->size;i++)
   for(j=0;j<v->valence[i];j++) 
   {edgeinvert *  ln=&v->vertlist[i][j];
     if(ln->nextvert.vno != nullvert)
     { edgeinvert * next=&v->vertlist[ln->nextvert.vno-1][ln->nextvert.edno-1]; 
           
       if(!ln->moment)  { ln->moment=++nmom; next->moment=-ln->moment;}
       if(!ln->lorentz&&vectorp(ln->partcl))
       { ln->lorentz=++nlor;
         next->lorentz=nlor;
        }
     }  
   }
   
   for(i=0;i<MAXINOUT;i++) fermLines[i]=0;
   for(i=0;i<v->outno;i++) if(fermLines[i]==0)
   { int ii=v->outer[i].vno-1;
     int jj=v->outer[i].edno-1;
     if(prtclbase[v->vertlist[ii][jj].partcl-1].spin ==1) 
     {
       while(1) 
       {  int k=0;  
          while(k==jj||prtclbase[v->vertlist[ii][k].partcl-1].spin !=1) k++;

          if(v->vertlist[ii][k].nextvert.vno==nullvert)
          { 
              ii=v->vertlist[ii][jj].nextvert.edno;
              fermLines[i]=ii;
              fermLines[ii]=i;
              break;
          }else
          {                 
             jj=v->vertlist[ii][k].nextvert.edno-1;
             ii=v->vertlist[ii][k].nextvert.vno-1;
          }
       }
     }  
   }

}


static void symbolicAmplitude(void)
{ adiagramTar adiagTar;
  FILE *diagrpTar=fopen(DIAGRPTAR_NAME,"r+b");
  int fpos=ftell(diagrpTar);
  
  while(1 == fread(&adiagTar,sizeof(adiagTar),1,diagrpTar) )
  {   
     if(adiagTar.status==0) 
     { 
       sCalcAmpl(&(adiagTar.Ampl));
       adiagTar.status=1;
       fseek(diagrpTar,fpos,SEEK_SET);
       fwrite(&adiagTar,sizeof(adiagTar),1,diagrpTar);
       fseek(diagrpTar,ftell(diagrpTar),SEEK_SET);
       fpos=ftell(diagrpTar);
     }
  }

  fclose(diagrpTar);

  messanykey(10,10,"Place for symbolic $"
                          "calculation program$");
}



static void codeAmplitude(void)
{   
   messanykey(10,10,"Place for REDUCE code $program$");
}
                          
