The .dat files are images stored as matrices where each line of the file represents a row in the matrix and consists of 512 decimal numbers between 0 and 1 separated by spaces. There are 512 lines in each file. One can read and write the .dat files in Matlab/Octave using load and save.
The .pgm files contain the same images as the corresponding .dat files. The .pgm file format originated as part of the netpbm image manipulation software. One can read and write the .pgm files in Matlab/Octave using imread and imwrite. One can also view .pgm files using the GNU Image Manipulation Program and many other standard image viewers.