Titel:

NMR Studies in Hexaborides Diplomarbeit in experimenteller Festkörperphysik.

Startseite
english
  
ISBN: 354085794X   ISBN: 354085794X   ISBN: 354085794X   ISBN: 354085794X 
 
  Wir empfehlen:       
  next up previous contents
Next: Additional Figures Up: Fitting Spectra Previous: Simulating Spectra

External ProFit Modules

Our data analysis and fitting program, ProFit provides a special language to write fitting functions with. For most purposes this language is fast enough, but not for spectra. ProFit therefore offers the possibility of writing functions in a faster language such as C++ or ObjectPascal. We are going to have a look at an example written in C++ (with no use of any object oriented features). The developpement environnement is Metrowerks Code Warrior.

ProFit makes some interface files available to the programmer which provides the code and headers needed to write a function which is accepted by ProFit. The file proFit_interface.c is the glue for interfacing with ProFit. The files proFit_interface.h and proFit_paramBlk.h are the header files providing the fitting parameters and the memory for the dialog box to our function. These files have to be placed in the project and in the project directory. The project file of a common ProFit function then has the entries

sources: specfit.c
  proFit_interface.c
ANSI Libraries: MSL C.PPC.Lib
  MSL C++.PPC.Lib
  MSL SIOUX.PPC.Lib
Mac Libraries: IntefaceLib
  Mathlib
  MSL RuntimePPC.Lib

The file specfit.c contains our code. Some parts of it are shown below. For further details please see [#!proFit!#].

It is of great importance that some special functions are supported by our program and that they are exported with the names ProFit is looking for. To make these names visible from outside, they have to be exported by the linker. For that reason the linker settings have to be:

PPC Linker generate SYM file
  full path in SYM file
  generate link map
PPC PEF export symbols: use #pragma
Te important parts of the program can be found in the listing below. The complete source code is available on B22 G3 or on the NMR server.

/***************************************************************************************/
/* specfit.c based on FunctionTemplate.c */
/***************************************************************************************/
 
#include "proFit_interface.h"
#include <math.h>
 
#define Pi 3.1415926535
#define max_ind 10000
#define nr_of_spins 1000
 
double bins[max_ind]; /*The bins can't be local since the locally available memory is
restricted to 32kB*/
 
/***************************************************************************************/
 
void SetUp ( ... )
/* SetUp is called once when the external module is linked to proFit */
{
*moduleKind=isFunction; /* we define a function */
SetPascalStr(name," $\backslash$pSpecFit 3/2",255); /* write its name here */
...
}
 
/***************************************************************************************/
 
void InitializeFunc( ... )
/* InitializeFunc is called once (after SetUp has been called) when the external module
is linked to proFit. Used to set all the information needed to describe a function
and to set up the parameter window. */
{
SetPascalStr(descr1stLine," $\backslash$pSpectrum for spin 3/2 atoms",255);
SetPascalStr(descr2ndLine," $\backslash$puse with care... very experimental version (drau, 13.8.99)",255);
*numberOfParams = 7;
 
SetPascalStr((*a0->name)[0]," $\backslash$pnu_L0",maxParamNameLength);
(*a0->mode)[0] = active;
(*a0->value)[0] = 70965;
 
... }
 
/***************************************************************************************/
 
void First ( ParamArray a, /* the new parameters */
ExtModulesParamBlock* pb) /*the complete parameter block passed by pro Fit*/
/* Called whenever the parameters are changed. Can be used to accelerate */
/* some calculations. See manual for more info */
{
double nu_L0, nu_Q, nusq_Q, fstep;
double theta;
double musq, nu_m, factor2nd;
double factor1st;
int index;
double sinttau, ftausq, ftausq2, nu, nu_off, tau, width;
double weight;
 
nu_L0 = a[0];
nu_Q = a[1];
fstep = a[3];
tau = a[2];
width = a[5];
weight = a[6];
 
nusq_Q = nu_Q * nu_Q;
factor2nd = (-3) * nusq_Q / ( 16 * nu_L0 ) * 3;
 
ftausq = 4 * tau * tau * 4 * Pi * Pi;
 
for(index=0;index<max_ind;index++) bins[index] = 0;
 
/* calculate the second order perturbation of the central line */
 
for(theta = 0; theta < Pi; theta += Pi/nr_of_spins ){
 
musq = cos(theta); musq *= musq;
nu_m = factor2nd * (1 - musq ) * ( 9 * musq - 1 );
 
sinttau = sin(theta) * 2 * tau;
 
for(nu=-width;nu<width;nu+=fstep){
index = int( nu / fstep ) + max_ind / 2;
nu_off = nu_m - nu;
if(index>=0 && index < max_ind) bins[index] += sinttau / ( 1 + ftausq * nu_off * nu_off );
}
}
for( index = 0; index < 10000; index ++) bins[index] *= weight;
 
/* calculate the first order perturbation of the wings*/
 
...
 
for( index = 0; index < 10000; index ++) bins[index]*=a[4];
}
 
/***************************************************************************************/
 
void Func ( double x, /* the x-value */
ParamArray a, /* the parameters */
double* const y, /* the y-value to be returned */
ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit */
/* called to calculate the y-value of the function for a given x and a given set of
parameters */
{
int index;
double nu_off;
nu_off = ( x - a[0] ) / a[3] + max_ind / 2;
index = int( nu_off );
*y = 0;
if( 0 <= index && index < max_ind ) *y = bins[index];
}
 
/***************************************************************************************/
 
void Derivatives( ... )
/* called to calculate the partial derivatives of the function with respect to */
/* its parameters. The elements of the array "dyda[i]" must be set to the derivatives of*/
/* the function with respect to parameter number "i". If any dyda[i] is not set by */
/* this function, then the derivatives will be calculated numerically by pro Fit.*/
/* If you set hasDerivatives to false in FuncInitialize, then ALL derivatives will always */
/* be calcuated numerically by pro Fit, no matter what you do in the function "Derivatives" */
/* If a derivative is too complicated to be calculated analytically, then don't set the */
/* corresponding "dyda". pro Fit will notice this and calculate that derivative numerically. */
/* If you are able to calculate the dyda analytically, do so! By doing this you will make */
/* fitting much, much faster. */
{
 
}
 
...


next up previous contents
Next: Additional Figures Up: Fitting Spectra Previous: Simulating Spectra
  
Festkörperphysik: Einführung in die Grundlagen (Springer-Lehrbuch) (Taschenbuch)
von Hans L&th,
Harald Ibach
Siehe auch:
Einführung in die Festkörperphysik
Teilchen und Kerne: Eine Einführung in die physik...
Atom- und Quantenphysik: Einführung in die expe...
Festkörperphysik
Lehrbuch zur Theoretischen Physik: Statisti...
Grundkurs Theoretische Physik 5 / 2: Quanten...
 
   
 
     

Zurück zur Themenseite:
ScientificPublication.com/Startseite/Wissenschaft

Das Setzen von Verweisen (Links) auf diese Seite ist gestattet und bedarf keine vorherige Absprache.
   
  Startseite  |  english  |  Bookmark setzen  |  Webseite weiterempfehlen  |  Copyright ©  |  Impressum