ResultsFileManagement : Différence entre versions
De Wiki
Ligne 76 : | Ligne 76 : | ||
Since V1.7, <font color=#556B2F>'''GENIUS'''</font> proposes talso to create data file with the [https://www.sqlite.org/ SQLite] format. | Since V1.7, <font color=#556B2F>'''GENIUS'''</font> proposes talso to create data file with the [https://www.sqlite.org/ SQLite] format. | ||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
+ | // Data initialization | ||
+ | |||
+ | final String NAME_EPHEM_TABLE = "ephemTable"; | ||
+ | final String NAME_EVENT_TABLE = "eventTable"; | ||
+ | |||
+ | final int nbColumnsSql = 3; | ||
+ | |||
+ | final String[] dataNames = { "TIME", "LATG", "LONG" }; | ||
+ | final Double[] gapThresholds = { 1.e+99, Math.PI, Math.PI }; | ||
+ | final String[] unitNames = { "s", "deg", "deg" }; | ||
+ | final String[] description = { "Time", "Latitude", "Longitude" }; | ||
+ | |||
+ | final int nbPtsEphem = 5; | ||
+ | final double[] timeTable = { 0., 10., 20., 30., 40. }; | ||
+ | final double[] latgTable = { -0.5*Math.PI, -0.25*Math.PI, 0., 0.25*Math.PI, 0.5*Math.PI }; | ||
+ | final double[] longTable = { -Math.PI, -0.5*Math.PI, 0., 0.5*Math.PI, Math.PI}; | ||
+ | |||
+ | final int nbPtsEvent = 2; | ||
+ | final double[] timeTableEvent = { 0., 40. }; | ||
+ | final double[] latgTableEvent = { -0.5*Math.PI, 0.5*Math.PI }; | ||
+ | final double[] longTableEvent = { -Math.PI, Math.PI}; | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="java"> | ||
+ | // File creation and reset if it already exists | ||
+ | |||
+ | final File sqliteFile = new File("EPHEM.db"); | ||
+ | if ( sqliteFile.exists() && !sqliteFile.delete() ) { | ||
+ | System.out.println("Sqlite output file failed to delete: %s"); | ||
+ | } | ||
+ | |||
+ | final ResultWriter resultWriter = new ResultWriter(sqliteFile); | ||
+ | resultWriter.open(); | ||
+ | |||
+ | // Table configuration | ||
+ | resultWriter.addTable (NAME_EPHEM_TABLE); | ||
+ | resultWriter.addTable (NAME_EVENT_TABLE); | ||
+ | |||
+ | // Columns configuration | ||
+ | /// Note: | ||
+ | // gapThreshold is the value given for plot discontinuities | ||
+ | // userVisible may be used to add columns but not visible via the GUI (for example for plotting). | ||
+ | for (int i = 0; i < nbColumnsSql; i++) { | ||
+ | resultWriter.addColumn(NAME_EPHEM_TABLE, dataNames[i], description[i], ColumnType.REAL, unitNames[i], gapThresholds[i], true); | ||
+ | resultWriter.addColumn(NAME_EVENT_TABLE, dataNames[i], description[i], ColumnType.REAL, unitNames[i], gapThresholds[i], true); | ||
+ | } | ||
+ | |||
+ | // Adding values for each line | ||
+ | // Note: each table is independant and one may fill them asynchroneously. | ||
+ | for (int i = 0; i < nbPtsEphem; i++) { | ||
+ | // Note: it is mandatory to add a value for each column. If it is not the case, it will raise an error. | ||
+ | // On the other hand, if we add two times a value for the same line/column, the last value will be taken into account. | ||
+ | resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[0], timeTable[i]); | ||
+ | resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[1], latgTable[i]); | ||
+ | resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[2], longTable[i]); | ||
+ | // Line is stored in the database | ||
+ | resultWriter.writeLine(NAME_EPHEM_TABLE); | ||
+ | } | ||
+ | |||
+ | // Same for events | ||
+ | for (int i = 0; i < nbPtsEvent; i++) { | ||
+ | resultWriter.addValue(NAME_EVENT_TABLE, dataNames[0], timeTableEvent[i]); | ||
+ | resultWriter.addValue(NAME_EVENT_TABLE, dataNames[1], latgTableEvent[i]); | ||
+ | resultWriter.addValue(NAME_EVENT_TABLE, dataNames[2], longTableEvent[i]); | ||
+ | resultWriter.writeLine(NAME_EVENT_TABLE); | ||
+ | } | ||
+ | |||
+ | // Closing the data base | ||
+ | resultWriter.close(); | ||
+ | |||
+ | </syntaxhighlight> |
Version du 26 octobre 2017 à 12:48
GENIUS proposes different management for data files. We may identify two different type of file:
- "Madona" files
- SQLite files
Madona files
This format is more or mless derived from the old one used with previous Fortran tools. Thus, its format is a bit different but the principles remains the same. Here is an example of such file with its header then the data ranked by colums:
#<AM-acces:COL-V2.0> <INIT: Logiciel="DOORS" VERSION="V10.0" <COL: 0 : DATE ~cal (Date) 1 : TIME ~s (Time) 2 : X ~m (Integration Frame X Coordinates) 3 : Y ~m (Integration Frame Y Coordinates) 4 : Z ~m (Integration Frame Z Coordinates) 5 : VX ~m/s (Integration Frame X Velocity Coordinates) 6 : VY ~m/s (Integration Frame Y Velocity Coordinates) 7 : VZ ~m/s (Integration Frame Z Velocity Coordinates) 8 : PSI ~deg (Integration Frame Pitch Angle) 9 : TETA ~deg (Integration Frame Yaw Angle) 10 : PHI ~deg (Integration Frame Roll Angle) > > 2010-01-01T00:00:00.000 0.000000000000000e+00 6.678133638255782e+06 3.787739409565575e-01 -6.700773491792874e+03 -6.052524398242765e+00 4.780628779989441e+03 -6.031804544978191e+03 9.000000000000000e+01 5.160000022816957e+01 2.699999999999999e+02 2010-01-01T00:00:10.000 1.000000000000000e+01 6.677625571129634e+06 4.780559859589861e+04 -6.701701843926338e+04 -9.555978350214156e+01 4.780308392028196e+03 -6.031309305094114e+03 9.106301358852552e+01 5.159519405116432e+01 2.708330583318874e+02 ...
Note that to be interpreted, dates must have the "yyyy-mm-ddThh:mm:ss.sss" format (and the "unit" must be ~cal).
Of course, GENIUS includes classes and methods to read or write such file. Here is an example for reading it:
// Opening it and load data final GPlotDataMadonaReader fileData = new GPlotDataMadonaReader(); fileData.load(new File("EPHEM.txt")); // Recovery of the colums information final int nbColumnsMadona = fileData.getNumberColums(null); // Loop on the columns for (int i = 0; i < nbColumnsMadona; i++) { final GPlotColumnInfo colInfo = fileData.getColumnInfo(null, i); System.out.print("Index: " + colInfo.getIndex()); System.out.print(" / Name: " + colInfo.getName()); System.out.print(" / Unit: " + colInfo.getUnitName()); System.out.println(" / Description: " + colInfo.getDesc()); } // We recover only colums 2, 12, 13 & 14 final List<Double[]> dataEphem = fileData.getColumns(null, new Integer[] { 1, 12, 13, 14 }); final int nbLines = dataEphem.get(0).length; System.out.println("Amount of lines of data: " + nbLines); System.out.println(String.format("%s %10e %10e %10e %10e", "First line: ", dataEphem.get(0)[0], dataEphem.get(1)[0], dataEphem.get(2)[0], dataEphem.get(3)[0])); System.out.println(String.format("%s %10e %10e %10e %10e", "Last line: ", dataEphem.get(0)[nbLines-1], dataEphem.get(1)[nbLines-1], dataEphem.get(2)[nbLines-1], dataEphem.get(3)[nbLines-1]));
SqLite files
Since V1.7, GENIUS proposes talso to create data file with the SQLite format.
// Data initialization final String NAME_EPHEM_TABLE = "ephemTable"; final String NAME_EVENT_TABLE = "eventTable"; final int nbColumnsSql = 3; final String[] dataNames = { "TIME", "LATG", "LONG" }; final Double[] gapThresholds = { 1.e+99, Math.PI, Math.PI }; final String[] unitNames = { "s", "deg", "deg" }; final String[] description = { "Time", "Latitude", "Longitude" }; final int nbPtsEphem = 5; final double[] timeTable = { 0., 10., 20., 30., 40. }; final double[] latgTable = { -0.5*Math.PI, -0.25*Math.PI, 0., 0.25*Math.PI, 0.5*Math.PI }; final double[] longTable = { -Math.PI, -0.5*Math.PI, 0., 0.5*Math.PI, Math.PI}; final int nbPtsEvent = 2; final double[] timeTableEvent = { 0., 40. }; final double[] latgTableEvent = { -0.5*Math.PI, 0.5*Math.PI }; final double[] longTableEvent = { -Math.PI, Math.PI};
// File creation and reset if it already exists final File sqliteFile = new File("EPHEM.db"); if ( sqliteFile.exists() && !sqliteFile.delete() ) { System.out.println("Sqlite output file failed to delete: %s"); } final ResultWriter resultWriter = new ResultWriter(sqliteFile); resultWriter.open(); // Table configuration resultWriter.addTable (NAME_EPHEM_TABLE); resultWriter.addTable (NAME_EVENT_TABLE); // Columns configuration /// Note: // gapThreshold is the value given for plot discontinuities // userVisible may be used to add columns but not visible via the GUI (for example for plotting). for (int i = 0; i < nbColumnsSql; i++) { resultWriter.addColumn(NAME_EPHEM_TABLE, dataNames[i], description[i], ColumnType.REAL, unitNames[i], gapThresholds[i], true); resultWriter.addColumn(NAME_EVENT_TABLE, dataNames[i], description[i], ColumnType.REAL, unitNames[i], gapThresholds[i], true); } // Adding values for each line // Note: each table is independant and one may fill them asynchroneously. for (int i = 0; i < nbPtsEphem; i++) { // Note: it is mandatory to add a value for each column. If it is not the case, it will raise an error. // On the other hand, if we add two times a value for the same line/column, the last value will be taken into account. resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[0], timeTable[i]); resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[1], latgTable[i]); resultWriter.addValue(NAME_EPHEM_TABLE, dataNames[2], longTable[i]); // Line is stored in the database resultWriter.writeLine(NAME_EPHEM_TABLE); } // Same for events for (int i = 0; i < nbPtsEvent; i++) { resultWriter.addValue(NAME_EVENT_TABLE, dataNames[0], timeTableEvent[i]); resultWriter.addValue(NAME_EVENT_TABLE, dataNames[1], latgTableEvent[i]); resultWriter.addValue(NAME_EVENT_TABLE, dataNames[2], longTableEvent[i]); resultWriter.writeLine(NAME_EVENT_TABLE); } // Closing the data base resultWriter.close();