Jonathan Watts, Sichuan

Viagra, pornography, partner-swapping, artificial tongues and electrified rectal probes. No, they are not the ingredients for a new series of Sex And The City; they are the hard-core husbandry techniques behind a massive boom in the captive giant panda population.

The world's most famous endangered species is making a comeback. After a record 31 births in zoos and research centres this year, Chinese scientists say they have developed a near-100 per cent success rate for breeding the animals.

The population in the wild has stabilised at just over 1500 and their habitat - one of the most important centres of biodiversity in the world - has been given a new and expanded guarantee of protection by the government.

But the story is not nearly as black and white as the animals, as a visit to the Wolong Nature Reserve, in the mountains of Sichuan Province, suggests.

Not so long ago, the panda seemed doomed to extinction. Although the real threat came from man, through hunting and logging, there was a widespread belief that the animals did themselves few favours.

They were known for shyness, a low sex drive and a diet that was overly dependent on eating huge quantities of a barely nutritious and hard-to-digest bamboo that was inedible every six years or so.

For those who believe in the survival of the fittest, the only surprise was that this apparently lumbering, dozy and sexually inadequate species had clung on for so long.

The good news, according to Zhang Hemin, head of Wolong Nature Reserve Administration, is that the panda is no longer in danger. The population at Wolong has almost doubled in the past two years.

Mr Zhang says the 10-year target is a captive population of 300 (up from 120 today), which would guarantee the survival of the species for 100 years.

After 20 years of trial and error, scientists at Wolong boast they can now breed pandas at will. To counter the suggestion that the captive animals may be too naive about the birds and the bears, the keepers have provided sex education in the form of wildlife videos - dubbed "panda porn" - showing the animals mating in the forests.

To boost sex drive, they once tried the remedy used by countless millions of humans: Viagra. "We'll never do that again," Mr Zhang says. "The panda was excited for 24 hours."

Another challenge was the risk of in-breeding. To widen the genetic stock, researchers had to come up with a way to find a mate for even the least popular females. How did they do that? "We tricked them," Mr Zhang says with a smile.

The "trick" is to put a fertile and attractive female into a breeding pen, where she leaves scratchmarks and droppings capable of exciting a male. But at the last moment the females are swapped. The zookeepers introduce a new, less popular, mate who has been scented with the urine of the more attractive animals. She is introduced into the mating pen rear end first, so the male cannot see the face of his partner until they have finished copulating.

"When the males find out, they get very angry and start fighting the female," Mr Zhang says. "We have had to use firecrackers and a water hose to separate them."

Artificial insemination has also helped boost panda numbers. The use of hormones and laboratory testing of oestrogen levels has maximised the short fertility window of female pandas, which lasts about 72 hours per year.

Adult females now have an 85 per cent chance of being impregnated. But the semen-harvesting technique is likely to come as a shock to anyone used to thinking of pandas in terms of cuteness and innocence.

Lab workers in Wolong display a rectal probe that is inserted into the anus of a sedated male. This is connected to an electricity supply and the charge is gradually increased until the panda ejaculates.

Despite such indignities, animals born here have a better chance of surviving than human babies in a dozen countries.

It was not always so positive. Until recently, about half of panda mothers gave birth to twins, one of which usually died through neglect. Mr Zhang says it is difficult for mothers to look after both twins, because infants are not capable of urinating or excreting until they are six months old.

The mother must lick them clean far more often than any human parent changes their baby's nappies.

But now , the Wolong team can now almost guarantee the survival of both twins by rotating the babies between their mother and the nursery. Keepers clean the babies by using a cotton swab warmed to the same temperature as the mother's tongue.

Because it is still essential to maintain as much genetic diversity as possible, only one twin will be used for breeding. The other is likely to be rented out to overseas zoos, a privilege American and Japanese zoos pay $1 million a year for.

Critics say the centre is a diversion from the more important task of conserving pandas in the wild.

"There is a real danger that we will have captive breeding centres that are farming for non-conservation purposes - to sell the skin and bones," says Jim Harkness, a former China representative for the World Wildlife Fund and now president of the US Institute of Agriculture and Trade Policy. "This is a terrible risk. It is more important to protect the existing wild population. Much more should be done for them."

According to Mr Harkness, the best available research suggests giant pandas breed without difficulties in the wild. "The problems often attributed to them - short *****es, narrow ******s and low sex drives - are not an issue in the wild.

Panda breeders tell us they are solving genetic problems, but those problems exist only among the captive population. It is a phoney issue to say that pandas face a breeding crisis that we have to solve."

Mr Zhang is determined to prove the doubters wrong. Earlier this year, his team released its first captive-bred panda, Xiang Xiang, into the wild.

"Xiang Xiang is doing very well," Mr Zhang says.

"His weight has increased by 15 kilograms. We taught him how to choose good bamboo. According to the satellite sensor, he has travelled up to nine kilometres and returned. We are hoping he will fight with males during the mating season next year. If that happens, it will prove the release is successful."