File: AsciiFormat.tmpl

package info (click to toggle)
xmds2 2.2.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 53,384 kB
  • ctags: 7,223
  • sloc: python: 54,076; cpp: 3,929; ansic: 1,463; makefile: 135; sh: 20
file content (103 lines) | stat: -rw-r--r-- 3,348 bytes parent folder | download | duplicates (3)
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
@*
AsciiFormat.tmpl

Created by Graham Dennis on 2007-09-18.

Copyright (c) 2007-2012, Graham Dennis

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*@
@extends xpdeint.Features.OutputFormat

@def description: ascii output format
@attr $name = 'ascii'

@*
  Write out the data in ASCII format
*@
@def writeOutFunctionImplementationBody($dict)
  @# The function prototype in which this code is going is:
  @#  void _mgN_write_out(FILE* _outfile)
  @# And this code is being automatically indented.
  @#
  @set $fp = dict['fp']
  @set $field = dict['field']
  @set $basis = dict['basis']
  @#
${writeOutFunctionImplementationBegin(dict)}@slurp
  
  @set $dependentVariables = $dict.dependentVariables
fprintf($fp, "    <Stream><Metalink Format=\"Text\" Delimiter=\" \\n\"/>\n");

  @set $vectors = set([variable['vector'] for variable in dependentVariables])
$loopOverFieldInBasisWithVectorsAndInnerContent(field, basis, vectors, $insideOutputLoops(dict), $loopingOrder=$LoopingOrder.StrictlyAscendingOrder, vectorsNotNeedingDefines=vectors)@slurp

fprintf($fp, "    </Stream>\n");

${writeOutFunctionImplementationEnd(dict)}@slurp
  @#
@end def

@def insideOutputLoops(dict)
  @#
  @set $fp = dict['fp']
  @set $dependentVariables = dict['dependentVariables']
  @set $field = dict['field']
  @set $basis = dict['basis']
  @#
  @set $componentCount = 0
  @for $variable in $dependentVariables
    @set $componentCount += len($variable.vector.components)
    @if $variable.vector.type == 'complex'
      @set $componentCount += len($variable.vector.components)
    @end if
  @end for
  @#
  @set dict['componentCount'] = componentCount
  @set $variableCount = len($field.dimensions) + componentCount
  @set $precisionPrefix = '.12'
  @if $precision == 'single'
    @set $precisionPrefix = ''
  @end if
// UNVECTORISABLE
fprintf($fp, "@slurp
  @# Loop over the variables that we're writing out
  @for $variableNumber in range($variableCount)
    @if $variableNumber != 0
      @# If this isn't the first dimension, include a space at the start
 %${precisionPrefix}e@slurp
    @else
%${precisionPrefix}e@slurp
    @end if
  @end for
\n"@slurp
  @#
  @for $dimension in $field.dimensions
, (real)${dimension.inBasis(basis).name}@slurp
  @end for
  @#
  @# Now loop over the (dependent) variables
  @for $variable in $dependentVariables
    @for $componentNumber, $component in enumerate($variable.components)
      @if $variable.vector.type == 'real'
, ${variable.arrayName}[_${variable.vector.id}_index_pointer + ${componentNumber}]@slurp
      @else
, ${variable.arrayName}[_${variable.vector.id}_index_pointer + ${componentNumber}].Re(), ${variable.arrayName}[_${variable.vector.id}_index_pointer + ${componentNumber}].Im()@slurp
      @end if
    @end for
  @end for
);
  @#
@end def