[ Milenko Markovic @ 12.11.2012. 15:23 ] @
Imam jedan paket koji je manje vise pisan u c, cshell kompiluje vecinu programa sem par stvari. gcc -Wall -O4 -funroll-all-loops -fschedule-insns -malign-double -c shotrec2tt.c -o shotrec2tt.o shotrec2tt.c: In function ‘main’: shotrec2tt.c:39: warning: ‘rfname’ may be used uninitialized in this function shotrec2tt.c:39: warning: ‘sfname’ may be used uninitialized in this function shotrec2tt.c:43: warning: ‘mag_l’ may be used uninitialized in this function shotrec2tt.c:43: warning: ‘mag_md’ may be used uninitialized in this function gcc -Wall -O4 -funroll-all-loops -fschedule-insns -malign-double -o shotrec2tt shotrec2tt.o gi_line.o -lm shotrec2tt.o: In function `main': shotrec2tt.c:(.text+0xb33): undefined reference to `distaz' collect2: ld returned 1 exit status make: *** [shotrec2tt] Error 1 evo shortec2tt.c: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "ref_xyz.h" #define VER 2.0 #define FIX 0 #define AUTHOR "Ari Tryggvason" #define DATE "100323" #define MAXL 256 char *progname; int main(argc, argv) int argc; char **argv; { char *rfname, *sfname, string[MAXL]; int i, j, k, nr, ns, n_ml, verbose, sflg, lflg; float *mag_l, *mag_md; float vel, s_vel, dist, az, baz, xdeg; STN *src, *rec; FILE *rf_in, *sf_in; int get_line(), distaz(); /* defaults */ sflg = 0; lflg = 0; s_vel = 0.; vel = 2500.; verbose = 0; n_ml = 0; /* command line arguments */ progname = *argv; while (--argc > 0) { if (**(++argv) == '-') { switch (*(*argv + 1)) { case 'm': for (n_ml=1; argc-n_ml > 0 && **(argv+n_ml) != '-'; n_ml++); n_ml--; n_ml /= 2; mag_l = (float *) malloc(n_ml*sizeof(float)); mag_md = (float *) malloc(n_ml*sizeof(float)); for (i=0; i<n_ml; i++) { mag_l[i] = atof(*(argv+i*2+1)); mag_md[i] = atof(*(argv+i*2+2)); } break; case 'r': rfname = *(argv + 1); break; case 's': switch (*(*argv + 2)) { case 'l': lflg++; default: sfname = *(argv + 1); break; } break; case 'u': switch (*(*argv + 2)) { case 's': s_vel = atof(*(argv + 1)); break; case 'r': s_vel = -atof(*(argv+1)); break; default: vel = atof(*(argv + 1)); break; } break; case 'v': verbose++; break; default: fprintf(stderr, "%s: Error in command line.\n", progname); case 'H': case 'h': fprintf(stderr, "%s (V %.1f.%1d) Usage:\n", progname, VER, FIX); fprintf(stderr, "%s [-m mag1 lim1 mag2 lim2 ... magn limn] -r receiver.xyz -s[l] shot.xyz (l: in lat lon) -u velocity [-us Vs -ur Vp/Vs -v (verbose)] > 'stdout'\n", progname); return (-1); } /* close switch. */ } /* close if */ } /* close while */ fprintf(stderr,"%s V %.1f.%1d by %s %s\n", progname, VER, FIX, AUTHOR, DATE); sflg = (s_vel ? 1 : 0); if (sflg && s_vel < 0) s_vel = -vel/s_vel; if (verbose) { fprintf(stderr, "Velocity used: %f", vel); if (sflg) fprintf(stderr, " and %f", s_vel); fprintf(stderr, "\n"); fprintf(stderr, "Shot file: %s\nReceiver file: %s\n", sfname, rfname); if (n_ml) { fprintf(stderr, "Magnitude/offset limits: "); for (i=0; i<n_ml; i++) fprintf(stderr, "%.1f %.1f ", mag_l[i], mag_md[i]); fprintf(stderr, "\n"); } } /* open input files */ if ((rf_in = fopen(rfname, "r")) == (FILE *) NULL) { fprintf(stderr, "%s: Can't open file %s.\n", progname, rfname); return (-1); } if ((sf_in = fopen(sfname, "r")) == (FILE *) NULL) { fprintf(stderr, "%s: Can't open file %s.\n", progname, sfname); return (-1); } /* count lines in the input files */ ns = nr = 0; while (get_line(rf_in, string, MAXL) != -1) { if (string[0] == '#' || string[0] == '>') continue; nr++; } rewind(rf_in); while (get_line(sf_in, string, MAXL) != -1) { if (string[0] == '#' || string[0] == '>') continue; ns++; } rewind(sf_in); if (verbose) fprintf(stderr,"No of receivers: %d\nNo of shots: %d\n", nr, ns); /* allocate memory */ if ((src = (STN *) malloc(ns*sizeof(STN))) == (STN *) NULL) { fprintf(stderr,"%s: Couldn't allocate memory for shot.\n", progname); return (-1); } if ((rec = (STN *) malloc(nr*sizeof(STN))) == (STN *) NULL) { fprintf(stderr,"%s: Couldn't allocate memory for rec.\n", progname); return (-1); } /* read in shots and receiver coordinates */ for (i=0;get_line(sf_in,string, MAXL) != -1;) { if (string[0] == '#' || string[0] == '>') continue; if (n_ml || lflg) sscanf(string, "%d %*d %*f %f %f %f %*f %f", &src[i].no, &src[i].y, &src[i].x, &src[i].z, &src[i].mag); else sscanf(string, "%d %f %f %f", &src[i].no, &src[i].x, &src[i].y, &src[i].z); i++; } for (j=0;get_line(rf_in,string, MAXL) != -1;) { if (string[0] == '#' || string[0] == '>') continue; if (lflg) sscanf(string, "%d %f %f %f", &rec[j].no, &rec[j].y, &rec[j].x, &rec[j].z); else sscanf(string, "%d %f %f %f", &rec[j].no, &rec[j].x, &rec[j].y, &rec[j].z); j++; } if (verbose) fprintf(stderr,"No of receivers read: %d\nNo of shots read: %d\n", j, i); /* output */ for (i=0; i<ns; i++) for (j=0; j<nr; j++) { if (n_ml) { distaz(&rec[j].x, &rec[j].y, &dist, &az, &baz, &xdeg, src[i].x, src[i].y, 1); for (k=0; k<n_ml; k++) if (src[i].mag < mag_l[k]) break; if (k<n_ml && dist > mag_md[k]) continue; fprintf(stdout, "%d %d %.6f", src[i].no, rec[j].no, sqrt(SQR(dist) + SQR(rec[j].z - src[i].z))/vel); if (sflg) fprintf(stdout, " %.6f", sqrt(SQR(dist) + SQR(rec[j].z - src[i].z))/s_vel); fprintf(stdout, "\n"); } else { fprintf(stdout, "%d %d %.6f", src[i].no, rec[j].no, HDIST(src[i].x, src[i].y, src[i].z, rec[j].x, rec[j].y, rec[j].z)/vel); if (sflg) fprintf(stdout, " %.6f", HDIST(src[i].x, src[i].y, src[i].z, rec[j].x, rec[j].y, rec[j].z)/s_vel); fprintf(stdout, "\n"); } } return(1); } /* the end */ [Ovu poruku je menjao X Files dana 12.11.2012. u 18:15 GMT+1] |