* Siemens Gamesa shares down 18.2%, Siemens Energy down 13.5%

* Siemens Gamesa's second profit warning this year

* Company cites higher costs, COVID-linked delays (Adds details from sources, analyst comment)

MADRID, July 15 (Reuters) - Shares in Siemens Gamesa fell more than 18% on Thursday after the wind turbine maker's second profit warning in less than three months due to spiralling raw materials prices and the cost of delivering its new onshore platform.

The warning of a possible loss this year had a knock-on effect on parent Siemens Energy, which owns 67% of Siemens Gamesa. Its shares fell 13.5% as it will now miss its own profit margin target.

The warning about raw materials prices, exacerbated by the pandemic, also hit shares in rivals such as Denmark's Vestas , the world's largest maker of wind turbines, which fell 6.5%, while smaller German rival Nordex fell 4.9%.

The ongoing failure to keep costs under control might cause Siemens Energy to consider a full takeover of its Spanish-listed subsidiary and end an arm's length relationship that has limited its influence, two people close to the matter said.

Siemens Gamesa has lost almost a third of its market value so far this year, extending losses that began in January with a sector-wide fall in renewable energy stocks. At current share prices, the remaining 33% stake would cost Siemens Energy around 5 billion euros ($5.9 billion).

A spokesperson for Siemens Energy declined to comment, referring to comments made by Chief Executive Christian Bruch in May, who said it was too early to talk about a full takeover but that it would become an issue at some point.

ONSHORE CHALLENGE

Siemens Gamesa is the world's biggest maker of offshore wind turbines, an industry set to benefit from featuring in the plans of some of the world's biggest economies to cut carbon emissions.

But its achilles heel is the escalating cost of development of its 5.X onshore wind turbine platform, especially in Brazil, where the company has complained of supply chain shortfalls and logistical bottlenecks.

"While we like Siemens Gamesa's strong position in the fast-growing offshore wind market, the challenging performance on the onshore wind casts a significant dark cloud over Siemens Gamesa's equity story," Bernstein analysts wrote.

Siemens Gamesa CEO Andreas Nauen said he remains optimistic that the company could reach a profit margin of 8-10% but the timing could slip from 2023 to 2024.

In recent months, the company has pushed harder to pass on the rising costs of materials such as steel to its customers, he added: "Of course, (customers) do not happily discuss that, it's clear... it's also clear that in light of the size of the increases it cannot stay with us," Nauen said. ($1 = 0.8466 euros) (Reporting by Isla Binnie, Christoph Steitz and Alexander Huebner; Editing by Philippa Fletcher and Elaine Hardcastle)