Пример #1
0
void Line::calculate()
{
//check if any of paramters is changed, if not : don't calculate
const Parameter* p1= getparameter(0);
double A=p1->getvalue();
const Parameter* p2= getparameter(1);
double B=p2->getvalue();

if (p1->changed()||p2->changed())
{
    #ifdef COMPONENT_DEBUG
  std::cout << "parameters changed calculating power law \n A: " << A << " B:" <<B<< "\n";
  #endif
  for (unsigned int i=0;i<(this->getnpoints());i++)
  {
    double en=this->getenergy(i);
    double cts=A+B*en;
    this->setdatapoint(i,en,cts,0.0);
  }
  //set parameters as unchanged since last time we calculated
  this->setunchanged();
}
else
{
     #ifdef COMPONENT_DEBUG
std::cout <<"parameters have not changed, i don't need to calculate again\n";
#endif
}

}
Пример #2
0
void Lorentz::calculate()
{
//check if any parameter is changed, if not : don't calculate
    const Parameter* Epeakptr= getparameter(0);
    const double Epeak=Epeakptr->getvalue();
    const Parameter* FWHMptr= getparameter(1);
    const double FWHM=FWHMptr->getvalue();
    const Parameter* heightptr= getparameter(2);
    const double height=heightptr->getvalue();

    if ((Epeakptr->changed())||(FWHMptr->changed())||(heightptr->changed()))
    {
        //if these have changed, do new calculation
#ifdef COMPONENT_DEBUG
        std::cout << "parameters changed calculating lorentz \n Epeak: " << Epeak << " FWHM:" <<FWHM<<" height: "<<height<< "\n";
#endif
        for (unsigned int i=0; i<(this->getnpoints()); i++)
        {
            const double en=this->getenergy(i);
            //arrea is FWHM*pi/2
            const double cts=height*(pow(FWHM,2.0)/4.0) * ( 1.0/ ( pow((en-Epeak),2.0) + pow((FWHM/2.0),2.0) ) );
            this->setcounts(i,cts);
        }
        //set parameters as unchanged since last time we calculated
        this->setunchanged();
    }
    else {
        //if nothing is changed
#ifdef COMPONENT_DEBUG
        std::cout <<"parameters have not changed, i don't need to calculate again\n";
#endif
    }
}
Пример #3
0
double Lorentz::getarea()
{
//return the area under the lorentz peak
    const Parameter* FWHMptr= getparameter(1);
    double FWHM=FWHMptr->getvalue();
    const Parameter* heightptr= getparameter(2);
    double height=heightptr->getvalue();
    const double pi=acos(-1.0);
    const double area=pi*FWHM*height/2.0;
    return area;
}
Пример #4
0
bool DosLifetimeSpline::checkxsection(){
  //check if the cross section component we are pointing to has still the same number
  //otherwise update the component number parameter
  Model* mymodel=geteelsmodelptr()->getmodel_nonconst();
  const int cnr=mymodel->getcomponentindexbypointer(compptr);
  if (compptr==NULL){
    return false;
  }
  Parameter* cnrptr= getparameter(degree+3);
  if ((cnr==-1)&&(compptr!=NULL)){
    //component not found also kill ourselves...
    Saysomething mysay(0,"Error","DOS: the component we are pointing to seems to be not present");

    delete(this);
    //it's over
    compptr=NULL;
    cnrptr->setchangeable(true); //unlock
    cnrptr->setvalue(-1); //update non-existing value
    cnrptr->setchangeable(false); //lock
    return false;
  }
  cnrptr->setchangeable(true); //unlock
  cnrptr->setvalue(cnr); //update to current value
  cnrptr->setchangeable(false); //lock
  return true;
}
Пример #5
0
Spectrum* Lorentz::getgradient(size_t j) {
//get analytical partial derivative to parameter j in point i
    const Parameter* Epeakptr= getparameter(0);
    double Epeak=Epeakptr->getvalue();
    const Parameter* FWHMptr= getparameter(1);
    double FWHM=FWHMptr->getvalue();
    const Parameter* heightptr= getparameter(2);
    double height=heightptr->getvalue();

#ifdef COMPONENT_DEBUG
    std::cout << "calculating the partial derivative in Epeak: " << Epeak << " FWHM:" <<FWHM<<" height: "<<height<< "\n";
#endif
    switch(j) {
    case 0:
        //analytical derivative wrt Epeak
        for (unsigned int i=0; i<this->getnpoints(); i++)
        {
            double en=this->getenergy(i);
            double denom=pow((en-Epeak),2.0) + pow((FWHM/2.0),2.0);
            gradient.setcounts(i,((height*pow(FWHM,2.0))/2.0)*((en-Epeak)/pow(denom,2.0)));

        }
        break;
    case 1:
        //analytical derivative wrt FWHM
        for (unsigned int i=0; i<(this->getnpoints()); i++)
        {
            double en=this->getenergy(i);
            double denom=pow((en-Epeak),2.0) + pow((FWHM/2.0),2.0);
            gradient.setcounts(i,0.5*(height)*FWHM*(1.0/denom-(pow(FWHM,2.0)/4.0)*(1.0/pow(denom,2.0))));
        }
        break;
    case 2:
        //analytical derivative wrt Height
        for (unsigned int i=0; i<(this->getnpoints()); i++)
        {
            double en=this->getenergy(i);
            double denom=pow((en-Epeak),2.0) + pow((FWHM/2.0),2.0);
            gradient.setcounts(i,(pow(FWHM,2.0)/4.0) * ( 1.0/ denom ));
        }

        break;
    default:
        throw Componenterr::bad_index();
    }
    return &gradient;
}
Пример #6
0
void DosLifetimeSpline::orderchanged(){
    //in case the order of the components changes, update the compnr
    const Model* mymodel=geteelsmodelptr()->getmodel();
    const int cnr=mymodel->getcomponentindexbypointer(compptr);
    Parameter* cnrptr= getparameter(degree+3);
    cnrptr->setchangeable(true); //unlock
    cnrptr->setvalue(cnr); //update to current value
    cnrptr->setchangeable(false); //lock
}
Пример #7
0
void PearsonIV::calculate()
{
//check if any parameter is changed, if not : don't calculate
const Parameter* lambdaptr= getparameter(0);
const double lambda=lambdaptr->getvalue();

const Parameter* mptr= getparameter(1);
const double m=mptr->getvalue();

const Parameter* nuptr= getparameter(2);
const double nu=nuptr->getvalue();

const Parameter* aptr= getparameter(3);
const double a=aptr->getvalue();

const Parameter* strengthptr= getparameter(4);
const double strength=strengthptr->getvalue();

if ((lambdaptr->changed())||(mptr->changed())||(aptr->changed())||(strengthptr->changed())||(nuptr->changed()))
{
  //if these have changed, do new calculation
  #ifdef COMPONENT_DEBUG
  std::cout << "parameters changed calculating pearsonIV \n lambda: " << lambda << " m:" <<m<<" nu:" <<nu<<" a:" <<a<<" strength: "<<strength<< "\n";
  #endif
  for (unsigned int i=0;i<(this->getnpoints());i++)
  {
    const double en=this->getenergy(i);

    //const double cts=height*(pow(FWHM,2.0)/4.0) * ( 1.0/ ( pow((en-Epeak),2.0) + pow((FWHM/2.0),2.0) ) );
    const double cts=strength*pow(1.0+pow((en-lambda)/a,2.0),-m)*exp(-nu*atan((en-lambda)/a));
    this->setcounts(i,cts);
  }
  //set parameters as unchanged since last time we calculated
  this->setunchanged();
}
else{
  //if nothing is changed
  #ifdef COMPONENT_DEBUG
  std::cout <<"parameters have not changed, i don't need to calculate again\n";
  #endif
  }
}
Пример #8
0
//inherit show but also redefine what should happen with the dos window
void DosLifetimeSpline::show(){
    Component::show(); //do the normal show
    initplotspec(); //but also update the points on the plot

    //copy energy values in the names of the parameters
    //this gives users the possiblity to know at what energy the dos points where taken
    for (size_t index=0;index<degree;index++){
        Parameter* pointptr=getparameter(index+3);
        std::string namestring;
        std::ostringstream s;
        if (s << "a" << index <<" @ " << Evector[index+offset] <<" eV"){ //converting an int to a string in c++ style rather than unsafe c-style
	     // conversion worked
	     namestring=s.str();
        }
        pointptr->setname(namestring);
   }
}
Пример #9
0
void Eshift::calculate() {
    //check if any of parameters is changed, if not : don't calculate
    const Parameter* p1= getparameter(0);
    const double dE=p1->getvalue();


    if (p1->changed()) {
        //do the energy shift on the HL spectrum
        HLptr->seteshift(dE);
        //and on the model
        mymodel->seteshift(dE);
        //set parameters as unchanged since last time we calculated
        this->setunchanged();
    }
    else
    {
#ifdef COMPONENT_DEBUG
        std::cout <<"dE=0, no need to calculate the energy shift\n";
#endif
    }

}
Пример #10
0
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename,
                struct Configurable *config)
{
  int res;
  FILE *file;
  char filebuffer[512];
  bool usedarg;
  char *home;
  int rc = 0;

