Commit cec16036 authored by Florian Wittkamp's avatar Florian Wittkamp

JSON: IFOS now compatible to the JSON standard

IFOS is now able to read in input files, that are formatted according the JSON standard. Nevertheless, the old files will work as well.

In addition, I fixed some compiler warnings.
parent 94121d66
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -68,5 +61,5 @@ ...@@ -68,5 +61,5 @@
"FORWARD_ONLY" : "10", "FORWARD_ONLY" : "10",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -98,5 +91,5 @@ ...@@ -98,5 +91,5 @@
"FORWARD_ONLY" : "10", "FORWARD_ONLY" : "10",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -99,5 +92,5 @@ ...@@ -99,5 +92,5 @@
"PRO" : "0.01", "PRO" : "0.01",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -237,5 +230,5 @@ ...@@ -237,5 +230,5 @@
"FILT_SIZE" : "5", "FILT_SIZE" : "5",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: toy_example_true.c with flnodes.toy_example
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -83,5 +76,5 @@ ...@@ -83,5 +76,5 @@
"FORWARD_ONLY" : "10", "FORWARD_ONLY" : "10",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: toy_example_true.c with flnodes.toy_example
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -97,5 +90,5 @@ ...@@ -97,5 +90,5 @@
"FORWARD_ONLY" : "10", "FORWARD_ONLY" : "10",
"Verbose" : "comment", "Verbose" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -161,5 +154,5 @@ ...@@ -161,5 +154,5 @@
"FILT_SIZE" : "3", "FILT_SIZE" : "3",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "4", "NPROCX" : "4",
...@@ -175,5 +168,5 @@ ...@@ -175,5 +168,5 @@
"FILT_SIZE" : "3", "FILT_SIZE" : "3",
"Verbose" : "comment", "Verbose" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: toy_example_true.c with flnodes.toy_example
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "2", "NPROCX" : "2",
...@@ -89,5 +82,5 @@ ...@@ -89,5 +82,5 @@
"FORWARD_ONLY" : "10", "FORWARD_ONLY" : "10",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
#-----------------------------------------------------------------
# JSON PARAMETER FILE FOR IFOS
#-----------------------------------------------------------------
# description:
# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start
#
{ {
"Domain Decomposition" : "comment", "Domain Decomposition" : "comment",
"NPROCX" : "2", "NPROCX" : "2",
...@@ -186,5 +179,5 @@ ...@@ -186,5 +179,5 @@
"FILT_SIZE" : "3", "FILT_SIZE" : "3",
"Verbose mode" : "comment", "Verbose mode" : "comment",
"VERBOSE" : "0", "VERBOSE" : "0"
} }
...@@ -46,7 +46,8 @@ void count_killed_traces(int ntr, int swstestshot, int ntr_glob, int **recpos_lo ...@@ -46,7 +46,8 @@ void count_killed_traces(int ntr, int swstestshot, int ntr_glob, int **recpos_lo
if(TRKILL_OFFSET) { if(TRKILL_OFFSET) {
if(MYID==0) { if(MYID==0) {
printf("Automatic offset based TraceKill: Experimental feature"); printf("\n\n ----- Offset based Tracekill ------");
printf("\n Kill offsets between %.1f m and %.1f m",TRKILL_OFFSET_LOWER,TRKILL_OFFSET_UPPER);
} }
/* Generate TraceKill file on the fly */ /* Generate TraceKill file on the fly */
......
...@@ -9,7 +9,7 @@ void eprecond1(float ** We, float ** Ws, float ** Wr, float epsilon){ ...@@ -9,7 +9,7 @@ void eprecond1(float ** We, float ** Ws, float ** Wr, float epsilon){
extern int NX, NY, IDX, IDY, DTINV, EPRECOND, VERBOSE; extern int NX, NY, IDX, IDY, DTINV, EPRECOND, VERBOSE;
extern int POS[3], NXG; extern int POS[3], NXG;
extern float DH; extern float DH;
int i, j, k, l, ii, jj; int i, j, ii, jj;
float maxWetmp, maxWe, x, y, xmin, xmax; float maxWetmp, maxWe, x, y, xmin, xmax;
xmin = DH; xmin = DH;
xmax = NXG*DH; xmax = NXG*DH;
......
...@@ -468,7 +468,7 @@ int *ivector(int nl, int nh); ...@@ -468,7 +468,7 @@ int *ivector(int nl, int nh);
double *dvector(int nl, int nh); double *dvector(int nl, int nh);
float **fmatrix(int nrl, int nrh, int ncl, int nch); float **fmatrix(int nrl, int nrh, int ncl, int nch);
int *ivector(int nl, int nh); int *ivector(int nl, int nh);
void quicksort(float *arr, int dummy, int elements);
float **matrix(int nrl, int nrh, int ncl, int nch); float **matrix(int nrl, int nrh, int ncl, int nch);
int **imatrix(int nrl, int nrh, int ncl, int nch); int **imatrix(int nrl, int nrh, int ncl, int nch);
float ***f3tensor(int nrl, int nrh, int ncl, int nch,int ndl, int ndh); float ***f3tensor(int nrl, int nrh, int ncl, int nch,int ndl, int ndh);
......
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
* Copyright (C) 2016 For the list of authors, see file AUTHORS. * Copyright (C) 2016 For the list of authors, see file AUTHORS.
* *
* This file is part of IFOS. * This file is part of IFOS.
* *
* IFOS is free software: you can redistribute it and/or modify * IFOS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.0 of the License only. * the Free Software Foundation, version 2.0 of the License only.
* *
* IFOS is distributed in the hope that it will be useful, * IFOS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>. * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
-----------------------------------------------------------------------------------------*/ -----------------------------------------------------------------------------------------*/
/* /*
* json_parser.c * json_parser.c
...@@ -24,403 +24,418 @@ ...@@ -24,403 +24,418 @@
#include "fd.h" #include "fd.h"
int read_objects_from_intputfile(FILE *fp, char *input_file,char ** varname_list,char ** value_list) { int read_objects_from_intputfile(FILE *fp, char *input_file,char ** varname_list,char ** value_list) {
char errormessage[STRING_SIZE2]; char errormessage[STRING_SIZE2];
char varname_tmp1[STRING_SIZE2], varname_tmp2[STRING_SIZE2], varname_tmp3[STRING_SIZE2]; char varname_tmp1[STRING_SIZE2], varname_tmp2[STRING_SIZE2], varname_tmp3[STRING_SIZE2];
char varname_tmp4[STRING_SIZE2], varname_tmp5[STRING_SIZE2]; char varname_tmp4[STRING_SIZE2], varname_tmp5[STRING_SIZE2];
char value_tmp1[STRING_SIZE2], value_tmp2[STRING_SIZE2], value_tmp3[STRING_SIZE2]; char value_tmp1[STRING_SIZE2], value_tmp2[STRING_SIZE2], value_tmp3[STRING_SIZE2];
char value_tmp4[STRING_SIZE2], value_tmp5[STRING_SIZE2]; char value_tmp4[STRING_SIZE2], value_tmp5[STRING_SIZE2];
char cline[STRING_SIZE2]; char cline[STRING_SIZE2];
int occurence_doublequotes = 0, occurence_commas = 0; int occurence_doublequotes = 0, occurence_commas = 0;
int lineno=0; int lineno=0;
int number_readobject=0; int number_readobject=0;
FILE * fp_in = NULL; FILE * fp_in = NULL;
//Open parameter input file //Open parameter input file
fp_in=fopen(input_file,"r"); fp_in=fopen(input_file,"r");
if (fp_in==NULL) { if (fp_in==NULL) {
fprintf(fp, "\n==================================================================\n"); fprintf(fp, "\n==================================================================\n");
fprintf(fp, " ERROR: Could not open input file '%s'!", input_file); fprintf(fp, " ERROR: Could not open input file '%s'!", input_file);
fprintf(fp, "\n==================================================================\n"); fprintf(fp, "\n==================================================================\n");
sprintf(errormessage, "\n in: <read_par_json.c> \n"); sprintf(errormessage, "\n in: <read_par_json.c> \n");
err(errormessage); err(errormessage);
} }
//read line by line into a string covering the whole line //read line by line into a string covering the whole line
while (fgets(cline,STRING_SIZE2,fp_in)){ /* leaves via break */ while (fgets(cline,STRING_SIZE2,fp_in)){ /* leaves via break */
/* If there are more than 255 characters in one line, this does not work. */ /* If there are more than 255 characters in one line, this does not work. */
//count of line numbers //count of line numbers
lineno++; lineno++;
/* tests if line is NOT a comment line*/ /* tests if line is NOT a comment line*/
/* tests if line contains at least a colon, double quote and comma sign per line*/ /* tests if line contains at least a colon, double quote sign per line*/
if (((strstr(cline,":"))&&((strstr(cline,","))&&(strstr(cline,"\"")))) && (!(strstr(cline,"comment")) && !(strstr(cline,"Comment")))) { if (((strstr(cline,":"))&&((strstr(cline,"\"")))) && (!(strstr(cline,"comment")) && !(strstr(cline,"Comment")))) {
//count number of double quoates and colon signs //count number of double quoates and colon signs
occurence_doublequotes=count_occure_charinstring(cline,"\""); occurence_doublequotes=count_occure_charinstring(cline,"\"");
occurence_commas=count_occure_charinstring(cline,","); occurence_commas=count_occure_charinstring(cline,",");
//only two pais of double quotes are allowed per line //only two pais of double quotes are allowed per line
switch(occurence_doublequotes){ switch(occurence_doublequotes){
case 4: case 4:
//up to 5 objects can be defined per line, more can be implemented here //up to 5 objects can be defined per line, more can be implemented here
switch(occurence_commas){ switch(occurence_commas){
case 1: //only a single object (name+value) in line
case 0: //only a single object (name+value) in line
//remove old data from strings //remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1)); memset(value_tmp1, '\0', sizeof(value_tmp1));
memset(varname_tmp1, '\0', sizeof(varname_tmp1)); memset(varname_tmp1, '\0', sizeof(varname_tmp1));
//extract object name + object value from the line-string //extract object name + object value from the line-string
if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) { if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) {
sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno); sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno);
err(errormessage); err(errormessage);
} }
//add extracted strings to object list //add extracted strings to object list
add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
break; break;
case 3://two objects (name+value) in line case 1: //only a single object (name+value) in line
//remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1)); //remove old data from strings
memset(varname_tmp1, '\0', sizeof(varname_tmp1)); memset(value_tmp1, '\0', sizeof(value_tmp1));
memset(value_tmp2, '\0', sizeof(value_tmp2)); memset(varname_tmp1, '\0', sizeof(varname_tmp1));
memset(varname_tmp2, '\0', sizeof(varname_tmp2)); //extract object name + object value from the line-string
if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) {
//extract object name + object value from the line-string sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno);
if (sscanf(cline," \"%[^,],%[^\"]\" : \"%[^,],%[^\"]\"", err(errormessage);
varname_tmp1,varname_tmp2,value_tmp1,value_tmp2) != 4) { }
sprintf(errormessage,"Error in Input file, line %i, cannot read two object names and values !",lineno);
err(errormessage); //add extracted strings to object list
} add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
break;
//add extracted strings to object list
add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); case 3://two objects (name+value) in line
add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); //remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1));
break; memset(varname_tmp1, '\0', sizeof(varname_tmp1));
memset(value_tmp2, '\0', sizeof(value_tmp2));
case 5://three objects (name+value) in line memset(varname_tmp2, '\0', sizeof(varname_tmp2));
//remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1)); //extract object name + object value from the line-string
memset(value_tmp2, '\0', sizeof(value_tmp2)); if (sscanf(cline," \"%[^,],%[^\"]\" : \"%[^,],%[^\"]\"",
memset(value_tmp3, '\0', sizeof(value_tmp3)); varname_tmp1,varname_tmp2,value_tmp1,value_tmp2) != 4) {
memset(varname_tmp1, '\0', sizeof(varname_tmp1)); sprintf(errormessage,"Error in Input file, line %i, cannot read two object names and values !",lineno);
memset(varname_tmp2, '\0', sizeof(varname_tmp2)); err(errormessage);
memset(varname_tmp3, '\0', sizeof(varname_tmp3)); }
if (sscanf(cline," \"%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^\"]\"", //add extracted strings to object list
varname_tmp1,varname_tmp2,varname_tmp3,value_tmp1,value_tmp2,value_tmp3) != 6) { add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list);
err(errormessage);
} break;
add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); case 5://three objects (name+value) in line
add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); //remove old data from strings
add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list); memset(value_tmp1, '\0', sizeof(value_tmp1));
memset(value_tmp2, '\0', sizeof(value_tmp2));
break; memset(value_tmp3, '\0', sizeof(value_tmp3));
memset(varname_tmp1, '\0', sizeof(varname_tmp1));
case 7://four objects (name+value) in line memset(varname_tmp2, '\0', sizeof(varname_tmp2));
//remove old data from strings memset(varname_tmp3, '\0', sizeof(varname_tmp3));
memset(value_tmp1, '\0', sizeof(value_tmp1));
memset(value_tmp2, '\0', sizeof(value_tmp2)); if (sscanf(cline," \"%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^\"]\"",
memset(value_tmp3, '\0', sizeof(value_tmp3)); varname_tmp1,varname_tmp2,varname_tmp3,value_tmp1,value_tmp2,value_tmp3) != 6) {
memset(value_tmp4, '\0', sizeof(value_tmp4)); sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno);
memset(varname_tmp1, '\0', sizeof(varname_tmp1)); err(errormessage);
memset(varname_tmp2, '\0', sizeof(varname_tmp2)); }
memset(varname_tmp3, '\0', sizeof(varname_tmp3));
memset(varname_tmp4, '\0', sizeof(varname_tmp4)); add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list);
if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^\"]\"", add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list);
varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,
value_tmp1,value_tmp2,value_tmp3,value_tmp4) != 8) { break;
sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno);
err(errormessage); case 7://four objects (name+value) in line
} //remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1));
add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); memset(value_tmp2, '\0', sizeof(value_tmp2));
add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); memset(value_tmp3, '\0', sizeof(value_tmp3));
add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list); memset(value_tmp4, '\0', sizeof(value_tmp4));
add_object_tolist(varname_tmp4, value_tmp4,&number_readobject, varname_list, value_list); memset(varname_tmp1, '\0', sizeof(varname_tmp1));
memset(varname_tmp2, '\0', sizeof(varname_tmp2));
break; memset(varname_tmp3, '\0', sizeof(varname_tmp3));
case 9://five objects (name+value) in line memset(varname_tmp4, '\0', sizeof(varname_tmp4));
//remove old data from strings
memset(value_tmp1, '\0', sizeof(value_tmp1)); if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^\"]\"",
memset(value_tmp2, '\0', sizeof(value_tmp2)); varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,
memset(value_tmp3, '\0', sizeof(value_tmp3)); value_tmp1,value_tmp2,value_tmp3,value_tmp4) != 8) {
memset(value_tmp4, '\0', sizeof(value_tmp4)); sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno);
memset(value_tmp5, '\0', sizeof(value_tmp5)); err(errormessage);
memset(varname_tmp1, '\0', sizeof(varname_tmp1)); }
memset(varname_tmp2, '\0', sizeof(varname_tmp2));
memset(varname_tmp3, '\0', sizeof(varname_tmp3)); add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
memset(varname_tmp4, '\0', sizeof(varname_tmp4)); add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list);
memset(varname_tmp5, '\0', sizeof(varname_tmp5)); add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list);
add_object_tolist(varname_tmp4, value_tmp4,&number_readobject, varname_list, value_list);
if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^,],%[^\"]\"",
varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,varname_tmp5, break;
value_tmp1,value_tmp2,value_tmp3,value_tmp4,value_tmp5) != 10) { case 9://five objects (name+value) in line
sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); //remove old data from strings
err(errormessage); memset(value_tmp1, '\0', sizeof(value_tmp1));
} memset(value_tmp2, '\0', sizeof(value_tmp2));
memset(value_tmp3, '\0', sizeof(value_tmp3));
add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); memset(value_tmp4, '\0', sizeof(value_tmp4));
add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); memset(value_tmp5, '\0', sizeof(value_tmp5));
add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list); memset(varname_tmp1, '\0', sizeof(varname_tmp1));
add_object_tolist(varname_tmp4, value_tmp4,&number_readobject, varname_list, value_list); memset(varname_tmp2, '\0', sizeof(varname_tmp2));
add_object_tolist(varname_tmp5, value_tmp5,&number_readobject, varname_list, value_list); memset(varname_tmp3, '\0', sizeof(varname_tmp3));
memset(varname_tmp4, '\0', sizeof(varname_tmp4));
//very strange: code crashes if both lines are commented here! memset(varname_tmp5, '\0', sizeof(varname_tmp5));
//this only effects the last case of the switch!
//should though not affect anything as long as number_readobject keeps its value if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^,],%[^\"]\"",
//in this case a new object is allocated which is already there... varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,varname_tmp5,
value_tmp1,value_tmp2,value_tmp3,value_tmp4,value_tmp5) != 10) {
//varname_list = malloc(sizeof(*varname_list)); sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno);
//value_list = malloc(sizeof(*value_list)); err(errormessage);
varname_list[number_readobject] = malloc(STRING_SIZE*sizeof(char*)); }
//varname_list[number_readobject] = (char**)malloc(STRING_SIZE*sizeof(char*)); add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list);
//value_list[number_readobject] = (char**)malloc(STRING_SIZE*sizeof(char*)); add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list);
add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list);
break; add_object_tolist(varname_tmp4, value_tmp4,&number_readobject, varname_list, value_list);
default: add_object_tolist(varname_tmp5, value_tmp5,&number_readobject, varname_list, value_list);
sprintf(errormessage,"Error in Input file, line %i, only 1, 3, 5, 7 or 9 commas are allowed per line, but found %i !",lineno,occurence_commas );
err(errormessage); //very strange: code crashes if both lines are commented here!
break; //this only effects the last case of the switch!
} //should though not affect anything as long as number_readobject keeps its value
break; //in this case a new object is allocated which is already there...
default:
sprintf(errormessage,"Error in Input file, line %i, only 4 (two pairs) of double quotes are allowed per line, but found %i !",lineno,occurence_doublequotes ); //varname_list = malloc(sizeof(*varname_list));
err(errormessage); //value_list = malloc(sizeof(*value_list));
break; varname_list[number_readobject] = malloc(STRING_SIZE*sizeof(char*));
} //varname_list[number_readobject] = (char**)malloc(STRING_SIZE*sizeof(char*));
//value_list[number_readobject] = (char**)malloc(STRING_SIZE*sizeof(char*));
//printf("line %i contains objectno %i varnamme %s with value %s \n",lineno,number_readobject, varname_list[number_readobject-1],value_list[number_readobject-1]);
break;
} default:
} sprintf(errormessage,"Error in Input file, line %i, only 0, 1, 3, 5, 7 or 9 commas are allowed per line, but found %i !",lineno,occurence_commas );
fclose(fp_in); err(errormessage);
return number_readobject; break;
}
break;
default:
sprintf(errormessage,"Error in Input file, line %i, only 4 (two pairs) of double quotes are allowed per line, but found %i !",lineno,occurence_doublequotes );
err(errormessage);
break;
}
//printf("line %i contains objectno %i varnamme %s with value %s \n",lineno,number_readobject, varname_list[number_readobject-1],value_list[number_readobject-1]);
}
}
fclose(fp_in);
return number_readobject;
} }
void print_objectlist_screen(FILE *fp, int number_readobject,char ** varname_list,char ** value_list) { void print_objectlist_screen(FILE *fp, int number_readobject,char ** varname_list,char ** value_list) {