The CSV (Comma Separated Values) file format is a very simple data format used by a number of "Excel" like programs.
In its original form, the format consist of lines of values (cells) separated by commas.
However since the commas are also used to separate fraction in Europe, in some cases it is more convenient to use a tab space or semicolon instead to separate the values.
So, which do we use? You actually have the choice! By default I use the tab space but in the configuration you can select between tab, comma or semicolon. You also have the choice of using a dot or a comma for the floating point fraction delimiter (3.5 or 3,5). You even have the choice of what you place in cells that have no computed values (space, zero "0" or three doted lines "---").
How does Excel know what delimiting character is used? That's simple, the CSV file start with the line "sep=x" where "x" is the delimiting character. Most Excel like programs can use this info.
Also, a normal CSV file may have a first data line that is used for labels for the different columns of cells. In sliceO's case, I have 3 lines of header. This enable me to have a hierarchy in the headers. To help my program recognize these lines I add a non printable character at the beginning of the 3 header lines: "0x1C", "0x1D" and "0x1E" (these are ASCII codes for "File, Group and Record Separators).
When I write a floating point value to the file, by default, I have 4 significant digits. This can be changed with the "$UNITS_PRECISION" system variable.
And finally I use UTF-16 when I create my CSV files. That's a character format that use 16 bits for each character. This enable me to use international characters in my files. This also means that the Windows added the value "0xFFFE" at the beginning of the file.
Example (separators in yellow, non printable in red):
|
0xFFFEsep=,<CR><LF> 0x1C00 Slice Info, Surface 2D, Surface 2D, Surface 2D, Surface 2D<CR><LF> 0x1D00 Study ID, Surf. (cm²), Surf. (cm²), mean (HU), mean (HU)<CR><LF> 0x1E00 , TAG 1, TAG 2, TAG 1, TAG 2<CR><LF> ID200631zw01, 54.09, 141.8, 75.57, -22.15<CR><LF> ID200631zw02, 81.72, 32.51, 945.2, 183.5<CR><LF> ID200631zw03, 7.732, 72.83, 42.86, 25.63<CR><LF>
|
|
3 lines of 5 columns with 3 header lines |
|
|