[PATCH 5/7] Add optional support for po2 import from csv files

Anton Lundin glance at acc.umu.se
Thu Nov 21 14:48:40 UTC 2013


Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 dive.h                    |  2 +-
 file.c                    | 10 +++++++---
 qt-ui/csvimportdialog.cpp | 12 +++++++++---
 qt-ui/csvimportdialog.h   |  1 +
 qt-ui/csvimportdialog.ui  | 25 +++++++++++++++++++++++++
 xslt/csv2xml.xslt         | 12 ++++++++++++
 6 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/dive.h b/dive.h
index 800596d..924bab7 100644
--- a/dive.h
+++ b/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, char **error);
+extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, char **error);
 
 extern void save_dives(const char *filename);
 extern void save_dives_logic(const char *filename, bool select_only);
diff --git a/file.c b/file.c
index db9a10e..e985dbb 100644
--- a/file.c
+++ b/file.c
@@ -327,20 +327,21 @@ 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, char **error)
+void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, char **error)
 {
 	struct memblock mem;
 	int pnr=0;
-	char *params[11];
+	char *params[13];
 	char timebuf[MAXCOLDIGITS];
 	char depthbuf[MAXCOLDIGITS];
 	char tempbuf[MAXCOLDIGITS];
+	char po2buf[MAXCOLDIGITS];
 	time_t now;
 	struct tm *timep;
 	char curdate[9];
 	char curtime[6];
 
-	if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS) {
+	if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS) {
 		int len = strlen(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d")) + MAXCOLDIGITS;
 		*error = malloc(len);
 		snprintf(*error, len, translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
@@ -350,6 +351,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, char
 	snprintf(timebuf, MAXCOLDIGITS, "%d", timef);
 	snprintf(depthbuf, MAXCOLDIGITS, "%d", depthf);
 	snprintf(tempbuf, MAXCOLDIGITS, "%d", tempf);
+	snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
 	time(&now);
 	timep = localtime(&now);
 	strftime(curdate, sizeof(curdate), "%Y%m%d", timep);
@@ -364,6 +366,8 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, char
 	params[pnr++] = depthbuf;
 	params[pnr++] = "tempField";
 	params[pnr++] = tempbuf;
+	params[pnr++] = "po2Field";
+	params[pnr++] = po2buf;
 	params[pnr++] = "date";
 	params[pnr++] = curdate;
 	params[pnr++] = "time";
diff --git a/qt-ui/csvimportdialog.cpp b/qt-ui/csvimportdialog.cpp
index 1920805..8a213e0 100644
--- a/qt-ui/csvimportdialog.cpp
+++ b/qt-ui/csvimportdialog.cpp
@@ -6,8 +6,8 @@
 
 const CSVImportDialog::CSVAppConfig CSVImportDialog::CSVApps[CSVAPPS] = {
 		{"", },
-		{"APD Log Viewer", 0, 1, 15, "Tab"},
-		{"XP5", 0, 1, 9, "Tab"},
+		{"APD Log Viewer", 0, 1, 15, 6, "Tab"},
+		{"XP5", 0, 1, 9, -1, "Tab"},
 		{NULL,}
 };
 
@@ -29,6 +29,8 @@ CSVImportDialog::CSVImportDialog(QWidget *parent) :
 	connect(ui->CSVTime, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
 	connect(ui->CSVTemperature, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
 	connect(ui->temperatureCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
+	connect(ui->CSVpo2, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
+	connect(ui->po2CheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
 }
 
 CSVImportDialog::~CSVImportDialog()
@@ -41,7 +43,10 @@ void CSVImportDialog::on_buttonBox_accepted()
 {
 	char *error = NULL;
 
-	parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(), ui->CSVDepth->value(), VALUE_IF_CHECKED(CSVTemperature), &error);
+	parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(),
+			ui->CSVDepth->value(), VALUE_IF_CHECKED(CSVTemperature),
+			VALUE_IF_CHECKED(CSVpo2),
+			&error);
 	if (error != NULL) {
 
 		mainWindow()->showError(error);
@@ -82,6 +87,7 @@ void CSVImportDialog::on_knownImports_currentIndexChanged(int index)
 	ui->CSVTime->blockSignals(false);
 	ui->CSVDepth->blockSignals(false);
 	SET_VALUE_AND_CHECKBOX(CSVTemperature, temperatureCheckBox, CSVApps[index].temperature);
+	SET_VALUE_AND_CHECKBOX(CSVpo2, po2CheckBox, CSVApps[index].po2);
 }
 
 void CSVImportDialog::unknownImports(bool arg1)
diff --git a/qt-ui/csvimportdialog.h b/qt-ui/csvimportdialog.h
index 9a4fc2c..b768827 100644
--- a/qt-ui/csvimportdialog.h
+++ b/qt-ui/csvimportdialog.h
@@ -37,6 +37,7 @@ private:
 		int time;
 		int depth;
 		int temperature;
+		int po2;
 		QString separator;
 	};
 
diff --git a/qt-ui/csvimportdialog.ui b/qt-ui/csvimportdialog.ui
index c650fe3..fe70a07 100644
--- a/qt-ui/csvimportdialog.ui
+++ b/qt-ui/csvimportdialog.ui
@@ -149,6 +149,23 @@
       </property>
      </widget>
     </item>
+    <item row="3" column="1">
+     <widget class="QSpinBox" name="CSVpo2">
+      <property name="enabled">
+       <bool>false</bool>
+      </property>
+      <property name="value">
+       <number>0</number>
+      </property>
+     </widget>
+    </item>
+    <item row="3" column="0">
+     <widget class="QCheckBox" name="po2CheckBox">
+      <property name="text">
+       <string>Po2</string>
+      </property>
+     </widget>
+    </item>
    </layout>
    <zorder>label</zorder>
    <zorder>label_2</zorder>
@@ -156,6 +173,8 @@
    <zorder>CSVDepth</zorder>
    <zorder>temperatureCheckBox</zorder>
    <zorder>CSVTemperature</zorder>
+   <zorder>po2CheckBox</zorder>
+   <zorder>CSVpo2</zorder>
   </widget>
   <widget class="QGroupBox" name="groupBox_4">
    <property name="geometry">
@@ -224,5 +243,11 @@
    <receiver>CSVTemperature</receiver>
    <slot>setEnabled(bool)</slot>
   </connection>
+  <connection>
+   <sender>po2CheckBox</sender>
+   <signal>clicked(bool)</signal>
+   <receiver>CSVpo2</receiver>
+   <slot>setEnabled(bool)</slot>
+  </connection>
  </connections>
 </ui>
diff --git a/xslt/csv2xml.xslt b/xslt/csv2xml.xslt
index 677e836..6a72ffa 100644
--- a/xslt/csv2xml.xslt
+++ b/xslt/csv2xml.xslt
@@ -5,6 +5,7 @@
   <xsl:param name="timeField" select="timeField"/>
   <xsl:param name="depthField" select="depthField"/>
   <xsl:param name="tempField" select="tempField"/>
+  <xsl:param name="po2Field" select="po2Field"/>
   <xsl:param name="date" select="date"/>
   <xsl:param name="time" select="time"/>
   <xsl:output method="xml" indent="yes"/>
@@ -105,6 +106,17 @@
             </xsl:when>
           </xsl:choose>
         </xsl:attribute>
+
+        <xsl:attribute name="po2">
+          <xsl:choose>
+              <xsl:when test="$po2Field >= 0">
+                <xsl:call-template name="getFieldByIndex">
+                  <xsl:with-param name="index" select="$po2Field"/>
+                  <xsl:with-param name="line" select="$line"/>
+                </xsl:call-template>
+              </xsl:when>
+          </xsl:choose>
+        </xsl:attribute>
       </sample>
     </xsl:if>
   </xsl:template>
-- 
1.8.3.2



More information about the subsurface mailing list