main.f roughly but entirely translated into something that's almost C++