       }
       i++;
     }
+    else {
+      if (path) {
+        fprintf(stderr, "%s: input file already specified\n", argv[i]);
+        return EXIT_FAILURE;
+      }
+      path = argv[i];
+    }
   }
 
 

    }
  }

  void* buildCayleyField(uint32_t nx, uint32_t ny, uint32_t nz, FieldFormat format)
  {
    size_t elementSize = 0;
    switch (format) {
    case FieldFormat::UInt8: elementSize = sizeof(uint8_t); break;
    case FieldFormat::UInt16: elementSize = sizeof(uint16_t); break;
    case FieldFormat::Float: elementSize = sizeof(float); break;
    default: assert(false); break;
    }
    size_t memSize = nx * ny * nz * elementSize;
    void * hostMem = malloc(memSize);
    for (unsigned k = 0; k < nz; k++) {
      for (unsigned j = 0; j < ny; j++) {
        for (unsigned i = 0; i < nx; i++) {
          float x = (2.f*i) / (nx - 1.f) - 1.f;
          float y = (2.f*j) / (ny - 1.f) - 1.f;
          float z = (2.f*k) / (nz - 1.f) - 1.f;
          float v = 1.f - 16.f*x*y*z - 4.f*(x*x + y * y + z * z);
          switch (format) {
          case FieldFormat::UInt8:
            v = 0.5f*255.f*(v + 1.f);
            if (v < 0.f) v = 0.f;
            if (255.f < v) v = 255.f;
            ((uint8_t*)hostMem)[(k*ny + j)*nx + i] = uint8_t(v);
            break;
          case FieldFormat::UInt16:
            v = 0.5f*65535.f*(v + 1.f);
            if (v < 0.f) v = 0.f;
            if (65535.f < v) v = 65535.f;
            ((uint16_t*)hostMem)[(k*ny + j)*nx + i] = uint16_t(v);
            break;
          case FieldFormat::Float:
            ((float*)hostMem)[(k*ny + j)*nx + i] = v;
            break;
          }
        }
      }
    }

    void* deviceMem = nullptr;
    CHECKED_CUDA(cudaMalloc(&deviceMem, memSize));
    CHECKED_CUDA(cudaMemcpy(deviceMem, hostMem, memSize, cudaMemcpyHostToDevice));
    free(hostMem);
    return deviceMem;
  }



using namespace ComputeStuff::MC;

namespace {

  FieldFormat format = FieldFormat::UInt8;
  uint32_t nx = 128;
  uint32_t ny = 128;
  uint32_t nz = 128;

  std::vector<char> scalarField_host;

  void onGLFWError(int error, const char* what)
  {
