Input of extended pgm (pink) files (magic number P2)

Seemingly netpbm files with magic number P2 are not read properly if extended to 3d data:

Example: Here depth is only 1, still gmic takes 255 as first pixel
P2
7 7 1
255

0 0 1 0 0 0 0
0 0 1 0 0 0 0
1 1 1 1 1 1 1
0 0 1 0 1 0 0
1 1 1 1 1 0 0
0 0 0 0 1 0 0
0 0 0 0 1 0 0

Another example test1.pgm: result is a 2,2 image starting with 255

P2
2 2 3
255

1 0
0 1

1 1
1 0

1 0
0 1

gmic test1.pgm
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘test1.pgm’ at position 0 (1 image 2x2x1x1).
[gmic]-1./ Display image [0] = ‘test1.pgm’.
[0] = ‘test1.pgm’:
size = (2,2,1,1) [16 b of floats].
data = (255,1;0,0).
min = 0, max = 255, mean = 64, std = 127.334, coords_min = (0,1,0,0), coords_max = (0,0,0,0).

Also ‘gmic pnk:test1.pgm’ does not help!

Indeed, no ASCII-based formats of netpbm have been made to support 3D images.
Only binary formats support it.

Thanks for the reminder, I think I have to circumvent that.