-
Notifications
You must be signed in to change notification settings - Fork 2
/
ccViz
executable file
·11712 lines (10182 loc) · 571 KB
/
ccViz
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
XSLTPROC=/usr/bin/xsltproc
MKTEMP=/usr/bin/mktemp
if [ ! -x $XSLTPROC ]; then
echo "Error: could not find xsltproc"
exit 1
elif [ ! -x $MKTEMP ]; then
echo "Error: could not find mktemp"
exit 1
elif [ $# -ne 1 ]; then
echo "Error: need exactly one argument"
exit 1
fi
TMPXSLTDIR=
trap 'rm -rf $TMPXSLTDIR; exit' 0 1 2 3 15
TMPXSLTDIR=$(mktemp -d)
cat > $TMPXSLTDIR/finishXML.py << "EOF"
#!/usr/bin/env python
import sys
from xml.parsers import expat
def finishXMLFile(filename):
"""
This function will read in a file which is a truncated well-formed XML file,
and fix it up at the end so that it is well-formed.
What it does *not* do:
1) Cope with ill-formed files (ie files that could not be transformed into
a well-formed file simply by appending characters)
2) Make any guarantees of the validitiy of the output file.
Known bugs:
1) If the file hasn't got a root element - or the root element opening
tag is incomplete - this will not create one, so the result will
be ill-formed. Probably this should throw an exception.
2) I think it's possible that where the file is Unicode, and the
truncation happens halfway through a Unicode character, that the
result will not be well-formed.
3) No checking is made that the input file is actually correct in its
nearly-well-formedness.
Warning: this *overwrites* the file which is given to it (Done this
way to save space since I am dealing with several-hundred
megabyte files ...
"""
tagStack = []
def start(name, attributes): tagStack.append(name)
def end(name): tagStack.pop()
p = expat.ParserCreate()
p.StartElementHandler = start
p.EndElementHandler = end
e = None
fIn = open(filename,'r+')
try:
p.ParseFile(fIn)
except expat.ExpatError, e:
pass
if not e: return
fIn.seek(0, 0)
for i in range(e.lineno-1): fIn.readline()
lastLine = fIn.readline()
fIn.seek(-len(lastLine), 1)
fIn.truncate()
lastLine = lastLine.rstrip() # for some reason python appends a newline
if e.message.startswith("no element found"):
# We're in a text section, carry on
pass
elif e.message.startswith("unclosed token"):
# throw away the final token and finish
lastLine = lastLine[:e.offset]
elif e.message.startswith("unclosed CDATA section"):
lastLine = lastLine + u']]>'
elif e.message.startswith("not well-formed (invalid token)"):
# We need to worry about where we are. These
# are the possibilities
if (lastLine[-1] == u'/'):
# We have "<tagName /"
lastLine = lastLine + u'>'
elif (lastLine[-1] == u'<'):
# We have simply "<"
lastLine = lastLine[:-1]
elif (lastLine[-1] == u'<'):
# We have "</t" with offset before the "<"
lastLine = lastLine[:e.offset]
elif (lastLine[-1] == u'!'):
# We have "<!"
lastLine = lastLine[:-2]
elif (lastLine[-1] == u'-'):
if (lastLine[-3:] == u'<!-'):
lastLine = lastLine[:-3]
elif (lastLine[-4:] == u'<!--'):
lastLine = lastLine[:-4]
else:
# We have "<!-- blah --"
lastLine = lastLine + u'>'
elif (lastLine[-1] == u"A"):
# We have "<![CDATA"
lastLine = lastLine[:-8]
elif (lastLine[-1] == u"?"):
# We have "<?"
lastLine = lastLine[:-2]
fIn.write(lastLine)
tagStack.reverse()
for tag in tagStack:
fIn.write("</"+tag+">")
fIn.close()
if __name__ == '__main__':
finishXMLFile(sys.argv[1])
EOF
cat > $TMPXSLTDIR/array.xsl << "EOF"
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cml="http://www.xml-cml.org/schema"
extension-element-prefixes="str">
<xsl:import href="loop.xsl"/>
<xsl:template match="cml:kpoint" mode="eigen">
<div><i><xsl:text>k</xsl:text></i><xsl:text>-point at: (</xsl:text>
<xsl:for-each select="str:tokenize(@coords)">
<xsl:value-of select="format-number(., '0.0000')"/>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>) with weight </xsl:text><xsl:value-of select="@weight"/></div>
</xsl:template>
<xsl:template match="cml:property" mode="eigen">
<table><tr>
<xsl:call-template name="rows-for-loop">
<xsl:with-param name="i" select="1"/>
<xsl:with-param name="increment" select="1"/>
<xsl:with-param name="testValue" select="ceiling(cml:array/@size div 8)"/>
<xsl:with-param name="innerTestValue" select="8"/>
<xsl:with-param name="outputString" select="concat(normalize-space(cml:array/text()),' ')"/>
</xsl:call-template>
</tr></table>
</xsl:template>
<xsl:template match="cml:array">
<xsl:variable name="delimiter">
<xsl:choose>
<xsl:when test="@delimiter">
<xsl:value-of select="@delimiter"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' '"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<p><br/></p>
<table class="prop2">
<tr>
<xsl:for-each select="str:tokenize(text(),$delimiter)">
<td>
<xsl:choose>
<xsl:when test="ceiling(.) = floor(.) and not(contains(.,'.'))">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="string(number(.)) != 'NaN'">
<xsl:value-of select="format-number(., '0.0000')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/averageVolume.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tohw="http://www.uszla.me.uk/xsl/1.0/functions"
xmlns:g="http://www.uszla.me.uk/xsl/1.0/graph"
extension-element-prefixes="tohw"
>
<xsl:import href="graphfuncs.xsl"/>
<xsl:output method="xml"/>
<xsl:param name="fileList"/>
<xsl:template match="/">
<g:graphSet>
<g:pointList>
<xsl:apply-templates select="*"/>
</g:pointList>
</g:graphSet>
</xsl:template>
<xsl:template match="file">
<xsl:element name="point" namespace="http://www.uszla.me.uk/xsl/1.0/graph">
<xsl:attribute name="x">
<xsl:value-of select="document(.)//cml:parameterList[@title='control parameters']/cml:parameter[@dictRef='dl_poly:pressure']/cml:scalar"/>
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="sum(document(.)//cml:step/cml:propertyList[@title='instantaneous']/cml:property[@dictRef='dl_poly:volume']/cml:scalar) div count(document(.)//cml:step/cml:propertyList[@title='instantaneous']/cml:property[@dictRef='dl_poly:volume']/cml:scalar)"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/bandList.xsl << "EOF"
<!--===================== BANDS =========================-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cml="http://www.xml-cml.org/schema"
extension-element-prefixes="str">
<!-- bandList -->
<xsl:template match="cml:bandList">
<xsl:if test="title"><H3><xsl:value-of select="@title"/></H3></xsl:if>
<!-- <H3>Eigenvalues</H3> -->
<table>
<xsl:apply-templates select="cml:band"/>
</table>
</xsl:template>
<!-- band -->
<xsl:template match="cml:band">
<xsl:param name="mouseoverString">
<xsl:for-each select="str:tokenize(@kpoint,' ')">
<xsl:value-of select="format-number(., '0.000')"/>
</xsl:for-each>
<xsl:text> (</xsl:text>
<xsl:value-of select="format-number(@weight, '0.000')"/>
<xsl:text>)</xsl:text>
</xsl:param>
<tr>
<th align="left">
<span>
<xsl:attribute name="title">
<xsl:value-of select="$mouseoverString"/>
</xsl:attribute>
<i>k</i>-point
<xsl:value-of select="position()"/>
</span>
</th>
</tr>
<tr>
<td>
<table>
<xsl:for-each select="str:tokenize(normalize-space(.), ' ')">
<xsl:if test="(position()-1) mod 10 = 0">
<xsl:variable name="pos" select="position()"/>
<tr>
<td class="eigen"><xsl:value-of select="../token[$pos+0]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+1]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+2]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+3]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+4]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+5]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+6]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+7]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+8]"/></td>
<td class="eigen"><xsl:value-of select="../token[$pos+9]"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/dict2frag.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl cml"
>
<xsl:template name="addDict">
<xsl:variable name="unique-dictRefs" select="//cml:*[@dictRef and (generate-id(.)=generate-id(key('dictRef-keys', concat(namespace::*[name()=substring-before(../@dictRef,':')], '#', substring-after(@dictRef, ':')))[1]))]"/>
<!-- Muenchian grouping -->
<xsl:for-each select="$unique-dictRefs">
<xsl:sort select="translate(substring-after(@dictRef, ':'), 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:variable name="dictRef" select="@dictRef"/>
<xsl:variable name="dictURI"
select="namespace::*[name()=substring-before($dictRef,':')]"/>
<xsl:variable name="dictEntry" select="substring-after($dictRef, ':')"/>
<xsl:choose>
<xsl:when test="$dictURI!='' and document('dictionaries.xml')//cml:dictionary[@namespace=$dictURI]/cml:entry[@id=$dictEntry]">
<xsl:apply-templates select="document('dictionaries.xml')//cml:dictionary[@namespace=$dictURI]/cml:entry[@id=$dictEntry]"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="empty-entry">
<xsl:with-param name="id" select="$dictEntry"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/dict2html.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:stm="http://www.xml-cml.org/schema/stmml"
xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:import href="dictcommon.xsl"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8"
omit-xml-declaration="no" standalone="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes" media-type="application/xhtml+xml"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="/stm:dictionary/@title"/></title>
</head>
<body>
<h1><xsl:value-of select="/stm:dictionary/@title"/></h1>
<hr></hr>
<xsl:apply-templates select="/stm:dictionary/stm:entry">
<!-- need translate below to prevent separating upper & lower case entries -->
<xsl:sort data-type="text" order="ascending"
select="translate(@term,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/dict2xsl.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:stm="http://www.xml-cml.org/schema/stmml"
xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:import href="dictcommon.xsl"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8"
omit-xml-declaration="no" standalone="yes"
indent="yes" media-type="text/xsl"/>
<xsl:template match="/">
<xsl:element name="xsl:stylesheet" namespace="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="version">1.0</xsl:attribute>
<!-- <xsl:attribute name="xmlns">http://www.w3.org/1999/xhtml</xsl:attribute> -->
<xsl:element name="xsl:template" namespace="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="name">addDict</xsl:attribute>
<xsl:apply-templates select="//stm:entry">
<!-- need translate below to prevent separating upper & lower case entries -->
<xsl:sort data-type="text" order="ascending"
select="translate(@term,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</xsl:apply-templates>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/dictcommon.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl cml"
>
<!-- For each entry in the dictionary -->
<xsl:template match="cml:entry">
<div class="dictAnchor">
<a>
<xsl:attribute name="name">
<xsl:value-of select="@id"/>
</xsl:attribute>
</a>
</div>
<div class="dictEntry">
<xsl:choose>
<xsl:when test="@term and @term!=''">
<xsl:value-of select="@term"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@id"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>:</xsl:text></div>
<xsl:if test="cml:definition">
<xsl:choose>
<xsl:when test="//text()='definition to be supplied'">
<p><font color="blue"><xsl:value-of select="cml:definition"/></font></p>
</xsl:when>
<xsl:otherwise>
<div class="dictDefinition"><xsl:value-of select="cml:definition"/></div>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="cml:description">
<xsl:copy-of select="cml:description/node()"/>
</xsl:if>
<hr/>
</xsl:template>
<!-- An empty entry -->
<xsl:template name="empty-entry">
<xsl:param name="id"/>
<div class="dictAnchor">
<a name="{$id}"/>
</div>
<div class="dictEntry">
<xsl:value-of select="$id"/>
<xsl:text>:</xsl:text></div>
<p><font color="blue">definition to be supplied</font></p>
<hr/>
</xsl:template>
<!-- for each description just copy everything -->
<!-- REM do the same for MathML stuff -->
<!-- <xsl:template match="stm:description/@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template> -->
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/dictionary.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl cml"
>
<xsl:template name="empty-entry-link">
<xsl:param name="id"/>
<span class="dictRef dotted">
<xsl:attribute name="onmouseover">window.location.href='#<xsl:value-of select="$id"/>';</xsl:attribute>
<xsl:value-of select="$id"/>
</span>
</xsl:template>
<xsl:template name="get.dictionary.reference.html">
<xsl:param name="dictRef"/>
<xsl:param name="title"/>
<xsl:choose>
<xsl:when test="$dictRef">
<xsl:variable name="dictURI"
select="namespace::*[name()=substring-before($dictRef,':')]"/>
<xsl:variable name="dictEntry" select="substring-after(@dictRef, ':')"/>
<xsl:choose>
<xsl:when test="document('dictionaries.xml')//cml:dictionary[@namespace=$dictURI]/cml:entry[@id=$dictEntry]">
<xsl:apply-templates select="document('dictionaries.xml')//cml:dictionary[@namespace=$dictURI]/cml:entry[@id=$dictEntry]" mode="htmlOutput">
<xsl:with-param name="title" select="$title"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="empty-entry-link">
<xsl:with-param name="id" select="$dictEntry"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="not($dictRef) and $title">
<span class="dictRef">
<xsl:value-of select="$title"/>
</span>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="cml:entry" mode="htmlOutput">
<xsl:param name="title"/>
<xsl:variable name="dictTitle">
<xsl:choose>
<xsl:when test="$title">
<xsl:value-of select="$title"/>
</xsl:when>
<xsl:when test="@term">
<xsl:value-of select="@term"/> <!-- 2nd otherwise use @term -->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@id"/> <!-- 3rd failing that use @dictRef -->
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<span class="dictRef dotted">
<xsl:attribute name="onmouseover">window.location.href='#<xsl:value-of select="@id"/>';</xsl:attribute>
<xsl:value-of select="$dictTitle"/>
</span>
</xsl:template>
<!-- GRAPH -->
<!-- GET DICTIONARY REFERENCE FOR USE WITHIN THE GRAPH OUTPUT -->
<xsl:template name="get.dictionary.reference.graph">
<!-- if dictionary reference is given try to resolve it -->
<xsl:param name="dictRef"/>
<xsl:choose>
<xsl:when test="$dictRef">
<xsl:call-template name="resolve.dictionary.id.graph">
<xsl:with-param name="dictionary"
select="document(concat(substring-before($dictRef, ':'), 'Dict.xml'))"/>
<xsl:with-param name="entry" select="substring-after($dictRef, ':')"/>
</xsl:call-template>
</xsl:when>
<!-- else try to use the title attribute and flag a warning -->
<xsl:when test="@title">
<xsl:text>No dictionary reference given</xsl:text>
</xsl:when>
<!-- otherwise just write 'unknown' and flag a warning -->
<xsl:otherwise>
<xsl:text>No dictionary reference or title given</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- RESOLVE DICTIONARY ID FOR THE GRAPH OUTPUT-->
<xsl:template name="resolve.dictionary.id.graph">
<xsl:param name="dictionary"/>
<xsl:param name="entry"/>
<xsl:choose>
<!-- If dictionary exists use it-->
<xsl:when test="$dictionary/dictionary">
<!-- If entry found then use it -->
<xsl:if test="$dictionary/dictionary/entry[@id = $entry]">
<xsl:apply-templates select="$dictionary/dictionary/entry[@id = $entry]" mode="graphOutput">
<xsl:with-param name="entry" select="$entry"/>
</xsl:apply-templates>
</xsl:if>
<!-- If entry NOT found then use entry name and flag a warning -->
<xsl:if test="not($dictionary/dictionary/entry[@id = $entry])">
<xsl:text>Entry </xsl:text><xsl:value-of select="$entry"/>
<xsl:text> not found in the dictionary</xsl:text>
</xsl:if>
</xsl:when>
<!-- If dictionary does NOT exist use entry name and flag a warning -->
<xsl:otherwise>
<xsl:value-of select="$dictionary"/><xsl:text> dictionary not found.</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- GET DICTIONARY ENTRY FOR GRAPH OUTPUT -->
<xsl:template match="entry" mode="graphOutput">
<xsl:param name="entry"/>
<xsl:value-of select="definition"/>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/display.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl"
>
<!-- JS/CSS includes -->
<xsl:import href="header.xsl"/>
<!-- CML -->
<xsl:import href="structure.xsl"/>
<xsl:import href="dictionary.xsl"/>
<xsl:import href="metadata.xsl"/>
<xsl:import href="parameter.xsl"/>
<xsl:import href="property.xsl"/>
<xsl:import href="bandList.xsl"/>
<xsl:import href="formula.xsl"/>
<xsl:import href="units.xsl"/>
<!-- CMLComp -->
<xsl:import href="module.xsl"/>
<xsl:import href="plottable.xsl"/>
<xsl:import href="lattice.xsl"/>
<!-- STMML -->
<xsl:import href="scalar.xsl"/>
<xsl:import href="array.xsl"/>
<xsl:import href="matrix.xsl"/>
<xsl:import href="table.xsl"/>
<!-- Dictionary -->
<xsl:import href="dict2frag.xsl"/>
<xsl:import href="dictcommon.xsl"/>
<!-- Special templates -->
<xsl:import href="summary.xsl"/>
<xsl:import href="rdf.xsl"/>
<xsl:strip-space elements="*"/>
<xsl:key name="dictRef-keys" match="//cml:*[@dictRef]"
use="concat(namespace::*[name()=substring-before(../@dictRef,':')], '#', substring-after(@dictRef, ':'))"/>
<xsl:template match="text()"/>
<xsl:template match="text()" mode="jmol"/>
<xsl:template match="text()" mode="structure"/>
<!-- Global Variable holding the program name -->
<xsl:param name="prog">
<xsl:choose>
<xsl:when test="/cml:cml/cml:metadataList/cml:metadata[@name='eMinerals:Program']">
<xsl:value-of select="/cml:cml/cml:metadataList/cml:metadata[@name='eMinerals:Program']/@content"/>
</xsl:when>
<xsl:when test="/cml:cml/cml:metadataList/cml:metadata[@name='siesta:Program']">
<xsl:value-of select="/cml:cml/cml:metadataList/cml:metadata[@name='siesta:Program']/@content"/>
</xsl:when>
<xsl:when test="/cml:cml/cml:metadataList/cml:metadata[@name='dl_poly:Program']">
<xsl:value-of select="/cml:cml/cml:metadataList/cml:metadata[@name='dl_poly:Program']/@content"/>
</xsl:when>
<xsl:when test="contains(/cml:cml/cml:metadataList/cml:metadata[@name='dc:identifier']/@content,'DL_POLY')">
<xsl:text>DL_POLY</xsl:text>
</xsl:when>
<xsl:when test="/cml:cml/cml:metadataList/cml:metadata[@name='dc:creator']">
<xsl:value-of select="/cml:cml/cml:metadataList/cml:metadata[@name='dc:creator']/@content"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>Program</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- Global variable - do we want jmol output or not? -->
<xsl:param name="Jmol">
<xsl:value-of select="boolean(//cml:molecule)"/>
</xsl:param>
<!-- Global variable - how many steps do we want? -->
<xsl:param name="stepinterval">
<xsl:choose>
<xsl:when test="count(cml:cml/cml:module[@role='step']) > 100">
10
</xsl:when>
<xsl:otherwise>
1
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:output method="xml" version="1.0" encoding="UTF-8"
omit-xml-declaration="no" standalone="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="no" media-type="application/xhtml+xml"/>
<!-- MAIN TEMPLATE -->
<xsl:template match="/">
<html>
<xsl:call-template name="head"/>
<body>
<xsl:if test="$Jmol!='false'">
<xsl:attribute name="onload">
<xsl:text>jmolInitialize(" https://data.eminerals.org/ccViz/jmol/", true);</xsl:text>
</xsl:attribute>
</xsl:if>
<div id="head"><div class="bigTitle">
<xsl:value-of select="$prog"/>
<xsl:text> Output</xsl:text>
</div></div>
<!-- Generate body of document -->
<div id="maindisplay">
<div class="innerMain">
<br/><div id="initialmetadata" class="divisionTitle clickable moduleDiv">
<xsl:text>Initial Metadata</xsl:text>
</div>
<div class="sublevel">
<xsl:apply-templates select="/cml:cml/cml:metadataList[position()=1]"/>
</div><br/>
<br/><div class="divisionTitle clickable moduleDiv">
<xsl:text>Input Parameters</xsl:text>
</div>
<div class="sublevel">
<xsl:apply-templates select="/cml:cml/cml:parameterList"/>
<!-- <xsl:apply-templates select="/cml:cml/cml:parameterList[position()=1]"/> -->
</div><br/>
<xsl:if test="/cml:cml/cml:module[@title='Initial System']">
<div class="divisionTitle clickable moduleDiv">
<xsl:text>Initial System</xsl:text>
</div>
<div class="sublevel">
<xsl:apply-templates select="/cml:cml/cml:module[@title='Initial System']">
<xsl:with-param name="title" select="false"/>
</xsl:apply-templates>
</div>
</xsl:if>
<br/>
<div class="divisionTitle clickable moduleDiv">
<xsl:text>Main Body of Simulation</xsl:text>
</div>
<div class="sublevel">
<xsl:apply-templates select="/cml:cml/cml:module[(@title!='Initial System' and @title!='Finalization') or not(@title)]"/>
</div>
<br/>
<xsl:if test="/cml:cml/cml:module[@title='Finalization']">
<div class="divisionTitle clickable moduleDiv">
<xsl:text>Final System</xsl:text>
</div>
<div class="sublevel">
<xsl:apply-templates select="/cml:cml/cml:module[@title='Finalization']">
<xsl:with-param name="title" select="false"/>
</xsl:apply-templates>
</div>
</xsl:if>
<br/>
<div class="divisionTitle clickable moduleDiv">
<xsl:text>Summary Information</xsl:text>
</div>
<div class="sublevel">
<xsl:call-template name="summary"/>
</div>
<br/>
<hr/>
</div>
</div>
<!-- Generate dictionary of document -->
<div id="dictdisplay">
<div class="innerDict">
<xsl:call-template name="addDict"/>
</div>
</div>
<!-- -->
<div id="foot">
<i>Created using <a href="http://cmlcomp.org/ccViz/">ccViz</a>, by Toby White <a href="mailto://[email protected]"><[email protected]></a>. See <a href="http://cmlcomp.org">CMLComp</a> for more information</i>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="top.level.section">
<xsl:param name="uid"/>
<xsl:param name="title"/>
<xsl:param name="templates"/>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/formula.xsl << "EOF"
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="formula">
<P/>
<H3>Formula</H3>
<xsl:call-template name="format.form">
<xsl:with-param name="formula" select="normalize-space(.)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="format.form">
<xsl:param name="formula"/>
<xsl:if test="not($formula = '')">
<xsl:variable name="substring" select="substring-before($formula,' ')"/>
<xsl:variable name="remainder" select="substring-after($formula,' ')"/>
<!-- Is variable a number or a string? -->
<xsl:choose>
<xsl:when test="string(number($substring)) = 'NaN'">
<xsl:value-of select="$substring"/>
</xsl:when>
<xsl:when test="string(number($substring)) != 'NaN' and $substring != 1">
<SUB><xsl:value-of select="$substring"/></SUB>
</xsl:when>
</xsl:choose>
<!-- on final iteration this will be processed instead -->
<xsl:if test="substring-after($formula,' ') = ''">
<xsl:choose>
<xsl:when test="string(number($formula)) = 'NaN'">
<xsl:value-of select="$formula"/>
</xsl:when>
<xsl:when test="string(number($formula)) != 'NaN' and $formula != 1">
<SUB><xsl:value-of select="$formula"/></SUB>
</xsl:when>
</xsl:choose>
</xsl:if>
<!-- Recurse -->
<xsl:call-template name="format.form">
<xsl:with-param name="formula" select="$remainder"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/graph_bits.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns="http://www.uszla.me.uk/xsl/1.0/graph"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns:g="http://www.uszla.me.uk/xsl/1.0/graph"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
>
<xsl:template name="drawGraphOf">
<xsl:param name="subTree" select="/cml:cml"/>
<xsl:param name="stepType"/>
<xsl:param name="propertyName"/>
<xsl:param name="title" select="$propertyName"/>
<xsl:param name="xAxisTitle" select="'Step'"/>
<xsl:param name="yAxisTitle" select="''"/>
<xsl:variable name="pointList">
<g:pointList>
<xsl:for-each select="$subTree/cml:module[@dictRef=$stepType]">
<xsl:variable name="x" select="@serial"/>
<xsl:variable name="y" select="cml:propertyList/cml:property[@dictRef=$propertyName]/cml:scalar"/>
<g:point x="{$x}" y="{$y}"/>
</xsl:for-each>
</g:pointList>
</xsl:variable>
<xsl:call-template name="drawGraph">
<xsl:with-param name="title" select="$title"/>
<xsl:with-param name="xAxisTitle" select="$xAxisTitle"/>
<xsl:with-param name="yAxisTitle" select="$yAxisTitle"/>
<xsl:with-param name="pointSet" select="exsl:node-set($pointList)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="selectNestedGraphNodes">
<xsl:param name="nodes"/>
<xsl:param name="propertyName"/>
<g:pointList>
<!-- for each step, if the property exists, then add its value to the pointList -->
<xsl:for-each select="$nodes">
<xsl:if test="cml:propertyList/cml:property[@dictRef=$propertyName]">
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="@serial">
<xsl:value-of select="@serial"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="position()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="y" select="cml:propertyList/cml:property[@dictRef=$propertyName]/cml:scalar"/>
<g:point x="{$x}" y="{$y}"/>
</xsl:if>
</xsl:for-each>
</g:pointList>
</xsl:template>
<xsl:template name="selectRDFPoints">
<!-- FIXME subject to change as we refine RDF XML format - this is bloody fragile -->
<xsl:param name="nodes"/>
<g:pointList>
<xsl:for-each select="$nodes">
<xsl:if test="@title='grid'">
<xsl:variable name="pos" select="position()"/>
<xsl:variable name="x" select="cml:scalar/text()"/>
<xsl:variable name="y" select="../cml:property[position() = ($pos + 1)]/cml:scalar/text()"/>
<g:point x="{$x}" y="{$y}"/>
</xsl:if>
</xsl:for-each>
</g:pointList>
</xsl:template>
<xsl:template name="selectPointsFromNodes">
<xsl:param name="nodes"/>
<xsl:param name="propertyNames"/>
<g:pointList>
<!-- for each step, if the property exists, then add its value to the pointList -->
<xsl:for-each select="$nodes">
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="@serial">
<xsl:value-of select="@serial"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="position()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="here" select="."/>
<xsl:for-each select="$propertyNames">
<xsl:variable name="propertyName" select="."/>
<g:group dictRef="{$propertyName}">
<xsl:if test="$here/cml:propertyList/cml:property[@dictRef=$propertyName]">
<xsl:variable name="y" select="$here/cml:propertyList/cml:property[@dictRef=$propertyName]/cml:scalar"/>
<g:point x="{$x}" y="{$y}"/>
</xsl:if>
</g:group>
</xsl:for-each>
</xsl:for-each>
</g:pointList>
</xsl:template>
<xsl:template name="selectedPointsFromList">
<xsl:param name="pointList"/>
<xsl:param name="dictRef"/>
<g:pointList>
<xsl:for-each select="$pointList/g:pointList/g:group[@dictRef=$dictRef]">
<xsl:copy-of select="g:point"/>
</xsl:for-each>
</g:pointList>
</xsl:template>
</xsl:stylesheet>
EOF
cat > $TMPXSLTDIR/graph_produce.xsl << "EOF"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:cml="http://www.xml-cml.org/schema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g="http://www.uszla.me.uk/xsl/1.0/graph"
>
<xsl:import href="toby_graph.xsl"/>
<xsl:import href="graphfuncs.xsl"/>
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:param name="graphTitle" select="default"/>
<xsl:param name="xAxisTitle" select="default"/>
<xsl:param name="yAxisTitle" select="default"/>
<!-- MAIN TEMPLATE -->
<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>