Skip to content

Commit

Permalink
can write network, station, location, channel ids in mseed files
Browse files Browse the repository at this point in the history
  • Loading branch information
emolch committed Mar 8, 2011
1 parent fba51e0 commit ed0e602
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
5 changes: 4 additions & 1 deletion ahfull.f90
Expand Up @@ -202,7 +202,10 @@ program ahfull
iend = nsamples

fn = basefn // '-' // ireceiver // '-' // xyz(n) // '-' // iwindow // '.' // offormat
call writeseismogram( fn, offormat, seismograms(n,ibeg:iend), real(tbegin(iwindow)+dt*(ibeg-1),8), dt, nerr )

call writeseismogram( fn, offormat, seismograms(n,ibeg:iend), &
real(tbegin(iwindow)+dt*(ibeg-1),8), dt, &
var_str(''), var_str(ireceiver), var_str(''), var_str(xyz(n)), nerr )
if (nerr /= 0) call die('failed to save seismogram to file: ' // fn )
end do
end do
Expand Down
4 changes: 3 additions & 1 deletion gfdb_extract.f90
Expand Up @@ -72,7 +72,9 @@ subroutine getentry( buffer, ok )
call trace_unpack( tracep, continuous )
span = strip_span( continuous )
filename = trim(filenamebase)
call writeseismogram( filename, var_str("*"), continuous%data, dble(db%dt*(span(1)-1)),db%dt,nerr )
call writeseismogram( filename, var_str("*"), continuous%data, dble(db%dt*(span(1)-1)),db%dt, &
var_str(''), var_str(''), var_str(''), var_str(ig), &
nerr )
if (nerr == 0) ok = .true.

call gfdb_uncache_trace( db, ix,iz,ig )
Expand Down
5 changes: 4 additions & 1 deletion gfdb_specialextract.f90
Expand Up @@ -69,7 +69,10 @@ subroutine getentry( buffer, ok )
continuous%data = sqrt( continuous%data )
span = strip_span( continuous )
filename = trim(filenamebase)
call writeseismogram( filename, var_str("*"), continuous%data, dble( db%dt*(span(1)-1) ),db%dt,nerr )
call writeseismogram( filename, var_str("*"), continuous%data, &
dble( db%dt*(span(1)-1) ),db%dt, &
var_str(''), var_str(''), var_str(''), var_str(''), &
nerr )

end subroutine

Expand Down
22 changes: 15 additions & 7 deletions mseed/mseed_simple.c
Expand Up @@ -9,7 +9,8 @@ static void record_handler (char *record, int reclen, void *outfile) {
}
}

