Thread: Now able to write sac header in C

Started: 2012-01-01 20:44:29
Last activity: 2012-01-02 02:05:51
Topics: SAC Help
Sunil .
2012-01-01 20:44:29
Hi SAC user,

I am trying to write the complete sac header for evenly space file using wsac0() in c program.
But i am always getting error or segmentation fault. The problem is that I am not able to understand
what input it is taking to write the complete header information using wsac0() function. what is the 2nd and
3rd input in wsac0(). The code to write the sac file is given here. What is the problem in the code or I would be thankful for your advise to correct the code.

int main(int argc, char *argv[])
  FILE *fp1;
  char **fi;
  char fi1[400];
  static int nrf=0;
  int i;
    fi=malloc ( strlen(fi1) + 1 );
  /* Define variables to be used in the call to rsac1() and getfhv() */
    static  int max = MAX, nlen, nerr, n1, n2, npts=0;
    static float xarray[ MAX ] , yarray [ MAX ], beg , del , delta , b , o, e, stla=0, stlo=0, stel=0, evla,evlo,evdp, mag, cmpaz;
  int leven=1;
  float minimum=1.0, maximum=6.0;

    static char kname[ 31 ], out[31], *kstnm, *kcmpnm;
    rsac1(kname, yarray, & nlen, & beg, & del, & max, & nerr, strlen( kname ) ) ;
    /* Check the Error status */
    if ( nerr != 0 ) {
      fprintf(stderr, "Error reading SAC file: %s\n", kname);
    setnhv("NPTS", & npts, & nerr, strlen("NPTS"));
    setfhv("DELTA", & del, &nerr, strlen("DELTA"));
    setfhv("B", & b, & nerr, strlen("B"));
    setfhv("E", & e, & nerr, strlen("E"));
    setfhv("O", & o, & nerr, strlen("O"));
    setfhv("STLA", & stla, & nerr, strlen("STLA"));
    setfhv("STLO", & stlo, & nerr, strlen("STLO"));
    setfhv("STEL", & stel, & nerr, strlen("STEL"));
    setfhv("EVLA", & evla, & nerr, strlen("EVLA"));
    setfhv("EVLO", & evlo, & nerr, strlen("EVLO"));
    setfhv("EVDP", & evdp, & nerr, strlen("EVDP"));
    setkhv("KSTNM", kstnm, & nerr, strlen("KSTNM"),strlen(kstnm));
    setfhv("CMPAZ", &cmpaz, &nerr, strlen("CMPAZ"));
    setkhv("KCMPNM", kcmpnm, & nerr, strlen("KCMPNM"),strlen(kcmpnm));
    setfhv("MAG", & mag, & nerr, strlen("MAG"));
      if(nerr != 0) {
      fprintf(stderr, "Error in reading SAC File: %s\n", kname);
   wsac0 (kname, b, yarray, &nerr, strlen( out ));
    if ( nerr != 0 ) {
      fprintf(stderr, "Error getting header variable: delta\n");
      exit(-1); }
  return 0;

Error Message:
xx3.c: In function ‘main’:
xx3.c:105:4: error: incompatible type for argument 2 of ‘wsac0’
../include/sacio.h:104:6: note: expected ‘float *’ but argument is of type ‘float’

What will be the input in 2nd and 3rd place of wsac0() for evenly space file

Thanking you,

Sunil Roy
Research Scholar
National Geophysical Research Institute
Hyderbad, India

  • Arthur Snoke
    2012-01-02 02:05:51
    I had not answered because my calls to wsac0 have been using Fortran so I
    hoped that someone would respond. This being a vacation time for much of
    the world, that has not happened. So I will try.

    I looked at the help pages and was surprised to find that between v101.3
    and 101.4 discussionas about C and Fortran subroutines were left out of
    the user_manual sections on input_output and appendix. Here is a short
    section from the old input_output that addresses some of your questions?


    C: void wsac0(kname, xarray, yarray, nerr, kname_s)
    char *kname;
    float *xarray;
    float *yarray;
    long int *nerr;
    long int kname_s;

    FORTRAN: call wsac0(kname, xarray, yarray, nerr)
    character*8 kname
    real*4 xarray(*)
    real*4 yarray(*)
    integer*4 nerr

    purpose: To write a SAC file to disk using current header

    Input variables:
    kname: Name of disk file to write (padded at the
    end with blanks or '\0's).
    xarray: contains the independent variable.
    yarray: contains the dependent variable.
    kname_s: (C only) string length of kname

    Output variables:
    nerr: error status; always 0 if there was no

    Subroutine wsac0 can write SAC files with even spacing (LEVEN true) in
    which case xarray is just a dummy file. Or it can write unevenly0spaced
    or spectral files (LEVEN false). Perhaps you need to include the line

    setlhv ( "LEVEN" , &true , &nerr , 5 ) ;

    Let me know if this helps -- or if you need more information.

    We will look into adding more documentation about subroutines to the HELP
    file. We cannot change files in the distribution until the next release,
    but it is easy to alter the online HELP files at IRIS.


Page built 07:47:06 | v.b'ea7a92