{ Measure Intensity TimeTrace for 4 Sample holder
 check HTML Help file for this script for more informations }

{ block of variable definitions }
def
  C1: Curve;
  C2: Curve;
  C3: Curve;
  C4: Curve;
  MeasTime: Float;
  TimeStep: Float;
  NumMeas: Int;
  StartTime: Int;
  i: Int;
  j: Int;
  s: String;
  Intensity: Int;
  RealWait: Float;
exec
  { >> set the script aqusition parameters HERE << }
  Sample    = "TestSample";  // Sample name
  Solvent   = "undefined";   // Solvent name
  Container = "MultiIntensityTrace";    // Name of the file to create
  //
  MeasTime = 1.0; // time to measure every sample in seconds
  TimeStep = 20.0; // Measure every xxx seconds (must be >> 4 * MeasTime!)
  NumMeas = 10; // Number of Measurements
  { >> end set parameter, start of measurement << }

  DETECTOR_1.DETShutterPos = FALSE;
  C1.NumPoints = NumMeas;
  C2.NumPoints = NumMeas;
  C3.NumPoints = NumMeas;
  C4.NumPoints = NumMeas;
  StartTime = GetTickCount;
  SAMPLE_CHANGER.SMPPos = 1;
  for i = 0 to NumMeas - 1 step 1
    C1.x[i] = i * TimeStep;
    C2.x[i] = C1.x[i];
    C3.x[i] = C1.x[i];
    C4.x[i] = C1.x[i];
    // the actual 4 way measurement
    s = "Intensities: ";
    for j = 1 to 4 step 1
      SAMPLE_CHANGER.SMPPos = j;
      Intensity = 0;
      DETECTOR_1.DETShutterPos = TRUE;
      MeasIntensity(MeasTime, Intensity);
      s = s + j + ": " + Intensity + "  ";
      DETECTOR_1.DETShutterPos = FALSE;
      // save the Intensity
      if j == 1 then C1.y[i] = Intensity; end;
      if j == 2 then C2.y[i] = Intensity; end;
      if j == 3 then C3.y[i] = Intensity; end;
      if j == 4 then C4.y[i] = Intensity; end;
      DisplayStatus("Measurement " + (i + 1) + " / " + NumMeas + ". " + s);
    end;
    // Plot Result
    C1.Valid[i] = TRUE;
    C2.Valid[i] = TRUE;
    C3.Valid[i] = TRUE;
    C4.Valid[i] = TRUE;
    Plot(C1, 0);
    Plot(C2, 1);
    Plot(C3, 2);
    Plot(C4, -3);
    // back to sample 1 again
    SAMPLE_CHANGER.SMPPos = 1;
    if i < (NumMeas - 1) then
      // calculate how long to wait for next measurement
      RealWait = (StartTime /1000) + ((i + 1) * TimeStep) - (GetTickCount / 1000);
      DisplayStatus("Wait " + RealWait + " s for measurement " + (i + 2) + " / " + NumMeas + ". " + s);
      Delay(RealWait);
    end;
  end;
  { >> end of measurement, start of saving part << }
  Comment = "Sample in Position 1";
  StoreAsArbitrary(C1);
  Comment = "Sample in Position 2";
  StoreAsArbitrary(C2);
  Comment = "Sample in Position 3";
  StoreAsArbitrary(C3);
  Comment = "Sample in Position 4";
  StoreAsArbitrary(C4);
  SaveToWorkspace(Container);
end.