Nicaragua is insulted, Costa Rica angry and indignant, and everybody more than a little embarrassed as relations between the countries have reached a new low over the question, quite literally, of where the bodies are buried.

The particular bones of contention belong to Costa Rican hero Juan Santamaria, who died in 1856 fighting American adventurer William Walker in the Nicaraguan town of Rivas.

In a goodwill gesture toward the Costa Ricans, who gave them a vital base of operations for the defeat of the Somoza dictatorship in 1979, Nicaragua's Sandinista government decided to find Santamaria's grave in Rivas and return his remains and those of his Costa Rican comrades to their homeland.

With major fanfare in April, Costa Rica accepted the gesture, and the box full of bones, only to have Costa Rican archaeologists decide--just before the 150th anniversary of Santamaria's birth on Aug. 29--that most of the remains belonged to pigs, horses and other domestic animals.

The controversy suggests just how delicate relations are between Nicaragua and its friendliest, if perhaps most disillusioned, neighbor and how passionate the nationalism and important the role of symbols in Central American life.

People here were furious, both with the Nicaraguans, whom they accused of mocking their national hero, and with the already unpopular government of Costa Rican President Rodrigo Carazo, whom they felt acted the part of a fool.

Managua's often defensive leftist regime was no less incensed by the incident. Nicaraguan Ambassador Roberto Leal called the controversy a maneuver by people interested in creating a confrontation and "destabilizing the Sandinista revolution."

"We were a little appalled at that reaction," said Michael Snarskis, a member of the Costa Rican commission and director of archaeological research at the Costa Rican national museum.

The whole affair might have passed quietly. But the bones had been taken to the Juan Santamaria Museum in the town of Alajuela where the hero was born. After the Costa Rican report, anxious officials here decided to wrest the remains from the residents of the town. In the face of a jeering mob, the bogus bones were given a police escort to the Nicaraguan Embassy in San Jose where they lay in state overnight.

The controversy began in earnest and very publicly.

The Nicaraguan government sent an airplane to pick up the bones and flew them to Managua where the Sandinistas received the dusty relics with full military honors. The Nicaraguans vowed that since Costa Rica obviously didn't care about its national hero--a great fighter against Yankee imperialism, after all--the Sandinistas would make him a Nicaraguan hero.

The irony of the whole affair is that Juan Santamaria's body is almost certainly impossible to find. The peasant soldier wasn't made a legend for setting fire to Walker's headquarters until 30 or more years after his death in battle.

He was buried in a common grave in 1856 and the humble hero now could never be positively identified.

The Nicaraguans dug themselves into a hole by depending on highly unreliable oral tradition as to where the mass grave of the heroes of 1856 was, then excavating a niche at Rivas' San Francisco church that somebody remembered as Santamaria's.

The Nicaraguans claimed that a mark on one of the niche's bricks looked like a "J.S.," but nobody else can find those letters in the symbols that some consider a brickmaker's mark or the Greek letter "psi."

The Costa Rican experts believe that particular set of bone chips belonged to a priest.

As for the remains of the 137 other corpses from the battle, there was only one piece of one femur to identify them, the other bits being the famous animal bones.

What the Nicaraguans actually turned over to Costa Rica, in fact, were three handfuls of fragments, according to Snarskis--not enough to make one whole body, an identifiable Juan Santamaria, much less a collection of more than 130 heroes.

"It would have been better to take a handful of symbolic dirt and bury that," said Snarskis.

But Nicaragua wanted more, and Costa Rica as Snarskis put it, "wasn't interested in a purely symbolic gesture. They had to have the real thing or nothing."