Sonoma-Marin Area Rail Transit is poised to be the first rail line system in the country to start service completely outfitted with a safety system to prevent potentially deadly accidents, according to agency officials.

SMART has spent $50 million on implementation of what is known as a “Positive Train Control” system on the line from downtown San Rafael to the Santa Rosa Airport, which will see passenger service later this year.

The system essentially controls movements on the rails electronically to slow or stop trains before certain types of accidents could occur.

In SMART’s case, a fiber optic network is used to “talk” to the train system to prevent a train from moving while sitting in a turnout while another train passes, maintain safe speeds in curves to prevent derailments and to slow speeds in work zones where workers are present.

The system stops the train if an engineer fails to adhere to the software-programmed instructions. The system is also used by dispatchers to lower speeds when a grade crossing has been damaged.

“So if the engineer loses capacity to operate the train for some reason and becomes incapacitated, or if there is a criminal act of some type, the system ensures the safety of the train as it travels,” said Farhad Mansourian, the rail agency’s general manager.

Such a system could have prevented the deadly accident of Amtrak passenger train 188 in Philadelphia in May 2015, National Transportation Safety Board officials said last month. That train had entered a curve where the speed is restricted to 50 mph. But the train was traveling at 106 mph because the engineer was distracted and failed to slow the train. Eight passengers were killed and 185 others were transported to area hospitals. SMART’s top speed will be 79 mph.

SMART has just applied for $3 million from the federal government to have the safety system installed for the 2.1-mile extension from downtown San Rafael to Larkspur. The extension could open as soon as 2018.

In April, the U.S. Department of Transportation’s Federal Railroad Administration announced $25 million in grants for implementation of the safety system.

SMART will have to spend between $10 million and $12 million to operate the safety system on the downtown San Rafael to Larkspur extension and hopes to land the $3 million to augment the cost.

“The system is both software and hardware equipment,” Mansourian said.

In 2008, Congress required railroads to install the safety systems. Last October, Congress extended the original deadline to implement the system from Dec. 31, 2015 to at least Dec. 31, 2018. In theory, SMART could have delayed deploying the safety system until later to save money now.

“It’s an important safety feature and the SMART board saw its value,” Mansourian said.

The federal grant money is part of the 2016 Consolidated Appropriations Act that finances the U.S. Department of Transportation. The grant is competitive and there is no guarantee the money will come to SMART.

Federal rail officials will give preference to projects that would provide the greatest level of public safety benefits.

“Positive train control is a long overdue technology that prevents accidents and saves lives,” said U.S. Transportation Secretary Anthony Foxx in a statement. “These funds will help us get closer to implementing PTC, and I encourage applications that can make these limited dollars go as far as possible.”