Example #1
0
int
main(int argc, char *argv[])
{
	char *infile, *swf, *outfile;
	long work_factor;
	char *cptr;
	unsigned char *param, *dp;
	size_t param_len, dp_len;

	if (argc != 4) {
		usage();
	}
	infile = argv[1];
	swf = argv[2];
	outfile = argv[3];
	work_factor = strtol(swf, &cptr, 0);
	if (*swf == 0 || *cptr != 0 || work_factor < 0) {
		usage();
	}
	param = read_file(infile, &param_len);
	CF(makwa_delegation_generate(param, param_len,
		work_factor, NULL, &dp_len));
	dp = xmalloc(dp_len);
	CF(makwa_delegation_generate(param, param_len,
		work_factor, dp, &dp_len));
	write_file(outfile, dp, dp_len);
	xfree(param);
	xfree(dp);
	return 0;
}
Example #2
0
Word CF(Word L,Word F,Word P)
{
  Word Fp,A,Ap,f;

  switch(FIRST(F)) {
  case (TRUE)  : Fp = F; break;
  case (FALSE) : Fp = F; break;
  case (ANDOP) : 
    A = RED(F);
    for(Ap = NIL; A != NIL; A = RED(A)) {
      f = CF(L,FIRST(A),P);
      if (FIRST(f) == FALSE) {
	Fp = f;
	goto Return; }
      if (FIRST(f) != TRUE)
	Ap = COMP(f,Ap); }
    if (Ap == NIL)
      Fp = LIST1(TRUE);
    else if (LENGTH(Ap) == 1)
      Fp = FIRST(Ap);
    else
      Fp = COMP(ANDOP,Ap);
    break;
  case (OROP) :
    A = RED(F);
    for(Ap = NIL; A != NIL; A = RED(A)) {
      f = CF(L,FIRST(A),P);
      if (FIRST(f) == TRUE) {
	Fp = f;
	goto Return; }
      if (FIRST(f) != FALSE)
	Ap = COMP(f,Ap); }
    if (Ap == NIL)
      Fp = LIST1(FALSE);
    else if (LENGTH(Ap) == 1)
      Fp = FIRST(Ap);
    else
      Fp = COMP(OROP,Ap);
    break;
  default:
    f = UNIFORMTV(L,F,P);
    if (f == UNDET)
      Fp = F;
    else
      Fp = LIST1(f);
    break; }
Return:
  return Fp;
}
Example #3
0
int
main(int argc, char *argv[])
{
	char *nargv[3];
	int i, nargc;
	char *infile, *swf, *outfile;
	long work_factor;
	char *cptr;
	unsigned char *param, *dp;
	size_t param_len, dp_len;
	int param_type;

	nargc = 0;
	param_type = MAKWA_RANDOM_PAIRS;
	for (i = 1; i < argc; i ++) {
		if (eq_nocase(argv[i], "-genX")) {
			param_type = MAKWA_GENERATOR_EXPAND;
		} else if (eq_nocase(argv[i], "-gen1")) {
			param_type = MAKWA_GENERATOR_ONLY;
		} else {
			if (nargc >= 3) {
				usage();
			}
			nargv[nargc ++] = argv[i];
		}
	}
	if (nargc != 3) {
		usage();
	}
	infile = nargv[0];
	swf = nargv[1];
	outfile = nargv[2];
	work_factor = strtol(swf, &cptr, 0);
	if (*swf == 0 || *cptr != 0 || work_factor < 0) {
		usage();
	}
	param = read_file(infile, &param_len);
	CF(makwa_delegation_generate_gen(param, param_len,
		work_factor, param_type, NULL, &dp_len));
	dp = xmalloc(dp_len);
	CF(makwa_delegation_generate_gen(param, param_len,
		work_factor, param_type, dp, &dp_len));
	write_file(outfile, dp, dp_len);
	xfree(param);
	xfree(dp);
	return 0;
}
Example #4
0
/*
Inputs
S:  a set of cells of level k - 1.
F:  a DNF formula (formally speaking!)
P:  the projection factors that go with the cells in S.
Outputs
Fp: a formula that, restricted to the children of S, is
    equivalent to F.
*/
Word CLEANUPFORM(Word S,Word F,Word P)
{
    Word Sp,L,Fp;
    for(Sp = S, L = NIL; Sp != NIL; Sp = RED(Sp))
      L = CCONC(LELTI(FIRST(Sp),SC_CDTV),L);
    Fp = CF(L,F,P);
    return Fp;
}
Example #5
0
	void Cells::add( const char* row, const char* columnFamily, const char* columnQualifier, uint64_t timestamp, const void* value, uint32_t valueLength, uint8_t flag ) {
		if( valueLength > Cell::MaxSize ) {
			HT4C_THROW_ARGUMENT("cell value exceeds the limit", "valueLength");
		}

		flag = FLAG( columnFamily, columnQualifier, flag );
		Cell cell( row
						 , CF(columnFamily)
						 , columnQualifier
						 , TIMESTAMP(timestamp, flag)
						 , value
						 , valueLength
						 , flag);

		cellsBuilder->add( cell.get(), true );
	}
Example #6
0
static void
c_f_conversion(double *cels_arr, double *far_arr, int arr_len)
{
    int val_len;
    int sign;
    int dot_pos;
    char buff[BUFF_SIZE+1];

    for (int i = 0; i < arr_len; i++) {
        val_len = 0;
        sign = 0;
        dot_pos = 0;
        for (int j = 0; j < BUFF_SIZE; j++) { buff[j] = '0'; }

        double_to_buff(cels_arr[i], buff, &val_len, &dot_pos, &sign);
        CF(buff, &val_len, &dot_pos, &sign);
        far_arr[i] = buff_to_double(buff, dot_pos, sign);
    }
}
void Node::Print_Summary(Stat *Stats, std::ofstream &fo) const 
{
Entry tmpent;
tmpent.Init(entry[0].sx.dim);
CF(tmpent);
fo<<"Root CF\t"<<tmpent<<std::endl;
fo<<"FootPrint\t"<<sqrt(tmpent.Radius())<<std::endl;

#ifdef RECTANGLE
Rectangle tmprect;
tmprect.Init(entry[0].sx.dim);
Rect(tmprect);
fo<<"Root Rectangle\t"<<tmprect<<std::endl;
#endif RECTANGLE

fo<<"Leaf Nodes\t"<<LeafNum()<<std::endl;
fo<<"Nonleaf Nodes\t"<<NonleafNum()<<std::endl;
fo<<"Tree Size\t"<<Size()<<std::endl;
fo<<"Tree Depth\t"<<Depth()<<std::endl;

fo<<"Leaf Entries\t"<<NumLeafEntry()<<std::endl;
fo<<"Nonleaf Entries\t"<<NumNonleafEntry()<<std::endl;
fo<<"Occupancy\t"<<Occupancy(Stats)<<std::endl;
}
Example #8
0
//===================
//     PRIVATE
//===================
bool WebServer::setupWebSocket(quint16 port){
  WSServer = new QWebSocketServer("sysadm-server", QWebSocketServer::SecureMode, this);
  //SSL Configuration
  QSslConfiguration config = QSslConfiguration::defaultConfiguration();
	QFile CF( QStringLiteral(SSLCERTFILE) ); 
	  if(CF.open(QIODevice::ReadOnly) ){
	    QSslCertificate CERT(&CF,QSsl::Pem);
	    config.setLocalCertificate( CERT );
	    CF.close();   
	  }else{
	    qWarning() << "Could not read WS certificate file:" << CF.fileName();
	  }
	QFile KF( QStringLiteral(SSLKEYFILE));
	  if(KF.open(QIODevice::ReadOnly) ){
	    QSslKey KEY(&KF, QSsl::Rsa, QSsl::Pem);
	    config.setPrivateKey( KEY );
	    KF.close();	
	  }else{
	    qWarning() << "Could not read WS key file:" << KF.fileName();
	  }
	config.setPeerVerifyMode(QSslSocket::VerifyNone);
	config.setProtocol(SSLVERSION);
  WSServer->setSslConfiguration(config);
  //Setup Connections
  connect(WSServer, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) );
  connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) );
  //  -- websocket specific signals
  connect(WSServer, SIGNAL(closed()), this, SLOT(ServerClosed()) );
  connect(WSServer, SIGNAL(serverError(QWebSocketProtocol::CloseCode)), this, SLOT(ServerError(QWebSocketProtocol::CloseCode)) );
  connect(WSServer, SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*)), this, SLOT(OriginAuthRequired(QWebSocketCorsAuthenticator*)) );
  connect(WSServer, SIGNAL(peerVerifyError(const QSslError&)), this, SLOT(PeerVerifyError(const QSslError&)) );
  connect(WSServer, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(SslErrors(const QList<QSslError>&)) );
  connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(ConnectError(QAbstractSocket::SocketError)) );
  //Now start the server
  return WSServer->listen(QHostAddress::Any, port);
}
Example #9
0
void MODEL::Boundary()
{
  char text[200];

  // initializations ---------------------------------------------------------------------

  if( !boundList )
  {
    boundList = new ELEM* [region->Getnp()];
    if( !boundList )
      REPORT::rpt.Error( kMemoryFault, "can not allocate memory - MODEL::Boundary(1)" );
  }

  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    CF( nd->flag, NODE::kBound );

    nd->mark = false;


    // remove slip boundary conditions ---------------------------------------------------

    if( isFS(nd->bc.kind, BCON::kAutoSlip) )
    {
      CF( nd->bc.kind, BCON::kAutoSlip | BCON::kFixU | BCON::kFixV );
    }

    if( isFS(nd->bc.kind, BCON::kAutoKD) )
    {
      CF( nd->bc.kind, BCON::kAutoKD | BCON::kFixK | BCON::kFixD );
    }
  }


  // determine boundary midside nodes ----------------------------------------------------

  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    // midside nodes which are connected to only one element are boundary nodes ----------

    if( nd->noel == 1  &&  isFS(nd->flag, NODE::kMidsNode) )
    {
      if( !isFS(nd->flag, NODE::kInface) )  SF( nd->flag, NODE::kBound );
    }
  }


  // determine number of boundary elements: nb -------------------------------------------

  int nb = 0;

  for( int n=0; n<region->Getnp(); n++ )
  {
    if( isFS(region->Getnode(n)->flag,NODE::kBound) )  nb++;
  }


  // allocate memory for boundary elements -----------------------------------------------

  bound->Free();
  bound->Alloc( 0, nb );


  // set up boundary elements ------------------------------------------------------------

  int be = 0;       // counter for boundary elements

  for( int re=0; re<region->Getne(); re++ )
  {
    ELEM* el = region->Getelem(re);

    if( isFS(el->flag, ELEM::kDry) )  continue;

    int ncn = el->Getncn();
    int nnd = el->Getnnd();

    for( int i=ncn; i<nnd; i++ )
    {
      // check, if el->nd[i] is a midside boundary node ----------------------------------

      if( isFS(el->nd[i]->flag, NODE::kBound) )
      {
        ELEM* bd = bound->Getelem(be);

        boundList[el->nd[i]->Getno()] = bd;

        int left = i - ncn;
        int rght = (left + 1) % ncn;

        bd->nd[0] = el->nd[left];           // corner nodes
        bd->nd[1] = el->nd[rght];
        bd->nd[2] = el->nd[i];              // midside node

        SF( bd->nd[0]->flag, NODE::kBound );
        SF( bd->nd[1]->flag, NODE::kBound );


        // set shape specifications ------------------------------------------------------

        bd->Setshape( kLine );
        bd->Setname( el->Getname() );

        SF( bd->flag, ELEM::kBound );

        bd->type     = el->type;
        bd->areaFact = 1.0;

        be++;
      }
    }
  }


  ////////////////////////////////////////////////////////////////////////////////////////
  // communicate boundary nodes

//# ifdef _MPI_DBG
//  REPORT::rpt.Output( " (MODEL::Boundary)       communication of boundary nodes", 1 );
//# endif

# ifdef _MPI_
  if( subdom->npr > 1 )
  {
    INFACE* inface = subdom->inface;

    // loop on all interfaces: exchange bound flag ---------------------------------------
    for( int s=0; s<subdom->npr; s++ )
    {
      MPI_Status status;

      int npinf = inface[s].np;

      if( npinf > 0 )
      {
        for( int n=0; n<npinf; n++ )
        {
          NODE* nd = inface[s].node[n];

          if( isFS(nd->flag, NODE::kBound) )  inface[s].sia1[n] = true;
          else                                inface[s].sia1[n] = false;
        }

        MPI_Sendrecv( inface[s].sia1, npinf, MPI_CHAR, s, 1,
                      inface[s].ria1, npinf, MPI_CHAR, s, 1,
                      MPI_COMM_WORLD, &status );

        for( int n=0; n<npinf; n++ )
        {
          NODE* nd = inface[s].node[n];
          if( inface[s].ria1[n] )  SF( nd->flag, NODE::kBound );
        }
      }
    }
  }
# endif
  ////////////////////////////////////////////////////////////////////////////////////////


  // -------------------------------------------------------------------------------------
  // count for newly required boundary conditions
  // note: (sc, 30.10.2004)
  // a boundary condition is needed for marsh-nodes in case of dry-rewet-method 3

  int nbc = 0;

  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    if( isFS(nd->flag, NODE::kBound) )  nbc++;
  }

  sprintf( text,"\n (MODEL::Boundary)       number of boundary elements: %d\n", nb );
  REPORT::rpt.Output( text, 3 );


