[SAC-HELP] Now able to write sac header in C

Sunil Roy seismo_003 at rediffmail.com
Sun Jan 1 04:44:29 PST 2012


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;
  nrf=count(argv[1]);
  fp1=fopen(argv[1],"r");
    fscanf(fp1,"%s",fi1);
    fi=malloc ( strlen(fi1) + 1 );
    strcpy(fi,fi1);
  fclose(fp1);
  /* 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;
    strcpy(kname,fi[i]);
    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);
      exit(-1);
    }
    newhdr();
    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);
      exit(-1);
      }
    sprintf(out,"%s.out",fi);
    strcpy(kname,out);
   wsac0 (kname, b, yarray, &nerr, strlen( out ));
    if ( nerr != 0 ) {
      fprintf(stderr, "Error getting header variable: delta\n");
      exit(-1); }
  free(fi);
  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.iris.washington.edu/pipermail/sac-help/attachments/20120101/aef9c02d/attachment.html>


More information about the sac-help mailing list