diff --git a/par/in_and_out/IFOS2D_FW.json b/par/in_and_out/IFOS2D_FW.json index 0d79b71b0ab0f18c35ba7f670f069bd03499cb13..b1f5b5d2036daab069dd9234f5f1e851e7dde0b7 100644 --- a/par/in_and_out/IFOS2D_FW.json +++ b/par/in_and_out/IFOS2D_FW.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -68,5 +61,5 @@ "FORWARD_ONLY" : "10", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/IFOS2D_FW_all_parameters.json b/par/in_and_out/IFOS2D_FW_all_parameters.json index 065ad2bc9c747fc164c802039b91ff69eff3979c..91fc8548273af9c7247b281cff4a91d8453ccb3f 100644 --- a/par/in_and_out/IFOS2D_FW_all_parameters.json +++ b/par/in_and_out/IFOS2D_FW_all_parameters.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -98,5 +91,5 @@ "FORWARD_ONLY" : "10", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/IFOS2D_INV.json b/par/in_and_out/IFOS2D_INV.json index 73bf766ca483e3a15edea8000bc88fb18de1c61e..b685b15ca19f5aeb0e46f08638c2a45c9d27726c 100644 --- a/par/in_and_out/IFOS2D_INV.json +++ b/par/in_and_out/IFOS2D_INV.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -99,5 +92,5 @@ "PRO" : "0.01", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/IFOS2D_INV_all_parameters.json b/par/in_and_out/IFOS2D_INV_all_parameters.json index bc45d8378d61f53e6308b0ca117762872b197c5e..4a7721f64e9bd94c660d77258c07c099e2cb2e6c 100644 --- a/par/in_and_out/IFOS2D_INV_all_parameters.json +++ b/par/in_and_out/IFOS2D_INV_all_parameters.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: 2 layer example, model grid created by ../genmod/2layer.c -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -237,5 +230,5 @@ "FILT_SIZE" : "5", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_FW.json b/par/in_and_out/toy_example/toy_example_FW.json index 0b8e48e2808beb13cc0655fa4b94693c3185b184..edf9580c9a90aeb3576c9c05a978896300ebb63c 100644 --- a/par/in_and_out/toy_example/toy_example_FW.json +++ b/par/in_and_out/toy_example/toy_example_FW.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: toy_example_true.c with flnodes.toy_example -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -83,5 +76,5 @@ "FORWARD_ONLY" : "10", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_FW_SH.json b/par/in_and_out/toy_example/toy_example_FW_SH.json index 235e51fd513df40e30a2053232187b64e6892fc1..19f2659de5bb9fda0214af6259546bd4ecbaf93f 100644 --- a/par/in_and_out/toy_example/toy_example_FW_SH.json +++ b/par/in_and_out/toy_example/toy_example_FW_SH.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: toy_example_true.c with flnodes.toy_example -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -97,5 +90,5 @@ "FORWARD_ONLY" : "10", "Verbose" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_INV.json b/par/in_and_out/toy_example/toy_example_INV.json index 0f81d8f7ef523d0acc0300cd90ab7bb253292a93..9122200b83d4bc300dece58d64cc2f8825533412 100644 --- a/par/in_and_out/toy_example/toy_example_INV.json +++ b/par/in_and_out/toy_example/toy_example_INV.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -161,5 +154,5 @@ "FILT_SIZE" : "3", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_INV_SH.json b/par/in_and_out/toy_example/toy_example_INV_SH.json index 82e02ac3daafa67acaa2b27db435128c6e385918..9f5b9e98bd12bb7bd059b77a248a62464ee60c55 100644 --- a/par/in_and_out/toy_example/toy_example_INV_SH.json +++ b/par/in_and_out/toy_example/toy_example_INV_SH.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start -# - { "Domain Decomposition" : "comment", "NPROCX" : "4", @@ -175,5 +168,5 @@ "FILT_SIZE" : "3", "Verbose" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_ac_FW.json b/par/in_and_out/toy_example/toy_example_ac_FW.json index 7a1c0e46840dea2bf64a14af93f143c5e3db26ac..0324b7562eaa5b08ce6591a353d84e19da89e92c 100644 --- a/par/in_and_out/toy_example/toy_example_ac_FW.json +++ b/par/in_and_out/toy_example/toy_example_ac_FW.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: toy_example_true.c with flnodes.toy_example -# - { "Domain Decomposition" : "comment", "NPROCX" : "2", @@ -89,5 +82,5 @@ "FORWARD_ONLY" : "10", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/par/in_and_out/toy_example/toy_example_ac_INV.json b/par/in_and_out/toy_example/toy_example_ac_INV.json index f16f1e20656d936ef78f8937e8c208525bfc7b12..7aedfe756dd2557e06a74c4ceb188936a4fc3f05 100644 --- a/par/in_and_out/toy_example/toy_example_ac_INV.json +++ b/par/in_and_out/toy_example/toy_example_ac_INV.json @@ -1,10 +1,3 @@ -#----------------------------------------------------------------- -# JSON PARAMETER FILE FOR IFOS -#----------------------------------------------------------------- -# description: -# description/name of the model: genmod/toy_example_start.c with flnodes.toy_example.start -# - { "Domain Decomposition" : "comment", "NPROCX" : "2", @@ -186,5 +179,5 @@ "FILT_SIZE" : "3", "Verbose mode" : "comment", - "VERBOSE" : "0", + "VERBOSE" : "0" } diff --git a/src/count_killed_traces.c b/src/count_killed_traces.c index 59d4442b79961dd140cdda2b573b842182bc9bd4..1d549bc9cd57768a68e06641653089e57003b007 100644 --- a/src/count_killed_traces.c +++ b/src/count_killed_traces.c @@ -46,7 +46,8 @@ void count_killed_traces(int ntr, int swstestshot, int ntr_glob, int **recpos_lo if(TRKILL_OFFSET) { 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 */ diff --git a/src/eprecond1.c b/src/eprecond1.c index dafc586a7b70da1027ac5b3d84896bd673505c33..ab3fe3c137f8e21c55e2e333b7fbf84a4ed2c859 100644 --- a/src/eprecond1.c +++ b/src/eprecond1.c @@ -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 POS[3], NXG; extern float DH; - int i, j, k, l, ii, jj; + int i, j, ii, jj; float maxWetmp, maxWe, x, y, xmin, xmax; xmin = DH; xmax = NXG*DH; diff --git a/src/fd.h b/src/fd.h index c9c203537098dcb22e8e9523ea752f138fe60349..d6c9d1f3f071fea55f1797fa3e1b139dd9b4fc0c 100644 --- a/src/fd.h +++ b/src/fd.h @@ -468,7 +468,7 @@ int *ivector(int nl, int nh); double *dvector(int nl, int nh); float **fmatrix(int nrl, int nrh, int ncl, int nch); int *ivector(int nl, int nh); - +void quicksort(float *arr, int dummy, int elements); float **matrix(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); diff --git a/src/json_parser.c b/src/json_parser.c index 8b46571a8407319baa9fdf3c94d6d50b5296a4c9..50c3b271f7b043025688ae2c4b6d2a56fa56d43c 100644 --- a/src/json_parser.c +++ b/src/json_parser.c @@ -2,19 +2,19 @@ * Copyright (C) 2016 For the list of authors, see file AUTHORS. * * This file is part of IFOS. - * + * * IFOS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2.0 of the License only. - * + * * IFOS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with IFOS. See file COPYING and/or . ------------------------------------------------------------------------------------------*/ + -----------------------------------------------------------------------------------------*/ /* * json_parser.c @@ -24,403 +24,418 @@ #include "fd.h" int read_objects_from_intputfile(FILE *fp, char *input_file,char ** varname_list,char ** value_list) { - - char errormessage[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 value_tmp1[STRING_SIZE2], value_tmp2[STRING_SIZE2], value_tmp3[STRING_SIZE2]; - char value_tmp4[STRING_SIZE2], value_tmp5[STRING_SIZE2]; - char cline[STRING_SIZE2]; - int occurence_doublequotes = 0, occurence_commas = 0; - int lineno=0; - int number_readobject=0; - FILE * fp_in = NULL; - - //Open parameter input file - fp_in=fopen(input_file,"r"); - - - if (fp_in==NULL) { - fprintf(fp, "\n==================================================================\n"); - fprintf(fp, " ERROR: Could not open input file '%s'!", input_file); - fprintf(fp, "\n==================================================================\n"); - sprintf(errormessage, "\n in: \n"); - err(errormessage); - } - - //read line by line into a string covering the whole line - while (fgets(cline,STRING_SIZE2,fp_in)){ /* leaves via break */ - /* If there are more than 255 characters in one line, this does not work. */ - //count of line numbers - lineno++; - /* tests if line is NOT a comment line*/ - /* tests if line contains at least a colon, double quote and comma sign per line*/ - if (((strstr(cline,":"))&&((strstr(cline,","))&&(strstr(cline,"\"")))) && (!(strstr(cline,"comment")) && !(strstr(cline,"Comment")))) { - - //count number of double quoates and colon signs - occurence_doublequotes=count_occure_charinstring(cline,"\""); - occurence_commas=count_occure_charinstring(cline,","); - - //only two pais of double quotes are allowed per line - switch(occurence_doublequotes){ - case 4: - //up to 5 objects can be defined per line, more can be implemented here - switch(occurence_commas){ - case 1: //only a single object (name+value) in line - - //remove old data from strings - memset(value_tmp1, '\0', sizeof(value_tmp1)); - memset(varname_tmp1, '\0', sizeof(varname_tmp1)); - //extract object name + object value from the line-string - if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) { - sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno); - err(errormessage); - } - - //add extracted strings to object list - add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); - break; - - case 3://two objects (name+value) in line - //remove old data from strings - memset(value_tmp1, '\0', sizeof(value_tmp1)); - memset(varname_tmp1, '\0', sizeof(varname_tmp1)); - memset(value_tmp2, '\0', sizeof(value_tmp2)); - memset(varname_tmp2, '\0', sizeof(varname_tmp2)); - - //extract object name + object value from the line-string - if (sscanf(cline," \"%[^,],%[^\"]\" : \"%[^,],%[^\"]\"", - 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); - add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); - - break; - - case 5://three objects (name+value) in line - //remove old data from strings - memset(value_tmp1, '\0', sizeof(value_tmp1)); - memset(value_tmp2, '\0', sizeof(value_tmp2)); - memset(value_tmp3, '\0', sizeof(value_tmp3)); - memset(varname_tmp1, '\0', sizeof(varname_tmp1)); - memset(varname_tmp2, '\0', sizeof(varname_tmp2)); - memset(varname_tmp3, '\0', sizeof(varname_tmp3)); - - if (sscanf(cline," \"%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^\"]\"", - varname_tmp1,varname_tmp2,varname_tmp3,value_tmp1,value_tmp2,value_tmp3) != 6) { - sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); - err(errormessage); - } - - 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); - add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list); - - break; - - case 7://four objects (name+value) in line - //remove old data from strings - memset(value_tmp1, '\0', sizeof(value_tmp1)); - memset(value_tmp2, '\0', sizeof(value_tmp2)); - memset(value_tmp3, '\0', sizeof(value_tmp3)); - memset(value_tmp4, '\0', sizeof(value_tmp4)); - memset(varname_tmp1, '\0', sizeof(varname_tmp1)); - memset(varname_tmp2, '\0', sizeof(varname_tmp2)); - memset(varname_tmp3, '\0', sizeof(varname_tmp3)); - memset(varname_tmp4, '\0', sizeof(varname_tmp4)); - - if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^\"]\"", - varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4, - value_tmp1,value_tmp2,value_tmp3,value_tmp4) != 8) { - sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); - err(errormessage); - } - - 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); - 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); - - break; - case 9://five objects (name+value) in line - //remove old data from strings - memset(value_tmp1, '\0', sizeof(value_tmp1)); - memset(value_tmp2, '\0', sizeof(value_tmp2)); - memset(value_tmp3, '\0', sizeof(value_tmp3)); - memset(value_tmp4, '\0', sizeof(value_tmp4)); - memset(value_tmp5, '\0', sizeof(value_tmp5)); - memset(varname_tmp1, '\0', sizeof(varname_tmp1)); - memset(varname_tmp2, '\0', sizeof(varname_tmp2)); - memset(varname_tmp3, '\0', sizeof(varname_tmp3)); - memset(varname_tmp4, '\0', sizeof(varname_tmp4)); - memset(varname_tmp5, '\0', sizeof(varname_tmp5)); - - if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^,],%[^\"]\"", - varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,varname_tmp5, - value_tmp1,value_tmp2,value_tmp3,value_tmp4,value_tmp5) != 10) { - sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); - err(errormessage); - } - - 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); - 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); - add_object_tolist(varname_tmp5, value_tmp5,&number_readobject, varname_list, value_list); - - //very strange: code crashes if both lines are commented here! - //this only effects the last case of the switch! - //should though not affect anything as long as number_readobject keeps its value - //in this case a new object is allocated which is already there... - - //varname_list = malloc(sizeof(*varname_list)); - //value_list = malloc(sizeof(*value_list)); - 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*)); - - break; - default: - 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); - 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; + + char errormessage[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 value_tmp1[STRING_SIZE2], value_tmp2[STRING_SIZE2], value_tmp3[STRING_SIZE2]; + char value_tmp4[STRING_SIZE2], value_tmp5[STRING_SIZE2]; + char cline[STRING_SIZE2]; + int occurence_doublequotes = 0, occurence_commas = 0; + int lineno=0; + int number_readobject=0; + FILE * fp_in = NULL; + + //Open parameter input file + fp_in=fopen(input_file,"r"); + + + if (fp_in==NULL) { + fprintf(fp, "\n==================================================================\n"); + fprintf(fp, " ERROR: Could not open input file '%s'!", input_file); + fprintf(fp, "\n==================================================================\n"); + sprintf(errormessage, "\n in: \n"); + err(errormessage); + } + + //read line by line into a string covering the whole line + while (fgets(cline,STRING_SIZE2,fp_in)){ /* leaves via break */ + /* If there are more than 255 characters in one line, this does not work. */ + //count of line numbers + lineno++; + /* tests if line is NOT a comment line*/ + /* tests if line contains at least a colon, double quote sign per line*/ + if (((strstr(cline,":"))&&((strstr(cline,"\"")))) && (!(strstr(cline,"comment")) && !(strstr(cline,"Comment")))) { + + //count number of double quoates and colon signs + occurence_doublequotes=count_occure_charinstring(cline,"\""); + occurence_commas=count_occure_charinstring(cline,","); + + //only two pais of double quotes are allowed per line + switch(occurence_doublequotes){ + case 4: + //up to 5 objects can be defined per line, more can be implemented here + switch(occurence_commas){ + + case 0: //only a single object (name+value) in line + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + //extract object name + object value from the line-string + if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) { + sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno); + err(errormessage); + } + + //add extracted strings to object list + add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); + break; + + case 1: //only a single object (name+value) in line + + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + //extract object name + object value from the line-string + if (sscanf(cline," \"%[^\"]\" : \"%[^\"]\"",varname_tmp1,value_tmp1) != 2) { + sprintf(errormessage,"Error in Input file, line %i, cannot read object name and object value !",lineno); + err(errormessage); + } + + //add extracted strings to object list + add_object_tolist(varname_tmp1, value_tmp1,&number_readobject, varname_list, value_list); + break; + + case 3://two objects (name+value) in line + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + memset(value_tmp2, '\0', sizeof(value_tmp2)); + memset(varname_tmp2, '\0', sizeof(varname_tmp2)); + + //extract object name + object value from the line-string + if (sscanf(cline," \"%[^,],%[^\"]\" : \"%[^,],%[^\"]\"", + 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); + add_object_tolist(varname_tmp2, value_tmp2,&number_readobject, varname_list, value_list); + + break; + + case 5://three objects (name+value) in line + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(value_tmp2, '\0', sizeof(value_tmp2)); + memset(value_tmp3, '\0', sizeof(value_tmp3)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + memset(varname_tmp2, '\0', sizeof(varname_tmp2)); + memset(varname_tmp3, '\0', sizeof(varname_tmp3)); + + if (sscanf(cline," \"%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^\"]\"", + varname_tmp1,varname_tmp2,varname_tmp3,value_tmp1,value_tmp2,value_tmp3) != 6) { + sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); + err(errormessage); + } + + 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); + add_object_tolist(varname_tmp3, value_tmp3,&number_readobject, varname_list, value_list); + + break; + + case 7://four objects (name+value) in line + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(value_tmp2, '\0', sizeof(value_tmp2)); + memset(value_tmp3, '\0', sizeof(value_tmp3)); + memset(value_tmp4, '\0', sizeof(value_tmp4)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + memset(varname_tmp2, '\0', sizeof(varname_tmp2)); + memset(varname_tmp3, '\0', sizeof(varname_tmp3)); + memset(varname_tmp4, '\0', sizeof(varname_tmp4)); + + if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^\"]\"", + varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4, + value_tmp1,value_tmp2,value_tmp3,value_tmp4) != 8) { + sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); + err(errormessage); + } + + 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); + 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); + + break; + case 9://five objects (name+value) in line + //remove old data from strings + memset(value_tmp1, '\0', sizeof(value_tmp1)); + memset(value_tmp2, '\0', sizeof(value_tmp2)); + memset(value_tmp3, '\0', sizeof(value_tmp3)); + memset(value_tmp4, '\0', sizeof(value_tmp4)); + memset(value_tmp5, '\0', sizeof(value_tmp5)); + memset(varname_tmp1, '\0', sizeof(varname_tmp1)); + memset(varname_tmp2, '\0', sizeof(varname_tmp2)); + memset(varname_tmp3, '\0', sizeof(varname_tmp3)); + memset(varname_tmp4, '\0', sizeof(varname_tmp4)); + memset(varname_tmp5, '\0', sizeof(varname_tmp5)); + + if (sscanf(cline," \"%[^,],%[^,],%[^,],%[^,],%[^\"]\" : \"%[^,],%[^,],%[^,],%[^,],%[^\"]\"", + varname_tmp1,varname_tmp2,varname_tmp3,varname_tmp4,varname_tmp5, + value_tmp1,value_tmp2,value_tmp3,value_tmp4,value_tmp5) != 10) { + sprintf(errormessage,"Error in Input file, line %i, cannot read three object names and values !",lineno); + err(errormessage); + } + + 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); + 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); + add_object_tolist(varname_tmp5, value_tmp5,&number_readobject, varname_list, value_list); + + //very strange: code crashes if both lines are commented here! + //this only effects the last case of the switch! + //should though not affect anything as long as number_readobject keeps its value + //in this case a new object is allocated which is already there... + + //varname_list = malloc(sizeof(*varname_list)); + //value_list = malloc(sizeof(*value_list)); + 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*)); + + 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 ); + err(errormessage); + 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) { - - int ii; - fprintf(fp, "\n===========================================================\n"); - fprintf(fp, "|| Object # | object name \t| object value ||"); - fprintf(fp, "\n===========================================================\n"); - for (ii=0;ii0){ - /* string empty or 'garbage after double' */ - sprintf(errormessage,"Error in Input file, value of object %s contains more than one float: '%s'!",string_in,string_buffer); - err(errormessage); - } - - //printf("string %s found with value %f \n",string_in,double_buffer); - //printf ("%lf = %lf + %lf \n", double_buffer, intpart, fractpart); - - if ((modf (double_buffer, &intpart))==0){ - *int_buffer = atoi(value_list[ii]); - //printf("\nfunc: string %s found with value %i \n",string_in,*int_buffer); - checkifstringfound=0; - } - else { - //double read, not an int (there are decimal places) - sprintf(errormessage,"Error in Input file, value of object %s is not an int : %f !",string_in,double_buffer); - err(errormessage); - *int_buffer=-1; - checkifstringfound=2; - } - - } - else { - checkifstringfound=1; - } - return checkifstringfound; + char ** varname_list,char ** value_list){ + + int ii=0, checkifstringfound=1; + double double_buffer; + double intpart; + char * string_buffer; + char errormessage[STRING_SIZE2]; + + + while ((strcmp(varname_list[ii],string_in)!=0) && ((ii+1)0){ + /* string empty or 'garbage after double' */ + sprintf(errormessage,"Error in Input file, value of object %s contains more than one float: '%s'!",string_in,string_buffer); + err(errormessage); + } + + //printf("string %s found with value %f \n",string_in,double_buffer); + //printf ("%lf = %lf + %lf \n", double_buffer, intpart, fractpart); + + if ((modf (double_buffer, &intpart))==0){ + *int_buffer = atoi(value_list[ii]); + //printf("\nfunc: string %s found with value %i \n",string_in,*int_buffer); + checkifstringfound=0; + } + else { + //double read, not an int (there are decimal places) + sprintf(errormessage,"Error in Input file, value of object %s is not an int : %f !",string_in,double_buffer); + err(errormessage); + *int_buffer=-1; + checkifstringfound=2; + } + + } + else { + checkifstringfound=1; + } + return checkifstringfound; } int get_float_from_objectlist(char string_in[STRING_SIZE2], int number_readobject, float * double_buffer, - char ** varname_list,char ** value_list){ - - int ii=0, checkifstringfound=1; - double double_dummy; - char * string_buffer; - char errormessage[STRING_SIZE2]; - - while ((strcmp(varname_list[ii],string_in)!=0) && ((ii+1)0) && ((is_string_blankspace(string_buffer))==1))){ - //printf("\nfunc: string %s found with value %5.5f \n",string_in,double_dummy); - *double_buffer=double_dummy; - checkifstringfound=0; - } - else { - /* string empty or 'garbage after double' */ - sprintf(errormessage,"Error in Input file, value of object %s contains more than one float: '%s'!",string_in,string_buffer); - err(errormessage); - checkifstringfound=2; - } - - } - else { - checkifstringfound=1; - } - return checkifstringfound; + char ** varname_list,char ** value_list){ + + int ii=0, checkifstringfound=1; + double double_dummy; + char * string_buffer; + char errormessage[STRING_SIZE2]; + + while ((strcmp(varname_list[ii],string_in)!=0) && ((ii+1)0) && ((is_string_blankspace(string_buffer))==1))){ + //printf("\nfunc: string %s found with value %5.5f \n",string_in,double_dummy); + *double_buffer=double_dummy; + checkifstringfound=0; + } + else { + /* string empty or 'garbage after double' */ + sprintf(errormessage,"Error in Input file, value of object %s contains more than one float: '%s'!",string_in,string_buffer); + err(errormessage); + checkifstringfound=2; + } + + } + else { + checkifstringfound=1; + } + return checkifstringfound; } int get_string_from_objectlist(char string_in[STRING_SIZE2], int number_readobject, char string_buffer[STRING_SIZE2], - char ** varname_list,char ** value_list){ - - int ii=0, checkifstringfound=1; - char errormessage[STRING_SIZE2]; - - while ((strcmp(varname_list[ii],string_in)!=0) && ((ii+1). ------------------------------------------------------------------------------------------*/ + -----------------------------------------------------------------------------------------*/ #define SHIFT_IND 1 @@ -24,441 +24,441 @@ void err(char err_text[]){ - extern int MYID; - - fprintf(stdout,"Message from PE %d\n",MYID); - fprintf(stdout,"R U N - T I M E E R R O R: \n"); - fprintf(stdout,"%s\n",err_text); - fprintf(stdout,"...now exiting to system.\n"); - - MPI_Abort(MPI_COMM_WORLD, 1); - exit(1); + extern int MYID; + + fprintf(stdout,"Message from PE %d\n",MYID); + fprintf(stdout,"R U N - T I M E E R R O R: \n"); + fprintf(stdout,"%s\n",err_text); + fprintf(stdout,"...now exiting to system.\n"); + + MPI_Abort(MPI_COMM_WORLD, 1); + exit(1); } void warning(char warn_text[]){ - /* standard warnings handler */ - fprintf(stdout,"W A R N I N G M E S S A G E: \n"); - fprintf(stdout,"%s\n",warn_text); + /* standard warnings handler */ + fprintf(stdout,"W A R N I N G M E S S A G E: \n"); + fprintf(stdout,"%s\n",warn_text); } double maximum(float **a, int nx, int ny){ - double maxi=0.0; - int i, j; - - - for (j=1;j<=ny;j++) - for (i=1;i<=nx;i++) - if (fabs((double) a[i][j])>maxi) maxi=fabs((double)a[i][j]); - return maxi; + double maxi=0.0; + int i, j; + + + for (j=1;j<=ny;j++) + for (i=1;i<=nx;i++) + if (fabs((double) a[i][j])>maxi) maxi=fabs((double)a[i][j]); + return maxi; } float minimum_m(float **mat, int nx, int ny) { - float minm; - int i,j; - - minm = mat[1][1]; - for (i=1;i<=nx;i++) - for (j=1;j<=ny;j++) - { - if (i*j==1) continue; - if (mat[j][i] < minm) - { - minm = mat[j][i]; - } - } - return minm; + float minm; + int i,j; + + minm = mat[1][1]; + for (i=1;i<=nx;i++) + for (j=1;j<=ny;j++) + { + if (i*j==1) continue; + if (mat[j][i] < minm) + { + minm = mat[j][i]; + } + } + return minm; } float maximum_m(float **mat, int nx, int ny) { - float maxm; - int i,j; - - maxm = mat[1][1]; - for (i=1;i<=nx;i++) - for (j=1;j<=ny;j++) - { - if (i*j==1) continue; - if (mat[j][i] > maxm) - { - maxm = mat[j][i]; - } - } - return maxm; + float maxm; + int i,j; + + maxm = mat[1][1]; + for (i=1;i<=nx;i++) + for (j=1;j<=ny;j++) + { + if (i*j==1) continue; + if (mat[j][i] > maxm) + { + maxm = mat[j][i]; + } + } + return maxm; } float *vector(int ni, int nj){ - float *a; - int k; - - a=(float *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(float))); - if (!a) err("util.c: allocation failure in function vector()"); - for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0.0; - return a-ni+SHIFT_IND; + float *a; + int k; + + a=(float *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(float))); + if (!a) err("util.c: allocation failure in function vector()"); + for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0.0; + return a-ni+SHIFT_IND; } int *ivector(int ni, int nj){ - - int *a; - int k; - - a=(int *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(int))); - if (!a) err("util.c: allocation failure in function ivector()"); - for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; - return a-ni+SHIFT_IND; + + int *a; + int k; + + a=(int *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(int))); + if (!a) err("util.c: allocation failure in function ivector()"); + for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; + return a-ni+SHIFT_IND; } unsigned short int *usvector(int ni, int nj){ - - unsigned short int *a; - int k; - - a=(unsigned short int *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned short int))); - if (!a) err("util.c: allocation failure in function usvector()"); - for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; - return a-ni+SHIFT_IND; + + unsigned short int *a; + int k; + + a=(unsigned short int *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned short int))); + if (!a) err("util.c: allocation failure in function usvector()"); + for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; + return a-ni+SHIFT_IND; } unsigned char *cvector(int ni, int nj){ - - unsigned char *a; - - a=(unsigned char *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned char))); - if (!a) err("util.c: allocation failure in function cvector()"); - return a-ni+SHIFT_IND; + + unsigned char *a; + + a=(unsigned char *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned char))); + if (!a) err("util.c: allocation failure in function cvector()"); + return a-ni+SHIFT_IND; } unsigned long *lvector(int ni, int nj){ - - unsigned long *a; - int k; - - a=(unsigned long *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned long))); - if (!a) err("util.c: allocation failure in function lvector()"); - for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; - return a-ni+SHIFT_IND; + + unsigned long *a; + int k; + + a=(unsigned long *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(unsigned long))); + if (!a) err("util.c: allocation failure in function lvector()"); + for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0; + return a-ni+SHIFT_IND; } double *dvector(int ni, int nj){ - - double *a; - int k; - - a=(double *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(double))); - if (!a) err("util.c: allocation failure in function dvector()"); - for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0.0; - return a-ni+SHIFT_IND; + + double *a; + int k; + + a=(double *)malloc((size_t) ((nj-ni+1+SHIFT_IND)*sizeof(double))); + if (!a) err("util.c: allocation failure in function dvector()"); + for (k=0;k<(nj-ni+1+SHIFT_IND);k++) a[k]=0.0; + return a-ni+SHIFT_IND; } float **fmatrix(int mrl, int mrh, int mcl, int mch){ - - int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; - float **ma; - - ma=(float **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float*))); - if (!ma) err("util.c: allocation failure 1 in function fmatrix() "); - ma += SHIFT_IND; - ma -= mrl; - - ma[mrl]=(float *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float))); - if (!ma[mrl]) err("util.c: allocation failure 2 in function fmatrix() "); - ma[mrl] += SHIFT_IND; - ma[mrl] -= mcl; - - for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; - - for (k=mrl;k<=mrh;k++) - for (l=mcl;l<=mch;l++) ma[k][l]=0.0; - - return ma; + + int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; + float **ma; + + ma=(float **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float*))); + if (!ma) err("util.c: allocation failure 1 in function fmatrix() "); + ma += SHIFT_IND; + ma -= mrl; + + ma[mrl]=(float *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float))); + if (!ma[mrl]) err("util.c: allocation failure 2 in function fmatrix() "); + ma[mrl] += SHIFT_IND; + ma[mrl] -= mcl; + + for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; + + for (k=mrl;k<=mrh;k++) + for (l=mcl;l<=mch;l++) ma[k][l]=0.0; + + return ma; } float **matrix(int mrl, int mrh, int mcl, int mch){ - - int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; - float **ma; - - ma=(float **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float*))); - if (!ma) err("util.c: allocation failure 1 in function matrix() "); - ma += SHIFT_IND; - ma -= mrl; - - ma[mrl]=(float *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float))); - if (!ma[mrl]) err("util.c: allocation failure 2 in function matrix() "); - ma[mrl] += SHIFT_IND; - ma[mrl] -= mcl; - - for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; - - for (k=mrl;k<=mrh;k++) - for (l=mcl;l<=mch;l++) ma[k][l]=0.0; - - return ma; + + int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; + float **ma; + + ma=(float **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float*))); + if (!ma) err("util.c: allocation failure 1 in function matrix() "); + ma += SHIFT_IND; + ma -= mrl; + + ma[mrl]=(float *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float))); + if (!ma[mrl]) err("util.c: allocation failure 2 in function matrix() "); + ma[mrl] += SHIFT_IND; + ma[mrl] -= mcl; + + for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; + + for (k=mrl;k<=mrh;k++) + for (l=mcl;l<=mch;l++) ma[k][l]=0.0; + + return ma; } double **dmatrix(int mrl, int mrh, int mcl, int mch){ - - int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; - double **ma; - - ma=(double **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(double*))); - if (!ma) err("util.c: allocation failure 1 in function matrix() "); - ma += SHIFT_IND; - ma -= mrl; - - ma[mrl]=(double *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(double))); - if (!ma[mrl]) err("util.c: allocation failure 2 in function dmatrix() "); - ma[mrl] += SHIFT_IND; - ma[mrl] -= mcl; - - for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; - - for (k=mrl;k<=mrh;k++) - for (l=mcl;l<=mch;l++) ma[k][l]=0.0; - - return ma; + + int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; + double **ma; + + ma=(double **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(double*))); + if (!ma) err("util.c: allocation failure 1 in function matrix() "); + ma += SHIFT_IND; + ma -= mrl; + + ma[mrl]=(double *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(double))); + if (!ma[mrl]) err("util.c: allocation failure 2 in function dmatrix() "); + ma[mrl] += SHIFT_IND; + ma[mrl] -= mcl; + + for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; + + for (k=mrl;k<=mrh;k++) + for (l=mcl;l<=mch;l++) ma[k][l]=0.0; + + return ma; } int **imatrix(int mrl, int mrh, int mcl, int mch){ - - int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; - int **ma; - - ma=(int **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(int*))); - if (!ma) err("util.c: allocation failure 1 in function imatrix() "); - ma += SHIFT_IND; - ma -= mrl; - - ma[mrl]=(int *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(int))); - if (!ma[mrl]) err("util.c: allocation failure 2 in function imatrix() "); - ma[mrl] += SHIFT_IND; - ma[mrl] -= mcl; - - for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; - - for (k=mrl;k<=mrh;k++) - for (l=mcl;l<=mch;l++) ma[k][l]=0; - - return ma; + + int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; + int **ma; + + ma=(int **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(int*))); + if (!ma) err("util.c: allocation failure 1 in function imatrix() "); + ma += SHIFT_IND; + ma -= mrl; + + ma[mrl]=(int *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(int))); + if (!ma[mrl]) err("util.c: allocation failure 2 in function imatrix() "); + ma[mrl] += SHIFT_IND; + ma[mrl] -= mcl; + + for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; + + for (k=mrl;k<=mrh;k++) + for (l=mcl;l<=mch;l++) ma[k][l]=0; + + return ma; } unsigned short int **usmatrix(int mrl, int mrh, int mcl, int mch){ - - int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; - unsigned short int **ma; - - ma=(unsigned short int **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(unsigned short int*))); - if (!ma) err("util.c: allocation failure 1 in function usmatrix() "); - ma += SHIFT_IND; - ma -= mrl; - - ma[mrl]=(unsigned short int *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(unsigned short int))); - if (!ma[mrl]) err("util.c: allocation failure 2 in function usmatrix() "); - ma[mrl] += SHIFT_IND; - ma[mrl] -= mcl; - - for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; - - for (k=mrl;k<=mrh;k++) - for (l=mcl;l<=mch;l++) ma[k][l]=0; - - return ma; + + int k,l, mrow=mrh-mrl+1,mcol=mch-mcl+1; + unsigned short int **ma; + + ma=(unsigned short int **) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(unsigned short int*))); + if (!ma) err("util.c: allocation failure 1 in function usmatrix() "); + ma += SHIFT_IND; + ma -= mrl; + + ma[mrl]=(unsigned short int *) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(unsigned short int))); + if (!ma[mrl]) err("util.c: allocation failure 2 in function usmatrix() "); + ma[mrl] += SHIFT_IND; + ma[mrl] -= mcl; + + for (k=mrl+1;k<=mrh;k++) ma[k]=ma[k-1]+mcol; + + for (k=mrl;k<=mrh;k++) + for (l=mcl;l<=mch;l++) ma[k][l]=0; + + return ma; } float ***f3tensor(int mrl, int mrh, int mcl, int mch,int mdl, int mdh){ - - int w,e,r, mrow=mrh-mrl+1,mcol=mch-mcl+1,mdep=mdh-mdl+1; - float ***te; - - te=(float ***) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float**))); - if (!te) err("util.c: allocation failure 1 in function f3tensor() "); - te += SHIFT_IND; - te -= mrl; - - te[mrl]=(float **) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float*))); - if (!te[mrl]) err("util.c: allocation failure 2 in function f3tensor() "); - te[mrl] += SHIFT_IND; - te[mrl] -= mcl; - - te[mrl][mcl]=(float *) malloc((size_t)((mrow*mcol*mdep+SHIFT_IND)*sizeof(float))); - if (!te[mrl][mcl]) err("util.c: allocation failure 3 in function f3tensor() "); - te[mrl][mcl] += SHIFT_IND; - te[mrl][mcl] -= mdl; - - for (e=mcl+1;e<=mch;e++) te[mrl][e]=te[mrl][e-1]+mdep; - for (w=mrl+1;w<=mrh;w++){ - te[w]=te[w-1]+mcol; - te[w][mcl]=te[w-1][mcl]+mcol*mdep; - for (e=mcl+1;e<=mch;e++) te[w][e]=te[w][e-1]+mdep; - } - - for (w=mrl;w<=mrh;w++) - for (e=mcl;e<=mch;e++) - for (r=mdl;r<=mdh;r++) te[w][e][r]=0.0; - - return te; + + int w,e,r, mrow=mrh-mrl+1,mcol=mch-mcl+1,mdep=mdh-mdl+1; + float ***te; + + te=(float ***) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(float**))); + if (!te) err("util.c: allocation failure 1 in function f3tensor() "); + te += SHIFT_IND; + te -= mrl; + + te[mrl]=(float **) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(float*))); + if (!te[mrl]) err("util.c: allocation failure 2 in function f3tensor() "); + te[mrl] += SHIFT_IND; + te[mrl] -= mcl; + + te[mrl][mcl]=(float *) malloc((size_t)((mrow*mcol*mdep+SHIFT_IND)*sizeof(float))); + if (!te[mrl][mcl]) err("util.c: allocation failure 3 in function f3tensor() "); + te[mrl][mcl] += SHIFT_IND; + te[mrl][mcl] -= mdl; + + for (e=mcl+1;e<=mch;e++) te[mrl][e]=te[mrl][e-1]+mdep; + for (w=mrl+1;w<=mrh;w++){ + te[w]=te[w-1]+mcol; + te[w][mcl]=te[w-1][mcl]+mcol*mdep; + for (e=mcl+1;e<=mch;e++) te[w][e]=te[w][e-1]+mdep; + } + + for (w=mrl;w<=mrh;w++) + for (e=mcl;e<=mch;e++) + for (r=mdl;r<=mdh;r++) te[w][e][r]=0.0; + + return te; } int ***i3tensor(int mrl, int mrh, int mcl, int mch,int mdl, int mdh){ - - int w,e,r, mrow=mrh-mrl+1,mcol=mch-mcl+1,mdep=mdh-mdl+1; - int ***te; - - te=(int ***) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(int**))); - if (!te) err("util.c: allocation failure 1 in function i3tensor() "); - te += SHIFT_IND; - te -= mrl; - - te[mrl]=(int **) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(int*))); - if (!te[mrl]) err("util.c: allocation failure 2 in function i3tensor() "); - te[mrl] += SHIFT_IND; - te[mrl] -= mcl; - - te[mrl][mcl]=(int *) malloc((size_t)((mrow*mcol*mdep+SHIFT_IND)*sizeof(int))); - if (!te[mrl][mcl]) err("util.c: allocation failure 3 in function i3tensor() "); - te[mrl][mcl] += SHIFT_IND; - te[mrl][mcl] -= mdl; - - for (e=mcl+1;e<=mch;e++) te[mrl][e]=te[mrl][e-1]+mdep; - for (w=mrl+1;w<=mrh;w++){ - te[w]=te[w-1]+mcol; - te[w][mcl]=te[w-1][mcl]+mcol*mdep; - for (e=mcl+1;e<=mch;e++) te[w][e]=te[w][e-1]+mdep; - } - - for (w=mrl;w<=mrh;w++) - for (e=mcl;e<=mch;e++) - for (r=mdl;r<=mdh;r++) te[w][e][r]=0.0; - - - return te; + + int w,e,r, mrow=mrh-mrl+1,mcol=mch-mcl+1,mdep=mdh-mdl+1; + int ***te; + + te=(int ***) malloc((size_t) ((mrow+SHIFT_IND)*sizeof(int**))); + if (!te) err("util.c: allocation failure 1 in function i3tensor() "); + te += SHIFT_IND; + te -= mrl; + + te[mrl]=(int **) malloc((size_t)((mrow*mcol+SHIFT_IND)*sizeof(int*))); + if (!te[mrl]) err("util.c: allocation failure 2 in function i3tensor() "); + te[mrl] += SHIFT_IND; + te[mrl] -= mcl; + + te[mrl][mcl]=(int *) malloc((size_t)((mrow*mcol*mdep+SHIFT_IND)*sizeof(int))); + if (!te[mrl][mcl]) err("util.c: allocation failure 3 in function i3tensor() "); + te[mrl][mcl] += SHIFT_IND; + te[mrl][mcl] -= mdl; + + for (e=mcl+1;e<=mch;e++) te[mrl][e]=te[mrl][e-1]+mdep; + for (w=mrl+1;w<=mrh;w++){ + te[w]=te[w-1]+mcol; + te[w][mcl]=te[w-1][mcl]+mcol*mdep; + for (e=mcl+1;e<=mch;e++) te[w][e]=te[w][e-1]+mdep; + } + + for (w=mrl;w<=mrh;w++) + for (e=mcl;e<=mch;e++) + for (r=mdl;r<=mdh;r++) te[w][e][r]=0.0; + + + return te; } void free_vector(float *a, int ni, int nj){ - free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); + free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); } void free_ivector(int *a, int ni, int nj){ - free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); + free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); } void free_cvector(char *a, int ni, int nj){ - free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); + free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); } void free_dvector(double *a, int ni, int nj){ - free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); - } - + free((FREE_ARGUMENT) (a+ni-SHIFT_IND)); +} + void free_matrix(float **ma, int mrl, int mrh, int mcl, int mch){ - free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); - free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); } void free_imatrix(int **ma, int mrl, int mrh, int mcl, int mch){ - free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); - free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); } void free_usmatrix(unsigned short int **ma, int mrl, int mrh, int mcl, int mch){ - free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); - free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma[mrl]+mcl-SHIFT_IND)); + free((FREE_ARGUMENT) (ma+mrl-SHIFT_IND)); } void free_f3tensor(float ***te, int mrl, int mrh, int mcl, int mch, int mdl, int mdh){ - free((FREE_ARGUMENT) (te[mrl][mcl]+mdl-SHIFT_IND)); - free((FREE_ARGUMENT) (te[mrl]+mcl-SHIFT_IND)); - free((FREE_ARGUMENT) (te+mrl-SHIFT_IND)); + free((FREE_ARGUMENT) (te[mrl][mcl]+mdl-SHIFT_IND)); + free((FREE_ARGUMENT) (te[mrl]+mcl-SHIFT_IND)); + free((FREE_ARGUMENT) (te+mrl-SHIFT_IND)); } void free_i3tensor(int ***te, int mrl, int mrh, int mcl, int mch, int mdl, int mdh){ - free((FREE_ARGUMENT) (te[mrl][mcl]+mdl-SHIFT_IND)); - free((FREE_ARGUMENT) (te[mrl]+mcl-SHIFT_IND)); - free((FREE_ARGUMENT) (te+mrl-SHIFT_IND)); + free((FREE_ARGUMENT) (te[mrl][mcl]+mdl-SHIFT_IND)); + free((FREE_ARGUMENT) (te[mrl]+mcl-SHIFT_IND)); + free((FREE_ARGUMENT) (te+mrl-SHIFT_IND)); } void zero(float *A, int u_max){ - int u=0; - while(++u<=u_max) *(A++)=0.0; + int u=0; + while(++u<=u_max) *(A++)=0.0; } void normalize_data(float **data, int ntr, int ns){ - - float *max_min_trace=NULL, *max_min_data_trace=NULL; - float max, min, tmp; - int i,j; - - - max_min_trace = vector(1,ntr); - for(i=1;i<=ntr;i++){ - + + float *max_min_trace=NULL; + float max, min, tmp=0.0; + int i,j; + + + max_min_trace = vector(1,ntr); + for(i=1;i<=ntr;i++){ + max=0.0; min=0.0; - - for(j=2;j<=ns;j++){ - /* Looking for max and min */ - if(data[i][j]>max){max = data[i][j];} - if(data[i][j](fabs(min))){tmp=max;} - else{tmp=fabs(min);} - } - - max_min_trace[i]=tmp; - - /* set maximum_values=0.0 to 1.0 */ - if(max_min_trace[i]==0.0){max_min_trace[i]=1.0;} - - - for(j=2;j<=ns;j++){ - data[i][j] = data[i][j]/max_min_trace[i]; - } - - } + + for(j=2;j<=ns;j++){ + /* Looking for max and min */ + if(data[i][j]>max){max = data[i][j];} + if(data[i][j](fabs(min))){tmp=max;} + else{tmp=fabs(min);} + } + + max_min_trace[i]=tmp; + + /* set maximum_values=0.0 to 1.0 */ + if(max_min_trace[i]==0.0){max_min_trace[i]=1.0;} + + + for(j=2;j<=ns;j++){ + data[i][j] = data[i][j]/max_min_trace[i]; + } + + } } /* quickSort -* This public-domain C implementation by Darel Rex Finley . -* http://alienryderflex.com/quicksort */ + * This public-domain C implementation by Darel Rex Finley . + * http://alienryderflex.com/quicksort */ void quicksort(float *arr, int dummy, int elements) { - - /* number of levels: 64 is enough for 1.8e19 elements to be sorted */ - #define MAX_LEVELS 64 - - int beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, swap ; - float piv; - - beg[0]=0; - end[0]=elements; - - while (i>=0) { - L=beg[i]; R=end[i]-1; - if (L=piv && Lend[i-1]-beg[i-1]) { - swap=beg[i]; beg[i]=beg[i-1]; beg[i-1]=swap; - swap=end[i]; end[i]=end[i-1]; end[i-1]=swap; - } - } - else i--; - } + + /* number of levels: 64 is enough for 1.8e19 elements to be sorted */ +#define MAX_LEVELS 64 + + int beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, swap ; + float piv; + + beg[0]=0; + end[0]=elements; + + while (i>=0) { + L=beg[i]; R=end[i]-1; + if (L=piv && Lend[i-1]-beg[i-1]) { + swap=beg[i]; beg[i]=beg[i-1]; beg[i-1]=swap; + swap=end[i]; end[i]=end[i-1]; end[i-1]=swap; + } + } + else i--; + } }