Created
January 12, 2016 17:18
-
-
Save DustinMorado/fe6de4ffdd4aa47cfcd9 to your computer and use it in GitHub Desktop.
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
header_fmt = 'iii' -- nx, ny, nz | |
header_fmt = header_fmt .. 'i' -- mode | |
header_fmt = header_fmt .. 'iii' -- nxstart, nystart, nzstart | |
header_fmt = header_fmt .. 'iii' -- mx, my, mz | |
header_fmt = header_fmt .. 'fff' -- xlen, ylen, zlen | |
header_fmt = header_fmt .. 'fff' -- alpha, beta, gamma | |
header_fmt = header_fmt .. 'iii' -- mapc, mapr, maps | |
header_fmt = header_fmt .. 'fff' -- amin, amax, amean | |
header_fmt = header_fmt .. 'i' -- ispg | |
header_fmt = header_fmt .. 'i' -- Next | |
header_fmt = header_fmt .. 'h' -- CreateID | |
header_fmt = header_fmt .. 'hiiiiiii' -- Empty | |
header_fmt = header_fmt .. 'h' -- nint | |
header_fmt = header_fmt .. 'h' -- nreal | |
header_fmt = header_fmt .. 'iiiii' -- Empty | |
header_fmt = header_fmt .. 'ii' -- imodStamp, imodFlags | |
header_fmt = header_fmt .. 'h' -- idType | |
header_fmt = header_fmt .. 'h' -- lens | |
header_fmt = header_fmt .. 'hh' -- nd1, nd2 | |
header_fmt = header_fmt .. 'hh' -- vd1, vd2 | |
header_fmt = header_fmt .. 'ffffff' -- tiltAngles | |
header_fmt = header_fmt .. 'fff' -- xorg, yorg, zorg | |
header_fmt = header_fmt .. 'c4' -- MAP | |
header_fmt = header_fmt .. 'c4' -- DA | |
header_fmt = header_fmt .. 'f' -- RMS | |
header_fmt = header_fmt .. 'i' -- nlabl | |
header_fmt = header_fmt .. string.rep('c80', 10) -- labels | |
int_size = arg[1] | |
flt_size = int_size^1 | |
int_vol = int_size * int_size * int_size -- exponentiation converts to float | |
flt_vol = flt_size^3 | |
nx, ny, nz = int_size, int_size, int_size | |
mode = 0 | |
nxstart, nystart, nzstart = 0, 0, 0 | |
mx, my, mz = int_size, int_size, int_size | |
xlen, ylen, zlen = flt_size, flt_size, flt_size | |
alpha, beta, gamma = 90.0, 90.0, 90.0 | |
mapc, mapr, maps = 1, 2, 3 | |
amin, amax, amean = 0.0, 255.0, 255.0 / flt_vol | |
ispg = 0 | |
Next = 0 | |
CreateID = 0 | |
nint = 0 | |
nreal = 32 | |
imodStamp = 1146047817 | |
imodFlags = 0 | |
idType = 0 | |
lens = 0 | |
nd1, nd2 = 0, 0 | |
vd1, vd2 = 0, 0 | |
ta1, ta2, ta3, ta4, ta5, ta6 = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 | |
xorg, yorg, zorg = 0.0, 0.0, 0.0 | |
map = 'MAP ' | |
da = 'DA ' | |
rms = math.sqrt(255^2 / flt_vol) | |
nlabl = 0 | |
label = string.rep(' ', 80) | |
header = string.pack(header_fmt, nx, ny, nz, mode, nxstart, nystart, nzstart, | |
mx, my, mz, xlen, ylen, zlen, alpha, beta, gamma, mapc, | |
mapr, maps, amin, amax, amean, ispg, Next, CreateID, | |
0, 0, 0, 0, 0, 0, 0, 0, nint, nreal, 0, 0, 0, 0, 0, | |
imodStamp, imodFlags, idType, lens, nd1, nd2, vd1, vd2, | |
ta1, ta2, ta3, ta4, ta5, ta6, xorg, yorg, zorg, map, da, | |
rms, nlabl, label, label, label, label, label, label, | |
label, label, label, label) | |
MRC = io.open(arg[3], 'wb') | |
MRC:write(header) | |
for k = 1, int_size do -- Z maps | |
for j = 1, int_size do -- Y mapr | |
for i = 1, int_size do -- X mapc | |
index = ((k - 1) * int_size * int_size) + ((j - 1) * int_size) + i | |
if index == tonumber(arg[2]) then | |
print('Writing the one white pixel to ' .. i .. ', ' .. j .. ', ' .. | |
k .. '!') | |
MRC:write(string.pack('B', 255)) | |
else | |
MRC:write(string.pack('B', 0)) | |
end | |
end | |
end | |
end | |
MRC:close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment