-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIDSDef2F90TypeDef.xsl
More file actions
454 lines (369 loc) · 19 KB
/
IDSDef2F90TypeDef.xsl
File metadata and controls
454 lines (369 loc) · 19 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<?modxslt-stylesheet type="text/xsl" media="fuffa, screen and $GET[stylesheet]" href="./%24GET%5Bstylesheet%5D" alternate="no" title="Translation using provided stylesheet" charset="ISO-8859-1" ?>
<?modxslt-stylesheet type="text/xsl" media="screen" alternate="no" title="Show raw source of the XML file" charset="ISO-8859-1" ?>
<xsl:stylesheet xmlns:yaslt="http://www.mod-xslt2.com/ns/2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" extension-element-prefixes="yaslt" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:local="http://www.example.com/functions/local" exclude-result-prefixes="local xs">
<!-- -->
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- -->
<xsl:param name="DD_GIT_DESCRIBE" as="xs:string" required="yes"/>
<xsl:param name="AL_GIT_DESCRIBE" as="xs:string" required="yes"/>
<xsl:variable name="version_regex" select="'^([0-9]+)\.([0-9]+)\.([0-9]+)([+-].*)?$'"/>
<xsl:variable name="DD_MAJOR" as="xs:integer" select="xs:integer(replace($DD_GIT_DESCRIBE, $version_regex, '$1'))"/>
<xsl:variable name="DD_MINOR" as="xs:integer" select="xs:integer(replace($DD_GIT_DESCRIBE, $version_regex, '$2'))"/>
<xsl:variable name="DD_PATCH" as="xs:integer" select="xs:integer(replace($DD_GIT_DESCRIBE, $version_regex, '$3'))"/>
<xsl:variable name="HLI_MAJOR" as="xs:integer" select="xs:integer(replace($AL_GIT_DESCRIBE, $version_regex, '$1'))"/>
<xsl:variable name="HLI_MINOR" as="xs:integer" select="xs:integer(replace($AL_GIT_DESCRIBE, $version_regex, '$2'))"/>
<xsl:variable name="HLI_PATCH" as="xs:integer" select="xs:integer(replace($AL_GIT_DESCRIBE, $version_regex, '$3'))"/>
<!-- TOP -->
<xsl:include href="utils.xsl"/>
<xsl:template match="/IDSs">
<xsl:result-document href="ids_types.f90">
! IDS FORTRAN 90 type definitions
! Contains the type definition of all IDSs
<!-- -->
<!-- ======================= ==== Begin : Common Types definition ==== =====================-->
module ids_types ! declare the size of real and integer variables to be used in all sub-trees, along with the invalid numbers.
use iso_c_binding, only: ids_real => c_double, &
ids_int => c_int32_t, &
ids_complex => c_double_complex
<!--
Possible way to extend the types to single precision floats, c_int, etc
!!use iso_c_binding, only: &
!! ids_c_double => c_double, &
!! ids_c_float => c_float, &
!! ids_c_int => c_int
!! real(ids_c_float), parameter :: ids_c_float_invalid = -9.0E30_ids_c_float
-->
implicit none
integer(ids_int), parameter :: ids_string_length = 132_ids_int
integer(ids_int), parameter :: ids_int_invalid = -999999999_ids_int
real(ids_real), parameter :: ids_real_invalid = -9.0E40_ids_real
complex(ids_real), parameter :: ids_complex_invalid = CMPLX(-9.0E40_ids_real,-9.0E40_ids_real,8)
integer(ids_int), parameter :: ids_data_dictionary_version(3) = (/ ids_int_invalid , ids_int_invalid , ids_int_invalid /) !! NOTE: to be filled with e.g. (/3,7,4/).
! ids_is_valid - Function for testing the validity of scalar and arrays of integers and real numbers
interface ids_is_valid
module procedure &
ids_is_valid_int, &
ids_is_valid_ids_real, &
ids_is_valid_array_of_int, &
ids_is_valid_array_of_real
end interface
! Version info
! HLI version, currently this is the same as the lowlevel version (see al_get_version)
character(*), parameter :: al_fortran_version = '<xsl:value-of select="$AL_GIT_DESCRIBE"/>'
integer(ids_int), parameter :: al_fortran_major_version = <xsl:value-of select="$HLI_MAJOR"/>
integer(ids_int), parameter :: al_fortran_minor_version = <xsl:value-of select="$HLI_MINOR"/>
integer(ids_int), parameter :: al_fortran_patch_version = <xsl:value-of select="$HLI_PATCH"/>
! DD version
character(*), parameter :: al_dd_version = '<xsl:value-of select="$DD_GIT_DESCRIBE"/>'
integer(ids_int), parameter :: al_dd_major_version = <xsl:value-of select="$DD_MAJOR"/>
integer(ids_int), parameter :: al_dd_minor_version = <xsl:value-of select="$DD_MINOR"/>
integer(ids_int), parameter :: al_dd_patch_version = <xsl:value-of select="$DD_PATCH"/>
contains
logical function ids_is_valid_int(in)
implicit none
integer(ids_int) :: in
ids_is_valid_int = in .ne. ids_int_invalid
return
end function ids_is_valid_int
logical function ids_is_valid_ids_real(in)
real(ids_real) :: in
ids_is_valid_ids_real = abs(in - ids_real_invalid) .gt. tiny(ids_real_invalid)
return
end function ids_is_valid_ids_real
logical function ids_is_valid_array_of_int(in)
integer(ids_int) :: in(:)
ids_is_valid_array_of_int = .not. any( in(:) .eq. ids_int_invalid )
return
end function ids_is_valid_array_of_int
logical function ids_is_valid_array_of_real(in)
real(ids_real) :: in(:)
ids_is_valid_array_of_real = .not. any( abs(in(:) - ids_real_invalid) .le. tiny(ids_real_invalid) )
return
end function ids_is_valid_array_of_real
!!! to be defined if needed !!!
!logical function ids_is_valid_array_of_complex(in)
end module ids_types
<!-- ======================= ==== End :Common Types definition ==== =====================-->
<!-- -->
<!-- -->
<!-- ======================= ==== Begin : Common Utility definition ==== =====================-->
</xsl:result-document>
<xsl:result-document href="ids_utilities.f90">
module ids_utilities ! declare the set of types common to all sub-trees
use ids_types
<!-- Base IDS type -->
type, abstract :: IDS_base
end type
<!-- Declare utilities types -->
<xsl:apply-templates select="/IDSs/utilities" mode="module"/> <!-- Original IDS structure -->
end module ! end of the utilities module
</xsl:result-document>
<!-- ======================= ==== End :Common Utility definition ==== =====================-->
<!-- ======================= ==== Begin : declare schema ==== =====================-->
<xsl:apply-templates select="IDS" mode="declare_in_file"/>
</xsl:template>
<!-- ============================ End : declare schema ========================= -->
<!-- -->
<!-- *********************************** TEMPLATES ********************************************* -->
<xsl:template match="IDS" mode="declare_set_c_data">
module procedure set_c_data_<xsl:value-of select="@name"/>
</xsl:template>
<xsl:template match="IDS" mode="declare_is_c_data">
module procedure is_c_data_<xsl:value-of select="@name"/>
</xsl:template>
<xsl:template match="IDS" mode="declare_get_max_occurrences">
module procedure get_max_occurrences_<xsl:value-of select="@name"/>
</xsl:template>
<xsl:template match="utilities" mode="module">
<xsl:for-each select="./field[@data_type='structure' or @data_type='struct_array']">
<xsl:variable name="this-type">
<xsl:choose>
<xsl:when test="@structure_reference='self'">
<xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@structure_reference"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
type ids_<xsl:value-of select="$this-type"/> !<xsl:value-of select="local:commentstring(@documentation)"/>
<xsl:apply-templates select="./field" mode="declare_field"/>
end type
</xsl:for-each>
</xsl:template>
<xsl:template match="IDS" mode="declare">
use <xsl:value-of select="@name"/>
</xsl:template>
<xsl:template match="IDS" mode="declare_in_file">
<xsl:result-document href="{@name}_schema.f90">
module ids_schemas_<xsl:value-of select="@name"/>
use ids_types
use ids_utilities
implicit none
interface set_c_data
module procedure set_c_data_<xsl:value-of select="@name"/>
end interface
interface is_c_data
module procedure is_c_data_<xsl:value-of select="@name"/>
end interface
interface get_max_occurrences
module procedure get_max_occurrences_<xsl:value-of select="@name"/>
end interface
interface ids_is_defined
module procedure ids_is_defined_<xsl:value-of select="@name"/>
end interface
! *********** <xsl:value-of select="@name"/> IDS internal structures declaration
<xsl:variable name="this-ids" select="@name"/>
<xsl:for-each select="./field[@data_type='structure' or @data_type='struct_array']">
<xsl:variable name="this-name" select="@name"/>
<xsl:variable name="this-type">
<xsl:choose>
<xsl:when test="@structure_reference='self'">
<xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@structure_reference"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:apply-templates select="." mode="declare_struct_recurse">
<xsl:with-param name="this-type" select="$this-type"/>
<xsl:with-param name="this-ids" select="$this-ids"/>
<xsl:with-param name="this-name" select="$this-name"/>
</xsl:apply-templates>
</xsl:for-each>
! *********** <xsl:value-of select="@name"/> IDS
type, extends(IDS_base) :: ids_<xsl:value-of select="@name"/> !<xsl:value-of select="local:commentstring(@documentation)"/>
logical, private :: c_data = .FALSE. ! Fortran specific metadata telling whether the IDS has been populated from C allocated data (LL) or not
integer, private :: max_occurrence = <xsl:value-of select="@maxoccur"/>! Maximum occurrence allowed as defined in the DD
character(len = 50), private :: ids_name = '<xsl:value-of select="@name"/>'
<xsl:apply-templates select="./field" mode="declare_field"/>
contains
procedure check_name_<xsl:value-of select="@name"/>
end type
contains
subroutine set_c_data_<xsl:value-of select="@name"/>(ids, bool)
type(ids_<xsl:value-of select="@name"/>), intent(inout) :: ids
logical, intent(in) :: bool
ids%c_data = bool
end subroutine
subroutine is_c_data_<xsl:value-of select="@name"/>(ids, bool)
type(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
logical, intent(out) :: bool
bool = ids%c_data
end subroutine
subroutine check_name_<xsl:value-of select="@name"/>(ids, name, retstatus)
class(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
character*(*), intent(in) :: name
integer, intent(out) :: retstatus
integer :: slash_index
slash_index = INDEX(name, '/')
if ( (slash_index == 0 .AND. ids%ids_name /= name) .OR. (slash_index /= 0 .AND. ids%ids_name /= name(1:slash_index - 1)) ) then
retstatus = -3
else
retstatus = 0
end if
end subroutine
function get_max_occurrences_<xsl:value-of select="@name"/>(ids)
type(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
integer :: get_max_occurrences_<xsl:value-of select="@name"/>
get_max_occurrences_<xsl:value-of select="@name"/> = ids%max_occurrence
end function
function ids_is_defined_<xsl:value-of select="@name"/>(ids) result(is_defined)
use al_defs
type(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
logical :: is_defined
integer :: time_mode
time_mode = ids%ids_properties%homogeneous_time
if (time_mode == IDS_TIME_MODE_HETEROGENEOUS) then
is_defined = .TRUE.
return
endif
if (time_mode == IDS_TIME_MODE_HOMOGENEOUS) then
is_defined = .TRUE.
return
endif
if (time_mode == IDS_TIME_MODE_INDEPENDENT) then
is_defined = .TRUE.
return
endif
is_defined = .FALSE.
end function
end module
</xsl:result-document>
</xsl:template>
<xsl:template match="IDS" mode="sbrt_c_data">
subroutine set_c_data_<xsl:value-of select="@name"/>(ids, bool)
type(ids_<xsl:value-of select="@name"/>), intent(inout) :: ids
logical, intent(in) :: bool
ids%c_data = bool
end subroutine
subroutine is_c_data_<xsl:value-of select="@name"/>(ids, bool)
type(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
logical, intent(out) :: bool
bool = ids%c_data
end subroutine
</xsl:template>
<xsl:template match="IDS" mode="sbrt_max_occurrences">
function get_max_occurrences_<xsl:value-of select="@name"/>(ids)
type(ids_<xsl:value-of select="@name"/>), intent(in) :: ids
integer :: get_max_occurrences_<xsl:value-of select="@name"/>
get_max_occurrences_<xsl:value-of select="@name"/> = ids%max_occurrence
end function
</xsl:template>
<!-- browse substructures recursively -->
<!-- make sure structures are declared before being used -->
<xsl:template match="field" mode="declare_struct_recurse">
<xsl:param name="this-type"/>
<xsl:param name="this-ids"/>
<xsl:param name="this-name"/>
<xsl:if test="descendant::field[(@data_type='structure' or @data_type='struct_array')]">
<xsl:for-each select="./field[@data_type='structure' or @data_type='struct_array']">
<xsl:variable name="this-type">
<xsl:choose>
<xsl:when test="@structure_reference='self'">
<xsl:value-of select="@name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@structure_reference"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="this-name" select="@name"/>
<xsl:apply-templates select="." mode="declare_struct_recurse">
<xsl:with-param name="this-type" select="$this-type"/>
<xsl:with-param name="this-ids" select="$this-ids"/>
<xsl:with-param name="this-name" select="$this-name"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:if>
<xsl:if test="not(preceding::field[@structure_reference=$this-type and ancestor::IDS/@name=$this-ids] or /IDSs/utilities/field/@name=$this-type)">
<xsl:apply-templates select="." mode="declare_struct">
<xsl:with-param name="this-type" select="$this-type"/>
<xsl:with-param name="this-ids" select="$this-ids"/>
<xsl:with-param name="this-name" select="$this-name"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
<xsl:template match="field" mode="declare_struct">
<xsl:param name="this-type"/>
<xsl:param name="this-ids"/>
<xsl:param name="this-name"/>
type :: ids_<xsl:value-of select="$this-type"/>
<xsl:for-each select="./field">
<xsl:apply-templates select="." mode="declare_field"/>
</xsl:for-each>
end type
</xsl:template>
<xsl:template match="field" mode="declare_field">
<xsl:choose>
<xsl:when test="@data_type='structure'">
type(ids_<xsl:value-of select="@structure_reference"/>) :: <xsl:value-of select="@name"/> !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='struct_array'">
type(ids_<xsl:value-of select="@structure_reference"/>), pointer :: <xsl:value-of select="@name"/>(:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='str_type' or @data_type='str_1d_type' or @data_type='STR_0D' or @data_type='STR_1D'">
character(len=ids_string_length), dimension(:), pointer :: <xsl:value-of select="@name"/> => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='int_type' or @data_type='INT_0D'">
integer(ids_int) :: <xsl:value-of select="@name"/>=ids_int_invalid !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='flt_type' or @data_type='FLT_0D'">
real(ids_real) :: <xsl:value-of select="@name"/>=ids_real_invalid !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='cpx_type' or @data_type='CPX_0D'">
complex(ids_real) :: <xsl:value-of select="@name"/>=ids_complex_invalid !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='int_1d_type' or @data_type='INT_1D'">
integer(ids_int), pointer :: <xsl:value-of select="@name"/>(:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='flt_1d_type' or @data_type='FLT_1D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='cpx_1d_type' or @data_type='CPX_1D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='int_2d_type' or @data_type='INT_2D'">
integer(ids_int), pointer :: <xsl:value-of select="@name"/>(:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='flt_2d_type' or @data_type='FLT_2D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='cpx_2d_type' or @data_type='CPX_2D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='FLT_3D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='INT_3D'">
integer(ids_int), pointer :: <xsl:value-of select="@name"/>(:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='cpx_3d_type' or @data_type='CPX_3D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='FLT_4D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='CPX_4D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='FLT_5D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='CPX_5D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='FLT_6D'">
real(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:when test="@data_type='CPX_6D'">
complex(ids_real), pointer :: <xsl:value-of select="@name"/>(:,:,:,:,:,:) => null() !<xsl:value-of select="local:commentstring(@documentation)"/>
</xsl:when>
<xsl:otherwise>
ERROR
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>