WHEN John Wayne died last year, the western movie was in such a sorry state that it seemed to have followed his example.

For more than two decades, the western has been limping off toward the horizon like Shane, bleeding from a fatal wound in the box office.

In 1958, Hollywood made 54 cowboy movies -- 28 percent of the industry's product. Last year, only five were made. And the closest thing to a western now on television, which carried 26 prime-time westerns in 1958 (seven of which were among the top 10 shows that season), is "Little House on the Prairie."

But perhaps the old warhorse is only being turned out to pasture -- to be recalled to service at the last minute, just before the fadeout.

That could happen, if any of the 15 or so westerns currently planned by Hollywood returns a profit.

Four major films are scheduled for release this summer. Opening here on Friday is Walter Hill's outlaw saga "The Long Riders," with real-life brothers like James and Stacy Keach and the three Carradines (Keith, David and Robert) playing the James brothers and the Youngers.

That will be followed by the nationwide release of "Tom Horn," Steve McQueen's troubled production recounting the last years of the famous Indian scout, Pinkerton agent and stock detective.

By mid-summer we'll have Charlton Heston and Brian Keith in "The Mountain Men," from a script about early trappers written by Heston's son Fraser, and Burt Lancaster as Big Bill Doolin in "Cattle Annie and Little Britches," the story of two girls who joined up with the Doolin-Dalton gang.

And straddling the autumn release schedule like a cornered grizzly is Michael Cimino's $30-million epic "Heaven's Gate," set in 1892 when the cattle companies mounted an invasion of Johnson County, Wyo., to stamp out rustling among small stockmen. It's millions and years over schedule. And by the time we see it -- after a p lanned $15-million promotion effort -- "Heaven Gate" may overtake "Cleopatra," "Apocalypse Now" and "Star Trek" as the most expensive movie ever made in the United States.

