This is a very large function, it could probably do with being split up into different subroutines covering each action, so that it's clearer what steps are happening. Declaring variables, setting up coordinates and setting the field values would be good things to make into separate functions.