Put Multiple SlicesΒΆ
This example focuses on putting multiple slices of IDS into entry.
public static void putSlice() throws Exception {
try {
int dataEntry = imas.open("imas:mdsplus?path=./testdb_mdsplus", LowLevel.FORCE_CREATE_PULSE);
imas.summary emptySummary = new imas.summary();
// set mandatory field
emptySummary.ids_properties.homogeneous_time = LowLevel.IDS_TIME_MODE_HOMOGENEOUS;
// summary/heating_current_drive/nbi is an array of structures, so we need to resize it to use it.
int arraySize = 1;
emptySummary.heating_current_drive.nbi = new imas.summary.heating_current_driveClass.nbiClass[arraySize];
emptySummary.heating_current_drive.nbi[0] = new imas.summary.heating_current_driveClass.nbiClass();
emptySummary.stationary_phase_flag.value = new Vect1DInt(arraySize);
emptySummary.time = new Vect1DDouble(arraySize);
emptySummary.heating_current_drive.nbi[0].beam_current_fraction.value = new Vect2DDouble(3,1);
for (int timeSlice = 0; timeSlice < 5; timeSlice++) {
// NOTE: time-independent data is being put only if it is empty in entry
// in this case summary/stationary_phase_flag/source will be put only at first iteration.
// suggested way to fill this type of fields is to do this outside loop
emptySummary.stationary_phase_flag.source = "Name saved by example code iteration: " + timeSlice;
// fill example data
emptySummary.stationary_phase_flag.value.setElementAt(0, 10*timeSlice);
// fill 2D data
double timeSliceDouble = (double) timeSlice;
double[][] value2DArray = new double[3][1];
for (int i = 0; i<3; i++){
value2DArray[i][0] = 100 * timeSliceDouble;
}
emptySummary.heating_current_drive.nbi[0].beam_current_fraction.value.set(value2DArray);
// NOTE: it is user's responsibility to organize <ids>/time field in ascending manner
// breaking this rule will make get_slice() command to fail
// slice time is being appended to <ids>/time stored in entry
emptySummary.time.setElementAt(0, timeSliceDouble);
emptySummary.putSlice(dataEntry, "summary", emptySummary);
}
// multiple slices can be put into entry as well
emptySummary.stationary_phase_flag.value = new Vect1DInt(3);
double[] valueArray = {11.0, 12.0, 13.0};
Vect1DDouble vectValueArray = new Vect1DDouble(valueArray);
for (int i = 0; i < 3; i++){
int intValue = (int) vectValueArray.getElementAt(i);
emptySummary.stationary_phase_flag.value.setElementAt(i, intValue);
}
emptySummary.heating_current_drive.nbi[0].beam_current_fraction.value = new Vect2DDouble(3,3);
double[][] value2DArray = new double[3][3];
for ( int i = 0; i < 3; i++){
value2DArray[i] = new double[]{1000.0, 2000.0, 3000.0};
}
emptySummary.heating_current_drive.nbi[0].beam_current_fraction.value.set(value2DArray);
emptySummary.time = new Vect1DDouble(3);
double[] timeArray = {50.0, 60.0, 70.0};
Vect1DDouble vectTimeArray = new Vect1DDouble(timeArray);
for (int i =0; i < 3; i++) {
emptySummary.time.setElementAt(i, vectTimeArray.getElementAt(i));
}
emptySummary.putSlice(dataEntry, "summary", emptySummary);
imas.close(dataEntry);
// printing all saved slices in IDS.
try {
int dataEntry1 = imas.open("imas:mdsplus?path=./testdb_mdsplus", LowLevel.OPEN_PULSE);
imas.summary savedSummary = imas.summary.get(dataEntry1, "summary");
System.out.println("\nSaved summary/time field: \n" + savedSummary.time);
System.out.println("Saved summary/heating_current_drive/nbi[0]/beam_current_fraction/value field: \n" + savedSummary.heating_current_drive.nbi[0].beam_current_fraction.value);
System.out.println("Saved summary/stationary_phase_flag/value field: \n" + savedSummary.stationary_phase_flag.value);
imas.close(dataEntry1);
} catch (Exception e) {
System.out.println("Caught exception (raised intentionally): " + e.getMessage());
throw e;
}
} catch (Exception e) {
System.err.println("Following exception occurred\n" + e.getMessage());
throw e;
}
}