# ifdef kDebug
{
  int pid;
  MPI_Comm_rank( MPI_COMM_WORLD, &pid );

  char fname[40];
  sprintf( fname, "bound_%02d.inp", pid+1 );

  FILE* id = fopen( fname, "w" );

  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    CF( nd->flag, NODE::kMarker );
  }


  for( int e=0; e<bound->Getne(); e++ )
  {
    ELEM* el = bound->Getelem(e);

    for( int i=0; i<el->getnnd(); i++ )
    {
      SF( el->nd[i]->flag, NODE::kMarker );
    }
  }


  int j = 0;

  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    if( isFS(nd->flag, NODE::kMarker) )  j++;
  }


  fprintf( id, "%6d  %6d   0   0   0\n", j, nb );


  for( int n=0; n<region->Getnp(); n++ )
  {
    NODE* nd = region->Getnode(n);

    if( isFS(nd->flag, NODE::kMarker) )
    {
      fprintf( id, "%6d  %17.9le  %17.9le  %17.9le\n",
                   nd->Getname(), nd->x, nd->y, nd->z );
    }
  }

  for( int e=0; e<bound->Getne(); e++ )
  {
    ELEM* el = bound->Getelem(e);

    fprintf( id, "%6d  %3d  line   %6d  %6d  %6d\n",
                 el->Getname(), TYPE::getid(el->type),
                 el->nd[0]->Getname(), el->nd[1]->Getname(), el->nd[2]->Getname() );
  }

  fclose( id );
}
# endif
}
Example #10
0
	void ThriftTableMutator::set( const char* columnFamily, const char* columnQualifier, uint64_t timestamp, const void* value, uint32_t valueLength, std::string& row ) {
		row = Common::KeyBuilder();
		set( row.c_str(), CF(columnFamily), columnQualifier, timestamp, value, valueLength, Hypertable::FLAG_INSERT );
	}
Example #11
0
TESTLAYER_CREATE_FUNC(SchedulerPauseResume)
TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAll)
TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAllUser)
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAll)
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllHard)
TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllUserLevel)
TESTLAYER_CREATE_FUNC(SchedulerSchedulesAndRemove)
TESTLAYER_CREATE_FUNC(SchedulerUpdate)
TESTLAYER_CREATE_FUNC(SchedulerUpdateAndCustom)
TESTLAYER_CREATE_FUNC(SchedulerUpdateFromCustom)
TESTLAYER_CREATE_FUNC(RescheduleSelector)
TESTLAYER_CREATE_FUNC(SchedulerDelayAndRepeat)
TESTLAYER_CREATE_FUNC(SchedulerIssue2268)

static NEWTESTFUNC createFunctions[] = {
    CF(SchedulerTimeScale),
    CF(TwoSchedulers),
    CF(SchedulerAutoremove),
    CF(SchedulerPauseResume),
    CF(SchedulerPauseResumeAll),
    CF(SchedulerPauseResumeAllUser),
    CF(SchedulerUnscheduleAll),
    CF(SchedulerUnscheduleAllHard),
    CF(SchedulerUnscheduleAllUserLevel),
    CF(SchedulerSchedulesAndRemove),
    CF(SchedulerUpdate),
    CF(SchedulerUpdateAndCustom),
    CF(SchedulerUpdateFromCustom),
    CF(RescheduleSelector),
    CF(SchedulerDelayAndRepeat),
    CF(SchedulerIssue2268)
Example #12
0
TESTLAYER_CREATE_FUNC(CommonLayerClip);
TESTLAYER_CREATE_FUNC(CommonLocale);
TESTLAYER_CREATE_FUNC(CommonLocalization);
TESTLAYER_CREATE_FUNC(CommonMenuItemColor);
TESTLAYER_CREATE_FUNC(CommonProgressHUD);
TESTLAYER_CREATE_FUNC(CommonRichLabel);
TESTLAYER_CREATE_FUNC(CommonRichLabel2);
TESTLAYER_CREATE_FUNC(CommonResourceLoader);
TESTLAYER_CREATE_FUNC(CommonRookieGuide);
TESTLAYER_CREATE_FUNC(CommonScreenshot);
TESTLAYER_CREATE_FUNC(CommonSlider);
TESTLAYER_CREATE_FUNC(CommonTiledSprite);
TESTLAYER_CREATE_FUNC(CommonToast);

static NEWTESTFUNC createFunctions[] = {
    CF(CommonCalendar),
    CF(CommonCallFuncT),
    CF(CommonCatmullRomSprite),
	CF(CommonGradientSprite),
	CF(CommonImagePicker),
	CF(CommonLaserSprite),
    CF(CommonLayerClip),
	CF(CommonLocale),
    CF(CommonLocalization),
    CF(CommonMenuItemColor),
    CF(CommonProgressHUD),
	CF(CommonRichLabel),
    CF(CommonRichLabel2),
	CF(CommonResourceLoader),
    CF(CommonRookieGuide),
	CF(CommonScreenshot),
Example #13
0
#include "CommonTest.h"
#include "../testResource.h"
#include "cocos2d.h"

TESTLAYER_CREATE_FUNC(CommonCalendar);
TESTLAYER_CREATE_FUNC(CommonGradientSprite);
TESTLAYER_CREATE_FUNC(CommonLocale);
TESTLAYER_CREATE_FUNC(CommonLocalization);
TESTLAYER_CREATE_FUNC(CommonMissile);
TESTLAYER_CREATE_FUNC(CommonRichLabel);
TESTLAYER_CREATE_FUNC(CommonShake);
TESTLAYER_CREATE_FUNC(CommonTiledSprite);
TESTLAYER_CREATE_FUNC(CommonTreeFadeInOut);

static NEWTESTFUNC createFunctions[] = {
    CF(CommonCalendar),
	CF(CommonGradientSprite),
	CF(CommonLocale),
    CF(CommonLocalization),
    CF(CommonMissile),
	CF(CommonRichLabel),
    CF(CommonShake),
    CF(CommonTiledSprite),
	CF(CommonTreeFadeInOut),
};

static int sceneIdx=-1;
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))

static CCLayer* nextAction()
{
Example #14
0
static VALUE FuncTable[10][10];

DEFCALLBACK(0)
DEFCALLBACK(1)
DEFCALLBACK(2)
DEFCALLBACK(3)
DEFCALLBACK(4)
DEFCALLBACK(5)
DEFCALLBACK(6)
DEFCALLBACK(7)
DEFCALLBACK(8)
DEFCALLBACK(9)

void *CallbackTable[10][10] = {
{CF(0,0),CF(0,1),CF(0,2),CF(0,3),CF(0,4),CF(0,5),CF(0,6),CF(0,7),CF(0,8),CF(0,9)},
{CF(1,0),CF(1,1),CF(1,2),CF(1,3),CF(1,4),CF(1,5),CF(1,6),CF(1,7),CF(1,8),CF(1,9)},
{CF(2,0),CF(2,1),CF(2,2),CF(2,3),CF(2,4),CF(2,5),CF(2,6),CF(2,7),CF(2,8),CF(2,9)},
{CF(3,0),CF(3,1),CF(3,2),CF(3,3),CF(3,4),CF(3,5),CF(3,6),CF(3,7),CF(3,8),CF(3,9)},
{CF(4,0),CF(4,1),CF(4,2),CF(4,3),CF(4,4),CF(4,5),CF(4,6),CF(4,7),CF(4,8),CF(4,9)},
{CF(5,0),CF(5,1),CF(5,2),CF(5,3),CF(5,4),CF(5,5),CF(5,6),CF(5,7),CF(5,8),CF(5,9)},
{CF(6,0),CF(6,1),CF(6,2),CF(6,3),CF(6,4),CF(6,5),CF(6,6),CF(6,7),CF(6,8),CF(6,9)},
{CF(7,0),CF(7,1),CF(7,2),CF(7,3),CF(7,4),CF(7,5),CF(7,6),CF(7,7),CF(7,8),CF(7,9)},
{CF(8,0),CF(8,1),CF(8,2),CF(8,3),CF(8,4),CF(8,5),CF(8,6),CF(8,7),CF(8,8),CF(8,9)},
{CF(9,0),CF(9,1),CF(9,2),CF(9,3),CF(9,4),CF(9,5),CF(9,6),CF(9,7),CF(9,8),CF(9,9)}};


void *find_callback(VALUE obj,int len)
{
   int i;
   for(i=0;i<10;i++)
char *
mnote_pentax_entry_get_value (MnotePentaxEntry *entry,
			      char *val, unsigned int maxlen)
{
	ExifLong vl;
	ExifShort vs, vs2;
	int i = 0, j = 0;

	if (!entry) return (NULL);

	memset (val, 0, maxlen);
	maxlen--;

	switch (entry->tag) {
	  case MNOTE_PENTAX_TAG_MODE:
	  case MNOTE_PENTAX_TAG_QUALITY:
	  case MNOTE_PENTAX_TAG_FOCUS:
	  case MNOTE_PENTAX_TAG_FLASH:
	  case MNOTE_PENTAX_TAG_WHITE_BALANCE:
	  case MNOTE_PENTAX_TAG_SHARPNESS:
	  case MNOTE_PENTAX_TAG_CONTRAST:
	  case MNOTE_PENTAX_TAG_SATURATION:
	  case MNOTE_PENTAX_TAG_ISO_SPEED:
	  case MNOTE_PENTAX_TAG_COLOR:
	  case MNOTE_PENTAX2_TAG_MODE:
	  case MNOTE_PENTAX2_TAG_QUALITY:
	  case MNOTE_PENTAX2_TAG_FLASH_MODE:
	  case MNOTE_PENTAX2_TAG_FOCUS_MODE:
	  case MNOTE_PENTAX2_TAG_AFPOINT_SELECTED:
	  case MNOTE_PENTAX2_TAG_AUTO_AFPOINT:
	  case MNOTE_PENTAX2_TAG_WHITE_BALANCE:
	  case MNOTE_PENTAX2_TAG_PICTURE_MODE:
	  case MNOTE_PENTAX2_TAG_IMAGE_SIZE:
	  case MNOTE_CASIO2_TAG_BESTSHOT_MODE:
		CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
		CC2 (entry->components, 1, 2, val, maxlen);
		if (entry->components == 1) {
			vs = exif_get_short (entry->data, entry->order);

			/* search the tag */
			for (i = 0; (items[i].tag && items[i].tag != entry->tag); i++);
			if (!items[i].tag) {
				snprintf (val, maxlen,
					  _("Internal error (unknown value %i)"), vs);
			  	break;
			}

			/* find the value */
			for (j = 0; items[i].elem[j].string &&
			    (items[i].elem[j].index < vs); j++);
			if (items[i].elem[j].index != vs) {
				snprintf (val, maxlen,
					  _("Internal error (unknown value %i)"), vs);
				break;
			}
			strncpy (val, _(items[i].elem[j].string), maxlen);
		} else {
			/* Two-component values */
			CF (entry->format, EXIF_FORMAT_SHORT, val, maxlen);
			CC2 (entry->components, 1, 2, val, maxlen);
			vs = exif_get_short (entry->data, entry->order);
			vs2 = exif_get_short (entry->data+2, entry->order) << 16;

			/* search the tag */
			for (i = 0; (items2[i].tag && items2[i].tag != entry->tag); i++);
			if (!items2[i].tag) {
				snprintf (val, maxlen,
					  _("Internal error (unknown value %i %i)"), vs, vs2);
			  	break;
			}

			/* find the value */
			for (j = 0; items2[i].elem[j].string && ((items2[i].elem[j].index2 < vs2)
				|| ((items2[i].elem[j].index2 == vs2) && (items2[i].elem[j].index1 < vs))); j++);
			if ((items2[i].elem[j].index1 != vs) || (items2[i].elem[j].index2 != vs2)) {
				snprintf (val, maxlen,
					  _("Internal error (unknown value %i %i)"), vs, vs2);
				break;
			}
			strncpy (val, _(items2[i].elem[j].string), maxlen);
		}
		break;

	case MNOTE_PENTAX_TAG_ZOOM:
		CF (entry->format, EXIF_FORMAT_LONG, val, maxlen);
		CC (entry->components, 1, val, maxlen);
		vl = exif_get_long (entry->data, entry->order);
		snprintf (val, maxlen, "%li", (long int) vl);
		break;
	case MNOTE_PENTAX_TAG_PRINTIM:
		CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
		CC (entry->components, 124, val, maxlen);
		snprintf (val, maxlen, _("%i bytes unknown data"),
			entry->size);
		break;
	case MNOTE_PENTAX_TAG_TZ_CITY:
	case MNOTE_PENTAX_TAG_TZ_DST:
		CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
		CC (entry->components, 4, val, maxlen);
		strncpy (val, (char*)entry->data, MIN(maxlen, entry->size));
		break;
	case MNOTE_PENTAX2_TAG_DATE:
		CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
		CC (entry->components, 4, val, maxlen);
		/* Note: format is UNDEFINED, not SHORT -> order is fixed: MOTOROLA */
		vs = exif_get_short (entry->data, EXIF_BYTE_ORDER_MOTOROLA);
		snprintf (val, maxlen, "%i:%02i:%02i", vs, entry->data[2], entry->data[3]);
		break;
	case MNOTE_PENTAX2_TAG_TIME:
		CF (entry->format, EXIF_FORMAT_UNDEFINED, val, maxlen);
		CC2 (entry->components, 3, 4, val, maxlen);
		snprintf (val, maxlen, "%02i:%02i:%02i", entry->data[0], entry->data[1], entry->data[2]);
		break;
	default:
		switch (entry->format) {
		case EXIF_FORMAT_ASCII:
		  strncpy (val, (char *)entry->data, MIN(maxlen, entry->size));
		  break;
		case EXIF_FORMAT_SHORT:
		  {
			const unsigned char *data = entry->data;
		  	size_t k, len = strlen(val);
		  	for(k=0; k<entry->components; k++) {
				vs = exif_get_short (data, entry->order);
				snprintf (val+len, maxlen-len, "%i ", vs);
				len = strlen(val);
				data += 2;
			}
		  }
		  break;
		case EXIF_FORMAT_LONG:
		  {
			const unsigned char *data = entry->data;
		  	size_t k, len = strlen(val);
		  	for(k=0; k<entry->components; k++) {
				vl = exif_get_long (data, entry->order);
				snprintf (val+len, maxlen-len, "%li", (long int) vl);
				len = strlen(val);
				data += 4;
			}
		  }
		  break;
		case EXIF_FORMAT_UNDEFINED:
		default:
		  snprintf (val, maxlen, _("%i bytes unknown data"),
			  entry->size);
		  break;
		}
		break;
	}

	return (val);
}
Example #16
0
TESTLAYER_CREATE_FUNC(HoleDemo);
TESTLAYER_CREATE_FUNC(ShapeTest);
TESTLAYER_CREATE_FUNC(ShapeInvertedTest);
TESTLAYER_CREATE_FUNC(SpriteTest);
TESTLAYER_CREATE_FUNC(SpriteNoAlphaTest);
TESTLAYER_CREATE_FUNC(SpriteInvertedTest);
TESTLAYER_CREATE_FUNC(NestedTest);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest2);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest3);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest4);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest5);
TESTLAYER_CREATE_FUNC(RawStencilBufferTest6);