Poised in expectation are another half-dozen projects, everything from a spoof on old California -- George Hamilton as "Zorro, the Gay Blade" -- to a $20-million revival of "The Legend of the Lone Ranger." Two television movies are in the works; two Canadian westerns will be released here; an English production with American settings and stars (Martin Sheen and Sam Waterston in Egale's Wing) has already played some U.S. cities; and Ray Stark plans to produce a western based on the Eagles' album "Desperado." There would have been a movie about Belle Starr under way, but television beat United Artists to the draw with the recent TV movie starring Elizabeth Montgomery.

Hollywood has well over $100 million invested in current and future western projects, even though everyone agrees that westerns have been box-office poison for several years.

And not every company is willing to take the risk. A spokesman for 20th Century-Fox explained why they have no westerns planned: "Remember a picture called 'Comes a Horseman'?" (the Jane Fonda-James Caan box-office bomb of 1978). And a staffer at Warner Brothers, which is distributing "Tom Horn," says, "If a filmmaker that we really respect comes in and says that's what he wants to do, then we try to develop the property for him. But we're certainly not looking for westerns."

But other producers are convinced there's a change in audience tastes developing, that their cyclical industryis about to witness a resurgence of interest in the kind of action-filled, virtuous tales that made the American western a worldwide favorite.

"We just think the timing's right," says an executive at Hemdale -- a new producing company owned by a British distributor -- which produced "Cattle Annie and Little Britches." Hemdale plans to shoot another $5-million western later this year. "Westerns are coming back, without a doubt. Even more so now, within the context of what people feel about themselves and about this country.

"Westerns have more appeal to people as escapist material or as a morality play when things are a little bit rougher in their own collective lives."

Hemdale thought it prudent, just the same, to have a new musical score written for "Cattle Annie." Originally, veteran film composer Alex North was hired; now the film sports a contemporary country music sound. aCountry music is very "hot" in Hollywood, a fire recently fueled by the success of "Coal Miner's Daughter." Country music star Willie Nelson, in fact, will star in a western due to shoot in late summer -- as well as continuing with plans for "Red-Headed Stranger," a film based on his album.

Steven Bach, worldwide production chief at United Artists -- the company about to give us both "The Long Riders" and "Heaven's Gate" -- thinks the clearest indicator of a change is coming from writers and directors. "Creative people dictate what the public has to choose from, and there seems to be a burgeoning feeling among creative people that the western is a form that has been away too long."

Thus a director with a successul picture behind him, like Walter Hill; who directed "The Warriors," can satisfy an old craving to work in westerns by capitalizing on his own track record and the adventurousness of a new studio administration with not enough product in development. That was the economic situation which Hill thinks made "The Long Riders" possible. If Hill's film is a hit, every studio will want a western, at least until the first multimillion-dollar flop.

The stigma of the western is still apparent even at United Artists, where Bach is quick to point out that his company does not consider "Heaven's Gate" a western. "It's a period piece," he says, "like 'Gone With the Wind.'"

David Ward knows that some studios are still gun-shy. He wrote the screenplay for "The Sting," and has had a big western script circulating for a few years. It's about small farmers fighting the Southern Pacific Railroad over land rights in the San Joaquin Valley of California. "If it's got horses," he says, "they don't want it."

Ward and Hill are examples of how attitudes toward the western have changed over the years among filmmakers. Their desire to work in the genre is shared by many filmmakers who admire the western's scale and moral context. It's an affection that has grown precisely as the western's popularity has declined. Twenty-five years ago, when the western flourished, novice filmmaker Marlon Brando told Truman Capote that he was embarrassed to admit that his first independent production would be a western. (It was "One-Eyed Jacks," and he ended up directing it as well.) Brando's motive was money; his first picture needed to return a profit, and he thought a western was a sure thing.

Those were the days when Hollywood reminded critics that nobody liked westerns but the public. Now it seems to Hollywood that everybody but the public wants the western back.

If the western returns to any prominence, its resuscitation will be as puzzling as its decline. The Last Round-Up

Television contributed to the western's decline by overloading the public in the late '50s, but Hollywood itself helped hogtie the genre into a helpless paralysis of conscience that started in the mid-'60s. As writers and directors explored ever more complex and ambiguous themes through America's frontier, the western matured and its public turned elsewhere. For the simple satisfaction of seeing American virtue triumphant, audiences sought the paranoid heroes of thrillers and the fantasy of science fiction . . .

"The western got caught in the cycle of realistic films," David Ward thinks. "The debunking westerns tried to destroy the myth of the West by saying it wasn't what we thought it was. It was violent, ugly and brutal -- without any of the things we used to consider virtues, like morality, loyalty, courage."

That certainly describes the new look of westerns in the '60s, when the Sam Peckinpah emerged as a major talent with "Ride the High Country" and "The Wild Bunch." Greater authenticity of detail, more sex and explicit violence combined with a rereading of American history to turn America's favorite morality tale into a bloody skeleton in the nation's closet. The Indian Wars were portrayed as genocide in films like "Little Big Man." It was a change in perception that forever altered the significance of a vast body of American popular literature and film: John Wayne would never look the same.

There's a backlash now against that vision of the West, whatever its authenticity. And when directors and writers say they want to work in westerns, they're talking about the classical western of John Ford and even the simplistic boys' adventure B westerns that disappeared into television series.

Walter Hill, for instance, describes "The Long Riders" as situated "about 180 degrees different" from Philip Kaufman's excellent 1972 version of the James gang, a revisionist western that pictured Jesse as a psychotic killer. Hill thinks his own film is a "revisionist revisionist" western.

Out in New Mexico, a full-scale drama about the most famous of the B Westerners who made it to television is in production. William A. Fraker, the cinematographer who a decade ago directed the solemnly beautiful "Monte Walsh," is filming "The Legend of the Lone Ranger." Fraker clearly has his sights on a heroic epic, even going so far as to shoot some scenes in the mythic landscape of John Ford, Monument Valley.

Fraker recreated the opening scene of "Stagecoach," including the stunt Yakima Canutt made famous: dropping down between the lead horses and letting the coach pass over him. Stunt coordinator Jerry Gatlin, a veteran of John Ford and John Wayne films, cheerfully predicts that Fraker's film will be the "'Star Wars' of the western."

That's more than wishful thinking about box-office returns. "The Lone Ranger" is just the sort of simplified and nostalgic pulp material that, combined with mammouth production values, made "Star Wars" a blockbuster. It's the kind of western that pleads no message, just entertainment.

Science fiction, in fact, has succeeded the urban thriller as the western myth's chief refugee in the '70s. John Cawelti, who wrote one of the most perceptive studies of the western, "The Six-Gun Mystique," points out how the concerns of the western have passed to other forms of entertainment.

"For many people," he says, "the real frontier -- the place of strangeness and excitement and mystery -- is now the city more than the desert or the mountains. The heroic time of the West is past." But the myth lingers on, as indicated by the title of Paul Newman's urban western filming in New York, "Fort Apache, the Bronx."

Social historian Leslie Fiedler thinks the truest western of the past decade was "Star Trek." Not "Star Wars," which cannibalized all kinds of recognizable western images. "Star Trek," Fiedler says, "is that real masculine myth reborn. It even has the masculine bonding between Spock and Kirk, and the Klingons as the bad Injuns.

"But the real new western," he continues, "is 'Dallas.' The new image which Americans all over the country project on the old traditional western is no longer the image of the cowboy, but of the exploitative bastard of an entrepreneur like J.R.

"He's wearing the remnants of the traditional outfit and there's the ranch stretching out around him. But quite different things are happening.

"Larry Hagman seems to me to be at the center of everything. He's a mythological creature to begin with, being Mary Martin's son. And he really is a product of the true West."

One thing that science fiction and the entrepreneurial cowboy have over urban thrillers as a replacement for the western is some sense of a future. The western, in its innocence, worked because in constructing a heroic past, it justified whatever present that past produced. The urban western like "Dirty Harry" is in John Cawelti's words "a world of conspiracy and danger. "The only area at the present in which people can get away with the fantasy of good triumphant over evil is in far-out fantasy. You need to shove it into a very distant place" -- the world of the ultra-rich, perhaps, or outer space. It's hard, after all, to debunk the future.

The western's celebration of masculinity has also suffered a sustained assault in the last decade. "The confusion over sex roles," as John Cawelti points out, has made some of the western's enduring preoccupations -- a masculine code of honor, skill at mayhem, and male camaraderie on the trail -- seem irrelevant to a society where people are trying desperately to get along with the opposite sex, and to avoid sex-role stereotypes. The Right Stuff

So why anticipate a renewed interest in the western, if it can be so easily replaced and when many of its cherished values seem to have become obsolete?

Perhaps one answer is emerging in the mood of the electorate, as Ronald Reagan and Jimmy Carter appear to be heading for a showdown in November. The man of the West and the Southern agrarian fundamentalist stand for values and choices just as traditional to Middle America as the western's vision of what made the nation great. The pioneer spirit may be just the right backdrop for this year's campaign.

Many people, especially those old enough to have spent their childhood with B westerns and television series heroes from the '50s, believe that the public will return for "the right kind of western." And they believe that the genre is appealing enough in its "innocent" form to attract the young generation of filmgoers who have grown up without those western heroes.

Novelist Louis L'Amour, who should know a thing or two westerns, thinks the public will never desert them. His public certainly hasn't deserted him; he's about to celebrate his 100 millionth copy in print. "Films got away from what the western was really about," he says, "and that's opening up a country. Most Americans consider themselves westerners whether they are or not. They think of themselves in pioneer terms."

To novelist Tom McGuane, who wrote the screenplay for "The Missouri Breaks" and "Tom Horn," the western is "one of the primary American myths, a form of theater in which to talk about all the other things we're interested in. I can't imagine that the western is finished.

And though he was fired from "Tom Horn" because he refused to change his script in the direction that Steve McQueen wanted to take the character of the scout ("They wanted a real cosmetic job on some of the more unsavory aspects of Horn's character," McGuane says), McGuane himself longs for the support of a myth like the western.

"Don't you want to believe in Lincoln and Jesse James and Ulysses S. Grant? Don't you want something back there? I don't want to be out on the end of the diving board in the depths with no history."

History, like the frontier myth, dies hard, and can be revived in the right circumstances. "Times change," as United Artists' Steven Bach says. "I think there's a mood shift in the last six months that may provide for a return of heroic action in the movies. We've been seeing cowboys and Indians in Tehran."

With talk of John Wayne diplomacy and the thought of troopers crossing the desert to free captives taken by a swarthy enemy led by a formidable medicine man, we might just pause before we conduct a wake over the body of the cowboy, or speculate on his return.

It may be that the Masked Man has never wandered very far from our world at all.