;;=============================================================================
;;
;; Functions:  segy_write, segy_read, segy_header
;;
;; Author:     Martin Luethi, VAW, ETH Zurich, Switzerland
;;             luthi@vaw.baum.ethz.ch
;;
;; Date:       26. September 1996
;;
;; Purpose:    Write and read data files in SEGY format
;;             
;;             The SEGY format is a standard file format for seismic data.
;;             It consists mainly of headers containing all the information
;;             on a trace and a body with the measured seismic data. The
;;             data is stored in binary form.
;;
;;             The header fields are those defined by Seismic Unix which
;;             do not correspond in all detail to standard SEGY format
;;             (see the documentation of Seismic Unix for further details).
;;
;;             Seismic Unix is powerful free seismic software which is
;;             available via ftp from the Colorado School of Mines:
;;                   ftp.cwp.mines.edu. 
;;             Their homepage is located at 
;;                   http://www.cwp.mines.edu
;;
;;=============================================================================
;;
;; Example 1:  Save 50 traces of seismic data with 600 samples per trace
;;             to a SEGY-file. Set some header fields with important data
;;             such as coordinates of the shots

;; Save ntr=50 traces with ns=600 samples each

   ntr = 50
   ns = 600

;; The header structure is defined using SEGY_header:

   SEGY_header, header

;; Now make an array of ntr headers and define the data array

   head = Replicate(header, ntr)
   data = FltArr(ntr, ns)

;; Fill the header fields with important values (this fields will be set
;; automatically by segy_write

   head.ntr = ntr
   head.ns  = ns

;; here we fill the header with any information we want
;; see SU documentation or SEGY_header.pro for field names

   head.dt = dt ;;                            sample time
   FOR i = 0, ntr-1 DO BEGIN
      head(i).sx = source_coordinate_x(i) ;;  cooridates of shotpoints
      head(i).sy = source_coordinate_y(i)
   ENDFOR

;; now let's write the data to disk

   SEGY_write, '/usr/data/seis/myprofile.su', head, data

;;=============================================================================

;; Example 2:  Read some seismic traces from a SEGY file

;; read all data from the file (head and data will be declared on output)

   SEGY_read, '/usr/data/seis/myprofile.su', head, data

;; if we need only some traces, we may pick them from the file

   trace_idx = indgen(20)+35 ;;  read only traces 55..75
   SEGY_read, '/usr/data/seis/myprofile.su', head, data, trace_idx

;; get information on the traces from the header

   ntr = head(0).ntr ;;                    number of trace in profile
   ns  = head(0).ns  ;;                    number of samples per trace
   dt  = head(0).dt  ;;                    sampling interval
   
;; now read all the source coordinates in an array

   scoord = fltarr(2,ntr)
   scoord(0,*) = head.sx
   scoord(1,*) = head.sy

;; the names and contents of the other header fields are documented in the
;; source code of segy_header.pro or in the Seismic Unix Manual

;; finally plot the trace nr 52

   plot, indgen(ns)*dt, data(52,*)

;;=============================================================================
