From c8370d025f50bbb55a39d21701607481d90ddc47 Mon Sep 17 00:00:00 2001 From: Tilman Metz Date: Tue, 12 Apr 2016 16:36:17 +0200 Subject: [PATCH] implemented json input + few addidtional changes: SRCREC is now the switch to either read from .dat file =1 or use plane wave =2 reduced some arrays (currently unused) to variables --- par/in_and_out/ifos3d_inv_all_parameters.json | 132 +++ .../ifos3d_inv_all_parameters_commented.json | 240 ++++++ par/in_and_out/ifos3d_toy.json | 126 +++ par/in_and_out/ifos3d_toy_FW.json | 90 +++ par/receiver/receiver.dat | 20 + src/Makefile | 8 +- src/fd.h | 31 +- src/globvar.h | 5 +- src/ifos3d.c | 48 +- src/json_parser.c | 463 +++++++++++ src/part_model.c | 21 +- src/read_par.c | 22 +- src/read_par_json.c | 765 ++++++++++++++++++ src/saveseis.c | 1 + src/snapmerge.c | 133 +-- 15 files changed, 2013 insertions(+), 92 deletions(-) create mode 100644 par/in_and_out/ifos3d_inv_all_parameters.json create mode 100644 par/in_and_out/ifos3d_inv_all_parameters_commented.json create mode 100644 par/in_and_out/ifos3d_toy.json create mode 100644 par/in_and_out/ifos3d_toy_FW.json create mode 100644 par/receiver/receiver.dat create mode 100644 src/json_parser.c create mode 100644 src/read_par_json.c diff --git a/par/in_and_out/ifos3d_inv_all_parameters.json b/par/in_and_out/ifos3d_inv_all_parameters.json new file mode 100644 index 0000000..2804acd --- /dev/null +++ b/par/in_and_out/ifos3d_inv_all_parameters.json @@ -0,0 +1,132 @@ +{ +"MODELING PARAMETERS" : "comment", + +"Domain Decomposition" : "comment", + "NPROCX" : "2", + "NPROCY" : "2", + "NPROCZ" : "2", + +"3-D Grid" : "comment", + "NX" : "160", + "NY" : "160", + "NZ" : "184", + "DX" : "0.8", + "DY" : "0.8", + "DZ" : "0.8", + +"FD order" : "comment", + "FDORDER" : "4", + "FDCOEFF" : "2", + +"Time Stepping" : "comment", + "TIME" : "0.06", + "DT" : "5.0e-05", + +"Source" : "comment", + "SOURCE_SHAPE" : "4", + "SOURCE_TYPE" : "4", + "ALPHA" : "45.0", + "BETA" : "45.0", + "PLANE_WAVE_DEPTH" : "0.0", + "PHI" : "0.0", + "TS" : "0.0033", + "SIGNAL_FILE" : "./STF/stf.su", + "SRCREC" : "1", + "SOURCE_FILE" : "./sources/sources_toy.dat", + "RUN_MULTIPLE_SHOTS" : "1", + +"Model" : "comment", + "READMOD" : "0", + "MFILE" : "model/toy", + + +"Q-approximation" : "comment", + "L" : "0", + "FL1" : "1000.0", + "TAU" : "0.000001", + +"Free Surface" : "comment", + "FREE_SURF" : "0", + + +"Absorbing Boundary" : "comment", + "ABS_TYPE" : "1", + "FW" : "10", + "DAMPING" : "8.0", + "VPPML" : "6200.0", + "FPML" : "200.00", + "BOUNDARY" : "0", + +"Snapshots" : "comment", + "SNAP" : "0", + "TSNAP1" : "0.01", + "TSNAP2" : "0.24", + "TSNAPINC" : "0.0075", + "IDX, IDY, IDZ" : "1,1,1", + "SNAP_FORMAT" : "4", + "SNAP_FILE" : "./snap/back", + "SNAP_PLANE" : "1", + +"Receiver" : "comment", + "SEISMO" : "1", + "READREC" : "0", + "REC_FILE" : "./receiver/receiver.dat", + "REFRECX, REFRECY, REFRECZ" : "0.0 , 0.0, 0.0", + "XREC1, YREC1, ZREC1" : "90.0 , 90.0, 90.0", + "XREC2, YREC2, ZREC2" : "90.0 , 90.0, 90.0", + "NGEOPH" : "1", + +"Receiver array" : "comment", + "REC_ARRAY" : "1", + "REC_ARRAY_DEPTH" : "24.0", + "REC_ARRAY_DIST" : "30.0", + "DRX" : "10", + "DRY" : "10", + + +"Seismograms" : "comment", + "NDT" : "1", + "NDTSHIFT" : "0", + "SEIS_FORMAT" : "1", + "SEIS_FILE" : "su/IFOS", + + +"Method" : "comment", + "METHOD" : "0", + +"INVERSION PARAMETERS" : "comment", + +"In- and Output Files" : "comment", + "GRAD_FILE" : "./grad/toy_grad", + "MOD_OUT_FILE" : "./model/toy", + "SEIS_OBS_FILE" : "./su_obs/obs_toy", + "EXTOBS" : "0", + "INV_FILE" : "./in_and_out/workflow_toy.dat", + "HESS_FILE" : "./hess/toy_hess", + +"General" : "comment", + "ITMIN, ITMAX" : "1 , 80", + "FILT" : "1", + "NFMAX" : "5", + "TAST" : "100", + "VP0, VS0, RHO0" : "6200.0, 3600.0, 2800.0", + "WEIGHT_VP,WEIGHT_VS,WEIGHT_RHO" : "1.0, 1.0, 0.0", + +"Steplength estimation" : "comment", + "NSHOTS_STEP" : "4", + "TESTSTEP" : "0.02", + +"Gradient preconditioning" : "comment", + "DAMPTYPE" : "2", + +"Hessian" : "comment", + "HESS" : "0", + "READ_HESS" : "0", + "REC_HESS" : "1", + "WATER_HESS_VP, WATER_HESS_VS, WATER_HESS_RHO" : "0.0192, 0.0192, 1.0e-14", + +"L-BFGS" : "comment", + "LBFGS" : "0", + "NUMPAR" : "2", + "BFGSNUM" : "5" +} diff --git a/par/in_and_out/ifos3d_inv_all_parameters_commented.json b/par/in_and_out/ifos3d_inv_all_parameters_commented.json new file mode 100644 index 0000000..d2137b8 --- /dev/null +++ b/par/in_and_out/ifos3d_inv_all_parameters_commented.json @@ -0,0 +1,240 @@ +{ +"MODELING PARAMETERS" : "comment", + +"Note that z denotes the vertical direction !" : "comment", + +"Domain Decomposition" : "comment", + "NPROCX" : "2", + "NPROCY" : "2", + "NPROCZ" : "2", + +"3-D Grid" : "comment", + "NX" : "160", + "NY" : "160", + "NZ" : "184", + "DX" : "0.8", + "DY" : "0.8", + "DZ" : "0.8", + "Caution: first gridpoint is not at {0.0,0.0,0.0} but at {dx,dy,dz}!" : "comment", + +"FD order" : "comment", + "FDORDER" : "4", + "possible values are 2, 4, 6, 8, 10, 12" : "comment", + "fd_coefficients_(Taylor=1;Holberg=2)" : "comment", + "FDCOEFF" : "2", + +"Time Stepping" : "comment", + "time_of_wave_propagation_(in_sec)" : "comment", + "TIME" : "0.06", + "timestep_(in_seconds)" : "comment", + "DT" : "5.0e-05", + +"Source" : "comment", + "Shape_of_source-signal:" : "comment", + "SOURCE_SHAPE" : "4", + "SOURCE_SHAPE values: ricker=1;fumue=2;from_SIGNAL_FILE=3;SIN**3=4;deltapulse=5" : "comment", + "External signal input instead of SOURCE_SHAPE" : "comment", + "SIGNAL_FILE" : "./STF/stf.su", + "SOURCE_TYPE" : "4", + "SOURCE_TYPE values (point_source): explosive=1;force_in_x=2;force_in_y=3;force_in_z=4;custom=5" : "comment", + "If SOURCE_TYPE <5 the following two lines are ignored" : "comment", + "ALPHA" : "45.0", + "BETA" : "45.0", + "ALPHA=force_angle_between_x_y_(in_degree) (BETA between x_z)" : "comment", + "read_source_positions_from_SOURCE_FILE_(yes=1;Plane wave=2) " : "comment", + "SRCREC" : "1", + "SOURCE_FILE" : "./sources/sources_toy.dat", + "run_multiple_shots_defined_in_SOURCE_FILE_(yes=1)" : "comment", + "RUN_MULTIPLE_SHOTS" : "1", + + "Following lines can be ignored if SRCREC!=2" : "comment", + "Plane wave (PW) excitation,if PLANE_WAVE_DEPTH>0, SRCREC is treated as 0" : "comment", + "depth_of_PW_excitation_(no<=0)_(in_meter)" : "comment", + "PLANE_WAVE_DEPTH" : "0.0", + "dip_of_PW_from_vertical_(in_degrees)" : "comment", + "PHI" : "0.0", + "duration_of_source-signal_PW_(in_seconds)" : "comment", + "TS" : "0.0033", + +"Model" : "comment", + "read_model_from_MFILE(yes=1)" : "comment", + "READMOD" : "0", + "MFILE" : "model/toy", + + +"Q-approximation" : "comment", + "Number_of_relaxation_mechanisms" : "comment", + "L" : "0", + "L_Relaxation_frequencies" : "comment", + "FL1" : "1000.0", + "Tau_value_for_entire_model" : "comment", + "TAU" : "0.000001", + +"Free Surface" : "comment", + "free_surface_(yes=1)" : "comment", + "FREE_SURF" : "0", + + +"Absorbing Boundary" : "comment", + "type_of_boundary_condition_(ABS_TYPE)_(PML=1/ABS=2)" : "comment", + "ABS_TYPE" : "1", + "width_of_absorbing_frame_(in_grid_points)_(No<=0)" : "comment", + "FW" : "10", + "percentage_of_amplitude_decay_at_outer_edge" : "comment", + "DAMPING" : "8.0", + "parameter for PML:" : "comment", + "P_wave_velocity_near_the_grid_boundary(in_m/s)" : "comment", + "VPPML" : "6200.0", + "Dominant_frequency_(in_Hz)" : "comment", + "FPML" : "200.00", + "apply_periodic_boundary_condition_at_edges" : "comment", + "BOUNDARY" : "0", + +"Snapshots" : "comment", + "output_of_snapshots(yes>0)" : "comment", + "SNAP" : "0", + "output of particle velocities: SNAP=1" : "comment", + "output of pressure field: SNAP=2" : "comment", + "output of curl and divergence energy: SNAP=3" : "comment", + "output of both particle velocities and energy : SNAP=4" : "comment", + "first_snapshot_(in_sec)" : "comment", + "TSNAP1" : "0.01", + "last_snapshot_(in_sec)" : "comment", + "TSNAP2" : "0.24", + "increment_(in_sec)" : "comment", + "TSNAPINC" : "0.0075", + "increment_x,y,z-direction" : "comment", + "IDX, IDY, IDZ" : "1,1,1", + "data-format(ASCII(2);BINARY(3))" : "comment", + "SNAP_FORMAT" : "4", + "basic_filename" : "comment", + "SNAP_FILE" : "./snap/back", + "if SNAP !=3 the following line is ignored" : "comment", + "SNAP_PLANE" : "1", + "output of snapshots as energy wihout sign SNAP_PLANE=1" : "comment", + "energy with sign true for x-z-plane SNAP_PLANE=2" : "comment", + "energy with sign true for x-y-plane SNAP_PLANE=3" : "comment", + "energy with sign true for y-z-plane SNAP_PLANE=4" : "comment", + +"Receiver" : "comment", + "output_of_seismograms" : "comment", + "SEISMO" : "1", + "SEISMO=0: no seismograms" : "comment", + "SEISMO=1: particle-velocities" : "comment", + "SEISMO=2: pressure (hydrophones)" : "comment", + "SEISMO=3: curl and div" : "comment", + "SEISMO=4: everything" : "comment", + "Warning: "curl" is not really curl in 3D" : "comment", + "read_receiver_positions_from_file_(yes=1)" : "comment", + "READREC" : "0", + "REC_FILE" : "./receiver/receiver.dat", + "reference_point_for_receiver_coordinate_system" : "comment", + "REFRECX, REFRECY, REFRECZ" : "0.0 , 0.0, 0.0", + "if READREC=1 the following three lines are ignored" : "comment", + "Note that z denotes the vertical direction !" : "comment", + "position_of_first_receiver_(in_m)" : "comment", + "XREC1, YREC1, ZREC1" : "90.0 , 90.0, 90.0", + "position_of_last_receiver_(in_m)" : "comment", + "XREC2, YREC2, ZREC2" : "90.0 , 90.0, 90.0", + "distance_between_two_adjacent_receivers" : "comment", + "NGEOPH" : "1", + +"Receiver array" : "comment", + "parameters for horizontal plane of receivers" : "comment", + "number_of_planes_(no<=0)" : "comment", + "REC_ARRAY" : "1", + "depth_of_first_(upper)_plane_(in_m)" : "comment", + "REC_ARRAY_DEPTH" : "24.0", + "vertical_distance_between_planes_(in_m)" : "comment", + "REC_ARRAY_DIST" : "30.0", + "distance_between_receivers_in_x/y-direction" : "comment", + "DRX" : "10", + "DRY" : "10", + + +"Seismograms" : "comment", + "samplingrate_and_timelag_(in_timesteps!)" : "comment", + "NDT" : "1", + "NDTSHIFT" : "0", + "write every (ndt)th sample, leaving ndtshift samples at the beginning out" : "comment", + "default: ndt=1 and ndtshift=0. (ndt=0 is set to ndt=1, ndt<0 are set to -ndt.)" : "comment", + "data-format" : "comment", + "SEIS_FORMAT" : "1", + "0: SEG-Y (ASCII-text/native 4-byte-floats (IEEE on PC)/little endian on PC)" : "comment", + "1: SU (native 4-byte-floats (IEEE on PC)/little endian on PC)" : "comment", + "2: TEXTUAL (native ASCII)" : "comment", + "3: BINARY (IEEE-4-byte-floats on PC/little endian on PC)" : "comment", + "4: SEG-Y (ASCII-text/native 4-byte-floats (IEEE on PC)/little endian on PC)" : "comment", + "5: SEG-Y (ASCII-text/IBM-4-byte-floats on PC/big endian on PC) " : "comment", + "basic_filename" : "comment", + "SEIS_FILE" : "su/IFOS", + + +"Method" : "comment", + "METHOD" : "0", + "0: only forward simulation" : "comment", + "1: conjugate_gradient_FWI" : "comment", + +"INVERSION PARAMETERS" : "comment", + +"In- and Output Files" : "comment", + "gradient_filename" : "comment", + "GRAD_FILE" : "./grad/toy_grad", + "model_output_filename" : "comment", + "MOD_OUT_FILE" : "./model/toy", + "observed_data_fileneame" : "comment", + "SEIS_OBS_FILE" : "./su_obs/obs_toy", + "external_or_internal_observed_data" : "comment", + "EXTOBS" : "0", + "inversion_parameter_file" : "comment", + "INV_FILE" : "./in_and_out/workflow_toy.dat", + "hessian_file" : "comment", + "HESS_FILE" : "./hess/toy_hess", + +"General" : "comment", + "minimum/maximum_iteration_number >0" : "comment", + "ITMIN, ITMAX" : "1 , 80", + "filtering_(yes=1/no=0)" : "comment", + "FILT" : "1", + "maximum_number_frequencies_per_iteration" : "comment", + "NFMAX" : "5", + "number_of_timestep_per_period_used_for_inversion" : "comment", + "TAST" : "100", + "average_model_parameter" : "comment", + "VP0, VS0, RHO0" : "6200.0, 3600.0, 2800.0", + "velocities in m/s, density in kg/m³" : "comment", + "parameter_class_weighting_factors_for_vp/vs/rho_" : "comment", + "WEIGHT_VP,WEIGHT_VS,WEIGHT_RHO" : "1.0, 1.0, 0.0", + "choose from 1.0 (full update) to 0.0 (no update)" : "comment", + +"Steplength estimation" : "comment", + "number_of_shots_used_for_steplength_estimation" : "comment", + "NSHOTS_STEP" : "4", + "initial_test_steplength" : "comment", + "TESTSTEP" : "0.02", + +"Gradient preconditioning" : "comment", + "Type_of_preconditioning" : "comment", + "DAMPTYPE" : "2", + "0: no damping; 1: Circular taper around receivers;" : "comment", + "2: Cicular taper around sources and receivers; 3: Tapering of source and receiver planes" : "comment", + +"Hessian" : "comment", + "Apply_Hessian_(yes=1/no=0)" : "comment", + "HESS" : "0", + "Read_Hessian_from_file" : "comment", + "READ_HESS" : "0", + "Part_of_receivers_used_for_Hessian" : "comment", + "REC_HESS" : "1", + "(Each REC_HESS Receiver is used to calculate the Hessian, not yet implemented)" : "comment", + "Water_level_Hessian_for_vp/vs/rho" : "comment", + "WATER_HESS_VP, WATER_HESS_VS, WATER_HESS_RHO" : "0.0192, 0.0192, 1.0e-14", + +"L-BFGS" : "comment", + "Apply_L_BFGS" : "comment", + "LBFGS" : "0", + "Number_of_inverted_parameters" : "comment", + "NUMPAR" : "2", + "Number_iterations_used_for_LBFGS" : "comment", + "BFGSNUM" : "5" +} diff --git a/par/in_and_out/ifos3d_toy.json b/par/in_and_out/ifos3d_toy.json new file mode 100644 index 0000000..3921bce --- /dev/null +++ b/par/in_and_out/ifos3d_toy.json @@ -0,0 +1,126 @@ +{ +"MODELING PARAMETERS" : "comment", + +"Domain Decomposition" : "comment", + "NPROCX" : "2", + "NPROCY" : "2", + "NPROCZ" : "2", + +"3-D Grid" : "comment", + "NX" : "160", + "NY" : "160", + "NZ" : "184", + "DX" : "0.8", + "DY" : "0.8", + "DZ" : "0.8", + +"FD order" : "comment", + "FDORDER" : "4", + "FDCOEFF" : "2", + +"Time Stepping" : "comment", + "TIME" : "0.06", + "DT" : "5.0e-05", + +"Source" : "comment", + "SOURCE_SHAPE" : "4", + "SOURCE_TYPE" : "4", + "SIGNAL_FILE" : "./STF/stf.su", + "SRCREC" : "1", + "SOURCE_FILE" : "./sources/sources_toy.dat", + "RUN_MULTIPLE_SHOTS" : "1", + +"Model" : "comment", + "READMOD" : "0", + "MFILE" : "model/toy", + + +"Q-approximation" : "comment", + "L" : "0", + "FL1" : "1000.0", + "TAU" : "0.000001", + +"Free Surface" : "comment", + "FREE_SURF" : "0", + + +"Absorbing Boundary" : "comment", + "ABS_TYPE" : "1", + "FW" : "10", + "VPPML" : "6200.0", + "FPML" : "200.00", + "BOUNDARY" : "0", + +"Snapshots" : "comment", + "SNAP" : "0", + "TSNAP1" : "0.01", + "TSNAP2" : "0.24", + "TSNAPINC" : "0.0075", + "IDX, IDY, IDZ" : "1,1,1", + "SNAP_FORMAT" : "4", + "SNAP_FILE" : "./snap/back", + "SNAP_PLANE" : "1", + +"Receiver" : "comment", + "SEISMO" : "1", + "READREC" : "0", + "REC_FILE" : "./receiver/receiver.dat", + "REFRECX, REFRECY, REFRECZ" : "0.0 , 0.0, 0.0", + "XREC1, YREC1, ZREC1" : "90.0 , 90.0, 90.0", + "XREC2, YREC2, ZREC2" : "90.0 , 90.0, 90.0", + "NGEOPH" : "1", + +"Receiver array" : "comment", + "REC_ARRAY" : "1", + "REC_ARRAY_DEPTH" : "24.0", + "REC_ARRAY_DIST" : "30.0", + "DRX" : "10", + "DRY" : "10", + + +"Seismograms" : "comment", + "NDT" : "1", + "NDTSHIFT" : "0", + "SEIS_FORMAT" : "1", + "SEIS_FILE" : "./su_obs/obs_toy", + + +"Method" : "comment", + "METHOD" : "0", + +"INVERSION PARAMETERS" : "comment", + +"In- and Output Files" : "comment", + "GRAD_FILE" : "./grad/toy_grad", + "MOD_OUT_FILE" : "./model/toy", + "SEIS_OBS_FILE" : "./su_obs/obs_toy", + "EXTOBS" : "0", + "INV_FILE" : "./in_and_out/workflow_toy.dat", + "HESS_FILE" : "./hess/toy_hess", + +"General" : "comment", + "ITMIN, ITMAX" : "1 , 60", + "FILT" : "0", + "NFMAX" : "5", + "TAST" : "100", + "VP0, VS0, RHO0" : "6200.0, 3600.0, 2800.0", + "WEIGHT" : "1.0, 1.0, 0.0", + +"Steplength estimation" : "comment", + "NSHOTS_STEP" : "4", + "TESTSTEP" : "0.02", + +"Gradient preconditioning" : "comment", + "DAMPTYPE" : "2", + +"Hessian" : "comment", + "HESS" : "0", + "READ_HESS" : "0", + "REC_HESS" : "1", + "WATER_HESS_VP, WATER_HESS_VS, WATER_HESS_RHO" : "0.0192, 0.0192, 1.0e-14", + +"L-BFGS" : "comment", + "LBFGS" : "0", + "NUMPAR" : "2", + "BFGSNUM" : "5" +} diff --git a/par/in_and_out/ifos3d_toy_FW.json b/par/in_and_out/ifos3d_toy_FW.json new file mode 100644 index 0000000..30be844 --- /dev/null +++ b/par/in_and_out/ifos3d_toy_FW.json @@ -0,0 +1,90 @@ +{ +"MODELING PARAMETERS" : "comment", + +"Domain Decomposition" : "comment", + "NPROCX" : "2", + "NPROCY" : "2", + "NPROCZ" : "2", + +"3-D Grid" : "comment", + "NX" : "160", + "NY" : "160", + "NZ" : "184", + "DX" : "0.8", + "DY" : "0.8", + "DZ" : "0.8", + +"FD order" : "comment", + "FDORDER" : "4", + "FDCOEFF" : "2", + +"Time Stepping" : "comment", + "TIME" : "0.06", + "DT" : "5.0e-05", + +"Source" : "comment", + "SOURCE_SHAPE" : "4", + "SOURCE_TYPE" : "4", + "SIGNAL_FILE" : "./STF/stf.su", + "SRCREC" : "1", + "SOURCE_FILE" : "./sources/sources_toy.dat", + "RUN_MULTIPLE_SHOTS" : "1", + +"Model" : "comment", + "READMOD" : "0", + "MFILE" : "model/toy", + + +"Q-approximation" : "comment", + "L" : "0", + "FL1" : "1000.0", + "TAU" : "0.000001", + +"Free Surface" : "comment", + "FREE_SURF" : "0", + + +"Absorbing Boundary" : "comment", + "ABS_TYPE" : "1", + "FW" : "10", + "VPPML" : "6200.0", + "FPML" : "200.00", + "BOUNDARY" : "0", + +"Snapshots" : "comment", + "SNAP" : "0", + "TSNAP1" : "0.01", + "TSNAP2" : "0.24", + "TSNAPINC" : "0.0075", + "IDX, IDY, IDZ" : "1,1,1", + "SNAP_FORMAT" : "4", + "SNAP_FILE" : "./snap/back", + "SNAP_PLANE" : "1", + +"Receiver" : "comment", + "SEISMO" : "1", + "READREC" : "0", + "REC_FILE" : "./receiver/receiver.dat", + "REFRECX, REFRECY, REFRECZ" : "0.0 , 0.0, 0.0", + "XREC1, YREC1, ZREC1" : "90.0 , 90.0, 90.0", + "XREC2, YREC2, ZREC2" : "90.0 , 90.0, 90.0", + "NGEOPH" : "1", + +"Receiver array" : "comment", + "REC_ARRAY" : "1", + "REC_ARRAY_DEPTH" : "24.0", + "REC_ARRAY_DIST" : "30.0", + "DRX" : "10", + "DRY" : "10", + + +"Seismograms" : "comment", + "NDT" : "1", + "NDTSHIFT" : "0", + "SEIS_FORMAT" : "1", + "SEIS_FILE" : "./su_obs/obs_toy", + + +"Method" : "comment", + "METHOD" : "0" +} diff --git a/par/receiver/receiver.dat b/par/receiver/receiver.dat new file mode 100644 index 0000000..1cf6c73 --- /dev/null +++ b/par/receiver/receiver.dat @@ -0,0 +1,20 @@ +35.0 32.0 92.0 +35.8 32.0 92.0 +36.6 32.0 92.0 +37.4 32.0 92.0 +38.2 32.0 92.0 +39.0 32.0 92.0 +39.8 32.0 92.0 +40.6 32.0 92.0 +41.4 32.0 92.0 +# +#(comment line is indicated by # or % as first character) +# +# Parameters for each receiver postiton (one receiver per line): +# +# XSRC YSRC ZSRC +# +# Symbols: +# XSRC= x-coordinate of source point [meter] +# YSRC= y-coordinate of source point [meter] +# ZSRC= z-coordinate of source point [meter] (vertical) diff --git a/src/Makefile b/src/Makefile index 56e5a32..6d3d480 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,6 +47,7 @@ IFLAGS=-I./../libcseife .c.o: $(CC) -c $(CFLAGS) $< $(IFLAGS) +SNAPMERGE_OBJ = $(SNAPMERGE_SCR:%.c=%.o) SEISMERGE_SCR = seismerge.c @@ -54,7 +55,9 @@ SEISMERGE_SCR = seismerge.c SNAPMERGE_SCR = \ snapmerge.c \ merge.c \ + json_parser.c \ read_par.c \ + read_par_json.c \ readdsk.c \ writedsk.c \ util.c @@ -62,6 +65,7 @@ SNAPMERGE_SCR = \ PARTMODEL_SCR = \ part_model.c \ read_par.c \ + read_par_json.c \ util.c @@ -79,6 +83,8 @@ FDMPI_UTIL = \ rd_sour.c \ readdsk.c \ read_par.c \ + json_parser.c \ + read_par_json.c \ exchange_par.c \ receiver.c \ readmod.c \ @@ -155,7 +161,7 @@ seismerge: $(SEISMERGE_OBJ) $(CC) $(LFLAGS) $(SEISMERGE_OBJ) -o ../bin/seismerge snapmerge: $(SNAPMERGE_OBJ) - $(CC) $(LFLAGS) $(SNAPMERGE_OBJ) -o ../bin/snapmerge + $(CC) $(SFLAGS) $(SNAPMERGE_OBJ) -o ../bin/snapmerge $(LFLAGS) # part_model: $(PARTMODEL_OBJ) # $(CC) $(LFLAGS) $(PARTMODEL_OBJ) -o ../bin/partmodel diff --git a/src/fd.h b/src/fd.h index d34b37a..23836a6 100644 --- a/src/fd.h +++ b/src/fd.h @@ -40,6 +40,7 @@ #define PI (3.141592653589793) #define NPAR 45 #define STRING_SIZE 74 +#define STRING_SIZE2 256 #define REQUEST_COUNT 6 #define NPROCX_MAX 100 #define NPROCY_MAX 100 @@ -182,6 +183,8 @@ float readdsk(FILE *fp_in, int format); int read_par(FILE *fp); +void read_par_json(FILE *fp, char *fileinp); + void readmod_acoustic(float *** rho, float *** pi, int ishot); int **receiver(FILE *fp, int *ntr); @@ -309,7 +312,7 @@ float *** sxx, float *** syy, float *** szz, float *** sxy, float *** syz, float *** sxz, float *** rho, float ** srcpos_loc, float ** signals, int nsrc, float ***absorb_coeff); -void wavelet(float **srcpos_loc, int nsrc, int quelltype, float ** signals); +void wavelet(float **srcpos_loc, int nsrc, int sourceshape, float ** signals); void writebufs(float *** sxx, float *** syy, float *** szz, float *** sxy, float *** syz, float *** sxz, @@ -328,6 +331,32 @@ void writemod(char modfile[STRING_SIZE], float *** rho, int format); void writepar(FILE *fp, int ns); +/* declaration of functions for json parser in json_parser.c*/ +int read_objects_from_intputfile(FILE *fp, char input_file[STRING_SIZE],char ** varname_list,char ** value_list); + +void print_objectlist_screen(FILE *fp, int number_readobject,char ** varname_list,char ** value_list); + +int count_occure_charinstring(char stringline[STRING_SIZE], char teststring[]); + +void copy_str2str_uptochar(char string_in[STRING_SIZE], char string_out[STRING_SIZE], char teststring[]); + +int get_int_from_objectlist(char string_in[STRING_SIZE], int number_readobject, int * int_buffer, + char ** varname_list,char ** value_list); + +int get_float_from_objectlist(char string_in[STRING_SIZE], int number_readobject, float * double_buffer, + char ** varname_list,char ** value_list); + +int get_string_from_objectlist(char string_in[STRING_SIZE], int number_readobject, char string_buffer[STRING_SIZE], + char ** varname_list,char ** value_list); + +int is_string_blankspace(char string_in[STRING_SIZE]); + +void remove_blankspaces_around_string(char string_in[STRING_SIZE] ); + +void add_object_tolist(char string_name[STRING_SIZE],char string_value[STRING_SIZE], int * number_read_object, + char ** varname_list,char ** value_list ); + + /* utility functions (defined in file util.c)*/ void err(char error_text[]); void warning(char warn_text[]); diff --git a/src/globvar.h b/src/globvar.h index 5144f08..685981c 100644 --- a/src/globvar.h +++ b/src/globvar.h @@ -28,13 +28,14 @@ float DX, DY, DZ, TIME, DT, TS, PLANE_WAVE_DEPTH, PHI; float TSNAP1, TSNAP2, TSNAPINC, *FL, TAU, REC_ARRAY_DEPTH, REC_ARRAY_DIST; float XREC1, XREC2, YREC1, YREC2, ZREC1=0.0, ZREC2=0.0; float REFREC[4]={0.0, 0.0, 0.0, 0.0}, DAMPING=8.0, VPPML, FPML; -int SEISMO, NDT, NDTSHIFT, NGEOPH, SEIS_FORMAT[6], FREE_SURF, READMOD, MOD_FORMAT[6], READREC, REC_ARRAY, LOG, FDORDER, FW=0, ABS_TYPE, BLOCK; +int SEISMO, NDT, NDTSHIFT, NGEOPH, SEIS_FORMAT[6]={0, 0, 0, 0, 0, 0}, FREE_SURF, READMOD, MOD_FORMAT, READREC, REC_ARRAY, LOG, FDORDER, FW=0, ABS_TYPE, BLOCK; int NX, NY, NZ=1, NT, SOURCE_SHAPE, SOURCE_TYPE, SNAP, SNAP_FORMAT, BOUNDARY, SRCREC, SNAP_PLANE; float ALPHA, BETA; int NXG, NYG, NZG, IDX, IDY, IDZ, L=1, NX1, NX2, NY1, NY2, NZ1, NZ2, DRX, DRY, RUN_MULTIPLE_SHOTS, FDCOEFF; char SNAP_FILE[STRING_SIZE], SOURCE_FILE[STRING_SIZE], SIGNAL_FILE[STRING_SIZE], INV_FILE[STRING_SIZE]; char MFILE[STRING_SIZE], REC_FILE[STRING_SIZE]; char SEIS_FILE[STRING_SIZE],MOD_FILE[STRING_SIZE]; +int VERBOSE; FILE *FP=NULL; FILE *FI=NULL; @@ -49,7 +50,7 @@ const int TAG1=1,TAG2=2, TAG3=3, TAG4=4, TAG5=5,TAG6=6; float FC,AMP, REFSRC[3], SRC_DT, SRCTSHIFT; -int SRC_MF, SIGNAL_FORMAT[6], SRCOUT_PAR[6], FSRC, JSRC, LSRC; +int SRC_MF, SIGNAL_FORMAT, SRCOUT_PAR[6], FSRC, JSRC, LSRC; char SRCOUT_FILE[STRING_SIZE]; int METHOD; diff --git a/src/ifos3d.c b/src/ifos3d.c index 4143bbf..fdacb85 100644 --- a/src/ifos3d.c +++ b/src/ifos3d.c @@ -127,9 +127,19 @@ int main(int argc, char **argv){ fprintf(stderr," Caution: input parameter filename set to default 'ifos3d.inp'. \n\n"); } FP=fopen(FILEINP,"r"); - read_par(FP); + + if (strstr(FILEINP,".json")) { + //read json formated input file + read_par_json(stdout, FILEINP); + fclose(FP); + } else { + //read "old" input file *.inp, might not work in future + read_par(FP); + } + } - + + /* PE 0 will broadcast the parameters to all others PEs */ exchange_par(); @@ -554,19 +564,11 @@ MPI_Barrier(MPI_COMM_WORLD); /* Reading source positions from SOURCE_FILE */ fprintf(FP,"\n ------------------ READING SOURCE PARAMETERS ------------------- \n"); - if ((PLANE_WAVE_DEPTH>0)) { - /*determining the number of sources in the specified plane normal/tilted to the surface/upper model boundary*/ - nsrc=(NXG-2*FW+1)*(NYG-2*FW+1); - /*fprintf(FP,"\n nsrc= %i with NGX=%i, NYG=%i and FW=%i. \n",nsrc,NXG,NYG,FW);*/ - MPI_Barrier(MPI_COMM_WORLD); - MPI_Bcast(&nsrc,1,MPI_INT,0,MPI_COMM_WORLD); - srcpos= fmatrix(1,7,1,nsrc); - pwsources(&nsrc,srcpos); - } - else { + if (MYID==0) switch (SRCREC) { case 0: - fprintf(FP,"\n Reading source parameters specified in input file instead of source file. \n");break; + if (MYID==0) err("SRCREC parameter is invalid (SRCREC!=1)! No source parameters specified!"); + break; case 1: fprintf(FP,"\n Reading source parameters from file: %s (IFOS source format)\n",SOURCE_FILE); if ((fpsrc=fopen(SOURCE_FILE,"r"))==NULL) err(" Source file could not be opened !"); @@ -581,10 +583,20 @@ MPI_Barrier(MPI_COMM_WORLD); if ((nsrc)==0) fprintf(FP,"\n WARNING: Could not determine number of sources parameter sets in input file. Assuming %d.\n",(nsrc=0)); else fprintf(FP," Number of source positions specified in %s : %d \n",SOURCE_FILE,nsrc); break; - case 2: break; - case 3: fprintf(FP,"\n Reading source parameters from file: %s\n",SOURCE_FILE); - break; - default: fprintf(FP,"\n WARNING: Format of source file %s unknown! Using default parameters instead of source file. \n",SOURCE_FILE); + case 2: if ((PLANE_WAVE_DEPTH>0)) { + /*determining the number of sources in the specified plane normal/tilted to the surface/upper model boundary*/ + nsrc=(NXG-2*FW+1)*(NYG-2*FW+1); + /*fprintf(FP,"\n nsrc= %i with NGX=%i, NYG=%i and FW=%i. \n",nsrc,NXG,NYG,FW);*/ + MPI_Barrier(MPI_COMM_WORLD); + MPI_Bcast(&nsrc,1,MPI_INT,0,MPI_COMM_WORLD); + srcpos= fmatrix(1,7,1,nsrc); + pwsources(&nsrc,srcpos); + } else { + err("SRCREC parameter specifies PLANE_WAVE excitation, but PLANE_WAVE_DEPTH<=0!"); + } + break; + + default: err("SRCREC parameter is invalid (SRCREC!=1 or SRCREC!=2)! No source parameters specified!"); } MPI_Bcast(&nsrc,1,MPI_INT,0,MPI_COMM_WORLD); @@ -593,7 +605,7 @@ MPI_Barrier(MPI_COMM_WORLD); sources(fpsrc,&nsrc,srcpos); /*originally, SOURCE_TYPE (stype) is defined in the source file, if not, SOURCE_TYPE is taken from the input file */ /*if (stype==NULL) printf("PE%d: Source type(s) undefined?! \n",MYID);*/ - } + snum_loc = ivector(1,nsrc); srcpos_loc = splitsrc(srcpos,&nsrc_loc, nsrc,snum_loc); diff --git a/src/json_parser.c b/src/json_parser.c new file mode 100644 index 0000000..5c4626b --- /dev/null +++ b/src/json_parser.c @@ -0,0 +1,463 @@ +/*----------------------------------------------------------------------------------------- + * 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 + * + */ + +#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 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; +} + +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; +} + +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). + -----------------------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------ + * program IFOS, reading input-parameters from input-file or stdin + * ----------------------------------------------------------------------*/ + +#include +#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); + fprintf(fp,"\nFrom input file %s, %i objects have been read in. \n",fileinp, number_readobjects); + + /* print objects to screen */ + fprintf(fp, "\n==========================================================="); + fprintf(fp, "\n= List of Parameters read by the built in Json Parser ="); + 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 + =================================*/ + fprintf(fp,"The following default values are set:\n"); + fprintf(fp,"=====================================\n\n"); + + + if (get_int_from_objectlist("SOURCE_SHAPE",number_readobjects,&SOURCE_SHAPE,varname_list, value_list)) { + err("Variable SOURCE_SHAPE could not be retrieved from the json input file!"); + } + + else { + if (SOURCE_SHAPE==3) { + if (get_string_from_objectlist("SIGNAL_FILE",number_readobjects,SIGNAL_FILE,varname_list, value_list)) { + err("Variable SIGNAL_FILE could not be retrieved from the json input file!"); + + } else { + if (get_int_from_objectlist("SIGNAL_FORMAT",number_readobjects,&SIGNAL_FORMAT,varname_list, value_list)) { + + } + } + } + } + + if (get_int_from_objectlist("SOURCE_TYPE",number_readobjects,&SOURCE_TYPE,varname_list, value_list)) { + err("Variable SOURCE_TYPE could not be retrieved from the json input file!"); + } + + else { + if (SOURCE_TYPE==5) { + if (get_float_from_objectlist("ALPHA",number_readobjects,&ALPHA,varname_list, value_list)) { + err("Variable ALPHA could not be retrieved from the json input file!"); + } + + if (get_float_from_objectlist("BETA",number_readobjects,&BETA,varname_list, value_list)) { + err("Variable BETA could not be retrieved from the json input file!"); + } + } + + } + + if (get_int_from_objectlist("SRCREC",number_readobjects,&SRCREC,varname_list, value_list)) { + err("Variable SRCREC could not be retrieved from the json input file!"); + + } else { + if (get_int_from_objectlist("SRC_MF",number_readobjects,&SRC_MF,varname_list, value_list)) { + SRC_MF=0; + } + + if (get_float_from_objectlist("REFSRC0",number_readobjects,&REFSRC[0],varname_list, value_list)) { + REFSRC[0]=0.0; + } + + if (get_float_from_objectlist("REFSRC1",number_readobjects,&REFSRC[1],varname_list, value_list)) { + REFSRC[1]=0.0; + } + + if (get_float_from_objectlist("REFSRC2",number_readobjects,&REFSRC[2],varname_list, value_list)) { + REFSRC[2]=0.0; + } + + + if (SRCREC==1) { + if (get_string_from_objectlist("SOURCE_FILE",number_readobjects,SOURCE_FILE,varname_list, value_list)) { + err("Variable SOURCE_FILE could not be retrieved from the json input file!"); + } + + if (get_int_from_objectlist("RUN_MULTIPLE_SHOTS",number_readobjects,&RUN_MULTIPLE_SHOTS,varname_list, value_list)) { + err("Variable RUN_MULTIPLE_SHOTS could not be retrieved from the json input file!"); + + } 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)) { + err("Variable PLANE_WAVE_DEPTH could not be retrieved from the json input file!"); + + } 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)) { + VERBOSE=0; + 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; + fprintf(fp,"Variable L is set to default value %d.\n",L); + + } 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; + } + + 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!"); + } + + } + + /*================================= + 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)) { + err("Variable BOUNDARY could not be retrieved from the json input file!"); + } + + 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)) { + SNAP=0; + fprintf(fp,"Variable SNAP is set to default value %d.\n",SNAP); + + } 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; + fprintf(fp,"Variable IDX is set to default value %d.\n",IDX); + } + + if (get_int_from_objectlist("IDZ",number_readobjects,&IDY,varname_list, value_list)) { + IDY=1; + fprintf(fp,"Variable IDY is set to default value %d.\n",IDY); + } + + if (get_int_from_objectlist("IDY",number_readobjects,&IDZ,varname_list, value_list)) { + IDY=1; + fprintf(fp,"Variable IDZ is set to default value %d.\n",IDY); + } + + /*================================= + 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_float_from_objectlist("REFRECX",number_readobjects,&REFREC[1],varname_list, value_list)) { + err("Variable REFRECX could not be retrieved from the json input file!"); + } + + 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!"); + } + + 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!"); + } + + 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 { + if (READREC==0) { + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + + 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!"); + } + + } else { + 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!"); + } + } + } + + 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!"); + + } else { + if (REC_ARRAY>0) { + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + + } + } + + /* --------output ---------- + *------------------------*/ + + if (get_int_from_objectlist("NDT",number_readobjects,&NDT,varname_list, value_list)) { + NDT=1; + fprintf(fp,"Variable NDT is set to default value %d.\n",NDT); + } + + if (get_int_from_objectlist("NDTSHIFT",number_readobjects,&NDTSHIFT,varname_list, value_list)) { + NDTSHIFT=0; + fprintf(fp,"Variable NDTSHIFT is set to default value %d.\n",NDT); + } + + 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; + } + } + + + + } + } + + 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 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + /*================================= + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + + + /*================================= + section Steplength estimation + Gradient preconditioning + =================================*/ + + 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!"); + } + + 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!"); + } + + 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 + =================================*/ + + 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!"); + } + + 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!"); + } + + 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!"); + } + + 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!"); + } + + + } /* end if (METHOD==1) */ + + else {/* only forward modeling is applied */ + + ITMIN=1; + fprintf(fp,"Variable ITMIN is set to default value %d.\n",ITMIN); + ITMAX=1; + fprintf(fp,"Variable ITMAX is set to default value %d.\n",ITMAX); + + } + + } + + fprintf(fp,"\nEnd of setting default values\n"); + fprintf(fp,"=====================================\n\n"); + + + /********************************************/ + /* 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 */ + if (READREC) { + 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: \n"); + err(errormessage); + } + + + } /* End of if(MYID==0) */ +} + diff --git a/src/saveseis.c b/src/saveseis.c index f81ca67..ee25602 100644 --- a/src/saveseis.c +++ b/src/saveseis.c @@ -48,6 +48,7 @@ int **recpos, int **recpos_loc, int ntr, float ** srcpos, int ishot,int ns, in case 3: sprintf(file_ext,"bin"); break; case 4: sprintf(file_ext,"sgy"); break; case 5: sprintf(file_ext,"sgy"); break; + case 7: sprintf(file_ext,"su"); break; } /*note that internally "y" is used for the vertical coordinate, for usability reasons, we switch the "y" and "z" coordinate diff --git a/src/snapmerge.c b/src/snapmerge.c index 9e55c87..bb06cdb 100644 --- a/src/snapmerge.c +++ b/src/snapmerge.c @@ -2,76 +2,103 @@ * 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 + * along with IFOS3D. See file COPYING and/or * . --------------------------------------------------------------------------*/ /*------------------------------------------------------------------------ - * loop over snapshotfiles which have to be merged. + * loop over snapshotfiles which have to be merged. * ----------------------------------------------------------------------*/ #include "fd.h" #include "globvar.h" /* definition of global variables */ -int main(int argc, char **argv){ - -int nsnap; -/* read parameters from parameter-file (stdin) */ -read_par(stdin); - - - -NXG=NX; -NYG=NY; -NZG=NZ; -NX = NXG/NPROCX; -NY = NYG/NPROCY; -NZ = NZG/NPROCZ; - -nsnap=1+iround((TSNAP2-TSNAP1)/TSNAPINC); - -FP=stdout; - - switch(SNAP){ - case 1 : /*particle velocity*/ - - merge(nsnap,1); - merge(nsnap,2); - merge(nsnap,3); - break; - case 2 : /*pressure */ - merge(nsnap,6); - break; - case 4 : /*particle velocity*/ - merge(nsnap,1); - merge(nsnap,2); - merge(nsnap,3); - case 3 :/*curl and divergence energy*/ - merge(nsnap,4); - merge(nsnap,5); - break; - case 5 :/*Gradient/Model*/ - merge(0,7); - merge(0,8); - merge(0,9); - break; - default : - warning(" snapmerge: cannot identify content of snapshot !"); - break; - - } -return 0; +int main(int argc, char **argv) { + + int nsnap; + char *fileinp=""; + //FILE *FP; + fileinp = argv[1]; + + + if ((FP=fopen(fileinp,"r"))==NULL) { + err(" Opening input file failed."); + + } else { + printf(" Opening input file was successful.\n\n"); + } + + /* read parameters from parameter-file */ + + if (strstr(fileinp,".json")) { + //read json formated input file + read_par_json(stdout, fileinp); + fclose(FP); + + } else { + //read "old" input file *.inp, might not work in future + read_par(FP); + } + + + + NXG=NX; + NYG=NY; + NZG=NZ; + NX = NXG/NPROCX; + NY = NYG/NPROCY; + NZ = NZG/NPROCZ; + + nsnap=1+iround((TSNAP2-TSNAP1)/TSNAPINC); + + FP=stdout; + + switch (SNAP) { + case 1 : /*particle velocity*/ + + merge(nsnap,1); + merge(nsnap,2); + merge(nsnap,3); + break; + + case 2 : /*pressure */ + merge(nsnap,6); + break; + + case 4 : /*particle velocity*/ + merge(nsnap,1); + merge(nsnap,2); + merge(nsnap,3); + + case 3 :/*curl and divergence energy*/ + merge(nsnap,4); + merge(nsnap,5); + break; + + case 5 :/*Gradient/Model*/ + merge(0,7); + merge(0,8); + merge(0,9); + break; + + default : + warning(" snapmerge: cannot identify content of snapshot !"); + break; + + } + + return 0; } -- GitLab