Notebook to Aid in Mossbauer Data Processing for Experiment 28

Instructions: Use this notebook to enter Mossbauer Data

Needs["CurveFit`"];

Initialization Section... This section executes when you use the notebook.

Off[General::"spell1"];

The Global Data

MossData : The Processed Mosbauer Data Array,an array of data triples: 
    {velocity(mm/sec), rate(1/sec), sigma(1/sec), counts, time (sec)}.
    (this array will be maintained by the fwd[],bkwd[], and zero[] functions)

MossData = {}

LastData={}   (* The last entry made in MossData *)

dist : The distance the absorber travels (mm).
Change this value using SetDist[ ]:

dist=Abs[
31.5       (* First limit of travel (mm) *)
-
8.0       (* Other limit of travel (mm) *)
]

The Data Entry Functions

This function is called by fwd[] and bkwd[] to maintain CurveFit's data arrays

ToCurvefitData[values_]:=
Module[{i},
(* n, xx, yy, sy, sx are Curvefit variables *)
n=Length[values];xx={};yy={};sy={};sx={};
For[i=1,i≤n,i++,
xx=Append[xx,values[[i,1]]];
yy=Append[yy,values[[i,2]]];
sy=Append[sy,values[[i,3]]];
sx=Append[sx,0];
]
]

fwd[] : Call this function to add a data value for the forward (plus) direction of the absorber:

fwd[counts_ , time_ (* Total counts, Time (sec) *)]:=
Module[
{datum=
{dist/Abs[time],Abs[counts/time],Abs[Sqrt[Abs[counts]]/time], Abs[counts], Abs[time]}
},
LastData=datum;
MossData=Union[MossData,{datum}];
ToCurvefitData[MossData];
alldata
]

bkwd[] : Call this function to add a data value for the backward (minus) direction of the absorber:

bkwd[counts_ , time_ (* Total counts, Time (sec) *)]:=
Module[
{datum=
{- dist/Abs[time],Abs[counts/time],Abs[Sqrt[Abs[counts]]/time], Abs[counts], Abs[time]}
},
LastData=datum;
MossData=Union[MossData,{datum}];
ToCurvefitData[MossData];
alldata
]

zero[] : Call this function to add a data value for a zero-velocity data point:

zero[counts_ , time_ (* Total counts, Time (sec) *)]:=
Module[
{datum=
{0.0,Abs[counts/time],Abs[Sqrt[Abs[counts]]/time], Abs[counts], Abs[time]}
},
LastData=datum;
MossData=Union[MossData,{datum}];
ToCurvefitData[MossData];
alldata
]

SetDist[] : Call this function to change the distance value and correctly update MossData and CurveFit:

SetDist[d_]:=
If[d>0,
Module[{i},
For[i=1,i≤Length[MossData],i++,
MossData[[i]]*={1.0 d/dist,1,1,1,1};
];
ToCurvefitData[MossData];
If[Length[LastData]>0,LastData *={1.0 d/dist,1,1,1,1}];
dist =d],
Print["Set the distance to a positive value!"],
Print["Set the distance to a positive value!"]
]

MossData Data Manipulation/Editing Functions

alldata : Return MossData in TableForm format, with headings

alldata:= TableForm[
Join[{
{"V (mm/sec)","Rate (1/sec)","sigma (1/sec)","Counts","Time (sec)"},
{"----------","------------","-------------","------","----------"}
},MossData]
]

entry[] : Find a data entry with the given counts and time

entry[counts_ , time_ (* Total counts, Time (sec) *)]:=Module[{data=Select[MossData,(#1[[4]]==Abs[counts] && #1[[5]]==Abs[time]&),1]},
If[Length[data]>0,data[[1]],{}]
]

rmdata[element] : Remove the provided element from MossData

rmdata[element_ (* element to be removed *)]:=
Module[{},
MossData=Complement[MossData, {element}];
ToCurvefitData[MossData];
alldata
]

Summary of the defined variables and functions:

MossData : 
global list variable; maintained by the functions fwd[], bkwd[], zero[], and SetDist[].
The elements of MossData are lists of the form:
{speed (mm/sec), rate (counts/sec), sigma (counts/sec), counts, time (sec)}

SetDist[distance (mm)] :
function; sets or changes the distance the absorber travels. Updates both MossData and the CurveFit data sets.

fwd[counts, time (sec)] :
function; adds a data point for travel in the forward (+) direction. Updates both MossData and the CurveFit data sets.

bkwd[counts, time (sec)] :
function; adds a data point for travel in the backward (-) direction. Updates both MossData and the CurveFit data sets.

zero[counts, time (sec)] :
function; adds a zero-velocity data point. Updates both MossData and the CurveFit data sets.

LastData : 
global variable; contains the last data element inserted into MossData by one of the functions fwd[], bkwd[], and zero[]. LastData is a list of the form:
{speed (mm/sec), rate (counts/sec), sigma (counts/sec), counts, time (sec)}

alldata : 
this "function" takes no arguments; executing alldata returns the contents of MossData as a table with headings.

entry[counts, time (sec)] :
function; finds an entry (element) in MossData with the specified counts and time, if it exists. The returned value is a list of the form (a null list is returned if no entry could be found):
{speed (mm/sec), rate (counts/sec), sigma (counts/sec), counts, time (sec)}

rmdata[entry] :
function; removes the specified entry (element) from MossData and the CurveFit data sets. the specified entry should be a list as returned by entry[] or LastData.

Here Are a Couple of Calls to the data entry functions. You should replace these lines with your own commands to enter the data you take.

(* Empty the Mossbauer data set *)
MossData = {}

(* Set or change the distance the absorber travels (in mm) *)
SetDist[31.5-8.0]

(* Add a forward measurement *)
fwd[38529,141.000];

(* Add a backward measurement *)
bkwd[36976,140.696];

(* Display the data so far *)
alldata

(* Here's the last data entry made *)
LastData

(* Here's how to remove data points, in case you make a mistake *)
rmdata[LastData];
(* or *)
rmdata[entry[38529,141]];

(* Now there should be no remaining data *)
alldata

You can enter your own data and commands following this line.

(* Your commands *)