We can avoid math by using appropriate software. Because
R is free and handy, here is a solution in that platform. It uses some math purely in a data-processing capacity to split the two parts of the [Z05Code] field into row and column indexes.
# Read the file (details depend on the location and name on your system)
data <- read.csv("f:/temp/hg/hg.txt")
# Extract the `i` and `j` indexes from the [Z05Code] field
# Reference: http://www.amap.no/Resources/HgEmissions/HgInventoryDocs.html#Grids
j <- data$Z05Code %/% 1000 # Prefix: latitude index
i <- data$Z05Code %% 1000 # Three-digit suffix: longitude index
The challenge is to convert what is effectively an (i,j,value) format into an actual array of values.
R makes this easy, because it allows indexing into an array using the (i,j) pairs.
# Convert one of the data fields to an array.
# For this example, [HgT_00_a] will be used. Execute `names(data)` for a list
# .. of all field names.
a <- matrix(NaN, ncol=720, nrow=360) # Start with numeric NoData values
a[cbind(361-j,i)] <- data$HgT_00_a # Notice how rows need to be reversed!
The rest is routine. We probably want to create a disk dataset in a standard grid format. But first we have to specify the coordinate system: the math gets done here.
# Convert to raster format in order to exploit the `raster` library capabilities.
a.raster <- raster(a, crs="+proj=longlat +datum=WGS84")
extent(a.raster) <- c(-180,180, -90,90)
It's always a good idea to visually check one's work. (This check originally showed me I had to reverse the rows in the array.)
# Double-check by making a map.
# (To see detail, we plot the log Hg emissions.)
Once you're happy, create the output.
# Use ?writeRaster to see more formatting options.
writeRaster(a.raster, "F:/temp/HgT_00_a.asc", format="ascii")
The "ascii" output format is the ESRI ASCII grid format, which is readily imported into ArcGIS.
Don't go through this manually for each of the 48 value fields!
R has many iteration constructs that can automate producing disk datasets for every field.