  if(!filename || !*filename) {
    /* NULL or no file name attempts to load .curlrc from the homedir! */

#ifndef __AMIGA__
    filename = CURLRC;   /* sensible default */
    home = homedir();    /* portable homedir finder */
    if(home) {
      if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
        snprintf(filebuffer, sizeof(filebuffer),
                 "%s%s%s", home, DIR_CHAR, CURLRC);

#ifdef WIN32
        /* Check if the file exists - if not, try CURLRC in the same
         * directory as our executable
         */
        file = fopen(filebuffer, "r");
        if(file != NULL) {
          fclose(file);
          filename = filebuffer;
        }
        else {
          /* Get the filename of our executable. GetModuleFileName is
           * already declared via inclusions done in setup header file.
           * We assume that we are using the ASCII version here.
           */
          int n = GetModuleFileName(0, filebuffer, sizeof(filebuffer));
          if(n > 0 && n < (int)sizeof(filebuffer)) {
            /* We got a valid filename - get the directory part */
            char *lastdirchar = strrchr(filebuffer, '\\');
            if(lastdirchar) {
              size_t remaining;
              *lastdirchar = 0;
              /* If we have enough space, build the RC filename */
              remaining = sizeof(filebuffer) - strlen(filebuffer);
              if(strlen(CURLRC) < remaining - 1) {
                snprintf(lastdirchar, remaining,
                         "%s%s", DIR_CHAR, CURLRC);
                /* Don't bother checking if it exists - we do
                 * that later
                 */
                filename = filebuffer;
              }
            }
          }
        }
#else /* WIN32 */
        filename = filebuffer;
#endif /* WIN32 */
      }
      Curl_safefree(home); /* we've used it, now free it */
    }

# else /* __AMIGA__ */
    /* On AmigaOS all the config files are into env:
     */
    filename = "ENV:" CURLRC;

#endif
  }

  if(strcmp(filename,"-"))
    file = fopen(filename, "r");
  else
    file = stdin;

  if(file) {
    char *line;
    char *aline;
    char *option;
    char *param;
    int lineno = 0;
    bool alloced_param;

    while(NULL != (aline = my_get_line(file))) {
      lineno++;
      line = aline;
      alloced_param=FALSE;

      /* line with # in the first non-blank column is a comment! */
      while(*line && ISSPACE(*line))
        line++;

      switch(*line) {
      case '#':
      case '/':
      case '\r':
      case '\n':
      case '*':
      case '\0':
        Curl_safefree(aline);
        continue;
      }

      /* the option keywords starts here */
      option = line;
      while(*line && !ISSPACE(*line) && !ISSEP(*line))
        line++;
      /* ... and has ended here */

      if(*line)
        *line++ = '\0'; /* zero terminate, we have a local copy of the data */

#ifdef DEBUG_CONFIG
      fprintf(stderr, "GOT: %s\n", option);
#endif

      /* pass spaces and separator(s) */
      while(*line && (ISSPACE(*line) || ISSEP(*line)))
        line++;

      /* the parameter starts here (unless quoted) */
      if(*line == '\"') {
        /* quoted parameter, do the quote dance */
        line++;
        param = malloc(strlen(line) + 1); /* parameter */
        if(!param) {
          /* out of memory */
          Curl_safefree(aline);
          rc = 1;
          break;
        }
        alloced_param = TRUE;
        (void)unslashquote(line, param);
      }
      else {
        param = line; /* parameter starts here */
        while(*line && !ISSPACE(*line))
          line++;
        *line = '\0'; /* zero terminate */
      }

      if(param && !*param) {
        /* do this so getparameter can check for required parameters.
           Otherwise it always thinks there's a parameter. */
        if(alloced_param)
          Curl_safefree(param);
        param = NULL;
      }

#ifdef DEBUG_CONFIG
      fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
#endif
      res = getparameter(option, param, &usedarg, config);

      if(param && *param && !usedarg)
        /* we passed in a parameter that wasn't used! */
        res = PARAM_GOT_EXTRA_PARAMETER;

      if(res != PARAM_OK) {
        /* the help request isn't really an error */
        if(!strcmp(filename, "-")) {
          filename = (char *)"<stdin>";
        }
        if(PARAM_HELP_REQUESTED != res) {
          const char *reason = param2text(res);
          warnf(config, "%s:%d: warning: '%s' %s\n",
                filename, lineno, option, reason);
        }
      }

      if(alloced_param)
        Curl_safefree(param);

      Curl_safefree(aline);
    }
    if(file != stdin)
      fclose(file);
  }
  else
    rc = 1; /* couldn't open the file */

  return rc;
}
Пример #11
0
double  DosLifetimeSpline::Lifetimebroadening(double E){
  //calculate Lifetime broadening in eV according to Egerton 2007
  //E is the energy in eV above the onset

    const double dEmin=this->getdispersion(); //the minimum energy step is the dispersion
    const double dEmax=100.0; //maximum lifetime broadening, more doesn't make sense
    const double epsilon=E;
    const double h=4.13566733e-15; //eV/s
    const double m0=9.10938188e-31; //electron mass in kg
    const double e=1.60217646e-19; //electron charge (C)
    const double m=m0;
    const Parameter* aptr=getparameter(2);
    const double a=aptr->getvalue(); //atomic diameter in nm
    double lambda=0.0;
    double v=0.1;

    double tau=0.0;
    const double pi=acos(-1.0);
    const Parameter* Estartptr= getparameter(0);
    const double Estart=Estartptr->getvalue();
    const Parameter* Estopptr= getparameter(1);
    const double Estop=Estopptr->getvalue();
    //#ifdef COMPONENT_DEBUG
    //  std::cout <<"Z="<<Z<<" rho="<<rho<<" \n";
    //#endif
    broadeningtype=CONSTANT;
    if (aptr->getname()=="Linear coefficient") broadeningtype=LINEAR;
    if (aptr->getname()=="Quadratic coefficient") broadeningtype=QUADRATIC;
    if (aptr->getname()=="Egerton Broadening atomic distance [nm]") broadeningtype=EGERTON;
    if (a==0.0) broadeningtype=CONSTANT;
    double dE;

switch(broadeningtype)
{
    case EGERTON:
        //Egerton broadening
        if (epsilon>this->getdispersion()){
            v=sqrt(2.0*e*epsilon/m); //speed
        }
        lambda=538.0*fabs(a)*pow(fabs(epsilon),-2.0)+0.41*pow(fabs(a),3.0/2.0)*sqrt(fabs(epsilon));
        tau=lambda*1e-9/v; //lifetime in seconds
        //#ifdef COMPONENT_DEBUG
        //std::cout <<"v="<<v<<" tau="<<tau<<" lambda"<<lambda<<" a="<<a<<" \n";
        //#endif

        dE=h/(2.0*pi*tau);
        //if dE lower than dispersion or E< Eonset
       break;
    case QUADRATIC:
        //Quadratic broadening
        dE=fabs(a)*pow(fabs(epsilon),2.0); // a simple quadratic broadening
        //check for infinity
        break;
    case LINEAR:
        //broadening linear with energy above onset
         dE=fabs(a)*fabs(epsilon); // a simple linear broadening
         break;
    case CONSTANT:
    default:
        dE=(Estart-Estop)/degree;
        break;
}

if (dE<dEmin){
    dE=dEmin;
}
if (E<=0){
    dE=dEmin;
}
if (dE>dEmax){
    dE=dEmax;
}

//#ifdef COMPONENT_DEBUG
//std::cout <<"Returning a lifetime broadening of dE="<<dE<<"for energy E="<<E<<"\n";
//#endif
return dE;
}
Пример #12
0
void DosLifetimeSpline::calculate()
{
  if (!checkxsection()) return; //if a problem with the cross section we are pointing to, stop calculating
  //get the parameters
  const Parameter* Estartptr= getparameter(0);
  const double Estart=Estartptr->getvalue();
  const Parameter* Estopptr= getparameter(1);
  const double Estop=Estopptr->getvalue();
   const Parameter* aptr= getparameter(2);


  //calculate the DOS
  Parameter* pointptr=0; //pointer to a datapoint in the list
  bool changes=false;
  for (size_t index=0;index<degree;index++){
    pointptr=getparameter(index+3);
    changes=(changes||pointptr->changed()); //see if any of the data point parameters has changed
   }
  if ((Estartptr->changed()||Estopptr->changed())||aptr->changed()){
      //setup a new energy grid
    InitEnergy();
    changes=true;
  }
  if (changes){
    //if anything changed, we need to calculate, if not we leave without calculating
    #ifdef COMPONENT_DEBUG
    std::cout << "parameters changed calculating DOS \n degree: " << degree <<"\n";
    std::cout << "Estart: " << Estart <<"\n";
    std::cout << "Estop: " << Estop <<"\n";
    for (size_t index=0;index<degree;index++){
      std::cout<< " a" <<index<<" :"<<getparameter(index+3)->getvalue()<< "\n";
    }
    #endif


   //copy the parameter values in the spline vectors
    copyparameters();

    //calculate the spline parameters
    dospline();


    //do the evaluation
  for (size_t i=0; i<this->getnpoints();i++){
        const double en=this->getenergy(i);

        double cts=0.0;

        if ((en>Estart)&(en<Estop)){
          cts=seval(en);
        }
        if (en<=Estart){
            cts=0.0;
        }
        if (en>=Estop){
            cts=1.0;
        }
    this->setcounts(i,cts);
  }

  //set parameters as unchanged since last time we calculated
  this->setunchanged();

  }
  else{
#ifdef COMPONENT_DEBUG
    std::cout <<"parameters have not changed, i don't need to calculate again\n";
#endif
  }

}
Пример #13
0
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
{
  FILE *file;
  char filebuffer[512];
  bool usedarg = FALSE;
  int rc = 0;
  struct OperationConfig *operation = global->first;

  if(!filename || !*filename) {
    /* NULL or no file name attempts to load .curlrc from the homedir! */

#ifndef __AMIGA__
    char *home = homedir();    /* portable homedir finder */
    filename = CURLRC;   /* sensible default */
    if(home) {
      if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
        msnprintf(filebuffer, sizeof(filebuffer),
                  "%s%s%s", home, DIR_CHAR, CURLRC);

#ifdef WIN32
        /* Check if the file exists - if not, try CURLRC in the same
         * directory as our executable
         */
        file = fopen(filebuffer, FOPEN_READTEXT);
        if(file != NULL) {
          fclose(file);
          filename = filebuffer;
        }
        else {
          /* Get the filename of our executable. GetModuleFileName is
           * already declared via inclusions done in setup header file.
           * We assume that we are using the ASCII version here.
           */
          int n = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer));
          if(n > 0 && n < (int)sizeof(filebuffer)) {
            /* We got a valid filename - get the directory part */
            char *lastdirchar = strrchr(filebuffer, '\\');
            if(lastdirchar) {
              size_t remaining;
              *lastdirchar = 0;
              /* If we have enough space, build the RC filename */
              remaining = sizeof(filebuffer) - strlen(filebuffer);
              if(strlen(CURLRC) < remaining - 1) {
                msnprintf(lastdirchar, remaining,
                          "%s%s", DIR_CHAR, CURLRC);
                /* Don't bother checking if it exists - we do that later */
                filename = filebuffer;
              }
            }
          }
        }
#else /* WIN32 */
        filename = filebuffer;
#endif /* WIN32 */
      }
      Curl_safefree(home); /* we've used it, now free it */
    }

