The movie version of "Hair" sobers up just in time to keep a last-reel rendezvous with greatness I can't recall another musical that took so long to discover and proclaim its sentimental essence - in this case an elegiac vision of generational camaraderie, perplexity and herocic sacrifice.

"Hair" closes with an emotional sure that one simply can't anticipate during the first 90 minutes or so, which are devoted to a hit-and-miss miscellany of production numbers inspired by the original Galt Mac-Dermot-Gerome Ragni-James Rado score. But when director Milos Forman and screenwriter Michael Weller finally succeed in giving the original amorphous libretto dramatic form and momentum, the effect seems miraculous.

Although the production never lacks energy or professionalism, many numbers fizzle out after coming on strong. Pictorial dynamism sustains an occasional song, like the brash crowd-pleasing "I Got Life" bellowed and strutted by Treat Williams as the sly hippie leader Berger

There are highlights, but they flare up and burn out quickly. A dramatic structure is needed to preserve and enhance their effectiveness. At the start it's only dimly suggested in the funny, intuitive rapport that develops between Williams and John Savage. Savage is cast as Claude, the straight-arrow interloper in the hippies' Central Park domain, a shy kid from Oklahoma supposedly on a brief vacation prior to enlistment in the Army.

Later, when Forman and Weller recognize how this rapport can be manipulated for dramatic purposes, you regret the failure to concentrate on the oddball friend-ship of these incongruous but fundamentally gallant young men from the very beginning.

Despite its status as a music rabble-rouser and blockbuster, "Hair" always cried out for a playwright. The Ragni-Rado book reads like gibberish. Now the

Zeitgeist that sheltered and humored the gibberish, not to mention the calculated affronts aimed at middle-class theatergoers - notorious, innocuous nude scene and the inane lyrics to "songs" like "Sodomy" - has faded into social history. It was widely assumed that the movie version was a risky attempt to revitalize a period piece, and until blessed by inspiration, the filmmakers do indeed struggle.

The turning point is easy to indentify. It coincides with the entrance of an electrifying young blues singer named Cheryl Barnes. She plays a character wholly invented by the filmmakers; the estranged girlfriend of Hud, a black hippie played by Dorsey Wright.

Barnes, who has a child by her runaway boyfriend, suddenly confronts him in a scene set in Washington Square. Refreshingly unhip, she reminds him of his obligations. Their argument gives the film its first whiff of intimate emotional conflict. Suddenly the rejected world of old ties and obligations imposes itself forcefully and irrevocably on Berger's group of dropouts.

Rebuffed by Hud and shocked at the idea that he may have impregnated the ingenuous groupie Jeannie (Annie Golden), the young woman expresses herself in song. Barnes' powerful rendition of "Easy to Be Hard" holds you transfixed. It's a long solo, but you don't want the camera to budge from her gravely dignified, ardent image. She makes the case for conventional loyalties and duties with a resolute, heartfelt pride.

Forman does allow his attention to stray from Barnes. He can't resist a superfluous closeup of her little boy with a tear glistening on his cheek. The more defensible secondary view-point reveals Berger in pantomine trying to persuade Hud to patch things up. Yhe upshot is that he succeeds. At the same time the movie itself seems to acquire in urgent, conciliatory sense of purpose.

The inadvertent reunion between Hud and his neglected straight family coincides with a Berger scheme to reunite with Claude, now stationed at a base in the Mojave Desert. The pretext for being in Washington Square was a meeting with Sheila (Beverly D'Angelo), a wealthy suburban girl drawn into Berger's group the previous autumn when Claude saw her riding horseback in Central Park and fell in love at first sight. When she reads a letter from Claude, Berger gets an irresistible impulse to drive out west with the whole gang for one last fling before Claude is sent overseas.

The consequences of this freindly, playful impulse put Berger in the appealing heroic tradition of Dickens' Sydney Carton.

In retrospect it's apparent that all those early tentative moments between Williams and Savage should have been expanded, even if that meant junking a favorite song or fancy production number.

Even during the aimless stages of the movie, when the continuity seems to ricochet from one production number to the next, it's obvious that this "Hair" is being controlled by more skeptical sensibilities than those dominating the theatrical production.

If the movie catches on in a big way - and audiences who are patient with the film may feel very touched by its powerhouse finish - "Hair" may be impossible to revive in its old theatrical form. An attempted Broadway revival flopped last year. Now any projected revivals may have to incorporate some of the dramatic improvements made by Forman and Weller.

The self-congratuatory aspects of the counterculture are now subject to humorous undercutting. Forman and Weller recognize how much Berger's independent lift style depends on the good will, generosity or acquiescence of middle-class squares. Even berger's bad manners at the suburban dinner party which provides the setting for "I Got Lift" delight as many guests as they scandalize. His exuberant effrontery sums up the popular appeal of "Hair" itself.

Ultimately, the most satisfying numbers in the film are those with the simplest visual and fhythmic designs: Cheryl Barnes on "Easy to Be Hard" and the beautifully backlit traveling shots chosen for "Good Morning Starshine," sung on the open road as the gang drives toward the reunion with claude.

The least satisfying numbers are the halluncinatory interludes that seem to pay apologetic homage to Tom O'Horgan and Ken Russell. Twyla Tharp, whose writhing, loping, herky jerky choreography is sprinkled through the production to no particular advantage or disadvantage, turns up as a solo contortionist in the most elaborate set piece, supposedly trigered by a dose of LSD. I suppose that would explain a lot of kitschy bummers, but all the same. . . .

Treat Williams stood out in Richard Lester's misguided film version of "The Ritz" playing it deadpan and innocent. His scroungy, ruggedly amiable Berger will probably be a ticket to stardom. Follish, generous rebels armed with robust pysicality, wicked sidelong glances and broad, infectious grins are hard to resist.

As a virginal small-town boy in "The Deer Hunter," John Savage projected a downright pathetic vulnerability. As Claude he's awkward and tongue-tied, but he also reveals a wiry streak of toughness and sneaky flickers of humor.

Annie Golden recalls Hayley Mills in her teens, only transformed into a cherubic hippie cheerleader. Her round mug, curly hairdo, upturned nose and snaggletoothed smile combine to give her an endearingly distinctive presence. D'Angelo projects a fresh, subdued beauty. She resembles Faye Dunaway with a healthily fleshed-out face and physique, but the aura she brings to Sheila is closer to the illusion Kim Novak used to create, an ignorant but oddly touching sort of feminine ripeness.

At its best this film musical reaf-films the evocative power of astutely simple dramatic and melodic appeals. Forman and Weller have restored a soul to a nealy moribund show.