File: load_templates.pl

package info (click to toggle)
eccodes 2.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,404 kB
  • sloc: cpp: 162,953; ansic: 26,308; sh: 21,742; f90: 6,854; perl: 6,361; python: 5,172; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 283; xml: 183; awk: 66
file content (130 lines) | stat: -rwxr-xr-x 3,040 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/local/apps/perl/current/bin/perl -I/usr/local/lib/metaps/perl -I.

use confUtils;
use Getopt::Long;
use strict;

my %res=();

#The confluence space
my $confSpace="ECC";

#---------------------------------
# Read arguments
#---------------------------------

GetOptions("confSpace=s" => \$confUtils::confSpace)
    or die("Error in command line arguments\n");

print "confluence space=".$confUtils::confSpace."\n";

#----------------------------------
# Dirs
#----------------------------------

#The root dir of the examples
my $inFile="../definitions/bufr/templates/BufrTemplate.def";

#The genareted html files are stored here
my $htmlDir=$ENV{TMPDIR}."/res_html";

#--------------------------------------------------
# The confluence pages
#--------------------------------------------------

#The root page of templates in confluence!!!
my $pageTitle="BUFR templates";
my $parentPage="";

#----------------------------------------
# Preparations
#----------------------------------------

unless ( -d  $htmlDir ) {
    mkdir $htmlDir  
}

#---------------------------------------------------
# Read the templates file
#---------------------------------------------------

read_templates();

#---------------------------------------------------
# Generate confluence tabel
#---------------------------------------------------

my $fOut=$htmlDir."/bufr_templates.html";
open(OUT,">$fOut") or die "$fOut: $!";

print OUT "<p>ecCodes provides a simple way to define the structure of a BUFR message using the key \"BufrTemplate\".<br />
Here are all the available values for this key:</p><br />";


my $header="Teplate name</th><th>Unexpanded descriptors</th>";
      
print OUT "<table><tbody>"."\n";
print OUT "<tr><th>Template name</th><th>Unexpanded descriptors</th></tr>\n";

foreach my $name (sort {$a cmp $b} keys %res) {

    #Get the examples
    my @desc=$res{$name};

    print OUT "<tr><td>$name</td><td>".$res{$name}."</td></tr>\n";
    print  "$name--> $res{$name}\n";
}

print OUT "</tbody></table>"."\n";   

close(OUT);

#Upload to confluence
confUtils::loadToConf($fOut,$pageTitle,$parentPage); 


#==========================================================
#===========================================================
#
# FUNCTIONS
#
#===========================================================
#===========================================================

sub read_templates {

    #my %res=();
    my $fIn=$inFile;
    open(IN,"<$fIn") or die "$fIn: $!";
    
    my $line;   
    my $actType;
    
    while (defined ($line = <IN>)) {
        chomp($line);
        if ($line =~ /.*#/) {next;}
        
        #print $line."\n";
    
        $line =~ s/\s+//g;
    
        #print $line."\n";
        my @desc;
        my ($a,$b)=($line =~ /\"(\S+)\"=\{unexpandedDescriptors=(\S+);\}/);
        
        unless ($a) {next;}

        $res{$a}=$b;

        my ($c) = ($b =~ /\[(\S+)\]/);
        if($c) {
            $res{$a}=$c;
        }

        #print "    ".$res{$a}."\n";
    }
    
    close(IN);
}