I don't know about three dimensional arrays (or vectors or whatever) and all those else ifs heh. I would say it should be broken into more function, but I don't really know.
It might be good if you were doing a larger project or if you wanted it to be more (quickly) understandable for others or yourself if you come back to it after a long while.