A thousand books have been damaged at the National Library of Scotland as an investigation was launched into why a faulty sprinkler system, that caused a flood, malfunctioned.

The main building in Edinburgh was hit with around 5000 litres of water in about five minutes when a top-floor sprinkler system malfunctioned on Thursday night.

Around 15 firefighters with three pumps worked with library staff after the water flooded the building on George IV Bridge.

The water was quickly turned off at the mains and most of it was directed into the basement and out into the sewers, a library spokesman said.

The library was closed yesterday while staff dealt with the aftermath of the flood, but it will reopen on Monday.

The spokesman said that about 1000 books had "light" water damage and had been placed in a reading room to dry out with the help of fans and dehumidifiers.

Some of the books, which date back to the 19th century, may need preservation or conservation work, which will take place in the next few days.

The spokesman said: "The vast majority of the water has gone out of the building but some has gone into various collection areas.

"It is a very small proportion of the collection. We have got six million items in the building.

"The library has iconic treasures and unique heritage collections. These have additional protective measures in place and none of these type of books are affected.

"There is no great loss to Scottish literary heritage on the cards."

The spokesman said there was no structural damage to the building.

Areas affected by the flood will be checked to ensure there is no excess moisture on the stonework and dry it out if necessary.

The spokesman said there may have been a problem with one of the pipes.

The National Library is Scotland's largest and houses around 14 million printed items and more than 100,000 manuscripts in its collections, according to its website.

It is also the country's deposit library, meaning it is legally permitted to request a copy of all printed items published in the UK. There are only six such libraries in the UK and Ireland.

The library was still open when the flood hit around 6pm on Thursday but no-one had to be evacuated from surrounding buildings and no-one was injured.

Lothian and Borders Fire and Rescue Service was on the scene until about 9.30pm.