The data set I have is an ASCII file containing a header over 4 lines and the actual data comprised of dezimal numbers in a 1000x1000 grid (1000 lines and 1000 columns).
Since I want to plot the data in GMT I need to convert it into the following format:
[x coordinate] [y coordinate] [value]
This means every single value will be in a single line preceeded by its coordinates. For simplicity lets say the upper left corner has coordinats 0,0 and the grid spacing is 500 in both directions.
You are running a loop from 1 to 1000 over columns which don't exist and lines haven't been read. BEGIN takes place before any data is read.
Further, awk does not process expressions inside strings.
That you have a loop from 1 to 1000 doesn't tell awk to read 1000 lines anyway. awk has its own built in loop, which it will use if you don't specifically force it not to (by using BEGIN or END).
It is always beneficial to post sample input and output data, describe the underlying structure, show the (intended!) logics or algorithms that connect the two, and - in case of failures - what and where fails, and error messages.
In your case - which are the coordinates, and which are the values to plot? Is it [row No.] [col No.] field value ? When looping across the fields, does it make sense to use $(i-1) and $i , and then only increment by 1 (which would mean you're using $i twice)?