[cig-commits] r14873 - seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/UTILS/seis_process
tan2 at geodynamics.org
tan2 at geodynamics.org
Tue May 5 13:23:27 PDT 2009
Author: tan2
Date: 2009-05-05 13:23:26 -0700 (Tue, 05 May 2009)
New Revision: 14873
Modified:
seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/UTILS/seis_process/asc2sac.c
Log:
saving as evenly spaced SAC file
Modified: seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/UTILS/seis_process/asc2sac.c
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/UTILS/seis_process/asc2sac.c 2009-05-05 18:57:52 UTC (rev 14872)
+++ seismo/3D/SPECFEM3D_GLOBE/branches/pluggable/UTILS/seis_process/asc2sac.c 2009-05-05 20:23:26 UTC (rev 14873)
@@ -11,37 +11,35 @@
int
main(int argc, char *argv[])
{
- int npts, nerr, i;
- int itmp;
+ long int npts, nerr, i;
+ long int itmp;
float ftmp;
char *endptr, *str;
char *ascfn, *sacfn;
float *time, *data;
- float a, b;
- char buffer[255];
FILE *f;
if(argc < 4) {
- fprintf(stderr, "%s ascii-file npts sac-file\n", argv[0]);
- exit(1);
+ fprintf(stderr, "%s ascii-file npts sac-file\n", argv[0]);
+ exit(1);
}
str = argv[2];
errno = 0;
npts = strtol(str, &endptr, 10);
-
+
/* Check for various possible errors */
if ((errno == ERANGE && (npts == INT_MAX || npts == INT_MIN))
- || (errno != 0 && npts <= 0)) {
- perror("strtol");
- exit(EXIT_FAILURE);
+ || (errno != 0 && npts <= 0)) {
+ perror("strtol");
+ exit(EXIT_FAILURE);
}
-
+
if (endptr == str) {
- fprintf(stderr, "No npts were found\n");
- exit(EXIT_FAILURE);
+ fprintf(stderr, "No npts were found\n");
+ exit(EXIT_FAILURE);
}
-
+
/* If we got here, strtol() successfully parsed a number */
ascfn = argv[1];
sacfn = argv[3];
@@ -61,15 +59,17 @@
fprintf(stderr, "Cannot open file '%s' to read\n", ascfn);
exit(-1);
}
-
+
for(i=0; i<npts; i++) {
- fgets(buffer, 254, f);
- if(sscanf(buffer, "%f %f\n", &a, &b) != 2) {
- fprintf(stderr, "error when reading file '%s'\n", ascfn);
- exit(-1);
- }
- time[i] = a;
- data[i] = b;
+ char buffer[255];
+ float a, b;
+ fgets(buffer, 254, f);
+ if(sscanf(buffer, "%f %f\n", &a, &b) != 2) {
+ fprintf(stderr, "error when reading file '%s'\n", ascfn);
+ exit(-1);
+ }
+ time[i] = a;
+ data[i] = b;
}
fclose(f);
/* finished reading ascii file */
@@ -78,9 +78,7 @@
nerr = 0;
newhdr();
setnhv("npts", &npts, &nerr, strlen("npts"));
- itmp = 6;
- setnhv("nvhdr", &itmp, &nerr, strlen("nvhdr"));
- itmp = 0;
+ itmp = 1;
setlhv("leven", &itmp, &nerr, strlen("leven"));
ftmp = time[1] - time[0];
setfhv("delta", &ftmp, &nerr, strlen("delta"));
@@ -97,8 +95,8 @@
wsac0(sacfn, time, data, &nerr, strlen(sacfn));
if(nerr) {
- fprintf(stderr, "error when writing '%s'\n", sacfn);
- exit(-1);
+ fprintf(stderr, "error when writing '%s'\n", sacfn);
+ exit(-1);
}
return 0;
More information about the CIG-COMMITS
mailing list