[cig-commits] [commit] pluggable: saving as evenly spaced SAC file (384ec0e)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Apr 9 08:55:22 PDT 2014


Repository : ssh://geoshell/specfem3d_globe

On branch  : pluggable
Link       : https://github.com/geodynamics/specfem3d_globe/compare/64e1b38f0c5ebb4056cce0b15d41c0b9f94ab6e5...099a4d330d5b173b21e51ad441f9f429e5d37842

>---------------------------------------------------------------

commit 384ec0e87417973d2c88cb0cd6020aa31738d95f
Author: Eh Tan <tan2 at earth.sinica.edu.tw>
Date:   Tue May 5 20:23:26 2009 +0000

    saving as evenly spaced SAC file


>---------------------------------------------------------------

384ec0e87417973d2c88cb0cd6020aa31738d95f
 UTILS/seis_process/asc2sac.c | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/UTILS/seis_process/asc2sac.c b/UTILS/seis_process/asc2sac.c
index 069538c..c1c1db8 100644
--- a/UTILS/seis_process/asc2sac.c
+++ b/UTILS/seis_process/asc2sac.c
@@ -11,19 +11,17 @@
 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];
@@ -32,14 +30,14 @@ main(int argc, char *argv[])
 
     /* 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 */
@@ -63,13 +61,15 @@ main(int argc, char *argv[])
     }
 
     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 @@ main(int argc, char *argv[])
     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 @@ main(int argc, char *argv[])
     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