mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Allow comma separated CSV files
The separator selector in the CSV import dialog was unused. This passes the value into the xslt and adds ',' as possible value. I'm sure this could be done much better (pass the actual character instead of the index), but I couldn't get that to work and this does seem to do the trick. Also added a test dive to test this feature. Fixes #321 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5fc50b2aab
commit
b5d3476b0b
5 changed files with 43 additions and 4 deletions
2
dive.h
2
dive.h
|
@ -626,7 +626,7 @@ extern void set_filename(const char *filename, bool force);
|
|||
extern int parse_dm4_buffer(const char *url, const char *buf, int size, struct dive_table *table, char **error);
|
||||
|
||||
extern void parse_file(const char *filename, char **error);
|
||||
extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, char **error);
|
||||
extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, int sepidx, char **error);
|
||||
|
||||
extern void save_dives(const char *filename);
|
||||
extern void save_dives_logic(const char *filename, bool select_only);
|
||||
|
|
27
dives/TestComma.csv
Normal file
27
dives/TestComma.csv
Normal file
|
@ -0,0 +1,27 @@
|
|||
Dive Time (s),Depth (m),PPO2 - Setpoint (Bar),PPO2 - C1 Cell 1 (Bar),PPO2 - C1 Cell 2 (Bar),PPO2 - C1 Cell 3 (Bar),PPO2 - C1 Measured (Bar),PPO2 - C2 Cell 1 (Bar),PPO2 - C2 Cell 2 (Bar),PPO2 - C2 Cell 3 (Bar),PPO2 - C2 Measured (Bar),C1 Battery 1 (Volts),C1 Battery 2 (Volts),C2 Battery 1 (Volts),C2 Battery 2 (Volts),Ambient Temp. (Celcius),OTU Exposure (%),CNS Exposure (%),Deco Ceiling (m),Gradient Factor
|
||||
0,0.0,0,0,0,0,0,0,0,0,0,0,0,0,0,19.00,0,0,0,0
|
||||
60,2.5,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
120,4.5,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
180,5.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
240,5.5,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
300,5.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
360,5.5,0,0,0,0,0,0,0,0,0,0,0,0,0,17.00,0,0,0,0
|
||||
420,7.0,0,0,0,0,0,0,0,0,0,0,0,0,0,17.00,0,0,0,0
|
||||
480,9.0,0,0,0,0,0,0,0,0,0,0,0,0,0,17.00,0,0,0,0
|
||||
540,11.5,0,0,0,0,0,0,0,0,0,0,0,0,0,16.00,0,0,0,0
|
||||
600,11.5,0,0,0,0,0,0,0,0,0,0,0,0,0,16.00,0,0,0,0
|
||||
660,12.5,0,0,0,0,0,0,0,0,0,0,0,0,0,16.00,0,0,0,0
|
||||
720,13.5,0,0,0,0,0,0,0,0,0,0,0,0,0,16.00,0,0,0,0
|
||||
780,16.0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
840,17.0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
900,18.0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
960,18.5,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
1020,20.0,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
1080,18.5,0,0,0,0,0,0,0,0,0,0,0,0,0,15.00,0,0,0,0
|
||||
1140,16.0,0,0,0,0,0,0,0,0,0,0,0,0,0,16.00,0,0,0,0
|
||||
1200,10.5,0,0,0,0,0,0,0,0,0,0,0,0,0,17.00,0,0,0,0
|
||||
1260,5.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
1320,4.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
1380,2.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
1440,1.5,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
||||
1460,0.0,0,0,0,0,0,0,0,0,0,0,0,0,0,18.00,0,0,0,0
|
|
8
file.c
8
file.c
|
@ -327,17 +327,18 @@ void parse_file(const char *filename, char **error)
|
|||
|
||||
#define MAXCOLDIGITS 3
|
||||
#define MAXCOLS 100
|
||||
void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, char **error)
|
||||
void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, int sepidx, char **error)
|
||||
{
|
||||
struct memblock mem;
|
||||
int pnr=0;
|
||||
char *params[17];
|
||||
char *params[19];
|
||||
char timebuf[MAXCOLDIGITS];
|
||||
char depthbuf[MAXCOLDIGITS];
|
||||
char tempbuf[MAXCOLDIGITS];
|
||||
char po2buf[MAXCOLDIGITS];
|
||||
char cnsbuf[MAXCOLDIGITS];
|
||||
char stopdepthbuf[MAXCOLDIGITS];
|
||||
char separator_index[MAXCOLDIGITS];
|
||||
time_t now;
|
||||
struct tm *timep;
|
||||
char curdate[9];
|
||||
|
@ -356,6 +357,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
|
|||
snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
|
||||
snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
|
||||
snprintf(stopdepthbuf, MAXCOLDIGITS, "%d", stopdepthf);
|
||||
snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
|
||||
time(&now);
|
||||
timep = localtime(&now);
|
||||
strftime(curdate, sizeof(curdate), "%Y%m%d", timep);
|
||||
|
@ -380,6 +382,8 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
|
|||
params[pnr++] = curdate;
|
||||
params[pnr++] = "time";
|
||||
params[pnr++] = curtime;
|
||||
params[pnr++] = "separatorIndex";
|
||||
params[pnr++] = separator_index;
|
||||
params[pnr++] = NULL;
|
||||
|
||||
if (filename == NULL)
|
||||
|
|
|
@ -22,6 +22,7 @@ CSVImportDialog::CSVImportDialog(QWidget *parent) :
|
|||
ui->knownImports->addItem(CSVApps[i].name);
|
||||
|
||||
ui->CSVSeparator->addItem("Tab");
|
||||
ui->CSVSeparator->addItem(",");
|
||||
ui->knownImports->setCurrentIndex(1);
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
|
@ -52,6 +53,7 @@ void CSVImportDialog::on_buttonBox_accepted()
|
|||
VALUE_IF_CHECKED(CSVpo2),
|
||||
VALUE_IF_CHECKED(CSVcns),
|
||||
VALUE_IF_CHECKED(CSVstopdepth),
|
||||
ui->CSVSeparator->currentIndex(),
|
||||
&error);
|
||||
if (error != NULL) {
|
||||
|
||||
|
|
|
@ -11,11 +11,17 @@
|
|||
<xsl:param name="stopdepthField" select="stopdepthField"/>
|
||||
<xsl:param name="date" select="date"/>
|
||||
<xsl:param name="time" select="time"/>
|
||||
<xsl:param name="separatorIndex" select="separatorIndex"/>
|
||||
<xsl:output method="xml" indent="yes"/>
|
||||
|
||||
<xsl:variable name="lf"><xsl:text>
|
||||
</xsl:text></xsl:variable>
|
||||
<xsl:variable name="fs"><xsl:text> </xsl:text></xsl:variable>
|
||||
<xsl:variable name="fs">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$separatorIndex = 0"><xsl:text> </xsl:text></xsl:when>
|
||||
<xsl:otherwise><xsl:text>,</xsl:text></xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:template match="/">
|
||||
<divelog program="subsurface-import" version="2">
|
||||
|
|
Loading…
Reference in a new issue