par.h

Go to the documentation of this file.
00001 /* Copyright (c) Colorado School of Mines, 2002.*/
00002 /* All rights reserved.                       */
00003 
00004 /* par.h - include file for getpar, selfdoc, and error handling functions */
00005 
00006 #ifndef PAR_H
00007 #define PAR_H
00008 
00009 
00010 /* INCLUDES */
00011 
00012 #include "cwp.h"
00013 
00014 /* GLOBAL DECLARATIONS */
00015 extern int xargc; extern char **xargv;
00016 
00017 /* ssize_t does not exist on some systems */
00018 #ifndef ssize_t
00019 #define ssize_t int
00020 #endif
00021 
00022 
00023 /* TYPEDEFS */
00024 typedef enum {cwp_false, cwp_true} cwp_Bool;
00025 typedef char *cwp_String;
00026 
00027 typedef enum {BADFILETYPE = -1,
00028     TTY, DISK, DIRECTORY, TAPE, PIPE, FIFO, SOCKET, SYMLINK} FileType;
00029     
00030 /* define structures for Hale's modeling */
00031 typedef struct ReflectorSegmentStruct {
00032     float x;    /* x coordinate of segment midpoint */
00033     float z;    /* z coordinate of segment midpoint */
00034     float s;    /* x component of unit-normal-vector */
00035     float c;    /* z component of unit-normal-vector */
00036 } ReflectorSegment;
00037 typedef struct ReflectorStruct {
00038     int ns;         /* number of reflector segments */
00039     float ds;       /* segment length */
00040     float a;        /* amplitude of reflector */
00041     ReflectorSegment *rs;   /* array[ns] of reflector segments */
00042 } Reflector;
00043 typedef struct WaveletStruct {
00044     int lw;         /* length of wavelet */
00045     int iw;         /* index of first wavelet sample */
00046     float *wv;      /* wavelet sample values */
00047 } Wavelet;
00048 
00049 
00050 /* DEFINES */
00051 
00052 /* getpar macros */
00053 #define MUSTGETPARINT(x,y) if(!getparint(x,y)) suerr("must specify %s=",x)
00054 #define MUSTGETPARFLOAT(x,y) if(!getparfloat(x,y)) suerr("must specify %s=",x)
00055 #define MUSTGETPARSTRING(x,y) if(!getparstring(x,y)) suerr("must specify %s=",x)
00056 
00057 #define STDIN (0)
00058 #define STDOUT (1)
00059 #define STDERR (2)
00060 
00061 
00062 /* FUNCTION PROTOTYPES */
00063 
00064 #ifdef __cplusplus  /* if C++, specify external C linkage */
00065 extern "C" {
00066 #endif
00067 
00068 /* getpar parameter parsing */
00069 void initargs (int argc, char **argv);
00070 int getparint (char *name, int *p);
00071 int getparuint (char *name, unsigned int *p);
00072 int getparshort (char *name, short *p);
00073 int getparushort (char *name, unsigned short *p);
00074 int getparlong (char *name, long *p);
00075 int getparulong (char *name, unsigned long *p);
00076 int getparfloat (char *name, float *p);
00077 int getpardouble (char *name, double *p);
00078 int getparstring (char *name, char **p);
00079 int getparstringarray (char *name, char **p);
00080 int getnparint (int n, char *name, int *p);
00081 int getnparuint (int n, char *name, unsigned int *p);
00082 int getnparshort (int n, char *name, short *p);
00083 int getnparushort (int n, char *name, unsigned short *p);
00084 int getnparlong (int n, char *name, long *p);
00085 int getnparulong (int n, char *name, unsigned long *p);
00086 int getnparfloat (int n, char *name, float *p);
00087 int getnpardouble (int n, char *name, double *p);
00088 int getnparstring (int n, char *name, char **p);
00089 int getnparstringarray (int n, char *name, char **p);
00090 int getnpar (int n, char *name, char *type, void *ptr);
00091 int countparname (char *name);
00092 int countparval (char *name);
00093 int countnparval (int n, char *name);
00094 
00095 /* For ProMAX */
00096 void getPar(char *name, char *type, void *ptr);
00097 
00098 /* errors and warnings */
00099 void suerr(char *fmt, ...);
00100 void syssuerr(char *fmt, ...);
00101 void suwarn(char *fmt, ...);
00102 
00103 /* self documentation */
00104 void pagedoc (void);
00105 void requestdoc (int i);
00106 
00107 /* system calls with error trapping */
00108 int ecreat(char *path, int perms);
00109 int efork(void);
00110 int eopen(char *path, int flags, int perms);
00111 int eclose(int fd);
00112 int eunlink(char *path);
00113 long elseek(int fd, long offset, int origin);
00114 int epipe(int fd[2]);
00115 
00116 ssize_t eread(int fd, char *buf, size_t nbytes);
00117 ssize_t ewrite(int fd, char *buf, size_t nbytes);
00118 
00119 /* system subroutine calls with error trapping */
00120 FILE *efopen(const char *file, const char *mode);
00121 FILE *efreopen(const char *file, const char *mode, FILE *stream1);
00122 FILE *efdopen(int fd, const char *mode);
00123 FILE *epopen(char *command, char *type);
00124 int efclose(FILE *stream);
00125 int epclose(FILE *stream);
00126 int efflush(FILE *stream);
00127 int eremove(const char *file);
00128 int erename(const char *oldfile, const char* newfile);
00129 int efseeko(FILE *stream, off_t offset, int origin);
00130 int efseek(FILE *stream, long offset, int origin);
00131 long eftell(FILE *stream);
00132 off_t eftello(FILE *stream);
00133 void erewind(FILE *stream);
00134 FILE *etmpfile(void);
00135 char *etmpnam(char *namebuffer);
00136 void *emalloc(size_t size);
00137 void *erealloc(void *memptr, size_t size);
00138 void *ecalloc(size_t count, size_t size);
00139 size_t efread(void *bufptr, size_t size, size_t count, FILE *stream);
00140 size_t efwrite(void *bufptr, size_t size, size_t count, FILE *stream);
00141 
00142 /* some SUN users may need to comment out the next two items, */
00143 /* if your system does not have "fgetpos()" and "fsetpos()" defined. */
00144 /* You will also need to comment out the lines defining the functions */
00145 /* efgetpos() and efsetpos() in CWPROOT/src/par/lib/subcalls.c */
00146 
00147 /* Modified: 21 June 1995: */
00148 /* so that setting -DSUN_A in Makefile.config should make this unnecessary */
00149 /* CWP: John Stockwell */
00150 
00151 #ifndef SUN_A
00152 int efgetpos(FILE *stream, fpos_t *position);
00153 int efsetpos(FILE *stream, const fpos_t *position);
00154 #endif
00155 
00156 /* allocation with error trapping */
00157 void *ealloc1 (size_t n1, size_t size);
00158 void *erealloc1 (void *v, size_t n1, size_t size);
00159 void **ealloc2 (size_t n1, size_t n2, size_t size);
00160 void ***ealloc3 (size_t n1, size_t n2, size_t n3, size_t size);
00161 void ****ealloc4 (size_t n1, size_t n2, size_t n3, size_t n4, size_t size);
00162 void ****ealloc4 (size_t n1, size_t n2, size_t n3, size_t n4, size_t size);
00163 void *****ealloc5 (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, size_t size);
00164 void ******ealloc6 (size_t n1, size_t n2, size_t n3, size_t n4, size_t n5,
00165                   size_t n6, size_t size);
00166 
00167 int *ealloc1int(size_t n1);
00168 int *erealloc1int(int *v, size_t n1);
00169 int **ealloc2int(size_t n1, size_t n2);
00170 int ***ealloc3int(size_t n1, size_t n2, size_t n3);
00171 float *ealloc1float(size_t n1);
00172 float *erealloc1float(float *v, size_t n1);
00173 float **ealloc2float(size_t n1, size_t n2);
00174 float ***ealloc3float(size_t n1, size_t n2, size_t n3);
00175 
00176 int ****ealloc4int(size_t n1, size_t n2, size_t n3, size_t n4);
00177 int *****ealloc5int(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5);
00178 float ****ealloc4float(size_t n1, size_t n2, size_t n3, size_t n4);
00179 float *****ealloc5float(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5);
00180 float ******ealloc6float(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5,
00181        size_t n6);
00182 
00183 unsigned short *****ealloc5ushort(size_t n1, size_t n2,
00184          size_t n3, size_t n4, size_t n5);
00185 unsigned char *****ealloc5uchar(size_t n1, size_t n2,
00186         size_t n3, size_t n4, size_t n5);
00187 unsigned short ******ealloc6ushort(size_t n1, size_t n2,
00188          size_t n3, size_t n4, size_t n5, size_t n6);
00189 
00190 double *ealloc1double(size_t n1);
00191 double *erealloc1double(double *v, size_t n1);
00192 double **ealloc2double(size_t n1, size_t n2);
00193 double ***ealloc3double(size_t n1, size_t n2, size_t n3);
00194 
00195 /* string to numeric conversion with error checking */
00196 short eatoh(char *s);
00197 unsigned short eatou(char *s);
00198 int eatoi(char *s);
00199 unsigned int eatop(char *s);
00200 long eatol(char *s);
00201 unsigned long eatov(char *s);
00202 float eatof(char *s);
00203 double eatod(char *s);
00204 
00205 /* file type checking */
00206 FileType filestat(int fd);
00207 char *printstat(int fd);
00208 
00209 /* Hale's modeling code */
00210 void decodeReflectors (int *nrPtr,
00211     float **aPtr, int **nxzPtr, float ***xPtr, float ***zPtr);
00212 int decodeReflector (char *string,
00213     float *aPtr, int *nxzPtr, float **xPtr, float **zPtr);
00214 void breakReflectors (int *nr, float **ar, 
00215     int **nu, float ***xu, float ***zu);
00216 void makeref (float dsmax, int nr, float *ar, 
00217     int *nu, float **xu, float **zu, Reflector **r);
00218 void raylv2 (float v00, float dvdx, float dvdz,
00219     float x0, float z0, float x, float z,
00220     float *c, float *s, float *t, float *q);
00221 void addsinc (float time, float amp,
00222     int nt, float dt, float ft, float *trace);
00223 void makericker (float fpeak, float dt, Wavelet **w);
00224 
00225 /* upwind eikonal stuff */
00226 void eikpex (int na, float da, float r, float dr, 
00227     float sc[], float uc[], float wc[], float tc[],
00228     float sn[], float un[], float wn[], float tn[]);
00229 void ray_theoretic_sigma (int na, float da, float r, float dr, 
00230     float uc[], float wc[], float sc[],
00231     float un[], float wn[], float sn[]);
00232 void ray_theoretic_beta (int na, float da, float r, float dr, 
00233     float uc[], float wc[], float bc[],
00234     float un[], float wn[], float bn[]);
00235 void eiktam (float xs, float zs, 
00236     int nz, float dz, float fz, int nx, float dx, float fx, float **vel,
00237     float **time, float **angle, float **sig, float **beta);
00238 
00239 /* smoothing routines */
00240 void dlsq_smoothing (int nt, int nx, int ift, int ilt, int ifx, int ilx,
00241         float r1, float r2, float rw, float **traces);
00242 void SG_smoothing_filter (int np, int nl, int nr, int ld, int m, float *filter);
00243 void rwa_smoothing_filter (int flag, int nl, int nr, float *filter);
00244 void gaussian2d_smoothing (int nx, int nt, int nsx, int nst, float **data);
00245 void gaussian1d_smoothing (int ns, int nsr, float *data);
00246 void smooth_histogram (int nintlh, float *pdf);
00247 
00248 /* function minimization */
00249 void bracket_minimum(float *ax, float *bx, float *cx, float *fa,
00250                 float *fb,float *fc, float (*func)(float));
00251 float golden_bracket(float ax, float bx, float cx,
00252                         float (*f)(float), float tol,float *xmin);
00253 float brent_bracket(float ax, float bx, float cx,
00254                 float (*f)(float), float tol, float *xmin);
00255 
00256 void linmin(float p[],float xi[],int n,float *fret, float (*func)());
00257 void powell_minimization(float p[], float **xi, int n,
00258                 float ftol,int *iter,float *fret,float (*func)());
00259 
00260 /***** lincoeff -- linearized reflection coefficients */
00261 /* type definitions */
00262 
00263 typedef struct ErrorFlagStructure
00264     {
00265       float iso[5];
00266       float upper[2];
00267       float lower[2];
00268       float global[4];
00269       float angle[4];
00270   } ErrorFlag;
00271 
00272 /* prototypes for functions defined */
00273 
00274 float Rp(float ang, float azim, float kappa, float *rpp, ErrorFlag *rp_1st, ErrorFlag *rp_2nd, 
00275          int count);
00276 
00277 float Rs(float ang, float azim, float kappa, float *rps1, float *rps2, 
00278        float *sv, float *sh, float *cphi, float *sphi, int i_hsp,
00279        ErrorFlag *rsv_1st, ErrorFlag *rsv_2nd, ErrorFlag *rsh_1st, ErrorFlag *rsh_2nd, int count);
00280 
00281 float Iso_exact(int type, float vp1, float vs1, float rho1, 
00282           float vp2, float vs2, float rho2, float ang);  
00283 
00284 int Phi_rot(float *rs1,float *rs2,int iso_plane,float pb_x,float pb_y,float pb_z,float gs1_x,float gs1_y,
00285        float gs1_z,float gs2_x,float gs2_y,float gs2_z,float *CPhi1,float *SPhi1,float *CPhi2,float
00286 *SPhi2);
00287 
00288 /* there are other functions involved. However, they are declared inside of the corresponding
00289    routines */
00290 /*** end lincoeff */
00291 
00292 #ifdef __cplusplus  /* if C++ (external C linkage is being specified) */
00293 }
00294 #endif
00295 
00296 #endif /* PAR_H */

Generated on 5 Jan 2017 for IWAVE by  doxygen 1.4.7