-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIDSDef2Java.xsl
More file actions
3735 lines (3295 loc) · 177 KB
/
IDSDef2Java.xsl
File metadata and controls
3735 lines (3295 loc) · 177 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
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
<?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 make gentype="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/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="yaslt exsl"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<!-- <xsl:stylesheet xmlns:yaslt="http://www.mod-xslt2.com/ns/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:exsl="http://exslt.org/common"
xmlns:func="http://exslt.org/functions"
xmlns:my="http://localhost.localdomain/localns"
exclude-result-prefixes="my"
extension-element-prefixes="yaslt exsl func">
-->
<xsl:param name="SYSTEM" as="xs:string" required="yes"/>
<xsl:param name="DD_VERSION" as="xs:string" required="yes"/>
<xsl:param name="AL_VERSION" 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_VERSION, $version_regex, '$1'))"/>
<xsl:variable name="DD_MINOR" as="xs:integer" select="xs:integer(replace($DD_VERSION, $version_regex, '$2'))"/>
<xsl:variable name="DD_PATCH" as="xs:integer" select="xs:integer(replace($DD_VERSION, $version_regex, '$3'))"/>
<xsl:variable name="HLI_MAJOR" as="xs:integer" select="xs:integer(replace($AL_VERSION, $version_regex, '$1'))"/>
<xsl:variable name="HLI_MINOR" as="xs:integer" select="xs:integer(replace($AL_VERSION, $version_regex, '$2'))"/>
<xsl:variable name="HLI_PATCH" as="xs:integer" select="xs:integer(replace($AL_VERSION, $version_regex, '$3'))"/>
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:function name="fn:getpathdoc">
<xsl:param name="string1"/>
<xsl:if test="contains($string1,'(:')">
<xsl:value-of select="substring-before($string1,'(:')"/>
</xsl:if>
<xsl:if test="not(contains($string1,'(:'))">
<xsl:value-of select="$string1"/>
</xsl:if>
</xsl:function>
<!-- MODE can be set to get or put in the 2 transformations for generating the subroutines, this reduced editing requirements
it could also be done with 2 xslt operations on a single file, but this might be overkill ??
PUT HERE "get" OR "put"-->
<!--=================================================-->
<!-- General section -->
<!--=================================================-->
<xsl:template match = "/IDSs">
<xsl:result-document href="src/imasjava/imas.java" method="text">
package imasjava;
import java.io.File;
import java.lang.reflect.*;
import java.util.*;
import imasjava.utilities.ImasReflection;
import imasjava.ids.*;
import imasjava.wrapper.LowLevel;
import imasjava.wrapper.Wrapper;
public class imas {
static {
try {
System.loadLibrary("al-java-binding");
} catch (UnsatisfiedLinkError exc) {
System.err.println("(imas.java) Caught UnsatisfiedLinkError: " + exc);
} catch (Throwable exc) {
System.err.println("Cannot link to JNI library: " + exc);
System.exit(1);
}
}
public static final int INTERPOLATION = 3, CLOSEST_SAMPLE = 1, PREVIOUS_SAMPLE = 2;
public static final String al_java_version = "<xsl:value-of select="$AL_VERSION"/>";
public static final int al_java_major_version = <xsl:value-of select="$HLI_MAJOR"/>;
public static final int al_java_minor_version = <xsl:value-of select="$HLI_MINOR"/>;
public static final int al_java_patch_version = <xsl:value-of select="$HLI_PATCH"/>;
public static final String al_dd_version = "<xsl:value-of select="$DD_VERSION"/>";
public static final int al_dd_major_version = <xsl:value-of select="$DD_MAJOR"/>;
public static final int al_dd_minor_version = <xsl:value-of select="$DD_MINOR"/>;
public static final int al_dd_patch_version = <xsl:value-of select="$DD_PATCH"/>;
public static String get_al_version() {
return LowLevel.al_get_version();
}
public static int pulseCtx = -1;
public static String user;
public static String tokamak;
public static String version;
public static int pulse;
public static int run;
/**
* Methods returning the size along the input dimension
*
* @param dim The dimension that is checked.
* @param objs Object input.
* @return the size
*/
public static int get_possible_coordinate(int dim, Object obj) {
java.lang.reflect.Method method;
if (obj != null) {
try {
method = obj.getClass().getMethod("getDim",int.class);
}
catch (SecurityException e) { return 0; }
catch (NoSuchMethodException e) {method=null;}
if (method != null) {
int size;
try {
size = (int) method.invoke(obj,dim);
}
catch (IllegalArgumentException e) { return 0; }
catch (IllegalAccessException e) { return 0; }
catch (InvocationTargetException e) { return 0; }
return size;
} else {
return ((Object[])obj).length;
}
}
return 0;
}
/**
* Methods returning true if the object obj is allocated and of size different to 0. False otherwise.
*
* @param dim The dimension that is checked.
* @param obj Object of the possible coordinates.
* @return False if the size is validated.
*/
public static boolean check_possible_coordinate(int dim, Object obj) {
boolean check = false;
java.lang.reflect.Method method;
if (obj == null) return false;
else {
try {
method = obj.getClass().getMethod("getDim",int.class);
}
catch (SecurityException e) { return true; }
catch (NoSuchMethodException e) {method=null;}
if (method != null) {
try {
int size = (int) method.invoke(obj,dim);
if (size != 0) check = true;
}
catch (IllegalArgumentException e) { return true; }
catch (IllegalAccessException e) { return true; }
catch (InvocationTargetException e) { return true; }
} else {
if (((Object[])obj).length != 0) check = true;
}
}
return check;
}
/**
* Coordinate validation method.
*
* @param dim The dimension that is checked.
* @param name The name of the object that we want to check the dim dimension size.
* @param objdim The target dimension of the coordinate.
* @param coordinates The targets names
* @param fixedcoord True if a fixed size is allowed. False if not
* @param fixeddim Eventual allowed fixed size. set to 0 if fixedcoord = false.
* @param objs Object list of the possible coordinates.
* @return void
* @exception ValidationException is thrown if the coordinate is wrong.
*/
public static void validate_coordinate(int[] shape, String[] coordNames, int[] coordValues, int dim, String name, int objdim, String coordinates, boolean fixedcoord, int fixeddim ,Object... objs) throws ValidationException
{
int arraySize = shape[dim];
if (arraySize > 0){
boolean check = true;
boolean error = true;
int i = 0;
// We check all the possible coordinates allocation
for (Object s : objs) {
if (check_possible_coordinate( objdim, s)) i = i + 1;
}
if (i!=1) {
check = false;
}
// If more of one alternatives coordinates is allocated we raise an exception
if (i>1) {
String[] coordinateslist = {coordinates};
String errMsg = CoordinateValidation.coordinate_not_filled_message(name, coordNames, coordValues, shape, dim+1, coordinateslist);
throw new ValidationException(errMsg);
}
// We check all the possible coordinates (one is allocated)
if(check) {
String[] coordinateslist = coordinates.split(" OR ");
int crd = 0;
for (Object s : objs) {
int objSize = imas.get_possible_coordinate(objdim, s);
if (objSize != 0) {
if (objSize == arraySize) {
error = false;
} else {
if (!fixedcoord) {
String errMsg = CoordinateValidation.coordinate_incorrect_size_message(name, coordNames, coordValues, shape, dim+1, objSize, coordinateslist[crd]);
throw new ValidationException(errMsg);
}
}
}
crd = crd + 1;
}
}
// Last chance: possible alternative fixed size?
if (error && fixedcoord && arraySize == fixeddim) {
error = false;
}
// The size of the target dimension not validated - we raise an error
if (error) {
String errMsg = CoordinateValidation.coordinate_incorrect_size_message(name, coordNames, coordValues, shape, dim+1, 0, coordinates);
throw new ValidationException(errMsg);
}
}
}
public static boolean isIDSClassTimeDependent(String idsName) throws java.lang.ClassNotFoundException {
Class ids = ImasReflection.getIdsClass(idsName);
return imas.isIDSClassTimeDependent(ids);
}
public static boolean isIDSClassTimeDependent(Class idsClass) {
Field[] fields = idsClass.getFields();
boolean timedIds = false;
for (Field field: fields) {
if (field.getName().equals("time")) {
timedIds = true;
break;
}
}
return timedIds;
}
public static java.util.ArrayList getAvailableIDSs() throws
java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException {
java.util.ArrayList result = new java.util.ArrayList();
Class[] classes = imasjava.imas.class.getClasses();
for (Class classId: classes) {
// if(CPOInterface.class.isAssignableFrom(classId))
{
Method method = classId.getMethod("getIdsName");
Object retVal = method.invoke(null);
result.add((String) retVal);
}
}
return result;
}
public static int getMaxOccurences(String idsName) throws
java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException {
Class[] classes = imasjava.imas.class.getClasses();
Class idsClass = null;
for (Class classId: classes) {
if (classId.getName().contains(idsName)) {
Method method = classId.getMethod("getMaxOccurences");
Object retVal = method.invoke(null);
return ((Integer) retVal).intValue();
}
}
return -1;
}
public static int defaultBackend()
{
int backend = LowLevel.MDSPLUS_BACKEND;
String backend_value = System.getenv("IMAS_AL_DEFAULT_BACKEND");
if (backend_value != null)
backend = Integer.parseInt(backend_value);
return backend;
}
public static int fallbackBackend()
{
int backend = LowLevel.NO_BACKEND;
String backend_value = System.getenv("IMAS_AL_FALLBACK_BACKEND");
if (backend_value != null)
backend = Integer.parseInt(backend_value);
return backend;
}
static public void setPulseCtx(int pulseCtx)
{
<xsl:apply-templates select="IDS" mode="SET_PULSE_CTX"/>
}
/**
* Opens database instance.
* @param uri, URI of the IMAS Data Entry
* @param mode, opening mode {OPEN_PULSE, FORCE_OPEN_PULSE, CREATE_PULSE, FORCE_CREATE_PULSE}
* @exception ALException is thrown if the database cannot be open.
*/
public static int open(String uri, int mode) throws ALException
{
int pulseCtx = -1;
try{
pulseCtx = Wrapper.alBeginDataEntryAction(uri, mode);
}
catch(Exception exc) {
throw new ALException( "[al_begin_dataentry_action]: Error opening data entry with URI: " + uri + ", using mode:" + mode + ":\n" + exc.getMessage() );
}
/* to be checked
imas.pulse = pulse;
imas.run = run;
imas.user = user;
imas.tokamak = tokamak;
imas.version = version; */
imas.pulseCtx = pulseCtx;
imas.setPulseCtx(pulseCtx);
return pulseCtx;
}
/**
* Opens database instance.
*
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Machine name
* @param version Database version
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int openEnv(int pulse, int run, String user, String tokamak, String version)
throws ALException {
return openEnv(pulse, run, user, tokamak, version, defaultBackend(), "");
}
/**
* Opens database instance.
*
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Machine name
* @param version Database version
* @param options Options passed down to LowLevel
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int openEnv(
int pulse, int run, String user, String tokamak, String version, String options)
throws ALException {
return openEnv(pulse, run, user, tokamak, version, defaultBackend(), options);
}
/**
* Opens database instance.
*
* @param backendType Type of the backend to be used
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @param backendType Type of the backend to be used
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int openEnv(
int pulse, int run, String user, String tokamak, String version, int backendType)
throws ALException {
return openEnv(pulse, run, user, tokamak, version, backendType, "");
}
/**
* Opens database instance.
* @param backendType Type of the backend to be used
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @param backendType Type of the backend to be used
* @param options Options passed down to LowLevel
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int openEnv(int pulse, int run, String user, String tokamak, String version, int backendType, String options) throws ALException
{
int pulseCtx = -1;
String uri;
try{
uri = Wrapper.alBuildUriFromLegacyParameters(backendType, pulse, run, user, tokamak, version, options);
pulseCtx = Wrapper.alBeginDataEntryAction(uri, LowLevel.OPEN_PULSE);
}
catch(Exception exc) {
int fallback = fallbackBackend();
if (fallback != LowLevel.NO_BACKEND) {
System.out.println("WARNING: the pulse file is not available with the backend " + Integer.toString(backendType) + ", now attempting to access it with the fallback backend " + Integer.toString(fallback));
try {
uri = Wrapper.alBuildUriFromLegacyParameters(fallback, pulse, run, user, tokamak, version, options);
pulseCtx = Wrapper.alBeginDataEntryAction(uri, LowLevel.OPEN_PULSE);
}
catch (Exception exc2) {
throw new ALException("[al_begin_pulse_action]: Error opening pulse file: " + user + "/" + tokamak + "/" + version + "/" + pulse + "/" + run + "/" + fallback + ":\n" + exc.getMessage());
}
}
}
imas.pulse = pulse;
imas.run = run;
imas.user = user;
imas.tokamak = tokamak;
imas.version = version;
imas.pulseCtx = pulseCtx;
imas.setPulseCtx(pulseCtx);
return pulseCtx;
}
/**
* Creates a new database instance.
*
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int createEnv(int pulse, int run, String user, String tokamak, String version)
throws ALException {
return createEnv(pulse, run, user, tokamak, version, defaultBackend(), "");
}
/**
* Creates a new database instance.
*
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @param options Options that are passed down to LowLevel
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int createEnv(
int pulse, int run, String user, String tokamak, String version, String options)
throws ALException {
return createEnv(pulse, run, user, tokamak, version, defaultBackend(), options);
}
/**
*Creates a new database instance.
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @param backendType Type of the backend to be use (take a look inside wrapper/LowLevel)
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int createEnv(int pulse, int run, String user, String tokamak, String version, int backendType) throws ALException
{
return createEnv(pulse, run, user, tokamak, version, backendType, "");
}
/**
*Creates a new database instance.
* @param pulse Pulse number.
* @param run Run Number.
* @param user User name
* @param tokamak Name of the machine
* @param version Database version
* @param backendType Type of the backend to be use (take a look inside wrapper/LowLevel)
* @param options Options passed down to LowLevel
* @return the database index to be used in subsequent get/put calls
* @exception ALException is thrown if the database cannot be open.
*/
public static int createEnv(int pulse, int run, String user, String tokamak, String version, int backendType, String options) throws ALException
{
int pulseCtx = -1;
try {
String uri = Wrapper.alBuildUriFromLegacyParameters(backendType, pulse, run, user, tokamak, version, options);
pulseCtx = Wrapper.alBeginDataEntryAction(uri, LowLevel.FORCE_CREATE_PULSE);
}
catch(Exception exc){
throw new ALException("[al_begin_uri_action]: Error creating pulse file: " + user + "/" + tokamak + "/" + version + "/"+ pulse + "/" + run + "/" + backendType + ":\n" + exc.getMessage() );
}
imas.pulse = pulse;
imas.run = run;
imas.user = user;
imas.tokamak = tokamak;
imas.version = version;
imas.pulseCtx = pulseCtx;
imas.setPulseCtx(pulseCtx);
return pulseCtx;
}
/**
*Closes the currently open database.
* @param refIdx database index, returned by create or open.
**/
static public void close() throws ALException
{
close(imas.pulseCtx);
}
static public void close(int refIdx, String name, int pulse, int run) throws ALException{
System.err.println( "WARNING:\n"
+ "\"int close(int refIdx, String name, int pulse, int run)\" is DEPRECATED.\n"
+ "Please use \"close()\" instead");
close(refIdx);
}
static public void close(int refIdx) throws ALException
{
try{
LowLevel.al_close_pulse(refIdx, LowLevel.CLOSE_PULSE);
}
catch (Exception exc) {
throw new ALException("[al_close_pulse]: Error closing pulse file: " + imas.user + "/" + imas.tokamak + "/" + imas.version + "/"+ imas.pulse + "/" + imas.run + ":\n" + exc.getMessage() );
}
finally {
if(refIdx >= 0)
LowLevel.al_end_action(refIdx);
}
}
/**
*Get the time base of a ids.
* @param idx database index, returned by create or open.
* @param path name of the IDS
* @return a vector containing the times of all slices
* @exception ALException is thrown if the time base cannot be read.
**/
static public Vect1DDouble getTime(int expIdx, String path) throws ALException {
ALLowLevel.beginIDSGet(expIdx, path, true);
Vect1DDouble time = ALLowLevel.getVect1DDouble(expIdx, path, "time");
ALLowLevel.endIDSGet(expIdx, path);
return time;
}
static public int readIdsTimeMode(int pulseCtx, String idsFullName) throws ALException
{
int idsTimeMode = LowLevel.IDS_TIME_MODE_UNKNOWN;
int ctx = -1;
// Open ctx
ctx = LowLevel.al_begin_global_action(pulseCtx, idsFullName, LowLevel.READ_OP);
try
{
idsTimeMode = Wrapper.readData(ctx, "ids_properties/homogeneous_time", "", idsTimeMode);
}
finally
{
LowLevel.al_end_action(ctx);
}
switch(idsTimeMode)
{
case LowLevel.IDS_TIME_MODE_UNKNOWN:
case LowLevel.IDS_TIME_MODE_HETEROGENEOUS:
case LowLevel.IDS_TIME_MODE_HOMOGENEOUS:
case LowLevel.IDS_TIME_MODE_INDEPENDENT:
break;
default:
throw new ALException("ERROR! IDS '<xsl:value-of select="@name"/>': time dependency mode ('ids_properties/homogeneous_time') set to unknown value!");
}
return idsTimeMode;
}
static public String timeModeToString( int idsTimeMode )
{
String strTimeMode;
switch(idsTimeMode)
{
case LowLevel.IDS_TIME_MODE_UNKNOWN:
strTimeMode = "UNKNOWN";
break;
case LowLevel.IDS_TIME_MODE_HETEROGENEOUS:
strTimeMode = "HETEROGENEOUS";
break;
case LowLevel.IDS_TIME_MODE_HOMOGENEOUS:
strTimeMode = "HOMOGENEOUS";
break;
case LowLevel.IDS_TIME_MODE_INDEPENDENT:
strTimeMode = "INDEPENDENT";
break;
default:
strTimeMode = "UNKNOWN";
break;
}
return strTimeMode;
}
static public HashMap<Integer, String> listAllOccurrences(int idx, String idsName, String nodePath)
{
HashMap<Integer, String> OccurrenceList = new HashMap<Integer, String>();
int alOccurrenceList[] = { };
String[] nodeContentist;
int[] occurrenceList;
int size = 0;
try {
alOccurrenceList = LowLevel.al_get_occurrences(idx, idsName);
} catch (Exception exc) {
System.out.println("IMAS:list_all_occurrences:Failed. Error calling al_get_occurrences: " + exc);
}
if (alOccurrenceList != null && !(alOccurrenceList.length == 0)) {
size = alOccurrenceList.length;
} else {
size = 0;
}
nodeContentist = new String[size];
if (nodePath != null && !nodePath.trim().isEmpty()) {
for (int i = 0; i < size; i++) {
int ctx = -1;
int retSize[] = new int[1];
byte dataArr[] = null;
String str = null;
String occurrenceName = idsName;
if (i > 0) occurrenceName += "/"+Integer.toString(i);
try {
ctx = LowLevel.al_begin_global_action(idx, occurrenceName, LowLevel.READ_OP);
}
catch (Exception exc) {
System.out.println("IMAS:list_all_occurrences:Failed. Error calling al_begin_global_action: " + exc);
return null;
}
try {
dataArr = LowLevel.al_read_data_char(ctx, nodePath, "", 1, retSize);
}
catch (Exception exc) {
System.out.println("IMAS:list_all_occurrences:Failed. Error calling al_read_data_char: " + exc);
return null;
}
str = new String(dataArr);
nodeContentist[i] = str.trim();
try {
LowLevel.al_end_action(ctx);
}
catch (Exception exc) {
System.out.println("IMAS:list_all_occurrences:Failed. Error calling al_end_action: " + exc);
return null;
}
}
}
else {
for (int i = 0; i < size; i++) nodeContentist[i] = "";
}
for (int i = 0; i < size; i++) {
OccurrenceList.put(alOccurrenceList[i],nodeContentist[i]);
}
return OccurrenceList;
}
<xsl:apply-templates select = "IDS" mode="DEFINE_IDS_MEMBER"/>
}
</xsl:result-document>
<xsl:apply-templates select = "IDS" mode="DEFINE_IDS_BASE_CLASS"/>
</xsl:template>
<xsl:template match = "IDS" mode="DEFINE_IDS_MEMBER">
public static class <xsl:value-of select="@name"/> extends <xsl:value-of select="@name"/>_IDSBase
{
}
</xsl:template>
<!--=========================================================================================================================================================-->
<!--=========================================================================================================================================================-->
<!--=========================================================================================================================================================-->
<!-- Definition of IDS Base class -->
<!--=========================================================================================================================================================-->
<!--=========================================================================================================================================================-->
<!--=========================================================================================================================================================-->
<xsl:template match = "IDS" mode="DEFINE_IDS_BASE_CLASS">
<xsl:result-document href="src/imasjava/ids/{@name}_IDSBase.java" standalone="yes" method="text">
package imasjava.ids;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import imasjava.wrapper.*;
import imasjava.*;
public class <xsl:value-of select="@name"/>_IDSBase
{
private static final int maxOccurences = <xsl:value-of select="@maxoccur"/>;
private static final String IDS_NAME = "<xsl:value-of select="@name"/>";
private static int idsTimeMode = LowLevel.IDS_TIME_MODE_UNKNOWN;
private static Vect1DDouble idsTime = null;
private static int pulseCtx = -1;
public static int getMaxOccurences() {
return maxOccurences;
}
/**
* Checks whether IDS was initialized or not.
* @return true in case ids_properties is initialized and homogenous_time is set to either 0, or 1, or 2
**/
public boolean isDefined() {
if( (this.ids_properties != null)
&& ( this.ids_properties.homogeneous_time == 0
|| this.ids_properties.homogeneous_time == 1
|| this.ids_properties.homogeneous_time == 2) ) {
return true;
}
return false;
}
public static String getIdsName()
{
return <xsl:value-of select="@name"/>_IDSBase.IDS_NAME;
}
/*
static private void setHomogeneous(boolean isHomogeneous)
{
<xsl:value-of select="@name"/>_IDSBase.isHomogeneous = isHomogeneous;
}
static boolean isHomogeneous()
{
return <xsl:value-of select="@name"/>_IDSBase.isHomogeneous;
}
*/
static private void setIdsTime(Vect1DDouble idsTime )
{
<xsl:value-of select="@name"/>_IDSBase.idsTime = idsTime;
}
static private Vect1DDouble getIdsTime()
{
return <xsl:value-of select="@name"/>_IDSBase.idsTime;
}
static public void setPulseCtx(int pulseCtx)
{
<xsl:value-of select="@name"/>_IDSBase.pulseCtx = pulseCtx;
}
<xsl:apply-templates select = "field" mode = "DECLARE"/>
<xsl:choose>
<!--============ Define time-dependent IDSs ============-->
<xsl:when test = "@timed = 'yes'">
</xsl:when>
<!--============ Define time-independent IDSs ============-->
<xsl:otherwise>
/**
* Method copy <xsl:value-of select="@name"/> copies a full IDS between two databases.
* @param srcIdx The index of the source database, returned by imas.open()
* @param srcOccur The occurence of the IDS in the source database.
* @param destIdx The index of the destination database, returned by imas.open()
* @param destOccur The occurence of the IDS in the destination database.
* @exception ALException Issued when the operation fails for any reason.
**/
public static void copy(int srcIdx, int srcOccur, int destIdx, int destOccur) throws ALException
{
ALLowLevel.alCopyIds(srcIdx, destIdx, "<xsl:value-of select="@name"/>", srcOccur, destOccur);
}
/**
* Method copyEnv <xsl:value-of select="@name"/> copies a full IDS between two databases.
* @param srcUser User of the source database
* @param srcTokamak Tokamak of the source database
* @param srcVersion Version of the source database
* @param srcPulse Pulse number of the source database
* @param srcRun Run number of the source database
* @param srcOccur The occurence of the IDS in the source database.
* @param destUser User of the destination database
* @param destTokamak Tokamak of the destination database
* @param destVersion Version of the destination database
* @param destPulse Pulse number of the destination database
* @param destRun Run number of the destination database
* @param destOccur The occurence of the IDS in the destination database.
* @exception ALException Issued when the operation fails for any reason.
**/
public static void copyEnv(String srcUser, String srcTokamak, String srcVersion, int srcPulse, int srcRun, int srcOccur, String destUser, String destTokamak, String destVersion, int destPulse, int destRun, int destOccur) throws ALException
{
ALLowLevel.alCopyIdsEnv(srcTokamak, srcVersion, srcUser, srcPulse, srcRun, srcOccur, destTokamak, destVersion, destUser, destPulse, destRun, destOccur, "<xsl:value-of select="@name"/>");
}
/* ------------------------------------------------------------------------------------------------------------ */
/* ----------------------------------- PUT ------------------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------ */
/**
* Method put stores a non timed <xsl:value-of select="@name"/> IDSs in the open database.
* @param expIdx The index to the database, returned by imas.open()
* @param path The path name to the selected data item. By convention, only a single tree level is defined for IDS objects in the database.
* @param idss The passed <xsl:value-of select="@name"/> ids.
* @exception ALException Issued when data cannot be stored for any reason.
**/
public static void put(int pulseCtx, String idsFullName, imas.<xsl:value-of select="@name"/> ids) throws ALException
{
int iOccurrence = 0;
/* System.err.println("WARNING:\n"
+ "\"put(int pulseCtx, String idsFullName, imas.<xsl:value-of select="@name"/> ids) \" is DEPRECATED.\n"
+ "Please use \"put()\" instead");
*/
//<xsl:value-of select="@name"/>_IDSBase.setIdsTime(ids.time);
if(!<xsl:value-of select="@name"/>_IDSBase.IDS_NAME.equals(idsFullName))
{
String tokens[] = idsFullName.split("/");
iOccurrence = Integer.parseInt(tokens[1]);
}
ids.setPulseCtx(pulseCtx);
ids.put(iOccurrence);
}
/* ------------------------------------------------------------------------------------------------------------ */
/* ----------------------------------- IDS SERIALIZE --------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------ */
/**
*Serialize data.
* @exception ALException is thrown if can not serialize.
*/
public byte[] serialize() throws ALException
{
return this.serialize(LowLevel.DEFAULT_SERIALIZER_PROTOCOL);
}
/* ------------------------------------------------------------------------------------------------------------ */
/* ----------------------------------- IDS SERIALIZE --------------------------------------------- */
/* ------------------------------------------------------------------------------------------------------------ */
/**
*Serialize data.
* @param protocol Serializer protocol
* @exception ALException is thrown if can not serialize.
*/
public byte[] serialize(int protocol) throws ALException
{
if (protocol == LowLevel.ASCII_SERIALIZER_PROTOCOL) {
File tmpdir;
String IMAS_AL_SERIALIZER_TMP_DIR = System.getenv("IMAS_AL_SERIALIZER_TMP_DIR");
if(IMAS_AL_SERIALIZER_TMP_DIR != null){
tmpdir = new File(IMAS_AL_SERIALIZER_TMP_DIR);
}
else{
tmpdir=new File("/dev/shm") ;
}
if (!tmpdir.exists()) {
tmpdir = new File(System.getProperty("user.dir"));
}
File tmpfile=null;
try{
tmpfile = File.createTempFile("al_serialize_", null, tmpdir);
} catch (Exception exc) {
throw new ALException("Can not create temporary file");
}
String filename= tmpfile.getName();
int _pulseCtx = -1;
<!-- String options = String.format("-fullpath %s",tmpfile); -->
try{
String uri = "imas:ascii?path="+tmpdir+";filename="+filename;
<!-- String uri = Wrapper.alBuildUriFromLegacyParameters(LowLevel.ASCII_BACKEND, 0, 0, "serialize", "serialize", "3", options); -->
_pulseCtx = Wrapper.alBeginDataEntryAction(uri, LowLevel.CREATE_PULSE);
} catch(Exception exc)
{
LowLevel.al_end_action(_pulseCtx);
throw new ALException("Error calling alBeginDataEntryAction() in serialize");
}
// store state and overwrite so we use the ASCII backend in this->put
int _pulseCtx_stored = this.pulseCtx;
this.pulseCtx = _pulseCtx;
this.put();
// restore state
this.pulseCtx = _pulseCtx_stored;
// cleanup
try{
LowLevel.al_close_pulse(_pulseCtx, LowLevel.CLOSE_PULSE);
} catch (Exception exc) {
throw new ALException("[al_close_pulse]: Error closing pulse file: " + exc.getMessage() );
} finally {
if(_pulseCtx >= 0)
LowLevel.al_end_action(_pulseCtx);
}
// read contents of tmpfile
byte[] output =null;
try{
byte[] data=null;
try{
data = Files.readAllBytes(tmpfile.toPath());
} catch (Exception exc) {
throw new ALException("Can not read bytes");
}
output = new byte[1 + data.length];
// prepend serializer proto encoded as one byte ascii code
output[0] = (byte)((char)LowLevel.ASCII_SERIALIZER_PROTOCOL);
int j=1;
for(int i=0;i < data.length; i++){
output[j] = data[i];
j++;
}
}
finally{
tmpfile.delete();
}
return output;
}
else if (protocol == LowLevel.FLEXBUFFERS_SERIALIZER_PROTOCOL) {
int _pulseCtx = -1;
try{
_pulseCtx = Wrapper.alBeginDataEntryAction("imas:flexbuffers?path=/", LowLevel.CREATE_PULSE);
} catch(Exception exc)
{
LowLevel.al_end_action(_pulseCtx);
throw new ALException("Error calling alBeginDataEntryAction() in serialize");
}
// store state and overwrite so we use the Serialize backend in this->put
int _pulseCtx_stored = this.pulseCtx;
this.pulseCtx = _pulseCtx;
this.put();
// restore state
this.pulseCtx = _pulseCtx_stored;
// Read buffer from the backend
int[] size = {0};
byte[] data = LowLevel.al_read_data_char(_pulseCtx, "<buffer>", "", 1, size);
// cleanup
try{
LowLevel.al_close_pulse(_pulseCtx, LowLevel.CLOSE_PULSE);
} finally {
if(_pulseCtx >= 0)
LowLevel.al_end_action(_pulseCtx);