~ubuntu-branches/debian/experimental/stellarium/experimental

« back to all changes in this revision

Viewing changes to plugins/Quasars/util/tsv2json.pl

  • Committer: Package Import Robot
  • Author(s): Tomasz Buchert
  • Date: 2012-05-18 13:26:18 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20120518132618-3uso09fo68c218cx
Tags: 0.11.2-1
* Imported Upstream version 0.11.1 and then 0.11.2 (Closes: #658431)
* Change maintainer (Closes: #668916)
* Machine-readable copyright file
* Bump Standards-Version to 3.9.3
* Update debhelper compat to 9
* Fix lintian duplicate-font-file warning
* Fix copyright-refers-to-symlink-license lintian tag
* Add lintian override for embedded-library error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# read quasars.tsv from VizieR and convert to JSON
 
4
#
 
5
 
 
6
$TSV    = "./quasars.tsv";
 
7
$JSON   = "./catalog.json";
 
8
 
 
9
open (TSV, "<$TSV");
 
10
@catalog = <TSV>;
 
11
close TSV;
 
12
 
 
13
open (JSON, ">$JSON");
 
14
print JSON "{\n";
 
15
print JSON "\t\"version\": \"0.1.1\",\n";
 
16
print JSON "\t\"shortName\": \"A catalogue of quasars\",\n";
 
17
print JSON "\t\"quasars\":\n";
 
18
print JSON "\t{\n";
 
19
 
 
20
for ($i=0;$i<scalar(@catalog);$i++) {
 
21
        if ($catalog[$i] =~ /^([a-zA-Z0-9]+)/) {
 
22
                ($name,$RA,$DE,$z,$Vmag,$bV,$Amag) = split(";", $catalog[$i]);
 
23
 
 
24
                ($hour,$min,$sec) = split(" ",$RA);
 
25
                $outRA = $hour."h".$min."m".$sec."s";
 
26
 
 
27
                ($deg,$min,$sec) = split(" ",$DE);
 
28
                $outDE = $deg."d".$min."m".$sec."s";
 
29
 
 
30
                $name =~ s/(\s{2,})//gi;
 
31
                $name =~ s/(\s)$//gi;
 
32
                $z =~ s/(\s+)//gi;
 
33
                $bV =~ s/(\s+)//gi;
 
34
                $Amag =~ s/(\s+)//gi;
 
35
                $bV =~ s/(\s+)//gi;
 
36
 
 
37
                # exclude quasar M 31
 
38
                if ($name ne 'M 31') {
 
39
                        $out  = "\t\t\"".$name."\":\n";
 
40
                        $out .= "\t\t{\n";
 
41
                        $out .= "\t\t\t\"RA\": \"".$outRA."\",\n";
 
42
                        $out .= "\t\t\t\"DE\": \"".$outDE."\",\n";
 
43
                        $out .= "\t\t\t\"z\": ".$z.",\n";
 
44
                        $out .= "\t\t\t\"Vmag\": ".$Vmag;
 
45
                        if ($Amag ne '') {
 
46
                                $out .= ",\n\t\t\t\"Amag\": ".$Amag;
 
47
                        }
 
48
                        if ($bV ne '') {
 
49
                                $out .= ",\n\t\t\t\"bV\": ".$bV;
 
50
                        }
 
51
                        $out .= "\n\t\t}";
 
52
 
 
53
                        if ($i<scalar(@catalog)-1) {
 
54
                                $out .= ",";
 
55
                        }
 
56
 
 
57
                        print JSON $out."\n";
 
58
                }
 
59
        }
 
60
}
 
61
 
 
62
print JSON "\t}\n}";
 
63
 
 
64
close JSON;