Debian Codegraph @

biosig4c++/php/demo.php

raw symbols SCIP
1 #!/usr/bin/php
2 <?php
3
4 /*
5 #
6 # Demonstrates how the Header information of biosig data can be read through
7 # JSON header export
8 #
9 # References:
10 # [1] https://www.hl7.org/fhir/references.html
11 # [2] ÖNorm K2204:2015, GDF - A general data format for biomedical signals
12
13 Copyright (C) 2016 Alois Schloegl <[email protected]>
14 This file is part of the BioSig repository at http://biosig.sf.net/
15
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 3
19 of the License, or (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30
31
32 function ext() {
33 if (preg_match("/windows/i",php_uname())) return ".exe";
34
35 return;
36 }
37
38 /*
39 biosig_fhir_base64:
40 encodes a biosig file as a base64-encoded GDFv3.0 stream
41 */
42 function biosig_fhir_base64($filename) {
43 $h = popen('biosig_fhir' . ext() . ' -base64 "' . $filename.'"', 'rb');
44 $jsonhdr = stream_get_contents($h);
45 fclose($h);
46 return $jsonhdr;
47 }
48
49 /*
50 biosig_fhir:
51 makes a fhir_json_binary template
52 */
53 function biosig_fhir_json($filename) {
54 $h = popen('biosig_fhir' . ext() . ' -json "' . $filename.'"', 'rb');
55 $jsonhdr = stream_get_contents($h);
56 fclose($h);
57 return $jsonhdr;
58 }
59
60 /*
61 biosig_fhir_xml:
62 makes a fhir_xml_binary template
63 */
64 function biosig_fhir_xml($filename) {
65 $h = popen('biosig_fhir' . ext() . ' -xml "' . $filename.'"', 'rb');
66 $jsonhdr = stream_get_contents($h);
67 fclose($h);
68 return $jsonhdr;
69 }
70
71 /*
72 get header (meta) information
73 */
74 function biosig_json_header($filename) {
75 $h = popen('save2gdf' . ext() . ' -JSON "' . $filename.'"', 'rb');
76 $jsonhdr = stream_get_contents($h);
77 fclose($h);
78 return $jsonhdr;
79 }
80
81 /*
82 get header (meta) information in php array
83 */
84 function biosig_header($filename) {
85 return json_decode( biosig_json_header($filename) );
86 }
87
88 ## example file
89 $filename="data/Newtest17-256.bdf";
90
91 ## extract header information through JSON export
92 $HDR = biosig_header($filename);
93 var_dump($HDR);
94
95 ## extract fhir binary template
96 $BIN = biosig_fhir_base64($filename);
97 echo $BIN;
98 print "\n\n";
99
100 ## extract fhir binary template
101 $BIN = biosig_fhir_json($filename);
102 echo $BIN;
103 print "\n\n";
104 ?>
105