How can I sum several grids?

Hi there…

I am looking for a more “elegant” way to merge several grids at once without using temp files like this:

gmt grdmath GRD_X1.grd GRD_X2.grd ADD = temp.grd

gmt grdmath temp.grd GRD_X3.grd ADD = temp1.grd

gmt grdmath temp1.grd GRD_X4.grd ADD = temp2.grd

gmt grdmath temp2.grd GRD_X5.grd ADD = FINAL.grd

I have some few now and I capable to manage them but for sure one or two lines could help.

You can add as many .grd files as you want in just one statement:

gmt grdmath GRD_X1.grd GRD_X2.grd ADD GRD_X3.grd ADD GRD_X4.grd ADD ... GRD_Xn.grd ADD = final.grd

1 Like

ADD is a reducing operator,just use -S option

gmt grdmath -S GRD_X1.grd GRD_X2.grd  ....  ADD = final.grd
2 Likes