One hundred years ago, a madman began his grand design to put Rio de Janeiro on the map.
Augusto Ferreira Ramos wasn't genuinely insane, but that's what many claimed. As a professor of engineering, he was convinced it was possible to build a cable-car route from the suburbs of Brazil's capital up to the top of the huge granite rock known as Morro da Urca.
Urca is one of two volcanic pegs that guard the entrance to the great bay on which Rio de Janeiro stands. From there, a second cable-car could link to the Morro do Pao de Acucar, which we know better today as the Sugar Loaf.
No one prevented Professor Ramos but no one thought he'd manage it either.
Morro da Urca is 215 metres above the city, the Sugar Loaf is 396m high. Yet, within a year Ramos had done it. Sweet little canary-yellow cars were swaying their way up to the summit and he'd already started the second phase, to connect across the great chasm to the Sugar Loaf. The views were stupendous and the local postcard industry went into overdrive.
Everything else we think of today as Rio de Janeiro came afterwards - the statue of Christ the Redeemer, Carnival as we know it, the Copacabana Palace, Oscar Niemeyer and all those girls from Ipanema. Today, Professor Ramos's achievement is celebrated by a statue of him on the summit of Morro da Urca - a small, benign man in bow-tie and trilby, who smiles at those who wrote him off and who are themselves forgotten now.
I take a photo of the statue and then pause in the heat to admire the view as jets bank in front of Morro da Urca and the Sugar Loaf. What a place to fly in to.
The city of Rio spreads itself around a number of these old volcanic plugs, like moss infilling a rockery. The only problem with Rio is what happens to you between flying in past the Sugar Loaf and reaching the increasingly well-restored city centre below.
There is a road from Galeao International Airport that spoils it all. The Elevado da Perimetral is old, rusty and cantilevered. It cuts like a two-tiered Berlin Wall through the city's historic district. I came in this way and was amazed at what I saw below; colonial Rio bisected by an ageing 1960s monstrosity.
Later, I stood below the avenue and wondered at what the city planners had been thinking. I had my back to Placa Tiradentes, a popular gathering point during Rio Carnival. It's named after a bearded Brazilian revolutionary whose aim was full independence from the Portuguese. In 1792 he was betrayed, executed and ritually dismembered, but since the 19th century Tiradentes has been a national hero. He is also, curiously, patron of the military police in Minas Gerais, the city of his birth.
Opposite me stood a whitewashed building similar to some of the old palaces I'd seen in Tenerife - low, colonial, pan-tiled and balconied. This was the Paço Imperiale, now half a kilometre from the sea and kept away from it by the noisy Perimetral. Today, it's an art gallery, restaurant and bookshop, yet back in the time of Napoleon, this was the harbour-front palace from which the Portuguese Empire was ruled (at least in theory).
King John VI of Portugal lived here from 1808 after fleeing Lisbon following Napoleon's invasion. It was the British Navy that brought him over, along with his mother, Maria a Luoco (Mad Maria). She was installed at a safe distance across the street, in a Carmelite convent that still stands today.
In the confused mix of post-Napoleonic politics after the dust had settled in Europe, King John's son, Prince Pedro, was in this palace in 1822 when he proclaimed Brazil's independence, and it was from here that the fledgling country was run. Even today, many Brazilians speak proudly of the fact that their newly independent country was a liberal monarchy long before it was a republic.
The old harbour has long since been filled in to create a square. Looming over it are two towering Baroque churches that are rather squashed together: the Cathedral of Our Lady of Carmo and the Church Ordem Terceira. In the middle of the square, facing the sea, stands a mounted statue of General Manuel Luis Osorio, hero of Brazil's war against Paraguay (1864-70). Sadly, all the lettering was smashed off in the days before inner-city Rio cleaned up its act, so I had to take the words of a dapper old man who looked rather like Professor Ramos that this was, indeed, Osorio.
The general and his horse stand facing a Baroque fountain by Master Valentin where people used to do their washing. It produces no water now.
Worse, however, is the fact that statue, fountain and palace - not to mention St James' Fort nearby - no longer face the sea at all but the Elevado da Perimetral. I know it's a useful road because my taxi used it to bring me into town, but really, it looks horrible and it cuts off what locals call the Cultural Corridor from the sea, which was the reason these buildings were called into being in the first place.
Fortunately, the city, with its eye on the 2014 World Cup, is doing something about this insensitive piece of urban planning. The road is going underground, thus opening up the historic centre of Brazil's great trading port to the bay.
Better still, a whole dockland redevelopment is planned - on rather European lines - to reclaim the old port and make it worth visiting. I negotiated my way under the Perimetral to find a number of impressive warehouses that used to serve the White Star Line on the other side. They remain undemolished and there is an absolute jewel of an Art Deco harbour building.
In front of it, an ugly old concrete jetty extends far into the bay, but it is being transformed by the great and highly idiosyncratic Spanish architect Santiago Calatrava. His characteristic white-ribbed structure will be the port's signature building, Museu do Amanha (Museum of the Future), to be completed next year.
By 2014, visitors and locals will be able to walk from the narrow Cultural Corridor to this $2.8 billion (NZ$3.7bn) waterfront redevelopment and the historic centre will be reborn.
The project has been dubbed "The Marvellous Port", a reference to Rio's long-term nickname, Cidade Maravilhosa (Marvellous City).
With a characteristic touch of the dramatic, and uncharacteristic modesty, Calatrava has declared that his building will not dominate the landscape as his work has in Tenerife, Liege and his home city of Valencia.
"I do not want to compete with all that Rio already has," he says.
Retracing my steps, I passed by the fountain and the nameless general and ducked under the Arco do Telles, a simple passageway under a house owned by the Telles family. It led to a narrow cobbled street, Travessa Do Comercio. There used to be many winding streets like this before the city had its Baron Haussmann moment in the 19th century and labyrinthine Rio was replaced by an attempted grid.
Travessa Do Comercio used not to be at all safe and in its shadows and blind alleys you can see why. But nowadays this is prime tourist-trap territory and tables were already being set up for lunch.
I looked for the house (No 13) where Carmen Miranda was brought up, after she arrived from Portugal in 1910. To my surprise there was no plaque to the lady with the tutti-frutti hat.
The streets kept twisting at right angles and eventually I came out at the church Igreja de Nossa Senhora da Lapa dos Mercadores, one of two in Rio dedicated to the 17th-century cult that came over from Portugal. The current structure dates from 1870 but was closed for many years during the bad times. It's recently reopened and is wonderfully gilded inside.
Nearby, at the western edge of the Lapa district, stands my already-all-time-favourite restaurant in Rio. Every visitor should go to the Rio Scenarium - three huge dark solid Gothic-style houses put together in a street, Rua do Lavradio, that was once a byword for drugs, robbery and murder.
A few years ago, the owner, who had been renting the property as a warehouse for film props, turned it into a bar-cum-restaurant, its walls decorated with photo-montages of Brazilian movie stars, fridge doors, bicycles, clocks, Chinese lanterns, you name it. Security was tight - it still is - but the experiment worked, reclaiming this part of Lapa for fun.
When I visited, the dance floor was busy, the band was pumping out samba and people were hanging over the internal balconies laughing and drinking. It was everything I had imagined when I first picked up my ticket for Rio.
When all this is finished: when they've renamed the General; put up a plaque at Travessa Do Comercio; opened more places like Rio Scenarium; and, most importantly, got rid of that awful elevated highway, Rio is truly going to be Cidade Maravilhosa.
It will always have its eyesores: The infamous Cathedral Sao Sebastiao do Rio de Janeiro (built 1964-79) has been voted one of the ugliest buildings in South America. Standing 75m high, it looks like a giant furnace out of Blade Runner and can be picked out, clearly, from the summit of Morro da Urca. If Professor Ramos had seen that, he may not have bothered to complete his bold cable-car initiative.
But such mistakes are in the past. Rio is now heading in the right direction.
I can't wait to see it once it's finished.