THE Scottish novelist Ian Rankin was in reflective, even pensive mood.

As anyone might be, perhaps, as the paper record of your private and public life enters a national archive, to be studied, categorised, and pored over for decades to come.

Yesterday the author spoke, at times movingly, at an event at the National Library of Scotland - at the centre of the Scottish capital that he has made the stage for his best selling novels - of the memories, drafts, letters, typescripts, notes and books which he has gifted to the nation.

The archive is substantial: around 50 boxes of material, around 21ft of shelving, spanning 45 years of his career and vocation.

It is, the Fife-born writer said, "a pretty complete author's life, late-20th century-style."

Within the boxes, which as well as correspondence with writers including the late Iain Banks, Val McDermid, William McIlvanney, Colin Dexter, Jilly Cooper, Ruth Rendell and JK Rowling, it shows the struggles, anxieties, despairs, successes and triumphs of a Scottish writer trying to make in the literary world.

He also noted that he might be among the last generation of writers who has written physical letters, not emails or texts: he said he corresponded with Banks and McDermid before he had ever met them.

The material, which will have its own curator, dates from 1972 to 2018 - it does not, he said, contain his teenage diaries, but it does encompass much else.

Rankin said he had, just on Monday this week, 'downsized' to a flat from a house, and had undergone a sometimes painful process of sorting through his hoarded material.

Among the papers are, he said, some surprises, including a film and a TV series he drafted in the late 1990s, and early drafts of his many Rebus novels, although not the very first draft of Knots and Crosses, where Inspector John Rebus is shot dead at the end.

He noted: "Maybe I just wrote it in long hand and just threw it away - but maybe it is in there, for someone to find."

There is a letter from a US publisher noting that he should perhaps put the murders in his book closer to the opening of the novel.

Rankin said there were four or five drafts of each of his novels in the archive.

He said: "I am relieved...I just spent weeks if not months going through it all.

"I have mixed emotions, because you go back to your beginnings as a writer when you were making a lot of mistakes, getting a lot of rejection letters, writing things that you weren't happy with, just trying everything.

"There are lots of scraps of paper there, different projects that I have no memory of - there's a film script, a TV drama script, which I have no memory of.

"There are short stories that I don't remember writing, a tonne of stuff: but the main emotion was that it was like looking at a life from the beginning, right back when I was unsure about what I was doing: back as someone from Cardenden, a working class background, didn't know anyone who was a writer and: how to I get published?

"Looking back at that young Ian, I wish I'd known then what I know now, and that it was all going to be OK."

He added: "I remember that in my first week as a postgraduate student, we were given a tour of the National Library of Scotland, including access to the basement levels.

"Those vaulted underground corridors would reappear in the climactic scenes of my first Rebus novel.

"The library has seemed like a friend ever since, so it seems fitting - as well as a thrill and an honour - that my archive should find a permanent home there."

The library said it will recruit a curator to catalogue and promote the Ian Rankin archive.

National librarian Dr John Scally has described the archive as "comprehensive, fascinating (and) in-depth".

He said: "Ian Rankin is a well-known face to us here at the National Library. We knew him when he was researching Muriel Spark as part of his PhD, and we knew him when he penned his first novels here in our very reading rooms.

"Little did we know then just how successful he was to become, and that in time, his archive would be as gratefully received as Spark's.

"It will be preserved into perpetuity alongside other Scottish literary giants.

"Rankin's main protagonist, John Rebus, has walked George IV Bridge many times, and frequently visited this very library while researching cases.

"We are honoured to be a character in the Rebus novels alongside the city of Edinburgh, and we feel this is the rightful home for Ian's archive.

"Because of his generosity, readers will be able to gain insight into the creative process of this wonderful writer."

Rankin has said that he had gone through every paper item, "lest there be something there I don’t want anyone seeing".

After shredding financial material, recycling other papers, and giving books and music to charity, he said put the items he wanted to keep in boxes.

Rankin says that the process of reducing his belonging has been "a reckoning, and it is proving cathartic."