read_par_json.c 29.6 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/*-----------------------------------------------------------------------------------------
 * 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 <http://www.gnu.org/licenses/gpl-2.0.html>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   program IFOS, reading input-parameters from input-file or stdin
 *  ----------------------------------------------------------------------*/

#include <unistd.h>
#include "fd.h"

char **varname_list,* *value_list;

void read_par_json(FILE *fp, char *fileinp) {

	/* declaration of extern variables */
	extern int   NX, NY, NZ, SOURCE_SHAPE, SOURCE_TYPE, SNAP, SNAP_FORMAT, SNAP_PLANE;
	extern int DRX, DRY, L, SRCREC, FDORDER, FW, FDCOEFF;
	extern float DX, DY, DZ, TIME, DT, TS, *FL, TAU, PLANE_WAVE_DEPTH, PHI;
	extern float XREC1, XREC2, YREC1, YREC2, ZREC1, ZREC2, ALPHA, BETA;
	extern float REC_ARRAY_DEPTH, REC_ARRAY_DIST;
	extern int SEISMO, NDT, NDTSHIFT, NGEOPH, SEIS_FORMAT[6], FREE_SURF, READMOD, MOD_FORMAT, READREC, RUN_MULTIPLE_SHOTS;
	extern int BOUNDARY, REC_ARRAY, IDX, IDY, IDZ, ABS_TYPE;
	extern float TSNAP1, TSNAP2, TSNAPINC, REFREC[4], DAMPING, FPML, VPPML;
	extern char  MFILE[STRING_SIZE], SIGNAL_FILE[STRING_SIZE];
	extern char SNAP_FILE[STRING_SIZE], SOURCE_FILE[STRING_SIZE], REC_FILE[STRING_SIZE];
	extern char SEIS_FILE[STRING_SIZE],GRAD_FILE[STRING_SIZE], SEIS_OBS_FILE[STRING_SIZE],INV_FILE[STRING_SIZE];
	extern int NPROCX,NPROCY,NPROCZ;
	extern int ASCIIEBCDIC,LITTLEBIG,IEEEIBM;

	extern float REFSRC[3], SRCTSHIFT;
	extern int SRC_MF, SIGNAL_FORMAT;
	extern char MOD_OUT_FILE[STRING_SIZE], HESS_FILE[STRING_SIZE];
	extern int METHOD;
	extern int ITMIN, ITMAX, FILT, NFMAX, TAST, NSHOTS_STEP, DAMPTYPE, HESS, READ_HESS, REC_HESS,EXTOBS,LBFGS;
	/*extern float F_INV;*/
	extern float TESTSTEP, WATER_HESS[3], WEIGHT[3], VP0, VS0, RHO0;
	extern int BFGSNUM, NUMPAR;
	extern int MYID;
	extern int VERBOSE;
	/* definition of local variables */

	int number_readobjects=0,fserr=0;
	char errormessage[STRING_SIZE2];

	char **varname_list, ** value_list;

	if (MYID == 0) {

		/* allocate first object in list */
		varname_list = malloc(STRING_SIZE2*sizeof(char *));
		value_list = malloc(STRING_SIZE2*sizeof(char *));

		/* read in objects from file */
		number_readobjects=read_objects_from_intputfile(fp, fileinp, varname_list, value_list);
70
		fprintf(fp,"\n From input file %s, %i objects have been read in. \n",fileinp, number_readobjects);
Tilman Steinweg's avatar
Tilman Steinweg committed
71 72

		/* print objects to screen */
73 74
		fprintf(fp, "\n ===========================================================");
		fprintf(fp, "\n =   List of Parameters read by the built in Json Parser   =");
Tilman Steinweg's avatar
Tilman Steinweg committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
		print_objectlist_screen(fp, number_readobjects, varname_list, value_list);

		/* extract variables form object list */

		/*=================================
		 section general grid and discretization parameters
		 =================================*/
		if (get_int_from_objectlist("NPROCX",number_readobjects,&NPROCX,varname_list, value_list)) {
			err("Variable NPROCX could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("NPROCZ",number_readobjects,&NPROCY,varname_list, value_list)) {
			err("Variable NPROCY could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("NPROCY",number_readobjects,&NPROCZ,varname_list, value_list)) {
			err("Variable NPROCZ could not be retrieved from the json input file!");
		}


		if (get_int_from_objectlist("NX",number_readobjects,&NX,varname_list, value_list)) {
			err("Variable NX could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("NZ",number_readobjects,&NY,varname_list, value_list)) {
			err("Variable NY could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("NY",number_readobjects,&NZ,varname_list, value_list)) {
			err("Variable NZ could not be retrieved from the json input file!");
		}

		if (get_float_from_objectlist("DX",number_readobjects,&DX,varname_list, value_list)) {
			err("Variable DX could not be retrieved from the json input file!");
		}

		if (get_float_from_objectlist("DZ",number_readobjects,&DY,varname_list, value_list)) {
			err("Variable DY could not be retrieved from the json input file!");
		}

		if (get_float_from_objectlist("DY",number_readobjects,&DZ,varname_list, value_list)) {
			err("Variable DZ could not be retrieved from the json input file!");
		}


		if (get_int_from_objectlist("FDORDER",number_readobjects,&FDORDER,varname_list, value_list)) {
			err("Variable FDORDER could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("FDCOEFF",number_readobjects,&FDCOEFF,varname_list, value_list)) {
			err("Variable FDCOEFF could not be retrieved from the json input file!");
		}


		if (get_float_from_objectlist("TIME",number_readobjects,&TIME,varname_list, value_list)) {
			err("Variable TIME could not be retrieved from the json input file!");
		}

		if (get_float_from_objectlist("DT",number_readobjects,&DT,varname_list, value_list)) {
			err("Variable DT could not be retrieved from the json input file!");
		}

		/*=================================
		 section source parameters
		 =================================*/
140 141
		fprintf(fp," The following default values are set:\n");
		fprintf(fp," =====================================\n\n");
Tilman Steinweg's avatar
Tilman Steinweg committed
142 143 144


		if (get_int_from_objectlist("SOURCE_SHAPE",number_readobjects,&SOURCE_SHAPE,varname_list, value_list)) {
145
			err(" Variable SOURCE_SHAPE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
146 147 148 149 150
		}

		else {
			if (SOURCE_SHAPE==3) {
				if (get_string_from_objectlist("SIGNAL_FILE",number_readobjects,SIGNAL_FILE,varname_list, value_list)) {
151
					err(" Variable SIGNAL_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
152 153 154

				} else {
					if (get_int_from_objectlist("SIGNAL_FORMAT",number_readobjects,&SIGNAL_FORMAT,varname_list, value_list)) {
155
						SIGNAL_FORMAT=1;
Tilman Steinweg's avatar
Tilman Steinweg committed
156 157 158 159 160 161
					}
				}
			}
		}

		if (get_int_from_objectlist("SOURCE_TYPE",number_readobjects,&SOURCE_TYPE,varname_list, value_list)) {
162
			err(" Variable SOURCE_TYPE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
163 164 165 166 167
		}

		else {
			if (SOURCE_TYPE==5) {
				if (get_float_from_objectlist("ALPHA",number_readobjects,&ALPHA,varname_list, value_list)) {
168
					err(" Variable ALPHA could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
169 170 171
				}

				if (get_float_from_objectlist("BETA",number_readobjects,&BETA,varname_list, value_list)) {
172
					err(" Variable BETA could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
173 174 175 176 177 178
				}
			}

		}

		if (get_int_from_objectlist("SRCREC",number_readobjects,&SRCREC,varname_list, value_list)) {
179
			err(" Variable SRCREC could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
180 181 182 183 184 185

		} else {
			if (get_int_from_objectlist("SRC_MF",number_readobjects,&SRC_MF,varname_list, value_list)) {
				SRC_MF=0;
			}

186
			if (get_float_from_objectlist("REFSRCX",number_readobjects,&REFSRC[0],varname_list, value_list)) {
Tilman Steinweg's avatar
Tilman Steinweg committed
187
				REFSRC[0]=0.0;
188
				fprintf(fp," Variable REFSRCX is set to default value %.1f.\n",REFSRC[0]);
Tilman Steinweg's avatar
Tilman Steinweg committed
189 190
			}

191
			if (get_float_from_objectlist("REFSRCZ",number_readobjects,&REFSRC[1],varname_list, value_list)) {
Tilman Steinweg's avatar
Tilman Steinweg committed
192
				REFSRC[1]=0.0;
193
				fprintf(fp," Variable REFSRCZ is set to default value %.1f.\n",REFSRC[1]);
Tilman Steinweg's avatar
Tilman Steinweg committed
194 195
			}

196
			if (get_float_from_objectlist("REFSRCY",number_readobjects,&REFSRC[2],varname_list, value_list)) {
Tilman Steinweg's avatar
Tilman Steinweg committed
197
				REFSRC[2]=0.0;
198
				fprintf(fp," Variable REFSRCY is set to default value %.1f.\n",REFSRC[2]);
Tilman Steinweg's avatar
Tilman Steinweg committed
199 200 201 202 203
			}


			if (SRCREC==1) {
				if (get_string_from_objectlist("SOURCE_FILE",number_readobjects,SOURCE_FILE,varname_list, value_list)) {
204
					err(" Variable SOURCE_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
205 206 207
				}

				if (get_int_from_objectlist("RUN_MULTIPLE_SHOTS",number_readobjects,&RUN_MULTIPLE_SHOTS,varname_list, value_list)) {
208
					err(" Variable RUN_MULTIPLE_SHOTS could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
209 210 211 212 213 214 215 216 217 218 219 220

				} else {
					if (get_float_from_objectlist("SRCTSHIFT",number_readobjects,&SRCTSHIFT,varname_list, value_list)) {
						SRCTSHIFT=0.0;
					}

				}
			}


			if (SRCREC==2) {
				if (get_float_from_objectlist("PLANE_WAVE_DEPTH",number_readobjects,&PLANE_WAVE_DEPTH,varname_list, value_list)) {
221
					err(" Variable PLANE_WAVE_DEPTH could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

				} else {
					if (PLANE_WAVE_DEPTH>0) {
						if (get_float_from_objectlist("PHI",number_readobjects,&PHI,varname_list, value_list)) {
							err("Variable PHI could not be retrieved from the json input file!");
						}

						if (get_float_from_objectlist("TS",number_readobjects,&TS,varname_list, value_list)) {
							err("Variable TS could not be retrieved from the json input file!");

						}
					}
				}
			}
		} /* end of SRCREC */



		/*=================================
		 section general model and log parameters
		 =================================*/
		if (get_int_from_objectlist("VERBOSE",number_readobjects,&VERBOSE,varname_list, value_list)) {
244
			VERBOSE=1;
Tilman Steinweg's avatar
Tilman Steinweg committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
			fprintf(fp,"Variable VERBOSE is set to value %d.\n",VERBOSE);
		}

		if (get_int_from_objectlist("READMOD",number_readobjects,&READMOD,varname_list, value_list)) {
			err("Variable READMOD could not be retrieved from the json input file!");

		} else {
			if (get_int_from_objectlist("MOD_FORMAT",number_readobjects,&MOD_FORMAT,varname_list, value_list)) {
				MOD_FORMAT=0;
			}

			if (get_string_from_objectlist("MFILE",number_readobjects,MFILE,varname_list, value_list)) {
				err("Variable MFILE could not be retrieved from the json input file!");
			}
		}


		if (get_int_from_objectlist("L",number_readobjects,&L,varname_list, value_list)) {
			L=0;
264
			fprintf(fp," Variable L is set to default value %d.\n",L);
Tilman Steinweg's avatar
Tilman Steinweg committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284

		} else {
			FL=vector(1,L);

			switch (L) {
				case 0:
					break;

				case 1:
					if (get_float_from_objectlist("FL1",number_readobjects,&FL[1],varname_list, value_list)) {
						err("Variable FL1 could not be retrieved from the json input file!");
					}

					break;

				default:
					err("More than four relaxation Parameter (L>1) are not implemented yet!");
					break;
			}

285 286 287 288
			if (L) {
				if (get_float_from_objectlist("TAU",number_readobjects,&TAU,varname_list, value_list)) {
					err("Variable TAU could not be retrieved from the json input file!");
				}
Tilman Steinweg's avatar
Tilman Steinweg committed
289 290 291 292 293 294 295 296 297 298 299 300
			}
		}

		/*=================================
			  section boundary parameters
		  =================================*/

		if (get_int_from_objectlist("FREE_SURF",number_readobjects,&FREE_SURF,varname_list, value_list)) {
			err("Variable FREE_SURF could not be retrieved from the json input file!");
		}

		if (get_int_from_objectlist("BOUNDARY",number_readobjects,&BOUNDARY,varname_list, value_list)) {
301
			BOUNDARY=0;
302
			fprintf(fp," Variable BOUNDARY is set to default value %d.\n",BOUNDARY);
Tilman Steinweg's avatar
Tilman Steinweg committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
		}

		if (get_int_from_objectlist("ABS_TYPE",number_readobjects,&ABS_TYPE,varname_list, value_list)) {
			err("Variable ABS_TYPE could not be retrieved from the json input file!");
		}

		if (ABS_TYPE==1) {
			if (get_float_from_objectlist("FPML",number_readobjects,&FPML,varname_list, value_list)) {
				err("Variable FPML could not be retrieved from the json input file!");
			}

			if (get_float_from_objectlist("VPPML",number_readobjects,&VPPML,varname_list, value_list)) {
				err("Variable VPPML could not be retrieved from the json input file!");
			}
		}

		if (get_int_from_objectlist("FW",number_readobjects,&FW,varname_list, value_list)) {
			err("Variable FW could not be retrieved from the json input file!");
		}

		if (ABS_TYPE==2) {
			if (get_float_from_objectlist("DAMPING",number_readobjects,&DAMPING,varname_list, value_list)) {
				err("Variable DAMPING could not be retrieved from the json input file!");
			}
		}


		/*=================================
		section snapshot parameters
		=================================*/
		if (get_int_from_objectlist("SNAP",number_readobjects,&SNAP,varname_list, value_list)) {
334
			err("Variable SNAP not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

		} else {
			if (SNAP>0) {
				if (get_int_from_objectlist("SNAP_FORMAT",number_readobjects,&SNAP_FORMAT,varname_list, value_list)) {
					err("Variable SNAP_FORMAT could not be retrieved from the json input file!");
				}

				if (get_float_from_objectlist("TSNAP1",number_readobjects,&TSNAP1,varname_list, value_list)) {
					err("Variable TSNAP1 could not be retrieved from the json input file!");
				}

				if (get_float_from_objectlist("TSNAP2",number_readobjects,&TSNAP2,varname_list, value_list)) {
					err("Variable TSNAP2 could not be retrieved from the json input file!");
				}

				if (get_float_from_objectlist("TSNAPINC",number_readobjects,&TSNAPINC,varname_list, value_list)) {
					err("Variable TSNAPINC could not be retrieved from the json input file!");
				}

				if (get_string_from_objectlist("SNAP_FILE",number_readobjects,SNAP_FILE,varname_list, value_list)) {
					err("Variable SNAP_FILE could not be retrieved from the json input file!");
				}

			}
		}

		if (SNAP==3) {
			if (get_int_from_objectlist("SNAP_PLANE",number_readobjects,&SNAP_PLANE,varname_list, value_list)) {
				err("Variable SNAP_PLANE could not be retrieved from the json input file!");
			}
		}

		/* increments are read in any case, because they will be also used as increment for model output */
		if (get_int_from_objectlist("IDX",number_readobjects,&IDX,varname_list, value_list)) {
			IDX=1;
370
			fprintf(fp," Variable IDX is set to default value %d.\n",IDX);
Tilman Steinweg's avatar
Tilman Steinweg committed
371 372 373 374
		}

		if (get_int_from_objectlist("IDZ",number_readobjects,&IDY,varname_list, value_list)) {
			IDY=1;
375
			fprintf(fp," Variable IDZ is set to default value %d.\n",IDY);
Tilman Steinweg's avatar
Tilman Steinweg committed
376 377 378
		}

		if (get_int_from_objectlist("IDY",number_readobjects,&IDZ,varname_list, value_list)) {
379
			IDZ=1;
380
			fprintf(fp," Variable IDY is set to default value %d.\n",IDZ);
Tilman Steinweg's avatar
Tilman Steinweg committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
		}

		/*=================================
		 section seismogramm parameters
		 =================================*/
		if (get_int_from_objectlist("SEISMO",number_readobjects,&SEISMO,varname_list, value_list)) {
			err("Variable SEISMO could not be retrieved from the json input file!");
		}

		else {
			if (SEISMO>0) {
				if (get_string_from_objectlist("SEIS_FILE",number_readobjects,SEIS_FILE,varname_list, value_list)) {
					err("Variable SEIS_FILE could not be retrieved from the json input file!");
				}

				if (get_int_from_objectlist("READREC",number_readobjects,&READREC,varname_list, value_list)) {
					err("Variable READREC could not be retrieved from the json input file!");
				}

				else {
401 402 403 404 405
					switch (READREC) {
						case 0 : /*Receiver line*/
							if (get_float_from_objectlist("XREC1",number_readobjects,&XREC1,varname_list, value_list)) {
								err("Variable XREC1 could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
406

407 408 409
							if (get_float_from_objectlist("XREC2",number_readobjects,&XREC2,varname_list, value_list)) {
								err("Variable XREC2T could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
410

411 412 413
							if (get_float_from_objectlist("YREC1",number_readobjects,&ZREC1,varname_list, value_list)) {
								err("Variable YREC1 could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
414

415 416 417
							if (get_float_from_objectlist("YREC2",number_readobjects,&ZREC2,varname_list, value_list)) {
								err("Variable YREC2 could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
418

419 420 421
							if (get_float_from_objectlist("ZREC1",number_readobjects,&YREC1,varname_list, value_list)) {
								err("Variable ZREC1 could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
422

423 424 425
							if (get_float_from_objectlist("ZREC2",number_readobjects,&YREC2,varname_list, value_list)) {
								err("Variable ZREC2 could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
426 427


428 429 430
							if (get_int_from_objectlist("NGEOPH",number_readobjects,&NGEOPH,varname_list, value_list)) {
								err("Variable NGEOPH could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
431

432
							break;
Tilman Steinweg's avatar
Tilman Steinweg committed
433

434 435 436 437
						case 1 : /*Receiver from file*/
							if (get_string_from_objectlist("REC_FILE",number_readobjects,REC_FILE,varname_list, value_list)) {
								err("Variable REC_FILE could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
438

439 440 441
							if (get_float_from_objectlist("REFRECX",number_readobjects,&REFREC[1],varname_list, value_list)) {
								err("Variable REFRECX could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
442

443 444 445
							if (get_float_from_objectlist("REFRECZ",number_readobjects,&REFREC[2],varname_list, value_list)) {
								err("Variable REFRECZ could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
446

447 448 449
							if (get_float_from_objectlist("REFRECY",number_readobjects,&REFREC[3],varname_list, value_list)) {
								err("Variable REFRECY could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
450

451
							break;
Tilman Steinweg's avatar
Tilman Steinweg committed
452

453 454 455 456
						case 2: /*Receiver array*/
							if (get_int_from_objectlist("REC_ARRAY",number_readobjects,&REC_ARRAY,varname_list, value_list)) {
								err("Variable REC_ARRAY could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
457

458 459 460
							if (get_float_from_objectlist("REC_ARRAY_DEPTH",number_readobjects,&REC_ARRAY_DEPTH,varname_list, value_list)) {
								err("Variable REC_ARRAY_DEPTH could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
461

462 463 464
							if (get_float_from_objectlist("REC_ARRAY_DIST",number_readobjects,&REC_ARRAY_DIST,varname_list, value_list)) {
								err("Variable REC_ARRAY_DIST could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
465

466 467 468
							if (get_int_from_objectlist("DRX",number_readobjects,&DRX,varname_list, value_list)) {
								err("Variable DRX could not be retrieved from the json input file!");
							}
Tilman Steinweg's avatar
Tilman Steinweg committed
469

470 471 472 473 474 475 476 477
							if (get_int_from_objectlist("DRY",number_readobjects,&DRY,varname_list, value_list)) {
								err("Variable DRZ could not be retrieved from the json input file!");
							}

							break;

						default :
							err("Please choose READREC=0 (Receiver Line) ,READREC=1 (Receiver from file) or READREC=2(Receiver Array)");
Tilman Steinweg's avatar
Tilman Steinweg committed
478 479 480 481 482


					}
				}

483 484 485 486
				if (READREC!=1) {
					REFREC[0]=0.0;
					REFREC[1]=0.0;
					REFREC[2]=0.0;
487
					fprintf(fp," Variable REFREC is set to default value (%.1f,%.1f,%.1f).\n",REFREC[0],REFREC[1],REFREC[2]);
488 489 490
				}
			}

Tilman Steinweg's avatar
Tilman Steinweg committed
491

492 493
			/* --------output ----------
			 *------------------------*/
Tilman Steinweg's avatar
Tilman Steinweg committed
494

495 496
			if (get_int_from_objectlist("NDT",number_readobjects,&NDT,varname_list, value_list)) {
				NDT=1;
497
				fprintf(fp," Variable NDT is set to default value %d.\n",NDT);
Tilman Steinweg's avatar
Tilman Steinweg committed
498
			}
499 500 501

			if (get_int_from_objectlist("NDTSHIFT",number_readobjects,&NDTSHIFT,varname_list, value_list)) {
				NDTSHIFT=0;
502
				fprintf(fp," Variable NDTSHIFT is set to default value %d.\n",NDT);
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
			}

			if (get_int_from_objectlist("SEIS_FORMAT",number_readobjects,&SEIS_FORMAT[0],varname_list, value_list)) {
				err("Variable SEIS_FORMAT could not be retrieved from the json input file!");

			} else {
				if (SEIS_FORMAT[0]==4) {
					SEIS_FORMAT[0]=0;
				}

				if (SEIS_FORMAT[0]==5) {
					SEIS_FORMAT[0]=0;
					SEIS_FORMAT[1]=1;
					SEIS_FORMAT[3]=1;
					SEIS_FORMAT[4]=0;
					SEIS_FORMAT[5]=0;
				}
			}
		}/*end of seismo*/
Tilman Steinweg's avatar
Tilman Steinweg committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

		if (get_int_from_objectlist("ASCIIEBCDIC",number_readobjects,&ASCIIEBCDIC,varname_list, value_list)) {
			ASCIIEBCDIC=0;
		}

		if (get_int_from_objectlist("LITTLEBIG",number_readobjects,&LITTLEBIG,varname_list, value_list)) {
			LITTLEBIG=0;
		}

		if (get_int_from_objectlist("IEEEIBM",number_readobjects,&IEEEIBM,varname_list, value_list)) {
			IEEEIBM=0;
		}

		/*=================================
		 section inversion parameters
		 =================================*/


		if (get_int_from_objectlist("METHOD",number_readobjects,&METHOD,varname_list, value_list)) {
			err("Variable METHOD could not be retrieved from the json input file!");
		}

		else {
			if (METHOD==1) {	/* FWI is calculated */


				/*=================================
				section General
				=================================*/

				if (get_int_from_objectlist("ITMIN",number_readobjects,&ITMIN,varname_list, value_list)) {
					err("Variable ITMIN could not be retrieved from the json input file!");
				}

				if (get_int_from_objectlist("ITMAX",number_readobjects,&ITMAX,varname_list, value_list)) {
					err("Variable ITMAX could not be retrieved from the json input file!");
				}

				if (get_int_from_objectlist("FILT",number_readobjects,&FILT,varname_list, value_list)) {
					err("Variable FILT could not be retrieved from the json input file!");
				}


				if (get_int_from_objectlist("NFMAX",number_readobjects,&NFMAX,varname_list, value_list)) {
					err("Variable NFMAX could not be retrieved from the json input file!");
				}

				if (get_int_from_objectlist("TAST",number_readobjects,&TAST,varname_list, value_list)) {
					err("Variable TAST could not be retrieved from the json input file!");
				}
572

Tilman Steinweg's avatar
Tilman Steinweg committed
573 574 575
				if (get_float_from_objectlist("VP0",number_readobjects,&VP0,varname_list, value_list)) {
					err("Variable VP0 could not be retrieved from the json input file!");
				}
576

Tilman Steinweg's avatar
Tilman Steinweg committed
577 578 579
				if (get_float_from_objectlist("VS0",number_readobjects,&VS0,varname_list, value_list)) {
					err("Variable VS0 could not be retrieved from the json input file!");
				}
580

Tilman Steinweg's avatar
Tilman Steinweg committed
581 582 583
				if (get_float_from_objectlist("RHO0",number_readobjects,&RHO0,varname_list, value_list)) {
					err("Variable RHO0 could not be retrieved from the json input file!");
				}
584

Tilman Steinweg's avatar
Tilman Steinweg committed
585 586 587
				if (get_float_from_objectlist("RHO0",number_readobjects,&RHO0,varname_list, value_list)) {
					err("Variable RHO0 could not be retrieved from the json input file!");
				}
588

Tilman Steinweg's avatar
Tilman Steinweg committed
589 590 591
				if (get_float_from_objectlist("WEIGHT_VP",number_readobjects,&WEIGHT[0],varname_list, value_list)) {
					err("Variable WEIGHT_VP could not be retrieved from the json input file!");
				}
592

Tilman Steinweg's avatar
Tilman Steinweg committed
593 594 595
				if (get_float_from_objectlist("WEIGHT_VS",number_readobjects,&WEIGHT[1],varname_list, value_list)) {
					err("Variable WEIGHT_VS could not be retrieved from the json input file!");
				}
596

Tilman Steinweg's avatar
Tilman Steinweg committed
597 598 599
				if (get_float_from_objectlist("WEIGHT_RHO",number_readobjects,&WEIGHT[2],varname_list, value_list)) {
					err("Variable WEIGHT_RHO could not be retrieved from the json input file!");
				}
600 601 602



Tilman Steinweg's avatar
Tilman Steinweg committed
603 604 605
				/*=================================
				section Steplength estimation + Gradient preconditioning
				=================================*/
606

Tilman Steinweg's avatar
Tilman Steinweg committed
607 608 609
				if (get_int_from_objectlist("NSHOTS_STEP",number_readobjects,&NSHOTS_STEP,varname_list, value_list)) {
					err("Variable NSHOTS_STEP could not be retrieved from the json input file!");
				}
610

Tilman Steinweg's avatar
Tilman Steinweg committed
611 612 613
				if (get_float_from_objectlist("TESTSTEP",number_readobjects,&TESTSTEP,varname_list, value_list)) {
					err("Variable TESTSTEP could not be retrieved from the json input file!");
				}
614

Tilman Steinweg's avatar
Tilman Steinweg committed
615 616 617 618 619 620 621
				if (get_int_from_objectlist("DAMPTYPE",number_readobjects,&DAMPTYPE,varname_list, value_list)) {
					err("Variable DAMPTYPE could not be retrieved from the json input file!");
				}

				/*=================================
				section Hessian + L-BFGS
				=================================*/
622

Tilman Steinweg's avatar
Tilman Steinweg committed
623 624
				if (get_int_from_objectlist("HESS",number_readobjects,&HESS,varname_list, value_list)) {
					err("Variable HESS could not be retrieved from the json input file!");
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647

				} else {
					if (HESS) {
						if (get_int_from_objectlist("READ_HESS",number_readobjects,&READ_HESS,varname_list, value_list)) {
							err("Variable READ_HESS could not be retrieved from the json input file!");
						}

						if (get_int_from_objectlist("REC_HESS",number_readobjects,&REC_HESS,varname_list, value_list)) {
							err("Variable REC_HESS could not be retrieved from the json input file!");
						}

						if (get_float_from_objectlist("WATER_HESS_VP",number_readobjects,&WATER_HESS[0],varname_list, value_list)) {
							err("Variable WATER_HESS_VP could not be retrieved from the json input file!");
						}

						if (get_float_from_objectlist("WATER_HESS_VS",number_readobjects,&WATER_HESS[1],varname_list, value_list)) {
							err("Variable WATER_HESS_VS could not be retrieved from the json input file!");
						}

						if (get_float_from_objectlist("WATER_HESS_RHO",number_readobjects,&WATER_HESS[2],varname_list, value_list)) {
							err("Variable WATER_HESS_RHO could not be retrieved from the json input file!");
						}
					}
Tilman Steinweg's avatar
Tilman Steinweg committed
648
				}
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663

				if (get_int_from_objectlist("LBFGS",number_readobjects,&LBFGS,varname_list, value_list)) {
					err("Variable LBFGS could not be retrieved from the json input file!");

				} else {
					if (LBFGS) {

						if (get_int_from_objectlist("NUMPAR",number_readobjects,&NUMPAR,varname_list, value_list)) {
							err("Variable NUMPAR could not be retrieved from the json input file!");
						}

						if (get_int_from_objectlist("BFGSNUM",number_readobjects,&BFGSNUM,varname_list, value_list)) {
							err("Variable BFGSNUM could not be retrieved from the json input file!");
						}
					}
Tilman Steinweg's avatar
Tilman Steinweg committed
664
				}
665 666 667 668 669 670 671

				/*=================================
				section In- and Output Files
				=================================*/

				if (get_string_from_objectlist("GRAD_FILE",number_readobjects,GRAD_FILE,varname_list, value_list)) {
					err("Variable GRAD_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
672
				}
673 674 675

				if (get_string_from_objectlist("MOD_OUT_FILE",number_readobjects,MOD_OUT_FILE,varname_list, value_list)) {
					err("Variable MOD_OUT_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
676
				}
677 678 679

				if (get_string_from_objectlist("SEIS_OBS_FILE",number_readobjects,SEIS_OBS_FILE,varname_list, value_list)) {
					err("Variable SEIS_OBS_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
680
				}
681 682 683

				if (get_int_from_objectlist("EXTOBS",number_readobjects,&EXTOBS,varname_list, value_list)) {
					err("Variable EXTOBS could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
684
				}
685 686 687

				if (get_string_from_objectlist("INV_FILE",number_readobjects,INV_FILE,varname_list, value_list)) {
					err("Variable INV_FILE could not be retrieved from the json input file!");
Tilman Steinweg's avatar
Tilman Steinweg committed
688
				}
689 690 691 692 693

				if (HESS) {
					if (get_string_from_objectlist("HESS_FILE",number_readobjects,HESS_FILE,varname_list, value_list)) {
						err("Variable HESS_FILE could not be retrieved from the json input file!");
					}
Tilman Steinweg's avatar
Tilman Steinweg committed
694 695 696 697 698 699
				}
			} /* end if (METHOD==1) */

			else {/* only forward modeling is applied */

				ITMIN=1;
700
				fprintf(fp," Variable ITMIN is set to default value %d.\n",ITMIN);
Tilman Steinweg's avatar
Tilman Steinweg committed
701
				ITMAX=1;
702
				fprintf(fp," Variable ITMAX is set to default value %d.\n",ITMAX);
703 704 705

				if (get_int_from_objectlist("FILT",number_readobjects,&FILT,varname_list, value_list)) {
					FILT=0;
706
					fprintf(fp," Variable FILT is set to default value %d.\n",FILT);
707 708

				}
Tilman Steinweg's avatar
Tilman Steinweg committed
709 710 711 712 713

			}

		}

714 715
		fprintf(fp,"\n End of setting default values\n");
		fprintf(fp," =====================================\n\n");
Tilman Steinweg's avatar
Tilman Steinweg committed
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763


		/********************************************/
		/* Check files and directories if necessary */
		/********************************************/

		/* signal file */
		if (SOURCE_SHAPE == 3) {
			if (access(SIGNAL_FILE,0) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The signal file does not exist!\n");
				fprintf(fp, "        File name: <%s>", SIGNAL_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;

			} else if (access(SIGNAL_FILE,4) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The signal file does not have read access!\n");
				fprintf(fp, "        File name: <%s>", SIGNAL_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;
			}
		}

		/* source file */
		if (SRCREC==1) {
			if (access(SOURCE_FILE,0) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The source file does not exist!\n");
				fprintf(fp, "        File name: <%s>", SOURCE_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;

			} else if (access(SOURCE_FILE,4) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The source file does not have read access!\n");
				fprintf(fp, "        File name: <%s>", SOURCE_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;
			}
		}


		/* receiver file */
764
		if (READREC==1) {
Tilman Steinweg's avatar
Tilman Steinweg committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
			if (access(REC_FILE,0) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The receiver file does not exist!\n");
				fprintf(fp, "        File name: <%s>", REC_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;

			} else if (access(REC_FILE,4) != 0) {
				fprintf(fp, "\n==================================================================\n");
				fprintf(fp, "  ERROR parsing input file <%s>:\n", fileinp);
				fprintf(fp, "        The receiver file does not have read access!\n");
				fprintf(fp, "        File name: <%s>", REC_FILE);
				fprintf(fp, "\n==================================================================\n");
				fserr = 1;
			}
		}


		/********************************************/
		/* ERROR                                    */
		/********************************************/
		if (fserr) {
			fprintf(fp, "\n");
			sprintf(errormessage, "\n  in: <read_par_json.c> \n");
			err(errormessage);
		}


	} /* End of if(MYID==0) */
}

797