Created
March 17, 2013 14:00
-
-
Save danko3/5181627 to your computer and use it in GitHub Desktop.
Plotfile creator. It creates a two dimensional array of a normal distribution or a sinc function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; quick and dirty testfile creator | |
; it produces a two dimensional square array of values. | |
; two functions can be selected: | |
; a sinc and a normal distribution. | |
#SingleInstance force ; If it is alReady Running it will be restarted. | |
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
SetTitleMatchMode,2 ; string somewhere in titel is ok. | |
SetTitleMatchMode,fast ; makes window recognition more reliable | |
DetectHiddenWindows, On | |
SetKeyDelay,0 | |
;MsgBox, d= %A_ScriptFullPath% | |
size = 643 ; <---- edit! 100 x 100 array | |
xmin = -20 ; <---- edit! function range (~20 for sinc) | |
xmax = 20 ; <---- edit! function range (~1 for normal) | |
func = sinc ; <---- edit! 'sinc' or 'normal' | |
sd = 0.3 ; standard deviation | |
pi = 3.14159265 | |
xdif := xmax - xmin | |
xstep := xdif/size | |
; filename is [func][size].csv | |
Datafile := func . size . .csv | |
file := FileOpen(DataFile, "w") ; open a file for writing | |
if !file | |
MsgBox,16,Error: %A_LastError%, Datafile not created | |
Encoding := File.Encoding | |
loop, %size% | |
{ | |
y := A_Index | |
yg := A_Index*xstep+(xmin-xstep/2) | |
loop, %size% | |
{ | |
x := A_Index | |
xg := A_Index*xstep+(xmin-xstep/2) | |
q := sqrt(xg**2+yg**2) | |
if func = sinc | |
z := sinc(q) | |
if func = normal | |
z := normal(q) | |
if (x=size) | |
File.WriteLine(z) | |
else | |
File.Write(z ",") | |
} | |
} | |
File.Close() | |
return | |
; | |
; Math Functions | |
; | |
normal(q) | |
{ | |
z := (1/sqrt(2*pi*sd))*exp(-0.5*((q/sd)**2)) ; create a normal distribution | |
return, z | |
} | |
sinc(q) | |
{ | |
if q<>0 | |
z:= sin(q)/q ; create a sinc function | |
else | |
z = 1 | |
return, z | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment