HelloWorld: EGS.php

File EGS.php, 1.7 KB (added by /C=FR/O=CNRS/OU=UMR8607/CN=Christian Arnault/emailAddress=arnault@…, 12 years ago)
Line 
1<?php
2
3include ('Faisceau.php');
4include ('Cible.php');
5
6class Paramètres
7{
8  var $twiss;
9  var $énergie;
10
11  var $épaisseur;
12};
13
14$Paramètres = new Paramètres ();
15
16class Control
17{
18  function get_post ()
19    {
20      global $_GET;
21      global $Paramètres;
22
23      foreach ($_GET as $cle => $value)
24        {
25          //echo "[{$cle}]={$value}<br>";
26
27          $words = explode ('_', $cle);
28
29          $n = count ($words);
30
31          $classe = $words[0];
32          $champ = '';
33          if ($n > 1) $champ = str_replace ($classe . '_', '', $cle);
34
35          if (is_array ($value))
36            {
37              $str = "cle=($cle) _POST[{$classe}.{$champ}]=";
38            }
39          else
40            {
41              $Paramètres->$cle = $value;
42            }
43        }
44    }
45
46};
47
48class EGS
49{
50  function EGS ()
51    {
52    }
53
54  function run ($cible, $faisceau)
55    {
56      $sortie = $cible->interaction ($faisceau);
57
58      $string = '<pspa></pspa>';
59
60      $xml = new SimpleXMLElement($string);
61
62      foreach ($sortie as $f)
63        {
64          $c = $xml->addChild ("faisceau", $f->nom);
65          $c->addAttribute ("twiss", $f->twiss);
66          $c->addAttribute ("energie", $f->énergie);
67        }
68
69      echo $xml->asXML();
70    }
71};
72
73$control = new Control ();
74
75$control->get_post ();
76
77$xml = simplexml_load_file($Paramètres->data);
78
79$faisceau = $xml->faisceau;
80$Paramètres->twiss = (double) $faisceau['twiss'];
81$Paramètres->énergie = (double) $faisceau['energie'];
82$cible = $xml->cible;
83$Paramètres->épaisseur = (double) $cible['epaisseur'];
84
85$faisceau = new Faisceau ("", $Paramètres->twiss, $Paramètres->énergie);
86$cible = new Cible ($Paramètres->épaisseur);
87
88$EGS = new EGS ();
89
90$EGS->run ($cible, $faisceau);
91
92?>