Try also
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
int main()
{
vector < pair < int, double> > vp;
multimap<int, double> mm;
string line;
getline(cin, line);
for (;;)
{
int id,z;
double tke, y, yerror;
cin >> id >> z >> tke >> y >> yerror;
if ( ! cin ) break;
mm.emplace( id, y);
}
auto it_begin = mm.begin();
while (it_begin != mm.end() )
{
auto it_end = mm.upper_bound(it_begin->first);
auto sumfun = [] (double a, pair < int, double> p) {return a + p.second;};
double sum = accumulate(it_begin, it_end, 0.0, sumfun);
vp.push_back( make_pair(it_begin->first, sum));
it_begin = it_end;
}
cout << "id ysum" << endl;
for (auto p : vp)
cout << p.first << " " << p.second << endl;
}
Run it redirecting your data file as standard input.
Used with the following input data
A Z TKE Y Yerror
118 46 140.0 0.3326E-03 0.6799E-04
118 45 140.0 0.9057E-04 0.1851E-04
118 47 140.0 0.9122E-04 0.1864E-04
119 46 140.0 0.7077E-04 0.2217E-04
119 45 140.0 0.5748E-05 0.1800E-05
119 47 140.0 0.6486E-04 0.2032E-04
120 47 140.0 0.3259E-03 0.7113E-04
120 46 140.0 0.1016E-03 0.2217E-04
120 48 140.0 0.7759E-04 0.1694E-04
It produces the output
id ysum
118 0.00051439
119 0.000141378
120 0.00050509