int writemseed(char *filename, float *seismogram, int length, double toffset, double deltat ) {
int writemseed(char *filename, float *seismogram, int length, double toffset, double deltat,
char *network, char *station, char *location, char *channel ) {
MSTrace *trace;
char srcname[50];
int psamples, precords;
Expand All @@ -25,10 +26,16 @@ int writemseed(char *filename, float *seismogram, int length, double toffset, do

trace = mst_init (NULL);

strcpy( trace->network, "XX" );
strcpy( trace->station, "XXXX" );
strcpy( trace->channel, "XXX" );

strncpy( trace->network, network, 2 );
strncpy( trace->station, station, 4 );
strncpy( trace->location, location, 2 );
strncpy( trace->channel, channel, 3 );
trace->network[3] = '\0';
trace->station[5] = '\0';
trace->location[3] = '\0';
trace->channel[4] = '\0';


/* double is only precise up to something slightly below 1e-5 s in this
century, so last digit in hptime with HPTMODULUS==1000000 is not reliable.
I try to set it to zero here... */
Expand Down Expand Up @@ -251,7 +258,8 @@ void readmseed2_( float *seismogram ) {
*/

void writemseed_( char *filename, float *seismogram, int *length, double *toffset,
double *deltat, int *nerr ) {
double *deltat,
char *network, char *station, char *location, char *channel, int *nerr ) {

float *data;
int i;
Expand All @@ -260,6 +268,6 @@ void writemseed_( char *filename, float *seismogram, int *length, double *toffse
for (i=0;i<(*length); i++) {
data[i] = seismogram[i];
}
*nerr = writemseed( filename, data, *length, *toffset, *deltat ); /* data is deallocated inside of this */
*nerr = writemseed( filename, data, *length, *toffset, *deltat, network, station, location, channel ); /* data is deallocated inside of this */
}

12 changes: 9 additions & 3 deletions receiver.f90
Expand Up @@ -518,7 +518,9 @@ subroutine receiver_output_seismogram( self, filenamebase, fileformat, which_pro
span = strip_span( strip )
call writeseismogram( char(outfn), "*", &
strip%data, &
reftime+(span(1)-1)*dt, dt, nerr )
reftime+(span(1)-1)*dt, dt, &
'', '', '', component_names(self%components(icomponent)), &
nerr )

if (nerr /= 0) then
ok = .false.
Expand Down Expand Up @@ -560,7 +562,9 @@ subroutine receiver_output_seismogram_spectra( self, filenamebase, which_probe,

call writeseismogram( char(outfn), "*", &
strip%data, &
dble(0.0), df, nerr )
dble(0.0), df, &
'', '', '', component_names(self%components(icomponent)), &
nerr )
if (nerr /= 0) then
ok = .false.
call error( "failed to write output file: " // outfn )
Expand Down Expand Up @@ -596,7 +600,9 @@ subroutine receiver_output_cross_correlations( self, filenamebase, ok )
outfn = filenamebase // "-" // component_names(self%components(icomponent)) // ".table"
call writeseismogram( char(outfn), "*", &
self%cross_corr(:,icomponent), &
dble(lbound(self%cross_corr,1)*self%dt), self%dt, nerr )
dble(lbound(self%cross_corr,1)*self%dt), self%dt, &
'', '', '', component_names(self%components(icomponent)), &
nerr )
if (nerr /= 0) then
ok = .false.
call error( "failed to write output file: " // outfn )
Expand Down
24 changes: 18 additions & 6 deletions seismogram_io.f90
Expand Up @@ -45,26 +45,30 @@ module seismogram_io

contains

subroutine writeseismogram_vs( filename, fileformat, seismogram, toffset, deltat, nerr )
subroutine writeseismogram_vs( filename, fileformat, seismogram, toffset, deltat, &
network, station, location, channel, nerr )

type(varying_string), intent(in) :: filename, fileformat
real, dimension(:), intent(in) :: seismogram
real(kind=8), intent(in) :: toffset
real, intent(in) :: deltat
type(varying_string), intent(in) :: network, station, location, channel
integer, intent(out) :: nerr

call writeseismogram_c( char(filename), char(fileformat), seismogram, toffset, deltat, nerr )
call writeseismogram_c( char(filename), char(fileformat), seismogram, toffset, deltat, &
char(network), char(station), char(location), char(channel), nerr )

end subroutine

subroutine writeseismogram_c( filename, fileformat, seismogram, toffset, deltat, nerr )
subroutine writeseismogram_c( filename, fileformat, seismogram, toffset, deltat, &
network, station, location, channel, nerr )

character(len=*), intent(in) :: filename, fileformat
real, dimension(:), intent(in) :: seismogram
real(kind=8), intent(in) :: toffset
real, intent(in) :: deltat
integer, intent(out) :: nerr

character(len=*), intent(in) :: network, station, location, channel
type(varying_string) :: fileformat_

! dump 1-component seismogram to file
Expand All @@ -73,6 +77,10 @@ subroutine writeseismogram_c( filename, fileformat, seismogram, toffset, deltat,
real(kind=8) :: ddeltat
real, dimension(size(seismogram)) :: seismogram_copy
character(len=len(filename)+1) :: filename_cstr
character(len=len(network)+1) :: network_cstr
character(len=len(station)+1) :: station_cstr
character(len=len(location)+1) :: location_cstr
character(len=len(channel)+1) :: channel_cstr

! look at the filename extension what kind of output is wanted
nerr = 0
Expand Down Expand Up @@ -103,10 +111,14 @@ subroutine writeseismogram_c( filename, fileformat, seismogram, toffset, deltat,
seismogram_copy(:) = seismogram(:)

ddeltat = deltat
filename_cstr = filename//char(0)
filename_cstr = trim(filename)//char(0)
network_cstr = trim(network)//char(0)
station_cstr = trim(station)//char(0)
location_cstr = trim(location)//char(0)
channel_cstr = trim(channel)//char(0)
nlen = size(seismogram_copy)
call writemseed( filename_cstr, seismogram_copy, nlen, &
toffset, ddeltat, nerr )
toffset, ddeltat, network_cstr, station_cstr, location_cstr, channel_cstr, nerr )

end if

Expand Down
1 change: 1 addition & 0 deletions seismosizer.f90
Expand Up @@ -217,6 +217,7 @@ program seismosizer
outfn = outfnbase // "-" // ireceiver // "-" // icomponent // "." // outformat
call writeseismogram( char(outfn), "*", &
displacement(icomponent)%data, &
'', '', '', '', &
(span(1)-1)*db%dt, db%dt, nerr )
if (nerr /= 0) call die( "failed to write output file: " // outfn )
end if
Expand Down

0 comments on commit ed0e602

Please sign in to comment.