Emerging from the clouds of steam engulfing platform nine and three-quarters, the gleaming Hogwarts Express commands a special place in the hearts of Harry Potter fans.

Yet there was a time when the only place this engine could call home, was a south Wales scrapyard where it lay rotting among the hulks of a bygone era.

That is because the locomotive that entranced millions of Potter viewers and now sits proudly in Warner Brothers Studios, was once earmarked to be dismantled for the furnace.

Written off, abandoned and forgotten for 17 years, this lowly engine's final destiny was originally far from Hogwarts School of Witchcraft and Wizardry.

But the story of humble GWR 5972 Olton Hall, is as enchanting as any told by JK Rowling.

"It was in a hell of a state after being sat for nearly 20 years in a scrapyard," recalled James Shuttleworth, of West Coast Railway, the heritage rail operator that rescued the engine.

"As renovations go, it was nothing out of the ordinary. But then Warner Brothers came along."

Built more than 80 years ago, GWR 5972 was among the work-horses of the rail network in the industrial heartland of south Wales in the 1940s and 1950s.

In a golden era for steam train travel, Olton Hall was a regular feature on one of Great Western Railways' mainline routes to London Paddington.

But amid the move towards diesel and electric, the engine's days were numbered.

After a spell in Plymouth, it returned to south Wales in 1959 before finally being withdrawn from Cardiff East Dock shed in 1963.

Set for scrap

When it was bought by the owners of a scrapyard in Barry Docks, more commonly known as the "locomotive's graveyard", in the Vale of Glamorgan - the future looked bleak.

"British Rail started getting rid of steam in the '60s, so once a locomotive needed any sort of work, they got rid," explained Mr Shuttleworth.

"Almost all of the 22,000 steam locomotives were chopped up for scrap, either for the Far East or many to fuel the furnaces of south Wales."

Woodham Brothers, a pebble's throw from Barry Island pleasure beach, soon became a treasure trove for rail enthusiasts.

But Olton Hall's reincarnation was to prove unique.

Purchased in 1981 by David Smith, now the owner of West Coast Railways, it took a small army of volunteers 16 years to restore the express to its former glory.

Yet there was to be another twist that saw 5972 rise from the ashes like Prof Dumbledore's faithful phoenix Fawkes.

Hollywood called
"There had been a lot of deterioration in that time so it took a lot of work," said Mr Shuttleworth.

"You can't just throw in some water and fire up the boiler or you would have gone skyward very quickly. So you almost have to start all over again.

"But we had it up and running charter trips on tracks in the north of England.

"It hadn't done anything extraordinary, but then we had a call from Warner Brothers."

When the first Harry Potter novel - Harry Potter and the Philosopher's Stone - was to be turned into a movie, film-makers were desperate for an authentic steam engine to represent the Hogwarts Express.

"Hogwarts was set in Scotland and Warner Brothers knew we operated on the West Highland Line," said Mr Shuttleworth.

"They wanted an engine that was quintessentially British and JK Rowling had apparently seen one on a journey from Edinburgh to London.

"When the artistic director showed me a photo of what they wanted, a Hall class engine, I replied, 'That's easy, we've got one of those'."

'Upset the purists'
The harder task turned out to be appeasing trainspotters over the choice of colour when Warner Brothers insisted the livery was red, in keeping with Rowling's original text.

"Since the earliest day, Great Western Railway was always 'green until I die', so the decision to paint it red really upset the purists," said Mr Shuttleworth.

GWR 5972 would play a leading role in all seven of the subsequent Harry Potter films and today takes pride of place among the attractions at Warner Brothers Studios in Hertfordshire.

Yet the 6,000 daily visitors to Leavesdon would not be able to marvel at the Hogwarts Express if not for an avid group of rail enthusiasts and an opportunist Barry scrap merchant.

"At his soul, Dai Woodham was a businessman," said Mr Shuttleworth.

"He managed to get the rule rescinded that prevented engines being re-sold after they were scrapped," said Mr Shuttleworth.

"As a result he sold some 220 engines that mostly went on to be restored.

"I doubt preservation was his prime motivation, but he inadvertently helped save the steam engine almost single-handedly."

Millions of Harry Potter fans will be forever grateful that he did.