Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created July 11, 2016 03:18
Show Gist options
  • Save mikeobrien/34b76d4da1aeabe5063f992179728e9b to your computer and use it in GitHub Desktop.
Save mikeobrien/34b76d4da1aeabe5063f992179728e9b to your computer and use it in GitHub Desktop.
Thin Film Measurement Proof of Concept
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Series;
namespace GraphingTests
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class ElementData
{
public int Wavelength { get; set; }
public double IndexOfRefraction { get; set; }
}
public class Spectrum
{
public double Wavelength { get; set; }
public double Reflectance { get; set; }
}
private List<ElementData> _sio2Data;
private PlotModel _model;
private LineSeries _lineSeries;
private void Form1_Load(object sender, EventArgs e)
{
var spectrum = File.ReadAllLines(@"D:\Documents\Projects\Semiconductor Processing\Reflectance Spectrums\0-15.txt")
.Skip(14).Where(x => !string.IsNullOrEmpty(x))
.Select(x => x.Split('\t')).Where(x => !x[1].Contains("-")).Select(x => new Spectrum
{
Wavelength = double.Parse(x[0]),
Reflectance = Math.Min(double.Parse(x[1]), 120)
}).ToList();
var min = spectrum.Min(x => x.Wavelength);
var max = spectrum.Max(x => x.Wavelength);
_sio2Data = File.ReadAllLines(@"D:\Documents\Projects\Semiconductor Processing\SiO2.txt")
.Skip(1).Where(x => !string.IsNullOrEmpty(x))
.Select(x => x.Split('\t')).Select(x => new ElementData
{
Wavelength = int.Parse(x[0]),
IndexOfRefraction = double.Parse(x[1])
}).Where(x => x.Wavelength > min && x.Wavelength < max).ToList();
_model = new PlotModel { Title = "Example 1" };
var series = new LineSeries();
spectrum.ForEach(x => series.Points.Add(new DataPoint(x.Wavelength, x.Reflectance)));
_model.Series.Add(series);
Recalc();
plot1.Model = _model;
}
// 79.9 nm
private double CallContext(int wavelength, double indexOfRefraction)
{
var offset = (double)Offset.Value; // A
var amplitude = (double)Amplitude.Value; // B
var depth = (double)Thickness.Value;
var result = offset + amplitude * Math.Cos((2 * Math.PI * indexOfRefraction * depth) / wavelength);
return result;
}
public void Recalc()
{
if (_model.Series.Contains(_lineSeries)) _model.Series.Remove(_lineSeries);
_lineSeries = new LineSeries();
_sio2Data.ForEach(x => _lineSeries.Points.Add(new DataPoint(x.Wavelength, CallContext(x.Wavelength, x.IndexOfRefraction))));
_model.Series.Add(_lineSeries);
_model.InvalidatePlot(true);
}
private void Offset_ValueChanged(object sender, EventArgs e)
{
Recalc();
}
private void Amplitude_ValueChanged(object sender, EventArgs e)
{
Recalc();
}
private void Thickness_ValueChanged(object sender, EventArgs e)
{
Recalc();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment