read_par.c 13.9 KB
Newer Older
Simone Butzer's avatar
Simone Butzer 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
/*------------------------------------------------------------------------
 * Copyright (C) 2015 For the list of authors, see file AUTHORS.
 *
 * This file is part of IFOS3D.
 * 
 * IFOS3D 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.
 * 
 * IFOS3D 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 IFOS3D. See file COPYING and/or 
 * <http://www.gnu.org/licenses/gpl-2.0.html>.
--------------------------------------------------------------------------*/

/*---------------------------------------------------------------
 * Reading FD-Parameters from input-file                           
 ----------------------------------------------------------------*/

#include "fd.h"

int read_par(FILE *fp_in){


	/* declaration of extern variables */
30
	extern int   NX, NY, NZ, SOURCE_SHAPE, SOURCE_TYPE, SNAP, SNAP_FORMAT, SNAP_PLANE;
Simone Butzer's avatar
Simone Butzer committed
31 32 33 34
	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;
tilman.metz's avatar
tilman.metz committed
35
	extern int SEISMO, NDT, NDTSHIFT, NGEOPH, SEIS_FORMAT[6], FREE_SURF, READMOD, MOD_FORMAT, READREC, RUN_MULTIPLE_SHOTS;
Simone Butzer's avatar
Simone Butzer committed
36 37 38 39 40 41 42 43 44
	extern int BOUNDARY, REC_ARRAY, LOG, 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 FC,AMP, REFSRC[3], SRC_DT, SRCTSHIFT;
tilman.metz's avatar
tilman.metz committed
45
	extern int SRC_MF, SIGNAL_FORMAT, SRCOUT_PAR[6], FSRC, JSRC, LSRC;
Simone Butzer's avatar
Simone Butzer committed
46 47 48 49 50
	extern char SRCOUT_FILE[STRING_SIZE];
	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;*/
51
	extern float TESTSTEP, WATER_HESS[3], WEIGHT[3], VP0, VS0, RHO0;
52
	extern int BFGSNUM, NUMPAR;
Simone Butzer's avatar
Simone Butzer committed
53 54 55 56 57 58
	
	/* definition of local variables */
	char s[256], cline[256]="";
	int  lineno=0, l, nvarin=0;
	
	
59
	if (fp_in==NULL) err(" Could not open input parameter file (ifos3d.inp)! ");
Simone Butzer's avatar
Simone Butzer committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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

		while (fgets(cline,255,fp_in)){ /* leaves via break */
			/* If there are more than 255 characters in one line, this does not work. */
			if (cline[0]!='#'){      /* no comment line */
				lineno++;
				/* fprintf(stderr,"Reading Linenumber %i\n",lineno); */
				switch (lineno){
				case 1 :
					sscanf(cline,"%s =%i",s,&NPROCX);
					break;
				case 2 :
					sscanf(cline,"%s =%i",s,&NPROCZ); 
					/*not that internally "y" is used for the vertical coordinate,
					for usability reasons, we switch the "y" and "z" coordinate 
					so that "z" - as commonly used - denotes the depth (vertical direction)*/
					break;
				case 3 :
					sscanf(cline,"%s =%i",s,&NPROCY); 
					break;
				case 4 :
					sscanf(cline,"%s =%i",s,&NX);
					break;
				case 5 :
					sscanf(cline,"%s =%i",s,&NZ);
					break;
				case 6 :
					sscanf(cline,"%s =%i",s,&NY);
					break;
				case 7 :
					sscanf(cline,"%s =%f",s,&DX);
					break;
                                case 8 :
					sscanf(cline,"%s =%f",s,&DZ);
					break;
				case 9 :
					sscanf(cline,"%s =%f",s,&DY);
					break;
				case 10 :
					sscanf(cline,"%s =%i",s,&FDORDER);
					break;
				case 11 :
					sscanf(cline,"%s =%i",s,&FDCOEFF);
					break;	
				case 12 :
					sscanf(cline,"%s =%f",s,&TIME);
					break;
				case 13 :
					sscanf(cline,"%s =%f",s,&DT);
					break;					
				case 14 :
110
					nvarin=sscanf(cline,"%s =%i , %f , %f",s,&SOURCE_SHAPE,&FC,&AMP);
Simone Butzer's avatar
Simone Butzer committed
111 112
					switch(nvarin){
						case 0: 
113 114
						case 1: SOURCE_SHAPE=0;
							/* fprintf(stderr," Caution: SOURCE_SHAPE set to %d.\n",SOURCE_SHAPE); */
Simone Butzer's avatar
Simone Butzer committed
115 116 117 118 119 120 121 122 123
						case 2: FC=0.0; 
							/* fprintf(stderr," FC set to %d.\n",FC); */
						case 3: AMP=1.0;
							/* fprintf(stderr," AMP set to %d.\n",AMP); */
						/* case 4: break;
						default: fprintf(stderr,"This line of read_par.c should never be reached! [1]\n"); */
					}
					break;
				case 15 :
124
					sscanf(cline,"%s =%i",s,&SOURCE_TYPE);
Simone Butzer's avatar
Simone Butzer committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
					break;
				case 16 :
					sscanf(cline,"%s =%f",s,&ALPHA);		
					break;
				case 17 :
					sscanf(cline,"%s =%f",s,&BETA);
					break;
				case 18 :
					sscanf(cline,"%s =%f",s,&PLANE_WAVE_DEPTH);
					break;
				case 19 :
					sscanf(cline,"%s =%f",s,&PHI);
					break;
				case 20 :
					/* TS has to remain for the plane wave excitation*/
					nvarin=sscanf(cline,"%s =%f , %f",s,&TS,&SRC_DT);
					switch(nvarin){
						case 0: 
						case 1: TS=0; /* to be determined from input data */
						case 2: SRC_DT=DT;
					}					
					break;
				case 21 :
148
					nvarin=sscanf(cline,"%s =%s , %i ",s,SIGNAL_FILE,&SIGNAL_FORMAT);
Simone Butzer's avatar
Simone Butzer committed
149 150 151
					switch(nvarin){
						case 0: 
						case 1: strcpy(SIGNAL_FILE,"\0");
tilman.metz's avatar
tilman.metz committed
152
						case 2: SIGNAL_FORMAT=0;		
Simone Butzer's avatar
Simone Butzer committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
						/* case 8: break;
						default: fprintf(stderr,"This line of read_par.c should never be reached! [2]\n");*/
					}
					break;
				
				case 22 :
					nvarin=sscanf(cline,"%s =%i , %i , %f , %f , %f",s,&SRCREC,&SRC_MF,&REFSRC[0],&REFSRC[1],&REFSRC[2]);
					switch(nvarin){
						case 0: 
						case 1: SRCREC=0; /* default: do not read source positions from file */
						case 2: SRC_MF=0; /* source positions in meter */
						case 3: REFSRC[0]=0.0; /* Reference x-coordinate */
						case 4: REFSRC[1]=0.0; /* Reference y-coordinate */
						case 5: REFSRC[2]=0.0; /* Reference z-coordinate (vertical!)*/
					}
					break;
				case 23 :
					nvarin=sscanf(cline,"%s =%s , %s , %i , %i , %i , %i , %i , %i",s,SOURCE_FILE,SRCOUT_FILE,&SRCOUT_PAR[0],&SRCOUT_PAR[1],&SRCOUT_PAR[2],&SRCOUT_PAR[3],&SRCOUT_PAR[4],&SRCOUT_PAR[5]);	
					switch(nvarin){
						case 0:
						case 1: strcpy(SOURCE_FILE,"\0");
						case 2: strcpy(SRCOUT_FILE,"\0");
						case 3: SRCOUT_PAR[0]=0;
						case 4: SRCOUT_PAR[1]=0;
						case 5: SRCOUT_PAR[2]=0;
						case 6: SRCOUT_PAR[3]=0;
						case 7: SRCOUT_PAR[4]=0;
						case 8: SRCOUT_PAR[5]=0;
					}
					break;
				case 24 :
					nvarin=sscanf(cline,"%s =%i , %f , %i , %i , %i",s,&RUN_MULTIPLE_SHOTS,&SRCTSHIFT,&FSRC,&JSRC,&LSRC);
					switch(nvarin){
						case 0:
						case 1: RUN_MULTIPLE_SHOTS=1;
						case 2: SRCTSHIFT=0.0;
						case 3: FSRC=0;
						case 4: JSRC=1;
						case 5: LSRC=2147483647; /* max int */
					}
					break;
				case 25 :
195
					nvarin=sscanf(cline,"%s =%i , %i ",s,&READMOD,&MOD_FORMAT);
Simone Butzer's avatar
Simone Butzer committed
196 197 198
					switch(nvarin){
						case 0:
						case 1: READMOD=0;
tilman.metz's avatar
tilman.metz committed
199
						case 2: MOD_FORMAT=0;							
Simone Butzer's avatar
Simone Butzer committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 334 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 370 371 372 373 374 375 376 377 378 379 380 381 382
					}
					break;
				case 26 :
					sscanf(cline,"%s =%s",s,MFILE);
					break;
				case 27 :
					sscanf(cline,"%s =%i",s,&L);
					FL=vector(1,L);
					break;
				case 28 :
					sscanf(cline,"%s =%f",s,&FL[1]);
					for (l=2;l<=L;l++) sscanf(cline,"%f",&FL[l]);
					break;
				case 29 :
					sscanf(cline,"%s =%f",s,&TAU);
					break;
				case 30 :
					sscanf(cline,"%s =%i",s,&FREE_SURF);
					break;
				case 31 :
					sscanf(cline,"%s =%i",s,&ABS_TYPE);
					break;	
				case 32 :
					sscanf(cline,"%s =%i",s,&FW);
					if (FW<0) FW=0;
					break;				
				case 33 :
					sscanf(cline,"%s =%f",s,&DAMPING);
					break;
				case 34 :
					sscanf(cline,"%s =%f",s,&FPML);
					break;

				case 35 :
					sscanf(cline,"%s =%f",s,&VPPML);
					break;	
				case 36:
					sscanf(cline,"%s =%i",s,&BOUNDARY);
					break;
				case 37 :
					sscanf(cline,"%s =%i",s,&SNAP);
					break;
				case 38 :
					sscanf(cline,"%s =%f",s,&TSNAP1);
					break;
				case 39 :
					sscanf(cline,"%s =%f",s,&TSNAP2);
					break;
				case 40 :
					sscanf(cline,"%s =%f",s,&TSNAPINC);
					break;
				case 41 :
					sscanf(cline,"%s =%i",s,&IDX);
					break;
				case 42 :
					sscanf(cline,"%s =%i",s,&IDZ);
					/*not that internally "y" is used for the vertical coordinate,
					for usability reasons, we switch the "y" and "z" coordinate 
					so that "z" - as commonly used - denotes the depth (vertical direction)*/
					break;
				case 43 :
					sscanf(cline,"%s =%i",s,&IDY);
					break;
				case 44 :
					sscanf(cline,"%s =%i",s,&SNAP_FORMAT);
					break;
				case 45 :
					sscanf(cline,"%s =%s",s,SNAP_FILE);
					break;
				case 46 :
					sscanf(cline,"%s =%i",s,&SNAP_PLANE);
					break;	
				case 47 :
					sscanf(cline,"%s =%i",s,&SEISMO);
					break;
				case 48 :
					sscanf(cline,"%s =%i",s,&READREC);
					break;
				case 49 :
					sscanf(cline,"%s =%s",s,REC_FILE);
					break;
				case 50 :
					sscanf(cline,"%s =%f ,%f , %f",s,&REFREC[1],&REFREC[3],&REFREC[2]);
					break;
				case 51 :
					sscanf(cline,"%s =%f ,%f ,%f",s,&XREC1,&ZREC1,&YREC1);
					break;
				case 52 :
					sscanf(cline,"%s =%f ,%f ,%f",s,&XREC2,&ZREC2,&YREC2);
					break;
				case 53 :
					sscanf(cline,"%s =%i",s,&NGEOPH);
					break;
				case 54 :
					sscanf(cline,"%s =%i",s,&REC_ARRAY);
					break;
				case 55 :
					sscanf(cline,"%s =%f",s,&REC_ARRAY_DEPTH);
					break;
				case 56 :
					sscanf(cline,"%s =%f",s,&REC_ARRAY_DIST);
					break;
				case 57 :
					sscanf(cline,"%s =%i",s,&DRX);
					break;
				case 58 :
					sscanf(cline,"%s =%i",s,&DRY);
					break;
				case 59 :
					nvarin=sscanf(cline,"%s =%i , %i",s,&NDT,&NDTSHIFT);
					switch(nvarin){ /* missing input values may be read as zero or lead to reduced nvarin */
						case 0: ;
						case 1: NDT=1;
							/* fprintf(stderr," NDT set to %d.\n",NDT); */
						case 2: NDTSHIFT=0;
							/* fprintf(stderr," NDTSHIFT set to %d.\n",NDTSHIFT); */
					}
					break;
				case 60 :
					nvarin=sscanf(cline,"%s =%i ,%i ,%i ,%i ,%i ,%i",
						s,&SEIS_FORMAT[0],&SEIS_FORMAT[1],&SEIS_FORMAT[2],&SEIS_FORMAT[3],&SEIS_FORMAT[4],&SEIS_FORMAT[5]);
					/* fprintf (stderr,"%d values read to SEIS_FORMAT.\n",nvarin-1); */
					switch(nvarin){
						case 0: ;
						case 1: SEIS_FORMAT[0]=0; /* seimogram data format */
						        /* fprintf(stderr," SEIS_FORMAT[0] set to %d.\n",SEIS_FORMAT[0]); */
						case 2: SEIS_FORMAT[1]=0; /* ASCII- / EBCDIC- output*/
						        /* fprintf(stderr," SEIS_FORMAT[1] set to %d.\n",SEIS_FORMAT[1]); */
						case 3: SEIS_FORMAT[2]=0; /* little / big endian output */
						        /* fprintf(stderr," SEIS_FORMAT[2] set to %d.\n",SEIS_FORMAT[2]); */
						case 4: SEIS_FORMAT[3]=0; /* ieee / ibm float output */
						        /* fprintf(stderr," SEIS_FORMAT[3] set to %d.\n",SEIS_FORMAT[3]); */
						case 5: SEIS_FORMAT[4]=0; /* output in meter / feet */
						        /* fprintf(stderr," SEIS_FORMAT[4] set to %d.\n",SEIS_FORMAT[4]); */
						case 6: SEIS_FORMAT[5]=0; /* maximum trace length */
						        /* fprintf(stderr," SEIS_FORMAT[5] set to %d.\n",SEIS_FORMAT[5]); */
					}
					if (SEIS_FORMAT[0]==4) {
						SEIS_FORMAT[0]=0;
						/* fprintf(stderr," SEIS_FORMAT[1] set to %d.\n",SEIS_FORMAT[1]); */
					}
					if (SEIS_FORMAT[0]==5) {
						SEIS_FORMAT[0]=0;
						SEIS_FORMAT[1]=1;
						/* fprintf(stderr," SEIS_FORMAT[1] set to %d.\n",SEIS_FORMAT[1]); */
						SEIS_FORMAT[2]=1;
						/* fprintf(stderr," SEIS_FORMAT[2] set to %d.\n",SEIS_FORMAT[2]); */
						SEIS_FORMAT[3]=1;
						/* fprintf(stderr," SEIS_FORMAT[3] set to %d.\n",SEIS_FORMAT[3]); */
						SEIS_FORMAT[4]=0;
						SEIS_FORMAT[5]=0;					
					}
					break;
				case 61 :
					sscanf(cline,"%s =%s",s,SEIS_FILE);
					break;
				case 62:
					sscanf(cline,"%s =%i",s,&METHOD);
	    				break;
				case 63 :
					sscanf(cline,"%s =%s",s,GRAD_FILE);
					break;
				case 64 :
					sscanf(cline,"%s =%s",s,MOD_OUT_FILE);
					break;	
				/*case 69 :
					sscanf(cline,"%s =%f",s,&F_INV);
					break;	*/
				case 65 :
					sscanf(cline,"%s =%s",s,SEIS_OBS_FILE);
					break;	
				case 66:
					sscanf(cline,"%s =%i",s,&EXTOBS);
	    				break;
				case 67 :
					sscanf(cline,"%s =%s",s,INV_FILE);
					break;
				case 68 :
					sscanf(cline,"%s =%s",s,HESS_FILE);
					break;	
				case 69 :	
					sscanf(cline,"%s =%i , %i",s,&ITMIN,&ITMAX);
					if(!METHOD) ITMAX=1;
383
					break;						
Simone Butzer's avatar
Simone Butzer committed
384 385 386 387 388 389 390 391 392
				case 70 :
					sscanf(cline,"%s =%i",s,&FILT);
					break;
				case 71 :
					sscanf(cline,"%s =%i",s,&NFMAX);
					break;	
				case 72 :
					sscanf(cline,"%s =%i",s,&TAST);
					break;	
393 394
				case 73:
					sscanf(cline,"%s =%f, %f, %f",s,&VP0,&VS0,&RHO0);
Simone Butzer's avatar
Simone Butzer committed
395 396
					break;	
				case 74 :
397 398 399 400 401 402 403
					sscanf(cline,"%s =%f, %f, %f",s,&WEIGHT[0],&WEIGHT[1],&WEIGHT[2]);	
					break;	
					
				case 75 :
					sscanf(cline,"%s =%i",s,&NSHOTS_STEP);
					break;	
				case 76 :
Simone Butzer's avatar
Simone Butzer committed
404 405
					sscanf(cline,"%s =%f",s,&TESTSTEP);
					break;
406
				case 77 :
Simone Butzer's avatar
Simone Butzer committed
407 408
					sscanf(cline,"%s =%i",s,&DAMPTYPE);
					break;
409
				case 78 :
Simone Butzer's avatar
Simone Butzer committed
410 411
					sscanf(cline,"%s =%i",s,&HESS);
					break;	
412
				case 79 :
Simone Butzer's avatar
Simone Butzer committed
413 414
					sscanf(cline,"%s =%i",s,&READ_HESS);
					break;	
415
				case 80 :
Simone Butzer's avatar
Simone Butzer committed
416 417
					sscanf(cline,"%s =%i",s,&REC_HESS);
					break;	
418
				case 81 :
Simone Butzer's avatar
Simone Butzer committed
419 420
					sscanf(cline,"%s =%f, %f, %f",s,&WATER_HESS[0],&WATER_HESS[1],&WATER_HESS[2]);
					break;	
421
				case 82 :
Simone Butzer's avatar
Simone Butzer committed
422 423
					sscanf(cline,"%s =%i",s,&LBFGS);
					break;
424
				case 83 :
425 426 427 428 429 430
					sscanf(cline,"%s =%i",s,&NUMPAR);
					break;	
				case 84 :
					sscanf(cline,"%s =%i",s,&BFGSNUM);
					break;	
				case 85 :
Simone Butzer's avatar
Simone Butzer committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444
	    				nvarin=sscanf(cline,"%s =%i ,%i ,%i",s,&ASCIIEBCDIC,&LITTLEBIG,&IEEEIBM);
					switch(nvarin){
						case 0: ;
						case 1: ASCIIEBCDIC=0;
						case 2: LITTLEBIG=0;
						case 3: IEEEIBM=0;
					}					
	    				break;						    			
 				default:
					break;
				}		
			}
		}
		LOG=0;
445
		if(lineno<85) fprintf(stderr," Warning: only %d non-commentary lines of input parameters read (expected 83).\n",lineno);
Simone Butzer's avatar
Simone Butzer committed
446 447 448 449 450 451
		/* else if (lineno>71) fprintf(stderr," Warning: %d non-commentary lines of input parameters read \n \t(expected and interpreted: 67).\n",lineno); */
		/* else  fprintf(stderr," %d non-commentary lines of input parameters read.\n",lineno); */
		fclose(fp_in);
	return (lineno);
}