├── MCM_rmspace.m ├── PS-OKINV_ParamaterFile.txt ├── README.inp ├── README.md ├── StrainToStress.m ├── angle2dcm.m ├── batch_checkbox.m ├── batch_checkerboard.m ├── batch_dsmmc.m ├── batch_dsmmc_ys_t047.m ├── batch_joint_inversion.m ├── batch_optimal_dips.m ├── batch_pcode.m ├── batch_plot4optimalALPHA.m ├── batch_shift.m ├── batch_sim_psokinv.m ├── batch_trace2distmodel.m ├── cgls_bvls.m ├── conv_package.m ├── deg2utm.m ├── do_quadtree.m ├── edit_quadtree.m ├── eqs_rotaxs.m ├── fixmodel_fpara2patch.m ├── fixmodel_smoothoper.m ├── fminsearch_band3.m ├── ge_parse_pairs.m ├── geo2okada3d.m ├── geo2okada3d_test.m ├── get1mdem.m ├── hillshade.m ├── ll2utm.m ├── loaddb.m ├── main_merest.m ├── main_sim.m ├── main_simualtion_points.m ├── main_smest.m ├── map_afault.m ├── map_default.m ├── modelwt.m ├── modification.log ├── mogi_v_obj.m ├── mohr2d.m ├── multiTRIdis.m ├── multiTRIstrain.m ├── mycolor.mat ├── oksar2gmt.m ├── peakdet.m ├── polygon_area.m ├── process_quadtree.m ├── ps_batchinversion.m ├── ps_bestdipstrike.m ├── ps_dsm.m ├── ps_forward.m ├── ps_forword_current.asv ├── ps_forword_current.m ├── ps_forword_fig3d.asv ├── ps_forword_fig3d.m ├── ps_forword_init.asv ├── ps_forword_init.m ├── ps_forword_read.asv ├── ps_forword_read.m ├── ps_forword_update.m ├── ps_gridsearch2para.m ├── ps_nz_bestmodel.m ├── ps_para2gmt.m ├── ps_psoksar2gmt.m ├── ps_reestwithnewweights.m ├── ps_sim.m ├── ps_simtrif.m ├── ps_simwithplotting.m ├── ps_sm2dbatch.m ├── ps_smest.m ├── ps_stat.m ├── ps_triest.m ├── pso_localv4.m ├── psokinv.m ├── psokinv_batch_log.m ├── psokinv_processing.m ├── psokinv_pscfg2input.m ├── psokinv_psokinv_create_cfg.m ├── psokinv_psokinv_from_inp2initoksar.m ├── psokinv_quickuncertainty.m ├── psokinv_simglobal.m ├── psokinvangle2dcm.m ├── psoksar2gmt.m ├── remove.m ├── rotatedata.m ├── sar_checkstdfrominpxy.m ├── sar_roi2cenp.m ├── sar_rsc2cc.m ├── sar_rsc2roi.m ├── sar_rsc2zone.m ├── sim_FUNCinvnfault.m ├── sim_FUNCinvnfault_MC.m ├── sim_FUNCinvnfault_MCv2.m ├── sim_SIM2ENVI.m ├── sim_edcmpinp.m ├── sim_edcmpinp2d.m ├── sim_edgrn.m ├── sim_edgrninp.m ├── sim_elastic2dis.m ├── sim_empirical2foc.m ├── sim_enalongstrike.m ├── sim_enu2los.m ├── sim_enu2sar.m ├── sim_envi4info.m ├── sim_eqcov.m ├── sim_est2doutput.m ├── sim_fault2form.m ├── sim_fig2d.m ├── sim_fig2d.m~ ├── sim_fig2d_v2.m ├── sim_fig3d.m ├── sim_findbnds.m ├── sim_fixfpara.m ├── sim_fixmodel2chng.m ├── sim_fixmodelconvstr.m ├── sim_fixmodelview2D.m ├── sim_fpara2Dxyz.m ├── sim_fpara2allcors.m ├── sim_fpara2azi.m ├── sim_fpara2bdconstraints.m ├── sim_fpara2bnd_xd.m ├── sim_fpara2bnds.m ├── sim_fpara2boundary.m ├── sim_fpara2cc.m ├── sim_fpara2cc4tri.m ├── sim_fpara2constraint.m ├── sim_fpara2corners.m ├── sim_fpara2coulomb.m ├── sim_fpara2cross.m ├── sim_fpara2dist.m ├── sim_fpara2dist_listric.m ├── sim_fpara2distmodel.m ├── sim_fpara2distmodel_uncertainty.m ├── sim_fpara2dshow.m ├── sim_fpara2dshow_v2.m ├── sim_fpara2envi.m ├── sim_fpara2geo.m ├── sim_fpara2geofig.m ├── sim_fpara2gmt.m ├── sim_fpara2green.m ├── sim_fpara2index.m ├── sim_fpara2index_dep.m ├── sim_fpara2lap.m ├── sim_fpara2lap_2d.m ├── sim_fpara2lap_bydist.m ├── sim_fpara2lap_updated.m ├── sim_fpara2lap_v4.m ├── sim_fpara2lap_xd.m ├── sim_fpara2lapv2.m ├── sim_fpara2lapv3.m ├── sim_fpara2lapv4.m ├── sim_fpara2llpoly.m ├── sim_fpara2moment.m ├── sim_fpara2new.m ├── sim_fpara2oksar.m ├── sim_fpara2oksar_SYN.m ├── sim_fpara2oversamplebyscale.m ├── sim_fpara2polygon.m ├── sim_fpara2profile.m ├── sim_fpara2psoksar.m ├── sim_fpara2rand.m ├── sim_fpara2rand_UP.m ├── sim_fpara2rough.m ├── sim_fpara2roughness.m ├── sim_fpara2seamlesspoly.m ├── sim_fpara2simp.m ├── sim_fpara2sort.m ├── sim_fpara2sort_fixmodel.m ├── sim_fpara2sortv2.m ├── sim_fpara2sortv3.m ├── sim_fpara2topcenter.m ├── sim_fpara2tri.m ├── sim_fpara2tris.m ├── sim_fpara2vol.m ├── sim_fpara2whole.m ├── sim_fpara2xyz.m ├── sim_fpara4G.m ├── sim_fpara4G.m~ ├── sim_fpara4auxi.m ├── sim_fpara4col3d.m ├── sim_fpara4los.m ├── sim_fpara_ll2utm.m ├── sim_fparaboundaries.m ├── sim_fparaconv.m ├── sim_fparaontoanother.m ├── sim_fparashiftcentraldepth.m ├── sim_fparastd.m ├── sim_gaussianfit.m ├── sim_getGMTpatch.m ├── sim_getdsmcfg.m ├── sim_getfileinfo.m ├── sim_getinps.m ├── sim_getrev2.asv ├── sim_getrev2.m ├── sim_getsimcfg.m ├── sim_getslipmodel.m ├── sim_getsmcfg.m ├── sim_gfpara.m ├── sim_green4lapweight.m ├── sim_greentransform.m ├── sim_indgestslip.m ├── sim_infovarmag.m ├── sim_infpara.m ├── sim_inp2cm.m ├── sim_inp2cov.m ├── sim_inp2cov_sub.m ├── sim_inp2pert_byauto.m ├── sim_inp2size.m ├── sim_inp2uzone.m ├── sim_inp2weight.m ├── sim_inpboxsize4weighting.m ├── sim_inpdir2cfg.m ├── sim_inpgetcov.m ├── sim_inpndk.m ├── sim_inpoutput.m ├── sim_inps2cfg.m ├── sim_inpsrtm.m ├── sim_inpumt2ll.m ├── sim_input2li.m ├── sim_input2liv2.m ├── sim_input2outfile.m ├── sim_inputdata.m ├── sim_inputdsm.m ├── sim_inputm2ll.m ├── sim_inputrms.m ├── sim_invconfig.m ├── sim_invnfault.m ├── sim_iplot2.m ├── sim_iplot3.m ├── sim_laps2lap.m ├── sim_line2azi.m ├── sim_listfuncs.m ├── sim_ll2xy.m ├── sim_ll2xyz.m ├── sim_look.m ├── sim_lsq.m ├── sim_mC2COV.m ├── sim_mG2G.m ├── sim_mL2L.m ├── sim_mPS2bnd.m ├── sim_mapfpara.m ├── sim_mat2en.m ├── sim_mat2spread.m ├── sim_mcDTnoise.m ├── sim_mcest2slipmodel.m ├── sim_mcshow.m ├── sim_merest.m ├── sim_mergin.m ├── sim_merstat.m ├── sim_mindist.m ├── sim_mindistv2.m ├── sim_mkdist_model.m ├── sim_mo2mw.m ├── sim_mw2fpara.m ├── sim_mw2length.m ├── sim_ndk2gmt.m ├── sim_ndk2meca.m ├── sim_nnls.m ├── sim_obj.m ├── sim_obj_conrake.m ├── sim_obj_conrake_BAK.m ├── sim_obj_oksar_SLIPALP.m ├── sim_obj_oksar_SLIPRAKE.m ├── sim_obj_psoksar_SLIPALP.m ├── sim_objv2.m ├── sim_okinv2res.m ├── sim_oksar2SIM.m ├── sim_oksar2horivel.m ├── sim_oksar2oversample.m ├── sim_oksar2oversamplebyscale.m ├── sim_oksar2psoksar.m ├── sim_oksar2simp.m ├── sim_oksar2utm.m ├── sim_oksar4psokinvcfg.m ├── sim_oksargreenALP.m ├── sim_oksargreenRAKE.m ├── sim_openfault.m ├── sim_optimaldipalpha.m ├── sim_ouputinp.m ├── sim_p2p.m ├── sim_para2rsc.m ├── sim_paraest.m ├── sim_passingparameters.m ├── sim_plot2d.m ├── sim_plot3d.m ├── sim_plot3d2oksar.m ├── sim_plot3dTRI.m ├── sim_polygon4faultpatches.m ├── sim_pre4smest.m ├── sim_pre4smestGRN.m ├── sim_pre4triest.m ├── sim_pre4triest_isjoint.m ├── sim_pscmp.m ├── sim_pscmp2dis.m ├── sim_pscmp2stress.m ├── sim_pscmpcfg.m ├── sim_pscmpinp.m ├── sim_pscmpinp.m.obsleted ├── sim_psokinv2re.m ├── sim_psokinv4COL.m ├── sim_psokinv4SIM.m ├── sim_psoksar2SIM.m ├── sim_psoksar2oksar.m ├── sim_psoksar4psokinvcfg.m ├── sim_psov2dataset.m ├── sim_psov2result.m ├── sim_quad2okinv.m ├── sim_quad2wt.m ├── sim_quadfunc.m ├── sim_quadsub.m ├── sim_quickshow.m ├── sim_rakelbub.m ├── sim_rbfunc.m ├── sim_rcest.m ├── sim_readconfig.m ├── sim_readdlc.m ├── sim_readedcmp.m ├── sim_readenvi.m ├── sim_readgmtlines.m ├── sim_readimg.m ├── sim_readme_on_givenfaults.m ├── sim_readroi.m ├── sim_readweights.m ├── sim_remcinpf.m ├── sim_resastat.m ├── sim_rig.m ├── sim_rmduplicate.m ├── sim_rms.m ├── sim_rmspace.m ├── sim_roi2dsmcfg.m ├── sim_roi2profile.m ├── sim_roi2rsc.m ├── sim_roi2rsc_v2.m ├── sim_roirsc.m ├── sim_rotaxs.m ├── sim_rquads.m ├── sim_rsc2envihdr.m ├── sim_sarerror.m ├── sim_senstivityfrominp.m ├── sim_shengjislip2simp.m ├── sim_shiftfpara.m ├── sim_showinpdata.m ├── sim_showoksar.m ├── sim_showperts.m ├── sim_showsimpinGEO.m ├── sim_simcfg.m ├── sim_simerror.m ├── sim_siminp.m ├── sim_simp2fpara.m ├── sim_simp2xyz.m ├── sim_simresi.m ├── sim_simulation4envi.m ├── sim_slip4depdist.m ├── sim_slipmodel2qiang.m ├── sim_slipresolution.m ├── sim_slipuncertainty.m ├── sim_sm2R.m ├── sim_sm2dgetmat.m ├── sim_sm2oksar.m ├── sim_smabic.m ├── sim_smbestpara.m ├── sim_smcfg.m ├── sim_smcfg_ii.m ├── sim_smcv.m ├── sim_smest.m ├── sim_smest_mc.m ├── sim_smestabc.m ├── sim_smestoutdata.m ├── sim_smgcv.m ├── sim_smgcvv2.m ├── sim_smgetre.m ├── sim_sminpudata.m ├── sim_smtrif.m ├── sim_sortdata4mcanalysis.m ├── sim_sortsmre.m ├── sim_stadsm.m ├── sim_strain2stress.m ├── sim_stress2coulomb.m ├── sim_strikerot.m ├── sim_subtract.m ├── sim_swarmDEN.m ├── sim_tensorrot.m ├── sim_trace2fpara.m ├── sim_trace2trif.m ├── sim_tradeoffdip.m ├── sim_tri.m ├── sim_triarea.m ├── sim_triestcfg.m ├── sim_trif2G.m ├── sim_trif2d.m ├── sim_trif2lap.m ├── sim_trif2moment.m ├── sim_trifgetre.m ├── sim_trifre.m ├── sim_trifshow.m ├── sim_trismest.m ├── sim_twolines4interaction.m ├── sim_uieditokada.m ├── sim_uieditsimp.m ├── sim_unique2d.m ├── sim_updatedweight.m ├── sim_updategeometry.m ├── sim_updatesmcfg.m ├── sim_updateweightsfile.m ├── sim_usgsslip2simp.m ├── sim_varmag.m ├── sim_volgreenALP.m ├── sim_working4obj.m ├── sim_wrap.m ├── sim_xyz2fpara.m ├── sim_xyz2input.m ├── split_test.m ├── subplot_tight.m.obs ├── triangle_angles.m ├── triangle_area.m ├── unique2d.m ├── uokadacal3d.m ├── utm2deg.m └── utm2ll.m /MCM_rmspace.m: -------------------------------------------------------------------------------- 1 | function stringout=MCM_rmspace(stringin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Purpose: 9 | % To remove all blank in a string. 10 | % The Author, Shi Yuzhen && Feng Wanpeng, IAP & IGP 11 | % Release time: 2007/05/08 12 | 13 | indspace=strfind(stringin,' '); 14 | if isempty(indspace)==1 15 | stringout=stringin; 16 | elseif isempty(indspace)==0 17 | num=size(indspace,2); 18 | if num==1 19 | stringout=[stringin(1:indspace-1),stringin(indspace+1:length(stringin))]; 20 | elseif num >1 21 | temp=stringin(1:indspace(1)-1); 22 | for i=2:num 23 | temp=[temp,stringin(indspace(i-1)+1:indspace(i)-1)]; 24 | end 25 | stringout=[temp,stringin(indspace(num)+1:length(stringin))]; 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # psokinv 2 | Geophysical Inversion Package 3 | -------------------------------------------------------------------------------- /batch_pcode.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | file = dir('*.m'); 10 | for ni = 1:numel(file) 11 | disp(file(ni).name); 12 | pcode(file(ni).name); 13 | end 14 | -------------------------------------------------------------------------------- /batch_plot4optimalALPHA.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | % An example script 4 | % plot for optimal alpha 5 | % 6 | % writtend by W. Feng, @SYSU, Guangzhou, 2022/11/17 7 | % 8 | % to make sure that the targetDIP below has been estimated in test.out. 9 | % 10 | targetDIP = 50; 11 | % 12 | data = load('test.out'); 13 | % 14 | cdata = data(data(:,1)==targetDIP,:); 15 | % 16 | % 17 | plot(cdata(:,2),cdata(:,5)./max(cdata(:,5)),'o-g'); 18 | xlabel('Smoothing factors(alpha) for dip 50d') 19 | ylabel('Variations of STD and Roughness') 20 | hold on 21 | plot(cdata(:,2),cdata(:,4)./max(cdata(:,4)),'o-b'); 22 | hold on 23 | 24 | yyaxis right 25 | plot(cdata(:,2),cdata(:,3),'-r','LineWidth',3.5); 26 | set(gca,'YColor','red'); 27 | ylabel('Log-function for optimal Alpha') 28 | legend('Normalized STD','Normalized Smoothness','OptimalAlpha'); -------------------------------------------------------------------------------- /batch_shift.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % ps_forword_init 8 | % +Usage: 9 | % get all infomation in the GUI of ps_forward. 10 | hid = findobj('tag','edt_psoksar'); 11 | ginfo.psoksar = get(hid,'String'); 12 | disp(ginfo); 13 | -------------------------------------------------------------------------------- /batch_sim_psokinv.m: -------------------------------------------------------------------------------- 1 | function ps_simwithplotting(simcfg,varargin) 2 | % 3 | % 4 | % New version for calculating simulation and residuals of Phase... 5 | % 6 | % 7 | % 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | postfix = 'Nepal1505'; 10 | % 11 | outsimfile = psokinv_simglobal(simcfg,... 12 | 'ispara',0,... 13 | 'simulation','MO',... 14 | 'outpixelsize',0.001); 15 | siminfo = sim_getsimcfg(simcfg); 16 | % 17 | for ni = 3:numel(siminfo.unwf) 18 | sar_phs2resfromenu(siminfo.unwf{ni},... 19 | outsimfile{1},... 20 | outsimfile{2},... 21 | outsimfile{3},... 22 | 'postfix', postfix,... 23 | 'gmt_minwrap', -10,... 24 | 'gmt_maxwrap', 10,... 25 | 'ininc', siminfo.incf{ni},... 26 | 'inazi', siminfo.azif{ni}); 27 | end -------------------------------------------------------------------------------- /batch_trace2distmodel.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % From Trace to create a continuous curve fault plane... 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | tra = load('data/faultTrace.inp'); 12 | % 13 | mv = mean(tra); 14 | % 15 | [~,~,zone] = deg2utm(mv(2),mv(1)); 16 | % 17 | [x,y] = deg2utm(tra(:,2),tra(:,1),'53 S'); 18 | x = x./1000; 19 | y = y./1000; 20 | rep = mean([x,y]); 21 | rep(1) = rep(1) - 100; 22 | dip = zeros(size(x))+14; 23 | wid = 240; 24 | pw = 15; 25 | pl = 15; 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 27 | [fpara,tf,mps] = sim_trace2fpara([x,y],rep,dip,wid,pw,pl); 28 | input_1 = sim_inputdata('inp/E.inp'); 29 | input_2 = sim_inputdata('inp/N.inp'); 30 | input_3 = sim_inputdata('inp/U.inp'); 31 | input = [input_1;input_2;input_3]; 32 | %input = input_3; 33 | cfpara{1} = fpara; 34 | rakecons = [1,45,135]; 35 | whichbnds{1} = {'R','L','B'}; 36 | mC{1} = diag(ones(numel(input(:,1)),1)); 37 | mPS{1} = mps; 38 | mfpara = sim_fpara2distmodel(cfpara,input,rakecons,mC,mPS,0.001,0,'cgls',whichbnds,'Japan_save_dip14.mat'); 39 | -------------------------------------------------------------------------------- /conv_package.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | %Regular the input 10 | % 11 | invf = 'wenchuan.inp'; 12 | [psoPS,insfile,symbols,outoksar,outmatf,fpara,lamda,... 13 | myu,scamin,scamax,Inv,locals] = ... 14 | sim_readconfig(invf); 15 | % 16 | mf = 'zhli_eqModel.inp'; 17 | fpara= sim_oksar2SIM(mf); 18 | %sim_fig3d(fpara,[],[],[],[],1,1); 19 | % 20 | f = sim_fparaconv(fpara(1,:),0,1); 21 | disp('Fault-1:'); 22 | [f(1) f(2) f(4) f(6)] 23 | f = sim_fparaconv(fpara(2,:),0,0); 24 | disp('Fault-2:'); 25 | [f(1) f(2) f(4) f(6)] 26 | f = sim_fparaconv(fpara(3,:),0,0); 27 | disp('Fault-3:'); 28 | [f(1) f(2) f(4) f(6)] 29 | f = sim_fparaconv(fpara(4,:),0,2); 30 | disp('Fault-4:'); 31 | [f(1) f(2) f(4) f(6)] 32 | -------------------------------------------------------------------------------- /edit_quadtree.m: -------------------------------------------------------------------------------- 1 | function decomp=edit_quadtree(decomp,editfile,imsize) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | 8 | % Allows manual editing of quadtree decompositions to eliminate 9 | % annoying patches of noise. 10 | % 11 | % gjf, 14/12/01 12 | % 13 | % genius in action (TM) 14 | 15 | % load data 16 | 17 | edit_coords=load(editfile) ; 18 | 19 | % loop through entries in 'editfile' and correct the decomp matrix 20 | 21 | for i=1:numel(edit_coords(:,1)) 22 | 23 | decomp(edit_coords(i,1):(edit_coords(i,1)+edit_coords(i,3)-1),... 24 | edit_coords(i,2):(edit_coords(i,2)+edit_coords(i,3)-1))=... 25 | zeros(edit_coords(i,3)) ; 26 | 27 | decomp(edit_coords(i,1),edit_coords(i,2))=edit_coords(i,3) ; 28 | 29 | end 30 | 31 | -------------------------------------------------------------------------------- /eqs_rotaxs.m: -------------------------------------------------------------------------------- 1 | function [cx,cy] = eqs_rotaxs(cx0,cy0,azimuth,p0) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @UoG/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com for more details 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % LOG: 10 | % Feng Wanpeng, IGP/CEA, 2009/11/23/ 11 | % added some log info 12 | 13 | if nargin < 3 14 | disp('[cx,cy] = eqs_rotaxs(cx0,cy0,azimuth,p0)'); 15 | disp(' Input:'); 16 | disp(' cx0, the x-coordinates of points'); 17 | disp(' cy0, the y-coordinates of points'); 18 | disp(' azimuth, the azimuth angle, counterclockwise is positive and east is zero '); 19 | disp(' p0, the referenced points, e.g, [x0,y0]'); 20 | disp(' if you do not give it, the center point will be used'); 21 | disp(' Output:'); 22 | disp(' cx, the roted x-coordinates along the azimuth'); 23 | disp(' cy, the roted y-coordinates along the azimuth'); 24 | % 25 | cx = []; 26 | cy = []; 27 | return 28 | end 29 | % 30 | i = sqrt(-1); 31 | pi = 3.14159265; 32 | strkr = (90-azimuth)*pi/180; 33 | % 34 | if nargin < 4 35 | x0 = 0;%min(cx0(:)); 36 | y0 = 0;%min(cy0(:)); 37 | else 38 | x0 = p0(1); 39 | y0 = p0(2); 40 | end 41 | % 42 | start = (x0+y0*i); 43 | outdata = ((cx0+cy0.*i)-start).*exp(-i*strkr); 44 | cx = real(outdata); 45 | cy = imag(outdata);% 46 | 47 | -------------------------------------------------------------------------------- /ge_parse_pairs.m: -------------------------------------------------------------------------------- 1 | function v = ge_parse_pairs(pairs) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | %% ge_parse_pairs 8 | % helper function allowing named generic name value parameter passing 9 | 10 | v = {}; 11 | 12 | for ii=1:2:length(pairs(:)) 13 | 14 | if isnumeric(pairs{ii+1}) 15 | str = [ pairs{ii} ' = [' num2str(pairs{ii+1}),'];' ]; 16 | else 17 | str = [ pairs{ii} ' = ' 39 pairs{ii+1} 39,';' ]; 18 | end 19 | %str 20 | v{(ii+1)/2,1} = str; 21 | 22 | end 23 | -------------------------------------------------------------------------------- /geo2okada3d.m: -------------------------------------------------------------------------------- 1 | function [ox,oy] = geo2okada3d(x,y,faultp) 2 | % 3 | % Managing coordiates for observations corresponding to a reference fault 4 | % Developed by Wanpeng Feng, @BJ, 2008 5 | % 6 | xfaultp = sim_fparaconv(faultp,0,3); 7 | xstart = xfaultp(1); 8 | ystart = xfaultp(2); 9 | dip = xfaultp(4); 10 | strike = xfaultp(3); 11 | % 12 | i = sqrt(-1); 13 | cc = -1*0 -i*0*cosd(dip); 14 | strkr = (90-strike)*pi/180; 15 | cc = (xstart+ystart*i)+cc.*exp(i*strkr); 16 | pokada = ((x+y.*i)-cc).*exp(-i*strkr); 17 | ox = real(pokada); 18 | oy = imag(pokada); -------------------------------------------------------------------------------- /geo2okada3d_test.m: -------------------------------------------------------------------------------- 1 | function [ox,oy] = geo2okada3d_test(x,y,faultp) 2 | % 3 | % by wanpeng feng, @NRCan, 2016-10-02 4 | % 5 | xfaultp = sim_fparaconv(faultp,0,3); 6 | xstart = xfaultp(1); 7 | ystart = xfaultp(2); 8 | dip = xfaultp(4); 9 | strike = xfaultp(3); 10 | % 11 | i = sqrt(-1); 12 | % cc = -1*0 -i*0*cosd(dip); 13 | strkr = (90-strike)*pi/180; 14 | cc = (xstart+ystart*i);%+cc.*exp(i*strkr); 15 | pokada = ((x+y.*i)-cc).*exp(-i*strkr); 16 | ox = real(pokada); 17 | oy = imag(pokada); -------------------------------------------------------------------------------- /loaddb.m: -------------------------------------------------------------------------------- 1 | function loaddb(index,opt) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % add different database by user 10 | switch opt 11 | case 'add' 12 | switch index 13 | case 'raw' 14 | p = path(); 15 | path(p,'D:\mdbase\dbase_0'); 16 | case 'psov1' 17 | p = path(); 18 | path(p,'D:\mdbase\dbase_1'); 19 | case 'psov2' 20 | p = path(); 21 | path(p,'D:\mdbase\dbase_2'); 22 | case 'stamps' 23 | p = path(); 24 | path(p,'D:\mdbase\StaMPS_v3.0.4_beta\matlab'); 25 | end 26 | case 'rm' 27 | switch index 28 | case 'raw' 29 | p = path(); 30 | rmpath('D:\mdbase\dbase_0'); 31 | case 'psov1' 32 | p = path(); 33 | rmpath('D:\mdbase\dbase_1'); 34 | case 'psov2' 35 | p = path(); 36 | rmpath('D:\mdbase\dbase_2'); 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /main_sim.m: -------------------------------------------------------------------------------- 1 | function main_sim(siminp) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | if nargin<1 || isempty(siminp)==1||exist(siminp,'file')==0 12 | disp('The SIM config file is not found...'); 13 | return 14 | end 15 | siminfo = sim_getsimcfg(siminp); 16 | if exist(siminfo.savedir,'dir')==0 17 | mkdir(siminfo.savedir); 18 | end 19 | if siminfo.numjob >0 20 | for ni=1:siminfo.numjob 21 | [pathstr, bname] = fileparts(siminfo.incf{ni}); 22 | outsim = fullfile(siminfo.savedir,... 23 | [siminfo.simpref,bname,siminfo.postfix]); 24 | outerr = fullfile(siminfo.savedir,... 25 | [siminfo.errpref,bname,siminfo.postfix]); 26 | outdif = fullfile(siminfo.savedir,... 27 | [siminfo.difpref,bname,siminfo.postfix]); 28 | if siminfo.issim(ni)==1 29 | sim_psokinv4SIM(siminfo.oksarfile,siminfo.incf{ni},siminfo.azif{ni},siminfo.models{ni},outsim,0.5,0.05); 30 | disp([outsim ' SERIES have been created!']); 31 | end 32 | if siminfo.iserr(ni)==1 33 | sim_simerror(outsim,outerr); 34 | disp([outerr ' SERIES have been created!']); 35 | end 36 | if siminfo.isdif(ni)==1 37 | sim_simresi(siminfo.unwf{ni},outsim,outerr,outdif); 38 | disp([outdif ' SERIES have been created!']); 39 | end 40 | 41 | 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /main_simualtion_points.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Simulation for Points 9 | %finf = 'brazilV2.inp'; 10 | fmat = 'result\Brazil_matfileV5_dip-50.1.mat'; 11 | dmat = load(fmat); 12 | inpf = dmat.cinput; 13 | nf = size(inpf,1); 14 | data = []; 15 | for ni = 1:nf 16 | tdata = sim_inputdata(inpf{ni}{1}); 17 | data = [data;tdata]; 18 | end 19 | % 20 | fpara = dmat.outfpara{1}; 21 | DIST = multiokadaALP(fpara,data(:,1),data(:,2),0,0.5,0); 22 | OSIM = DIST.E.*data(:,4)+DIST.N.*data(:,5)+DIST.V.*data(:,6); 23 | plot(data(:,3),'r'); 24 | hold on 25 | plot(OSIM,'b'); 26 | -------------------------------------------------------------------------------- /map_afault.m: -------------------------------------------------------------------------------- 1 | function [lon,lat] = map_afault(infile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | %+Name: 9 | % Map_afault, a maping tool to input a active fault data into the PC. 10 | %Input: 11 | % infile, the active fault file (formatted by Feng Wanpeng); 12 | %Outout: 13 | % lon, the longitude of the coordinate, in degree 14 | % lat, the latitude of the coordinate, in degree 15 | %Log: 16 | % Created by Feng Wanpeng 26/02/09,fengwp@cea-igp.ac.cn 17 | % 18 | if nargin < 1 19 | infile = 'ChinaFault.inp'; 20 | lon = []; 21 | lat = []; 22 | return 23 | end 24 | % 25 | finfo = dir(infile); 26 | ninfo = size(finfo,1); 27 | if ninfo ==0 28 | disp('Please set a corrected full data file path!'); 29 | lat = []; 30 | lon = []; 31 | return 32 | end 33 | % 34 | data = load(infile); 35 | lat = data(:,2); 36 | lon = data(:,1); 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /map_default.m: -------------------------------------------------------------------------------- 1 | demf = 'E:\work\data\imag\global_topo_1min\etop1.img'; 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | faultf = 'E:\MyWorks\map\data\ChinaFault.inp'; 8 | cityf = 'E:\MyWorks\map\data\xian.dat'; 9 | handles.data.demf = demf; 10 | handles.data.cityf = cityf; 11 | handles.data.faultf = faultf; 12 | -------------------------------------------------------------------------------- /modification.log: -------------------------------------------------------------------------------- 1 | 2009.09.09 2 | 3 | 1) Fix a bug when simulation... 4 | 2) Fix a bug when multi-VCM input... 5 | 3) -------------------------------------------------------------------------------- /mogi_v_obj.m: -------------------------------------------------------------------------------- 1 | function stdv = mogi_v_obj(x) 2 | % 3 | % 4 | % 5 | % input by Wanpeng Feng, @Ottawa, 2016-10-05 6 | % 7 | global input 8 | % 9 | x0 = x(1); 10 | y0 = x(2); 11 | z0 = x(3); 12 | radius = x(4); 13 | % 14 | [dx,dy,dz] = mogi_2d_v(input(:,1),input(:,2),x0,y0,z0,radius); 15 | simv = dx .* input(:,4) + dy .* input(:,5) + dz .* input(:,6); 16 | stdv = std(input(:,3) - simv); 17 | -------------------------------------------------------------------------------- /multiTRIdis.m: -------------------------------------------------------------------------------- 1 | function U = multiTRIdis(trif,x,y,z,pr) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % +Usage: 9 | % U = multiTRIdis(trif,x,y,z[,pr]); 10 | % +Input: 11 | % trif, the model in triangular model 12 | % x, the x coordinates of observation points in km 13 | % y, the y coordinates of observation points in km 14 | % z, the z coordinates of observation points in km 15 | % pr, the possion ration 16 | % +Output: 17 | % U, a structure saving the deformation at the points of (x,y,z) 18 | % Created by Feng, W.P, fengwp@cea-igp.ac.cn 19 | % Version 0.1, 2010-08-10, in Beijing 20 | % 21 | if nargin < 5 22 | pr = 0.25; 23 | end 24 | % 25 | U.x = zeros(size(x)); 26 | U.y = zeros(size(x)); 27 | U.z = zeros(size(x)); 28 | E = U.x; 29 | N = E; 30 | Z = E; 31 | % 32 | parfor ni=1:numel(trif) 33 | temp = CalcTriDisps( x, y, z, trif(ni).x, trif(ni).y, abs(trif(ni).z),pr,... 34 | trif(ni).ss,trif(ni).ts, trif(ni).ds); 35 | E = E + temp.x.*-1; 36 | N = N + temp.y.*-1; 37 | Z = Z + temp.z; 38 | disp(['Now the ' num2str(ni) ' TRIF model has been calculated..']); 39 | end 40 | U.x = E; 41 | U.y = N; 42 | U.z = Z; 43 | -------------------------------------------------------------------------------- /multiTRIstrain.m: -------------------------------------------------------------------------------- 1 | function [U,stress] = multiTRIstrain(trif,x,y,z,pr,lambda,mu) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % +Usage: 9 | % U = multiTRIdis(trif,x,y,z[,pr]); 10 | % +Input: 11 | % trif, the model in triangular model 12 | % x, the x coordinates of observation points in km 13 | % y, the y coordinates of observation points in km 14 | % z, the z coordinates of observation points in km 15 | % pr, the possion ration 16 | % +Output: 17 | % U, a structure saving the deformation at the points of (x,y,z) 18 | % Created by Feng, W.P, fengwp@cea-igp.ac.cn 19 | % Version 0.1, 2010-08-10, in Beijing 20 | % 21 | if nargin < 5 22 | pr = 0.25; 23 | end 24 | if nargin < 6 25 | lambda = 3.2e2; 26 | end 27 | if nargin < 7 28 | mu = lambda; 29 | end 30 | % 31 | XX = zeros(size(x(:),1),1); 32 | YY = XX; 33 | ZZ = XX; 34 | XY = XX; 35 | XZ = XX; 36 | YZ = XX; 37 | % 38 | parfor ni=1:numel(trif) 39 | temp = CalcTriStrains( x, y, z, trif(ni).x, trif(ni).y, abs(trif(ni).z),pr,... 40 | trif(ni).ss,trif(ni).ts, trif(ni).ds); 41 | XX = XX + temp.xx; 42 | YY = YY + temp.yy; 43 | ZZ = ZZ + temp.zz; 44 | XY = XY + temp.xy; 45 | XZ = XZ + temp.xz; 46 | YZ = YZ + temp.yz; 47 | end 48 | U.xx = XX; 49 | U.yy = YY; 50 | U.zz = ZZ; 51 | U.xy = XY; 52 | U.xz = XZ; 53 | U.yz = YZ; 54 | stress = StrainToStress(U, lambda, mu); 55 | stress.sxx = stress.sxx.*-1; 56 | stress.syy = stress.syy.*-1; 57 | stress.sxy = stress.sxy.*-1; 58 | stress.szz = stress.szz.*-1; 59 | %stress.yz = stress.yz; 60 | %stress.xx = stress.xx.*-1; 61 | 62 | -------------------------------------------------------------------------------- /mycolor.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpfeng/psokinv/d35532b0bc3c0d257cb9c9a3550f75fae6f788d2/mycolor.mat -------------------------------------------------------------------------------- /polygon_area.m: -------------------------------------------------------------------------------- 1 | function p_area = polygon_area(x,y) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % Get the number of vertices 8 | n = length(x); 9 | 10 | % Initialize the area 11 | p_area = 0; 12 | 13 | % Apply the formula 14 | for i = 1 : n-1 15 | p_area = p_area + (x(i) + x(i+1)) * (y(i) - y(i+1)); 16 | end 17 | p_area = abs(p_area)/2; 18 | 19 | -------------------------------------------------------------------------------- /ps_forword_current.asv: -------------------------------------------------------------------------------- 1 | % 2 | % ps_forword_current 3 | % 4 | set(ginfo.currentparaid,'String',num2str(Cfpara(ginfo.faultno,ginfo.para.no))); 5 | -------------------------------------------------------------------------------- /ps_forword_current.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % ps_forword_current 8 | % 9 | %ginfo.faultno 10 | %ginfo.para.no 11 | %Cfpara 12 | set(ginfo.currentparaid,'String',num2str(Cfpara(ginfo.faultno,ginfo.para.no))); 13 | -------------------------------------------------------------------------------- /ps_forword_fig3d.asv: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | % ps_forword_fig3d 4 | % 5 | if isempty(fig3dID)||ishandle(fig3dID)==0 6 | fig3dID = figure('Name','Fig3D'); 7 | if isempty(fig3dID)~=1 8 | ginfo.fig3dposition = get(fig3dID,'Position'); 9 | cid = get(fig3dID,'CurrentAxes'); 10 | if isempty(cid)~=1 11 | [ginfo.az,ginfo.el] = view(cid); 12 | end 13 | end 14 | else 15 | ginfo.fig3dposition = get(fig3dID,'Position'); 16 | cid = get(fig3dID,'CurrentAxes'); 17 | if isempty(cid)~=1 18 | [ginfo.az,ginfo.el] = view(cid); 19 | end 20 | delete(fig3dID); 21 | fig3dID = figure('Name','Fig3D'); 22 | set(fig3dID,G 23 | end 24 | if sum(Cfpara(:)) ~=0 25 | figure(fig3dID); 26 | sim_fig3d(Cfpara); 27 | view([ginfo.az,ginfo.el]); 28 | end -------------------------------------------------------------------------------- /ps_forword_fig3d.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % ps_forword_fig3d 9 | % 10 | if isempty(fig3dID)||ishandle(fig3dID)==0 11 | fig3dID = figure('Name','Fig3D'); 12 | if isempty(fig3dID)~=1 13 | ginfo.fig3dposition = get(fig3dID,'Position'); 14 | cid = get(fig3dID,'CurrentAxes'); 15 | if isempty(cid)~=1 16 | [ginfo.az,ginfo.el] = view(cid); 17 | end 18 | end 19 | else 20 | ginfo.fig3dposition = get(fig3dID,'Position'); 21 | cid = get(fig3dID,'CurrentAxes'); 22 | if isempty(cid)~=1 23 | [ginfo.az,ginfo.el] = view(cid); 24 | end 25 | delete(fig3dID); 26 | fig3dID = figure('Name','Fig3D'); 27 | if isempty(ginfo.fig3dposition)~=1 28 | set(fig3dID,'Position',ginfo.fig3dposition); 29 | end 30 | end 31 | if sum(Cfpara(:)) ~=0 32 | figure(fig3dID); 33 | sim_fig3d(Cfpara); 34 | view([ginfo.az,ginfo.el]); 35 | end 36 | -------------------------------------------------------------------------------- /ps_forword_init.asv: -------------------------------------------------------------------------------- 1 | % 2 | % ps_forword_init 3 | % +Usage: 4 | % get all infomation in the GUI of ps_forward. 5 | % psoksar 6 | hid = findobj('tag','edt_psoksar'); 7 | ginfo.psoksar = get(hid,'String'); 8 | ginfo.psoksarid = hid; 9 | % 10 | % inp 11 | hid = findobj('tag','edt_inp'); 12 | ginfo.inp = get(hid,'String'); 13 | % format 14 | hid = findobj('tag','list_format'); 15 | ginfo.format.no = get(hid,'value'); 16 | ginfo.format.value = get(hid,'String'); 17 | ginfo.currentformat = ginfo.format.value{ginfo.format.no}; 18 | % no fault 19 | hid = findobj('tag','list_fault_index'); 20 | ginfo.faultno = get(hid,'value'); 21 | ginfo.faultnoid = hid; 22 | % no parameter 23 | hid = findobj('tag','list_para_index'); 24 | ginfo.para.no = get(hid,'value'); 25 | ginfo.para.value = get(hid,'String'); 26 | %ginfo.currentpara = ginfo.para.value{ginfo.para.no}; 27 | % value of parameters 28 | hid = findobj('tag','edt_para_value'); 29 | ginfo.currentpara = str2double(get(hid,'String')); 30 | ginfo.currentparaid = hid; 31 | % value of parameters 32 | hid = findobj('tag','edt_step'); 33 | ginfo.step = str2double(get(hid,'String')); 34 | ginfo.stepid = hid; 35 | %%%%% 36 | ginfo.faultnum = 0; 37 | cfpara(ginfo.faultno,ginfo.para.no) = -------------------------------------------------------------------------------- /ps_forword_init.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % ps_forword_init 8 | % +Usage: 9 | % get all infomation in the GUI of ps_forward. 10 | % psoksar 11 | hid = findobj('tag','edt_psoksar'); 12 | ginfo.psoksar = get(hid,'String'); 13 | ginfo.psoksarid = hid; 14 | % 15 | % inp 16 | hid = findobj('tag','edt_inp'); 17 | ginfo.inp = get(hid,'String'); 18 | % format 19 | hid = findobj('tag','list_format'); 20 | ginfo.format.no = get(hid,'value'); 21 | ginfo.format.value = get(hid,'String'); 22 | ginfo.currentformat = ginfo.format.value{ginfo.format.no}; 23 | % no fault 24 | hid = findobj('tag','list_fault_index'); 25 | ginfo.faultno = get(hid,'value'); 26 | ginfo.faultnoid = hid; 27 | % no parameter 28 | hid = findobj('tag','list_para_index'); 29 | ginfo.para.no = get(hid,'value'); 30 | ginfo.para.value = get(hid,'String'); 31 | %ginfo.currentpara = ginfo.para.value{ginfo.para.no}; 32 | % value of parameters 33 | hid = findobj('tag','edt_para_value'); 34 | ginfo.currentpara = str2double(get(hid,'String')); 35 | ginfo.currentparaid = hid; 36 | % value of parameters 37 | hid = findobj('tag','edt_step'); 38 | ginfo.step = str2double(get(hid,'String')); 39 | ginfo.stepid = hid; 40 | %%%%% 41 | ginfo.faultnum = 0; 42 | % 43 | ginfo.az = 20; 44 | ginfo.el = 30; 45 | ginfo.fig3dposition = []; 46 | -------------------------------------------------------------------------------- /ps_forword_read.asv: -------------------------------------------------------------------------------- 1 | % 2 | % ps_forword_read 3 | % read psoksar 4 | %ginfo.currentformat 5 | switch ginfo.currentformat 6 | case 'PSOKSAR' 7 | Gfpara = sim_psoksar2SIM(ginfo.psoksar); 8 | case 'FPARA' 9 | Gfpara = load(ginfo.psoksar); 10 | case 'OKSAR' 11 | Gfpara = sim_oksar2SIM(ginfo.psoksar); 12 | end 13 | ginfo.faultnum = size(Gfpara,1); 14 | set(ginfo.faultnoid,'String',num2cell(linspace(1,ginfo.faultnum,ginfo.faultn)')); 15 | set(ginfo.currentparaid,'String',num2str(Gfpara(ginfo.faultno,ginfo.para.no))); -------------------------------------------------------------------------------- /ps_forword_read.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % ps_forword_read 8 | % read psoksar 9 | %ginfo.currentformat 10 | switch ginfo.currentformat 11 | case 'PSOKSAR' 12 | Gfpara = sim_psoksar2SIM(ginfo.psoksar); 13 | case 'FPARA' 14 | Gfpara = load(ginfo.psoksar); 15 | case 'OKSAR' 16 | Gfpara = sim_oksar2SIM(ginfo.psoksar); 17 | end 18 | Cfpara = Gfpara; 19 | ginfo.faultnum = size(Gfpara,1); 20 | ginfo.faultno = 1; 21 | set(ginfo.faultnoid,'Value',1); 22 | set(ginfo.faultnoid,'String',num2cell(linspace(1,ginfo.faultnum,ginfo.faultnum)')); 23 | set(ginfo.currentparaid,'String',num2str(Gfpara(ginfo.faultno,ginfo.para.no))); 24 | -------------------------------------------------------------------------------- /ps_forword_update.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % ps_forword_current 8 | % 9 | %ginfo.faultno 10 | %ginfo.para.no 11 | %[ginfo.faultno,ginfo.para.no] 12 | Cfpara(ginfo.faultno,ginfo.para.no) = str2double(get(ginfo.currentparaid,'String')); 13 | -------------------------------------------------------------------------------- /ps_sm2dbatch.m: -------------------------------------------------------------------------------- 1 | function ps_sm2dbatch 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | matlabpool open; 10 | % 11 | psokinv = 'PSOKINV.cfg'; 12 | smcfg = 'YS_SM.cfg'; 13 | Nofault1 = 1; 14 | Nopara1 = 1; 15 | rng1 = 230:5:300; 16 | Nofault2 = 1; 17 | Nopara2 = 2; 18 | rng2 = 3660:1:3670; 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | info = sim_getsmcfg(smcfg); 21 | [~,cfgname] = fileparts(smcfg); 22 | % 23 | [psoksardir,parname,ext1] = fileparts(info.unifmat); 24 | [~,matname] = fileparts(info.unifmat); 25 | fpara = sim_psoksar2SIM(info.unifmat); 26 | moutcfg = cell(1); 27 | counter = 0; 28 | for ni=1:numel(rng1) 29 | fpara(Nofault1,Nopara1) = rng1(ni); 30 | for nj=1:numel(rng2) 31 | counter = counter + 1; 32 | fpara(Nofault2,Nopara2) = rng2(nj); 33 | nfpara = [psoksardir,'/',parname,'.',num2str(ni),'.',num2str(nj),ext1]; 34 | sim_fpara2psoksar(fpara,nfpara); 35 | outmat = [matname,'.',num2str(ni),'.',num2str(nj),'.mat']; 36 | outcfg = [cfgname,'.',num2str(ni),'.',num2str(nj),'.cfg']; 37 | sim_smcfg(outcfg,nfpara,info.unifinp,... 38 | info.unifwid,info.uniflen,... 39 | outmat,info.unifwsize,info.uniflsize,... 40 | info.unifsmps,info.bdconts,info.minscale); 41 | %disp(['Now Begin NO:', num2str(ni),'.',num2str(nj),' linear spare solution...']); 42 | %ps_smest(outcfg); 43 | moutcfg{counter} = outcfg; 44 | end 45 | end 46 | parfor ni = 1:counter 47 | ps_smest(moutcfg{ni}); 48 | end 49 | matlabpool close; 50 | -------------------------------------------------------------------------------- /psokinv.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpfeng/psokinv/d35532b0bc3c0d257cb9c9a3550f75fae6f788d2/psokinv.m -------------------------------------------------------------------------------- /psokinv_batch_log.m: -------------------------------------------------------------------------------- 1 | function psokinv_batch_log() 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Developed by FWP,@GU, 2014-05-18 9 | % 10 | % 11 | % 12 | % 13 | %************** FWP's work ************************ 14 | %Developed by FWP, @GU/BJ, 2007-2014 15 | % contact by wanpeng.feng@hotmail.com 16 | % 17 | cm = dir('*.m'); 18 | for ni = 1:numel(cm) 19 | cfile = cm(ni).name; 20 | fidopen = fopen(cfile,'r'); 21 | fidout = fopen(['D:\mdbase\users\psokin_sav\',cfile],'w'); 22 | nl = 0; 23 | while ~feof(fidopen) 24 | nl = nl+1; 25 | tline = fgetl(fidopen); 26 | if nl == 2 27 | fprintf(fidout,'%s\n','%'); 28 | fprintf(fidout,'%s\n','%************** FWP Work ************************'); 29 | fprintf(fidout,'%s\n','%Developed by FWP, @GU/BJ, 2007-2014'); 30 | fprintf(fidout,'%s\n','% contact by wanpeng.feng@hotmail.com'); 31 | fprintf(fidout,'%s\n','%************** Good Luck ***********************'); 32 | fprintf(fidout,'%s\n',tline); 33 | else 34 | fprintf(fidout,'%s\n',tline); 35 | end 36 | end 37 | fclose(fidopen); 38 | fclose(fidout); 39 | 40 | 41 | end 42 | -------------------------------------------------------------------------------- /psokinv_psokinv_from_inp2initoksar.m: -------------------------------------------------------------------------------- 1 | function psokinv = psokinv_psokinv_from_inp2initoksar(psokinv) 2 | % 3 | % Part of UI version for PSOKINV 4 | % Created by FWP, @ BJ, 2010 5 | % 6 | inp = psokinv.inps; 7 | % 8 | if ischar(inp)==0 9 | if (isempty(psokinv.inpids)==0 && exist(inp{psokinv.inpids},'file')~=0) 10 | data = sim_inputdata(inp{psokinv.inpids}); 11 | x = [mean(data(:,1)),min(data(:,1)),max(data(:,1))]; 12 | y = [mean(data(:,2)),min(data(:,2)),max(data(:,2))]; 13 | else 14 | x = [0.5,0,99]; 15 | y = [0.5,0,1]; 16 | end 17 | else 18 | x = [0.5,0,99]; 19 | y = [0.5,0,1]; 20 | end 21 | % 22 | strike = [90,0.1,180]; 23 | dip = [45,0.5,170]; 24 | depth = [2,0.01,20]; 25 | length = [2,0.1,20]; 26 | width = [2,0.1,20]; 27 | rakes = [0,-45,45,1]; 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 29 | % 30 | psokinv.rakes(psokinv.faultid,:) = rakes; 31 | psokinv.faultintpara(psokinv.faultid,1,:) = x; 32 | psokinv.faultintpara(psokinv.faultid,2,:) = y; 33 | psokinv.faultintpara(psokinv.faultid,3,:) = strike; 34 | psokinv.faultintpara(psokinv.faultid,4,:) = dip; 35 | psokinv.faultintpara(psokinv.faultid,5,:) = depth; 36 | psokinv.faultintpara(psokinv.faultid,6,:) = width; 37 | psokinv.faultintpara(psokinv.faultid,7,:) = length; 38 | psokinv.isinv(psokinv.faultid,:) = 1; 39 | -------------------------------------------------------------------------------- /remove.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % newlist=remove(list,entry); 8 | % 9 | function newlist=remove(list,entry) 10 | newlist = list; 11 | for ni=numel(entry) 12 | newlist=newlist(find(newlist-entry(ni)*ones(size(list)))); 13 | end 14 | -------------------------------------------------------------------------------- /rotatedata.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpfeng/psokinv/d35532b0bc3c0d257cb9c9a3550f75fae6f788d2/rotatedata.m -------------------------------------------------------------------------------- /sar_roi2cenp.m: -------------------------------------------------------------------------------- 1 | function [cx,cy,zone] = sar_roi2cenp(inrsc,isupdate) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | % Created by FWP, @ GU, 2013-03-1 12 | % 13 | if nargin < 2 14 | isupdate = 2; 15 | end 16 | % 17 | info = sim_roirsc(inrsc); 18 | proj = info.projection; 19 | % 20 | % initialize the parameters 21 | cx = []; 22 | cy = []; 23 | zone = []; 24 | 25 | % 26 | disp(' sar_roi2cenp: '); 27 | if isempty(strfind(upper(proj),'UTM')) 28 | % 29 | % 30 | wid = info.width; 31 | len = info.file_length; 32 | xstep = info.x_step; 33 | ystep = info.y_step; 34 | xfir = info.x_first; 35 | yfir = info.y_first; 36 | cx = xfir + wid/2 * xstep; 37 | cy = yfir + len/2 * ystep; 38 | % 39 | [~,~,zone] = deg2utm(cy,cx); 40 | % 41 | fprintf('[lon, lat] at the centre of the image: %10.7f %10.7f %s\n', cx,cy,zone); 42 | else 43 | % 44 | disp(' The projection of the image has been in UTM.'); 45 | disp(' The processing will quite without any operation.'); 46 | return 47 | end 48 | % 49 | if isupdate == 1 50 | info.utmzone = MCM_rmspace(zone); 51 | sim_croirsc(inrsc,info); 52 | % 53 | end 54 | -------------------------------------------------------------------------------- /sar_rsc2cc.m: -------------------------------------------------------------------------------- 1 | function [cx,cy] = sar_rsc2cc(inrsc) 2 | % 3 | % 4 | % To return lonlat at center of an image which has a rsc file 5 | % by wanpeng feng, @Ottawa, 2017-04-14 6 | % 7 | cx = []; 8 | cy = []; 9 | % 10 | info = sim_roirsc(inrsc); 11 | fwid = info.width; 12 | flength = info.file_length; 13 | cx = info.x_first + fwid/2 * info.x_step; 14 | cy = info.y_first + flength / 2 * info.y_step; -------------------------------------------------------------------------------- /sar_rsc2roi.m: -------------------------------------------------------------------------------- 1 | function [roi,roip,nwid,nlen] = sar_rsc2roi(rscfile) 2 | 3 | % + Purpose: 4 | % return the file region, the file has rsc header file... 5 | % + Input: 6 | % rscfile, the rscfile is header info of image data file... 7 | % + Output: 8 | % roi, [minx,maxx,miny,maxy] 9 | % + Log: 10 | % Created by Feng, W.P, 20110510, @ BJ 11 | % 12 | % 13 | % 14 | if exist(rscfile,'file')~=0 15 | info = sim_roirsc(rscfile); 16 | % 17 | nwid = info.width;%ceil((roi(2)-roi(1))/info.x_step); 18 | nlen = info.file_length;%ceil((roi(4)-roi(3))/abs(info.y_step)); 19 | % 20 | % 21 | roi = [info.x_first, info.x_step*(info.width-1)+info.x_first,... 22 | info.y_first-abs(info.y_step)*(info.file_length-1),info.y_first,nwid,nlen]; 23 | roip = [roi(1),roi(3); 24 | roi(1),roi(4); 25 | roi(2),roi(4); 26 | roi(2),roi(3); 27 | roi(1),roi(3)]; 28 | else 29 | disp([rscfile, ' is not existing. Please check the file...']); 30 | roi = []; 31 | roip = []; 32 | nwid = []; 33 | nlen = []; 34 | end 35 | -------------------------------------------------------------------------------- /sar_rsc2zone.m: -------------------------------------------------------------------------------- 1 | function [zone,x0,y0] = sar_rsc2zone(rsc) 2 | % 3 | % 4 | % 5 | % Return UTm zone number for a ROI_PAC image 6 | % by Wanpeng Feng, @Ottawa, 2016-11-12 7 | % 8 | info = sim_roirsc(rsc); 9 | maxlon = info.x_first + (info.width-1)*info.x_step; 10 | minlat = info.y_first + (info.file_length-1)*info.y_step; 11 | [x0,y0,zone] = deg2utm((minlat+info.y_first)/2,(maxlon+info.x_first)/2); 12 | zone = MCM_rmspace(zone); 13 | % -------------------------------------------------------------------------------- /sim_edgrn.m: -------------------------------------------------------------------------------- 1 | function sim_edgrn(edgrninp) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % edgrn inp 9 | % Modified by FWP, @ GU, 2013-05-14 10 | % 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | % if nargin < 1 13 | % layermodel = []; 14 | % end 15 | % if nargin < 2 16 | % obsdepth = 0; 17 | % end 18 | if exist('edgrnfcts','dir')==0 19 | mkdir('edgrnfcts'); 20 | end 21 | %sim_edgrninp('EDGRN06.inp',layermodel,obsdepth); 22 | dos(['echo ' edgrninp,' | edgrn2']); 23 | % 24 | -------------------------------------------------------------------------------- /sim_elastic2dis.m: -------------------------------------------------------------------------------- 1 | function outdata = sim_elastic2dis(oksar,data,varargin) 2 | % 3 | % Predict surface displacements associated with a fault slip model in a 4 | % half-space earth model 5 | % 6 | % oksar, a slip model in SIMP or OKSAR format 7 | % data, a N x 7 data matrix which including los change (3rd), e/n/u 8 | % projection vectors, (4th, 5th and 6th) 9 | % Developed by Feng, Wanpeng @ Ottawa, 2015-10-12 10 | % 11 | alpha = 0.5; 12 | % 13 | for ni = 1:2:numel(varargin) 14 | % 15 | par = varargin{ni}; 16 | val = varargin{ni+1}; 17 | eval([par,'=val;']); 18 | end 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | [t_tmp,t_mp,bext] = fileparts(oksar); 21 | % 22 | switch upper(bext) 23 | % 24 | case '.OKSAR' 25 | fpara = sim_oksar2SIM(oksar); 26 | case '.SIMP' 27 | fpara = sim_simp2fpara(oksar); 28 | end 29 | % 30 | dis = multiokadaALP(fpara,data(:,1),data(:,2),0,alpha); 31 | sim = dis.E.*data(:,4) + dis.N.*data(:,5) + dis.V.*data(:,6); 32 | outdata = [data(:,1:2),sim,dis.E,dis.N,dis.V]; -------------------------------------------------------------------------------- /sim_empirical2foc.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_empirical2foc(mag,type) 2 | % 3 | % 4 | % Reference: 5 | % Wells, D. L. & Coppersmith, K. J. New Empirical Relationships among Magnitude, 6 | % Rupture Length, Rupture Width, Rupture Area, And Surface Displacement. 7 | % Bull. Seism. Soc. Am. 84, 974-1002 (1994). 8 | % Based on a given magnitude, return an emperical fault model... 9 | % by Feng, W.P., @ IGP, 2015-09-01 10 | % 11 | mu = 3.23e10; 12 | % 13 | switch upper(type) 14 | case 'SS' 15 | % 16 | rld = 10.^(-2.57+0.62.*mag); 17 | rw = 10.^(-0.76+0.27.*mag); 18 | % 19 | sa = rw.*rld.*10^6; 20 | ss = sim_mag2moment(mag)./mu./sa; 21 | % 22 | fpara = [rw.*0,rw.*0,rw.*0,rw.*0+90,rw.*0,rw,rld,ss,ss.*0,ss.*0]; 23 | % 24 | case 'R' 25 | case 'N' 26 | end 27 | % 28 | -------------------------------------------------------------------------------- /sim_enu2sar.m: -------------------------------------------------------------------------------- 1 | function [simdis,simphs] = sim_enu2sar(e,n,u,azi,inc,model,lambda) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Created by Feng, W.P., @ GU, 2012/02/05 11 | % Reference paper: 12 | % Fialko, Y., Simons, M. & Agnew, D. 13 | % The complete (3-D) surface displacement field in the epicentral area of the 1999 Mw7.1 Hector Mine earthquake, California, from space geodetic observations. Geophysical Research Letters 28, 3063-3066 (2001). 14 | % 15 | % 16 | if nargin < 6 || isempty(model) 17 | model = 'los'; 18 | end 19 | if nargin < 7 20 | lambda = 0.2323; 21 | end 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | switch upper(model) 24 | case 'LOS' 25 | ve = -1.*cosd(azi).*sind(inc); 26 | vn = sind(azi).*sind(inc); 27 | vu = cosd(inc); 28 | case 'AZI' 29 | ve = sind(azi); 30 | vn = cosd(azi); 31 | vu = 0; 32 | end 33 | % 34 | simdis = e.*ve + n.*vn + u.*vu; 35 | simphs = simdis.*(4*pi)./(-1*lambda); 36 | -------------------------------------------------------------------------------- /sim_envi4info.m: -------------------------------------------------------------------------------- 1 | function mapinfo = sim_envi4info(hdr) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | fid = fopen(hdr,'r'); 11 | % 12 | mapinfo = []; 13 | % 14 | while feof(fid)~=1 15 | tlines = fgetl(fid); 16 | index = findstr(tlines,'map info'); 17 | if isempty(index)~=1 18 | mapinfo = tlines; 19 | return 20 | end 21 | end 22 | fclose(fid); 23 | -------------------------------------------------------------------------------- /sim_eqcov.m: -------------------------------------------------------------------------------- 1 | function out = sim_eqcov(inp,type) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % inp, a input value 9 | % type, two choices: moment, the size of earthquake in terms of energy 10 | % released; 11 | % magnitude scale, like mw, another type for earthquake 12 | % size; 13 | % there is following formulation for the relation between moment and mw. 14 | % mw = (2/3)*log10(moment)-6.033; 15 | % the type will tell that fuction should return which value. 16 | % & & % % $ $ & & 17 | % Created by Feng Wanpeng, 2010-03-18 18 | % 19 | if nargin<2 20 | type = 'mw'; 21 | end 22 | switch type 23 | case 'moment' 24 | out = 10^((inp+6.033)*3/2); 25 | case 'mw' 26 | out = (2/3)*log10(inp)-6.033; 27 | otherwise 28 | out = []; 29 | disp('You must give a proper "type": mw or moment'); 30 | return 31 | end 32 | -------------------------------------------------------------------------------- /sim_est2doutput.m: -------------------------------------------------------------------------------- 1 | function data = sim_est2doutput(index,givendir,searchmat,newweights) 2 | % 3 | % 4 | % Developed by Feng, W.P.,@ Yj, 2015-05-27 5 | % Udpated by Feng, W.P., @ Ottawa, 2015-10-17 6 | % 7 | if nargin < 3 8 | searchmat = []; 9 | end 10 | if nargin < 4 11 | newweights = []; 12 | end 13 | % 14 | if nargin < 2 15 | givendir = pwd; 16 | end 17 | % 18 | data = []; 19 | dirs = dir('*.cfg'); 20 | % 21 | for ni = 1:numel(dirs) 22 | % 23 | cdir = dirs(ni).name; 24 | [t_mp,bdir] = fileparts(cdir); 25 | info = sim_getsmcfg(cdir); 26 | if ~isempty(searchmat) 27 | outmat = searchmat; 28 | else 29 | outmat = info.unifouts; 30 | end 31 | % 32 | cd(bdir); 33 | % 34 | if ~exist(info.unifmat,'file') 35 | % 36 | [t_mp,bname,bext] = fileparts(info.unifmat); 37 | cfile = [givendir,bname,bext]; 38 | else 39 | cfile = info.unifmat; 40 | end 41 | % disp(cfile); 42 | fpara = sim_oksar2SIM(cfile); 43 | cvalue = fpara(1,index); 44 | cdata = sim_sortsmre(outmat,0,newweights); 45 | % 46 | data = [data;cdata(:,1).*0+cvalue,cdata]; 47 | % 48 | cd .. 49 | % 50 | end 51 | % 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 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 | -------------------------------------------------------------------------------- /sim_fault2form.m: -------------------------------------------------------------------------------- 1 | function cofs = sim_fault2form(infault,type) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % +Purpose: 10 | % calculate the plane formular due to input fault parameter 11 | % +Input: 12 | % infault, the fault data 13 | % type, fpara or TRIF 14 | % +Output: 15 | % a,b,c, ax + by + cz = 1; 16 | % 17 | % Created by Feng, Wanpeng, email: wanpeng.feng@hotmail.com 18 | % 2011-03-16, in Beijing 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | % format long 21 | % pi = 3.141592653589793238; 22 | % 23 | if nargin < 2 24 | type = 'fpara'; 25 | end 26 | cofs = []; 27 | switch lower(type) 28 | case 'fpara' 29 | points = sim_fpara2allcors(infault); 30 | points(:,3) = points(:,3).*(-1); 31 | case 'trif' 32 | cx = infault.x; 33 | cy = infault.y; 34 | cz = infault.z; 35 | points = [cx(:),cy(:),cz(:)]; 36 | otherwise 37 | display(['The format of fault,' ' ' lower(format) ', can not be recognized. Please check it...']); 38 | return 39 | end 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 | % a*x + b*y + c*z = 1; 42 | D = points(:,1).*0 + 1; 43 | cofs = points\D; 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /sim_fig2d_v2.m: -------------------------------------------------------------------------------- 1 | function [X,Y,slip,offx,offy] = sim_fig2d_v2(fpara,varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % ncl is colormap, like 'jet' 9 | % lwid is the width of the quiver, arrow 10 | % acl is the color of the quiver, arrow 11 | % polygon is another region on the planet. 12 | % isquiver, a signal, 1 is true, to plot; 0 is no, don't plot. 13 | % 14 | % Revised history: 15 | % Writen by Feng W.P, at 2008-07-05 16 | % added the some documents by Feng W.P, at 2008-07-19 17 | if nargin<1 18 | disp('sim_fig2d(fpara,ncl,lwid,acl,polygon,isquiver,qlen,conWid,conCol,crange,vector)'); 19 | disp('new version: sim_fig2d(fpara,varargin);'); 20 | return 21 | end 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | load mycolor.mat 24 | ncl = mycolor; 25 | lwid = 0.8; 26 | acl = 'k'; 27 | polygon = []; 28 | isquiver = 1; 29 | qlen = 0.8; 30 | conWid = 0.7; 31 | conCol = 'r'; 32 | crange = []; 33 | vector = 0.2:0.2:10; 34 | istitile = 0; 35 | iscolor = 1; 36 | sliptype = 'syn'; 37 | isnoline = 0; 38 | xytype = 1; 39 | colorbarloc = 1; 40 | modeltype = 'fpara'; 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 42 | for ni = 1:2:numel(varargin) 43 | para = varargin{ni}; 44 | val = varargin{ni+1}; 45 | eval([para,'=',val,';']); 46 | end 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 48 | % -------------------------------------------------------------------------------- /sim_findbnds.m: -------------------------------------------------------------------------------- 1 | function bndindex = sim_findbnds(cx,cy) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | ind1 = find(cx==min(cx(:))); 10 | ind2 = find(cx==max(cy(:))); 11 | ind3 = find(cy==max(cy(:))); 12 | ind4 = find(cy==min(cy(:))); 13 | bndindex = [ind1;ind2;ind3;ind4]; 14 | bndindex = unique(bndindex); 15 | 16 | -------------------------------------------------------------------------------- /sim_fixmodel2chng.m: -------------------------------------------------------------------------------- 1 | function rfpara = sim_fixmodel2chng(fpara,nw,nl) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | tfpara = [500,500,120,85,0,nw*1,nl*1,0,0,0]; 11 | distf = sim_fpara2dist(tfpara,nw,nl,1,1); 12 | whos distf 13 | -------------------------------------------------------------------------------- /sim_fixmodelconvstr.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_fixmodelconvstr(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | for ni = 1:numel(fpara(:,1)) 10 | if fpara(ni,3) > 180 || fpara(ni,3) < 0 11 | if fpara(ni,3) < 0 12 | fpara(ni,3) = 360+fpara(ni,3); 13 | end 14 | fpara(ni,3) = fpara(ni,3) -180; 15 | fpara(ni,4) = 180 - fpara(ni,4); 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /sim_fpara2Dxyz.m: -------------------------------------------------------------------------------- 1 | function [cx,cy,cz] = sim_fpara2Dxyz(fpara,x0,y0,mode) 2 | % 3 | % 4 | for i = 1:size(fpara,1) 5 | p = sim_fpara2allcors(fpara(i,:)); 6 | cx = p(:,1); 7 | cy = p(:,2); 8 | cz = p(:,3); 9 | % 10 | cz = [cz(1:4)',cz(1)]; 11 | [cx,cy] = sim_rotaxs(cx,cy,mean(fpara(:,3)),90,x0,y0); 12 | cx = [cx(1:4)',cx(1)]; 13 | cy = [cy(1:4)',cy(1)]; 14 | cx = cx - x0; 15 | cy = cy - y0; 16 | switch lower(mode) 17 | case {'xz'} 18 | px = cx; 19 | py = cz; 20 | case {'xy'} 21 | px = cx; 22 | py = cy; 23 | case {'yz'} 24 | px = cy; 25 | py = cz; 26 | end 27 | plot(px,py,'-'); 28 | hold on 29 | end 30 | end -------------------------------------------------------------------------------- /sim_fpara2allcors.m: -------------------------------------------------------------------------------- 1 | function p = sim_fpara2allcors(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, W.P., @ BJ, 2009/11/01 9 | % 10 | [x1,y1,z1] = sim_fpara2corners(fpara,'lr'); 11 | [x2,y2,z2] = sim_fpara2corners(fpara,'ll'); 12 | [x3,y3,z3] = sim_fpara2corners(fpara,'ul'); 13 | [x4,y4,z4] = sim_fpara2corners(fpara,'ur'); 14 | [x5,y5,z5] = sim_fpara2corners(fpara,'cc'); 15 | p = [x1,y1,z1;... 16 | x2,y2,z2;... 17 | x3,y3,z3;... 18 | x4,y4,z4;... 19 | x5,y5,z5]; 20 | -------------------------------------------------------------------------------- /sim_fpara2azi.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_fpara2azi(fpara,minazi) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % + Purpose: 9 | % set the all fault model with same upper wall and footwall. 10 | % + LOG: 11 | % created by Feng, W.P 12 | % 13 | if nargin < 2 14 | minazi = 180; 15 | end 16 | fpara(fpara(:,3)<0,3) = 360+fpara(fpara(:,3)<0,3); 17 | % 18 | fpara(fpara(:,3)>minazi,4) = 180-fpara(fpara(:,3)>minazi,4); 19 | fpara(fpara(:,3)>minazi,3) = fpara(fpara(:,3)>minazi,3)-180; 20 | -------------------------------------------------------------------------------- /sim_fpara2boundary.m: -------------------------------------------------------------------------------- 1 | function outfpara = sim_fpara2boundary(fpara) 2 | % 3 | % 4 | % 5 | % 6 | % developed by Wanpeng Feng, @CCMEO, NRCan, 2016-10-26 7 | % 8 | strs = unique(fpara(:,3)); 9 | % 10 | outfpara = []; 11 | for ni = 1:numel(strs) 12 | cfpara = fpara(fpara(:,3) == strs(ni),:); 13 | depths = unique(cfpara(:,5)); 14 | for nj = 1:numel(depths) 15 | tmpfpara = cfpara(cfpara(:,5)==depths(nj),:); 16 | tmpfpara(:,8) = 0; 17 | tmpfpara(:,9) = 0; 18 | if nj == 1 19 | tmpfpara(:,8) = 1; 20 | end 21 | % 22 | if nj == numel(depths) 23 | tmpfpara(:,8) = 4; 24 | end 25 | [x,y] = eqs_rotaxs(tmpfpara(:,1),tmpfpara(:,2),mean(tmpfpara(:,3))); 26 | tmpfpara(x==min(x),8) = 2; 27 | tmpfpara(x==max(x),8) = 3; 28 | outfpara = [outfpara;tmpfpara]; 29 | end 30 | end -------------------------------------------------------------------------------- /sim_fpara2cc.m: -------------------------------------------------------------------------------- 1 | function [p1,p2] = sim_fpara2cc(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng W.P, the code will return the center of the fault plane. 9 | % 10 | p1 = []; 11 | p2 = []; 12 | for ni=1:size(fpara,1) 13 | [x1,y1,z1] = sim_fpara2corners(fpara(ni,:),'uc'); 14 | [x2,y2,z2] = sim_fpara2corners(fpara(ni,:),'cc'); 15 | [x3,y3,z3] = sim_fpara2corners(fpara(ni,:),'lc'); 16 | %points = [points;x1,y1,z1;x2,y2,z2;x3,y3,z3]; 17 | p1 = [p1;x1,y1,z1;x3,y3,z3]; 18 | p2 = [p2;x2,y2,z2]; 19 | 20 | end 21 | -------------------------------------------------------------------------------- /sim_fpara2cc4tri.m: -------------------------------------------------------------------------------- 1 | function [p1,p2] = sim_fpara2cc4tri(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng W.P, the code will return the center of the fault plane. 9 | % 10 | p1 = []; 11 | p2 = []; 12 | dipstr = fix(fpara(:,3).*100)+fix(fpara(:,4).*100); 13 | udipstr = unique(dipstr); 14 | indexes = [(1:1:size(fpara,1))' dipstr]; 15 | tfpara = fpara; 16 | for nj = 1:numel(udipstr) 17 | cindex = indexes(:,2) == udipstr(nj); 18 | fpara = tfpara(cindex==1,:); 19 | ilr = sim_fpara2sort(fpara); 20 | 21 | for ni = 1:size(fpara,1) 22 | 23 | vmod = mod((ilr(ni,1)-1)*max(ilr(:,2))+ilr(ni,2),2); 24 | maxidex = max(ilr(:,1)); 25 | if vmod == 0 && ilr(ni,1) ~= maxidex && ilr(ni,1) ~= 1 26 | fpara(ni,7) = fpara(ni,7) + fpara(ni,7)/2; 27 | end 28 | %disp(fpara(ni,7)) 29 | [x1,y1,z1] = sim_fpara2corners(fpara(ni,:),'ul'); 30 | [x2,y2,z2] = sim_fpara2corners(fpara(ni,:),'ur'); 31 | %[x3,y3,z3] = sim_fpara2corners(fpara(ni,:),'lc'); 32 | % 33 | p1 = [p1;x1,y1,z1]; 34 | p2 = [p2;x2,y2,z2]; 35 | 36 | end 37 | end 38 | %plot(p1(:,1),p1(:,3),'or'); 39 | -------------------------------------------------------------------------------- /sim_fpara2geo.m: -------------------------------------------------------------------------------- 1 | function [lon,lat] = sim_fpara2geo(fpara,zone) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Developed by FWP, @ BJ, 2010-10-01 10 | % 11 | rfpara = sim_fpara2rand_UP(fpara,20,20); 12 | [lat,lon] = utm2deg(rfpara(:,1)*1000,rfpara(:,2)*1000,zone); 13 | -------------------------------------------------------------------------------- /sim_fpara2geofig.m: -------------------------------------------------------------------------------- 1 | function sim_fpara2geofig(fpara,geopoints,varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Developed by FWP, @ GU, long long ago 10 | % 11 | if nargin < 2 12 | disp('sim_fpara2geofig(fpara,geopoints,varargin)'); 13 | return 14 | end 15 | % 16 | demfile = 'etop1.img'; 17 | dempath = 'E:\work\data\imag\global_topo_1min'; 18 | offset = 0.5; 19 | faultname = ''; 20 | faultpath = ''; 21 | edgecolor = 'none'; 22 | facealpha = 1.0; 23 | %%%%%%%%% 24 | v = sim_varmag(varargin); 25 | for j = 1:length(v) 26 | eval(v{j}); 27 | end 28 | %%%%%%%%% 29 | [X,Y,Z,cx,cy,cz,aslip] = sim_plot3d(fpara); 30 | [x0,y0,zone] = deg2utm(geopoints(2),geopoints(1)); 31 | [n,m] = size(X); 32 | for ni = 1:n 33 | for nj = 1:m 34 | [Y(ni,nj) X(ni,nj)] = utm2deg(X(ni,nj)*1000,Y(ni,nj)*1000,zone); 35 | end 36 | end 37 | xmin = min(X(:)); 38 | xmax = max(X(:)); 39 | ymin = min(Y(:)); 40 | ymax = max(Y(:)); 41 | sim_topfig('lonscale',[xmin-offset,xmax+offset],... 42 | 'latscale',[ymin-offset,ymax+offset],... 43 | 'demfile',demfile,... 44 | 'dempath',dempath,... 45 | 'faultpath',faultpath,... 46 | 'faultname',faultname); 47 | % 48 | for ni = 1:n 49 | [X(ni,:),Y(ni,:)] = m_ll2xy(X(ni,:),Y(ni,:)); 50 | end 51 | % 52 | slip = sqrt(aslip(:,1).^2+aslip(:,2).^2); 53 | hold on 54 | pid = patch(X,Y,slip'); 55 | % 56 | set(pid,'Edgecolor',edgecolor); 57 | set(pid,'FaceAlpha',facealpha); 58 | 59 | 60 | -------------------------------------------------------------------------------- /sim_fpara2green.m: -------------------------------------------------------------------------------- 1 | function [G,rakes] = sim_fpara2green(fpara,input,rakecons) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | % Created by Feng, Wanpeng, 2011-03-30 12 | % Modified by Feng,W.P., @ Glasgow, 2012-09-08 13 | % 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | if nargin < 3 16 | rakecons = [0,0,90]; 17 | end 18 | % 19 | if numel(rakecons(:,1))==1 20 | rakecons = repmat(rakecons,numel(fpara(:,1)),1); 21 | end 22 | %% 23 | ncol = numel(fpara(:,1)); 24 | G = zeros(size(input,1),ncol); 25 | %% 26 | for ni = 1:ncol 27 | cfpara = fpara(ni,:); 28 | cfpara(1,8) = cosd(rakecons(ni,2)); 29 | cfpara(1,9) = sind(rakecons(ni,2)); 30 | dis = multiokadaALP(cfpara,input(:,1),input(:,2),0); 31 | Dip1_G = dis.E.*input(:,4) + dis.N .*input(:,5) + dis.V.*input(:,6); 32 | G(:,ni) = Dip1_G(:)'; 33 | if rakecons(ni,3) ~= rakecons(ni,2) 34 | cfpara(1,8) = cosd(rakecons(ni,3)); 35 | cfpara(1,9) = sind(rakecons(ni,3)); 36 | dis = multiokadaALP(cfpara,input(:,1),input(:,2),0); 37 | Dip2_G = dis.E.* input(:,4) + dis.N .* input(:,5) + dis.V.* input(:,6); 38 | G(:,ncol + ni) = Dip2_G; 39 | end 40 | end 41 | %whos G 42 | rakes = rakecons(:,2:3); 43 | % 44 | -------------------------------------------------------------------------------- /sim_fpara2index_dep.m: -------------------------------------------------------------------------------- 1 | function index = sim_fpara2index_dep(fpara) 2 | % 3 | % 4 | % Developed by Wanpeng Feng, @NRCan 5 | % 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | deps = unique(fpara(:,5)); 8 | index = fpara(:,1:2); 9 | % 10 | 11 | for ni = 1:numel(fpara(:,1)) 12 | cdep = fpara(ni,5); 13 | inddepth = find(deps == cdep); 14 | cfpara = fpara(fpara(:,5)==cdep,:); 15 | y = cfpara(:,2); 16 | [cy,ind] = sort(y); 17 | indy = ind(cy==fpara(ni,2)); 18 | index(ni,:) = [inddepth,indy]; 19 | end -------------------------------------------------------------------------------- /sim_fpara2lap_2d.m: -------------------------------------------------------------------------------- 1 | function [slap,dlap,lap] = sim_fpara2lap_2d(fpara,xyzind) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | %contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, Wanpeng,wanpeng.feng@hotmail.com, 2010-05 9 | % Modified by FWP, @ UoG, 2013-06-17 10 | % xyzind, 1,2,5 11 | % x,y,z 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | mstr = mean(fpara(:,3)); 14 | numf = size(fpara,1); 15 | x0 = fpara(1,1); 16 | y0 = fpara(1,2); 17 | cx = fpara(:,xyzind(1));%sim_rotaxs(x0,y0,mstr,90,fpara(:,1),fpara(:,2)); 18 | cy = fpara(:,xyzind(2)); %/sind(fpara(:,4); 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | slap = zeros(numf); 21 | %dlap = slap; 22 | % 23 | for ni=1:numf 24 | adist = sqrt((cx-cx(ni)).^2+(cy-cy(ni)).^2); 25 | [rdix,ind] = sort(adist); 26 | if numel(ind)<17 27 | iend = numel(ind); 28 | else 29 | iend = 17; 30 | end 31 | % 32 | idx = ind(2:iend); 33 | rdist = rdix(2:iend); 34 | % 35 | for nj=1:iend-1 36 | slap(ni,idx(nj)) = -1./rdist(nj);%./distr(nj); 37 | end 38 | slap(ni,ni) = sum(abs(1./rdist)); 39 | end 40 | dlap = slap; 41 | % 42 | lap = [dlap dlap.*0;dlap.*0 dlap]; 43 | -------------------------------------------------------------------------------- /sim_fpara2lap_bydist.m: -------------------------------------------------------------------------------- 1 | function lap = sim_fpara2lap_bydist(fpara,smoothingmodel) 2 | % 3 | % To calculate the Laplacian matrix due to the absolute distance per two 4 | % patches... 5 | % 6 | % Created by Feng, Wanpeng, in Beijing, 2011-03-30 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | % updated by Wanpeng Feng, @CCRS/NRCan, 2017-04-24 9 | % 10 | % Updated by Wanpeng Feng, @CCRS/NRCan, 2017-09-25 11 | % to find nearest patches within the same plate. 12 | % 13 | if nargin < 2 14 | % 15 | smoothingmodel = 'XYZ'; 16 | % 17 | end 18 | % 19 | np = size(fpara,1); 20 | lap = zeros(np,np); 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | % 23 | % [t_mp,~,t_mp,Cx,Cy,Cz] = sim_plot3d(fpara); 24 | [Cx,Cy,Cz] = sim_fpara2corners(fpara,'cc'); 25 | Cx = Cx-0.01; 26 | Cy = Cy-0.01; 27 | Cz = Cz-0.01; 28 | % 29 | for ni = 1:np 30 | switch upper(smoothingmodel) 31 | case 'XYZ' 32 | dist = sqrt((Cx-Cx(ni)).^2 + ... 33 | (Cy-Cy(ni)).^2 + ... 34 | (Cz-Cz(ni)).^2); 35 | case 'XY' 36 | dist = sqrt((Cx-Cx(ni)).^2 + ... 37 | (Cy-Cy(ni)).^2); 38 | case 'XZ' 39 | dist = sqrt((Cx-Cx(ni)).^2 + ... 40 | (Cy-Cy(ni)).^2); 41 | case 'YZ' 42 | dist = sqrt((Cz-Cz(ni)).^2 + ... 43 | (Cy-Cy(ni)).^2); 44 | end 45 | [sordist,sorind] = sort(dist); 46 | negd = 1./sordist(2:9); 47 | posd = sum(negd(:)); 48 | lap(ni,ni) = posd; 49 | for nk = 2:9 50 | lap(ni,sorind(2:9)) = -1.*negd; 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /sim_fpara2lap_v4.m: -------------------------------------------------------------------------------- 1 | function [slap,dlap,lap] = sim_fpara2lap_v4(fpara,xyzindex) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, Wanpeng,skyflow2008@126.com, 2010-05 9 | % Updated by fWP, @ IGPP of SIO, UCSD, 2013-10-16 10 | % + Input: 11 | % fpara, discretized fault models n x 10 12 | % xyzindex, flag for smoothing control, n x 3 13 | % tnum = 100; 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | numf = size(fpara,1); 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | slap = zeros(numf); 18 | % 19 | cfpara = fpara; 20 | cfpara(:,8) = fpara(:,5); 21 | flag = xyzindex{1}; 22 | if flag(1)==0 || flag(1) == 1 23 | cfpara(:,9) = fpara(:,1); 24 | else 25 | cfpara(:,9) = fpara(:,2); 26 | end 27 | % 28 | for ni=1:numf 29 | % 30 | adist = sqrt((cfpara(:,8)-cfpara(ni,8)).^2+... 31 | (cfpara(:,9)-cfpara(ni,9)).^2); 32 | % 33 | [~,cindex] = sort(adist); 34 | % 35 | adist(:) = 0; 36 | adist(cindex(2:17)) = -1./16; 37 | adist(cindex(1)) = 1; 38 | slap(ni,:) = adist; 39 | end 40 | %slap = slap./(max(abs(slap(:)))); 41 | dlap = slap; 42 | lap = [slap slap.*0; ... 43 | slap.*0 dlap]; 44 | 45 | return 46 | -------------------------------------------------------------------------------- /sim_fpara2lap_xd.m: -------------------------------------------------------------------------------- 1 | function [slap,dlap,lap] = sim_fpara2lap_xd(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | %contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, Wanpeng,wanpeng.feng@hotmail.com, 2010-05 9 | % Modified by FWP, @ UoG, 2013-06-17 10 | % Updated by Wanpeng Feng, @Ottawa, 2016-10-27 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | mstr = mean(fpara(:,3)); 14 | numf = size(fpara,1); 15 | tfpara = sim_fparaconv(fpara,0,3); 16 | cx = eqs_rotaxs(tfpara(:,1),tfpara(:,2),mstr); 17 | cx = cx - min(cx(:)); 18 | cy = tfpara(:,5); 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | slap = zeros(numf); 21 | %dlap = slap; 22 | % 23 | for ni=1:numf 24 | adist = sqrt((cx-cx(ni)).^2+(cy-cy(ni)).^2); 25 | [rdix,ind] = sort(adist); 26 | if numel(ind)<17 27 | iend = numel(ind); 28 | else 29 | iend = 17; 30 | end 31 | % 32 | idx = ind(2:iend); 33 | rdist = rdix(2:iend); 34 | % 35 | for nj=1:iend-1 36 | slap(ni,idx(nj)) = -1./rdist(nj);%./distr(nj); 37 | end 38 | slap(ni,ni) = sum(abs(1./rdist)); 39 | end 40 | dlap = slap; 41 | % 42 | lap = [dlap dlap.*0;dlap.*0 dlap]; 43 | -------------------------------------------------------------------------------- /sim_fpara2lapv2.m: -------------------------------------------------------------------------------- 1 | function [slap,dlap,lap] = sim_fpara2lapv2(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, Wanpeng,skyflow2008@126.com, 2010-05 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | mstr = mean(fpara(:,3)); 12 | numf = size(fpara,1); 13 | x0 = fpara(1,1); 14 | y0 = fpara(1,2); 15 | cx = sim_rotaxs(x0,y0,mstr,90,fpara(:,1),fpara(:,2)); 16 | cy = fpara(:,5); %/sind(fpara(:,4); 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | slap = zeros(numf); 19 | dlap = slap; 20 | % 21 | for ni=1:numf 22 | adist = sqrt((cx-cx(ni)).^2+(cy-cy(ni)).^2); 23 | [sdist,ind] = sort(adist); 24 | if numel(ind)<17 25 | iend = numel(ind); 26 | else 27 | iend = 17; 28 | end 29 | idx = ind(2:iend); 30 | rdist = sqrt((fpara(ni,1)-fpara(idx,1)).^2+... 31 | (fpara(ni,2)-fpara(idx,2)).^2+... 32 | (fpara(ni,5)-fpara(idx,5)).^2); 33 | for nj=1:iend-1 34 | slap(ni,idx(nj)) = -1./rdist(nj);%./distr(nj); 35 | end 36 | slap(ni,ni) = sum(abs(1./rdist)); 37 | end 38 | dlap = slap; 39 | % 40 | lap = [dlap dlap.*0;dlap.*0 dlap]; 41 | -------------------------------------------------------------------------------- /sim_fpara2lapv3.m: -------------------------------------------------------------------------------- 1 | function [lap,distfpara] = sim_fpara2lapv3(fpara,isjoint,l,w,pl,pw) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by Feng,W.P., @BJ, 2011-09 10 | % 11 | % 12 | if isjoint <= 1 13 | distfpara = []; 14 | for ni=1:numel(fpara(:,1)) 15 | cfpara = sim_fpara2dist(fpara(ni,:),l(ni),w(ni),pl(ni),pw(ni)); 16 | distfpara = [distfpara;cfpara]; 17 | end 18 | lap = sim_fpara2lapv2(distfpara); 19 | else 20 | distfpara = []; 21 | mlap = cell(1); 22 | lapindex = zeros(2,1); 23 | lapindex(1) = 0; 24 | for ni = 1:isjoint-1 25 | cfpara = sim_fpara2dist(fpara(ni,:),l(ni),w(ni),pl(ni),pw(ni)); 26 | distfpara = [distfpara;cfpara]; 27 | mlap{ni} = sim_fpara2lapv2(cfpara); 28 | lapindex(ni+1) = size(distfpara,1); 29 | end 30 | % 31 | dist2 = []; 32 | for nj = isjoint:size(fpara,1) 33 | cfpara = sim_fpara2dist(fpara(nj,:),l(nj),w(nj),pl(nj),pw(nj)); 34 | dist2 = [dist2;cfpara]; 35 | end 36 | distfpara = [distfpara;dist2]; 37 | lapindex(ni+2) = size(distfpara,1); 38 | mlap{ni+1} = sim_fpara2lapv2(dist2); 39 | lap = zeros(lapindex(end)); 40 | for nk=1:numel(mlap) 41 | lap(lapindex(nk)+1:lapindex(nk+1),lapindex(nk)+1:lapindex(nk+1)) = ... 42 | mlap{nk}; 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /sim_fpara2new.m: -------------------------------------------------------------------------------- 1 | function rfpara = sim_fpara2new(fpara,depth) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | x0 = fpara(1); 12 | y0 = fpara(2); 13 | dip = fpara(4); 14 | strike= fpara(3); 15 | wid = depth/sind(dip); 16 | i = sqrt(-1); 17 | %rlen = 0; 18 | new = 0 - i*wid*cosd(dip); % low-left ,ul 19 | strkr = (90-strike)*pi/180; 20 | rnew = (x0+y0*i) + new*exp(i*strkr); 21 | rx = real(rnew); 22 | ry = imag(rnew); 23 | %rdep = fpara(5)+depth; 24 | rfpara= fpara; 25 | rfpara(1) = rx; 26 | rfpara(2) = ry; 27 | -------------------------------------------------------------------------------- /sim_fpara2polygon.m: -------------------------------------------------------------------------------- 1 | function polygon = sim_fpara2polygon(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | if nargin < 1 || isempty(fpara)==1 12 | disp('polygon = sim_fpara2polygon(fpara)'); 13 | return 14 | end 15 | [x1 y1] = sim_fpara2corners(fpara,'ll',[]); 16 | [x2 y2] = sim_fpara2corners(fpara,'lr',[]); 17 | [x3 y3] = sim_fpara2corners(fpara,'ur',[]); 18 | [x4 y4] = sim_fpara2corners(fpara,'ul',[]); 19 | polygon = [x1 y1;... 20 | x2 y2;... 21 | x3 y3;... 22 | x4 y4;... 23 | x1 y1]; 24 | 25 | 26 | -------------------------------------------------------------------------------- /sim_fpara2profile.m: -------------------------------------------------------------------------------- 1 | function points = sim_fpara2profile(fpara,lens,np) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | % 12 | % Created by Feng, Wanpeng, 2011-03-15 13 | if nargin < 3 14 | np = 200; 15 | end 16 | if nargin < 2 17 | lens = 50; 18 | end 19 | rfpara = sim_fpara2whole(fpara); 20 | rfpara(3) = fpara(3) + 90; 21 | rfpara(7) = lens; 22 | [x1,y1] = sim_fpara2corners(rfpara,'ul'); 23 | [x2,y2] = sim_fpara2corners(rfpara,'ur'); 24 | x = linspace(x1,x2,np); 25 | y = linspace(y1,y2,np); 26 | points = [x(:),y(:)]; 27 | 28 | -------------------------------------------------------------------------------- /sim_fpara2psoksar.m: -------------------------------------------------------------------------------- 1 | function sim_fpara2psoksar(fpara,outname) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Purpose: 11 | % output the faults' parameters in SIM formation into a file as psoksar structure 12 | % 13 | % Input: 14 | % fpara, n*10, the parameters of n faults 15 | % outname, string variable, fullpath parameters 16 | % Writen by Feng W.P, 10/04/2009 17 | % 18 | if nargin <1 || isempty(fpara)==1 19 | disp('sim_fpara2oksar(fpara,outname)'); 20 | disp('>>>>fpara, the faultmodel in SIM format'); 21 | disp('>>>>outname, output file for the psoksar format'); 22 | return 23 | end 24 | fid = fopen(outname,'w'); 25 | nf = size(fpara,1); 26 | pi = 3.14159265; 27 | for nl=1:nf 28 | [x,y] = sim_fpara2corners(fpara(nl,:),'cc','utm'); 29 | fprintf(fid,'%s \n',[num2str(x*1000,'% 20.8f') ' ' num2str(y*1000,'% 20.8f') ' --- Fault ' ... 30 | num2str(nl) ' ---']); 31 | fprintf(fid,'%s \n',[num2str(fpara(nl,3),'% 15.8f') ' ' num2str(fpara(nl,4),'% 15.8f') ' ' ... 32 | num2str(atan2(fpara(nl,9),fpara(nl,8))*180./pi,'% 15.8f') ' s d r']); 33 | fprintf(fid,'%s \n',[num2str(sqrt(fpara(nl,8)^2+fpara(nl,9)^2),'% 15.8f') ' '... 34 | num2str(fpara(nl,10),'% 15.8f') ' Slip Opening']); 35 | fprintf(fid,'%s \n',[num2str(fpara(nl,7),'% 15.8f') ' ' num2str(fpara(nl,5),'% 15.8f') ' ' ... 36 | num2str(fpara(nl,6)*sind(fpara(nl,4))+fpara(nl,5),'% 15.8f') ' len top bot']); 37 | 38 | end 39 | fclose(fid); 40 | -------------------------------------------------------------------------------- /sim_fpara2rough.m: -------------------------------------------------------------------------------- 1 | function [rough,maxr,lap] = sim_fpara2rough(fpara,depthd) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by FWP, @ UoG, 2013-04-22 10 | % 11 | if nargin < 2 || isempty(depthd)==1 12 | depthd = 50; 13 | end 14 | lap = sim_fpara2lapv2(fpara); 15 | index = find(fpara(:,5)./sind(fpara(:,4)) <=depthd); 16 | slip = [fpara(:,8);fpara(:,9)]; 17 | roug = abs([lap lap.*0;lap.*0 lap]*slip); 18 | rough = sum(roug(index)/4)/numel(roug(:)); 19 | maxr = max(roug(index)); 20 | -------------------------------------------------------------------------------- /sim_fpara2roughness.m: -------------------------------------------------------------------------------- 1 | function roughness = sim_fpara2roughness(fpara) 2 | % 3 | % 4 | % 5 | % 6 | % Developed by Feng, W.P.,@ EOS of NTU, Singapore, 2015-06-15 7 | % 8 | nf = numel(fpara(:,1)); 9 | [~,L] = sim_fpara2lap(fpara); 10 | slip = [fpara(:,8);fpara(:,9)]; 11 | roughness = norm(L*slip); 12 | % 13 | roughness = sqrt(roughness./(nf*2)); -------------------------------------------------------------------------------- /sim_fpara2seamlesspoly.m: -------------------------------------------------------------------------------- 1 | function [distfpara,polys] = sim_fpara2seamlesspoly(rfpara,maxdepth,subv,dampingfactor,isplot) 2 | % 3 | % 4 | % Developed by Wanpeng Feng, @Ottawa, 2017-04-12 5 | % 6 | outpolym = fixmodel_fpara2patch(rfpara,maxdepth); 7 | polys = []; 8 | for ni = 1:numel(outpolym) 9 | % 10 | if isplot == 1 11 | plot3(outpolym{ni}(:,1),outpolym{ni}(:,2),outpolym{ni}(:,3).*-1,'-b','LineWidth',5); 12 | hold on 13 | end 14 | % 15 | outpoly = sim_distpoly(outpolym{ni},subv,dampingfactor,isplot); 16 | if ni == 1 17 | polys = outpoly; 18 | else 19 | polys = [polys outpoly]; 20 | end 21 | end 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | % 24 | distfpara = zeros(numel(polys),10); 25 | meanazi = mean(rfpara(:,3)); 26 | % 27 | for ni = 1:numel(polys) 28 | cpoly = polys{1,ni}; 29 | distfpara(ni,:) = sim_4points4fpara(cpoly); 30 | end 31 | % 32 | -------------------------------------------------------------------------------- /sim_fpara2sort_fixmodel.m: -------------------------------------------------------------------------------- 1 | function [fpara,sortindex] = sim_fpara2sort_fixmodel(fpara,xytype,prec) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | if nargin < 2 12 | xytype = 1; 13 | end 14 | if nargin < 3 15 | prec = 10; 16 | end 17 | % 18 | deps = fix((fpara(:,5)));%.*prec); 19 | udepth = unique(deps); 20 | % 21 | [~,dindex] = sort(udepth); 22 | sortindex_y= zeros(size(deps(:),1),1); 23 | % 24 | for ni = 1:numel(deps) 25 | % [~,sortindex_y] = sort(deps); 26 | sortindex_y(ni) = dindex(udepth==deps(ni)); 27 | end 28 | % 29 | sortindex_x = []; 30 | for ni = 1:numel(dindex) 31 | %index_x = find(fpara(:,5)==sortindex_y(ni)); 32 | if xytype==1 33 | cpx = fpara(sortindex_y==dindex(ni),1); 34 | cpx = fix(cpx.*prec);%./prec; 35 | ttxdepth = unique(cpx); 36 | [~,ttxindex] = sort(ttxdepth); 37 | tempx = zeros(size(cpx(:),1),1); 38 | for nj = 1:numel(cpx) 39 | tempx(nj) = ttxindex(ttxdepth==cpx(nj)); 40 | end 41 | sortindex_x = [sortindex_x;tempx]; 42 | else 43 | cpx = fpara(sortindex_y==dindex(ni),2); 44 | cpx = fix(cpx.*prec);%./prec; 45 | ttxdepth = unique(cpx); 46 | [~,ttxindex] = sort(ttxdepth); 47 | tempx = zeros(size(cpx(:),1),1); 48 | for nj = 1:numel(cpx) 49 | tempx(nj) = ttxindex(ttxdepth==cpx(nj)); 50 | end 51 | sortindex_x = [sortindex_x;tempx]; 52 | end 53 | end 54 | sortindex = [sortindex_x(:) sortindex_y(:)]; 55 | 56 | -------------------------------------------------------------------------------- /sim_fpara2sortv2.m: -------------------------------------------------------------------------------- 1 | function [ilr,mfpara] = sim_fpara2sortv2(testfpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % A new version by FWP, @ GU, 2013-03-26 10 | % 11 | % 12 | [cx,cy] = sim_rotaxs(testfpara(:,1),testfpara(:,2),mean(testfpara(:,3)),mean(testfpara(:,4)),testfpara(1,1),testfpara(1,2)); 13 | % 14 | ucx = sort(unique(fix(cx.*100)./100)); 15 | ucy = sort(unique(fix(cy.*100)./100),'descend'); 16 | % 17 | for ni = 1:numel(testfpara(:,1)) 18 | mdis = (ucx-cx(ni)).^2; 19 | ind = find(mdis == min(mdis)); 20 | testfpara(ni,8) = ind(1); 21 | % 22 | mdis = (ucy-cy(ni)).^2; 23 | ind = find(mdis == min(mdis)); 24 | testfpara(ni,9) = ind(1); 25 | % 26 | end 27 | %sim_fig3d(testfpara); 28 | ilr = [testfpara(:,8),testfpara(:,9)]; 29 | mx = ilr(:,1); 30 | my = ilr(:,2); 31 | mmx = sort(unique(mx)); 32 | mmy = sort(unique(my)); 33 | for ni = 1:numel(mx) 34 | index1 = find(mmx == mx(ni)); 35 | index2 = find(mmy == my(ni)); 36 | ilr(ni,:) = [index1,index2]; 37 | end 38 | mfpara = testfpara; 39 | -------------------------------------------------------------------------------- /sim_fpara2topcenter.m: -------------------------------------------------------------------------------- 1 | function sim_fpara2topcenter(insimp) 2 | % 3 | % return top-center of fault trace based on a SIMP fault format 4 | % created by FWP, @SYSU, Guangzhou, 2021/09/11 5 | % 6 | [fpara,zone] = sim_openfault(insimp); 7 | % 8 | topfpara = sim_fpara2dist(fpara,fpara(7),fpara(6),fpara(7),fpara(6),'d',0); 9 | topfpara(8) = fpara(8)*2; 10 | % 11 | [x,y,z] = sim_fpara2corners(topfpara,'uc'); 12 | % 13 | % 14 | [lat,lon] = utm2deg(x*1000,y*1000,zone); 15 | % 16 | disp([lon,lat]) 17 | % 18 | sim_fig3d([fpara;topfpara]); 19 | hold on 20 | plot3(x,y,z*-1,'oc','MarkerSize',15); -------------------------------------------------------------------------------- /sim_fpara2tris.m: -------------------------------------------------------------------------------- 1 | function [tri,trix,triy,triz,triss,trids,trits] = sim_fpara2tris(fpara) 2 | % 3 | % 4 | % Create triangular elements of faults from rectangular fault patches... 5 | % 6 | % Developed by Feng, W.P., @ YJ, 2015-07-12 7 | % 8 | tri = struct(); 9 | ntri = 0; 10 | trix = []; 11 | triy = []; 12 | triz = []; 13 | triss= []; 14 | trids= []; 15 | trits= []; 16 | % 17 | % 18 | % 19 | for ni = 1:numel(fpara(:,1)) 20 | % 21 | cfpara = fpara(ni,:); 22 | allp = sim_fpara2allcors(cfpara); 23 | ntri = ntri+1; 24 | tri(ntri).x = allp([1,2,4],1); 25 | tri(ntri).y = allp([1,2,4],2); 26 | tri(ntri).z = allp([1,2,4],3).*-1; 27 | tri(ntri).ss = cfpara(8); 28 | tri(ntri).ds = cfpara(9); 29 | tri(ntri).ts = cfpara(10); 30 | tri(ntri).numneig = ntri; 31 | trix = [trix;tri(ntri).x(:)']; 32 | triy = [triy;tri(ntri).y(:)']; 33 | triz = [triz;tri(ntri).z(:)']; 34 | triss= [triss;tri(ntri).ss]; 35 | trids= [trids;tri(ntri).ds]; 36 | trits= [trits;tri(ntri).ts]; 37 | 38 | % 39 | ntri = ntri+1; 40 | tri(ntri).x = allp([2,3,4],1); 41 | tri(ntri).y = allp([2,3,4],2); 42 | tri(ntri).z = allp([2,3,4],3).*-1; 43 | tri(ntri).ss = cfpara(8); 44 | tri(ntri).ds = cfpara(9); 45 | tri(ntri).ts = cfpara(10); 46 | tri(ntri).numneig = ntri; 47 | trix = [trix;tri(ntri).x(:)']; 48 | triy = [triy;tri(ntri).y(:)']; 49 | triz = [triz;tri(ntri).z(:)']; 50 | triss= [triss;tri(ntri).ss]; 51 | trids= [trids;tri(ntri).ds]; 52 | trits= [trits;tri(ntri).ts]; 53 | % 54 | end -------------------------------------------------------------------------------- /sim_fpara2vol.m: -------------------------------------------------------------------------------- 1 | function vol = sim_fpara2vol(fpara,factor) 2 | % 3 | % 4 | % 5 | % Calculated volumb changes due a vertical closing or opening action 6 | % 7 | % 8 | % Developed by Wanpeng Feng, @NRCan, 2016-09-20 9 | % 10 | if nargin < 2 11 | factor = 1; 12 | end 13 | % 14 | vol = sum(fpara(:,6).*fpara(:,7).*fpara(:,10).*factor.*10^6); -------------------------------------------------------------------------------- /sim_fpara2xyz.m: -------------------------------------------------------------------------------- 1 | function sim_fpara2xyz(fpara,zone,outxyz,factor) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, W.P., @ BJ, 2009/11/01 9 | % 10 | % [fpara,zone] = sim_openfault(insimp); 11 | % 12 | % 13 | fid = fopen(outxyz,'w'); 14 | % 15 | for i = 1:size(fpara,1) 16 | % 17 | cfpara = fpara(i,:); 18 | %[x,y,z] = sim_fpara2corners(cfpara); 19 | %disp([x,y,z]); 20 | polys = sim_fpara2allcors(cfpara); 21 | % 22 | polys = [polys(1:4,:);polys(1,:)]; 23 | % plot3(polys(:,1),polys(:,2),polys(:,3)); 24 | [lats,lons] = utm2deg(polys(:,1).*1000,polys(:,2).*1000,zone); 25 | % 26 | slip = sqrt(cfpara(8)^2+cfpara(9)^2); 27 | % 28 | % factor can be 1 or -1. 29 | % 30 | polys(:,3) = polys(:,3) * factor; 31 | % 32 | % 33 | fprintf(fid,'> -Z%f\n', slip); 34 | for j = 1:5 35 | fprintf(fid,'%15.8f %15.8f %15.8f\n',lons(j),lats(j),polys(j,3)); 36 | end 37 | end 38 | fclose(fid); -------------------------------------------------------------------------------- /sim_fpara4col3d.m: -------------------------------------------------------------------------------- 1 | function [shear,normals,col] = sim_fpara4col3d(fpara,x,y,z,varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % + Purpose: 10 | % calculate the stress change from fpara directly due to the coordinates 11 | % you give 12 | % + Input: 13 | % fpara, the fault parameters 14 | % x, the coordinates of x, in km 15 | % y, the coordinates of y, in km 16 | % z, the coordinates of z, in km 17 | % varargin, the many other parameters 18 | % strike, the optimal strike angle 19 | % dip, the optimal dip angle 20 | % rake, the optimal rupture rake angle 21 | %... 22 | % + Modified History: 23 | % Created by Feng,W.P., 2011/10/14, @UoG 24 | % wanpeng.feng@hotmail.com; w.feng.1@research.gla.ac.uk 25 | % 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 27 | strike = 180; 28 | dip = 89.9; 29 | rake = 0; 30 | friction = 0.5; 31 | display = 0; 32 | alpha = 2/3; 33 | young = double(800000); 34 | pois = 0.25; 35 | thd = 0; 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | for ni=1:2:numel(varargin) 38 | % 39 | par = varargin{ni}; 40 | val = varargin{ni+1}; 41 | eval([par,'=val;']); 42 | % 43 | end 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45 | [cm,cn] = size(x); 46 | x = x(:); 47 | y = y(:); 48 | z = z(:); 49 | dis = multiokada3Dstress(fpara,x,y,z,strike,dip,rake,friction,... 50 | display,alpha,young,pois,thd); 51 | % 52 | % 53 | % 54 | % 55 | shear = reshape(dis.shear, cm,cn); 56 | normals = reshape(dis.normal, cm,cn); 57 | col = reshape(dis.coulomb,cm,cn); 58 | -------------------------------------------------------------------------------- /sim_fpara4los.m: -------------------------------------------------------------------------------- 1 | function [los,e,n,u] = sim_fpara4los(fpara,input) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | % Developed by FWP, @ IGPP of SIO, UCSD, 2013-10-04 12 | % 13 | x = input(:,1); 14 | y = input(:,2); 15 | disp = 0; 16 | dis = multiokadaALP(fpara,x,y,disp); 17 | % 18 | e = dis.E; 19 | n = dis.N; 20 | u = dis.V; 21 | % 22 | los = dis.E.*input(:,4) + ... 23 | dis.N.*input(:,5) + ... 24 | dis.V.*input(:,6); 25 | -------------------------------------------------------------------------------- /sim_fpara_ll2utm.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_fpara_ll2utm(infault) 2 | % 3 | % 4 | % 5 | [cfpara,zone] = sim_openfault(infault); 6 | % 7 | [x,y] = deg2utm(cfpara(:,2),cfpara(:,1),zone); 8 | % 9 | fpara = cfpara; 10 | fpara(:,1) = x./1000; 11 | fpara(:,2) = y./1000; 12 | % -------------------------------------------------------------------------------- /sim_fparaboundaries.m: -------------------------------------------------------------------------------- 1 | function [fpara,lap] = sim_fparaboundaries(fpara,refdep,mode,innour) 2 | % 3 | % 4 | % 5 | if nargin < 3 6 | mode = 'xz'; 7 | end 8 | if nargin < 4 9 | nour = 0; 10 | else 11 | nour = innour; 12 | end 13 | % 14 | fpara(:,8) = 100; 15 | fpara(:,9) = 100; 16 | % 17 | fpara(fpara(:,5)>refdep,8) = 0; 18 | fpara(fpara(:,5)>refdep,9) = 0; 19 | % 20 | % right boundary 21 | if nour == 0 22 | [x,y,z] = sim_fpara2corners(fpara,'ur'); 23 | vmax = max(x); 24 | fpara(x>vmax-0.5,8) = 0; 25 | fpara(x>vmax-0.5,9) = 0; 26 | end 27 | % 28 | % left boundary 29 | % 30 | [x,y,z] = sim_fpara2corners(fpara,'ul'); 31 | vmin = min(x); 32 | fpara(x 0 32 | % 33 | % meaning moving upward... 34 | % 35 | cfpara(6) = fpara(6); 36 | ofpara = sim_fparaconv(cfpara,3,0); 37 | else 38 | % 39 | % meaning moving downward... 40 | % 41 | cfpara = sim_fparaconv(cfpara,0,13); 42 | cfpara(6) = fpara(6); 43 | ofpara = sim_fparaconv(cfpara,3,0); 44 | end 45 | sim_fpara2oksar(ofpara,outoksar,zone); 46 | % 47 | if isplot==1 48 | % 49 | sfpara = ofpara; 50 | sfpara(8) = 20; 51 | sfpara(9) = 0; 52 | hold on 53 | sim_fig3d(sfpara,1,[],'edgecolor',[0,1,1]); 54 | % 55 | end 56 | % 57 | -------------------------------------------------------------------------------- /sim_fparastd.m: -------------------------------------------------------------------------------- 1 | function output = sim_fparastd(oksar,thresh) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by FWP, @ GU, 2012-11-16 10 | % 11 | if nargin < 2 12 | thresh = 0.5; 13 | end 14 | output = []; 15 | fpara = sim_oksar2SIM(oksar); 16 | slip = sqrt(fpara(:,8).^2 + fpara(:,9).^2); 17 | maxslip = max(slip); 18 | [m1,m2,m3] = sim_fpara2moment(fpara); 19 | [~,mnrk] = sim_calrake(fpara,thresh); 20 | % 21 | disp(' +++++++++++++++++++++++++++++++++++++++++ '); 22 | disp(' EQ Information '); 23 | disp([' ', oksar]); 24 | disp(' +++++++++++++++++++++++++++++++++++++++++ '); 25 | disp([' Maximum slip:',num2str(maxslip,'%10.5f')]); 26 | disp([' Mw:',num2str(m3,'%5.3f')]); 27 | disp([' Seismic Moment:',num2str(m2,'%i')]); 28 | disp([' Mean Rake Angl:',num2str(mnrk)]); 29 | % 30 | sim_fig3d(fpara); 31 | -------------------------------------------------------------------------------- /sim_gaussianfit.m: -------------------------------------------------------------------------------- 1 | function [sigma,mu,A]=sim_gaussianfit(x,y,h) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | 8 | % 9 | % [sigma,mu,A] = sim_gaussfit(x,y) 10 | % [sigma,mu,A] = sim_gaussfit(x,y,h) 11 | % 12 | % this function is doing fit to the function 13 | % y=A * exp( -(x-mu)^2 / (2*sigma^2) ) 14 | % 15 | % the fitting is been done by a polyfit 16 | % the lan of the data. 17 | % 18 | % h is the threshold which is the fraction 19 | % from the maximum y height that the data 20 | % is been taken from. 21 | % h should be a number between 0-1. 22 | % if h have not been taken it is set to be 0.2 23 | % as default. 24 | % 25 | 26 | 27 | %% threshold 28 | if nargin <= 2 || isempty(h)==1 29 | h=0.2; 30 | end 31 | 32 | %% cutting 33 | ymax = max(y(:)); 34 | xnew = []; 35 | ynew = []; 36 | for n=1:length(x) 37 | if y(n)>ymax*h; 38 | xnew=[xnew,x(n)]; 39 | ynew=[ynew,y(n)]; 40 | end 41 | end 42 | 43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 | %%% Fitting 45 | ylog = log10(ynew); 46 | xlog = xnew; 47 | p = polyfit(xlog(:),ylog(:),2); 48 | A2 = p(1); 49 | A1 = p(2); 50 | A0 = p(3); 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 52 | sigma = sqrt(-1/(2*pi*A2)); 53 | mu = A1*sigma^2; 54 | A = exp(A0+mu^2/(2*sigma^2)); 55 | 56 | -------------------------------------------------------------------------------- /sim_getGMTpatch.m: -------------------------------------------------------------------------------- 1 | function [patchsize,points] = sim_getGMTpatch(gmtdata,nstep,pixelsize) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | if nargin < 2 10 | nstep = 5; 11 | end 12 | if nargin < 3 13 | pixelsize = 0.16; 14 | end 15 | % 16 | %point = []; 17 | counter = 0; 18 | fid = fopen(gmtdata,'r'); 19 | outd= []; 20 | while feof(fid)==0 21 | tfline = fgetl(fid); 22 | index = findstr(tfline,'>'); 23 | if isempty(index)==1 24 | tmp = textscan(tfline,'%f%f'); 25 | outd = [outd;tmp{1},tmp{2}]; 26 | else 27 | counter = counter + 1; 28 | end 29 | end 30 | fclose(fid); 31 | points = cell(counter,1); 32 | patchsize = zeros(counter,1); 33 | for ni = 1:counter 34 | cps = outd((ni-1)*nstep+1:(ni-1)*nstep + 5,:); 35 | patchsize(ni,1) = ceil((max(cps(:,1))-min(cps(:,1)))/pixelsize); 36 | points{ni} = cps; 37 | end 38 | -------------------------------------------------------------------------------- /sim_getfileinfo.m: -------------------------------------------------------------------------------- 1 | function [idir,bname,postfix] = sim_getfileinfo(fnames) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | %Purpose: 10 | % return the file's idir,basename,prefix and postfix 11 | %Input: 12 | % fnames, the full file path name 13 | %Output: 14 | % idir 15 | % bname 16 | % prefix 17 | % postfix 18 | %Created in Glasgow University 19 | %June 20 2009 20 | sysinfo = computer; 21 | if isempty(findstr(sysinfo,'PC'))~=1 22 | inidex = '\'; 23 | end 24 | if isempty(findstr(sysinfo,'PC'))==1 25 | inidex = '/'; 26 | end 27 | dirinds = findstr(fnames,inidex); 28 | if isempty(dirinds)==1 29 | idir = ''; 30 | fname= fnames; 31 | else 32 | idir = fnames(1:dirinds(end)-1); 33 | fname= fnames(dirinds(end)+1:end); 34 | end 35 | fixinds = findstr(fname,'.'); 36 | if isempty(fixinds)==1 37 | bname = fname; 38 | postfix = ''; 39 | else 40 | bname = fname(1:fixinds(1)-1); 41 | postfix = fname(fixinds(1):end); 42 | end 43 | 44 | -------------------------------------------------------------------------------- /sim_getinps.m: -------------------------------------------------------------------------------- 1 | function [input,cinput] = sim_getinps(inpfiles) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | nf = numel(inpfiles); 11 | input = []; 12 | cinput= cell(nf,1); 13 | for ni=1:nf 14 | % 15 | inf = inpfiles{ni}; 16 | data = load(inf{1}); 17 | input= [input;data]; 18 | cinput{ni} = data; 19 | end 20 | -------------------------------------------------------------------------------- /sim_getslipmodel.m: -------------------------------------------------------------------------------- 1 | function [fpara mabc] = sim_getslipmodel(matfile,funcs,index,oksarfile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | fpara = []; 11 | mabc = []; 12 | mat = load(matfile); 13 | switch upper(funcs) 14 | case 'PLOT' 15 | rgh = mat.roughness; 16 | rgh = rgh-min(rgh(:)); 17 | rgh = rgh./max(rgh(:)); 18 | std = mat.std; 19 | std = std - min(std(:)); 20 | std = std./max(std(:)); 21 | figure(); 22 | plot(mat.roughness,mat.std,'o-r'); 23 | figure(); 24 | distm = sqrt(rgh.^2+std.^2); 25 | index = find(distm==min(distm(:))); 26 | plot(rgh,std,'o-r'); 27 | hold on 28 | plot(rgh(index),std(index),'db'); 29 | case 'MODEL' 30 | aslip = mat.dismodel{index}; 31 | mat.disf(:,8) = aslip(1:mat.m/2); 32 | mat.disf(:,9) = aslip(mat.m/2+1:mat.m); 33 | abcs = aslip(mat.m+1:mat.m+mat.dm); 34 | fpara = mat.disf; 35 | whos fpara 36 | sim_fpara2oksar(fpara,oksarfile); 37 | ninp = numel(mat.cinput); 38 | mabc = cell(ninp,1); 39 | for ni = 1:ninp 40 | stind = (ni-1)*3; 41 | abc = abcs(stind+1:stind+3); 42 | fprintf('%s %f %f %f',mat.cinput{ni}{1},abc); 43 | mabc{ni} = {mat.cinput{ni}{1},abc}; 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /sim_gfpara.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_gfpara(varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % + Input: 11 | % 12 | % + Ouput: 13 | % 14 | % + Log: 15 | % Created by Feng, W.P.,@ GU, 2013-02-12 16 | % 17 | % 18 | xyloc = [0,0]; 19 | strike = 45; 20 | dip = 45; 21 | rake = 45; 22 | 23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 24 | v = sim_varmag(varargin); 25 | for j = 1:length(v) 26 | eval(v{j}); 27 | end 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 29 | -------------------------------------------------------------------------------- /sim_green4lapweight.m: -------------------------------------------------------------------------------- 1 | function w = sim_green4lapweight(green,obs,amfactor) 2 | %,weights) 3 | % 4 | % 5 | % 6 | % 7 | % Created by Feng, WP, @ Gu, 2013-04-17 8 | % 9 | if nargin < 3 10 | amfactor = 3; 11 | end 12 | % 13 | % obsoleted by Feng, W.P., @ EOS of NTU, Singapore, 2015-06-24 14 | % if nargin < 4 15 | % weights = 1; 16 | % end 17 | % 18 | dims = size(green); 19 | w = zeros(dims(2)); 20 | % 21 | for ni = 1:dims(2) 22 | % 23 | cgreen = green(:,ni); 24 | x = sim_bvls(cgreen,obs,0,200); 25 | res = std((obs-cgreen*x));%.*weights); 26 | % 27 | w(ni,:)= res; 28 | % 29 | end 30 | w = (exp(w))./mean(exp(w(:)));%.*amfactor; 31 | % 32 | minv = min(w(:)); 33 | maxv = max(w(:)); 34 | % 35 | if amfactor <= 0.95 36 | % 37 | amfactor = 1; 38 | end 39 | % 40 | rng = [0.95,amfactor]; 41 | w = (w-minv)./(maxv-minv).*(rng(2)-rng(1))+rng(1); 42 | % -------------------------------------------------------------------------------- /sim_greentransform.m: -------------------------------------------------------------------------------- 1 | function [soG,doG] = sim_greentransform(sG,dG,r1,r2) 2 | % 3 | % 4 | % 5 | % 6 | % 7 | % transform GREEN function with given rakes... 8 | % by Wanpeng Feng, @RNCan, 2016-09-27 9 | % 10 | soG = sG; 11 | doG = dG; 12 | % 13 | for nrg = 1:numel(sG(:,1)) 14 | % 15 | soG(nrg,:) = sG(nrg,:) .* cosd(r1(:))' + ... 16 | dG(nrg,:) .* sind(r1(:))'; 17 | doG(nrg,:) = sG(nrg,:) .* cosd(r2(:))' + ... 18 | dG(nrg,:) .* sind(r2(:))'; 19 | % 20 | end -------------------------------------------------------------------------------- /sim_indgestslip.m: -------------------------------------------------------------------------------- 1 | function pfpara = sim_indgestslip(pfpara,refpara,distthresh) 2 | % 3 | % 4 | % by Wanpeng Feng, @Ottawa, 2017-04-16 5 | % 6 | % 7 | pfpara(:,8) = 0; 8 | pfpara(:,9) = 0; 9 | pfpara(:,10)= 0; 10 | for ni = 1:numel(pfpara(:,1)) 11 | % 12 | dist = sqrt((pfpara(ni,1)-refpara(:,1)).^2 + ... 13 | (pfpara(ni,2)-refpara(:,2)).^2 + ... 14 | (pfpara(ni,5)-refpara(:,5)).^2); 15 | midist = min(dist); 16 | if midist<=distthresh 17 | pfpara(ni,8) = refpara(dist==midist,8); 18 | pfpara(ni,9) = refpara(dist==midist,9); 19 | pfpara(ni,10) = refpara(dist==midist,10); 20 | end 21 | end -------------------------------------------------------------------------------- /sim_infovarmag.m: -------------------------------------------------------------------------------- 1 | function v = sim_infovarmag(pairs) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | %%% 8 | % +Name: 9 | % sim_infovarmag, varible manager 10 | % +Purpose: 11 | % helper function allowing named generic name value parameter passing 12 | % History: 13 | % Modified by Feng W.P from Googleearth toolsbox... 14 | % 15 | 16 | v = {}; 17 | 18 | for ii=1:2:length(pairs(:)) 19 | % 20 | if isnumeric(pairs{ii+1}) 21 | str = [ ['info.',pairs{ii}] ' = [' num2str(pairs{ii+1}),'];' ]; 22 | else 23 | str = [ ['info.',pairs{ii}] ' = ' 39 pairs{ii+1} 39,';' ]; 24 | end 25 | v{(ii+1)/2,1} = str; 26 | % 27 | end 28 | -------------------------------------------------------------------------------- /sim_infpara.m: -------------------------------------------------------------------------------- 1 | function [fpara,zone] = sim_infpara(inoksar) 2 | % 3 | % 4 | % 5 | % Developed by Feng, W.P., @ EOS of NTU, Singapore, 2015-06-27 6 | % 7 | [tmp,tmp,bext] = fileparts(inoksar); 8 | % 9 | switch upper(bext) 10 | case '.OKSAR' 11 | [fpara,zone] = sim_oksar2SIM(inoksar); 12 | case '.SIMP' 13 | [fpara,zone] = sim_simp2fpara(inoksar); 14 | otherwise 15 | disp('No identified format was found!!'); 16 | return 17 | % 18 | end 19 | % -------------------------------------------------------------------------------- /sim_inp2cm.m: -------------------------------------------------------------------------------- 1 | function sim_inp2cm(inpf,outinp) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | data = load(inpf); 11 | % 12 | inp = data; 13 | inp(:,3) = data(:,3).*(0.0562356424/(-4*3.14159265)); 14 | inp(:,4) = -1.*cosd(data(:,5)).*sind(data(:,4)); 15 | inp(:,5) = sind(data(:,5)).*sind(data(:,4)); 16 | inp(:,6) = cosd(data(:,4)); 17 | inp(:,7) = sqrt(data(:,6)).*(0.0562356424/(4*3.14159265)); 18 | % 19 | fid = fopen(outinp,'w'); 20 | fprintf(fid,'%12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f \n',inp'); 21 | fclose(fid); 22 | -------------------------------------------------------------------------------- /sim_inp2cov_sub.m: -------------------------------------------------------------------------------- 1 | function out = sim_inp2cov_sub(indata,inpdata,cx,cy,outd,ni,lamda) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | %fid = fopen('tmp.list','u'); 9 | X = outd((ni-1)*5+1:(ni-1)*5+5,1); 10 | Y = outd((ni-1)*5+1:(ni-1)*5+5,2); 11 | xr=[min(X(:)),max(X(:))]; 12 | yr=[min(Y(:)),max(Y(:))]; 13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14 | %cdata = sim_subtract(unwfile,xr,yr); 15 | %imagesc(cx-xr(1)); 16 | ind1 = abs((cx-xr(1)))==min(abs((cx(:)-xr(1)))); 17 | ind2 = abs((cy-yr(2)))==min(abs((cy(:)-yr(2)))); 18 | ind = ind1.*ind2; 19 | [r1,c1] = find(ind==1); 20 | ind1 = abs(cx-xr(2))==min(abs(cx(:)-xr(2))); 21 | ind2 = abs(cy-yr(1))==min(abs(cy(:)-yr(1))); 22 | ind = ind1.*ind2; 23 | [r2,c2] = find(ind==1); 24 | %whos indata 25 | minr = (r1>=r2)*r2+(r1=r2)*r1+(r1=c2)*c2+(c1=c2)*c1+(c1 numel(data(:,1)) 21 | xe = numel(data(:,1)); 22 | end 23 | % 24 | numfile = numfile + 1; 25 | coutname = [bdir,'/',bname,'_',num2str(numfile),ext]; 26 | nfile = nfile+1; 27 | outfiles{nfile} = coutname; 28 | fid = fopen(coutname,'w'); 29 | fprintf(fid,'%12.6f %12.6f %18.14f %12.6f %12.6f %12.6f %12.6f\n',data(xs:xe,:)'); 30 | fclose(fid); 31 | end 32 | -------------------------------------------------------------------------------- /sim_inps2cfg.m: -------------------------------------------------------------------------------- 1 | function sim_inps2cfg(outcfg,varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by FWP, @ GU, 2013-03-01 10 | % 11 | % 12 | 13 | if nargin < 1 14 | disp('sim_inps2cfg(output_cfg,inp1,inp2,...,inpn);'); 15 | return 16 | end 17 | % 18 | inps = cell(nargin-1,1); 19 | % 20 | for ni = 1:nargin-1 21 | % disp(varargin{ni}) 22 | inps{ni} = varargin{ni}; 23 | inpids(ni) = 1; 24 | end 25 | % 26 | ninps = numel(inps); 27 | psokinv.inps = inps; 28 | psokinv.inpids = 1; 29 | psokinv.locals = 0; 30 | psokinv.isinv = zeros(1,10) + 1; 31 | psokinv.particles = 300; 32 | psokinv.lambda = 3.2*10*8; 33 | psokinv.mu = 3.2*10*8; 34 | psokinv.outoksar = 'eq.simp'; 35 | psokinv.outmat = 'eq.mat'; 36 | psokinv.psoiteration = 20; 37 | psokinv.sampleinfoshow = 0; 38 | psokinv.simpleiteration = 1000; 39 | psokinv.restartnum = 5; 40 | psokinv.mcinversionloop = 100; 41 | psokinv.convermindis = 1; 42 | psokinv.outdir = 'result'; 43 | psokinv.mcinpdir = 'perts'; 44 | psokinv.inpabc = zeros(ninps,3); 45 | psokinv.inpmc = zeros(ninps,1); 46 | psokinv.isvcm = zeros(ninps,1); 47 | psokinv.weight = zeros(ninps,1) + 1; 48 | % 49 | % 50 | faultintpara = zeros(1,10,3); 51 | psokinv.faultintpara = faultintpara; 52 | psokinv.rake = 0; 53 | psokinv.faultid = 1; 54 | psokinv.cfg = outcfg; 55 | % 56 | psokinv = psokinv_psokinv_from_inp2initoksar(psokinv); 57 | % 58 | psokinv.inpids = linspace(1,ninps,ninps); 59 | psokinv_psokinv_create_cfg(psokinv); 60 | % 61 | -------------------------------------------------------------------------------- /sim_inpumt2ll.m: -------------------------------------------------------------------------------- 1 | function sim_inpumt2ll(dirs,zone) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | files = dir([dirs,'/*.inp']); 10 | for ni = 1:numel(files) 11 | cfile = fullfile(dirs,files(ni).name); 12 | data = sim_inputdata(cfile); 13 | [lat,lon] = utm2deg(data(:,1).*1000,data(:,2).*1000,zone); 14 | data(:,1) = lon; 15 | data(:,2) = lat; 16 | [ipath,iname] = fileparts(cfile); 17 | outfile = fullfile(ipath,[iname,'_LL.inp']); 18 | fid = fopen(outfile,'w'); 19 | fprintf(fid,'%12.6f%12.6f%12.6f%12.6f%12.6f%12.6f%12.6f\n',data'); 20 | fclose(fid); 21 | end 22 | -------------------------------------------------------------------------------- /sim_input2outfile.m: -------------------------------------------------------------------------------- 1 | function sim_input2outfile(input,outname) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Developed by FWP, @ IGP, BJ, 2010-10-01 9 | % 10 | if nargin < 1 11 | disp('sim_input2outfile(input,outname)'); 12 | return 13 | end 14 | % 15 | fid = fopen(outname,'w'); 16 | fprintf(fid,'%15.8f %15.8f %11.8f %11.8f %11.8f %11.8f %11.8f\n',input'); 17 | fclose(fid); 18 | -------------------------------------------------------------------------------- /sim_inputdata.m: -------------------------------------------------------------------------------- 1 | function [data npoint] = sim_inputdata(inpfile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % created by FWP, @ GU, 2009/06 11 | % 12 | if nargin < 1 13 | data = []; 14 | npoint = []; 15 | disp('[data npoint] = sim_inputdata(inpfile);'); 16 | return 17 | end 18 | if exist(inpfile,'file')~=0 19 | fid = fopen(inpfile); 20 | % 21 | npoint = 0; 22 | data = zeros(1,7); 23 | while feof(fid)~=1 24 | txt = fgetl(fid); 25 | % modified by Feng, W.P, 2011-04-22 26 | % There will be more lines with no data at the end. 27 | if strcmpi(txt,'') ~= 1 28 | npoint = npoint+1; 29 | % 30 | tmp = textscan(txt,'%s %s %s %s %s %s %s'); 31 | data(npoint,1) = str2double(tmp{1}); 32 | data(npoint,2) = str2double(tmp{2}); 33 | data(npoint,3) = str2double(tmp{3}); 34 | data(npoint,4) = str2double(tmp{4}); 35 | data(npoint,5) = str2double(tmp{5}); 36 | data(npoint,6) = str2double(tmp{6}); 37 | data(npoint,7) = str2double(tmp{7}); 38 | end 39 | end 40 | fclose(fid); 41 | else 42 | disp([inpfile ' does not exist! ' 'Please input correct data file! ']); 43 | data = []; 44 | npoint = 0; 45 | end 46 | -------------------------------------------------------------------------------- /sim_inputm2ll.m: -------------------------------------------------------------------------------- 1 | function sim_inputm2ll(dirs,zone) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | files = dir([dirs,'/*.inp']); 10 | for ni = 1:numel(files) 11 | cfile = fullfile(dirs,files(ni).name); 12 | data = sim_inputdata(cfile); 13 | [lat,lon] = utm2deg(data(:,1).*1000,data(:,2).*1000,zone); 14 | data(:,1) = lon; 15 | data(:,2) = lat; 16 | [ipath,iname] = fileparts(cfile); 17 | outfile = fullfile(ipath,[iname,'_LL.inp']); 18 | fid = fopen(outfile,'w'); 19 | fprintf(fid,'%18.12f%18.12f%12.6f%12.6f%12.6f%12.6f%12.6f\n',data'); 20 | fclose(fid); 21 | end 22 | -------------------------------------------------------------------------------- /sim_inputrms.m: -------------------------------------------------------------------------------- 1 | function rms = sim_inputrms(fpara,input) 2 | % 3 | % 4 | % 5 | % Developed by Feng, W.P., @ EOS of NTU, Singapore, 2015-06-15 6 | % 7 | dis = multiokadaALP(fpara,input(:,1),input(:,2)); 8 | osim = dis.E.*input(:,4) + dis.N.*input(:,5) + dis.V.*input(:,6); 9 | %stdv = std(input(:,3)-osim); 10 | rms = sim_rms(input(:,3),osim); -------------------------------------------------------------------------------- /sim_iplot2.m: -------------------------------------------------------------------------------- 1 | function sim_iplot2(x,y,msize,color) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | if nargin < 4 9 | color = [1,0,0]; 10 | end 11 | for ni=1:size(x,1) 12 | hold on 13 | plot(x(ni),y(ni),'o','Color',color,... 14 | 'MarkerFaceColor','k','MarkerSize',msize(ni)); 15 | hold on 16 | end 17 | -------------------------------------------------------------------------------- /sim_iplot3.m: -------------------------------------------------------------------------------- 1 | function sim_iplot3(x,y,z,msize) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | for ni=1:size(x,1) 9 | plot3(x(ni),y(ni),z(ni),'or',... 10 | 'MarkerFaceColor','y','MarkerSize',msize(ni)); 11 | hold on 12 | end 13 | -------------------------------------------------------------------------------- /sim_laps2lap.m: -------------------------------------------------------------------------------- 1 | function lap = sim_laps2lap(laps) 2 | % 3 | % 4 | % 5 | % Combine laps 6 | % by Wanpeng Feng, @CCRS/NRCan, 2017-09-25 7 | % 8 | nlap = numel(laps); 9 | lapsize = 0; 10 | % 11 | for ni = 1:nlap 12 | clap = laps{ni}; 13 | dims = size(clap); 14 | lapsize = lapsize + dims(1); 15 | end 16 | % 17 | lap = zeros(lapsize); 18 | % 19 | lapsize = 0; 20 | for ni = 1:nlap 21 | clap = laps{ni}; 22 | dims = size(clap); 23 | lap((lapsize+1):(lapsize+dims(1)),(lapsize+1):(lapsize+dims(1))) = clap; 24 | lapsize = lapsize + dims(1); 25 | end 26 | -------------------------------------------------------------------------------- /sim_line2azi.m: -------------------------------------------------------------------------------- 1 | function azi = sim_line2azi(p) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | % Purpose: 9 | % return the azimuth angle from two points 10 | % Usage: 11 | % azi = sim_line2azi(p) 12 | % Input: 13 | % p, 2*2,two points 14 | % Output: 15 | % azi, degree angle 16 | % Modification History: 17 | % Feng, Wanpeng, 2010-11-30, initial version 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | azi = 90 - atan2(p(2,2)-p(1,2),p(2,1)-p(1,1))*180/pi; 20 | azi = (azi > 0 )*azi + (azi <= 0) *(360+azi); 21 | -------------------------------------------------------------------------------- /sim_listfuncs.m: -------------------------------------------------------------------------------- 1 | function sim_listfuncs(prefix,dbdir) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | if nargin<1 10 | prefix = '*'; 11 | end 12 | if nargin<2 13 | dbdir = 'D:\mdbase\dbase_2'; 14 | end 15 | files = dir(fullfile(dbdir,['*',prefix,'*.m'])); 16 | for ni=1:size(files,1) 17 | disp(files(ni).name); 18 | end 19 | -------------------------------------------------------------------------------- /sim_ll2xy.m: -------------------------------------------------------------------------------- 1 | function [x,y] = sim_ll2xy(lats,lons) 2 | % 3 | % 4 | % 5 | % 6 | lla = [lats(:) lons(:) lons(:).*0]; 7 | out = lla2ecef(lla); 8 | % 9 | x = out(:,2)/1000.; 10 | y = out(:,1)/1000.; -------------------------------------------------------------------------------- /sim_ll2xyz.m: -------------------------------------------------------------------------------- 1 | function [x,y,z] = sim_ll2xyz(lons,lats,r,e) 2 | % 3 | % Convert longlat(s) to km in a cartesian coordinate 4 | % This is appliable at the equator and I would strongly 5 | % suggest using a conversion between lonlat and utm in the 6 | % areas far from the equator. 7 | % +Output: 8 | % y and z can be considered to use in modelling 9 | % 10 | % by Wanpeng Feng, @SYSU, Guangzhou, 2019/05/06 11 | % 12 | if nargin < 3 13 | % 14 | r = 6378.1370; % at the Equator 15 | end 16 | if nargin < 4 17 | e = (6378.140-6356.755)/6378.140; 18 | end 19 | % 20 | % 21 | x = r .* cosd(lats) .* cosd(lons); 22 | y = r .* cosd(lats) .* sind(lons); 23 | z = (r*(1-e^2)) .* sind(lats); -------------------------------------------------------------------------------- /sim_look.m: -------------------------------------------------------------------------------- 1 | function sim_look(ipath) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | 8 | switch ipath 9 | case 'psov1' 10 | str = dir('D:\mdbase\dbase_1'); 11 | case 'psov2' 12 | str = dir('D:\mdbase\dbase_2'); 13 | 14 | case 'raw' 15 | str = dir('D:\mdbase\dbase_0'); 16 | end 17 | for ni = 1: numel(str) 18 | tnames = str(ni).name; 19 | [pa,na,ex,ve] = fileparts(tnames); 20 | if strcmp(ex,'.m')==1 21 | disp(na); 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /sim_lsq.m: -------------------------------------------------------------------------------- 1 | function [slips,rsq] = sim_lsq(G,D,L,alpha,COV,algor,minmoment,LB,UB,std) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Created by Feng, Wanpeng,2011-03-30 11 | % Modified by Feng, W.P, 2011-05-19 12 | % -> add std, standard deviation of obs as model new cosntraint 13 | % 14 | global slipscale 15 | 16 | if nargin < 6 17 | algor = 'cgls'; 18 | end 19 | if nargin < 10 20 | std = D.*0; 21 | end 22 | % 23 | A = [COV*G;L.*alpha]; 24 | D = COV*D; 25 | if size(A,1)>size(D) 26 | D = [D;zeros(size(A,1)-size(D,1),1)]; 27 | end 28 | % 29 | if minmoment ~= 0 30 | if isempty(slipscale) 31 | slipscale = 1; 32 | end 33 | Aslip = (A(1,:).*0+1).*slipscale(:)'; 34 | % 35 | % 36 | A = [A;minmoment.*Aslip]; 37 | D = [D;0]; 38 | end 39 | % 40 | switch lower(algor) 41 | case 'bvsl' 42 | slips = bvls(A,D,LB,UB); 43 | case 'lsqlin' 44 | options = optimset('LargeScale','on','display','off'); 45 | [slips,~,rsq] = lsqlin(A,D,[],[],[],[],LB,UB,[],options); 46 | otherwise 47 | [slips, rsq] = cgls_bvls(A,D,LB,UB,[],[],std); 48 | rsq = rsq(end); 49 | end 50 | -------------------------------------------------------------------------------- /sim_mC2COV.m: -------------------------------------------------------------------------------- 1 | function COV = sim_mC2COV(mC) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | ndata = numel(mC); 10 | COV = []; 11 | for ni = 1:ndata 12 | tmpC = mC{ni}; 13 | np = size(COV,1)+size(tmpC,1); 14 | cC = zeros(np); 15 | cC(1:size(COV,1),1:size(COV,1)) = COV; 16 | cC(size(COV,1)+1:end,size(COV,1)+1:end) = tmpC; 17 | COV = cC; 18 | end 19 | -------------------------------------------------------------------------------- /sim_mG2G.m: -------------------------------------------------------------------------------- 1 | function G = sim_mG2G(mG,mrakecons) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by Feng,Wanpeng,2011-03-30 10 | 11 | for ni = 1:numel(mG); 12 | tmpG = mG{ni}; 13 | rakecons = mrakecons{ni}; 14 | if ni==1 15 | if rakecons(ni,2)==rakecons(ni,3) 16 | bG = tmpG; 17 | aG = []; 18 | else 19 | aG = tmpG(:,1:end/2); 20 | bG = tmpG(:,end/2+1:end); 21 | end 22 | else 23 | if rakecons(ni,2)==rakecons(ni,3) 24 | aG = [aG,[]]; 25 | bG = [bG,tmpG]; 26 | else 27 | aG = [aG,tmpG(:,1:end/2)]; 28 | bG = [bG,tmpG(:,end/2+1:end)]; 29 | end 30 | end 31 | end 32 | G = [aG,bG]; 33 | -------------------------------------------------------------------------------- /sim_mL2L.m: -------------------------------------------------------------------------------- 1 | function L = sim_mL2L(mL) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | np = 0; 11 | L = []; 12 | iseq = zeros(numel(mL),1);%rakecons(:,2) == rakecons(:,3); 13 | for ni = 1:numel(find(iseq==0)) 14 | tmpG = mL{ni}; 15 | np = size(L,1)+size(tmpG,1); 16 | cL = zeros(np); 17 | % 18 | cL(1:size(L,1),1:size(L,1)) = L; 19 | cL(size(L,1)+1:np,size(L,1)+1:np) = tmpG; 20 | L = cL; 21 | end 22 | L = [L L.*0;L.*0 L]; 23 | if numel(find(iseq==1))>0 24 | for ni = numel(find(iseq==0))+1:numel(mL) 25 | tmpG = mL{ni}; 26 | np = size(L,1)+size(tmpG,1); 27 | cL = zeros(np); 28 | L = [L zeros(size(tmpG,1));... 29 | L.*0 tmpG]; 30 | % 31 | cL(1:size(L,1),1:size(L,1)) = L; 32 | cL(size(L,1)+1:np,size(L,1)+1:np) = tmpG; 33 | L = cL; 34 | end 35 | end 36 | 37 | -------------------------------------------------------------------------------- /sim_mapfpara.m: -------------------------------------------------------------------------------- 1 | function sim_mapfpara(fpara,model) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Usage: 9 | % sim_mapfpara(fpara,model) 10 | % Input: 11 | % fpara, the fault model(rec),N*10 12 | % model, detail requirement. 13 | % Modification History: 14 | % 2010-11-29, Feng, W.P, initial version 15 | % 16 | switch model 17 | case 2 18 | sim_fig2d(fpara); 19 | case 3 20 | sim_fig3d(fpara); 21 | case 2.1 22 | p = sim_fpara2allcors(fpara); 23 | p = [p(1:4,:);p(1,:)]; 24 | plot(p(:,1),p(:,2),'o-r'); 25 | end 26 | -------------------------------------------------------------------------------- /sim_mat2en.m: -------------------------------------------------------------------------------- 1 | function sim_mat2en(nrow,nlin,xmin,ymax,xstep,ystep,... 2 | zone,hdrname,numband) 3 | % 4 | %************** FWP Work ************************ 5 | %Developed by FWP, @GU/BJ, 2007-2014 6 | % contact by wanpeng.feng@hotmail.com 7 | %************** Good Luck *********************** 8 | 9 | % 10 | % 11 | % to write a header file for ENVI image 12 | % Feng W.P, 2009 Agu 16, added some info 13 | % 14 | fid = fopen(hdrname,'w'); 15 | fprintf(fid,'%s\n','ENVI'); 16 | fprintf(fid,'%s\n','description = {'); 17 | fprintf(fid,'%s\n',' Matlab2ENVI,'); 18 | outt = clock(); 19 | fprintf(fid,'%s\n',[' ',date(),num2str(outt(4)),':',num2str(outt(5)),':',num2str(outt(5)),'}']); 20 | fprintf(fid,'%s\n',['samples = ',num2str(nrow)]); 21 | fprintf(fid,'%s\n',['lines = ',num2str(nlin)]); 22 | fprintf(fid,'%s\n',['bands = ',num2str(numband)]); 23 | fprintf(fid,'%s\n','header offset = 0'); 24 | fprintf(fid,'%s\n','file type = ENVI Standard'); 25 | fprintf(fid,'%s\n','data type = 4'); 26 | fprintf(fid,'%s\n','interleave = bsq'); 27 | fprintf(fid,'%s\n','sensor type = Unknown'); 28 | fprintf(fid,'%s\n','byte order = 0'); 29 | fprintf(fid,'%s\n','x start = 0'); 30 | fprintf(fid,'%s\n','y start = 0'); 31 | fprintf(fid,'%s\n',zone);% ['map info = {UTM, 1.000, 1.000, ',num2str(xmin),',',... 32 | % num2str(ymax),',',num2str(xstep),',',num2str(ystep),',',... 33 | % num2str(zone),',',' North, WGS-84, units=Meters}']); 34 | fprintf(fid,'%s\n','wavelength units = Unknown'); 35 | fprintf(fid,'%s\n','band names = {'); 36 | fprintf(fid,'%s\n','InSAR, Rewrapped}'); 37 | fclose(fid); 38 | -------------------------------------------------------------------------------- /sim_mat2spread.m: -------------------------------------------------------------------------------- 1 | function v = sim_mat2spread(mtr) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | I = eye(size(mtr)); 11 | v = mtr-I; 12 | v = sum(v(:).^2); 13 | -------------------------------------------------------------------------------- /sim_mcest2slipmodel.m: -------------------------------------------------------------------------------- 1 | function sim_mcest2slipmodel(inmat) 2 | % 3 | % 4 | % 5 | % Developed by Feng, W.P., @ EOS of NTU, Singapore, 2015-06-24 6 | % 7 | cmat = load(inmat); 8 | fpara = cmat.fpara; 9 | mabicre = cmat.mabicre; 10 | mcslip = mabicre{1}.mcslip; 11 | zone = cmat.utmzone; 12 | % 13 | for ni = 1:numel(mcslip(1,:)) 14 | cslip = mcslip(:,ni); 15 | fpara(:,8) = cslip(1:end/2); 16 | fpara(:,9) = cslip(end/2+1:end); 17 | sim_fpara2simp(fpara,[num2str(ni),'.simp'],zone); 18 | end 19 | % 20 | -------------------------------------------------------------------------------- /sim_mergin.m: -------------------------------------------------------------------------------- 1 | function [am,index,noind] = sim_mergin(cinput,abccof) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Purpose: 9 | % create the matrix including (x,y,1) for the inverison of a,b,c. 10 | %%%%%%%%% 11 | % Output: 12 | % coefficient matrix for inversion of the offsets or orbit ramps 13 | % in default, none of them will be returned... 14 | % 15 | % index, the index of the data set which will be inverted ab or abc 16 | % or c only 17 | % noind, the index of the data set which will not be inverted abc. 18 | % 19 | % The number of the data set we need estimate the orbit error and offsets 20 | % Created by Feng, W.P, @IGP/CEA, wanpeng.feng@hotmail.com 21 | % 22 | index = find(abccof(:,2)==1); 23 | noind = find(abccof(:,2)~=1); 24 | am = []; 25 | for ni = 1:numel(index) 26 | finput = cinput{index(ni)}; 27 | input = sim_inputdata(finput{1}); 28 | tmp_1 = []; 29 | tmp_2 = []; 30 | if abccof(index(ni),3)==1 31 | tmp_1 = input(:,1:2); 32 | end 33 | if abccof(index(ni),4)==1 34 | tmp_2 = input(:,1).*0+1; 35 | end 36 | tmp = [tmp_1 tmp_2]; 37 | % 38 | % 39 | [n,m] = size(am); 40 | [dn,dm] = size(tmp); 41 | data = zeros(n+dn,m+dm); 42 | if n > 0 && m >0 43 | data(1:n,1:m) = am; 44 | end 45 | data(n+1:n+dn,m+1:m+dm) = tmp; 46 | am = data; 47 | 48 | end 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /sim_mindist.m: -------------------------------------------------------------------------------- 1 | function dmin = sim_mindist(x,y,preset) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Developed by FWP,@BJ, 2010-01-01 10 | % 11 | if nargin<3 || isempty(preset)==1 12 | preset = 0.1; 13 | end 14 | if numel(x(:))>4 15 | p = [x(:) y(:)]; 16 | TRI = delaunay(x,y); 17 | % 18 | tri = TRI(:,[1:end 1]); 19 | dx = diff(reshape(p(tri,1),size(tri)),1,2); 20 | dy = diff(reshape(p(tri,2),size(tri)),1,2); 21 | dmin = sqrt(min(dx(:).^2+dy(:).^2)); 22 | else 23 | dmin = preset; 24 | end 25 | -------------------------------------------------------------------------------- /sim_mindistv2.m: -------------------------------------------------------------------------------- 1 | function mindist = sim_mindistv2(p) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % return the min distance from a set of points. 9 | % Created by Feng Wanpeng based on www.mathwork.com. 10 | tri = delaunay(p(:,1),p(:,2)); 11 | d2fun = @(k,l) sum((p(k,:)-p(l,:)).^2,2); 12 | d2tri = @(k) [d2fun(tri(k,1),tri(k,2)) ... 13 | d2fun(tri(k,2),tri(k,3)) ... 14 | d2fun(tri(k,3),tri(k,1))]; 15 | dtri = cell2mat(arrayfun(@(k) d2tri(k),... 16 | (1:size(tri,1))','UniformOutput',0)); 17 | mindist = sqrt(min(dtri(:))); 18 | -------------------------------------------------------------------------------- /sim_mkdist_model.m: -------------------------------------------------------------------------------- 1 | function outfpara = sim_mkdist_model(fpara,inrake,nx,ny) 2 | % 3 | % 4 | % 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | if nargin < 3 7 | nx = 4; 8 | ny = 6; 9 | end 10 | % 11 | index = sim_fpara2index_dep(fpara); 12 | % 13 | % 14 | nxmax = max(index(:,1)); 15 | nymax = max(index(:,2)); 16 | % 17 | outfpara = fpara; 18 | outfpara(:,8) = 0; 19 | outfpara(:,9) = 0; 20 | % 21 | for ni = 2:nx:nxmax-1 22 | % 23 | for nj = 2:ny:nymax-1 24 | % 25 | % 26 | xind = [ni-1,ni,ni+1]; 27 | yind = [nj-1,nj,nj+1]; 28 | % 29 | for nk = 1:numel(xind) 30 | for np = 1:numel(yind) 31 | % 32 | xind1 = index(:,1)==xind(nk); 33 | yind1 = index(:,2)==yind(np); 34 | ind = xind1 .* yind1; 35 | outfpara(ind==1,8) = cosd(inrake); 36 | outfpara(ind==1,9) = sind(inrake); 37 | 38 | end 39 | end 40 | 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /sim_mo2mw.m: -------------------------------------------------------------------------------- 1 | function mw=sim_mo2mw(mo,unit) 2 | % 3 | % 4 | % Developed by Wanpeng Feng, @NRCan, 2016-07-10 5 | % 6 | if nargin < 2 7 | unit = 'nm'; 8 | end 9 | switch upper(unit) 10 | case 'NM' 11 | mw = 2/3*log10(mo)-6.033; 12 | case 'DCM' 13 | mw = 2/3*log10(mo)-10.7; 14 | end 15 | -------------------------------------------------------------------------------- /sim_mw2fpara.m: -------------------------------------------------------------------------------- 1 | function [fpara,zone] = sim_mw2fpara(x,y,focal,mw,slip,depth,isutm) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, W.P., 2011/10/23 9 | % 10 | if nargin < 5 11 | slip = 2.0; 12 | end 13 | if nargin < 7 14 | isutm = 0; 15 | end 16 | % 17 | zone = []; 18 | if isutm==0 19 | [x,y,zone] = deg2utm(y,x); 20 | end 21 | [lens,wids] = sim_mw2length(mw,slip); 22 | % 23 | fpara = zeros(1,10); 24 | if isutm == 0 25 | fpara(1) = x./1000; 26 | fpara(2) = y./1000; 27 | else 28 | fpara(1) = x; 29 | fpara(2) = y; 30 | end 31 | fpara(3) = focal(1); 32 | fpara(4) = focal(2); 33 | fpara(6) = wids*2; 34 | fpara(7) = lens/2; 35 | fpara(8) = slip.*cosd(focal(3)); 36 | fpara(9) = slip.*sind(focal(3)); 37 | fpara(5) = depth; 38 | % 39 | -------------------------------------------------------------------------------- /sim_mw2length.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpfeng/psokinv/d35532b0bc3c0d257cb9c9a3550f75fae6f788d2/sim_mw2length.m -------------------------------------------------------------------------------- /sim_ndk2gmt.m: -------------------------------------------------------------------------------- 1 | function sim_ndk2gmt(ndk,outname,outdate) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by FWP, @ BJ, 2010-01-01 10 | % Modified by FWP, @ GU, 2013-04-01 11 | % 12 | if nargin < 1 13 | disp('sim_ndk2gmt(ndk,outname)'); 14 | return 15 | else 16 | if ischar(ndk) 17 | ndk = sim_inpndk(ndk); 18 | end 19 | end 20 | % 21 | % 22 | if nargin < 2 23 | outname = 'GCMT.ndk'; 24 | end 25 | if nargin < 3 26 | outdate = 1; 27 | end 28 | % 29 | fid = fopen(outname,'A'); 30 | for ni=1:size(ndk,2) 31 | if outdate == 1 32 | fprintf(fid,'%8.4f %7.4f %7.2f %6.2f %4.1f %6.2f %4.2f %8.4f %7.4f %s\n',ndk(ni).lon,... 33 | ndk(ni).lat,ndk(ni).depth,ndk(ni).str1,ndk(ni).dip1,... 34 | ndk(ni).rak1,ndk(ni).mag,ndk(ni).lon,ndk(ni).lat,ndk(ni).date); 35 | else 36 | fprintf(fid,'%8.4f %7.4f %7.2f %6.2f %4.1f %6.2f %4.2f %8.4f %7.4f\n',ndk(ni).lon,... 37 | ndk(ni).lat,ndk(ni).depth,ndk(ni).str1,ndk(ni).dip1,... 38 | ndk(ni).rak1,ndk(ni).mag,ndk(ni).lon,ndk(ni).lat); 39 | end 40 | end 41 | fclose(fid); 42 | -------------------------------------------------------------------------------- /sim_oksar2oversample.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_oksar2oversample(oksar,outoksar,iteration) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Developed by FWP, @ Vienna, 20130409 9 | % 10 | % 11 | if nargin < 3 12 | iteration = 2; 13 | end 14 | % 15 | [fpara,zone] = sim_openfault(oksar); 16 | 17 | iter = 0; 18 | while iter < iteration 19 | iter = iter + 1; 20 | mfpara = []; 21 | for ni = 1:numel(fpara(:,1)) 22 | cfpara = fpara(ni,:); 23 | dfpara = sim_fpara2dist(cfpara,cfpara(6),cfpara(7),cfpara(6)/2,cfpara(7)/2,'w',cfpara(5)); 24 | dfpara(:,8) = 0; 25 | dfpara(:,9) = 0; 26 | % 27 | for nj = 1 : 4 28 | dist = sqrt((dfpara(nj,1)-fpara(:,1)).^2+ (dfpara(nj,2)-fpara(:,2)).^2); 29 | [dist,indx] = sort(dist,'ascend'); 30 | dist = dist(1:10); 31 | indx = indx(1:10); 32 | % 33 | % 34 | % 35 | if fpara(ni,8)~=0 36 | dfpara(nj,8) = sum((fpara(indx,8).*(1./dist)) ./ sum(1./dist)); 37 | end 38 | if fpara(ni,9)~=0 39 | dfpara(nj,9) = sum((fpara(indx,9).*(1./dist)) ./ sum(1./dist)); 40 | end 41 | end 42 | mfpara = [mfpara;dfpara]; 43 | end 44 | fpara = mfpara; 45 | end 46 | % 47 | sim_fpara2simp(fpara,outoksar,zone); 48 | -------------------------------------------------------------------------------- /sim_oksar2psoksar.m: -------------------------------------------------------------------------------- 1 | function sim_oksar2psoksar(oksar,psoksar) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Convert the OKSAR file into PSOKSAR file 11 | % PSOKSAR, top and bot represent the vertical diretion to surface. 12 | % OKSAR, top and bot represent the dip direction along the WIDTH. 13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14 | % Modified by Feng, W.P, 2010-04-14 15 | % -> redefine oksar 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | fpara = sim_oksar2SIM(oksar); 18 | sim_fpara2psoksar(fpara,psoksar); 19 | -------------------------------------------------------------------------------- /sim_oksar2simp.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_oksar2simp(inoksar,simp) 2 | % 3 | % 4 | % 5 | % Developed by Feng, W.P., @NRCan, 2015-10-12 6 | % 7 | [fpara,zone] = sim_oksar2SIM(inoksar); 8 | sim_fpara2simp(fpara,simp,zone); 9 | % -------------------------------------------------------------------------------- /sim_oksar2utm.m: -------------------------------------------------------------------------------- 1 | function utmzone = sim_oksar2utm(oksarfile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Created by Feng, W.P., @ GU, 2012-08-12 11 | % 12 | utmzone = []; 13 | %oksarfile 14 | fid = fopen(oksarfile,'r'); 15 | while ~feof(fid) 16 | tline = fgetl(fid); 17 | if isempty(strfind(tline,'UTM'))==0 18 | tmp = textscan(tline,'%s %s','delimiter','---'); 19 | utmzone = MCM_rmspace(tmp{1}{1}); 20 | end 21 | end 22 | fclose(fid); 23 | -------------------------------------------------------------------------------- /sim_oksar4psokinvcfg.m: -------------------------------------------------------------------------------- 1 | function sim_oksar4psokinvcfg(psoksar,outcfg,rake) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % +Usage: 9 | % sim_psoksar4psokinvcfg(psoksar,outcfg) 10 | % +Input: 11 | % 12 | % Modification: 13 | % Feng, W.P, 2011-02-27 14 | % 15 | if nargin < 1 16 | disp('sim_oksar4psokinvcfg(psoksar,outcfg)'); 17 | return 18 | end 19 | if nargin < 2 20 | outcfg = 'PSOKINV.cfg'; 21 | end 22 | if nargin < 3 23 | rake = [-135,-45]; 24 | end 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | fpara = sim_oksar2SIM(psoksar); 27 | nfaults = size(fpara,1); 28 | isinv = zeros(nfaults,10)+1; 29 | inpara = zeros(nfaults,10,3); 30 | inpara(:,:,1) = fpara(:,:); 31 | inpara(:,:,2) = fpara(:,:)-5; 32 | inpara(:,:,3) = fpara(:,:)+5; 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | sim_invconfig(outcfg,nfaults,[],isinv,... 35 | [],[],[],[],[],... 36 | [],[],[],[],... 37 | [],[],[],[],[],inpara,[],[],rake); 38 | -------------------------------------------------------------------------------- /sim_oksargreenRAKE.m: -------------------------------------------------------------------------------- 1 | function green = sim_oksargreenRAKE(fpara,input,thd,alp,rake) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | %format long 12 | x = input(:,1); 13 | y = input(:,2); 14 | % 15 | ndim = size(fpara,1); 16 | nraw = size(x,1); 17 | % 18 | sgreen = zeros(nraw,ndim); 19 | dgreen = sgreen; 20 | % 21 | for nd = 1:ndim 22 | fpara(nd,8) = 1; 23 | fpara(nd,9) = 0; 24 | fpara(nd,10)= 0; 25 | dis = multiokadaALP(fpara(nd,:),x,y,0,alp,thd); 26 | sim = dis.E.*input(:,4)+dis.N.*input(:,5)+dis.V.*input(:,6); 27 | sgreen(:,nd)= sim; 28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 29 | fpara(nd,8) = 0; 30 | fpara(nd,9) = 1; 31 | dis = multiokadaALP(fpara(nd,:),x,y,0,alp,thd); 32 | sim = dis.E.*input(:,4)+dis.N.*input(:,5)+dis.V.*input(:,6); 33 | dgreen(:,nd)= sim; 34 | end 35 | green = [sgreen.*cosd(rake)+dgreen.*sind(rake)]; 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sim_openfault.m: -------------------------------------------------------------------------------- 1 | function [fpara,zone] = sim_openfault(inoksar) 2 | % 3 | % 4 | % Developed by Wanpeng Feng, @NRCan, 2016-06-07 5 | % 6 | if nargin < 1 7 | disp('[fpara,zone] = sim_openfault(inoksar)') 8 | return 9 | end 10 | [tmp,tname,text] = fileparts(inoksar); 11 | % 12 | switch upper(text) 13 | case '.SIMP' 14 | [fpara,zone] = sim_simp2fpara(inoksar); 15 | case '.OKSAR' 16 | [fpara,zone] = sim_oksar2SIM(inoksar); 17 | end 18 | -------------------------------------------------------------------------------- /sim_ouputinp.m: -------------------------------------------------------------------------------- 1 | function sim_ouputinp(inp,outname) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % created by FWP, @ 2012-10-10 10 | fid = fopen(outname,'w'); 11 | fprintf(fid,'%12.6f%12.6f%12.6f%12.6f%12.6f%12.6f%12.6f\n',inp'); 12 | fclose(fid); 13 | -------------------------------------------------------------------------------- /sim_p2p.m: -------------------------------------------------------------------------------- 1 | function op = sim_p2p(point,strike,length) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Developed by FWP,@gU, 2009-10-01 9 | % calculate coordinates using fpara format (fault geometry) based on the 10 | % azimuth and distance 11 | % Input: 12 | % point, (x,y) 13 | % strike, azimuth angle 14 | % length, distance 15 | % 16 | fpara = [point(1),point(2),strike,90,0,1,2*length,0,0,0]; 17 | [x0,y0,zone ] = deg2utm(point(2),point(1)); 18 | [x1,y1] = sim_fpara2corners(fpara,'ur','LL','LL',zone); 19 | % 20 | op = [x1,y1]; 21 | -------------------------------------------------------------------------------- /sim_para2rsc.m: -------------------------------------------------------------------------------- 1 | function sim_para2rsc(outname,region,ps) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Develped by FWP,@BJ, 2010-01-01 9 | % Create a rsc header file based on input ROI 10 | % 11 | % region, [minlon,maxlon,minlat,maxlat] 12 | % ps, [sizelon,sizelat], pixel size... 13 | % 14 | if nargin < 1 15 | outname = 'TEST.img.rsc'; 16 | end 17 | info = sim_roirsc(); 18 | info.x_first = region(1); 19 | info.y_first = region(4); 20 | info.x_step = ps(1); 21 | info.y_step = abs(ps(2))*-1; 22 | info.width = ceil((region(2)-region(1))/ps(1)); 23 | info.file_length = ceil((region(4)-region(3))/ps(2)); 24 | info.xmax = info.width - 1; 25 | info.ymax = info.file_length - 1; 26 | sim_croirsc(outname,info); 27 | -------------------------------------------------------------------------------- /sim_paraest.m: -------------------------------------------------------------------------------- 1 | function [sigma,mu,a] = sim_paraest(fpara,ndix,samples,isfigs) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | if nargin <=2 || isempty(samples)==1 11 | samples = 100; 12 | end 13 | if nargin <=3 || isempty(isfigs)==1 14 | isfigs = 0; 15 | end 16 | [yout,xout] = hist(fpara(:,ndix),samples); 17 | xout = xout(:); 18 | yout = yout(:); 19 | [sigma,mu,a] = sim_gaussianfit(xout,yout); 20 | ynew = a.*exp(-(xout-mu).^2./(2*sigma^2)); 21 | % 22 | if isfigs==1 23 | hist(fpara(:,ndix),samples); 24 | hold on 25 | plot(xout,yout,'o-r'); 26 | hold on 27 | plot(xout,ynew,'o-b'); 28 | legend({'Obv','Est'}); 29 | end 30 | 31 | 32 | -------------------------------------------------------------------------------- /sim_passingparameters.m: -------------------------------------------------------------------------------- 1 | % 2 | % sim_passingparameters.m 3 | % New version for passing parameters for a m-function 4 | % 5 | %************** FWP Work ************************ 6 | %Developed by FWP, @UoG/CEA, 2007-2014 7 | % contact by wanpeng.feng@hotmail.com 8 | %************** Good Luck *********************** 9 | %% ge_parse_pairs 10 | % helper function allowing named generic name value parameter passing 11 | if rem(numel(varargin),2)~=0 12 | disp(' Please check Input parameters. Current input is not in a good shape!!!'); 13 | return 14 | end 15 | % 16 | for ni = 1:2:numel(varargin) 17 | mypara = varargin{ni}; 18 | myval = varargin{ni+1}; 19 | eval([mypara,'=myval;']); 20 | end 21 | -------------------------------------------------------------------------------- /sim_pre4smestGRN.m: -------------------------------------------------------------------------------- 1 | function [disfpara,G,lap,lb,ub] = sim_pre4smestGRN(fpara,input,dx,dy,... 2 | L,W,topdepth,whichnon,alp) 3 | % 4 | %************** FWP Work ************************ 5 | %Developed by FWP, @GU/BJ, 2007-2014 6 | % contact by wanpeng.feng@hotmail.com 7 | %************** Good Luck *********************** 8 | 9 | % 10 | % Purpose: 11 | % Inversion distributed slip model using LS Algorithm with boudary 12 | % constraints. 13 | % Input: 14 | % fpara, the uniform fault model 15 | % input, the input data 16 | % dx,dy,L,W, the sub-patch fault size and whole fault scale size 17 | % lamd, the control factor for smooth constraints 18 | % lb,ub, the boudary constraints bottom and up boudary. 19 | % wpara, the value of weight parameters,1 for 20 | % Output: 21 | % fpara, the distributed slip model 22 | % osim, the simulation result 23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 24 | %%% Calculate the G 25 | % 26 | thd = 0; 27 | [G,disfpara,lap,lb,ub] = sim_fpara4G(fpara,dx,dy,L,W,topdepth,input,thd,alp,whichnon); 28 | % 29 | % 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | 32 | -------------------------------------------------------------------------------- /sim_pre4triest.m: -------------------------------------------------------------------------------- 1 | function [trif,Lapm,lbs,lbd,ubs,ubd,info,rfpara] = sim_pre4triest(fpara,l,w,dl,dw,maxarea,topdepth) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by W.P, Feng, July-30-2010 10 | % part of TRIANGULAR inversion model... 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | if nargin < 6 14 | maxarea = 5; 15 | end 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | rfpara = []; 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | % 20 | for ni = 1:size(fpara(1:end,:),1); 21 | tfpara = fpara(ni,:); 22 | tfpara = sim_fpara2whole(tfpara); 23 | rfpara = [rfpara;sim_fpara2dist(tfpara,l(ni),w(ni),dl(ni),dw(ni),'d')]; 24 | end 25 | % 26 | [trif,~,info] = sim_tri(rfpara,'maxlength',max([dl;dw]).*3.0,'maxarea',maxarea,'isshow',0); 27 | [Lapm,lbs,lbd,ubs,ubd] = sim_trif2lap(trif,topdepth); 28 | lbs = lbs.*0; 29 | lbd = lbd.*0; 30 | ubs = (abs(ubs) == min(abs(ubs))).*0 + ... 31 | (abs(ubs) > min(abs(ubs))).*1000; 32 | ubd = (abs(ubd) == min(abs(ubd))).*0 + ... 33 | (abs(ubd) > min(abs(ubd))).*1000; 34 | -------------------------------------------------------------------------------- /sim_psoksar2SIM.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_psoksar2SIM(inpf) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % inpf, top and bot should represent the depth along the vertical direction. 9 | % in PSOKSAR format. 10 | % Wrote by Feng W.P, 27 July 2009 11 | % 12 | % 13 | [xlim,ylim,lamd,vect,cxy,focal,slip,fgeo,k] = sim_input2li(inpf); 14 | % 15 | fpara = zeros(k,10); 16 | for ni = 1:k 17 | fpara(ni,1) = cxy(ni,1)/1000; 18 | fpara(ni,2) = cxy(ni,2)/1000; 19 | fpara(ni,3) = focal(ni,1); 20 | fpara(ni,4) = focal(ni,2); 21 | fpara(ni,5) = fgeo(ni,2); 22 | fpara(ni,6) = (fgeo(ni,3)-fgeo(ni,2))/sind(focal(ni,2)); 23 | fpara(ni,7) = fgeo(ni,1); 24 | fpara(ni,8) = slip(ni,1)*cosd(focal(ni,3)); 25 | fpara(ni,9) = slip(ni,1)*sind(focal(ni,3)); 26 | fpara(ni,10)= slip(ni,2); 27 | fpara(ni,:) = sim_cc2uc(fpara(ni,:)); 28 | end 29 | 30 | 31 | -------------------------------------------------------------------------------- /sim_psoksar2oksar.m: -------------------------------------------------------------------------------- 1 | function sim_psoksar2oksar(psoksar,oksar) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Convert the PSOOKSAR file into OKSAR file 11 | % PSOKSAR, top and bot represent the vertical diretion to surface. 12 | % OKSAR, top and bot represent the dip direction along the WIDTH. 13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14 | % Modified by Feng, W.P, 2010-04-14 15 | % -> redefine oksar 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | fpara = sim_psoksar2SIM(psoksar); 18 | sim_fpara2oksar(fpara,oksar); 19 | -------------------------------------------------------------------------------- /sim_psoksar4psokinvcfg.m: -------------------------------------------------------------------------------- 1 | function sim_psoksar4psokinvcfg(psoksar,outcfg,rake) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % +Usage: 9 | % sim_psoksar4psokinvcfg(psoksar,outcfg) 10 | % +Input: 11 | % 12 | % Modification: 13 | % Feng, W.P, 2011-02-27 14 | % 15 | if nargin < 1 16 | disp('sim_psoksar4psokinvcfg(psoksar,outcfg)'); 17 | return 18 | end 19 | if nargin < 2 20 | outcfg = 'PSOKINV.cfg'; 21 | end 22 | if nargin < 3 23 | rake = [-135,-45]; 24 | end 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | fpara = sim_psoksar2SIM(psoksar); 27 | nfaults = size(fpara,1); 28 | isinv = zeros(nfaults,10); 29 | inpara = zeros(nfaults,10,3); 30 | inpara(:,:,1) = fpara(:,:); 31 | inpara(:,:,2) = fpara(:,:); 32 | inpara(:,:,3) = fpara(:,:); 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | sim_invconfig(outcfg,nfaults,[],isinv,... 35 | [],[],[],[],[],... 36 | [],[],[],[],... 37 | [],[],[],[],[],inpara,[],[],rake); 38 | -------------------------------------------------------------------------------- /sim_psov2dataset.m: -------------------------------------------------------------------------------- 1 | function [osim,objv,input,inpfile] = sim_psov2dataset(fpara,dataset,alpha) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | inpfile = dataset.fname; 11 | input = load(inpfile); 12 | if nargin<3 || isempty(alpha)==1 13 | alpha = 0.5; 14 | end 15 | green = sim_oksargreenALP(fpara,input,0,alpha); 16 | am = input(:,1:3); 17 | am(:,3) = 1; 18 | abc = [dataset.a;dataset.b;dataset.c]; 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | [n,m] = size(green); 21 | [dn,dm] = size(am); 22 | A = zeros(n,m+dm); 23 | A(1:n,1:m) = green; 24 | A(1:dn,m+1:m+dm) = am; 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | osim = A*[fpara(:,8);fpara(:,9);abc]; 27 | objv = aqrt(sum((osim-input(:,3)).^2)/numel(input(:,3))); 28 | -------------------------------------------------------------------------------- /sim_quickshow.m: -------------------------------------------------------------------------------- 1 | function input = sim_quickshow(inputfile,zone) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Purpose: 9 | % quick map the inp data by pcolor... 10 | % Modification History: 11 | % Feng, W.P, 2010-01,created. 12 | % Feng, W.P, 2010-11-29,add zone, a new option 13 | % -> permit to convert the coordinates into LL. 14 | % 15 | if nargin < 2 16 | zone = 'NULL'; 17 | end 18 | % 19 | [~,fname] = fileparts(inputfile); 20 | input = sim_inputdata(inputfile); 21 | x = input(:,1); 22 | y = input(:,2); 23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 24 | if strcmpi(zone,'NULL')~=1 25 | [cx,cy] = utm2deg(x.*1000,y.*1000,zone); 26 | x = cy; 27 | y = cx; 28 | end 29 | mindist = sim_mindistv2([x(:) y(:)]); 30 | np = size(x(:),1); 31 | XI = zeros(np,5); 32 | YI = zeros(np,5); 33 | XI(:,1) = x-mindist/2; 34 | XI(:,2) = x+mindist/2; 35 | XI(:,3) = x+mindist/2; 36 | XI(:,4) = x-mindist/2; 37 | XI(:,5) = x-mindist/2; 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 39 | YI(:,1) = y-mindist/2; 40 | YI(:,2) = y-mindist/2; 41 | YI(:,3) = y+mindist/2; 42 | YI(:,4) = y+mindist/2; 43 | YI(:,5) = y-mindist/2; 44 | %disp('FENG W.P...'); 45 | hold on 46 | %sim_fig3d(fpara); 47 | %figure(); 48 | %subplot(ndata,1,nf); 49 | patch(XI',YI',input(:,3)'); 50 | title(fname); 51 | colorbar; 52 | caxis([min(input(:,3)),max(input(:,3))]); 53 | xlim = get(gca,'XLim'); 54 | ylim = get(gca,'YLim'); 55 | axis equal; 56 | set(gca,'XLim',xlim); 57 | set(gca,'YLim',ylim); 58 | box on; 59 | -------------------------------------------------------------------------------- /sim_rakelbub.m: -------------------------------------------------------------------------------- 1 | function [lb,ub] = sim_rakelbub(fpara,wich) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by Feng, W.P, 2010-10-13 10 | % 11 | % 12 | lb = zeros(size(fpara,1),1); 13 | ub = lb + 10^4; 14 | % updated by FWP, @ GU, 2013-03-13 15 | index = sim_fpara2sortv2(fpara); 16 | % 17 | ub(index(:,1)==min(index(:,1))) = 0.0000001; 18 | ub(index(:,1)==max(index(:,1))) = 0.0000001; 19 | ub(index(:,2)==min(index(:,2))) = 0.0000001; 20 | ub(index(:,2)==max(index(:,2))) = 0.0000001; 21 | % 22 | % 23 | if isempty(wich) ~= 1 24 | nsize = size(wich,2); 25 | for ni= 1:nsize 26 | % 27 | switch wich{ni} 28 | case 'B' 29 | ub(index(:,2)==max(index(:,2))) = 10^4; 30 | case 'U' 31 | ub(index(:,2)==min(index(:,2))) = 10^4; 32 | case 'L' 33 | ub(index(:,1)==min(index(:,1))) = 10^4; 34 | case 'R' 35 | ub(index(:,1)==max(index(:,1))) = 10^4; 36 | end 37 | end 38 | end 39 | lb = [lb ;lb]; 40 | ub = [ub ;ub]; 41 | -------------------------------------------------------------------------------- /sim_readdlc.m: -------------------------------------------------------------------------------- 1 | function [fpara,zone] = sim_readdlc(indlc) 2 | % 3 | % 4 | % read slip model from Yuri's DLC slip model 5 | % 6 | fpara = []; 7 | fid = fopen(indlc,'r'); 8 | % 9 | % jump a line 10 | fgetl(fid); 11 | % 12 | while ~feof(fid) 13 | tline = fgetl(fid); 14 | tmp = textscan(tline,'%f'); 15 | tmp = tmp{1}; 16 | cfpara = [tmp(2),tmp(3),tmp(5),tmp(6),tmp(4),tmp(8),tmp(7),tmp(9),tmp(10),tmp(11)]; 17 | fpara = [fpara;cfpara]; 18 | end 19 | % 20 | fclose(fid); 21 | % 22 | mlon = mean(fpara(:,1)); 23 | mlat = mean(fpara(:,2)); 24 | % 25 | [x0,y0,zone] = deg2utm(mlat,mlon); 26 | % 27 | [x,y] = deg2utm(fpara(:,1),fpara(:,2),zone); 28 | fpara(:,1) = x./1000; 29 | fpara(:,2) = y./1000; 30 | % 31 | % fpara = sim_fparaconv(fpara,1,0); -------------------------------------------------------------------------------- /sim_readedcmp.m: -------------------------------------------------------------------------------- 1 | function data = sim_readedcmp(edfile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | fid = fopen(edfile,'r'); 10 | % 11 | % jump 3 rows 12 | fgetl(fid); 13 | fgetl(fid); 14 | fgetl(fid); 15 | % 16 | data = zeros(1,5); 17 | counter = 0; 18 | while ~feof(fid) 19 | 20 | temp = textscan(fid,'%f %f %f %f %f\n'); 21 | if isempty(temp{1})==0 22 | counter = counter + 1; 23 | data(counter,:) = [temp{1},temp{2},temp{3},temp{4},temp{5}]; 24 | end 25 | end 26 | fclose(fid); 27 | -------------------------------------------------------------------------------- /sim_readenvi.m: -------------------------------------------------------------------------------- 1 | function [data,gridinfo,dims,hdrfile] = sim_readenvi(imgf) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Input ENVI-format data file 10 | % gridinfo, including 4 parts: 11 | % 1- xstart 12 | % 2- ystart 13 | % 3- xpixel 14 | % 4- ypixel 15 | % 16 | [impath,imname] = fileparts(imgf); 17 | hdrfile = fullfile(impath,[imname,'.hdr']); 18 | % 19 | fid = fopen(hdrfile); 20 | while feof(fid)~=1 21 | tlines = fgetl(fid); 22 | index = findstr(tlines,'samples ='); 23 | if isempty(index)~=1 24 | tmp = textscan(tlines,'%s %s %s'); 25 | sample= str2double(tmp{3}); 26 | end 27 | index = findstr(tlines,'lines ='); 28 | if isempty(index)~=1 29 | tmp = textscan(tlines,'%s %s %s'); 30 | lines = str2double(tmp{3}); 31 | end 32 | index = findstr(tlines,'map info ='); 33 | if isempty(index)~=1 34 | tmp = textscan(tlines,'%s %s %s %s %s %s %s %s %s %s'); 35 | xstart = str2double(tmp{7})/1000.; 36 | ystart = str2double(tmp{8})/1000.; 37 | xpixel = str2double(tmp{9})/1000.; 38 | ypixel = str2double(tmp{10})/1000; 39 | % 40 | end 41 | 42 | end 43 | fclose(fid); 44 | % 45 | %data = zeros(lines,sample); 46 | fid = fopen(imgf); 47 | data = fread(fid,[sample,lines],'float32'); 48 | fclose(fid); 49 | % 50 | gridinfo = [xstart,ystart,xpixel,ypixel]; 51 | dims = [sample,lines]; 52 | % 53 | %imagesc(atan2(sin(data'),cos(data'))); 54 | 55 | -------------------------------------------------------------------------------- /sim_readgmtlines.m: -------------------------------------------------------------------------------- 1 | function cellsegments = sim_readgmtlines(inp,isplot) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % + Purpose: 9 | % input GMT format with flat ">" line or polygon data into matlab 10 | % + LOG: 11 | % created by Feng, Wanpeng, 20110410 12 | % 13 | % 14 | if nargin < 2 15 | isplot = 0; 16 | end 17 | fid = fopen(inp,'r'); 18 | ncell = 0; 19 | points = []; 20 | cellsegments = cell(1); 21 | while ~feof(fid) 22 | tlines = fgetl(fid); 23 | if isempty(findstr(tlines,'>'))==0 24 | if ncell >= 1 25 | cellsegments{ncell} = points; 26 | points = []; 27 | end 28 | ncell = ncell + 1; 29 | else 30 | tmp = textscan(tlines,'%f %f'); 31 | points = [points;tmp{1},tmp{2}]; 32 | end 33 | end 34 | cellsegments{ncell} = points; 35 | fclose(fid); 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 | if isplot ~= 0 38 | for ni = 1:ncell 39 | tlines = cellsegments{ni}; 40 | plot(tlines(:,1),tlines(:,2),'-or'); 41 | hold on 42 | end 43 | axis equal 44 | end 45 | -------------------------------------------------------------------------------- /sim_readme_on_givenfaults.m: -------------------------------------------------------------------------------- 1 | function sim_readme_on_givenfaults() 2 | 3 | % 4 | % 5 | % 6 | % 7 | disp(" # Slip Inversion bound Constraints, a simp file or NULL "); 8 | disp(" once given, the fault(:,8) is for the upper bounary"); -------------------------------------------------------------------------------- /sim_readweights.m: -------------------------------------------------------------------------------- 1 | function weights = sim_readweights(newweights) 2 | % 3 | % 4 | % 5 | % 6 | weights = 1; 7 | % 8 | if nargin < 1 9 | newweights = []; 10 | end 11 | % 12 | if exist('weight.info','file') 13 | fid = fopen('weight.info','r'); 14 | tline = textscan(fid,'%s %f\n'); 15 | % 16 | if isempty(newweights) 17 | newweights = tline{2}; 18 | end 19 | % 20 | weights = []; 21 | for ni = 1:numel(tline{2}) 22 | % 23 | file = tline{1}{ni}; 24 | input = load(file); 25 | weights = [weights;input(:,1).*0+newweights(ni)]; 26 | % 27 | end 28 | fclose(fid); 29 | end 30 | -------------------------------------------------------------------------------- /sim_remcinpf.m: -------------------------------------------------------------------------------- 1 | function cinf = sim_remcinpf(cinf,mcdir,fismc,noloops) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Developed by fWP, @IGP/CEA & GU, 2009/05/01 9 | % Improved by FWP, @GU, 2014-05-18 10 | % 11 | % 12 | nf = numel(cinf); 13 | t = cell(1,1); 14 | % 15 | for ni=1:nf 16 | if fismc(ni)==1 17 | fname = cinf{ni}; 18 | [~,bname,postfix] = fileparts(fname{1}); 19 | fname = fullfile(mcdir{1}{1},[bname '_MC_' num2str(noloops) postfix]); 20 | t{1} = fname; 21 | cinf{ni} = t; 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /sim_rmduplicate.m: -------------------------------------------------------------------------------- 1 | function outfpara = sim_rmduplicate(fpara) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | typefpara = fpara(:,1).*0.15 + ... 11 | fpara(:,2).*0.15 + ... 12 | fpara(:,3).*0.15 + ... 13 | fpara(:,4).*0.15 + ... 14 | fpara(:,5).*0.15 + ... 15 | fpara(:,6).*0.15 + ... 16 | fpara(:,7).*0.15 + ... 17 | fpara(:,8).*0.15 + ... 18 | fpara(:,9).*0.15; 19 | % 20 | outtype = unique(typefpara); 21 | if numel(outtype)==numel(typefpara) 22 | outfpara = fpara; 23 | return 24 | else 25 | outfpara = zeros(numel(outtype),10); 26 | for ni = 1:numel(outtype); 27 | index = find(typefpara == outtype(ni)); 28 | outfpara(ni,:) = fpara(index(1),:); 29 | end 30 | end 31 | 32 | 33 | -------------------------------------------------------------------------------- /sim_rms.m: -------------------------------------------------------------------------------- 1 | function rms = sim_rms(d1,d2) 2 | % 3 | % 4 | % Created by Feng,W.P.,@ UoG, 2012-11-18 5 | % Updated by FWP, @ UoG, 2013-04-18 6 | % 7 | if nargin > 1 8 | rms = sqrt(sum((d1-d2).^2)/numel(d1)); 9 | else 10 | rms = sqrt(sum(d1.^2)/numel(d1)); 11 | end 12 | -------------------------------------------------------------------------------- /sim_rmspace.m: -------------------------------------------------------------------------------- 1 | function stringout=sim_rmspace(stringin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Purpose: 9 | % To remove all blank in a string. 10 | % The Author, Shi Yuzhen && Feng Wanpeng, IAP & IGP 11 | % Release time: 2007/05/08 12 | 13 | indspace=strfind(stringin,' '); 14 | if isempty(indspace)==1 15 | stringout=stringin; 16 | elseif isempty(indspace)==0 17 | num=size(indspace,2); 18 | if num==1 19 | stringout=[stringin(1:indspace-1),stringin(indspace+1:length(stringin))]; 20 | elseif num >1 21 | temp=stringin(1:indspace(1)-1); 22 | for i=2:num 23 | temp=[temp,stringin(indspace(i-1)+1:indspace(i)-1)]; 24 | end 25 | stringout=[temp,stringin(indspace(num)+1:length(stringin))]; 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /sim_roi2dsmcfg.m: -------------------------------------------------------------------------------- 1 | function sim_roi2dsmcfg(in_roi,outdsmcfg,zone) 2 | % 3 | % Create a dsm configure file automatically 4 | % 5 | % Created by Wanpeng Feng, @NRCan, 2017-08-29 6 | % 7 | if nargin < 2 8 | disp('sim_roi2dsmcfg(in_roi,outdsmcfg)') 9 | return 10 | end 11 | if nargin < 3 12 | zone = 'NONE'; 13 | end 14 | phs = in_roi; 15 | [fdir,fname,fext] = fileparts(phs); 16 | % 17 | if isempty(fdir) 18 | fdir = '.'; 19 | end 20 | % 21 | inc = dir([fdir,'/',fname,'.inc']); 22 | azi = dir([fdir,'/',fname,'.azi']); 23 | if length(inc) == 0 %#ok 24 | inc = dir([fdir,'/*.inc']); 25 | azi = dir([fdir,'/*.azi']); 26 | end 27 | inc = [fdir,'/',inc(1).name]; 28 | azi = [fdir,'/',azi(1).name]; 29 | % 30 | if strcmpi(zone,'NONE') 31 | zone = MCM_rmspace(sar_rsc2zone([phs,'.rsc'],'cc')); 32 | end 33 | outname = fname; 34 | sim_dsmcfg(outdsmcfg,'unwfile',{phs},'incfile',{inc},'azifile',{azi},... 35 | 'outname',{outname},'zone',zone); 36 | % -------------------------------------------------------------------------------- /sim_roi2rsc.m: -------------------------------------------------------------------------------- 1 | function sim_roi2rsc(roi,xinc,outname,inc,azi) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Createf by Feng, W.P., 2011-10-23, @ GU 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | if nargin < 2 12 | xinc = 0.0008333; 13 | end 14 | if nargin < 4 15 | inc = 24; 16 | end 17 | if nargin < 5 18 | azi = -166.7; 19 | end 20 | % 21 | info = sim_roirsc(); 22 | info.x_first = roi(1); 23 | info.y_first = roi(4); 24 | info.x_step = xinc; 25 | info.y_step = -1*xinc; 26 | info.width = ceil((roi(2)-roi(1))./xinc); 27 | info.file_length = ceil((roi(4)-roi(3))./xinc); 28 | info.xmax = info.width - 1; 29 | info.ymax = info.file_length - 1; 30 | info.heading_deg = azi; 31 | info.incidence = inc; 32 | % 33 | sim_croirsc(outname,info); 34 | % 35 | 36 | -------------------------------------------------------------------------------- /sim_roi2rsc_v2.m: -------------------------------------------------------------------------------- 1 | function sim_roi2rsc_v2(roi,xinc,yinc,outname,inc,azi,varargin) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Createf by Feng, W.P., 2011-10-23, @ GU 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | if nargin < 2 12 | xinc = 0.0008333; 13 | end 14 | if nargin < 3 15 | yinc = 0.0008333; 16 | end 17 | if nargin < 5 18 | inc = 24; 19 | end 20 | if nargin < 6 21 | azi = -166.7; 22 | end 23 | % 24 | 25 | % updated by FWP, @SYSU, Guanghzou, 2021/0613 26 | lamda = 0.05600; 27 | for ni = 1:2:numel(varargin) 28 | % 29 | par = varargin{ni}; 30 | val = varargin{ni+1}; 31 | eval([par,'=val;']); 32 | end 33 | % 34 | info = sim_roirsc(); 35 | info.wavelength = lamda; 36 | info.x_first = roi(1); 37 | info.y_first = roi(4); 38 | info.x_step = xinc; 39 | info.y_step = -1*yinc; 40 | % 41 | % modified by FWP, @SYSU, 2021/06/13 42 | info.width = ceil((roi(2)-roi(1))./xinc)+1; 43 | info.file_length = ceil((roi(4)-roi(3))./yinc)+1; 44 | info.xmax = info.width - 1; 45 | info.ymax = info.file_length - 1; 46 | info.heading_deg = azi; 47 | info.incidence = inc; 48 | % 49 | sim_croirsc(outname,info); 50 | % 51 | 52 | -------------------------------------------------------------------------------- /sim_rotaxs.m: -------------------------------------------------------------------------------- 1 | function [cx,cy] = sim_rotaxs(x0,y0,strike,dip,cx0,cy0) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created by Feng,W.P, 2009-01-01 10 | % 11 | if nargin < 5 12 | cx0 = 0; 13 | end 14 | if nargin < 6 15 | cy0 = 0; 16 | end 17 | i = sqrt(-1); 18 | strkr = (90-strike).*pi/180; 19 | % 20 | start = (cx0+cy0*i); 21 | outdata = ((x0+y0.*i)-start).*exp(-i*strkr); 22 | cx = real(outdata); 23 | cy = imag(outdata).*cosd(dip); 24 | 25 | -------------------------------------------------------------------------------- /sim_sarerror.m: -------------------------------------------------------------------------------- 1 | function [phserror deferror] = sim_sarerror(deltaDEM,baseline,lamda,sathigh,incidence) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | if nargin<1 || isempty(deltaDEM)==1 11 | 12 | disp('sim_sarerror(deltaDEM,baseline,lamda)'); 13 | disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); 14 | disp('>> deltaDEM, the error of DEM'); 15 | disp('>> baseline, the perpandicular baseline, m'); 16 | disp('>> lamda, the wavelength of the satellite, m'); 17 | disp('>> sathigh, the high of the satellite, m'); 18 | disp('>> incidence, the sight of light, deg'); 19 | disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); 20 | disp('So, you must give DEM error size.'); 21 | return 22 | end 23 | if nargin<2|| isempty(baseline)==1 24 | disp('sim_sarerror(deltaDEM,baseline,lamda)'); 25 | disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); 26 | disp('>> deltaDEM, the error of DEM'); 27 | disp('>> baseline, the perpandicular baseline'); 28 | disp('>> lamda, the wavelength of the satellite'); 29 | disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); 30 | disp('So, you must give the perpendicular baseline'); 31 | return 32 | end 33 | if nargin<3|| isempty(lamda)==1 34 | lamda = 0.05623; 35 | end 36 | if nargin<4|| isempty(sathigh)==1 37 | sathigh = 0.7899368582E+06; 38 | end 39 | if nargin<5|| isempty(incidence)==1 40 | incidence = 23; 41 | end 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 43 | pi = 3.1415926535897932384626433832795; 44 | phserror = 4*pi./lamda.*(baseline.*deltaDEM)./(sathigh.*sind(incidence)); 45 | deferror = (baseline.*deltaDEM)./(sathigh.*sind(incidence)); 46 | 47 | 48 | -------------------------------------------------------------------------------- /sim_shengjislip2simp.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_shengjislip2simp(inshengji,outsimp,refzone,dx,dy) 2 | % 3 | % 4 | % 5 | % Read a USGS simple slip model 6 | % Developed by Feng, W.P., @ NRCan, 2015-10-07 7 | % 8 | data = load(inshengji); 9 | % 10 | [x,y] = deg2utm(data(:,1),data(:,2),refzone); 11 | x = x./1000; 12 | y = y./1000; 13 | % 14 | fpara = [x(:),y(:),data(:,6),data(:,7),data(:,3),x(:).*0+dy,x(:).*0+dx,... 15 | data(:,4).*cosd(data(:,5))./100,data(:,4).*sind(data(:,5))./100,x(:).*0]; 16 | % 17 | % convert centroid slip model to that with the reference on the top centre 18 | fpara = sim_fparaconv(fpara,3,0); 19 | % 20 | sim_fpara2simp(fpara,outsimp,refzone); 21 | % -------------------------------------------------------------------------------- /sim_shiftfpara.m: -------------------------------------------------------------------------------- 1 | function nfpara = sim_shiftfpara(fpara,lshift,dirs) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Usage: 9 | % nfpara = sim_shiftfpara(fpara,lshift,dirs) 10 | % Input: 11 | % fpara, the n*10, fault model 12 | % lshift, shift length,km 13 | % dirs, direction, the switch flag:1 for right;-1 for left; 14 | % Ouput: 15 | % nfpara, the fault model after shift 16 | % Modification History: 17 | % Feng, Wanpeng, 2010-11-29, created 18 | % 19 | if nargin < 1 20 | disp('nfpara = sim_shiftfpara(fpara,lshift,dirs)'); 21 | nfpara = []; 22 | return 23 | end 24 | if nargin < 3 25 | dirs = 1; 26 | end 27 | nfpara = fpara; 28 | for ni = 1:numel(fpara(:,1)) 29 | cfpara = fpara(ni,:); 30 | cfpara(7) = lshift*2; 31 | if dirs == -1 32 | [x,y] = sim_fpara2corners(cfpara,'ul'); 33 | else 34 | [x,y] = sim_fpara2corners(cfpara,'ur'); 35 | end 36 | cfpara(1) = x; 37 | cfpara(2) = y; 38 | cfpara(7) = fpara(ni,7); 39 | nfpara(ni,:) = cfpara; 40 | end 41 | 42 | -------------------------------------------------------------------------------- /sim_showinpdata.m: -------------------------------------------------------------------------------- 1 | function sim_showinpdata(inpdata) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | input = sim_inputdata(inpdata); 10 | x = input(:,1); 11 | y = input(:,2); 12 | mindist = sim_mindistv2([x(:) y(:)]); 13 | np = size(x(:),1); 14 | XI = zeros(np,5); 15 | YI = zeros(np,5); 16 | XI(:,1) = x-mindist/2; 17 | XI(:,2) = x+mindist/2; 18 | XI(:,3) = x+mindist/2; 19 | XI(:,4) = x-mindist/2; 20 | XI(:,5) = x-mindist/2; 21 | % 22 | YI(:,1) = y-mindist/2; 23 | YI(:,2) = y-mindist/2; 24 | YI(:,3) = y+mindist/2; 25 | YI(:,4) = y+mindist/2; 26 | YI(:,5) = y-mindist/2; 27 | whos XI 28 | whos YI 29 | patch(XI',YI',input(:,3)'); 30 | -------------------------------------------------------------------------------- /sim_showoksar.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_showpsoksar(psoksarfile,ishow) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Function: 10 | % Input the fault model in psoksar format. 11 | % Input: 12 | % psoksarfile, the full file path (or current dir) 13 | % ishow, 0,no show in 3d projection;1,show in 3d projection 14 | % Output: 15 | % fpara, the fault model in SIM format 16 | % figure, if you set "ishow" equal 1, you will get a figure to show 17 | % model in 3d 18 | % Created by Feng W.P 19 | % University of Glasgow, 19 June 2009 20 | % 21 | fpara= sim_psoksar2SIM(psoksarfile); 22 | if ishow ==1 23 | figure(); 24 | sim_fig3d(fpara); 25 | end 26 | -------------------------------------------------------------------------------- /sim_showperts.m: -------------------------------------------------------------------------------- 1 | function sim_showperts(prefix) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | if nargin<1 11 | prefix = '*.okinv'; 12 | end 13 | files = dir(prefix); 14 | nfile = size(files,1); 15 | for ni=1:nfile 16 | data = sim_inputdata(files(ni).name); 17 | plot(data(:,3),'color',rand(1,3)); 18 | hold on 19 | end 20 | -------------------------------------------------------------------------------- /sim_simerror.m: -------------------------------------------------------------------------------- 1 | function sim_simerror(inprefix,ouprefix,rzone) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % +Name: 10 | % sim_simerror(inprefix,ouprefix,rzone) 11 | % Purpose: to simualtion ramp phase and offset in the INSAR 12 | % Created by Feng Wanpeng, IGP-CEA 13 | % 2009/07/01 14 | % Modified by Feng W.P 15 | % added a new keywords,"rzone", to force to convert 2 UTM. 16 | %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 17 | if nargin < 1 18 | disp('sim_simerror(inprefix,ouprefix,rzone)'); 19 | disp('>>>> inprefix, the prefix of inp'); 20 | disp('>>>> ouprefix, the refix of output'); 21 | disp('>>>> rzone, the UTM zone '); 22 | return 23 | end 24 | if nargin<3 25 | rzone = []; 26 | end 27 | fileX = [inprefix '_X.los']; 28 | % 29 | %disp(fileX); 30 | [cdata,ux,uy,sarinfo]= sim_readroi(fileX); 31 | if isempty(findstr(lower(sarinfo.projection),'utm'))==1 32 | [ux,uy] = ll2utm(uy,ux,rzone); 33 | ux = ux./1000; 34 | uy = uy./1000; 35 | 36 | end 37 | % 38 | abc = sarinfo.abc; 39 | error = (ux.*abc(1)+uy.*abc(2)+abc(3)).*(-4*3.14159265/sarinfo.wavelength); 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 | file_ERROR = [ouprefix '_ABC.SIM']; 42 | file_ERRORrsc = [file_ERROR '.rsc']; 43 | file_ERRORhdr = [ouprefix '_ABC.hdr']; 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45 | fid = fopen(file_ERROR,'w'); 46 | fwrite(fid,error','float32'); 47 | fclose(fid); 48 | copyfile([fileX '.rsc'],file_ERRORrsc); 49 | sim_rsc2envihdr(file_ERRORhdr,sarinfo,'ERROR',sarinfo.projection,sarinfo.utmzone); 50 | 51 | -------------------------------------------------------------------------------- /sim_siminp.m: -------------------------------------------------------------------------------- 1 | function [osim,stdv,rms,input] = sim_siminp(fpara,inp,isplot) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % Created by Feng, W.P., @ BJ, 2010/05/01 9 | % Improved by Feng, W.P., @ GU, 2011/10/25 10 | % Improved by Feng,W.P., @ Glasgow, 2012/09/08 11 | % 12 | % 13 | if nargin < 1 14 | disp('stdv = sim_checkinp(fpara,inp,isplot)'); 15 | stdv = []; 16 | return 17 | end 18 | if nargin < 3 19 | isplot=0; 20 | end 21 | % 22 | if ischar(fpara) 23 | fpara = sim_openfault(fpara); 24 | end 25 | %% 26 | % Modified by Feng, W.P., @ Glasgow, 2012-09-08. 27 | % "inp" can be the vector of observations as well in this new version... 28 | % 29 | if isnumeric(inp)==0 30 | input = sim_inputdata(inp); 31 | [tmp,bname] = fileparts(inp); 32 | else 33 | input = inp; 34 | bname = 'inp'; 35 | end 36 | %% 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 38 | dis = multiokadaALP(fpara,input(:,1),input(:,2)); 39 | osim = dis.E.*input(:,4) + dis.N.*input(:,5) + dis.V.*input(:,6); 40 | stdv = std(input(:,3)-osim); 41 | % 42 | 43 | -------------------------------------------------------------------------------- /sim_simp2fpara.m: -------------------------------------------------------------------------------- 1 | function [fpara,zone,nf] = sim_simp2fpara(simp) 2 | % 3 | % 4 | % Read fault slip from a simp file... 5 | % by Feng, W.P., @ Yj, 2015-05-20 6 | % All slip should be alwasy in meter. Noted by Wanpeng Feng, @Ottawa, 7 | % 2017-04-16 8 | % 9 | fid = fopen(simp,'r'); 10 | fgetl(fid); 11 | % Read UTM zone information 12 | tmp = fgetl(fid); 13 | tmp = textscan(tmp,'%s %s','delimiter',':'); 14 | zone = tmp{2}{1}; 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | % Read fault number 17 | tmp = fgetl(fid); 18 | tmp = textscan(tmp,'%s'); 19 | tmp = tmp{1}; 20 | nf = fix(str2double(tmp{5})); % number of faults 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | % Jump one line... 23 | fgetl(fid); 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 25 | fpara = textscan(fid,'%f %f %f %f %f %f %f %f %f %f\n'); 26 | fclose(fid); 27 | % 28 | fpara = cell2mat(fpara); -------------------------------------------------------------------------------- /sim_simp2xyz.m: -------------------------------------------------------------------------------- 1 | function sim_simp2xyz(insimp,outxyz) 2 | % 3 | % 4 | % 5 | [fpara,zone] = sim_openfault(insimp); 6 | % 7 | fid = fopen(outxyz,'w'); 8 | % 9 | for i = 1:size(fpara,1) 10 | % 11 | cfpara = fpara(i,:); 12 | %[x,y,z] = sim_fpara2corners(cfpara); 13 | %disp([x,y,z]); 14 | disp(cfpara); 15 | polys = sim_fpara2allcors(cfpara); 16 | % 17 | polys = [polys(1:4,:);polys(1,:)]; 18 | % plot3(polys(:,1),polys(:,2),polys(:,3)); 19 | [lats,lons] = utm2deg(polys(:,1).*1000,polys(:,2).*1000,zone); 20 | % 21 | slip = sqrt(cfpara(8)^2+cfpara(9)^2); 22 | % 23 | fprintf(fid,'> -Z%f\n', slip); 24 | for j = 1:5 25 | fprintf(fid,'%15.8f %15.8f %15.8f\n',lons(j),lats(j),polys(j,3)); 26 | end 27 | end 28 | fclose(fid); -------------------------------------------------------------------------------- /sim_simresi.m: -------------------------------------------------------------------------------- 1 | function sim_simresi(inunw,outsim,outerr,outdif) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Developed by FWP, @GU, 2009-07-01 10 | % Fixed by fWP, @IGPP of SIO, UCSD, 2013-10-22 11 | % 12 | file_ERR = [outerr '_ABC.SIM']; 13 | file_ERRrsc = [file_ERR '.rsc']; 14 | file_UNW = inunw; 15 | file_SIM = [outsim '_LOS.phs']; 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | if exist(file_UNW,'file')~=0 18 | [UNW,ux,uy,sarinfo]= sim_readroi(file_UNW); 19 | else 20 | disp('Warning!!!!! UNW file is not found.'); 21 | return 22 | end 23 | if exist(file_SIM,'file')~=0 24 | [SIM ]= sim_readroi(file_SIM); 25 | else 26 | disp('Warning!!!!! SIM file is not found.'); 27 | return 28 | end 29 | if exist(file_ERR,'file')~=0 30 | [ERR ]= sim_readroi(file_ERR); 31 | else 32 | ERR = 0; 33 | end 34 | %whos SIM 35 | RES = (UNW == 0).*0+(UNW ~= 0).*(UNW-ERR-SIM); 36 | % 37 | file_RES = [outdif '_ABCSIM.phs']; 38 | file_RESrsc = [file_RES '.rsc']; 39 | file_REShdr = [outdif '_ABCSIM.hdr']; 40 | fid = fopen(file_RES,'w'); 41 | fwrite(fid,RES','float32'); 42 | fclose(fid); 43 | % 44 | if ~exist(file_ERRrsc,'file') 45 | file_ERRrsc = [file_UNW,'.rsc']; 46 | end 47 | copyfile(file_ERRrsc,file_RESrsc); 48 | sim_rsc2envihdr(file_REShdr,sarinfo,'RES',sarinfo.projection,sarinfo.utmzone); 49 | -------------------------------------------------------------------------------- /sim_simulation4envi.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % Name: sim_simulation4envi.m 8 | % Simluation InSAR fringe by fpara... 9 | clc; 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | incfile = 'E:\EQw\italy_20090406\italy\InSAR\gamma_080427_090412.inc'; 12 | azi = -167.7236970; 13 | outname = 'E:\EQw\italy_20090406\sim\dist_143'; 14 | lamd = 0.0562356424; % unit of deformation. 15 | thd = 0.05; 16 | %zone = 46; 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | [inc,gridinfo,dims,hdrfile] = sim_readenvi(incfile); 19 | % 20 | %% 21 | x1 = gridinfo(1); 22 | x2 = gridinfo(1)+gridinfo(3)*dims(1)-gridinfo(3); 23 | y2 = gridinfo(2); 24 | y1 = gridinfo(2)-gridinfo(4)*dims(2)+gridinfo(4); 25 | geox = x1:gridinfo(3):x2; 26 | geox = repmat(geox,dims(2),1); 27 | geoy = y1:gridinfo(4):y2; 28 | geoy = repmat(geoy',1,dims(1)); 29 | geoy = flipud(geoy); 30 | % 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | sim_fpara2envi(fpara,inc',azi,[],[],geox,geoy,outname,... 33 | gridinfo(3)*1000,gridinfo(4)*1000,[],lamd,5,thd); 34 | outhdr = [outname '.hdr']; 35 | copyfile(hdrfile,outhdr,'f'); 36 | -------------------------------------------------------------------------------- /sim_slip4depdist.m: -------------------------------------------------------------------------------- 1 | function [outdata,maxdepv] = sim_slip4depdist(fpara,precision) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % created by Feng, W.P., 2012-01-16, @ GU 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | % 14 | if nargin < 2 15 | precision = 0.01; 16 | end 17 | depth = fpara(:,5); 18 | pdepth = fix(depth./precision); 19 | udept = unique(pdepth); 20 | % 21 | outdata = zeros(numel(udept),2); 22 | maxdepv = outdata; 23 | for ni = 1:numel(udept) 24 | cfpara = fpara(pdepth==udept(ni),:); 25 | cslip = sqrt(cfpara(:,8).^2+cfpara(:,9).^2); 26 | [~,m0] = sim_fpara2moment(cfpara); 27 | outdata(ni,1) = cfpara(1,5); 28 | outdata(ni,2) = m0; 29 | maxdepv(ni,1) = cfpara(1,5); 30 | vmax = mean(cslip); 31 | maxdepv(ni,2) = max(vmax(1)); 32 | end 33 | -------------------------------------------------------------------------------- /sim_slipmodel2qiang.m: -------------------------------------------------------------------------------- 1 | function sim_slipmodel2qiang(insimp,outnewsimp,outmode) 2 | % 3 | % Developed Wanpeng Feng, @NRCan, 2015-11-26 4 | % 5 | % 6 | [fpara,zone] = sim_simp2fpara(insimp); 7 | % 8 | rakes = sim_calrake(fpara,0); 9 | % 10 | if outmode == 3 11 | fpara = sim_fparaconv(fpara,0,3); 12 | end 13 | if outmode == 1 14 | fpara = sim_fparaconv(fpara,0,1); 15 | end 16 | [lat,lon] = utm2deg(fpara(:,1).*1000,fpara(:,2).*1000,zone); 17 | % 18 | sfpara = fpara(:,2).*0; 19 | sfpara(:,1) = lon; 20 | sfpara(:,2) = lat; 21 | sfpara(:,3) = fpara(:,7); 22 | sfpara(:,4) = fpara(:,6); 23 | sfpara(:,5) = fpara(:,5); 24 | sfpara(:,6) = fpara(:,3); 25 | sfpara(:,7) = fpara(:,4); 26 | sfpara(:,8) = rakes; 27 | sfpara(:,9) = sqrt(fpara(:,8).^2+fpara(:,9).^2); 28 | fid = fopen(outnewsimp,'w'); 29 | fprintf(fid,'%s\n','#Lon Lat Length(Km) Width(Km) Depth(Km) Strike Dip Rake Slip(m) '); 30 | fprintf(fid,'%f %f %f %f %f %f %f %f %f\n',sfpara'); 31 | fclose(fid); 32 | % -------------------------------------------------------------------------------- /sim_sm2dgetmat.m: -------------------------------------------------------------------------------- 1 | function [res,ZIcor,ZIstd,ZImo,XI,YI] = sim_sm2dgetmat(dirs,post,psoksar,prefix,nofault1,nopara1,nofault2,nopara2,xsize,ysize,alpha) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | if nargin < 9 12 | xsize = 0.2; 13 | end 14 | if nargin < 10 15 | ysize = 0.2; 16 | end 17 | if nargin < 11 18 | alpha = 0.12; 19 | end 20 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 21 | mats = dir([dirs,'/',post,'*mat']); 22 | res = zeros(numel(mats),5); 23 | for ni=1:numel(mats) 24 | [fpara,~,corv,stdv] = sim_smgetre([dirs,'/',mats(ni).name],[],0,alpha); 25 | [~,m0] = sim_fpara2moment(fpara); 26 | sindex = strfind(mats(ni).name,'.'); 27 | strings= mats(ni).name; 28 | s1 = strings(sindex(1)+1:sindex(2)-1); 29 | s2 = strings(sindex(2)+1:sindex(3)-1); 30 | % 31 | psoksarname = [psoksar,'/',prefix,'.',s1,'.',s2,'.psoksar']; 32 | disp(psoksarname); 33 | fpara = sim_psoksar2SIM(psoksarname); 34 | % 35 | %psoksarfile(1).name 36 | res(ni,:) = [fpara(nofault1,nopara1),fpara(nofault2,nopara2),... 37 | corv,stdv,m0]; 38 | end 39 | % 40 | xrange = [min(res(:,1)),max(res(:,1))]; 41 | yrange = [min(res(:,2)),max(res(:,2))]; 42 | [XI,YI] = meshgrid(xrange(1):xsize:xrange(2),... 43 | yrange(1):ysize:yrange(2)); 44 | ZIcor = griddata(res(:,1),res(:,2),res(:,3),XI,YI,'cubic'); 45 | ZIstd = griddata(res(:,1),res(:,2),res(:,4),XI,YI,'cubic'); 46 | ZImo = griddata(res(:,1),res(:,2),res(:,5),XI,YI,'cubic'); 47 | -------------------------------------------------------------------------------- /sim_sm2oksar.m: -------------------------------------------------------------------------------- 1 | function sim_sm2oksar(matfile,outoksar,cdip,thr) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % Created by Feng,W.P.,@ GU, 2012-09-27 11 | % 12 | if nargin < 3 13 | cdip = []; 14 | end 15 | if nargin < 4 16 | thr = 10; 17 | end 18 | % 19 | outmat = load(matfile); 20 | % 21 | fpara = sim_smgetre(matfile,cdip,3,thr); 22 | uzone = outmat.utmzone; 23 | % 24 | [bdir,bname] = fileparts(outoksar); 25 | if ~exist(bdir,'dir') 26 | mkdir(bdir); 27 | end 28 | sim_fpara2oksar(fpara,outoksar,uzone); 29 | -------------------------------------------------------------------------------- /sim_smbestpara.m: -------------------------------------------------------------------------------- 1 | function outre = sim_smbestpara(matfile) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Created By Feng, W.P., @ GU, 2012/01/24 10 | % 11 | % 12 | if nargin < 1 13 | matfile = 'ps_sm_rb_2track/SMEST_unif_2track.mat'; 14 | end 15 | % 16 | mats = load(matfile); 17 | coutre = mats.mabicre; 18 | lamda = mats.lamda; 19 | % 20 | outre = zeros(numel(coutre),7); 21 | numpts = 0; 22 | for ni = 1:numel(coutre) 23 | tre = coutre{ni}; 24 | % 25 | model = tre.disf; 26 | cdip = model(1,4); 27 | %%%% 28 | smest = tre.smest; 29 | for nj = 1:numel(smest(:,1)) 30 | numpts = numpts + 1; 31 | vnorm = smest(nj,2); 32 | vroug = smest(nj,3); 33 | %%%% 34 | fpara = tre.disf; 35 | slips = tre.dismodel{nj}; 36 | %whos slips 37 | fpara(:,8) = slips(1:end/2); 38 | fpara(:,9) = slips(end/2+1:end); 39 | % 40 | [~,~,mw] = sim_fpara2moment(fpara); 41 | % 42 | [rough,maxr] = sim_fpara2rough(fpara); 43 | outre(numpts,1) = cdip; 44 | outre(numpts,2) = lamda(nj); 45 | outre(numpts,3) = vnorm; 46 | outre(numpts,4) = vroug; 47 | outre(numpts,5) = mw; 48 | outre(numpts,6) = rough; 49 | outre(numpts,7) = maxr; 50 | end 51 | end 52 | % 53 | % 54 | % 55 | % 56 | -------------------------------------------------------------------------------- /sim_smestoutdata.m: -------------------------------------------------------------------------------- 1 | function outdata = sim_smestoutdata(inmat) 2 | % 3 | % 4 | % Developed by Feng, W.P., @ EOS of NTU, in Singapore, 2015-06-18 5 | % 6 | inm = load(inmat); 7 | osim = inm.osim; 8 | nsample = numel(osim); 9 | fpara = inm.disf; 10 | % 11 | outdata = zeros(nsample,3); 12 | outdata(:,1) = inm.lamda; 13 | slips = inm.dismodel; 14 | input = inm.input; 15 | zone = inm.utmzone; 16 | abicre = inm.mabicre; 17 | abicre = abicre{1}; 18 | smest = abicre.smest; 19 | % 20 | for ni = 1:nsample 21 | % 22 | outdata(ni,2) = sim_rms(input(:,3)-osim{ni}); 23 | cslip = slips{ni}; 24 | fpara(:,8) = cslip(1:end/2); 25 | fpara(:,9) = cslip(end/2+1:end); 26 | % 27 | %outdata(ni,3) = sim_fpara2roughness(fpara); 28 | outdata(ni,3) = smest(ni,3); 29 | sim_fpara2simp(fpara,['Fault_slip_',num2str(ni),'.simp'],zone); 30 | end -------------------------------------------------------------------------------- /sim_sortsmre.m: -------------------------------------------------------------------------------- 1 | function outputdata = sim_sortsmre(matfile,isplot,newweights) 2 | % 3 | % 4 | % +Name: 5 | % sim_sortsmre 6 | % by Feng, W.P., @ Yj, 2015-05-29 7 | % 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | % 10 | if nargin < 2 11 | isplot = 0; 12 | end 13 | if nargin < 3 14 | newweights = []; 15 | end 16 | % 17 | matre = load(MCM_rmspace(matfile)); 18 | dips = matre.mdip; 19 | dips = dips(:,3); 20 | input = matre.input; 21 | % 22 | outputdata = []; 23 | for ni = 1:numel(dips) 24 | % 25 | cres = matre.mabicre{ni}; 26 | osim = cres.osim; 27 | smest = cres.smest; 28 | outdata= zeros(numel(osim),2); 29 | % 30 | weights = sim_readweights(newweights); 31 | for nk = 1:numel(osim) 32 | vstd = sim_rms((input(:,3)-osim{nk}).*weights); 33 | outdata(nk,2) = vstd; 34 | end 35 | % 36 | outdata(:,1) = smest(:,3); 37 | roughness = smest(:,3); 38 | % 39 | fid = fopen([num2str(dips(ni)),'.inp'],'w'); 40 | fprintf(fid,'%f %f\n',outdata'); 41 | fclose(fid); 42 | % 43 | outdata(:,1) = smest(:,1); 44 | fid = fopen([num2str(dips(ni)),'.scf'],'w'); 45 | fprintf(fid,'%f %f\n',outdata'); 46 | fclose(fid); 47 | if isplot > 0 48 | plot(outdata(:,1),outdata(:,2),'-or'); 49 | hold on 50 | text(outdata(end,1)+0.001,outdata(end,2)+0.0005,['Dip:',num2str(dips(ni))]); 51 | % 52 | end 53 | % 54 | outdata = [outdata(:,1).*0+dips(ni),outdata,roughness]; 55 | outputdata = [outputdata;outdata]; 56 | % 57 | 58 | end -------------------------------------------------------------------------------- /sim_stadsm.m: -------------------------------------------------------------------------------- 1 | function meanrake = sim_stadsm(fpara,thd) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % Statistic info to the distributed Slip Model 10 | % 11 | % 12 | slip = sqrt(fpara(:,8).^2+fpara(:,9).^2); 13 | fpara= fpara(slip>=thd,:); 14 | rake = atan2(fpara(:,9),fpara(:,8)).*180/3.14159265; 15 | meanrake = mean(rake(:)); 16 | -------------------------------------------------------------------------------- /sim_strain2stress.m: -------------------------------------------------------------------------------- 1 | function sout = sim_strain2stress(UXX,UYY,UZZ,... 2 | UYX,UZX,UXZ,... 3 | UYZ,UXY,UZY,YOUNG,POIS) 4 | % 5 | %************** FWP Work ************************ 6 | %Developed by FWP, @GU/BJ, 2007-2014 7 | % contact by wanpeng.feng@hotmail.com 8 | %************** Good Luck *********************** 9 | 10 | % Convert the strain tensor to stress tensor 11 | % 12 | % INPUT: strain,YOUNG,POIS 13 | % YOUNG, young's constant in the crustal 14 | % POIS, poisson's constant in the crustal 15 | % [XX,YY,ZZ,UXY,UYX,UXZ,UYZ,UYZ,UZY]. 16 | % --> sxx,syy,szz,syz,sxz,sxy 17 | % OUTPUT: sout,(6*nn) matix: newly calculated stress tensor with 18 | % horizontal rotation (not plunge change) 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | % Modified from tensor_trans (in coulomb3.0) 21 | % Changed by Feng W.P, 2010-04-14 22 | % 23 | % 24 | sk = YOUNG/(1.0+POIS); 25 | gk = POIS/(1.0-2.0*POIS); 26 | vol = UXX + UYY + UZZ; 27 | % 28 | sxx = sk * (gk * vol + UXX) * 0.001; 29 | syy = sk * (gk * vol + UYY) * 0.001; 30 | szz = sk * (gk * vol + UZZ) * 0.001; 31 | sxy = (YOUNG/(2.0*(1.0+POIS))) * (UXY + UYX) * 0.001; 32 | sxz = (YOUNG/(2.0*(1.0+POIS))) * (UXZ + UZX) * 0.001; 33 | syz = (YOUNG/(2.0*(1.0+POIS))) * (UYZ + UZY) * 0.001; 34 | % 35 | sout= [sxx(:)';syy(:)';szz(:)';sxy(:)';sxz(:)';syz(:)']; 36 | -------------------------------------------------------------------------------- /sim_subtract.m: -------------------------------------------------------------------------------- 1 | function cdata = sim_subtract(rawfile,x,y) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | [indata,cx,cy,info] = sim_readroi(rawfile); 11 | if isempty(findstr(lower(info.x_unit),'k'))==1 12 | cx = cx./1000; 13 | end 14 | if isempty(findstr(lower(info.y_unit),'k'))==1 15 | cy = cy./1000; 16 | end 17 | ind1 = (cx-x(1))==min((cx(:)-x(1))); 18 | ind2 = (cy-y(2))==min((cy(:)-y(2))); 19 | ind = ind1.*ind2; 20 | [r1,c1] = find(ind==1); 21 | ind1 = (cx-x(2))==min((cx(:)-x(2))); 22 | ind2 = (cy-y(1))==min((cy(:)-y(1))); 23 | ind = ind1.*ind2; 24 | [r2,c2] = find(ind==1); 25 | minr = (r1>=r2)*r2+(r1=r2)*r1+(r1=c2)*c2+(c1=c2)*c1+(c10 17 | tdata = cdata(:,1:2); 18 | tdata(:,1) = tdata(:,1)- cdata(1,1); 19 | tdata(:,2) = tdata(:,2)- cdata(1,2); 20 | flag = tdata*[1 1]'; 21 | cind = find(abs(flag)<=0.00001); 22 | ind = [ind;cind(1)]; 23 | cdata(cind,:) = []; 24 | end 25 | np = size(cdata,1); 26 | end 27 | % 28 | outdata = indata(ind,:); 29 | -------------------------------------------------------------------------------- /sim_updatedweight.m: -------------------------------------------------------------------------------- 1 | function dweight = sim_updatedweight(sdir) 2 | % 3 | % Developed by Feng, W.P., @NRCan, 2015-10-16 4 | % get some information printted during processing 5 | % by Wanpeng Feng, @NRCan, 2016-11-06 6 | % 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | % 9 | dfile = dir([sdir,'/weight.info']); 10 | % 11 | dweight = []; 12 | if numel(dfile) > 0 13 | % 14 | cfile = [sdir,'/',dfile(1).name]; 15 | % 16 | fid = fopen(cfile,'r'); 17 | while ~feof(fid) 18 | tline = fgetl(fid); 19 | tmp = textscan(tline,'%s %f'); 20 | % 21 | data = load(tmp{1}{1}); 22 | dweight = [dweight;data(:,1).*0+tmp{2}]; 23 | disp(['SIM_SMEST: Updating data weights now: ',tmp{1}{1}, ' ',num2str(tmp{2})]) 24 | end 25 | fclose(fid); 26 | 27 | end 28 | % -------------------------------------------------------------------------------- /sim_updategeometry.m: -------------------------------------------------------------------------------- 1 | function sim_updategeometry(inoksar,outoksar,varargin) 2 | % 3 | % 4 | % Developed by Feng, W.P., @ EOS of NTU in Singapore, 2015-06-20 5 | % Updated by Feng, W.P., @NRCan, 2015-10-09 6 | % -> make it more general for any case 7 | % -> now we can change any parameters through giving a keyward... 8 | % 9 | 10 | 11 | dip = []; 12 | strike = []; 13 | cdepth = []; 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | for ni = 1:2:numel(varargin) 16 | par = varargin{ni}; 17 | val = varargin{ni+1}; 18 | eval([par,'=val;']); 19 | end 20 | % 21 | if nargin < 1 22 | % 23 | disp('sim_updategeometry(inoksar,outoksar,varargin)'); 24 | disp(' Varargin inluding:'); 25 | disp(' dip, 0-90'); 26 | disp(' strike, 0-360'); 27 | disp(' cdepth, 0-100'); 28 | return 29 | end 30 | % 31 | [fpara,zone] = sim_oksar2SIM(inoksar); 32 | cfpara = sim_fparaconv(fpara,0,3); 33 | % 34 | if isempty(cdepth) 35 | cdepth = cfpara(5); 36 | end 37 | if isempty(dip) 38 | dip = cfpara(4); 39 | end 40 | % 41 | if isempty(strike) 42 | strike = cfpara(3); 43 | end 44 | % 45 | cfpara(3) = strike; 46 | cfpara(4) = dip; 47 | cfpara(5) = cdepth; 48 | 49 | % 50 | % 51 | fpara = sim_fparaconv(cfpara,3,0); 52 | sim_fpara2oksar(fpara,outoksar,zone); 53 | % -------------------------------------------------------------------------------- /sim_updateweightsfile.m: -------------------------------------------------------------------------------- 1 | function sim_updateweightsfile(infile,newweights) 2 | % 3 | % 4 | % by feng, w.p., @Ottawa, 2015-10-17 5 | % 6 | fid = fopen(infile,'r'); 7 | outfiles = []; 8 | ni = 0; 9 | while ~feof(fid) 10 | tline = fgetl(fid); 11 | tmp = textscan(tline,'%s %f'); 12 | ni = ni + 1; 13 | outfiles{ni} = tmp{1}{1}; 14 | end 15 | fclose(fid); 16 | % 17 | fid = fopen(infile,'w'); 18 | % 19 | for nk = 1:ni 20 | fprintf(fid,'%s %f\n',outfiles{nk},newweights(nk)); 21 | end 22 | fclose(fid); 23 | % -------------------------------------------------------------------------------- /sim_usgsslip2simp.m: -------------------------------------------------------------------------------- 1 | function fpara = sim_usgsslip2simp(inusgs,outsimp,refzone,strike,dip,dx,dy) 2 | % 3 | % 4 | % 5 | % Read a USGS simple slip model 6 | % Developed by Feng, W.P., @ NRCan, 2015-10-07 7 | % 8 | data = load(inusgs); 9 | % 10 | [x,y] = deg2utm(data(:,1),data(:,2),refzone); 11 | x = x./1000; 12 | y = y./1000; 13 | fpara = [x(:),y(:),strike+x(:).*0,dip+x(:).*0,data(:,5),x(:).*0+dy,x(:).*0+dx,data(:,6).*cosd(data(:,7)),data(:,6).*sind(data(:,7)),x(:).*0]; 14 | % convert centroid slip model to that with the reference on the top centre 15 | fpara = sim_fparaconv(fpara,3,0); 16 | % 17 | sim_fpara2simp(fpara,outsimp,refzone); 18 | % -------------------------------------------------------------------------------- /sim_varmag.m: -------------------------------------------------------------------------------- 1 | function v = sim_varmag(pairs) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | %%% 8 | % +Name: 9 | % sim_varmag, varible manager 10 | % +Purpose: 11 | % helper function allowing named generic name value parameter passing 12 | % History: 13 | % Modified by Feng W.P from Googleearth toolsbox... 14 | % 15 | 16 | v = {}; 17 | 18 | for ii=1:2:length(pairs(:)) 19 | % 20 | if isnumeric(pairs{ii+1}) 21 | str = [ pairs{ii} ' = [' num2str(pairs{ii+1}),'];' ]; 22 | else 23 | str = [ pairs{ii} ' = ' 39 pairs{ii+1} 39,';' ]; 24 | end 25 | v{(ii+1)/2,1} = str; 26 | % 27 | end 28 | -------------------------------------------------------------------------------- /sim_working4obj.m: -------------------------------------------------------------------------------- 1 | function outv = sim_working4obj(fpara,type,xory) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | if numel(fpara(1,:))<=10 12 | cfpara = zeros(1,10); 13 | cfpara(1:7) = fpara(1:7); 14 | fpara = cfpara; 15 | end 16 | 17 | incoor = 'UTM'; 18 | outcoor = 'UTM'; 19 | outzone = '30 T'; 20 | % 21 | [x,y,z] = sim_fpara2corners(fpara,type,incoor,outcoor,outzone); 22 | if xory==1 23 | outv = x; 24 | end 25 | if xory==-1 26 | outv = y; 27 | end 28 | if xory==0 29 | outv = z; 30 | end 31 | -------------------------------------------------------------------------------- /sim_wrap.m: -------------------------------------------------------------------------------- 1 | function output = sim_wrap(data,vmin,vmax) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @UoG/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % to re-wrap data by vmin and vmax 9 | % For example, 10 | % outdata = sim_wrap(indata,-3.14159265,3.14159265); 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | % Modification history, 13 | % Created by Feng,W.P., @ BJ, 2009/01/01 14 | % Add some help information by W.P. Feng, @ UoG, 2011/11/25 15 | % 16 | PI = 3.14159265; 17 | % 18 | if nargin < 3 19 | vmax = PI; 20 | end 21 | if nargin < 2 22 | vmin = -PI; 23 | end 24 | indnan = isnan(data); 25 | data(indnan==1) = 0; 26 | min_index = find(data <= vmin) ; 27 | output = data; 28 | % 29 | while isempty(min_index) ~= 1 30 | % 31 | output(min_index) = output(min_index) + (vmax-vmin); 32 | min_index = find(output <= vmin) ; 33 | end 34 | max_index = find(data > vmax) ; 35 | % 36 | while isempty(max_index)~= 1 37 | % 38 | output(max_index) = output(max_index) - (vmax-vmin); 39 | max_index = find(output > vmax) ; 40 | end 41 | % 42 | output(indnan==1) = NaN; 43 | output = output.*(data~=0); 44 | % 45 | -------------------------------------------------------------------------------- /sim_xyz2input.m: -------------------------------------------------------------------------------- 1 | function sim_xyz2input(xyz,outinput,vec) 2 | % 3 | % 4 | % 5 | % Created by Wanpeng Feng, @NRCan, 2017-01-23 6 | % 7 | if nargin < 3 8 | % 9 | disp('sim_xyz2input(xyz,outinput,vec)'); 10 | return 11 | % 12 | end 13 | % 14 | data = load(xyz); 15 | ndim = numel(data(:,1)); 16 | outdata = zeros(ndim,8); 17 | % 18 | outdata(:,1:3) = data; 19 | outdata(:,4) = vec(1); 20 | outdata(:,5) = vec(2); 21 | outdata(:,6) = vec(3); 22 | outdata(:,8) = 1; 23 | % 24 | % sim_input2outfile(outdata,outinput); 25 | save(outinput,'outdata','-ASCII'); 26 | % -------------------------------------------------------------------------------- /triangle_area.m: -------------------------------------------------------------------------------- 1 | function [area] = triangle_area(P,method) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % This function gives the area of a triangle 8 | % 9 | % [area] = triangle_area(Points, Method) 10 | % 11 | % Points: The Points should be a numeric array, of size 3xn, 12 | % thus the points can be 2D, 3D... nD 13 | % Method: Can be 'h' area calculation with Heron's formula 14 | % or can be 'q' Orthogonal-triangular decomposition (default) 15 | % 16 | % Example: 17 | % P1=[0 0]; P2=[1 0.5]; P3=[0.5 1]; 18 | % area = triangle_area([P1;P2;P3]) 19 | % 20 | % Version 1.1 updated on 2007-09-21 21 | % Added 'Orthogonal-triangular decomposition' after a usefull review of John D'Errico 22 | 23 | % Default output format 24 | if(exist('method','var')==0), method='q'; end 25 | 26 | % Check input 27 | if((method ~= 'h') && (method ~= 'q')), error('Unknown area calculation method'); end 28 | [k,m] = size(P); if(k~=3), error('Points are not a 3xn array'); end 29 | 30 | if(method=='h') 31 | % Length of edges 32 | L = [sqrt(sum((P(1,:)-P(2,:)).^2)) ... 33 | sqrt(sum((P(2,:)-P(3,:)).^2)) ... 34 | sqrt(sum((P(3,:)-P(1,:)).^2))]; 35 | % Area calculation with Heron's formula 36 | s = ((L(1)+L(2)+L(3))/2); 37 | area = sqrt(s*(s-L(1))*(s-L(2))*(s-L(3))); 38 | else 39 | % Area calculation with Orthogonal-triangular decomposition 40 | [q,r] = qr((P(2:3,:) - repmat(P(1,:),2,1))'); 41 | area = abs(prod(diag(r)))/2; 42 | end 43 | 44 | 45 | -------------------------------------------------------------------------------- /unique2d.m: -------------------------------------------------------------------------------- 1 | function outdata = unique2d(indata) 2 | % 3 | %************** FWP Work ************************ 4 | %Developed by FWP, @GU/BJ, 2007-2014 5 | % contact by wanpeng.feng@hotmail.com 6 | %************** Good Luck *********************** 7 | % 8 | % 9 | % 10 | % 11 | np = size(indata,1); 12 | for ni = 1:np 13 | 14 | end 15 | -------------------------------------------------------------------------------- /uokadacal3d.m: -------------------------------------------------------------------------------- 1 | function disl = uokadacal3d(faultpara,ox,oy,z,alpha,point_source) 2 | % 3 | % alpha is media parameter. 4 | % Developed by Wanpeng Feng, @BJ, 2010 5 | % Updated by Wanpeng Feng, @Ottawa, CA 2016-10 to support a Mogi-like 6 | % inflation source 7 | % 8 | DIP = faultpara(4); 9 | DEP = faultpara(5)+faultpara(6)/2*sind(DIP); 10 | strike = faultpara(3); 11 | %disp([alpha,ox,oy,DEP,0,faultpara(7),0,faultpara(6),SD,CD,faultpara(8)]); 12 | if point_source ~= 1 13 | % 14 | [UX,UY,UZ,UXX,UYX,UZX,UXY,UYY,UZY,UXZ,UYZ,UZZ] = ... 15 | Okada_DC3D(alpha,ox,oy,abs(z).*-1,DEP,DIP,faultpara(7)/2,faultpara(7)/2,... 16 | faultpara(6)/2,faultpara(6)/2,... 17 | faultpara(8),faultpara(9),faultpara(10)); 18 | factor = 1; 19 | else 20 | % convert to potency 21 | % km to m 22 | potency = faultpara(6) * faultpara(7) * faultpara(10) * 1e6; 23 | % 24 | [UX,UY,UZ,UXX,UYX,UZX,UXY,UYY,UZY,UXZ,UYZ,UZZ] = ... 25 | Okada_DC3D0(alpha,ox,oy,abs(z)*(-1),DEP,DIP,0,0,0,potency); 26 | % 27 | factor = 1; 28 | end 29 | % 30 | % updated by Wanpeng Feng, @Ottawa, point source is ready for that... 31 | % 32 | % unit of UX,UY,UZ is always in meter... 33 | % 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 35 | i = sqrt(-1); 36 | strkr = (90-strike)*pi/180; 37 | temp = (UX+UY.*i).*exp(i*strkr); 38 | disl.E = real(temp); 39 | disl.N = imag(temp); 40 | disl.V = UZ; 41 | disl.XX = UXX.*factor; 42 | disl.YX = UYX.*factor; 43 | disl.XY = UXY.*factor; 44 | disl.YZ = UYZ.*factor; 45 | disl.YY = UYY.*factor; 46 | disl.ZZ = UZZ.*factor; 47 | disl.ZY = UZY.*factor; 48 | disl.XZ = UXZ.*factor; 49 | disl.ZX = UZX.*factor; --------------------------------------------------------------------------------