diff --git a/api/src/Page/DC.php b/api/src/Page/DC.php index fac976dd0..0bd246e36 100644 --- a/api/src/Page/DC.php +++ b/api/src/Page/DC.php @@ -1212,24 +1212,6 @@ function _mca($id) $this->db->close(); $data = array(array(), array()); - if (file_exists($info['DAT'])) { - $dat = explode("\n", file_get_contents($info['DAT'])); - - foreach ($dat as $i => $d) { - if ($i > 2 && $d) { - list($e, $v) = preg_split('/\s+/', trim($d)); - if ($i % 2 == 1) { - if (floatval($e) <= $info['ENERGY']) { - if (floatval($e) > ($info['ENERGY'] - 1100)) - array_push($data[1], array(floatval($e), floatval($v))); - else - array_push($data[0], array(floatval($e), floatval($v))); - } - } - } - } - } - # pymca $results = str_replace('.mca', '.results.dat', preg_replace('/(data\/\d\d\d\d\/\w\w\d+-\d+)/', '\1/processed/pymca', $info['DIR'])); @@ -1238,23 +1220,56 @@ function _mca($id) $elements = array(); $el_no_match = array(); $max_counts = 0; + $line_number = 0; + $max_elements = 5; + $compton_cutoff = $info['ENERGY'] - 1100; if (file_exists($results)) { $dat = explode("\n", file_get_contents($results)); - foreach ($dat as $i => $d) { - if ($i < 5) { + foreach ($dat as $d) { + if (empty($d) || strpos($d, '#') === 0) { + if (strpos($d, 'COMPTON_CUTOFF_EV') !== false) { + $parts = explode('COMPTON_CUTOFF_EV', $d); + $compton_cutoff = floatval(trim($parts[1])); + } + continue; + } + if ($line_number < $max_elements) { $l = explode(' ', $d); - if ($i == 0) + if ($line_number == 0) { $max_counts = floatval($l[1]); + } if (array_key_exists($l[0], $el_to_en)) { $els = $el_to_en[$l[0]]; - if (($els[sizeof($els) - 1] * 1000) < ($info['ENERGY'] - 1000)) - $elements[$l[0]] = array(array_map('floatval', $els), floatval($l[1]), floatval($l[2])); - } else + $elements[$l[0]] = array(array_map('floatval', $els), floatval($l[1]), floatval($l[2])); + } else { array_push($el_no_match, $l[0]); + } + $line_number++; + } else { + break; } } } + + if (file_exists($info['DAT'])) { + $dat = explode("\n", file_get_contents($info['DAT'])); + + foreach ($dat as $i => $d) { + if ($i > 2 && $d) { + list($e, $v) = preg_split('/\s+/', trim($d)); + if ($i % 2 == 1) { + if (floatval($e) <= $info['ENERGY']) { + if (floatval($e) > $compton_cutoff) + array_push($data[1], array(floatval($e), floatval($v))); + else + array_push($data[0], array(floatval($e), floatval($v))); + } + } + } + } + } + array_push($data, $elements); array_push($data, $el_no_match); array_push($data, $max_counts);