DHAHRAN, SAUDI ARABIA, JULY 19 -- After decades of trying to contain the size of the American military presence here and keep what did exist hidden from the outside world, Saudi Arabia has dramatically changed its attitude in face of what one senior Saudi official called "the clear and present danger" now posed to the kingdom by neighboring Iraq.

Suddenly the Saudis seem to have decided to go for broke in their often uncertain "special relationship" with the United States. They have opened the kingdom's doors to tens of thousands of American troops and allowed in at least 40 American journalists and as many non-American ones to splash the massive U.S. buildup across the front pages and television screens of the world.

They have apparently even agreed to U.S. command and control over American forces stationed here. The two governments have just signed an agreement dealing with this delicate issue of Saudi sovereignty.

While its details remain secret, Defense Secretary Richard B. Cheney told reporters today that American troops would continue to operate under the U.S. national command authority "consistent with our constitutional principles." But he said "arrangements" had also been made so that "we coordinate very closely with the Saudi government on the overall strategic guidance" of the multinational force being assembled.

To a reporter who first began visiting the kingdom in the mid-1970s, the turnabout in attitude of Saudi officialdom toward the presence of so many American soldiers -- and the publicity about it -- seems extraordinary.

Senior members of the Saudi royal family used to say that the best place for American warships and planes was "over the horizon" -- somewhere out in the Gulf of Oman where they could not be seen. The presence of American troops or military facilities on Saudi soil would only act as a lightning rod for trouble for the royal family in the rest of the Arab world, they said.

During the eight years of the Iran-Iraq war, Saudi officials politely turned away repeated American requests for a formal agreement guaranteeing access to Saudi military "facilities" similar to those signed by Oman and Somalia in the late 1970s to support the Rapid Deployment Force, now called the Central Command.

Prince Bandar bin Sultan, the Saudi ambassador to Washington, used to explain to reporters the Saudi reluctance in these terms: "We know you'll try to come to our rescue if there is trouble. But we don't know when. It might be too late. In the meantime, these facilities will have caused us a lot of political trouble in the Arab world."

U.S. behavior in Lebanon after the Israeli invasion in 1982 sent shivers down the spines of the royal family, raising fears of an American abandonment at a time of crisis. Saudis noted that one day President Ronald Reagan was calling the strategically situated village of Suq al Gharb overlooking Beirut "a vital American interest" that U.S. forces in Lebanon had to help the Lebanese army defend. A week later, he was ordering the "redeployment" of all U.S. troops in Lebanon out of harm's way, onto ships in the Mediterranean.

But now the Saudis seem to have overcome all these bad memories and doubts about American steadfastness in the face of Iraq's most serious threat to the kingdom and the ruling House of Saud. Similarly, their diplomatic inhibitions toward any publicity about the American military presence have been cast aside -- for now anyway.

Furious about Iraqi President Saddam Hussein's duplicitous behavior toward the kingdom and comforted by the broad Arab and international support for their cause, the Saudis seem ready to support a U.S.-led armed confrontation with Iraq even if that could embroil them, too.

Asked to assess the potential benefits and liabilities of the highly publicized U.S. presence here, a senior Saudi offical who once was a leading doubter replied, "Now I think the benefits far outweigh the liabilities."

The quick American deployment of forces and the broad public American support for the new U.S. commitment in the gulf, he said, were "a tremendous morale booster" for the kingdom.

"The reluctance we had in the past is not there anymore," the official said, referring to the U.S. presence here. He also noted that there had previously been "a similar reluctance" on the part of many Americans toward any closer relationship with an extremely conservative Islamic state like Saudi Arabia.

The U.S.-Saudi "special relationship" dates back to 1945 and is the longest enduring alliance the United States has with any Middle East nation. From the start, the motivating interests of both have been oil and national security.

The alliance began with a meeting in 1945 between President Franklin Roosevelt and King Abdel-Aziz, better known abroad as Ibn Saud, aboard the cruiser USS Quincy in the Great Bitter Lake north of Suez, Egypt.

By then, the Arabian American Oil Company (Aramco), which later became the world's largest producing company, was already pumping oil and the United States had built one of the kingdom's first airfields here in Dhahran.

It is the same airfield, though vastly expanded, where the American transport planes are now disgorging thousands of troops and tons of war materiel in the biggest and quickest U.S. military buildup since Vietnam.

After World War II, the Saudis allowed the Americans to lease the Dhahran air base as part of its global containment policy toward the Soviet Union. Until 1961, when the lease was canceled, it was an important link in the worldwide U.S. network of bases.

Since then, Saudi-American relations have had serious ups and downs over U.S. support for Israel, Washington's failure to solve the Palestinian issue and repeated battles in Congress over arms sales to the kingdom.

In the mid-1980s, the "special relationship" appeared to be eroding and not so "special" anymore. The Saudis began turning to Britain, France and even China for tens of billions of dollars of arms purchases, threatening the exclusive American position and undermining the extensive web of U.S.-Saudi security ties built up over four decades.

But Washington's decision in 1987 to provide protection and the U.S. flag for 11 Kuwaiti tankers threatened by Iran reversed the deterioration in relations and overcame Saudi doubts that the kingdom might become "another Lebanon," abandoned by its American ally in a crisis.

Despite Iran's threats and a few U.S.-Iranian clashes in the Persian Gulf, Washington held to its Kuwaiti commitment and in the process was able to expand its secret security cooperation with Saudi Arabia, which allowed it to base five radar planes in Riyadh to provide surveillance of Iran's military movements. The Saudis also allowed U.S. warplanes and ships quietly to make occasional use of Saudi airfields and ports.

The Saudis insisted that all their cooperation be kept secret for fear of Iranian retaliation and Arab accusations of collaboration with Israel's main Western supporter. Visas for American journalists, always rare, became even rarer in the late 1980s.

Just how this conservative Islamic society will adjust to a likely longterm major U.S. presence remains to be seen. One senior Saudi official said Saturday he thought much would depend on how the American troops conduct themselves, "particularly in this kingdom" -- a clear reference to the fact that alcohol is forbidden here, women veiled and "off-limits" to Western men and dancing frowned upon.

But he noted that since Saudi Arabia had no colonial history, "there is no background of mistrust and bad treatment by Westerners."

"Saudi Arabia," he said, was "determined that no misunderstandings will arise." He also suggested that everyone was likely to be so busy in the coming weeks that there would be "very little occasion for misunderstanding or misconduct."

As for the problem of R & R for the American soldiers gathering here, the official thought for a moment and replied, "They'll have to find it somewhere else, perhaps outside the kingdom."