static NEWTESTFUNC createFunctions[] = {
    CF(ScrollViewDemo),
    CF(HoleDemo),
    CF(ShapeTest),
    CF(ShapeInvertedTest),
    CF(SpriteTest),
    CF(SpriteNoAlphaTest),
    CF(SpriteInvertedTest),
    CF(NestedTest),
    CF(RawStencilBufferTest),
    CF(RawStencilBufferTest2),
    CF(RawStencilBufferTest3),
    CF(RawStencilBufferTest4),
    CF(RawStencilBufferTest5),
    CF(RawStencilBufferTest6)
};
Example #17
0
int GRID::Dry( double  dryLimit,
               int     countDown )
{
  // initialization: mark all dry nodes and elements -------------------------------------

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    if( isFS(nd->flag, NODE::kDry) )  nd->mark = true;
    else                              nd->mark = false;

    SF( nd->flag, NODE::kDry );
  }


  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if ( isFS(el->flag, ELEM::kDry) )  el->mark = true;
    else                               el->mark = false;

    CF( el->flag, ELEM::kDry );
  }


  // loop on all elements ----------------------------------------------------------------

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    int ncn = el->Getncn();

    for( int i=0; i<ncn; i++ )
    {
      // set element dry, if flow depth is less than dry limit ---------------------------
      // or the node was already dry

      double H = el->nd[i]->v.S - el->nd[i]->z;

      if( H < dryLimit  ||  el->nd[i]->mark )
      {
        SF( el->flag, ELEM::kDry );
      }
    }
  }


  // loop on all elements: all nodes at wet elements are wet -----------------------------

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( !isFS(el->flag, ELEM::kDry) )
    {
      int nnd = el->Getnnd();

      for( int i=0; i<nnd; i++ )  CF( el->nd[i]->flag, NODE::kDry );
    }
  }


  // report all nodes that have got newly dry --------------------------------------------

  REPORT::rpt.Output( "\n (dry)           the following nodes have got dry\n", 5 );

  int jdry = 0;

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    if( isFS(nd->flag, NODE::kDry) )
    {
      nd->v.U = 0.0;
      nd->v.V = 0.0;
      nd->v.S = nd->z;

      nd->v.K = 0.0;
      nd->v.D = 0.0;

      nd->v.dUdt = 0.0;
      nd->v.dVdt = 0.0;

      nd->v.dSdt = 0.0;

      if( !nd->mark )
      {
        nd->countDown = countDown;

        char text[20];
        sprintf( text, "  %5d", nd->Getname() );
        REPORT::rpt.Output( text, 2 );

        jdry++;
        if( !( jdry % 10) )  REPORT::rpt.Output( "\n", 5 );
      }
    }

    nd->mark = false;
  }

  if( jdry % 10 )  REPORT::rpt.Output( "\n", 5 );


  // report all elements that have got newly dry -------------------------------------------

  REPORT::rpt.Output( "\n (dry)           the following elements have got dry\n", 5 );

  int idry = 0;

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem( e );

    if( isFS(el->flag, ELEM::kDry) && !el->mark )
    {
      char text[20];
      sprintf( text, "  %5d", el->Getname() );
      REPORT::rpt.Output( text, 5 );

      idry++;
      if( !( idry % 10) )  REPORT::rpt.Output( "\n", 5 );
    }

    el->mark = false;
  }

  if( idry % 10 )  REPORT::rpt.Output( "\n", 5 );


  return idry + jdry;
}
Example #18
0
int GRID::Rewet( double   rewetLimit,
                 int      rewetPasses,
                 PROJECT* project )
{
  int i, j, k;
  int l, m, pass, ncn, nnd, rewetFlag;
  double wElev, K, D, cm, cd, vt;
  char text[80];

  cm = project->KD.cm;
  cd = project->KD.cd;


  // initialization: mark all dry elements -----------------------------------------------

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    el->mark = false;

    if( isFS(el->flag, ELEM::kDry) )
    {
      el->mark = true;
    }
  }


  REPORT::rpt.Output( "\n (rewet)         the following nodes have been rewetted\n", 5 );

  m = 0;

  for( pass=0; pass<rewetPasses; pass++ )
  {
    for( int n=0; n<Getnp(); n++ )
    {
      NODE* nd = Getnode(n);

      nd->mark = false;
    }

    sprintf( text, " pass %d ...\n", pass+1 );
    REPORT::rpt.Output( text, 5 );


    for( int e=0; e<Getne(); e++ )
    {
      ELEM * el = Getelem(e);

      if( isFS(el->flag, ELEM::kBound) )  continue;


      TYPE* type = TYPE::Getid( el->type );


      // look only for dry elements ------------------------------------------------------

      if( isFS(el->flag, ELEM::kDry) )
      {
        // loop on corner nodes: minimal water elevation ---------------------------------

        ncn = el->Getncn();        // number of corner nodes
        nnd = el->Getnnd();        // total number of nodes

        rewetFlag = false;

        wElev = 0.0;

        for( j=0, i=0; j<ncn; j++ )
        {
          if( !isFS(el->nd[j]->flag, NODE::kDry) )
          {
            // determine averaged water elevation at wet points --------------------------

            rewetFlag = true;

            wElev += el->nd[j]->v.S;
            i++;
          }
        }


        // loop on all nodes: check for rewetting ----------------------------------------

        if( i )
        {
          wElev /= i;

          for( j=0; j<nnd; j++ )
          {
            if( (wElev - el->nd[j]->z) < rewetLimit )  rewetFlag = false;
          }
        }


        // if all nodes have been rewetted, rewet whole element --------------------------

        if( rewetFlag )
        {
          for( j=0; j<ncn; j++ )
          {
            // re-initialize flow parameters ---------------------------------------------

            if( isFS(el->nd[j]->flag, NODE::kDry) )
            {
              el->nd[j]->mark = true;
              el->nd[j]->v.S = wElev;
            }
          }

          for( j=ncn; j<nnd; j++ )
          {
            if( isFS(el->nd[j]->flag, NODE::kDry) )
            {
              el->nd[j]->mark = true;

              // get left and right corner node to midside node j ------------------------
              el->GetLShape()->getCornerNodes( j, &i, &k );

              el->nd[j]->v.S = (el->nd[i]->v.S + el->nd[k]->v.S) / 2.0;
            }
          }

          for( j=0; j<nnd; j++ )
          {
            if( isFS(el->nd[j]->flag, NODE::kDry) )
            {
              el->nd[j]->v.U = 0.0;
              el->nd[j]->v.V = 0.0;

              el->nd[j]->v.dUdt = 0.0;
              el->nd[j]->v.dVdt = 0.0;

              el->nd[j]->v.dSdt = 0.0;


              K = el->nd[j]->v.K = dryRew.interpolate(el->nd[j], kVarK, 1);
              D = el->nd[j]->v.D = dryRew.interpolate(el->nd[j], kVarD, 1);

              if( isFS(project->actualTurb, BCONSET::kVtConstant) )
              {
                el->nd[j]->vt = type->vt;
              }
              else if( isFS(project->actualTurb, BCONSET::kVtPrandtlKol) )
              {
                if( fabs(D) > 0.0 )  vt = cm * cd * K * K / D;
                else                 vt = 0.0;

                el->nd[j]->vt = vt;
              }
            }
          }
        }
      }
    }


    // check count down for nodes to be rewetted and report ------------------------------

    l = 0;
    for( int n=0; n<Getnp(); n++ )
    {
      NODE* nd = Getnode(n);

      if( nd->mark )
      {
        nd->countDown--;

        if( nd->countDown <= 0 )
        {
          CF( nd->flag, NODE::kDry );


          // look for boundary conditions ------------------------------------------------

          BCON *bc = &nd->bc;


          // ... outflow boundary or fixed flow depth h --------------------------------

          if( isFS(bc->kind, BCON::kOutlet)  ||  isFS(bc->kind, BCON::kSetS) )
          {
            nd->v.S = bc->val->S;
          }


          // ... inflow boundary or fixed velocities U,V -------------------------------

          if( isFS(bc->kind, BCON::kInlet) )
          {
            nd->v.U = bc->val->U * bc->niox / (nd->v.S - nd->z);
            nd->v.V = bc->val->U * bc->nioy / (nd->v.S - nd->z);
          }

          else if( !isFS(bc->kind, BCON::kAutoSlip) )
          {
            if ( isFS(bc->kind, BCON::kFixU) )  nd->v.U = bc->val->U;
            if ( isFS(bc->kind, BCON::kFixV) )  nd->v.V = bc->val->V;
          }

#         ifdef kDebug
          sprintf( text,
                   "  %5d (UVhKDvt): %9.2le %9.2le %9.2le %9.2le %9.2le %9.2le\n",
                                  nd->Getname(),
                                  nd->v.U,
                                  nd->v.V,
                                  nd->v.S - nd->z,
                                  nd->v.K,
                                  nd->v.D,
                                  nd->vt );
          REPORT::rpt.Output( text, 5 );

#         else

          sprintf( text, "  %5d", nd->Getname() );
          REPORT::rpt.Output( text, 5 );

          l++;
          if( !( l % 10) )  REPORT::rpt.Output( "\n", 5 );
#         endif

          m++;
        }

        else
        {
          nd->v.U = 0.0;
          nd->v.V = 0.0;
          nd->v.K = 0.0;
          nd->v.D = 0.0;
          nd->v.S = nd->z;
        }
      }

      nd->mark = false;
    }

#   ifndef kDebug
    if( l % 10 )
      REPORT::rpt.Output( "\n", 5 );
#   endif


    // rewet all dry elements without dry nodes ------------------------------------------

    for( int e=0; e<Getne(); e++ )
    {
      ELEM* el = Getelem(e);

      if( isFS(el->flag, ELEM::kDry) )
      {
        nnd = el->Getnnd();

        rewetFlag = true;

        for( j=0; j<nnd; j++ )
        {
          if( isFS(el->nd[j]->flag, NODE::kDry) )
          {
            rewetFlag = false;
            break;
          }
        }

        if( rewetFlag )
        {
          CF( el->flag, ELEM::kDry );
        }
      }
    }
  }


  // loop on all elements: all nodes at wet elements are wet -----------------------------

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    SF( nd->flag, NODE::kDry );

    nd->mark = false;
  }


  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( !isFS(el->flag, ELEM::kDry) )
    {
      nnd = el->Getnnd();

      for( j=0; j<nnd; j++ )  CF( el->nd[j]->flag, NODE::kDry );
    }
  }


  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    if( isFS(nd->flag, NODE::kDry) )
    {
      nd->v.U = 0.0;
      nd->v.V = 0.0;
      nd->v.K = 0.0;
      nd->v.D = 0.0;
      nd->v.S = nd->z;
    }
  }



  // report elements which have been rewetted --------------------------------------------

  REPORT::rpt.Output( "\n (rewet)         the following elements have been rewetted\n", 5 );

  l  = 0;
  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    nnd = el->Getnnd();

    if( el->mark  &&  !isFS(el->flag, ELEM::kDry) )
    {
      for( j=0; j<nnd; j++ )
      {
        if( isFS(el->nd[j]->flag, NODE::kDry) )
          REPORT::rpt.Error ("unexpected error - rewet (1)");
      }

      sprintf( text, "  %5d", el->Getname() );
      REPORT::rpt.Output( text, 5 );

      l++;
      if( !( l % 10) )  REPORT::rpt.Output( "\n", 5 );
    }

    el->mark = false;
  }

  if( l % 10 )  REPORT::rpt.Output( "\n", 5 );


# ifndef kDebug
  if( l % 10 )  REPORT::rpt.Output( "\n", 5 );
# endif


  return l;
}
Example #19
0
#include "ConfigurationTest.h"
#include "../testResource.h"
#include "cocos2d.h"

TESTLAYER_CREATE_FUNC(ConfigurationLoadConfig);
TESTLAYER_CREATE_FUNC(ConfigurationQuery);
TESTLAYER_CREATE_FUNC(ConfigurationInvalid);
TESTLAYER_CREATE_FUNC(ConfigurationDefault);
TESTLAYER_CREATE_FUNC(ConfigurationSet);

static NEWTESTFUNC createFunctions[] = {
    CF(ConfigurationLoadConfig),
	CF(ConfigurationQuery),
	CF(ConfigurationInvalid),
	CF(ConfigurationDefault),
	CF(ConfigurationSet)
};

static int sceneIdx=-1;
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))

static Layer* nextAction()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;
    
    auto layer = (createFunctions[sceneIdx])();
    layer->init();
    layer->autorelease();
    
