📄 sortrec_new.m,v
字号:
head 2.0;access;symbols;locks; strict;comment @// @;2.0date 99.05.21.18.46.41; author mah; state Exp;branches;next 1.3;1.3date 99.02.15.13.51.38; author mah; state Exp;branches;next 1.2;1.2date 99.02.12.22.13.08; author mah; state Exp;branches;next 1.1;1.1date 99.01.15.18.37.37; author mah; state Exp;branches;next ;desc@A quicker version of the old sortrec.m program@2.0log@Release 2@text@%sortrec_new -> designed to sort traces into records according to component%(x,y,z,r,or t); according to shot gathers, or in receiver gathers.%May later be extended to sort into CDP gathers.%%function [dataout]=sortrec_new(datain,sort_flg1,sort_flg2)%%sort_flg1 - variable indicating the trace header word containing the values%to be sorted by. Traces with the same value in the indicated header word%will be grouped together.%%Official DSI data protocol trace header number significance:% 2 - field file ID (FFID)% 3 - CDP number% 4 - component (1==h1,2==h2, 3==z, 1+n*3==r, 2+n*3==t, 3+n*3==rotated z)% n above is number of rotations that component has been subjected to% 26 - shot ID% 27 - receiver ID%%sort_flg2 - trace header word containing variable to sort traces within record%by, example wire line depth. If sort_flg2 is left out or set to zero then%the traces will not be sorted within the record.%%Warning: NO checking done for valid trace header words%%DSI customized VSP processing software%Based on program by Kristen Beaty October, 1997%Rewritten by Marko Mah January 1999%$Id: sortrec_new.m,v 1.3 1999/02/15 13:51:38 mah Exp mah $%$Log: sortrec_new.m,v $%Revision 1.3 1999/02/15 13:51:38 mah%deleted some commented out lines%%Revision 1.2 1999/02/12 22:13:08 mah%made it sort even faster%%Revision 1.1 1999/01/15 18:37:37 mah%Initial revision%%Revision 1.1 1999/01/06 19:09:08 kay%Initial revision%%%Copyright (C) 1998 Seismology and Electromagnetic Section/%Continental Geosciences Division/Geological Survey of Canada%%This library is free software; you can redistribute it and/or%modify it under the terms of the GNU Library General Public%License as published by the Free Software Foundation; either%version 2 of the License, or (at your option) any later version.%%This library is distributed in the hope that it will be useful,%but WITHOUT ANY WARRANTY; without even the implied warranty of%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%Library General Public License for more details.%%You should have received a copy of the GNU Library General Public%License along with this library; if not, write to the%Free Software Foundation, Inc., 59 Temple Place - Suite 330,%Boston, MA 02111-1307, USA.%%DSI Consortium%Continental Geosciences Division%Geological Survey of Canada%615 Booth St.%Ottawa, Ontario%K1A 0E9%%email: dsi@@cg.nrcan.gc.cafunction [dataout]=sortrec_new(datain,sort_flg1,sort_flg2)disp('[dataout]=sortrec_new(datain,sort_flg1,sort_flg2)');nrec=datain.fh{12}; %number of records in filedataout.fh=datain.fh;tot_trc=datain.fh{1}; % total number of traces within filesamples=dataout.fh{7}; % number of samples per trace% in this program, after the total number of traces is determined,% the program will read in all trace header first% then assign an index number to them in the order they are read in% then the index numbers will be shuffled aroung to see what order% the traces will be read in. Once this is done, the traces and % the headers will be written out in this order% initializes the sorting indexswitch nargin case 2% for only 1 sort flag index=zeros(tot_trc,3); case 3% for 2 sort flags index=zeros(tot_trc,4);end %nargin % the first column of the index will store the record the trace comes from% the second column will store the trace it was in that record% the third column will store the trace header word specified by the first sort flag% the fourth column will store the trace header word specified by the second sort flag (if present)% remember one can not assume that all records have the same number of tracespos=1; % pos is the position in the index% now to read in the trace headers depending on the number of argumentsswitch nargin case 2 % for only 1 sort flag for COUNT1=1:nrec temp=datain.th{COUNT1};% loads in the trace headers for the current record [a,ntraces]=size(temp);% determines the number of traces in the record for COUNT2=1:ntraces % the following reads into index the record numer, trace number, and the header word index(pos,:)=[COUNT1,COUNT2,temp(sort_flg1,COUNT2)]; pos=pos+1; end %for COUNT2 end %for COUNT1 % the following sorts the index by the header word order=sortrows(index,3); case 3 % for 2 sort flags for COUNT1=1:nrec temp=datain.th{COUNT1};% loads in the trace headers for the current record [a,ntraces]=size(temp);% determines the number of traces in the record for COUNT2=1:ntraces % the following reads into index the record numer, trace number, and the header words index(pos,:)=[COUNT1,COUNT2,temp(sort_flg1,COUNT2),temp(sort_flg2,COUNT2)]; pos=pos+1; end %for COUNT2 end %for COUNT1 % the following sorts the index by the header words order=sortrows(index,[3 4]);end %nargin% the following determines the number of new records and determines the position in the output data setnrec_new=1;% initializes the number of records to 1tracenum=1;% initializes the trace number in the new recordcurr_rec=order(1,3);% initializes the current record to the first recordoutput_pos=zeros(tot_trc,2);% initializes the output positionsoutput_pos(1,:)=[1 1];maxtrace=1;% maxtrace is the maximum record foldfor COUNT=2:tot_trc if order(COUNT,3)~=curr_rec curr_rec=order(COUNT,3); nrec_new=nrec_new+1; tracenum=1; else tracenum=tracenum+1; end %if output_pos(COUNT,:)=[nrec_new,tracenum]; % sets the output trace position maxtrace=max(maxtrace,tracenum); % determines the maximum record foldend %for COUNT% the following updates the number of records in the file headerdataout.fh{12}=nrec_new;% the following updates the maximum record folddataout.fh{13}=maxtrace;% the following writes out the data by going down the output_pos list and writing it outfor COUNT=1:tot_trc % outputs the trace headers dataout.th{output_pos(COUNT,1)}(:,output_pos(COUNT,2))=datain.th{order(COUNT,1)}(:,order(COUNT,2));end %for COUNT% the trace header words 12 (number of traces in record) and 13 (trace number within record) still have to be fixed up for each recordfor COUNT1=1:nrec_new temp=dataout.th{COUNT1}; [a,ntraces]=size(temp);% determines the number of traces in the record dataout.th{COUNT1}(12,:)=ntraces;% assigns the number of traces within the record to the trace header dataout.dat{COUNT1}=zeros(samples,ntraces); %zeros the output data space in order to speed it up for COUNT2=1:ntraces dataout.th{COUNT1}(13,COUNT2)=COUNT2;% assigns the trace number within the record to the trace header end% for COUNT2end% for COUNT1for COUNT=1:tot_trc % outputs the traces dataout.dat{output_pos(COUNT,1)}(:,output_pos(COUNT,2))=datain.dat{order(COUNT,1)}(:,order(COUNT,2));end %for COUNT@1.3log@deleted some commented out lines@text@d29 1a29 1%$Id: sortrec_new.m,v 1.2 1999/02/12 22:13:08 mah Exp mah $d31 3@1.2log@made it sort even faster@text@d29 1a29 1%$Id: sortrec_new.m,v 1.1 1999/01/15 18:37:37 mah Exp mah $d31 3a163 2 % outputs the traces% dataout.dat{output_pos(COUNT,1)}(:,output_pos(COUNT,2))=datain.dat{order(COUNT,1)}(:,order(COUNT,2));@1.1log@Initial revision@text@d29 5a33 2%$Id: sortrec.m,v 1.1 1999/01/06 19:09:08 kay Exp $%$Log: sortrec.m,v $d72 1d162 1a162 1 dataout.dat{output_pos(COUNT,1)}(:,output_pos(COUNT,2))=datain.dat{order(COUNT,1)}(:,order(COUNT,2));d170 1d175 5@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -