Add optional support for cns import from csv files

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2013-11-21 23:48:41 +01:00 committed by Dirk Hohndel
parent 8dde12fa35
commit 5eccd73a30
6 changed files with 52 additions and 6 deletions

10
file.c
View file

@ -327,21 +327,22 @@ 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, char **error)
void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, char **error)
{
struct memblock mem;
int pnr=0;
char *params[13];
char *params[15];
char timebuf[MAXCOLDIGITS];
char depthbuf[MAXCOLDIGITS];
char tempbuf[MAXCOLDIGITS];
char po2buf[MAXCOLDIGITS];
char cnsbuf[MAXCOLDIGITS];
time_t now;
struct tm *timep;
char curdate[9];
char curtime[6];
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS) {
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || cnsf >= 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);
@ -352,6 +353,7 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
snprintf(depthbuf, MAXCOLDIGITS, "%d", depthf);
snprintf(tempbuf, MAXCOLDIGITS, "%d", tempf);
snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
time(&now);
timep = localtime(&now);
strftime(curdate, sizeof(curdate), "%Y%m%d", timep);
@ -368,6 +370,8 @@ void parse_csv_file(const char *filename, int timef, int depthf, int tempf, int
params[pnr++] = tempbuf;
params[pnr++] = "po2Field";
params[pnr++] = po2buf;
params[pnr++] = "cnsField";
params[pnr++] = cnsbuf;
params[pnr++] = "date";
params[pnr++] = curdate;
params[pnr++] = "time";