Image caption Each poo is a time capsule to the dawn of the dinosaurs

A gigantic "communal latrine" created at the dawn of the dinosaurs has been unearthed in Argentina.

Thousands of fossilised poos left by rhino-like megaherbivores were found clustered together, scientists say.

The 240-million-year-old site is the "world's oldest public toilet" and the first evidence that ancient reptiles shared collective dumping grounds.

The dung contains clues to prehistoric diet, disease and vegetation says a study in Scientific Reports.

It's a warning to predators. If you leave a huge pile you are saying: 'Hey! Watch out!' Dr Lucas Fiorelli, Crilar-Conicet Walking with Dinosaurs: Prehistoric poo

Elephants, antelopes and horses are among modern animals who defecate in socially agreed hotspots - to mark territory and reduce the spread of parasites.

But their best efforts are dwarfed by the enormous scale of this latrine - which breaks the previous record "oldest toilet" by 220 million years.

Fossil "coprolites" as wide as 40cm and weighing several kilograms were found in seven massive patches across the Chanares Formation in La Rioja province.

Some were sausage-like, others pristine ovals, in colours ranging from whitish grey to dark brown-violet.

"There is no doubt who the culprit was," said Dr Lucas Fiorelli, of Crilar-Conicet, who discovered the dung heaps.

"Only one species could produce such big lumps - and we found their bones littered everywhere at the site."

Image caption The culprits were dicynodonts - ancient megaherbivores

The perpetrator was Dinodontosaurus, an eight-foot-long megaherbivore similar to modern rhinos.

These animals were dicynodonts - large, mammal-like reptiles common in the Triassic period when the first dinosaurs began to emerge.

The fact they shared latrines suggests they were gregarious, herd animals, who had good reasons to poo strategically, said Dr Fiorelli.

"Firstly, it was important to avoid parasites - 'you don't poo where you eat', as the saying goes.

"But it's also a warning to predators. If you leave a huge pile, you are saying: 'Hey! We are a big herd. Watch out!"

The predator in this case was the formidable Luperosuchus, a crocodile-like carnivore up to 8m in length.

But the dung patches were equally intimidating.

Image caption A museum of poos has been created by the researchers

A density of 94 poos per square metre was recorded by the researchers. And the excrement was spread across patches 900 square metres in size.

Prehistoric coprolites are nothing new, but it is extremely rare to find an accumulation as old and substantial as this one - because faeces degrade so easily.

A sheet of volcanic ash has preserved the ancient dung piles "like Pompeii", said Dr Fiorelli.

The coprolites are like time capsules.

"When cracked open they reveal fragments of extinct plants, fungi, and gut parasites," said Martin Hechenleitner, a fellow author on the study.

"Each poo is a snapshot of an ancient ecosystem - the vegetation and the food chain.

"This was a crucial time in evolutionary history. The first mammals were there, living alongside the grandfather of dinosaurs.

"Maybe with these fossils we can glimpse into the lost environment which gave rise to the dinosaurs."