Example #20
0
			&this->architectures_from,
			&this->architectures_into);
	if (r == RET_NOTHING) {
		fprintf(stderr,
"Warning parsing %s, line %u: an empty Architectures field\n"
"causes the whole rule to do nothing.\n",
				config_filename(iter),
				config_markerline(iter));
	}
	return r;
}

static const struct configfield pullconfigfields[] = {
	CFr("Name", pull_rule, name),
	CFr("From", pull_rule, from),
	CF("Architectures", pull_rule, architectures),
	CF("Components", pull_rule, components),
	CF("UDebComponents", pull_rule, udebcomponents),
	CF("FilterFormula", pull_rule, includecondition),
	CF("FilterSrcList", pull_rule, filtersrclist),
	CF("FilterList", pull_rule, filterlist)
};

retvalue pull_getrules(struct pull_rule **rules) {
	struct pull_rule *pull = NULL;
	retvalue r;

	r = configfile_parse("pulls", IGNORABLE(unknownfield),
			configparser_pull_rule_init, linkedlistfinish,
			"pull rule",
			pullconfigfields, ARRAYCOUNT(pullconfigfields), &pull);
Example #21
0
main(int argc, char* argv[]){
  time_t time1 = time(0), time2;

  //-------MPI initialzation-------------

  int numprocs, myid, namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);

  MPI_Get_processor_name(processor_name, &namelen);
  fprintf(stderr, "Process %d running on %s\n", myid, processor_name);

  string numbers = "0123456789";  // !!!!! np <= 10
  string myid_str(numbers, myid, 1);

  MPI_Status status;

  // define a new MPI data type for particles
  MPI_Datatype particletype;
  MPI_Type_contiguous(18, MPI_DOUBLE, &particletype);  // !!! 14->18 changed
  MPI_Type_commit(&particletype);

  //-------- end MPI init----------------

  // wait for gdb
  waitforgdb(myid);

  // read input file (e.g. patric.cfg):

  if(argv[1] == 0){
    printf("No input file name !\n");
    MPI_Abort(MPI_COMM_WORLD, 0);
  }
  input_from_file(argv[1], myid);
  double eps_x = rms_emittance_x0;  // handy abbreviation
  double eps_y = rms_emittance_y0;  // same

  // Synchronous particle:

  SynParticle SP;
  SP.Z = Z;
  SP.A = A;
  SP.gamma0 = 1.0 + (e_kin*1e6*qe)/(mp*clight*clight) ;
  SP.beta0 = sqrt((SP.gamma0*SP.gamma0-1.0)/(SP.gamma0*SP.gamma0)) ;
  SP.eta0 = 1.0/pow(gamma_t, 2)-1.0/pow(SP.gamma0, 2);

  //-------Init Lattice-------

  BeamLine lattice;
  double tunex, tuney; 
  SectorMap CF(CF_advance_h/NCF, CF_advance_v/NCF, CF_R, CF_length/NCF, SP.gamma0);
  BeamLine CF_cell;
  if(madx_input_file == 1){
    // read madx sectormap and twiss files 
	cout << "madx sectormap" << endl;
    string data_dir_in = input;
    lattice.init(data_dir_in+"/mad/", circum, tunex, tuney); 
  }
  else{
    // init constant focusing (CF) sectormap and cell:
	cout << "constsnt focusing" << endl;
    for(int j=0; j<NCF; j++)
      CF_cell.add_map(CF);
    lattice.init(CF_cell);
  }

  // Other variables:
  double dx = 2.0*piperadius/(NX-1.0);  // needed for Poisson solver and grids
  double dy = 2.0*piperadius/(NY-1.0);  // needed for Poisson solver and grids
  double dz = circum/NZ;
  double ds = 0.4;  // value needed here only for setting dxs, dys.
  double dxs = 4.0*(dx/ds)/(NX-1.0);  // only for plotting xs, not for tracking
  double dys = 4.0*(dx/ds)/(NX-1.0);  // only for plotting ys, not for tracking
  double charge = current*circum/(NPIC*SP.beta0*clight*qe);  // macro-particle charge Q/e
  double zm = 0.5*circum*bunchfactor;  // (initial) bunch length
  if(init_pic_z == 1 || init_pic_z == 3 || init_pic_z == 4 || init_pic_z == 6)
    zm = 1.5*0.5*circum*bunchfactor;  // for parabolic bunch
  double zm1 = -zm*1.0;  // left bunch boundary
  double zm2 = zm*1.0;  // right bunch boundary
  if(init_pic_z==7)
	zm=0.25;
  double rmsToFull;  // ratio of rms to full emittance for Bump; SP

  // open output file patric.dat:

  string data_dir = ausgabe;
  data_dir = data_dir + "/";
  string outfile = data_dir + "patric.dat";
  FILE *out = fopen(outfile.c_str(), "w"); 

  // init random number generator:
  long d = -11*(myid+1);  // was -1021  transverse distribution: each slice needs a different initialization !
  long dl = -103;  // was -103   longitudinal plane: same random set needed
  long dran = -101;  // for BTF noise excitation: same random sets needed


  // set some global lattice parameters

  double cell_length = lattice.get_L();
  int Nelements = lattice.get_size();
  if(myid == 0){
    cout << "Nelements:" << Nelements << endl;
    cout << "Cell length:" << cell_length << endl;
  }

  // define pointers to first/last element in beam line:

  const list<SectorMap>::iterator first_elem = lattice.get_first_element();
  const list<SectorMap>::iterator last_elem = --lattice.get_end_element();

  TwissP twiss0, twiss_TK;
  lattice.first_element();
  twiss0 = last_elem->get_twiss();
  twiss_TK = first_elem->get_twiss();
  double Ds0 = 0.0;  // Dispersion derivative

  if(madx_input_file == 0){
    // machine tunes from lattice
    lattice.phase_advance(tunex, tuney);
    tunex = circum/cell_length*tunex/(2.0*PI);
    tuney = circum/cell_length*tuney/(2.0*PI);
	bumpI=0;
    if(myid == 0){
      cout << "advancex: " << tunex*180.0/PI << endl;
      cout << "tunex0: " << tunex << endl;
      cout << "tuney0: " << tuney << endl;
    }
  }

  // Chromatic correction kick:
  Chrom Chrom0;


  // Octupole:
  Octupole Oct0(koct);

  // Amplitude detuning; works only for constant focusing; SA
  //if(madx_input_file == 0)
    //AmplitudeDetuning Amp0(tunex, tuney, dqx_detune/(1.0e-6*eps_x), dqy_detune/(1.0e-6*eps_y), circum/(2.0*PI), CF);

  //--------end lattice----------

  // set matched RF voltage:

  int linrf = 0;
  if (cavity == 3) linrf = 1;
  double Ym = circum/(2.0*PI)*(1.0-cos(2.0*PI*zm/circum));
  if (linrf == 1) Ym = circum/(2.0*PI)*0.5*pow(2.0*PI*zm/circum, 2);
  double velm = abs(SP.eta0)*SP.beta0*clight*sqrt(5.0)*momentum_spread*2.0*PI/(circum);
  double fsyn = 1.0/(2.0*PI)*velm*sqrt(circum/(2.0*PI))/sqrt(2.0*Ym);
  double V0rf = pow(2.0*PI*fsyn, 2)*pow(circum, 2)/(2.0*PI)*mp*SP.A*SP.gamma0/(qe*SP.Z*abs(SP.eta0));

  // Init particle distribution:

  Pic Pics(&SP, charge, NPIC/numprocs, data_dir + "pics_" + myid_str + ".dat");
  Pics.z1 = zm1+myid*(zm2-zm1)/numprocs;  // left boundary in z for this slice
  Pics.z2 = Pics.z1+(zm2-zm1)/numprocs;  // right boundary
  double slice_length = Pics.z2-Pics.z1;  // slice length

  Pic NewPics(&SP, charge, NPIC/numprocs);
  NewPics.z1 = Pics.z1;
  NewPics.z2 = Pics.z2;

  // Init 1D longitudinal grids

  Grid1D rho_z_tmp(NZ, dz, -0.5*circum);
  Grid1D rho_z(NZ, dz, -0.5*circum, data_dir + "rho_z.dat");
  Grid1D dipole_current_x_tmp(NZ, dz, -0.5*circum);
  Grid1D dipole_current_x(NZ, dz, -0.5*circum, data_dir + "dipole_x.dat");
  Grid1D dipole_current_xs_tmp(NZ, dz, -0.5*circum);
  Grid1D dipole_current_xs(NZ, dz, -0.5*circum);
  Grid1D dipole_kick_x(NZ, dz, -0.5*circum, data_dir + "dipole_kick_x.dat");
  Grid1D dipole_current_y_tmp(NZ, dz, -0.5*circum);
  Grid1D dipole_current_y(NZ, dz, -0.5*circum, data_dir + "dipole_y.dat");

  // Init 2D transverse grids:

  Grid2D rho_xy(NX, NY, dx, dy, data_dir + "rho_xy.dat");
  Grid2D rho_xy_tmp(NX, NY, dx, dy);
  Grid2D xxs(NX, NX, dx, dxs, data_dir + "xxs.dat");
  Grid2D xxs_tmp(NX, NX, dx, dxs);
  Grid2D yys(NY, NY, dy, dys, data_dir + "yys.dat");
  Grid2D yys_tmp(NY, NY, dy, dys);
  Grid2D xsys(NX, NY, dxs, dys, data_dir + "xsys.dat");
  Grid2D xsys_tmp(NX, NY, dxs, dys);
  Grid2D zx(NZ, NX, dz, dx, data_dir + "zx.dat");
  Grid2D zx_tmp(NZ, NX, dz, dx);

  Grid2D Ex(NX, NY, dx, dy, data_dir + "Ex.dat");
  Grid2D Ey(NX, NY, dx, dy, data_dir + "Ey.dat");

  // Init 3D sliced grids (for 3D space charge calculation)

  if( fmod((float)NZ_bunch, (float)numprocs) != 0.0 ){
    cout << "NZ_bunch kein Vielfaches von numprocs" << endl;
    MPI_Abort(MPI_COMM_WORLD, 0);
  }
  Grid3D rho_xyz(NZ_bunch/numprocs, Pics.z1, Pics.z2, rho_xy);
  Grid3D Ey3(NZ_bunch/numprocs, Pics.z1, Pics.z2, rho_xy);
  Grid3D Ex3(NZ_bunch/numprocs, Pics.z1, Pics.z2, rho_xy);

  // Init 2D Greens function for poisson solver

  Greenfb gf1(rho_xy, image_x, image_y);  // open boundary condition

  // for the beam radius cacluation;  factor for rms equivalent 
  switch(init_pic_xy){
  case 0:  // Waterbag
	rmsToFull = 6;
    break;
  case 1:  // KV
	rmsToFull = 4;
    break;
  case 2:  // Semi-Gauss
    rmsToFull = 4;  // approximate
    break;
  case 3:  // Gauss
  	rmsToFull = 4;  // approximate
    break;
  default:
    printf("Invalid option for transverse particle distribution. Aborting.\n");
    MPI_Abort(MPI_COMM_WORLD, 0);
  }

  // injection bump initialize 
  Bump lob(tunex);     
  double a; // beam radius horizontal
 
  switch(bumpI){
	case 0:
	  cout << "no mti"  << endl;
	  max_inj = 1;
	  amp0=0;
	  break;
	case 1:
	  // The bump height is defined by user given offcenter parameter. The injection angle is equal to the septum tilt angle (as done in SIS18). 
	  cout << "mti version SP" << endl; 
	  a = sqrt(twiss_TK.betx*eps_x*rmsToFull)*0.001+twiss_TK.Dx*momentum_spread;  // half width of injected beam [m] with WB distribution, change to Main, SA 
	  offcenter_x=x_septum + d_septum + a; 
	  amp0=offcenter_x;
	  amp=amp0;
	  ampp0=inj_angle;
	  delAmp=(amp0-2*a)/double(max_inj);   //0.0041*3;//    
	  lob.BumpSp(&lattice,max_inj, myid, amp0, ampp0, delAmp); // local orbit bump for beam injection; SP
	  break;
	case 2:
	  amp=amp0;
	  cout << "mti flexibility version" << endl; 
	  lob.BumpModi(&lattice,amp);
	  break;
	case 3:
	  amp=amp0;
	  cout << "mti flexibility version exponential decrease" << "tau" << tau << endl; 
	  lob.BumpModi(&lattice,amp);
	  break;
	case 4:
	  amp=amp0;
	  cout << "mti flexibility version sin decrease" << "tau" << tau << endl; 
	  lob.BumpModi(&lattice,amp);
	  break;
	default:
	   printf("Invalid option for bump injection. Aborting.\n");
	   MPI_Abort(MPI_COMM_WORLD, 0);
  }
	 
  //if(myid == 0)
    //cout << "Expected single beamlett tune shifts: dQ_x="
	 //<< rp*SP.Z*current*circum / (rmsToFull*PI*clight*qe*SP.A*pow(SP.beta0*SP.gamma0, 3)*(eps_x+sqrt(eps_x*eps_y*tunex/tuney)))*1e6
	 //<< ", dQ_y="
	 //<< rp*SP.Z*current*circum / (rmsToFull*PI*clight*qe*SP.A*pow(SP.beta0*SP.gamma0, 3)*(eps_y+sqrt(eps_x*eps_y*tuney/tunex)))*1e6
	 //<< endl;            
		

  // print IDL parameter file idl.dat:       
  if(myid == 0){
    //cout << "Vrf [kV]: " << V0rf*1.0e-3 << "  fsyn [kHz]: " << fsyn*1.0e-3 << endl; 
    print_IDL(data_dir, numprocs, cell_length, Nelements, tunex, tuney, lattice, cells, max_inj); 
  }


  //----------------counters and other variables--------------------------

  int Nexchange = 1;  // exchange of particles between slices after every sector map.
  int Nprint = print_cell*Nelements;  // output of particles every cell*print_cell
  //int Nibs = 1;  // correct for IBS every Nibs steps
  double Ntot;  // total number of particles: for screen output
  int counter = 0;  // counts sector maps
  double s = 0.0;  // path length
  double Nslice;  // total number of slices
  double emitx;  // emittance: for screen output
  double dtheta = 0.0;  // btf dipole kick
  double pickup_h, pickup_v;  // horizontal/vertical pickup signals
  double rms_advancex = 0.0, rms_advancey = 0.0;  // rms phase advance: for output
  int inj_counter = 0;  // number of injected beamletts; SP
  long N_inj = 0;  // number of injected particles

  //---------parameters for exchange of particles between slices-------

  int destl;  //!< ID of left neighbour slice (-1: no neighbour).
  int destr;  //!< ID of right neighbour



  //---finite bunch: no exchange between ends---
  if(bc_end == 0){
    if(myid == 0){
      destl =-1;
      destr = myid+1;
    }else
      if(myid == numprocs-1){
	destl = myid-1;
	destr =-1;
      }else{
	destl = myid-1;
	destr = myid+1;
      }
  }
  //---periodic (in z) boundary condition---
  if(bc_end == 1){
    if(myid == 0){
      destl = numprocs-1;
      destr = myid+1;
    }else
      if(myid == numprocs-1){
	destl = myid-1;
	destr = 0;
      }
      else{
	destl = myid-1;
	destr = myid+1;
      }
  }



  //--------------------- end-parameters for particle exchange ---------------

  long *septLoss = new long;
  long *sl_slice = new long;
  double *momenta = new double[19];
  double *momenta_tot = new double[19];       
  double tmp=0;
  long size_old;	
  offcenter_y=0.0;  
  inj_phase_y=0.0e-3;
  
  //--------------------------------------------------------------------------
  //----------------------- start loop (do...while) --------------------------
  //--------------------------------------------------------------------------
   double z0;
   do{  // injection; SP
    if(!(counter%Nelements))
	{  // at beginning each turn...
	  	
	if(inj_counter < max_inj)
	{
 	  size_old=Pics.get_size();
	  // set longitudinal distribution:
	  switch(init_pic_z){
	  case 0:  //  coasting + Elliptic
	    Pics.parabolic_dc(bunchfactor, circum, momentum_spread, NPIC, &dl);
	    break;
	  case 1:  //  bunch + Elliptic  (1.5 correction factor for bunching)
	    Pics.parabolic(zm, 0, momentum_spread, NPIC, &dl);
	    break;
	  case 2:  //  coasting + Gauss
	    Pics.coast_gauss(bunchfactor, circum, momentum_spread, NPIC, &dl); 
	    break;
	  case 3:  //  bunch + Gauss
	    Pics.bunch_gauss(zm, circum, momentum_spread, NPIC, &dl);
	    break;
	  case 4:  //  const. bunch dist.		
	    Pics.bunch_const(zm, circum, momentum_spread, NPIC, &dl,linrf);
	    break;
	  case 5:  //  air bag dist.
	    Pics.barrier_air_bag(zm, momentum_spread, NPIC, &dl);
	    break;
	  case 6:  //  bunch air bag dist.
	    Pics.bunch_air_bag(zm, circum, momentum_spread, NPIC, &dl);
	    break;
	  case 7:  //  168 mirco bunches, injection
		z0=-circum/2.;
		int l;
		for (l=0; l<168; l++){
	    	Pics.parabolic(zm, z0, momentum_spread, NPIC/168, &dl);
			z0+=1.286;
		}
	    break;
	  default:
	    printf("Invalid option for longitudinal particle distribution. Aborting.\n");
	    MPI_Abort(MPI_COMM_WORLD, 0);
	  }
		
	  // set transverse distribution:
	  switch(init_pic_xy){
	  case 0:  // Waterbag
		rmsToFull = 6;
	    Pics.waterbag_xy(1.e-6*eps_x, 1.0e-6*eps_y, twiss_TK.alpx, twiss_TK.alpy, pow(mismatch_x, 2)*twiss_TK.betx, pow(mismatch_y, 2)*twiss_TK.bety, 
				        twiss_TK.Dx, Ds0, offcenter_x, inj_angle, offcenter_y, inj_phase_y, size_old, &d);
	    break;
	  case 1:  // KV
		rmsToFull = 4;
	    Pics.KV_xy(1.e-6*eps_x, 1.0e-6*eps_y, twiss_TK.alpx, twiss_TK.alpy, pow(mismatch_x, 2)*twiss_TK.betx, pow(mismatch_y, 2)*twiss_TK.bety, 
				   twiss_TK.Dx, Ds0, offcenter_x, inj_angle, offcenter_y, inj_phase_y, size_old, &d);
	    break;
	  case 2:  // Semi-Gauss
	    rmsToFull = 4;  // approximate
		Pics.SG(1.e-6*eps_x, 1.0e-6*eps_y, twiss_TK.alpx, twiss_TK.alpy, pow(mismatch_x, 2)*twiss_TK.betx, pow(mismatch_y, 2)*twiss_TK.bety, 
				twiss_TK.Dx, Ds0, offcenter_x, inj_angle, offcenter_y, inj_phase_y, size_old, &d);
	    break;
	  case 3:  // Gauss
	  	rmsToFull = 4;  // approximate
	    Pics.Gauss_xy(1.e-6*eps_x, 1.0e-6*eps_y, twiss_TK.alpx, twiss_TK.alpy, pow(mismatch_x, 2)*twiss_TK.betx, pow(mismatch_y, 2)*twiss_TK.bety, 
					  twiss_TK.Dx, Ds0, offcenter_x, inj_angle, offcenter_y, inj_phase_y, size_old, &d);
	    break;
	  default:
	    printf("Invalid option for transverse particle distribution. Aborting.\n");
	    MPI_Abort(MPI_COMM_WORLD, 0);
	  }
	  
	  if (bumpI!=0)
	  {
	  	*sl_slice = NewPics.localLoss_x(x_septum, 100.);  // loss on septum  
      	loss+=*sl_slice; 
      	MPI_Reduce(sl_slice, septLoss, 1, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
	  	if(myid == 0)
     		cout<<"The incoming beamlett number "<<inj_counter+1<< " lost "<<loss<< " macro particles on the septum.\n";
      }
	  N_inj += NPIC; 
	  inj_counter +=1;
	}
	

	// bump reduction
    if (amp > 0.001 )
	{    
	   if(bumpI==1)
	   {   
		amp-=delAmp;                                 
	   	ampp0-=delAmp*ampp0/amp0;     
	   	lob.decrement();     
	   }
	   if (bumpI==2)
		{
		 amp-=delAmp;                                 
		 lob.decrementModi(amp);
		}
	   if (bumpI==3)
	    {
		 amp=amp0*exp(-tau*counter/Nelements);
		 lob.decrementModi(amp);
		}
	   if (bumpI==4)
	    {
		 amp=amp0*(1+sin(-tau*counter/Nelements));
		 lob.decrementModi(amp);
		}
	}	
   }
	
	
    //------------ Start Output----------------------------------------
    // store rms momenta every time step in patric.dat:
    
    if(counter%1 == 0){
      Nslice = Pics.get_size();  // number of particles in this slice
      momenta[0] = Nslice*Pics.rms_emittance_x();
      momenta[1] = Nslice*Pics.rms_emittance_y();
      momenta[2] = Nslice*Pics.x_max();
      momenta[3] = Nslice*Pics.y_max();
      momenta[4] = Nslice*Pics.x_rms();
      momenta[5] = Nslice*Pics.y_rms();
      momenta[6] = Nslice*Pics.rms_momentum_spread();
      momenta[7] = Nslice*Pics.xzn(2.0, zm);
      momenta[8] = Nslice*Pics.xzn(1.0, zm);
      momenta[9] = Nslice;
      momenta[10] = Nslice*rms_advancex;  // rms phase advance in x
      momenta[11] = Nslice*rms_advancey;
      momenta[12] = Nslice*Pics.offset_x();
      momenta[13] = Nslice*Pics.offset_y();
      momenta[14] = Nslice*dtheta;  // btf noise signal
      momenta[15] = Nslice*pickup_h;
      momenta[16] = Nslice*pickup_v; 
	  momenta[17] = Nslice*loss;   
	  momenta[18] = Nslice*N_inj;  
      // mpi_reduce for summation of all 17 moments over all slices
      MPI_Reduce(momenta, momenta_tot, 19, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
	 		
      Ntot = momenta_tot[9];  // total number of particles over all slices
      emitx = momenta_tot[0]/Ntot;  // total rms emittance    

 
      // stop when loss tolerance level is exceeded                            (1-Ntot/(max_inj*NPIC))*100.
	  
      if(myid == 0 && Ntot/N_inj <= lossTol){  // test on numer of injected particles; SP
		cout<<"Loss tolerance exceeded within "<<counter/Nelements+1<<" turns ("<<
	    Ntot<<" of "<<N_inj<<" macro particles left). Exiting.\n";
	    cout.flush();
	MPI_Abort(MPI_COMM_WORLD, 0);
      }  
      //      cout<<counter<<' '<<lattice.get_element()->get_name()<<' '<<lattice.get_element()->get_K(1)<<endl;  //tmp
      // write momenta
      if(myid == 0){
	fprintf(out, "%g", s);
	for(int i=0; i<19; i++)
	  if(i != 9){
	    fprintf(out, "%15g", momenta_tot[i]/Ntot);}
	  else{
	    fprintf(out, "%15g", momenta_tot[i]);}
	fprintf(out, "\n");
	fflush(out);
      }
}


    //------output every Nprint*sectormap---------

    if(counter%Nprint == 0){
      if(myid == 0){
	// to screen
	//printf("saving at s=%g (m) eps_t=%g dp/p=%g zm2=%g Ntotal=%g\n", s, 1.0e6*emitx, Pics.rms_momentum_spread(), zm2, Ntot);
	cout.flush();
	
	// electric fields
	Ex.print();
	Ey.print();
      }
	
      // paricle coordinates to pic.dat:
      Pics.print(pic_subset);
   	
      // collect densities for output only:

      Pics.gatherZ(charge*qe/dz, rho_z_tmp);
      Pics.gatherX(SP.beta0*clight*charge*qe/dz, dipole_current_x_tmp);
      Pics.gatherY(SP.beta0*clight*charge*qe/dz, dipole_current_y_tmp);
      Pics.gatherXY(charge*qe/circum, rho_xy_tmp);
      Pics.gatherXXs(charge*qe/circum, xxs_tmp);
      Pics.gatherYYs(charge*qe/circum, yys_tmp);
      Pics.gatherXsYs(charge*qe/circum, xsys_tmp);
      Pics.gatherZX(charge*qe/circum, zx_tmp);

      // summation over all slices:

      MPI_Allreduce(rho_z_tmp.get_grid(), rho_z.get_grid(),
		    NZ, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(dipole_current_x_tmp.get_grid(), dipole_current_x.get_grid(),
		    NZ, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(dipole_current_y_tmp.get_grid(), dipole_current_y.get_grid(),
		    NZ, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(rho_xy_tmp.get_grid(), rho_xy.get_grid(),
		    NX*NY, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(xxs_tmp.get_grid(), xxs.get_grid(),
		    NX*NX, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(yys_tmp.get_grid(), yys.get_grid(),
		    NY*NY, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(xsys_tmp.get_grid(), xsys.get_grid(),
		    NX*NY, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
      MPI_Allreduce(zx_tmp.get_grid(), zx.get_grid(),
		    NZ*NX, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
		  
		
      // output to density files:

      if(myid == 0){
	dipole_current_x.print();
	dipole_kick_x.print();
	dipole_current_y.print();
	rho_z.print();
	rho_xy.print();
	xxs.print();
	yys.print();
	xsys.print();
	zx.print();
      }
    } 
    //-----------------end output--------------------------------------------		
	
    // at beginning of a cell: calculate advance per (last) cell,
    // store old coordinates 
    if(lattice.get_element() == first_elem){
      rms_advancex = Pics.rms_phaseadvance_h();  // Pics.rms_wavelength_h();
      rms_advancey = Pics.rms_phaseadvance_v();  // Pics.rms_wavelength_v();
      if(footprint == 0)
	Pics.store_old_coordinates();
    }

	
    if(lattice.get_element()->get_name() == "\"SEPTUM\""){  // losses at septum; SP
      loss += Pics.localLoss_x(-piperadius, coll_halfgap);	  
	}  
  

   if(lattice.get_element()->get_name() == "\"ACCEPTANCE\""){  // losses at limiting acceptance; SA
	  double tmp = lattice.get_element()->get_betx();
      Pics.localLoss_x(-sqrt(180e-6*tmp), sqrt(180e-6*tmp));      
	}

	// Transport particles through sectormap, update slice position s: 
    ds = lattice.get_element()->get_L();

    s += ds;
    Pics.transport(lattice.get_element()->get_map(), piperadius);



    //-----exchange particles between slices------------------------

    if(counter != 0 && counter%Nexchange == 0 && numprocs > 1){
      int Npl;  //!< Number of particles to be exchanged with left neighbour
      int Npr;  //!< particles exchanged with right neighbour

      //! vector of particles to be exchanged
      vector<Particle> pl, pr;

      // send particle to neighbor slices:
	
      if(destl >= 0){
	pl = Pics.get_particles_left(circum);
	Npl = pl.size();
	MPI_Send(&Npl, 1, MPI_INT, destl, 1, MPI_COMM_WORLD);
	MPI_Send(&pl[0], Npl, particletype, destl, 1, MPI_COMM_WORLD);
      }
      if(destr >= 0){
	pr = Pics.get_particles_right(circum);
	Npr = pr.size();
	MPI_Send(&Npr, 1, MPI_INT, destr, 0, MPI_COMM_WORLD);
	MPI_Send(&pr[0], Npr, particletype, destr, 0, MPI_COMM_WORLD);
      }

      // receive from neighbour slices:
	
      Npl = 0; Npr = 0;
      vector<Particle> pl_in, pr_in;
      if( destl >= 0 ){
	MPI_Recv(&Npl, 1, MPI_INT, destl, 0, MPI_COMM_WORLD, &status);
	pl_in = vector<Particle>(Npl);
	MPI_Recv(&pl_in[0], Npl, particletype, destl, 0, MPI_COMM_WORLD, &status);
      }
      if(destr >= 0){
	MPI_Recv(&Npr, 1, MPI_INT, destr, 1, MPI_COMM_WORLD, &status);
	pr_in = vector<Particle>(Npr);
	MPI_Recv(&pr_in[0], Npr, particletype, destr, 1, MPI_COMM_WORLD, &status);
      }
      Pics.add_particles(pl_in);
      Pics.add_particles(pr_in);
    }

    //-----end exchange of particles-------------



    // periodic bc without exchange
    if(numprocs == 1)
      Pics.periodic_bc(circum);	

    // update wave lengths

    //if( footprint == 1){
    //Pics.update_wavelength_h(ds, 0.0);
    //Pics.update_wavelength_v(ds);}

    // nonlinear thin lens kick:
    if(octupole_kick == 1)
      Pics.kick(Oct0, lattice.get_element()->get_twiss(), ds);

    //if(ampdetun_kick == 1)  // works only for constant focusing
    //Pics.kick(Amp0, lattice.get_element()->get_twiss()ds);

    // correct for chromaticity
     if(chroma == 1)  
		Pics.kick(Chrom0,lattice.get_element()->get_twiss(), ds);
			
    // cavity kick every cell:

    if(cavity == 1 && counter%Nelements == 0.0)
      Pics.cavity_kick(V0rf*cell_length/circum, 1, circum/(2.0*PI));
    if(cavity == 2 && counter%Nelements == 0.0)
      Pics.barrier_kick(zm1, zm2);
    if(cavity == 3 && counter%Nelements == 0.0)
      Pics.cavity_kick_linear(V0rf*cell_length/circum, 1, circum/(2.0*PI));

    // Pickup signals

    Pics.gatherX(SP.beta0*clight*charge*qe/dz, dipole_current_x_tmp);
    Pics.gatherY(SP.beta0*clight*charge*qe/dz, dipole_current_y_tmp);
    MPI_Allreduce(dipole_current_x_tmp.get_grid(), dipole_current_x.get_grid(), NZ,
		  MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);	
    MPI_Allreduce(dipole_current_y_tmp.get_grid(), dipole_current_y.get_grid(), NZ,
		  MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);

    pickup_h = Pics.pickup_signal(dipole_current_x, circum,
				  s/(SP.beta0*clight))/current;
    pickup_v = Pics.pickup_signal(dipole_current_y, circum,
				  s/(SP.beta0*clight))/current;


    //---------------impedance kicks-----------------------

    komplex dqc_t(dqcr, dqci);  // for sliced == 0

    if(imp_kick == 1){
      if(sliced == 0)
	Pics.kick(ds/circum*InducedKick(Pics.offset_x(), ds, dqc_t, SP.beta0,
					tunex, circum), 0.0);
      else{
	dipole_kick_x.reset(); 	
	if(Rs > 0.0 || leit > 0.0){
	  Pics.gatherXs(SP.beta0*clight*charge*qe/dz, dipole_current_xs_tmp);
	  MPI_Allreduce(dipole_current_xs_tmp.get_grid(), dipole_current_xs.get_grid(),
			NZ, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);	
	  InducedWakeKick(dipole_kick_x, dipole_current_x, dipole_current_xs, tunex,
			  2.0*PI*SP.beta0*clight/circum, nres, Rs, Qs, piperadius,
			  leit, SP.beta0, SP.gamma0*mp*SP.A*pow(clight, 2), SP.Z*qe);
	}
	if(Zimage != 0.0)
	  InducedKick(dipole_kick_x, dipole_current_x, Zimage, SP.beta0,
		      SP.gamma0*mp*SP.A*pow(clight, 2), SP.Z*qe);
	Pics.impedance_kick(dipole_kick_x, circum, ds);
      }
    }


    //---------------end impedance kicks-----------------------

    //------------self-consistent space charge kicks after every sectormap----
    if(space_charge == 1){    
      // PIC -> charge density for Poisson solver:
      if (sliced == 0){
	Pics.gatherXY(charge*qe/circum, rho_xy_tmp);		
	MPI_Allreduce(rho_xy_tmp.get_grid(), rho_xy.get_grid(), NX*NY, MPI_DOUBLE,
		      MPI_SUM, MPI_COMM_WORLD);	
      }else{	
	Pics.gatherXYZ(charge*qe/rho_xyz.get_dz(), rho_xyz);

	// send and receive density ghost grids to neighbor slices:
	// what is exchanged here ???
	if(destl >= 0)
	  MPI_Send(rho_xyz.get_ghostl(), NX*NY, MPI_DOUBLE, destl, 2, MPI_COMM_WORLD);
	if(destr >= 0){
	  MPI_Recv(rho_xy_tmp.get_grid(), NX*NY, MPI_DOUBLE, destr, 2, MPI_COMM_WORLD,
		   &status);
	  rho_xyz[NZ_bunch/numprocs-1] += rho_xy_tmp;
	}
	if(destr >= 0)
	  MPI_Send(rho_xyz.get_ghostr(), NX*NY, MPI_DOUBLE, destr, 3, MPI_COMM_WORLD);
	if(destl >= 0){
	  MPI_Recv(rho_xy_tmp.get_grid(), NX*NY, MPI_DOUBLE, destl, 3, MPI_COMM_WORLD,
		   &status);
	  rho_xyz[0]+= rho_xy_tmp;
	}
      }
       // Poisson solver
      if(sliced == 0)
	poisson_xy(Ex, Ey, rho_xy, gf1);
      else{
	poisson_xyz(Ex3, Ey3, rho_xyz, gf1);
	
	// send and receive efield ghost grids to neighbor slices:
	if(destl >= 0){
	  MPI_Send(Ex3.get_ghostl(), NX*NY, MPI_DOUBLE, destl, 2,
		   MPI_COMM_WORLD);
	  MPI_Send(Ey3.get_ghostl(), NX*NY, MPI_DOUBLE, destl, 4,
		   MPI_COMM_WORLD);
	}
	if(destr >= 0){
	  MPI_Recv(Ex3[NZ_bunch/numprocs-1].get_grid(), NX*NY, MPI_DOUBLE,
		   destr, 2, MPI_COMM_WORLD, &status);
	  MPI_Recv(Ey3[NZ_bunch/numprocs-1].get_grid(), NX*NY, MPI_DOUBLE,
		   destr, 4, MPI_COMM_WORLD, &status);
	}
	if(destr >= 0){
	  MPI_Send(Ex3.get_ghostr(), NX*NY, MPI_DOUBLE, destr, 3, MPI_COMM_WORLD);
	  MPI_Send(Ey3.get_ghostr(), NX*NY, MPI_DOUBLE, destr, 5, MPI_COMM_WORLD);
	}
	if(destl >= 0){
	  MPI_Recv(Ex3[0].get_grid(), NX*NY, MPI_DOUBLE, destl, 3, MPI_COMM_WORLD, &status);
	  MPI_Recv(Ey3[0].get_grid(), NX*NY, MPI_DOUBLE, destl, 5, MPI_COMM_WORLD, &status);
	}
      }
    }
    
    // Shift xs and ys:
    
    if(space_charge == 1 && ds > 0.0){
      if(sliced == 0)
	Pics.kick(Ex, Ey, ds);
      else
	Pics.kick(Ex3, Ey3, ds);
    }
    
    //---------------end self-consistent space charge kicks---------------

    // linear sc kicks:
    
    if(space_charge == 2 && ds > 0.0)
      Pics.linear_SC_kick(dQxm, dQym, tunex, tuney, rho_z, current/(SP.beta0*clight),
			  dipole_current_x, dipole_current_y, circum, ds);
	
    // nonlinear sc kicks:

    if(space_charge == 3 && ds > 0.0)
      Pics.nonlinear_SC_kick(sqrt(1.0e-6*twiss0.betx*eps_x), sqrt(1.0e-6*twiss0.bety*eps_y),
			     dQxm, dQym, tunex, tuney, rho_z, current/(SP.beta0*clight),
			     circum, ds);

    // dipole noise modulation kick:
    double dnoiseamp = 1.0e-6;
    double nus = fsyn/(SP.beta0*clight/circum);
    if(btf == 1)
      dtheta = Pics.dipole_mod_kick(s/(SP.beta0*clight), ds, circum, dnoiseamp,
				    (tunex+nus)*SP.beta0*clight/circum, btf_harmonic);	
						
    // correct for ibs:

    /*if(counter != 0 && counter%Nibs == 0){
      double rate_ibs = 1.0e4;
      double Dz = rate_ibs*pow(Pics.rms_momentum_spread(), 2);
      double Dxy = rate_ibs*0.5*(Pics.rms_emittance_x()+Pics.rms_emittance_y());
      double betx = lattice.get_element()->get_betx();
      double bety = lattice.get_element()->get_bety();
      Pics.langevin(rate_ibs, rate_ibs*0.0, Dxy, Dz*0.0, Nibs*ds, betx, bety,
        &d);
      }*/

    // For bunch compression: Update slice boundaries z1 and z2 from
    // new bunch boundaries zm1, zm2:

    /*if(counter != 0 && counter%Nexchange == 0){
      if(myid == 0)
      zm1 = Pics.z_min();
      MPI_Bcast(&zm1, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
      if(myid == numprocs-1)
      zm2 = Pics.z_max();
      MPI_Bcast(&zm2, 1, MPI_DOUBLE, numprocs-1, MPI_COMM_WORLD);

      Pics.z1 = zm1+myid*(zm2-zm1)/numprocs;
      Pics.z2 = Pics.z1+(zm2-zm1)/numprocs;
      slice_length = Pics.z2-Pics.z1;

      rho_xyz.get_zleft() = zm1;
      rho_xyz.get_zright() = zm2;
      Ex3.get_zleft() = zm1;
      Ex3.get_zright() = zm2;
      Ey3.get_zleft() = zm1;
      Ey3.get_zright() = zm2;
      }*/


    // advance in beam line, go to next element:

    lattice.next_element();
    ++counter;

  }while(counter != cells*Nelements);          //loop check, cells (turns) given by user  SA

  //------------------end of loop-------------------------------

  // close files, free heap:

  delete septLoss, sl_slice;
  delete[] momenta, momenta_tot;  // [] needed here!; SP
  fclose(out);

  // MPI end:

  MPI_Finalize();

  time2 = time(0);
  double sec = difftime(time2, time1);
  double h = floor(sec/3600);
  double min = floor(sec/60-60.*h);
  sec -= 3600.*h+60.*min;
    
  if(myid == 0)  
    {cout << "Total losses: " << (1-Ntot/(max_inj*NPIC))*100. << " \%\n" <<
      "Stored particles: " << current*circum*Ntot/(qe*Z*SP.beta0*clight*NPIC) << endl <<
      "Computation time: " << h << ":" << min << ":" << sec << endl;   
	}
   }
Example #22
0
TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityB);
TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityC);
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorA);
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorB);
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorC);
TESTLAYER_CREATE_FUNC(LayerTest1);
TESTLAYER_CREATE_FUNC(LayerTest2);
TESTLAYER_CREATE_FUNC(LayerTestBlend);
TESTLAYER_CREATE_FUNC(LayerGradient);
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointPos);
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointRot);
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointScale);
TESTLAYER_CREATE_FUNC(LayerExtendedBlendOpacityTest);

static NEWTESTFUNC createFunctions[] = {
    CF(LayerTestCascadingOpacityA),
    CF(LayerTestCascadingOpacityB),
    CF(LayerTestCascadingOpacityC),
    CF(LayerTestCascadingColorA),
    CF(LayerTestCascadingColorB),
    CF(LayerTestCascadingColorC),
    CF(LayerTest1),
    CF(LayerTest2),
    CF(LayerTestBlend),
    CF(LayerGradient),
    CF(LayerIgnoreAnchorPointPos),
    CF(LayerIgnoreAnchorPointRot),
    CF(LayerIgnoreAnchorPointScale),
    CF(LayerExtendedBlendOpacityTest)
};
Example #23
0
#include "AnimTest.h"
#include "../testResource.h"
#include "cocos2d.h"
#include "cocos2d-better.h"

TESTLAYER_CREATE_FUNC(AnimMotionWelder);
TESTLAYER_CREATE_FUNC(AnimArctic);
TESTLAYER_CREATE_FUNC(AnimAuroraGT);
TESTLAYER_CREATE_FUNC(AnimSpriteX);
TESTLAYER_CREATE_FUNC(AnimSpriteX2011);
TESTLAYER_CREATE_FUNC(AnimClipMappingAuroraGT);

static NEWTESTFUNC createFunctions[] = {
    CF(AnimMotionWelder),
    CF(AnimArctic),
    CF(AnimAuroraGT),
    CF(AnimSpriteX),
    CF(AnimSpriteX2011),
    CF(AnimClipMappingAuroraGT)
};

static int sceneIdx=-1;
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))

