How to write a cube file? This is a technical question. I have a real-space representation of a potential in a grid of points, however I have the grid in the format:

x  y  z  w  v

meaning: the coordinates of each point, the weight and the value of the potential.

I would like to visualize this potential but I need to re-write this potential in a cube file. I haven't found any particular software or script to do that. 

I know how to get the header of the cube file. However I don't know how to re-write the points.

Is there a specific format to write the points?

Thank you
I would recommend using the functional PySCF cubegen script as a starting point for your own script. (https://sunqm.github.io/pyscf/_modules/pyscf/tools/cubegen.html)

If we have a grid defined with nx ny and nz points along the three axes, generating the cube file is just a nested loop over z, y, and x. (In that order) You should end up with nz lines of output each with nx*ny entries.