read_par_json.c 29.4 KB
Newer Older
tilman.metz's avatar
tilman.metz 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
/*-----------------------------------------------------------------------------------------
 * 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;
32
	extern int DRX, DRZ, L, SRCREC, FDORDER, FW, FDCOEFF;
tilman.metz's avatar
tilman.metz committed
33 34 35
	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;
36
	extern int SEISMO, NDT, NDTSHIFT, NGEOPH, SEIS_FORMAT, FREE_SURF, READMOD, MOD_FORMAT, READREC, RUN_MULTIPLE_SHOTS;
tilman.metz's avatar
tilman.metz committed
37 38 39 40 41 42
	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;
43
	extern int LITTLEBIG;
tilman.metz's avatar
tilman.metz committed
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

	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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
75 76 77 78 79 80 81 82 83 84 85
		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!");
		}

86
		if (get_int_from_objectlist("NPROCY",number_readobjects,&NPROCY,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
87 88 89
			err("Variable NPROCY could not be retrieved from the json input file!");
		}

90
		if (get_int_from_objectlist("NPROCZ",number_readobjects,&NPROCZ,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
91 92 93 94 95 96 97 98
			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!");
		}

99
		if (get_int_from_objectlist("NY",number_readobjects,&NY,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
100 101 102
			err("Variable NY could not be retrieved from the json input file!");
		}

103
		if (get_int_from_objectlist("NZ",number_readobjects,&NZ,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
104 105 106 107 108 109 110
			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!");
		}

111
		if (get_float_from_objectlist("DY",number_readobjects,&DY,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
112 113 114
			err("Variable DY could not be retrieved from the json input file!");
		}

115
		if (get_float_from_objectlist("DZ",number_readobjects,&DZ,varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
			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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
187
				REFSRC[0]=0.0;
188
				fprintf(fp," Variable REFSRCX is set to default value %.1f.\n",REFSRC[0]);
tilman.metz's avatar
tilman.metz committed
189 190
			}

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

196
			if (get_float_from_objectlist("REFSRCZ",number_readobjects,&REFSRC[2],varname_list, value_list)) {
tilman.metz's avatar
tilman.metz committed
197
				REFSRC[2]=0.0;
198
				fprintf(fp," Variable REFSRCZ is set to default value %.1f.\n",REFSRC[2]);
tilman.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
371 372
		}

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

378
		if (get_int_from_objectlist("IDZ",number_readobjects,&IDZ,varname_list, value_list)) {
379
			IDZ=1;
380
			fprintf(fp," Variable IDZ is set to default value %d.\n",IDZ);
tilman.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
410

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

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

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

423
							if (get_float_from_objectlist("ZREC2",number_readobjects,&ZREC2,varname_list, value_list)) {
424 425
								err("Variable ZREC2 could not be retrieved from the json input file!");
							}
tilman.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
431

432
							break;
tilman.metz's avatar
tilman.metz 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.metz's avatar
tilman.metz committed
438

439
							if (get_float_from_objectlist("REFRECX",number_readobjects,&REFREC[1],varname_list, value_list)) {
440 441
								REFREC[1]=0.0;
								fprintf(fp," Variable REFREC is set to default value %.1f.\n",REFREC[1]);
442
							}
tilman.metz's avatar
tilman.metz committed
443

444 445 446
							if (get_float_from_objectlist("REFRECY",number_readobjects,&REFREC[2],varname_list, value_list)) {
								REFREC[2]=0.0;
								fprintf(fp," Variable REFREC is set to default value %.1f.\n",REFREC[1]);
447
							}
tilman.metz's avatar
tilman.metz committed
448

449 450 451
							if (get_float_from_objectlist("REFRECZ",number_readobjects,&REFREC[3],varname_list, value_list)) {
								REFREC[3]=0.0;
								fprintf(fp," Variable REFREC is set to default value %.1f.\n",REFREC[1]);
452
							}
tilman.metz's avatar
tilman.metz committed
453

454
							break;
tilman.metz's avatar
tilman.metz committed
455

456 457 458 459
						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.metz's avatar
tilman.metz committed
460

461 462 463
							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.metz's avatar
tilman.metz committed
464

465 466 467
							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.metz's avatar
tilman.metz committed
468

469 470 471
							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.metz's avatar
tilman.metz committed
472

473
							if (get_int_from_objectlist("DRZ",number_readobjects,&DRZ,varname_list, value_list)) {
474 475 476 477 478 479 480
								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.metz's avatar
tilman.metz committed
481 482 483 484 485


					}
				}

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

tilman.metz's avatar
tilman.metz committed
494

495 496
			/* --------output ----------
			 *------------------------*/