# else /* __AMIGA__ */
    /* On AmigaOS all the config files are into env:
     */
    filename = "ENV:" CURLRC;

#endif
  }

  if(strcmp(filename, "-"))
    file = fopen(filename, FOPEN_READTEXT);
  else
    file = stdin;

  if(file) {
    char *line;
    char *aline;
    char *option;
    char *param;
    int lineno = 0;
    bool dashed_option;

    while(NULL != (aline = my_get_line(file))) {
      int res;
      bool alloced_param = FALSE;
      lineno++;
      line = aline;

      /* line with # in the first non-blank column is a comment! */
      while(*line && ISSPACE(*line))
        line++;

      switch(*line) {
      case '#':
      case '/':
      case '\r':
      case '\n':
      case '*':
      case '\0':
        Curl_safefree(aline);
        continue;
      }

      /* the option keywords starts here */
      option = line;

      /* the option starts with a dash? */
      dashed_option = option[0]=='-'?TRUE:FALSE;

      while(*line && !ISSPACE(*line) && !ISSEP(*line, dashed_option))
        line++;
      /* ... and has ended here */

      if(*line)
        *line++ = '\0'; /* zero terminate, we have a local copy of the data */

#ifdef DEBUG_CONFIG
      fprintf(stderr, "GOT: %s\n", option);
#endif

      /* pass spaces and separator(s) */
      while(*line && (ISSPACE(*line) || ISSEP(*line, dashed_option)))
        line++;

      /* the parameter starts here (unless quoted) */
      if(*line == '\"') {
        /* quoted parameter, do the quote dance */
        line++;
        param = malloc(strlen(line) + 1); /* parameter */
        if(!param) {
          /* out of memory */
          Curl_safefree(aline);
          rc = 1;
          break;
        }
        alloced_param = TRUE;
        (void)unslashquote(line, param);
      }
      else {
        param = line; /* parameter starts here */
        while(*line && !ISSPACE(*line))
          line++;

        if(*line) {
          *line = '\0'; /* zero terminate */

          /* to detect mistakes better, see if there's data following */
          line++;
          /* pass all spaces */
          while(*line && ISSPACE(*line))
            line++;

          switch(*line) {
          case '\0':
          case '\r':
          case '\n':
          case '#': /* comment */
            break;
          default:
            warnf(operation->global, "%s:%d: warning: '%s' uses unquoted "
                  "white space in the line that may cause side-effects!\n",
                  filename, lineno, option);
          }
        }
        if(!*param)
          /* do this so getparameter can check for required parameters.
             Otherwise it always thinks there's a parameter. */
          param = NULL;
      }

#ifdef DEBUG_CONFIG
      fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
#endif
      res = getparameter(option, param, &usedarg, global, operation);

      if(!res && param && *param && !usedarg)
        /* we passed in a parameter that wasn't used! */
        res = PARAM_GOT_EXTRA_PARAMETER;

      if(res == PARAM_NEXT_OPERATION) {
        if(operation->url_list && operation->url_list->url) {
          /* Allocate the next config */
          operation->next = malloc(sizeof(struct OperationConfig));
          if(operation->next) {
            /* Initialise the newly created config */
            config_init(operation->next);

            /* Copy the easy handle */
            operation->next->easy = global->easy;

            /* Set the global config pointer */
            operation->next->global = global;

            /* Update the last operation pointer */
            global->last = operation->next;

            /* Move onto the new config */
            operation->next->prev = operation;
            operation = operation->next;
          }
          else
            res = PARAM_NO_MEM;
        }
      }

      if(res != PARAM_OK && res != PARAM_NEXT_OPERATION) {
        /* the help request isn't really an error */
        if(!strcmp(filename, "-")) {
          filename = "<stdin>";
        }
        if(res != PARAM_HELP_REQUESTED &&
           res != PARAM_MANUAL_REQUESTED &&
           res != PARAM_VERSION_INFO_REQUESTED &&
           res != PARAM_ENGINES_REQUESTED) {
          const char *reason = param2text(res);
          warnf(operation->global, "%s:%d: warning: '%s' %s\n",
                filename, lineno, option, reason);
        }
      }

      if(alloced_param)
        Curl_safefree(param);

      Curl_safefree(aline);
    }
    if(file != stdin)
      fclose(file);
  }
  else
    rc = 1; /* couldn't open the file */

  return rc;
}
Пример #14
0
//-----------------------------------------------------------------------------------------
void gsBEncoder::getParameterDisplay (VstInt32 index, char* text)
{
	double val;
	getparameter(gen, index, &val);
	float2string((float)val, text, kVstMaxParamStrLen);
}
Пример #15
0
//-----------------------------------------------------------------------------------------
float gsBEncoder::getParameter (VstInt32 index)
{
	double val;
	getparameter(gen, index, &val);
	return (float)val;
}
Пример #16
0
void Plasmon::calculate()
{
//check if any of paramters is changed, if not : don't calculate

const Parameter* EZLptr= getparameter(0);
const double EZL=EZLptr->getvalue();

const Parameter* fwhmZLptr= getparameter(1);
const double fwhmZL=fwhmZLptr->getvalue();
const Parameter* heightZLptr= getparameter(2);
const double heightZL=heightZLptr->getvalue();

const Parameter* EPptr= getparameter(3);
const double EP=EPptr->getvalue();
const Parameter* fwhmPptr= getparameter(4);
const double fwhmP=fwhmPptr->getvalue();

const Parameter* tlambdaptr= getparameter(5);
const double tlambda=tlambdaptr->getvalue();

const Parameter* dnoiseptr= getparameter(6);
const double dnoise=dnoiseptr->getvalue();


const bool changes=EZLptr->changed()||fwhmZLptr->changed()||heightZLptr->changed()||EPptr->changed()||fwhmPptr->changed()||tlambdaptr->changed()||dnoiseptr->changed();

if (changes)
{
  #ifdef COMPONENT_DEBUG
    std::cout << "parameters changed calculating plasmon model again \n";
  #endif

  //const double en0=this->getenergy(0);
  //set parameters of all lorentz peaks
  //the ZL peak
  Parameter* p=peaklist[0]->getparameter(0);
  p->setvalue(EZL);
  p=peaklist[0]->getparameter(1);
  p->setvalue(fwhmZL);
  p=peaklist[0]->getparameter(2);
  p->setvalue(heightZL);
  peaklist[0]->calculate();
  const double ZLarea=peaklist[0]->getarea();


  //the plasmon peaks
  const int nrofpeaks=peaklist.size();
  for (int index=1;index<nrofpeaks;index++){
    Lorentz* lptr=peaklist[index];

    Parameter* posptr=lptr->getparameter(0);
    Parameter* fwhmptr=lptr->getparameter(1);
    Parameter* heightptr=lptr->getparameter(2);
    posptr->setvalue(EZL+EP*double(index)); //the plasmon position
    fwhmptr->setvalue(fwhmP);
    heightptr->setvalue(1.0); //set to one first to get area of a lorentz with these parameters
    lptr->calculate();
    const double area=lptr->getarea();
    //calculate height
    double height=ZLarea/(area*poissonfraction(tlambda,index));
    heightptr->setvalue(height); //now set to right height
    lptr->calculate();
  }

  //add them to get the total model
  for (unsigned int i=0;i<(this->getnpoints());i++)
  {
      //double en=this->getenergy(i);
      double cts=dnoise+peaklist[0]->getcounts(i);
      for (int index=1;index<nrofpeaks;index++){
        cts+=peaklist[index]->getcounts(i);
      }
      this->setcounts(i,cts);
  }


  //set parameters as unchanged since last time we calculated
  this->setunchanged();
}
else
{
  #ifdef COMPONENT_DEBUG
    std::cout <<"parameters have not changed, i don't need to calculate again\n";
  #endif
}

}
Пример #17
0
void SpinsplitEdge::calculate(){
  //get the parameters
  const Parameter* E0ptr= getparameter(0);
  const double E0=E0ptr->getvalue();
  const Parameter* Ekptr= getparameter(1);
  const double Ek=Ekptr->getvalue();
  const Parameter* thetastepptr= getparameter(3);
  const double thetasteps=thetastepptr->getvalue();
  const Parameter* thetamaxptr= getparameter(4);
  const double thetamax=thetamaxptr->getvalue();
  const Parameter* strengthptr= getparameter(5);
  const double strength=strengthptr->getvalue();
  const Parameter* Esplitptr= getparameter(6);
  const double Esplit=Esplitptr->getvalue();
  const Parameter* ratioptr= getparameter(7);
  const double ratio=ratioptr->getvalue();
  const Parameter* wstrengthptr= getparameter(8);
  const double wstrength=wstrengthptr->getvalue();
  const Parameter* fwhmptr= getparameter(9);
  const double fwhm=fwhmptr->getvalue();
  const Parameter* gapstartptr= getparameter(10);
  const double gapstart=gapstartptr->getvalue();
   const Parameter* gapendptr= getparameter(11);
  const double gapend=gapendptr->getvalue();

  #ifdef COMPONENT_DEBUG
  std::cout<<"Calculating spin split edge\n";
  std::cout<<"E0="<<E0<<" Ek="<<Ek<<" thetasteps="<<thetasteps<<" thetamax="<<thetamax<<"strength="<<strength<<"\n";
  std::cout<<"Esplit="<<Esplit<<" ratio="<<ratio<<" wstrength="<<wstrength<<" fwhm="<<fwhm<<" gapstart="<<gapstart<<" gapend="<<gapend<<"\n";

  #endif


  //recalculate subparts if parameters have changed
    //update the internal parameters for these models


    if (E0ptr->changed()) (continuum1->getparameter(0))->setvalue(E0);
    if (Ekptr->changed()) (continuum1->getparameter(1))->setvalue(Ek);
    if (thetastepptr->changed()) (continuum1->getparameter(3))->setvalue(thetasteps);
    if (thetamaxptr->changed()) (continuum1->getparameter(4))->setvalue(thetamax);
    if (strengthptr->changed()||ratioptr->changed()) (continuum1->getparameter(5))->setvalue(strength/(1.0+ratio));



    if (E0ptr->changed()) (continuum2->getparameter(0))->setvalue(E0);
    if (Ekptr->changed()||Esplitptr->changed()) (continuum2->getparameter(1))->setvalue(Ek+Esplit);
    if (thetastepptr->changed()) (continuum2->getparameter(3))->setvalue(thetasteps);
    if (thetamaxptr->changed()) (continuum2->getparameter(4))->setvalue(thetamax);
    if (strengthptr->changed()||ratioptr->changed()) (continuum2->getparameter(5))->setvalue(strength*ratio/(1.0+ratio));




    continuum1->calculate();
    continuum2->calculate();


    if (Ekptr->changed()) (whiteline1->getparameter(0))->setvalue(Ek);
    if (fwhmptr->changed()) (whiteline1->getparameter(1))->setvalue(fwhm);
    if (wstrengthptr->changed()) (whiteline1->getparameter(2))->setvalue(wstrength);

    if (Ekptr->changed()||Esplitptr->changed()) (whiteline2->getparameter(0))->setvalue(Ek+Esplit);
    if (fwhmptr->changed()) (whiteline2->getparameter(1))->setvalue(fwhm);
    if (wstrengthptr->changed()||ratioptr->changed()) (whiteline2->getparameter(2))->setvalue(wstrength*ratio);
    whiteline1->calculate();
    whiteline2->calculate();
    //add up the different components
    for (size_t i=0;i<this->getnpoints();i++){
      double cts=0.0;
      const double en=this->getenergy(i);
      if ((Ek+Esplit+gapstart<=en)&&(Ek+Esplit+gapend>en)){
        //continuum2 gap
         cts=continuum1->getcounts(i)+whiteline1->getcounts(i)+whiteline2->getcounts(i);
      }
      else
      {
         if ((Ek+gapstart<=en)&&(Ek+gapend>en)){
           //continuum1 gap
           cts=continuum2->getcounts(i)+whiteline1->getcounts(i)+whiteline2->getcounts(i);
         }
         else{
          //no gap
           cts=continuum1->getcounts(i)+continuum2->getcounts(i)+whiteline1->getcounts(i)+whiteline2->getcounts(i);
         }
      }
      this->setcounts(i,cts);
    }
    this->setunchanged();
    return;
}