Thread: Unable to load sac files

Started: 2018-12-31 15:52:40
Last activity: 2018-12-31 15:52:40
Topics: SAC Help
Junjie Liu
2018-12-31 15:52:40
Hello everyone, I am trying to read sacfiles using sac I/O routines for C
language but I do not know why it keeps reminding me that unable to open
sac file? I use sac to read the file and it succeeds.

This is my code:
int main(int argc, char **argv){
int i,count,npts;
char filename[160],tempfile[160];
float *trace1=NULL,*trace2=NULL,dt,dtemp;
float t1,t2,tmark,delta;
coeff c;
if(argc<5) nrerror("Too few arguments supplied!");
if(argc>5) nrerror("Too many arguments supplied!");
FILE* f;
SACHEAD hd1,hd2;
f = fopen(argv[1],"rb");
t1 = atof(argv[3]);
t2 = atof(argv[4]);
tmark = 0;
strcpy(tempfile,argv[2]);
trace1 = vector(0,MAX_Array-1);
trace2 = read_sac2(tempfile,&hd2,tmark,t1,t2);
printf("%s\n",tempfile);
dt = hd2.delta;
npts= hd2.npts;
printf("%f\n",hd2.b);
strcpy(filename,"2000.168.07.58.46.0510.BL.POPB.10.BHZ.M.SAC");
trace1 = read_sac(filename,&hd1);
printf("%f\n",hd1.b);

while(fgets(filename,sizeof(filename),f)){
/* fscanf(f,"%s",filename); */
trace1 = read_sac2(filename,&hd1,tmark,t1,t2);
printf("%f\n",hd1.delta);
dtemp = hd1.delta;
if(dtemp!=dt) {
/* printf("Time_intervals of two files are not equal\n");
printf("Not processing %s ...\n",filename);*/
continue;
}
c = xcorr(trace1,trace2,dt);
hd1.b = hd1.b+c.time_lag;
write_sac(filename, hd1, trace1);
}
fclose(f);
free(trace1);
free(trace2);
return 0;
}

Best

18:25:54 v.22510d55