static CCLayer* nextAction()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;
    
    CCLayer* pLayer = (createFunctions[sceneIdx])();
    pLayer->init();
Example #24
0
void MODEL::DoDryRewet( PROJECT* project, int* dried, int* wetted )
{
  DRYREW *dryRew = &region->dryRew;

  region->Connection( 0L );

  int del = 0;
  int wel = 0;

  if( dryRew->method == 1 )
  {
    // mark nodes and elements to be rewetted ------------------------------------------------------
    wel = region->Rewet( dryRew->rewetLimit, dryRew->rewetPasses, project );

    // mark dry nodes and elements -----------------------------------------------------------------
    del = region->Dry( dryRew->dryLimit, dryRew->countDown );
  }
  else if( dryRew->method == 2 )
  {
    region->DryRewet( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
  }
  else if( dryRew->method == 3 )
  {
    region->RewetDry( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
  }
/*
  // future work ...
  else if( dryRew->method == 4 )
  {
    // determine dynamic boundary ------------------------------------------------------------------
    region.DynamicBound( np, node, *elem, dryRew->dryLimit, project );
  }
*/

  //////////////////////////////////////////////////////////////////////////////////////////////////

# ifdef _MPI_
  del = project->subdom.Mpi_sum( del );
  wel = project->subdom.Mpi_sum( wel );
# endif

  char text [200];

  sprintf( text, "\n (MODEL::DoDryRewet)     %d elements have got dry\n", del );
  REPORT::rpt.Output( text, 3 );

  sprintf( text, "\n (MODEL::DoDryRewet)     %d elements have got wet\n", wel );
  REPORT::rpt.Output( text, 3 );

  int dryRewFlag = del + wel;

  if( dryRewFlag )
  {
    ////////////////////////////////////////////////////////////////////////////////////////////////
    // exchange information on dry nodes on interfaces
#   ifdef _MPI_
    if( project->subdom.npr > 1 )
    {
      MPI_Comm_Dry( project, true );

      //////////////////////////////////////////////////////////////////////////////////////////////
      // reset wetted area, in case of dry nodes that are not dry in adjacent subdomains
      // added on 20.04.2006, sc

      if( dryRew->method == 2  ||  dryRew->method == 3 )
      {
        int wetted = 0;

        for( int n=0; n<region->Getnp(); n++ )
        {
          NODE* nd = region->Getnode(n);

          nd->mark = false;

          double H = nd->v.S - nd->zor;

          if( H < dryRew->dryLimit )
          {
            SF( nd->flag, NODE::kDry );
          }

          else if( isFS(nd->flag, NODE::kDry) )
          {
            nd->mark = true;

            CF( nd->flag, NODE::kDry );
            wetted++;
          }

          CF( nd->flag, NODE::kMarsh );
          nd->z = nd->zor;
        }


        if( dryRew->method == 2 )
        {
          region->DryRewet( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
        }
        else if( dryRew->method == 3 )
        {
          region->RewetDry( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
        }

        ////////////////////////////////////////////////////////////////////////////////////////////

        MPI_Comm_Dry( project, false );

        wetted = project->subdom.Mpi_sum( wetted );

        sprintf( text, "\n (MODEL::DoDryRewet)     %d interface nodes have got wet\n", wetted );
        REPORT::rpt.Output( text, 3 );
      }
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////
    // reset interface flags: kInface, kInface_DN and kInface_UP; this is
    // necessary for the correct ordering of equations in EQS::ResetEqOrder()

    project->subdom.SetInface( region );

#   endif  //  #ifdef _MPI_
    ////////////////////////////////////////////////////////////////////////////////////////////////

    // determine 1D boundary elements and ----------------------------------------------------------
    // set up slip velocity boundary conditions

    Initialize();

    SetNormal();
    SetRotation();

    region->SetSlipFlow();

    REPORT::rpt.PrintTime( 3 );

//  ================================================================================================
#   ifdef kDebug_1
    for( int n=0; n<region->Getnp(); n++ )
    {
      NODE* ndbg = region->Getnode(n);

      switch( ndbg->Getname() )
      {
        case 3654:
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "### NODE %6d: inface    = %d\n", ndbg->Getname(), ndbg->flag&NODE::kInface );
          REPORT::rpt.Message( "###            : inface_dn = %d\n", ndbg->flag&NODE::kInface_DN );
          REPORT::rpt.Message( "###            : inface_up = %d\n", ndbg->flag&NODE::kInface_UP );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : dry       = %d\n", ndbg->flag&NODE::kDry );
          REPORT::rpt.Message( "###            : marsh     = %d\n", ndbg->flag&NODE::kMarsh );
          REPORT::rpt.Message( "###            : H         = %f\n", ndbg->v.S - ndbg->zor );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : bound     = %d\n", ndbg->flag&NODE::kBound );
          REPORT::rpt.Message( "###            : inflow    = %d\n", ndbg->flag&NODE::kInlet );
          REPORT::rpt.Message( "###            : outflow   = %d\n", ndbg->flag&NODE::kOutlet );
          REPORT::rpt.Message( "###            : rotat     = %d\n", ndbg->flag&NODE::kRotat );
          REPORT::rpt.Message( "###            : noMoment  = %d\n", ndbg->flag&NODE::kNoMoment );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : countDown = %d\n", ndbg->countDown );

          {
            SUB* sub = ndbg->sub;
            while( sub )
            {
              REPORT::rpt.Message( "### SUBDOM %4d: dry       = %d\n", sub->no+1, sub->dry );
              sub = sub->next;
            }
          }
          break;
      }
    }
#   endif
//  ================================================================================================
  }

  else
  {
    // set up structure for connection of nodes to elements ----------------------------------------
    // dry elements are not taken into consideration

    region->Connection( ELEM::kDry );
  }

  if( dried )  *dried  = del;
  if( wetted ) *wetted = wel;

  region->firstDryRew = false;
}
Example #25
0
void GRID::ReportDry( PROJECT* project,
                      double   dryLimit,
                      int      countDown )
{
  int dryNodes = false;


  // check for dry nodes -------------------------------------------------------------------

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    nd->countDown = 0;

    CF( nd->flag, NODE::kDry );

    if( (nd->v.S - nd->z) < dryLimit )
    {
      SF( nd->flag, NODE::kDry );

      dryNodes = true;
    }
  }


  // report all dry nodes ------------------------------------------------------------------

  if( dryNodes )
  {
    REPORT::rpt.Output( "\n\n----------------------------------------", 5 );
    REPORT::rpt.Output( "------------------------------\n", 5 );
    REPORT::rpt.Output( "\n ... the following nodes are dry\n", 5 );

    int jdry = 0;

    for( int n=0; n<Getnp(); n++ )
    {
      NODE* nd = Getnode(n);

      if( isFS(nd->flag, NODE::kDry) )
      {
        char text[20];
        sprintf( text, "  %5d", nd->Getname() );
        REPORT::rpt.Output( text, 5 );

        jdry++;
        if( !( jdry % 10) ) REPORT::rpt.Output( "\n", 5 );
      }
    }

    if( jdry % 10 ) REPORT::rpt.Output( "\n", 5 );


    // loop on all elements ----------------------------------------------------------------

    for( int e=0; e<Getne(); e++ )
    {
      ELEM* el = Getelem(e);

      CF( el->flag, ELEM::kDry );

      int nnd = el->Getnnd();

      for( int i=0; i<nnd; i++ )
      {
        if( isFS(el->nd[i]->flag, NODE::kDry) )
        {
          SF( el->flag, ELEM::kDry );
          break;
        }
      }
    }


    for( int n=0; n<Getnp(); n++ )
    {
      NODE* nd = Getnode(n);

      SF( nd->flag, NODE::kDry );
    }


    // loop on all elements: all nodes at wet elements are wet -----------------------------

    for( int e=0; e<Getne(); e++ )
    {
      ELEM* el = Getelem(e);

      if( !isFS(el->flag, ELEM::kDry) )
      {
        int nnd = el->Getnnd();

        for( int i=0; i<nnd; i++ ) CF( el->nd[i]->flag, NODE::kDry );
      }
    }


    int idry = 0;

    REPORT::rpt.Output( "\n ... the following elements are dry\n", 5 );

    for( int e=0; e<Getne(); e++ )
    {
      ELEM* el = Getelem(e);

      if( isFS(el->flag, ELEM::kDry) )
      {
        char text[20];
        sprintf( text, "  %5d", el->Getname() );
        REPORT::rpt.Output( text, 5 );

        idry++;
        if( !( idry % 10) )  REPORT::rpt.Output( "\n", 5 );
      }
    }

    if( idry % 10 )  REPORT::rpt.Output( "\n", 5 );

    REPORT::rpt.Output( "\n", 5 );


    for( int n=0; n<Getnp(); n++ )
    {
      NODE* nd = Getnode(n);

      if( isFS(nd->flag, NODE::kDry) )
      {
        nd->v.U = 0.0;
        nd->v.V = 0.0;
        nd->v.S = nd->z;

        nd->v.K = 0.0;
        nd->v.D = 0.0;

        nd->v.dUdt = 0.0;
        nd->v.dVdt = 0.0;

        nd->v.dSdt = 0.0;
      }
    }
  }
}
Example #26
0
static void
register_curses_constants(lua_State *L)
{
	/* colors */
	CC(COLOR_BLACK);	CC(COLOR_RED);		CC(COLOR_GREEN);
	CC(COLOR_YELLOW);	CC(COLOR_BLUE);		CC(COLOR_MAGENTA);
	CC(COLOR_CYAN);		CC(COLOR_WHITE);

	/* alternate character set */
	CC(ACS_BLOCK);		CC(ACS_BOARD);

	CC(ACS_BTEE);		CC(ACS_TTEE);
	CC(ACS_LTEE);		CC(ACS_RTEE);
	CC(ACS_LLCORNER);	CC(ACS_LRCORNER);
	CC(ACS_URCORNER);	CC(ACS_ULCORNER);

	CC(ACS_LARROW);		CC(ACS_RARROW);
	CC(ACS_UARROW);		CC(ACS_DARROW);

	CC(ACS_HLINE);		CC(ACS_VLINE);

	CC(ACS_BULLET);		CC(ACS_CKBOARD);	CC(ACS_LANTERN);
	CC(ACS_DEGREE);		CC(ACS_DIAMOND);

	CC(ACS_PLMINUS);	CC(ACS_PLUS);
	CC(ACS_S1);		CC(ACS_S9);

	/* attributes */
	CC(A_NORMAL);		CC(A_STANDOUT);		CC(A_UNDERLINE);
	CC(A_REVERSE);		CC(A_BLINK);		CC(A_DIM);
	CC(A_BOLD);		CC(A_PROTECT);		CC(A_INVIS);
	CC(A_ALTCHARSET);	CC(A_CHARTEXT);
	CC(A_ATTRIBUTES);
#ifdef A_COLOR
	CC(A_COLOR);
#endif

	/* key functions */
	CC(KEY_BREAK);		CC(KEY_DOWN);		CC(KEY_UP);
	CC(KEY_LEFT);		CC(KEY_RIGHT);		CC(KEY_HOME);
	CC(KEY_BACKSPACE);

	CC(KEY_DL);		CC(KEY_IL);		CC(KEY_DC);
	CC(KEY_IC);		CC(KEY_EIC);		CC(KEY_CLEAR);
	CC(KEY_EOS);		CC(KEY_EOL);		CC(KEY_SF);
	CC(KEY_SR);		CC(KEY_NPAGE);		CC(KEY_PPAGE);
	CC(KEY_STAB);		CC(KEY_CTAB);		CC(KEY_CATAB);
	CC(KEY_ENTER);		CC(KEY_SRESET);		CC(KEY_RESET);
	CC(KEY_PRINT);		CC(KEY_LL);		CC(KEY_A1);
	CC(KEY_A3);		CC(KEY_B2);		CC(KEY_C1);
	CC(KEY_C3);		CC(KEY_BTAB);		CC(KEY_BEG);
	CC(KEY_CANCEL);		CC(KEY_CLOSE);		CC(KEY_COMMAND);
	CC(KEY_COPY);		CC(KEY_CREATE);		CC(KEY_END);
	CC(KEY_EXIT);		CC(KEY_FIND);		CC(KEY_HELP);
	CC(KEY_MARK);		CC(KEY_MESSAGE); /* ncurses extension: CC(KEY_MOUSE); */
	CC(KEY_MOVE);		CC(KEY_NEXT);		CC(KEY_OPEN);
	CC(KEY_OPTIONS);	CC(KEY_PREVIOUS);	CC(KEY_REDO);
	CC(KEY_REFERENCE);	CC(KEY_REFRESH);	CC(KEY_REPLACE);
	CC(KEY_RESIZE);		CC(KEY_RESTART);	CC(KEY_RESUME);
	CC(KEY_SAVE);		CC(KEY_SBEG);		CC(KEY_SCANCEL);
	CC(KEY_SCOMMAND);	CC(KEY_SCOPY);		CC(KEY_SCREATE);
	CC(KEY_SDC);		CC(KEY_SDL);		CC(KEY_SELECT);
	CC(KEY_SEND);		CC(KEY_SEOL);		CC(KEY_SEXIT);
	CC(KEY_SFIND);		CC(KEY_SHELP);		CC(KEY_SHOME);
	CC(KEY_SIC);		CC(KEY_SLEFT);		CC(KEY_SMESSAGE);
	CC(KEY_SMOVE);		CC(KEY_SNEXT);		CC(KEY_SOPTIONS);
	CC(KEY_SPREVIOUS);	CC(KEY_SPRINT);		CC(KEY_SREDO);
	CC(KEY_SREPLACE);	CC(KEY_SRIGHT);		CC(KEY_SRSUME);
	CC(KEY_SSAVE);		CC(KEY_SSUSPEND);	CC(KEY_SUNDO);
	CC(KEY_SUSPEND);	CC(KEY_UNDO);

	/* KEY_Fx  0 <= x <= 63 */
	CC(KEY_F0);
	CF(1);  CF(2);  CF(3);  CF(4);  CF(5);  CF(6);  CF(7);  CF(8);
	CF(9);  CF(10); CF(11); CF(12); CF(13); CF(14); CF(15); CF(16);
	CF(17); CF(18); CF(19); CF(20); CF(21); CF(22); CF(23); CF(24);
	CF(25); CF(26); CF(27); CF(28); CF(29); CF(30); CF(31); CF(32);
	CF(33); CF(34); CF(35); CF(36); CF(37); CF(38); CF(39); CF(40);
	CF(41); CF(42); CF(43); CF(44); CF(45); CF(46); CF(47); CF(48);
	CF(49); CF(50); CF(51); CF(52); CF(53); CF(54); CF(55); CF(56);
	CF(57); CF(58); CF(59); CF(60); CF(61); CF(62); CF(63);
}
Example #27
0
int FC(int variable, int** values){
	/* Spécifications: fonction récursive qui va executer l'algorithme du foward checking sur avec
	les valeurs values sur une variable.*/
	int** copie = (int**) malloc(sizeof(int*)*nb_sommet);
	int i,j,k,ok=0;

	for(i=0;i<nb_sommet;i++)
		copie[i] = (int*) malloc(sizeof(int)*taille_domaine);


	for(i=0;i<nb_sommet;i++)
		for(j=0;j<taille_domaine;j++)
			copie[i][j] = values[i][j];

	for(i=0;i<taille_domaine;i++){

		if(values[variable][i] == 1){

			if( CF(values,variable,i) ){
				nbAffectation++;
				/*if(nbAffectation==1000){
					printf("Trop d'affectation\n");
					exit(EXIT_FAILURE);
				}*/
				affectation[variable] = i;
				affectationFC(values,variable,i);
				//printf("Affectation de la variable %d a la valeur %d\n",variable,i);
				//afficheFC(values);
				ok = 1;

				if(variable+1 < nb_sommet){
					ok  = FC(variable+1,values);
				}

				if(ok == 1){

					for(i=0;i<nb_sommet;i++)
						free(copie[i]);
						
					free(copie);
					return 1;
				}else{
					//printf("L'affectation de la variable %d a la valeur %d ne marche pas, backtrack\n",variable,affectation[variable]);
					affectation[variable] = NULL;

					for(k=0;k<nb_sommet;k++)
						for(j=0;j<taille_domaine;j++)
							values[k][j] = copie[k][j];
					
						//afficheFC(values);
				}

			}else{
				//printf("Impossible d'affecter la variable %d a la valeur %d\n",variable,i);
			}

		}

	}
	//printf("L'affectation de la variable %d a la valeur %d ne marche pas, backtrack\n",variable,affectation[variable]);
	affectation[variable] = NULL;

	for(i=0;i<nb_sommet;i++)
			for(j=0;j<taille_domaine;j++)
				values[i][j] = copie[i][j];
	//afficheFC(values);
	for(i=0;i<nb_sommet;i++)
			free(copie[i]);
			
	free(copie);
	return 0;
}
Example #28
0
void GRID::DryRewet( double  dryLimit,
                     double  rewetLimit,
                     int     countDown,
                     int*    dried,
                     int*    wetted )
{
  // -------------------------------------------------------------------------------------
  // check for dry nodes

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    // mark recently dry nodes
    if( isFS(nd->flag, NODE::kDry) )  nd->mark = true;
    else                              nd->mark = false;

    CF( nd->flag, NODE::kMarsh );


    double H = nd->v.S - nd->zor;

    if( H < dryLimit )
    {
      SF( nd->flag, NODE::kDry );
      nd->countDown = countDown;
    }
    else
    {
      if( nd->countDown > 0 )  nd->countDown--;
      else                     CF( nd->flag, NODE::kDry );
    }

    nd->z = nd->zor;
  }


  // -------------------------------------------------------------------------------------
  // loop on all elements: check for dry elements

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    // mark elements that have been dry --------------------------------------------------
    if( isFS(el->flag, ELEM::kDry) )  el->mark = true;
    else                              el->mark = false;

    CF( el->flag, ELEM::kDry | ELEM::kMarsh );

    int ncn = el->Getncn();

    int ndry = 0;

    for( int i=0; i<ncn; i++ )
    {
      if( isFS(el->nd[i]->flag, NODE::kDry) )  ndry++;
    }


    // set dry flag if all nodes are dry
    // set marsh flag if at least one node is dry

    if( ndry == ncn )
    {
      SF( el->flag, ELEM::kDry );
    }

    else if( ndry )
    {
      SF( el->flag, ELEM::kMarsh );

      for( int i=0; i<ncn; i++ )
      {
        if( isFS(el->nd[i]->flag, NODE::kDry) )
        {
          SF( el->nd[i]->flag, NODE::kMarsh );
        }
      }
    }
  }

  // -------------------------------------------------------------------------------------
  // loop on all elements: all nodes at wet elements are wet

  for( int n=0; n<Getnp(); n++ )
  {
    SF( Getnode(n)->flag, NODE::kDry );
  }


  // initialize water surface in marsh elements

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( !isFS(el->flag, ELEM::kDry) )
    {
      int ncn = el->Getncn();
      int nnd = el->Getnnd();

      for( int i=0; i<nnd; i++ )  CF( el->nd[i]->flag, NODE::kDry );

      for( int i=0; i<ncn; i++ )
      {
        double Si, Sj, Sk;

        if( isFS(el->nd[i]->flag, NODE::kMarsh) )
        {
          //----------------------------------------------------------------------------------------
          // 01.10.2004, sc
          // The following block of code will initialize the water surface in marsh elements.
          // This will be done only for elements that have been dry in the previous time step.
          //
          // improvement on 16.02.2013, sc
          // 1. A potential water elevation Si at the dry node is computed from adjacent nodes.
          // 2. The water elevation will be initialized according to the variable rewetLimit:
          //    a) Si > Z + rewetLimit                : S = Z + rewetLimit
          //    b) Si < Z + dryLimit                  : Z = S - dryLimit
          //    c) Z + dryLimit < Si < Z + rewetLimit : S = Si

          if( el->nd[i]->mark || firstDryRew )
          {
            int j = (i + 1)       % ncn;
            int k = (i + ncn - 1) % ncn;

            if(     !isFS(el->nd[j]->flag, NODE::kMarsh)
                &&  !isFS(el->nd[k]->flag, NODE::kMarsh) )
            {
              Sj = el->nd[j]->v.S;
              Sk = el->nd[k]->v.S;

              Si = (Sj + Sk) / 2.0;
            }
            else if( !isFS(el->nd[j]->flag, NODE::kMarsh) )
            {
              Si = el->nd[j]->v.S;
            }
            else if( !isFS(el->nd[k]->flag, NODE::kMarsh) )
            {
              Si = el->nd[k]->v.S;
            }
            else
            {
              j = (i + 2) % ncn;

              if( isFS(el->nd[j]->flag, NODE::kMarsh) )
                REPORT::rpt.Error( "unexpected marsh element - dryRewet (1)" );

              Si = el->nd[j]->v.S;
            }

            el->nd[i]->v.S = Si;

            // Adapt the water elevation S or bottom elevation z between dryLimit and rewetLimit.
            if( el->nd[i]->v.S > el->nd[i]->zor + rewetLimit )
            {
              el->nd[i]->v.S = el->nd[i]->zor + rewetLimit;
            }

            if( el->nd[i]->v.S < el->nd[i]->zor + dryLimit )
            {
              el->nd[i]->z = el->nd[i]->v.S - dryLimit;
            }
          }

          else
          {
            // Adapt bottom elevation of dry nodes.
            // changed on 18.04.2006, sc
            if( el->nd[i]->v.S < el->nd[i]->zor + dryLimit )
            {
              el->nd[i]->z = el->nd[i]->v.S - dryLimit;
            }
          }
        }
      }
    }
  }


  // -------------------------------------------------------------------------------------
  // interpolate midside nodes

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    int ncn = el->Getncn();
    int nnd = el->Getnnd();

    for( int i=ncn; i<nnd; i++ )
    {
      int    left, right;
      double leftS, rightS;
      double leftZ, rightZ;


      // get left and right corner node to midside node i

      el->GetLShape()->getCornerNodes( i, &left, &right );

      leftS  = el->nd[left]->v.S;
      rightS = el->nd[right]->v.S;

      leftZ  = el->nd[left]->z;
      rightZ = el->nd[right]->z;

      el->nd[i]->v.S =  0.5 * (leftS + rightS);
      el->nd[i]->z   =  0.5 * (leftZ + rightZ);

      if(     isFS(el->flag, ELEM::kMarsh)
          &&  el->nd[i]->z + dryLimit/10.0  <  el->nd[i]->zor )
      {
        SF( el->nd[i]->flag, NODE::kMarsh );
      }
    }
  }


  // -------------------------------------------------------------------------------------
  // initialize dry nodes

  for( int n=0; n<Getnp(); n++ )
  {
    NODE* nd = Getnode(n);

    if( isFS(nd->flag, NODE::kDry) )
    {
      nd->v.U = 0.0;
      nd->v.V = 0.0;
      nd->v.S = nd->z = nd->zor;

      nd->v.K = 0.0;
      nd->v.D = 0.0;

      nd->v.dUdt = 0.0;
      nd->v.dVdt = 0.0;
      nd->v.dSdt = 0.0;
    }
  }


  // -------------------------------------------------------------------------------------
  // report elements

  char text[100];

  REPORT::rpt.Output( "\n (GRID::DryRewet)        the following elements have got dry\n", 5 );

  int cnt = 0;

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( isFS(el->flag, ELEM::kDry)  &&  !el->mark )
    {
      sprintf( text, "  %6d", el->Getname() );
      REPORT::rpt.Output( text, 5 );

      cnt++;
      if( !(cnt % 10) )  REPORT::rpt.Output( "\n", 5 );
    }
  }

  if( cnt % 10 )  REPORT::rpt.Output( "\n", 5 );

  *dried += cnt;


  REPORT::rpt.Output( "\n (GRID::DryRewet)        the following elements have got wet\n", 5 );

  cnt = 0;

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( !isFS(el->flag, ELEM::kDry)  &&  el->mark )
    {
      sprintf( text, "  %6d", el->Getname() );
      REPORT::rpt.Output( text, 5 );

      cnt++;
      if( !(cnt % 10) )  REPORT::rpt.Output( "\n", 5 );
    }
  }

  if( cnt % 10 )  REPORT::rpt.Output( "\n", 5 );

  *wetted += cnt;


  // -------------------------------------------------------------------------------------
  // following the complete list of dry / marsh elements

