| 1 |
#!/usr/bin/env perl |
| 2 |
# (C) Copyright 1996-2016 ECMWF. |
| 3 |
# |
| 4 |
# This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
# In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
# granted to it by virtue of its status as an intergovernmental organisation nor |
| 8 |
# does it submit to any jurisdiction. |
| 9 |
|
| 10 |
|
| 11 |
use XML::Parser; |
| 12 |
use Time::localtime; |
| 13 |
|
| 14 |
my $file = shift; |
| 15 |
my $dir = shift; |
| 16 |
my $Author="MagicsTeam"; |
| 17 |
my $ecmwf="http://wms.ecmwf.int"; |
| 18 |
my $info = {}; |
| 19 |
my $element = {}; |
| 20 |
|
| 21 |
my %links = ( |
| 22 |
'psetr'=> [ 'Magics_using', 'Single_Parameter_Setting'], |
| 23 |
'pset1r'=> [ 'Magics_using', 'Array_Parameter_Setting'], |
| 24 |
'pset1c'=> [ 'Magics_using', 'Array_Parameter_Setting'], |
| 25 |
'pset1i'=> [ 'Magics_using', 'Array_Parameter_Setting'], |
| 26 |
'psetc'=> [ 'Magics_using', 'Single_Parameter_Setting'], |
| 27 |
'pseti'=> [ 'Magics_using', 'Single_Parameter_Setting'], |
| 28 |
'preset'=> [ 'Magics_using', 'table_single_param_reset_routines'], |
| 29 |
'pcoast'=> [ 'Magics_layout_mapping_coastlines', 'pcoast_tables'], |
| 30 |
'pcont'=> [ 'Magics_contour', 'pcont_tables'], |
| 31 |
'ptext'=> [ 'Magics', 'Text_Plotting_Parameters'], |
| 32 |
'pwind'=> [ 'Magics', 'Wind_Plotting_Parameters'], |
| 33 |
'pgrib'=> [ 'Magics_data', 'pgrib_tables'], |
| 34 |
'pnew("PAGE")'=> [ 'Magics_layout_mapping_coastlines', 'Pseudo_Action_Routine_PNEW'], |
| 35 |
); |
| 36 |
|
| 37 |
my %ulinks = ( |
| 38 |
'pobs'=> [ 'Magics', 'Observation_Plotting_Parameters_1'], |
| 39 |
); |
| 40 |
|
| 41 |
my %magmls = ( |
| 42 |
|
| 43 |
); |
| 44 |
|
| 45 |
my $linkmagml; |
| 46 |
|
| 47 |
sub link_function |
| 48 |
{ |
| 49 |
my $action = shift; |
| 50 |
if ( ${$links{$action}}[0] ne "") { |
| 51 |
return "<function><olink targetdoc=\"${$links{$action}}[0]\" targetptr=\"${$links{$action}}[1]\">$action</olink></function>"; |
| 52 |
} |
| 53 |
|
| 54 |
if ( ${$ulinks{$action}}[0] ne "") { |
| 55 |
return "<function><ulink url=\"http://www.ecmwf.int/publications/manuals/magics/manuals/${$ulinks{$action}}[1].html\">$action</ulink></function>"; |
| 56 |
} |
| 57 |
|
| 58 |
return "<function>$action</function>"; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
sub magml_function |
| 63 |
{ |
| 64 |
# my $magml = shift; |
| 65 |
# if ( ${$magmls{$magml}}[0] ne "") { |
| 66 |
# return "<olink targetdoc=\"${$magmls{$magml}}[0]\" targetptr=\"${$magmls{$magml}}[1]\">$magml</olink>"; |
| 67 |
# } |
| 68 |
# else { |
| 69 |
return "<olink targetdoc=\"Magics_using\" targetptr=\"MagML_Interface\" >MagML</olink>"; |
| 70 |
# } |
| 71 |
} |
| 72 |
|
| 73 |
sub parse |
| 74 |
{ |
| 75 |
my $def = shift; |
| 76 |
my $node = shift; |
| 77 |
|
| 78 |
while ( defined ( $element = shift @{ $node } ) ) |
| 79 |
{ |
| 80 |
|
| 81 |
my $child = shift @{ $node }; |
| 82 |
if ( ref $child ) |
| 83 |
{ |
| 84 |
my $attr = \%{ shift @{ $child } }; |
| 85 |
my $name = $attr->{name}; |
| 86 |
|
| 87 |
if ($name ne "") |
| 88 |
{ |
| 89 |
|
| 90 |
$def->{$element}->{$name} = {}; |
| 91 |
my $list = $element . "_list"; |
| 92 |
push( @{$def->{$list}}, $name); |
| 93 |
foreach my $a (keys %{$attr}) |
| 94 |
{ |
| 95 |
$def->{$element}->{$name}->{attributes}->{$a} = $attr->{$a}; |
| 96 |
|
| 97 |
} |
| 98 |
parse($def->{$element}->{$name}, $child); |
| 99 |
|
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
$def->{$element} = {}; |
| 104 |
foreach my $a (keys %{$attr}) |
| 105 |
{ |
| 106 |
$def->{$element}->{attributes}->{$a} = $attr->{$a}; |
| 107 |
|
| 108 |
} |
| 109 |
parse($def->{$element}, $child); |
| 110 |
} |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
|
| 115 |
$def->{data} = $child; |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
my $xml= new XML::Parser(Style=>"Tree"); |
| 125 |
|
| 126 |
parse ($info, $xml->parsefile($file)); |
| 127 |
|
| 128 |
foreach my $object (keys %{$info->{magics}->{tutorial}}) |
| 129 |
{ |
| 130 |
my $current=$info->{magics}->{tutorial}->{$object}; |
| 131 |
|
| 132 |
my $section=$current->{attributes}->{name}; |
| 133 |
my $title=$current->{attributes}->{title}; |
| 134 |
my $comment=$current->{attributes}->{comment}; |
| 135 |
my $magml=$current->{attributes}->{magml}; |
| 136 |
my $magplus=$current->{attributes}->{magplus}; |
| 137 |
|
| 138 |
print << "EOF"; |
| 139 |
<section id='section_$section'> |
| 140 |
<title>$title </title> |
| 141 |
<para> $comment </para> |
| 142 |
<figure id="figure_$section"> |
| 143 |
<title>The expected result</title> |
| 144 |
<mediaobject id="output_$section"> |
| 145 |
<imageobject role="fo"> |
| 146 |
<imagedata fileref="../examples/tutorial/fortran/png/$section\_m69_CYLINDRICAL_01.png" format="PNG" |
| 147 |
align="center"/> |
| 148 |
</imageobject> |
| 149 |
|
| 150 |
<imageobject role="html"> |
| 151 |
<imagedata fileref="images/fortran/$section\_m69_CYLINDRICAL_01_thumb.png" format="PNG" |
| 152 |
align="center"/> |
| 153 |
</imageobject> |
| 154 |
</mediaobject> |
| 155 |
</figure> |
| 156 |
<section id='$section\_requirements'> |
| 157 |
<title> Requirements </title> |
| 158 |
<para> Here are our requirements </para> |
| 159 |
<itemizedlist> |
| 160 |
|
| 161 |
EOF |
| 162 |
|
| 163 |
foreach my $req (sort keys %{$current->{requirement}} ) |
| 164 |
{ |
| 165 |
my $id=$current->{requirement}->{$req}->{attributes}->{name}; |
| 166 |
my $subject=$current->{requirement}->{$req}->{attributes}->{subject}; |
| 167 |
my $text=$current->{requirement}->{$req}->{attributes}->{text}; |
| 168 |
print << "EOF"; |
| 169 |
<listitem><para> <olink targetdoc="Magics_tutorial" targetptr="$section\_clues_$id"> $subject </olink>: |
| 170 |
<emphasis>$text</emphasis></para></listitem> |
| 171 |
EOF |
| 172 |
} |
| 173 |
print << "EOF"; |
| 174 |
</itemizedlist> |
| 175 |
</section> |
| 176 |
<section id='$section\_clues'> |
| 177 |
<title>Clues</title> |
| 178 |
EOF |
| 179 |
|
| 180 |
foreach my $req (sort keys %{$current->{requirement}} ) |
| 181 |
{ |
| 182 |
my $id=$current->{requirement}->{$req}->{attributes}->{name}; |
| 183 |
my $subject=$current->{requirement}->{$req}->{attributes}->{subject}; |
| 184 |
my $text=$current->{requirement}->{$req}->{attributes}->{text}; |
| 185 |
my $targetdoc=$current->{requirement}->{$req}->{attributes}->{link_doc}; |
| 186 |
my $targetptr=$current->{requirement}->{$req}->{attributes}->{link_ptr}; |
| 187 |
my $ulink=$current->{requirement}->{$req}->{attributes}->{ulink}; |
| 188 |
|
| 189 |
|
| 190 |
my $num_param = keys %{$current->{requirement}->{$req}->{parameter}}; |
| 191 |
my $num_action = keys %{$current->{requirement}->{$req}->{action}}; |
| 192 |
|
| 193 |
print <<"EOF"; |
| 194 |
<section id='$section\_clues_$id'> |
| 195 |
<title>$subject</title> |
| 196 |
EOF |
| 197 |
if ( $num_param ne 0 ) { |
| 198 |
print <<"EOF"; |
| 199 |
<table id="$section\_table_$id\_clues_params"> |
| 200 |
<title>Parameters for $subject</title> |
| 201 |
<tgroup cols="3"> |
| 202 |
<colspec colwidth="200"/> |
| 203 |
<colspec colwidth="80"/> |
| 204 |
<colspec colwidth="100"/> |
| 205 |
<thead> |
| 206 |
<row> |
| 207 |
<entry> Parameters </entry> |
| 208 |
<entry> Values </entry> |
| 209 |
<entry> Functions </entry> |
| 210 |
</row> |
| 211 |
</thead> |
| 212 |
<tbody> |
| 213 |
EOF |
| 214 |
foreach my $param (keys %{$current->{requirement}->{$req}->{parameter}} ) |
| 215 |
{ |
| 216 |
my $value = $current->{requirement}->{$req}->{parameter}->{$param}->{attributes}->{value}; |
| 217 |
my $function = $current->{requirement}->{$req}->{parameter}->{$param}->{attributes}->{function}; |
| 218 |
my $link = link_function($function); |
| 219 |
|
| 220 |
print <<"EOF"; |
| 221 |
<row> |
| 222 |
<entry><parameter>$param</parameter></entry> |
| 223 |
<entry>$value</entry> |
| 224 |
<entry>$link</entry> |
| 225 |
</row> |
| 226 |
|
| 227 |
|
| 228 |
EOF |
| 229 |
|
| 230 |
} |
| 231 |
print <<"EOF"; |
| 232 |
</tbody> |
| 233 |
</tgroup> |
| 234 |
</table> |
| 235 |
EOF |
| 236 |
} |
| 237 |
if ( $num_action ne 0 ) { |
| 238 |
|
| 239 |
print <<"EOF"; |
| 240 |
<table id="$section\_table_$id\_clues_actions"> |
| 241 |
<title>Action Routines for $subject</title> |
| 242 |
<tgroup cols="1"> |
| 243 |
<colspec colwidth="160"/> |
| 244 |
<thead> |
| 245 |
<row> |
| 246 |
<entry> Action Routines </entry> |
| 247 |
</row> |
| 248 |
</thead> |
| 249 |
<tbody> |
| 250 |
EOF |
| 251 |
|
| 252 |
foreach my $function (keys %{$current->{requirement}->{$req}->{action}} ) |
| 253 |
{ |
| 254 |
my $link = link_function($function); |
| 255 |
print " <row><entry>$link</entry></row>\n"; |
| 256 |
} |
| 257 |
|
| 258 |
print <<"EOF"; |
| 259 |
</tbody> |
| 260 |
</tgroup> |
| 261 |
</table> |
| 262 |
EOF |
| 263 |
} |
| 264 |
|
| 265 |
if ( $targetdoc ne "" ) { |
| 266 |
|
| 267 |
print <<"EOF"; |
| 268 |
<para> More information on <olink targetdoc="Magics_$targetdoc" targetptr="$targetptr" >$subject</olink> </para> |
| 269 |
|
| 270 |
EOF |
| 271 |
} |
| 272 |
if ( $ulink ne "" ) { |
| 273 |
|
| 274 |
print <<"EOF"; |
| 275 |
<para> More information on <ulink url=\"http://www.ecmwf.int/publications/manuals/magics/manuals/${ulink}.html\">$subject</ulink> </para> |
| 276 |
|
| 277 |
EOF |
| 278 |
} |
| 279 |
print <<"EOF"; |
| 280 |
</section> |
| 281 |
|
| 282 |
EOF |
| 283 |
} |
| 284 |
print << "EOF"; |
| 285 |
</section> |
| 286 |
<section id='$section\_solution'> |
| 287 |
<title>Solution</title> |
| 288 |
<para> Here is the complete solution |
| 289 |
<filename>$section\.f</filename></para> |
| 290 |
<programlisting> |
| 291 |
<xi:include href="../examples/tutorial/fortran/source/$section\.f_cc" parse="xml" |
| 292 |
xmlns:xi="http://www.w3.org/2001/XInclude" /> |
| 293 |
</programlisting> |
| 294 |
</section> |
| 295 |
EOF |
| 296 |
|
| 297 |
if ( $magplus ne 'off' ) { |
| 298 |
print << "EOF"; |
| 299 |
<section id='$section\_diff'> |
| 300 |
<title> Spot the differences... </title> |
| 301 |
<figure id="figure_output_mpp_$section"> |
| 302 |
<title>Output for <productname>Magics++</productname></title> |
| 303 |
<mediaobject id="output_mpp_$section"> |
| 304 |
|
| 305 |
<imageobject role="fo"> |
| 306 |
<imagedata fileref="../examples/tutorial/fortran/png/$section\_01.png" format="PNG" |
| 307 |
align="center"/> |
| 308 |
</imageobject> |
| 309 |
|
| 310 |
<imageobject role="html"> |
| 311 |
<imagedata fileref="images/fortran/$section\_01_thumb.png" format="PNG" |
| 312 |
align="center"/> |
| 313 |
</imageobject> |
| 314 |
</mediaobject> |
| 315 |
</figure> |
| 316 |
|
| 317 |
<figure id="figure_output_m69_$section"> |
| 318 |
<title>Output for <productname>Magics 6.9</productname></title> |
| 319 |
<mediaobject id="output_m69_$section"> |
| 320 |
<imageobject role="fo"> |
| 321 |
<imagedata fileref="../examples/tutorial/fortran/png/$section\_m69_CYLINDRICAL_01.png" format="PNG" |
| 322 |
align="center"/> |
| 323 |
</imageobject> |
| 324 |
|
| 325 |
<imageobject role="html"> |
| 326 |
<imagedata fileref="images/fortran/$section\_m69_CYLINDRICAL_01_thumb.png" format="PNG" |
| 327 |
align="center"/> |
| 328 |
</imageobject> |
| 329 |
</mediaobject> |
| 330 |
</figure> |
| 331 |
|
| 332 |
<important> |
| 333 |
<title>Main differences</title> |
| 334 |
<itemizedlist> |
| 335 |
EOF |
| 336 |
|
| 337 |
|
| 338 |
foreach my $spot (keys %{$current->{spot}} ) |
| 339 |
{ |
| 340 |
my $text=$current->{spot}->{$spot}->{attributes}->{text}; |
| 341 |
print << "EOF"; |
| 342 |
<listitem><para>$text</para></listitem> |
| 343 |
EOF |
| 344 |
|
| 345 |
} |
| 346 |
|
| 347 |
$linkmagml = magml_function($magml); |
| 348 |
print << "EOF"; |
| 349 |
</itemizedlist> |
| 350 |
</important> |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
</section > |
| 355 |
|
| 356 |
EOF |
| 357 |
|
| 358 |
} |
| 359 |
|
| 360 |
if ( $magml ne 'off' ) { |
| 361 |
print << "EOF"; |
| 362 |
<section id='$section\_magml'> |
| 363 |
<title> Using MagML </title> |
| 364 |
<para> To get the same result, you can create the following <productname>magml</productname> description </para> |
| 365 |
<para><filename>$section\.magml</filename></para> |
| 366 |
<programlisting> |
| 367 |
<xi:include href="../examples/tutorial/magml/source/$section\.magml_cc" parse="xml" |
| 368 |
xmlns:xi="http://www.w3.org/2001/XInclude" /> |
| 369 |
</programlisting> |
| 370 |
|
| 371 |
<mediaobject id="output_magml_$section"> |
| 372 |
<imageobject role="fo"> |
| 373 |
<imagedata fileref="../examples/tutorial/magml/png/$section\.png" format="PNG" |
| 374 |
align="center"/> |
| 375 |
</imageobject> |
| 376 |
|
| 377 |
<imageobject role="html"> |
| 378 |
<imagedata fileref="images/magml/$section\_thumb.png" format="PNG" |
| 379 |
align="center"/> |
| 380 |
</imageobject> |
| 381 |
</mediaobject> |
| 382 |
|
| 383 |
<para> More information on $linkmagml </para> |
| 384 |
|
| 385 |
</section > |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
EOF |
| 390 |
} |
| 391 |
|
| 392 |
print << "EOF"; |
| 393 |
</section > <!-- end $section --> |
| 394 |
EOF |
| 395 |
|
| 396 |
} |
| 397 |
|
| 398 |
|