Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ERROR);
- /**
- @@description Calcular peso atomico
- @@author Jefrey S. Santos
- */
- /*
- vetor: 3 dimensoes, index pascal-like
- ELEMENTO[Z] (
- [1] (
- [mass]=X
- [abund]=Y
- )
- [2] (
- [mass]=X
- [abund]=Y
- )
- )
- flat database:
- Z|1|x|Y
- Z|A|X|Y
- */
- $z_this = 0;
- function calc($vetor) {
- global $z_this;
- $j = sizeof($vetor);
- $sup = 0;
- #for($i=1; $i<=$j; $i++) {
- foreach($vetor as $array) {
- #print_r($vetor);
- #$array = $vetor[$i];
- #print_r($vetor);
- $cache = $array['mass']*$array['abund']; // vai calculando a parte superior da fração
- $sup += $cache;
- }
- $result = $sup/100;
- $z_this++;
- echo "\n\nElemento Z = $z_this\n$sup/100 = $result";
- return true;
- }
- function _main($table) {
- $table = str_replace(",", ".", $table);
- $mainarr = array();
- $elements = explode("\n", $table); // linha a linha
- foreach($elements as $elemento) {
- $elem = explode("|", $elemento); // explodir pra vetor
- $z = $elem[0];
- $a = $elem[1];
- $x = $elem[2];
- $y = $elem[3];
- #$mainarr[$z] = array(); NAO MUDAR! SE MUDAR EXPLODE! FUNCIONANDO!
- $mainarr[$z][$a] = array(
- 'mass' => $x,
- 'abund' => $y // PoG - Programacao Orientada a Gambiarra
- );
- #print_r($mainarr[$z]);
- }
- #print_r($mainarr);
- return $mainarr; // nao sei como, mas esta funcionando
- }
- function gasolina($todo_o_vetor) { // joga cada array dentro da func calc
- $j = sizeof($todo_o_vetor); $i = 1;
- #print_r($todo_o_vetor);
- #while($i<=$j) {
- foreach($todo_o_vetor as $esse_vetor_aqui) {
- calc($esse_vetor_aqui);
- $i++;
- }
- return true;
- }
- $database = file_get_contents("database.txt");
- $myarr = _main($database);
- ob_start();
- gasolina($myarr);
- $buffer = ob_get_clean();
- echo '<pre>'.str_replace(".", ",", $buffer).'</pre>';
- exit;
- ?>
Add Comment
Please, Sign In to add comment