# ifdef kDebug

  REPORT::rpt.Output( "\n (GRID::DryRewet)        list of dry elements\n", 5 );

  int pos =  0;
  int E1  = -1;
  int E2  = -1;
  int E3  = -1;

  for( int e=0; e<Getne(); e++ )
  {
    ELEM* el = Getelem(e);

    if( isFS(el->flag, ELEM::kDry) )
    {
      if( E1 < 0 )
      {
        E1 = el->Getname();
      }

      else if( E2 < 0 )
      {
        E2 = el->Getname();

        if( E2 > E1 + 1 )
        {
          switch( pos )
          {
            case  5:  REPORT::rpt.Output( "\n", 5 );
                      pos = 0;

            default:  sprintf( text, "           %6d", E1 );
                      REPORT::rpt.Output( text, 5 );
                      break;
          }

          pos++;

          E1 = E2;
          E2 = -1;
        }
      }


      else
      {
        E3 = el->Getname();

        if( E3 > E2 + 1 )
        {
          switch( pos )
          {
            case  5:  REPORT::rpt.Output( "\n", 5 );
                      pos = 0;

            default:  sprintf( text, "  %6d - %6d", E1, E2 );
                      REPORT::rpt.Output( text, 5 );
                      break;
          }

          pos++;

          E1 = E3;
          E2 = -1;
        }

        else
        {
          E2 = E3;
        }
      }
    }
  }

  if( E1 > 0  &&  E2 > 0 )
  {
    switch( pos )
    {
      case  5:  REPORT::rpt.Output( "\n", 5 );

      default:  sprintf( text, "  %6d - %6d", E1, E2 );
                REPORT::rpt.Output( text, 5 );
                break;
    }
  }

  else if( E1 > 0 )
  {
    switch( pos )
    {
      case  5:  REPORT::rpt.Output( "\n", 5 );

      default:  sprintf( text, "           %6d", E1 );
                REPORT::rpt.Output( text, 5 );
                break;
    }
  }

  REPORT::rpt.Output( "\n", 5 );

