A FORMER prosecutor who resigned from his post when his career was overshadowed by reports he had sex with a prostitute has been told to carry out 300 hours of unpaid work after admitting downloading indecent images of children.

Stuart MacFarlane, 45, a former depute fiscal, has been placed on a three-year community payback order and will have to accept specialist counselling and psychiatric input where necessary.

MacFarlane kept his secret from his family and spent hours hidden away in a garden hut that was kept for his exclusive use. When detectives with a search warrant went to the property in Eaglesham, East Renfrewshire, last December, they seized two laptops, one of which had an external storage device, and took them for forensic examination.

The computers contained 15,000 indecent images, the vast majority of which involved children in erotic poses, ranging in age from three to 14.

Paisley Sheriff Court had earlier heard MacFarlane was questioned after he had been medically examined because it was known he had previously claimed to be suffering from Post Traumatic Stress Disorder after service as a captain with the Territorial Army in Iraq.

Sheriff James Spy told MacFarlane yesterday that bearing a recent Appeal Court decision in mind and guidelines on sentencing, he had decided that to allow him to continue with counselling treatment that had already been under way for nine months, it would be best to refrain from sending him custody.

That, said, the sheriff, would ensure minimum risk to the public.

MacFarlane, whose address was given as Mount Florida, Glasgow, was ordered to attend a project to assist with sex offender rehabilitation and advised to attend when ordered to do so at the Douglas Inch Clinic, Glasgow, and to accept all psychiatric and psychological input as directed.

The sheriff said: "Regarding internet access, you will keep a readable internet history on your computer for inspection by any officer either at home or by surrender of the computer for examination. I intend to hold regular reviews, the first of which will take place in eight weeks to monitor your progress."

MacFarlane was warned that if he was found to be in breach of any of the conditions put in place he would inevitably face jail.

After departing from the Fiscal service in 2006 in what was described in court as "a fall from grace," MacFarlane went on to see active service in Iraq, Afghanistan and Pakistan.

Recently, he has been employed with US Special Forces as a team leader at administrator level involved in training and mentoring sections of the judiciary in Afghanistan. Before that he had a role in a Nato Rapid Reaction Force, which led him into direct contact with the Taliban as he tried to dissuade extremists from joining.

When serving with the Territorials in Iraq, he experienced "live" frontline action and afterwards was diagnosed as suffering from Post Traumatic Stress Disorder.

His defence agent Urfan Dar said his client had for the past nine months been paying for private counselling sessions to address underlying issues in his life which had caused MacFarlane to experience "a significant level of self-loathing and disgust" and led him to consider suicide.

MacFarlane had earlier admitted that between March and December last year he took, permitted to be taken or made indecent photographs or pseudo-photographs of children, contrary to the Civic Government (Scotland) Act of 1982.