As Scotland prepares for an independence referendum I decided to look back at the late 1690s when an independent Scotland launched an ambitious but ultimately doomed plan to create a colony in what is now Panama.

We landed near the border with Colombia, close to where the Isthmus of Panama is at its narrowest, on a little airstrip wedged between the blue sparkle of the Caribbean and the green intensity of an impenetrable forest, and boarded a little fibreglass boat with a single outboard motor.

We made our way west, parallel to the coast, bouncing roughly in the surging surf, until we came to the island that is still called Caledonia.

"In the time of our forefathers," a village elder told us, "white people came here - Scottish and Spanish people. We liked the Scottish more than the Spanish, for the Spanish attacked us and drove us inland away from the coast and the Scots did not. But there were battles and many ships were sunk".

Find out more Listen to From Our Own Correspondent for insight and analysis from BBC journalists, correspondents and writers from around the world Broadcast on Radio 4 on Saturdays at 11:30 BST and BBC World Service Listen to the programme Download the programme

The story of the ill-fated Scots colony at Darien survives in the oral history of the Kuna Indians, who are the only people who have ever settled successfully in this inhospitable place.

In 1698, a fleet of five ships sailed from Leith docks near Edinburgh carrying 1,200 settlers to found a colony in Panama.

It was a place where the poet John Keats would later locate "stout Cortez" gazing at the Pacific for the first time, "and all his men looked at each other with a wild surmise, silent upon a peak in Darien".

The Scots found a large sheltered harbour with a supply of fresh water. They went ashore and built a fort they called Fort St Andrew.

Three centuries on, we hacked our way through the forest and found a trench they had dug to provide the fort with a defensive moat.

It is a wide gash, filled with sea water, cut through solid coral rock by 17th Century hands - the first canal in Panama, possibly, built by Scotsmen under a punishing tropical sky. It is pretty much all that is left of the colony they named Caledonia, and the town they called New Edinburgh.

Between a quarter and a half of the available wealth of Scotland was spent, and lost

For even before they made landfall, the colonists had begun to die.

Tropical diseases - malaria, yellow fever, something they called the bloody flux - cut them down even faster on land.

Somewhere beneath the tangle we hacked through, there is a Scottish cemetery with hundreds of graves. No-one has ever found it.

The forest is too dense. Within nine months of setting sail from Leith, on a wave of national euphoria, most of the colonists were dead. A second fleet sailed in 1699, not knowing that the colony had already been attacked and burned to the ground by the Spanish, and abandoned by its few survivors.

Media playback is unsupported on your device Media caption Allan Little: "Scotland is rethinking the lessons of the Darien disaster"

The disaster helped end Scotland's independence. For the colony had been funded by public subscription - an early example of a financial mania.

Public bodies, town corporations, members of parliament, landed gentry, and thousands of private citizens - sea captains and surgeons, apothecaries and ironmongers - sank their life savings into the scheme.

Between a quarter and a half of the available wealth of Scotland was spent, and lost.

Image copyright RBS Image caption A record of all the investors was kept

And it was the role of England that was most bitterly resented.

Scotland, though an independent country, shared its head of state with England.

What the settlers took with them Tools - axes, spades and flooring nails

Pistols

Clothing - 85 ceremonial wigs, 2,000 hats, 1301 pairs of slippers and 324 pairs of women's gloves

3 traps (horse-drawn carriages)

Household items - 9 smoothing irons, 94 bed covers, 10 cups Source: RBS archives

King William was monarch of both kingdoms. English merchants and the English parliament saw the Scottish venture as a threat to the trading monopolies they enjoyed.

King William issued a decree to all the English colonies from Canada to the Caribbean: there was to be no trade with the errant Scots and no assistance - not so much as a barrel of clean water was to be offered to them.

Few of the 3,000 Scots who went made it home. Those who did found an impoverished country which, within a decade, accepted union with England.

The Treaty of Union of 1707 included a clause in which the English government agreed to pay a sum of money to the Scots, to compensate the Darien investors for what they had lost.

The sum of money England paid to the Scots was known in the treaty as the Equivalent, or the Price of Scotland.

Image copyright RBS

Darien still resonates, as Scotland prepares to vote on independence.

Pro-union Scots see in it a cautionary tale about the dangers of over-ambition. But when a nation is rethinking its future, as Scotland now is, it also looks again at its past.

Some now argue that the story reinforces the case for independence, for it proved that when Scotland and England place themselves under one government in London - as they were under King William - that government will, when the interests of the two countries conflict, inevitably favour the cause of the larger and more powerful partner.

The poet Robert Burns was scathing about the Scottish parliament that voted to accept union with England. "We're bought and sold for English gold," he wrote decades later, "such a parcel of rogues in a nation".

How to listen to From Our Own Correspondent:

BBC Radio 4: Saturdays at 11:30 and some Thursdays at 11:00

Listen online or download the podcast.

BBC World Service: Short editions Monday-Friday - see World Service programme schedule.

Follow @BBCNewsMagazine on Twitter and on Facebook