# endif
}
#include "NetworkTest.h"
#include "../testResource.h"
#include "cocos2d.h"
#include "cocos2d-better.h"

TESTLAYER_CREATE_FUNC(NetworkTCP);
TESTLAYER_CREATE_FUNC(NetworkUDP);

static NEWTESTFUNC createFunctions[] = {
    CF(NetworkTCP),
	CF(NetworkUDP)
};

static int sceneIdx=-1;
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))

static CCLayer* nextAction()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;
    
    CCLayer* pLayer = (createFunctions[sceneIdx])();
    pLayer->init();
    pLayer->autorelease();
    
    return pLayer;
}

static CCLayer* backAction()
{
    sceneIdx--;
Example #30
0
#include "FileUtilsTest.h"


TESTLAYER_CREATE_FUNC(TestResolutionDirectories);
TESTLAYER_CREATE_FUNC(TestSearchPath);
TESTLAYER_CREATE_FUNC(TestFilenameLookup);
TESTLAYER_CREATE_FUNC(TestIsFileExist);

static NEWTESTFUNC createFunctions[] = {
    CF(TestResolutionDirectories),
    CF(TestSearchPath),
    CF(TestFilenameLookup),
    CF(TestIsFileExist)
};

static int sceneIdx=-1;
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))

static CCLayer* nextAction()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;
    
    CCLayer* pLayer = (createFunctions[sceneIdx])();
    pLayer->init();
    pLayer->autorelease();
    
    return pLayer;
}

static CCLayer* backAction()