In an atmosphere of hope tempered by bloody experience, the people of Guatemala vote Sunday to choose a civilian president assigned to lead them out of 31 harsh years of direct or indirect military rule.

The election, which also picks mayors and 100 Legislative Assembly members, has been hailed by Guatemalan politicians and U.S. diplomats as a way to bring this country into the lineup of U.S.-oriented Central American nations with democratic institutions to confront the example of Nicaragua's Marxist-led revolution.

It also has come to represent what they describe as a hope of imposing civilian controls on military officers whose ruthless tactics against leftists and their suspected sympathizers have made this country's human rights record the worst in the region.

Gen. Oscar Humberto Mejia Victores, the chief of state who seized power from another general in a coup Aug. 8, 1983, repeatedly has pledged to turn over the presidency to whoever is elected and to keep the Army out of government.

The major presidential candidates have expressed confidence that Mejia and his officer corps sincerely intend to relinquish authority on inauguration day, Jan. 14.

The 30,000-man Guatemalan Army, after ruling directly or indirectly since a CIA-orchestrated coup in 1954, apparently has concluded it cannot manage Guatemala's economic crisis and defeat a long-simmering leftist guerrilla movement without the popular support a civilian government could bring, the candidates said.

Also in the background is a promise of renewed U.S. military aid, suspended in 1977 because of Guatemala's refusal to accept human rights conditions. Since then, except for some spare parts purchases, U.S. military aid has been restricted to $455,000 in 1985 for training.

On the promise of Sunday's vote, the Reagan administration has won congressional approval of a $10 million credit in 1986 for purchase of nonlethal U.S. military equipment, with helicopters a top priority. But Congress accompanied its approval with stipulations that no money can be handed over until a civilian president takes power and the Reagan administration certifies an improved human rights record in the Army.

Human rights groups have estimated that more than 50,000 Guatemalans have been killed and more than a million displaced from their homes since 1980 in the Army's drive to control remote areas and make sure the guerrillas cannot get help from peasants. In addition, the Inter-American Human Rights Commission has estimated that about 80 persons a month disappeared last year alone in abductions widely attributed here to the military.

At least two mayoral candidates have been killed in this fall's campaign.

The two leading candidates, Christian Democrat Vinicio Cerezo and Jorge Carpio of the National Center Union, have pledged to improve human rights controls. But neither has advocated efforts to punish officers responsible for the country's long history of killing.

"We are not going to be able to investigate the past," Cerezo said in an interview. "We would have to put the entire Army in jail."

Carpio, in a conversation with correspondents, said: "It is the judicial power that will have to take care of these matters." In the past, the courts have been unable to convict anyone for the thousands of killings and abductions.

Cerezo, whom many Guatemalan and foreign observers see as the front-runner, was challenged at the last moment to take a stronger stand. The Mutual Support Group, representing families of Guatemalans who were abducted by unidentified men thought to be police or military, occupied the capital's cathedral for the third day today to dramatize their repeated appeals for investigation into what happened to their relatives and urged Cerezo to take up the cause.

"Our homes, families and our very society have been and continue to be destroyed," the occupiers said in a statement.

The degree of authority the new president will enjoy over Army officers remains to be defined. Guatemalan political observers noted that the Army has been the font of power here for so many years that swift transition to genuine civilian authority is difficult.

"Certainly, holding general elections can be the first step to achieve a better situation in the country," the Guatemalan Catholic Bishops Conference said in a pastoral letter. "But to be achieved with the hoped-for success, this requires not only freedom at the moment of voting, but also a whole series of social, political and economic conditions that unfortunately are not prevalent in Guatemala."

In addition, the Army over the years has assumed tight control of local administration as well as the central government. The main mechanism for military control at the local level is the committees known as interinstitutional coordinators in the country's 22 zones, headed by the regional Army commanders.

Cerezo pledged to get Army commanders out of these committees except as consultants for security matters. He also said he would disband the National Police's Technical Investigations Department, which he and other sources have pinpointed as responsible for many abuses; order more careful Army tactics against guerrillas; and bring the Army budget under civilian scrutiny.

Asked whether such measures were realistic given Guatemalan history, he replied: "If it can't be done, they will mount a coup d'etat against me."