$index += $pm_count - 1; $cols[0] = trim(skip($cols[0], " ", 4 * ($pm_count - 1))); echo $cols[0] . "\n"; } if ($index == 1) { $z = $cols[0]; } if ($index == 6) { $mu = (double) $cols[0]; $dmu = trim(substr($cols[0], strpos($cols[0], "±") + 2)); } if ($index >= $length - 1) { $index = 0; $columns[] = array($z, $mu, $dmu); } else { ++$index; } } } $columns = array(); extract_columns($columns, 'sn_data1.csv', 8); extract_columns($columns, 'sn_data2.csv', 7); file_put_contents('sn_raw.res', ''); file_put_contents('sn.res', ''); foreach ($columns as $column) { $z = $column[0]; $d = 0.0002261568 * pow(10, ($column[1] + 5) / 5) / 1000000.0; $dd = log(10) / 5 * $d * $column[2]; file_put_contents('sn_raw.res', "{$z} {$column[1]} {$column[2]}\n", FILE_APPEND); file_put_contents('sn.res', "{$z} {$d} {$dd}\n", FILE_APPEND); }
foreach ($labels as $i => $label) { if (trim($label) == $column) { $column_numbers[$n] = $i; } } } foreach ($lines as $k => $line) { if ($k == 0) { continue; } $data = explode('|', $line); $entry = array(); foreach ($column_numbers as $j => $cn) { $entry[$j] = trim($data[$cn]); } $entries[$k] = $entry; } return $entries; } $entries = extract_columns(array('redshift', 'sn_mag', 'sn_type', 'sn_qmag', 'sn_gal_uncert', 'sn_mband')); file_put_contents('sn.res', ''); $count = 0; foreach ($entries as $entry) { if ($entry[0] > 0 && $entry[1] > 0 && $entry[2] == 'Ia' && $entry[3] != 'uncertain' && $entry[4] != 'uncertain' && $entry[5] != 'undef') { ++$count; $z = $entry[0]; $d = 0.0002261568 * pow(10, ($entry[1] + 19.3 + 5) / 5) / 1000000.0; file_put_contents('sn.res', "{$z} {$d}\n", FILE_APPEND); } } echo "Entries: {$count}\n";