Index: Interface_Web/trunk/pspaWT/sources/controler/src/softwareParmela.cc
===================================================================
--- Interface_Web/trunk/pspaWT/sources/controler/src/softwareParmela.cc	(revision 417)
+++ Interface_Web/trunk/pspaWT/sources/controler/src/softwareParmela.cc	(revision 418)
@@ -6,5 +6,5 @@
 #include "dataManager.h"
 #include "mixedTools.h"
-//#include "nomDeLogiciel.h"
+
 softwareParmela::softwareParmela() : abstractSoftware()
 {
@@ -15,4 +15,11 @@
 {
   nameOfSoftware_ = nomDeLogiciel("parmela");
+  registerElement(nomdElements::RFgun,TBoolOk);
+  registerElement(nomdElements::drift,TBoolOk);
+  registerElement(nomdElements::cell,TBoolOk);
+  registerElement(nomdElements::bend,TBoolOk);
+  registerElement(nomdElements::soleno,TBoolOk);
+  registerElement(nomdElements::fit,TBoolIgnore);
+  registerElement(nomdElements::snapshot,TBoolIgnore);
 }
 
@@ -23,5 +30,5 @@
   abstractElement* elPtr = dataManager_->getElementPointerFromNumero(numeroDeb_);
 
-  bool there_is_rfgun = ( elPtr->getNomdElement().getElementType() == RFgun );
+  bool there_is_rfgun = ( elPtr->getNomdElement().getElementType() == nomdElements::RFgun );
   unsigned offsetNumElem;
   // les elements de parmela sont indexes de 1 Ã  max, s'il n'y a pas de rfgun
@@ -40,5 +47,6 @@
     abstractElement* elem = dataManager_->getElementPointerFromNumero(k);
     cout << " liste PARMELA no absolu " << k << " relatif provisoire " << relativeParmelaElementIndices_.at(curseur) << endl;
-    if ( elem->is_accepted_by_software(nameOfSoftware_) == TBoolOk ) {
+    // if ( elem->is_accepted_by_software(nameOfSoftware_) == TBoolOk ) {
+    if ( doAcceptElement(elem->getNomdElement().getElementType() )  == TBoolOk ) {
       relativeParmelaElementIndices_.at(curseur) = id;
       cout << " mis a " << id << endl;
@@ -67,5 +75,5 @@
   double initalKineticEnergy = 0.0;
   elPtr = dataManager_->getElementPointerFromNumero(numeroDeb_);
-  bool there_is_rfgun = ( elPtr->getNomdElement().getElementType() == RFgun );
+  bool there_is_rfgun = ( elPtr->getNomdElement().getElementType() == nomdElements::RFgun );
   
   if ( !there_is_rfgun ) {
@@ -88,5 +96,6 @@
   unsigned int premier = numeroDeb_ ;
   if ( there_is_rfgun ) {
-    outfile << dataManager_->getElementPointerFromNumero(numeroDeb_)->parmelaOutputFlow();
+    //    outfile << dataManager_->getElementPointerFromNumero(numeroDeb_)->parmelaOutputFlow();
+    outfile << elementsData(dataManager_->getElementPointerFromNumero(numeroDeb_)->parametersToSoftware());
     premier++;
   } else {
@@ -98,5 +107,6 @@
       elPtr = dataManager_->getElementPointerFromNumero(k);
       if (elPtr) {
-	outfile << elPtr->parmelaOutputFlow();
+	//	outfile << elPtr->parmelaOutputFlow();
+	outfile << elementsData(elPtr->parametersToSoftware());
       }
     }
@@ -185,5 +195,5 @@
 	  unsigned numeroParmel;
 	  numeroParmel = (unsigned)relativeParmelaElementIndices_.at(curseur);
-	  cout << " lecture PARMELA el no absolu " << k << " numero relatif " << numeroParmel << " nom " << elem->getNomdElement().getElementName() << endl;
+	  cout << " lecture PARMELA el no absolu " << k << " numero relatif " << numeroParmel << " nom " << elem->getNomdElement().getExpandedName() << endl;
       	// lecture sortie parmela
 	if(!beamFromParmela(workingDir,numeroParmel,freq,centroid,refPart,particles))
@@ -338,2 +348,180 @@
     return true;
 }
+
+
+string softwareParmela::elementsData(const vector< pair<string, vector<string> > >& donnees) const {
+  unsigned k;
+  cout << " PASSAGE softwareParmela::elementsData " << endl;
+  if ( donnees.at(0).first != "labelsGenericSpecific" ) {
+    cout << " softwareParmela::elementsData ERROR : element badly defined " << endl;
+    return string();
+  }
+  string genericName = donnees.at(0).second.at(0);
+  if ( genericName == "rfgun" ) return rfgunData(donnees);
+  if ( genericName == "cell" ) return cellData(donnees);
+  if ( genericName == "drift" ) return driftData(donnees);
+  if ( genericName == "solnd" ) return solenoData(donnees);
+  if ( genericName == "bend" ) return bendData(donnees);
+  return string();
+}
+
+string softwareParmela::rfgunData(const vector< pair<string, vector<string> > >& donnees) const {
+
+  cout << " PASSAGE softwareParmela::rfgunData " << endl;
+  string nmacrop = "0";
+  string sigma_t = "0.0";
+  string sigma_r = "0.0";
+  string E_cin = "0.0";
+  string sigma_E = "0.0";
+  string phaseStep = "0.0";
+  string totalCharge = "0.0";
+
+  unsigned k;
+  for ( k=1; k < donnees.size(); k++) {
+    if ( donnees.at(k).first == "nbMacroparticles" ) { 
+      nmacrop = donnees.at(k).second.at(0);
+    } else if ( donnees.at(k).first == "sigmasTR" ) {
+      sigma_t = donnees.at(k).second.at(0);
+      sigma_r = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "kineticE" ) {
+      E_cin = donnees.at(k).second.at(0);
+      sigma_E = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "phaseStep" ) {
+      phaseStep = donnees.at(k).second.at(0);
+    } else if ( donnees.at(k).first == "totalCharge" ) {
+      totalCharge = donnees.at(k).second.at(0);
+    }
+  }
+  ostringstream sortie;
+  // on prend les troncatures tmax et rmax Ã  3 sigmas 
+  sortie << "INPUT 10 /np=" << nmacrop << "  /sigt=" << sigma_t << endl;
+  sortie << "  /tmax=" << 3.3*atof(sigma_t.c_str()) << " /sigr=" << sigma_r << endl;
+  sortie << " /rmax=" << 3.0*atof(sigma_r.c_str()) << " /W0=" << E_cin << " /dw0=" << sigma_E << endl;
+  sortie << " /dwt=" << phaseStep << " /ran=2" << endl;
+
+  // on doit entrer le nb vrai de part. (avec signe moins)
+  sortie << "SCHEFF /beami=" << -fabs( atof(totalCharge.c_str()) )/ELECTRONANOCOULOMB << " /nprog=2 /point=-1.7"  << endl;
+ 
+  return sortie.str();
+}
+
+string softwareParmela::cellData(const vector< pair<string, vector<string> > >& donnees) const {
+  cout << " PASSAGE softwareParmela::cellData " << endl;
+
+  string lenght = "0.0";
+  string aperture = "0.0";
+  string initialPhase = "0.0";
+  string acceleratingField = "0.0";
+  string phaseStepMax = "0.0";
+  string acceleratingShapeFile = "";
+  string focusingMagFile = "";
+  string offsetMag = "0.0";
+  string scaleFactor = "0.0";
+
+  unsigned k;
+  for ( k=1; k < donnees.size(); k++) {
+    if ( donnees.at(k).first == "lenghtAperture" ) { 
+      lenght = donnees.at(k).second.at(0);
+      aperture = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "phaseInitialStepmax" ) {
+      initialPhase = donnees.at(k).second.at(0);
+      phaseStepMax = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "fieldValueFile" ) {
+      acceleratingField = donnees.at(k).second.at(0);
+      acceleratingShapeFile = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "MagFocusingFileOffsetScale") {
+      focusingMagFile = donnees.at(k).second.at(0);
+      offsetMag = donnees.at(k).second.at(1);
+      scaleFactor = donnees.at(k).second.at(2);
+    }
+  }
+  ostringstream sortie;
+    sortie << "CELL /l=" << lenght << "  /aper=" << aperture << endl;
+    sortie << "  /iout=1  /phi0=" << initialPhase << " /E0=" << acceleratingField << endl;
+    sortie << " /nc=1 /dwtmax=" << phaseStepMax << " /sym=-1" << endl;
+    sortie << "CFIELD 1" << endl;
+    sortie << acceleratingShapeFile << endl;
+    if ( focusingMagFile != "") {
+      sortie << "POISSON /zoff=" << offsetMag << " /rmult=" << scaleFactor << endl;
+      sortie << focusingMagFile << endl;
+    }
+  return sortie.str();
+
+}
+
+string softwareParmela::driftData(const vector< pair<string, vector<string> > >& donnees) const {
+  cout << " PASSAGE softwareParmela::driftData " << endl;
+
+  string lenght = "0.0";
+  string aperture = "0.0";
+
+  unsigned k;
+  for ( k=1; k < donnees.size(); k++) {
+    if ( donnees.at(k).first == "lenghtAperture" ) { 
+      lenght = donnees.at(k).second.at(0);
+      aperture = donnees.at(k).second.at(1);
+    }
+  }
+  ostringstream sortie;
+  sortie << "DRIFT /l=" << lenght << "  /aper=" << aperture << "  /iout=1" << endl;
+  return sortie.str();
+}
+
+string softwareParmela::solenoData(const vector< pair<string, vector<string> > >& donnees) const {
+  cout << " PASSAGE softwareParmela::solenoData " << endl;
+  string lenght = "0.0";
+  string aperture = "0.0";
+  string B0 = "0.0";
+
+  unsigned k;
+  for ( k=1; k < donnees.size(); k++) {
+    if ( donnees.at(k).first == "lenghtAperture" ) { 
+      lenght = donnees.at(k).second.at(0);
+      aperture = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "field" ) {
+      B0 = donnees.at(k).second.at(0);
+    }
+  }
+    ostringstream sortie;
+    // on passe l'induction magnetique en Gauss 
+    sortie << "SOLENOID /l=" << lenght << "  /aper=" << aperture << "  /iout=1 /h=" << 1000.*atof(B0.c_str())  << endl;
+    return sortie.str();
+
+}
+
+string softwareParmela::bendData(const vector< pair<string, vector<string> > >& donnees) const {
+  cout << " PASSAGE softwareParmela::bendData " << endl;
+
+  string lenght = "0.0";
+  string aperture = "0.0";
+  string angleDeg = "0.0";
+  string momentum = "0.0";
+  string beta1 = "0.0";
+  string beta2 = "0.0";
+  unsigned k;
+  for ( k=1; k < donnees.size(); k++) {
+    if ( donnees.at(k).first == "lenghtAperture" ) { 
+      lenght = donnees.at(k).second.at(0);
+      aperture = donnees.at(k).second.at(1);
+    } else if ( donnees.at(k).first == "angleDegre" ) {
+      angleDeg = donnees.at(k).second.at(0);
+    } else if ( donnees.at(k).first == "momentum" ) {
+      momentum = donnees.at(k).second.at(0);
+     } else if ( donnees.at(k).first == "rotatedFaces" ) {
+      beta1 = donnees.at(k).second.at(0);
+      beta2 = donnees.at(k).second.at(1);
+    }   
+  }
+
+  double ecin = atof(momentum.c_str())/EREST_MeV;
+    ecin = ecin*ecin + 1.;
+    ecin = EREST_MeV*(sqrt(ecin) - 1.0);
+
+    ostringstream sortie;
+    // il faut entrer l'energie cinetique
+    sortie << "BEND /l=" << lenght << "  / aper=" << aperture << "  / iout=1 / wr=" << ecin << " /alpha=" << angleDeg << " / beta1=" << beta1;
+    sortie << " / beta2=" << beta2  << endl;
+
+    return sortie.str();
+
+}
