This is driving me crazy. In the below code, you can see the print
statement followed directly by a file write. The default value of the
variable mhullvol is -1. This is what gets written to the file, despite it
being assigned a value by that time, as demonstrated by the print, which
shows 0.827. Is there some behavior I should know about? Is the compiler
changing the order of execution? Even stranger, this is only happening to
mhullvol, and none of the other variables.
include("LCIOUtils.jl")
using MeshTools
using LCIOUtils
const globalscale = 0.005
if length(ARGS) != 10
println("Usage: PROGRAM filename collection startevent endevent resX resY
resZ blurRadius bufferpercent thresholdPercent")
exit()
end
filename = ARGS[1]
outputName = match(r".*/(.*).slcio", filename)[1]
collectionname = ARGS[2]
eventstart = parse(Int, ARGS[3])
eventend = parse(Int, ARGS[4])
resX, resY, resZ = parse(Int, ARGS[5]), parse(Int, ARGS[6]), parse(Int,
ARGS[7])
stdev = parse(Int, ARGS[8])
bufferpercent = parse(Int, ARGS[9])
thresholdPercent = parse(Int, ARGS[10])
type Collector
offset :: Int
densityfilename
ratiofilename
meshdensityfilename
energyfilename
mhullvolumefilename
Collector(num, offset) = new(offset,
"output/$(outputName)-$(collectionname)-events_$(eventstart)_to_$(eventend)-$(resX)x$(resY)x$(resZ)-blur_$(stdev)-buffer_$(bufferpercent)-threshold_$(thresholdPercent)-hulldensity.txt",
"output/$(outputName)-$(collectionname)-events_$(eventstart)_to_$(eventend)-$(resX)x$(resY)x$(resZ)-blur_$(stdev)-buffer_$(bufferpercent)-threshold_$(thresholdPercent)-volumeratio.txt",
"output/$(outputName)-$(collectionname)-events_$(eventstart)_to_$(eventend)-$(resX)x$(resY)x$(resZ)-blur_$(stdev)-buffer_$(bufferpercent)-threshold_$(thresholdPercent)-meshdensity.txt",
"output/$(outputName)-$(collectionname)-events_$(eventstart)_to_$(eventend)-$(resX)x$(resY)x$(resZ)-blur_$(stdev)-buffer_$(bufferpercent)-threshold_$(thresholdPercent)-mhullvolume.txt",
"output/$(outputName)-$(collectionname)-events_$(eventstart)_to_$(eventend)-MCEnergy.txt")
end
import Base.call
function call(collector :: Collector, positions :: Matrix, i :: Int,
maxEnergy::Float64)
print("processing event $i")
mhull_energydensity = -1
ratio = -1
mesh_energydensity = -1
maxEnergy = -1
mhullvol = -1
if size(positions)[2] == 0
println("no points to load!")
else
grid = MeshGrid(resX, resY, resZ, positions, true, stdev, bufferpercent
/ 100.0)
maxEnergyDensity = maximum(grid.data)
minEnergyDensity = minimum(grid.data)
print(".")
verts, indices = createMesh(grid.data, (grid.maxPt - grid.minPt)...,
grid.minPt..., (maxEnergyDensity - minEnergyDensity) / 100.0 *
thresholdPercent + minEnergyDensity, 1, globalscale)
print(".")
verts, indices = removeDoubles(verts, indices)
print(".")
verts_mhull, indices_mhull = convexhull(verts)
print(".")
vol = volume(verts, indices)
mhullvol = volume(verts_mhull, indices_mhull)
totalE = sum(positions[4, :])
mhull_energydensity = totalE/mhullvol
ratio = vol/mhullvol
mesh_energydensity = totalE/vol
print(".\n")
end
densityfile = open(collector.densityfilename, "a")
ratiofile = open(collector.ratiofilename, "a")
meshdensityfile = open(collector.meshdensityfilename, "a")
energyfile = open(collector.energyfilename, "a")
mhullvolumefile = open(collector.mhullvolumefilename, "a")
write(densityfile, "$(mhull_energydensity)\n")
write(ratiofile, "$(ratio)\n")
write(meshdensityfile, "$(mesh_energydensity)\n")
write(energyfile, "$(maxEnergy)\n")
println("Hull volume: $(mhullvol)")
write(mhullvolumefile, "$(mhullvol)\n")
close(densityfile)
close(ratiofile)
close(meshdensityfile)
close(energyfile)
close(mhullvolumefile)
end
mappositions(Collector(eventend - eventstart + 1, eventstart-1), filename,
eventstart, eventend)
As you can see, the print(mhullvol) and write("$(mhullvol)\n") are right
next to each other, so the discrepancy makes no sense.