{ Example shows how to perform a fit in a measurement script
  you need two .dat files (IRF.dat and Decay.dat).
  Set the BaseDataPath to the directory with these two files.

  IRF.dat and Decay.dat are produced using the Plot function
  (Plot a single curve export as ASCII without metadata/column captions
  '.' as decimal separator and TAB as column separator)
}

def
  C: Curve;
  i: Int;
  Value: Float;
  Str: String;
  BaseDataPath: String;
exec
  BaseDataPath = "D:\ETDaten\";
  DeleteAllCurves;
  ClearAllFits;

  C.NumPoints = 1; // neded to initialize the curve before loading curve
  ImportASCII(C, BaseDataPath + "IRF.dat");
  StoreAsDecay(C);

  ImportASCII(C, BaseDataPath + "Decay.dat");
  StoreAsDecay(C);

  // initialize Fit as Exponential Reconvolution Fit
  InitFitEntry(0, ExponentialReconvolution);
  // initialize Fit as Exponential Tail Fit
  //InitFitEntry(0, ExponentialTailFit);

  FitSetCurve(0, crv[1]); // must be done before SetValues
  FitSetIRF(0, crv[0]); // set IRF for this fit if its an Reconvolution fit
  // set the number of exponentials
  FitSetValue(0, "n_Exp", 1);
  // shows how to preset a start value
  //FitSetValue(0, "tau_1", 1);
  // shows how to fix a parameter
  //FitSetFixed(0, "tau_1", TRUE);
  //
  FitStart(0); // perform the fit
  //
  // Get individual parameters
  // identifiers for this calls can you find the the output of FitGetResult()
  Value = 0;
  FitGetValue(0, "tau_1", Value);
  Str = "found lifetime " + Value;
  FitGetValue(0, "A_1", Value);
  View(Str / "found Amplitude: " + Value);

  // how to get all fit paramters as string to show or save
  Str = "";
  FitGetResult(0, TRUE, Str);  // gest result with all curves (Raw + fit curve)
  WriteStringToFile(BaseDataPath + "FitResult.txt", Str); // write the result to a file
  //
  FitGetResult(0, FALSE, Str); // get only the fit parameter (without the curves)
  View(Str);  // show the fit result to user
end.