tilman.metz's avatar
tilman.metz committed
497

498 499
			if (get_int_from_objectlist("NDT",number_readobjects,&NDT,varname_list, value_list)) {
				NDT=1;
500
				fprintf(fp," Variable NDT is set to default value %d.\n",NDT);
tilman.metz's avatar
tilman.metz committed
501
			}
502 503 504

			if (get_int_from_objectlist("NDTSHIFT",number_readobjects,&NDTSHIFT,varname_list, value_list)) {
				NDTSHIFT=0;
505
				fprintf(fp," Variable NDTSHIFT is set to default value %d.\n",NDT);
506 507
			}

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

511
			} 
512
		}/*end of seismo*/
tilman.metz's avatar
tilman.metz committed
513 514 515 516 517 518 519 520 521 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


		if (get_int_from_objectlist("LITTLEBIG",number_readobjects,&LITTLEBIG,varname_list, value_list)) {
			LITTLEBIG=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!");
				}
557

tilman.metz's avatar
tilman.metz committed
558 559 560
				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!");
				}
561

tilman.metz's avatar
tilman.metz committed
562 563 564
				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!");
				}
565

tilman.metz's avatar
tilman.metz committed
566 567 568
				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!");
				}
569

tilman.metz's avatar
tilman.metz committed
570 571 572
				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!");
				}
573

tilman.metz's avatar
tilman.metz committed
574 575 576
				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!");
				}
577

tilman.metz's avatar
tilman.metz committed
578 579 580
				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!");
				}
581

tilman.metz's avatar
tilman.metz committed
582 583 584
				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!");
				}
585 586 587



tilman.metz's avatar
tilman.metz committed
588 589 590
				/*=================================
				section Steplength estimation + Gradient preconditioning
				=================================*/
591

tilman.metz's avatar
tilman.metz committed
592 593 594
				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!");
				}
595

tilman.metz's avatar
tilman.metz committed
596 597 598
				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!");
				}
599

tilman.metz's avatar
tilman.metz committed
600 601 602 603 604 605 606
				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
				=================================*/
607

tilman.metz's avatar
tilman.metz committed
608 609
				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!");
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632

				} 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.metz's avatar
tilman.metz committed
633
				}
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

				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.metz's avatar
tilman.metz committed
649
				}
650 651 652 653 654 655 656

				/*=================================
				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.metz's avatar
tilman.metz committed
657
				}
658 659 660

				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.metz's avatar
tilman.metz committed
661
				}
662 663 664

				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.metz's avatar
tilman.metz committed
665
				}
666 667 668

				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.metz's avatar
tilman.metz committed
669
				}
670 671 672

				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.metz's avatar
tilman.metz committed
673
				}
674 675 676 677 678

				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.metz's avatar
tilman.metz committed
679 680 681 682 683 684
				}
			} /* end if (METHOD==1) */

			else {/* only forward modeling is applied */

				ITMIN=1;
685
				fprintf(fp," Variable ITMIN is set to default value %d.\n",ITMIN);
tilman.metz's avatar
tilman.metz committed
686
				ITMAX=1;
687
				fprintf(fp," Variable ITMAX is set to default value %d.\n",ITMAX);
688 689 690

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

693 694 695 696
				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!");
				}

697
				}
tilman.metz's avatar
tilman.metz committed
698 699 700 701 702

			}

		}

703 704
		fprintf(fp,"\n End of setting default values\n");
		fprintf(fp," =====================================\n\n");
tilman.metz's avatar
tilman.metz committed
705 706 707 708 709 710 711 712 713 714 715 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


		/********************************************/
		/* 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 */
753
		if (READREC==1) {
tilman.metz's avatar
tilman.metz committed
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
			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) */
}

786