R/rseis2sac.R

Defines functions rseis2sac

Documented in rseis2sac

rseis2sac<-function(GH, sel=1, win=c(0,1), path=".", BIGLONG=FALSE )
  {
##############  convert an RSEIS structure to SAC format
########   if path is provided, the individual files will be
#########    written in that directory
    
    if(missing(sel)) { sel = 1:length(GH$STNS) }

    
    theENDIAN =  .Platform$endian

    aunits = "volts"

    
    RDT = rangedatetime(GH$info)
    newdir  = paste(path,filedatetime(RDT$min), sep="/")

     tdir =  dir.create(newdir)
      
    if(!dir.exists(newdir))
      {
        stop("Stopping: Output Directory Does not Exist")
      }
    
    for(j in 1:length(sel))
      {
        i = sel[j]
        
        fn = "GH"
        thesta = GH$STNS[i]
        thecomp = GH$COMPS[i]
        dt = GH$dt[i]
        
        tstart = list(yr=GH$info$yr[i]  ,
          jd=GH$info$jd[i]  ,
          mo=GH$info$mo[i]  ,
          dom=GH$info$dom[i]  ,
          hr=GH$info$hr[i]  ,
          mi=GH$info$mi[i]  ,
          sec=GH$info$sec[i]  ,
          msec=GH$info$msec[i]  ,
          dt=GH$info$dt[i]  ,
          t1=GH$info$t1[i]  ,
          t2=GH$info$t2[i]  ,
          off=GH$info$off[i]  
          )
        N = GH$info$n[i]

        sig = GH$JSTR[[i]]

    sacfn = paste(sep=".",
          formatC(GH$info$yr[i] , width = 4, flag = "0") ,
          formatC(GH$info$jd[i], width = 3, flag = "0"),
          formatC(GH$info$hr[i], width = 2, flag = "0") ,
          formatC(GH$info$mi[i], width = 2, flag = "0") ,
          formatC(GH$info$sec[i], width = 2, flag = "0")  ,
          thesta ,
          thecomp,
          "SAC")

        output.fn = paste(newdir,sacfn, sep='/') 
        
        a1 = list(fn=fn, sta=thesta,  comp=thecomp, dt=dt, DATTIM=tstart,
          N=N, units=aunits , amp=sig , IO=list(kind=2, Iendian=theENDIAN,
                                          BIGLONG=BIGLONG))

        ######################  write out the SAC file
        write1sac(a1, fn=output.fn, BIGLONG=BIGLONG )
        
      }

      return(newdir)

  }

Try the RSEIS package in your browser

Any scripts or data that you put into this service are public.

RSEIS documentation built on Sept. 13, 2024, 1:09 a.m.