⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvt2segd.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* do our best to avoid 2Gig filesize limits */#ifndef _LARGEFILE_SOURCE#define _LARGEFILE_SOURCE#endif#ifndef _LARGEFILE64_SOURCE#define _LARGEFILE64_SOURCE#endif#ifdef __GNUC__#ifndef _GNU_SOURCE#define _GNU_SOURCE#include <byteswap.h>#endif#endif#ifdef _AIX#ifndef _ALL_SOURCE#define _ALL_SOURCE#endif#ifndef _LARGE_FILES#define _LARGE_FILES#endif#endif#ifndef _FILE_OFFSET_BITS#define _FILE_OFFSET_BITS 64#endif#include <stdio.h>#include <stdlib.h>#if !defined(_WIN32)#include <unistd.h>#endif#include <math.h>#include <errno.h>#include <string.h>#include <ctype.h>#include <malloc.h>#include <fcntl.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <rpc/types.h>#include <netinet/in.h>/* * The <SeisData.h> file has some COLORREF variables defined for setting * the colors to support first break picking.  A COLORREF is simply * a 32 bit unsigned integer.  Remove the following statement if you * are running on an NT machine.  If you are running on a UNIX machine * leave it as is. */#if !defined(_WIN32)typedef unsigned long int COLORREF;  /* COLORREF is defined by windows */typedef unsigned long int DWORD;     /* DWORD is defined by windows    */typedef long int BOOL;               /* BOOL is defined by windows     */#endif#include "SeisData.h"static int big_endian;/* * Define a number to identify a data object.  This only needed to make sure * that the file we are reading is really a valid data object file. */static DWORD SEISDATAOBJECTID = 0x78F7B6CA;/* self-documentation */static void syntax(const char *program_name) {   fprintf(stderr,"Syntax: %s [-o out_segd_filename] infile1 [ infile2 ... ]\n",           program_name);    fprintf(stderr,"\n        Default output is stdout if -o not supplied\n");   fprintf(stderr,"        infile name(s) that don't match \"FFID_*%%*.SEIS\" are ignored\n");   fprintf(stderr,"\n        Copyright 2002, Landmark Graphics Corp., All Rights Reserved.\n");   exit(EXIT_FAILURE);}/* sanity check input SeisNet filename */static BOOL check_filename(const char* inname) {  const char *ptr = inname;  const char ffid[] = "FFID_";  const char seis[] = ".SEIS";  int i,n;  /* make sure filename begins with FFID_ */  n = strlen(ffid);  for(i=0; i<n; ++i)     if(toupper(ptr[i]) != ffid[i]) return ((BOOL) (!1));   /* make sure that there is a % sign after initial FFID_ */  ptr += n;  while((*ptr) != '\000') {    if((*ptr) == '\045') break;    ++ptr;  }    if((*ptr) == '\000') return ((BOOL) (!1));  /* make sure filename ends in ".SEIS" */  n = strlen(seis);  ptr += (strlen(ptr) - n);    if(ptr < inname) return ((BOOL) (!1));  for(i=0; i<n; ++i)     if(toupper(ptr[i]) != seis[i]) return ((BOOL) (!1));   /* we passed our sanity checks */  return ((BOOL) (!(!1)));}/* * byte swapping routines from ProMAX maxutil/misc  */static void u_swapends4(void *array, int nvals)       {                                               unsigned int *ivals = (unsigned int *) array;  int i;                                         for(i=0; i<nvals; ++i)                         {                                             #if defined(__i386)   ivals[0] = bswap_32(ivals[0]);              #else                                             unsigned int tmp1, tmp2;                       tmp1 = (ivals[0]<<16)+(ivals[0]>>16);          tmp2 = tmp1&0xff00ff00;                        ivals[0] = ((tmp1-tmp2)<<8) + (tmp2>>8);    #endif                                            ++ivals;                                     }                                             }                                              static void u_swapends2(void *array, int nvals){#if defined(__i386) int i; unsigned short *ivals = (unsigned short *) array; for(i=0; i<nvals; ++i) {   ivals[0] = bswap_16(ivals[0]);   ++ivals; }#else swab(array, array, nvals*2);#endif}static void writeTODcount(FILE*out_segd, const char *segd_outname, size_t nbytes) {    ssize_t nwrite;    size_t nb;    nb = htonl(nbytes);    errno = 0;    nwrite = fwrite((void *) &nb, sizeof(nb), 1, out_segd);    if(nwrite < 1) {      perror(segd_outname);      fprintf(stderr,"%s write of SEGD TOD byte count\n",	 (nwrite < 0) ? "Bad" : "Short");      fprintf(stderr,"Exiting.\n"); exit(EXIT_FAILURE);    }}static void writeTODdata(FILE *out_segd, const char *segd_outname, void *buf, size_t nbytes) {    ssize_t nwrite;    errno = 0;    nwrite = fwrite((void *) buf, sizeof(char), nbytes, out_segd);    if(nwrite < nbytes) {      perror(segd_outname);      fprintf(stderr,"%s write of SEGD record\n",	 (nwrite < 0) ? "Bad" : "Short");      fprintf(stderr,"Exiting.\n"); exit(EXIT_FAILURE);    }}static void writeTODrec(FILE *out_segd, const char *segd_outname, void *buf, size_t nbytes) {    ssize_t nwrite;    writeTODcount(out_segd, segd_outname, nbytes);    writeTODdata(out_segd, segd_outname, buf, nbytes);    writeTODcount(out_segd, segd_outname, nbytes);}/* * Start of the main program. */int main (int argc, char **argv){    /* Declare some local variables */    ssize_t nread, nwrite;    int ntraces;    size_t nb;    int i,j;    off_t nbytes;    SEISFILEHEADER sh;      /* See the <SeisData.h> file */    SEISDATAPARMS sd;	    /* See the <SeisData.h> file */    SEISTRACELOCATION *pl;  /* See the <SeisData.h> file */    TRACEDATA *td;	    /* See the <SeisData.h> file */    SEISTRACEHEADER *thdr;  /* See the <SeisData.h> file */    unsigned char *segd;    /* SEG-D file headers */    float *trace;           /* little endian IEEE float */    unsigned char *seghead; /* SEG-D trace header */    FILE *in_seisnet;       /* input SeisNet file handle */    FILE *out_segd;         /* output SEG-D file handle */    const char *segd_outname;     /* output SEG-D filename or "stdout" */    char **inname_ptr;      /* where SeisNet filenames start in cmdline */    int ifile, nfiles;    /* check local endianness to see if we need to byte swap from     * the PC little-endian format of SeisData file.     */    big_endian = (1 == htonl(1));    if(big_endian) u_swapends4((void *) &SEISDATAOBJECTID, 1);    /* process command line flag(s) */    inname_ptr = argv+1;    if(argc < 2) syntax(argv[0]); /* need at least one input filename */    if(0 == strncmp(argv[1],"-o",strlen("-o"))) { /* explicit output SEG-D filename */       char *ptr = argv[1]+strlen("-o");       inname_ptr++;       if(*ptr == '\0' && argc > 2) {	    ptr = argv[2]; /* next arg filename */	    inname_ptr++;       }       if(*ptr == '\0') syntax(argv[0]); /* couldn't get a filename */       segd_outname = ptr;       out_segd =  fopen(ptr,"wb");       if(out_segd == ((FILE *) NULL)) {	 perror(ptr);	 fprintf(stderr,"Failed to open output file \"%s\"\n", ptr);	 exit(EXIT_FAILURE);       }    } else {       out_segd = stdout;       segd_outname = "stdout";    }        /* remaining command line arguments are input filenames */    nfiles = argc - (inname_ptr - argv);    for(ifile = 0; ifile < nfiles; ++ifile) {	/*	 * Cycle through all the data file. Note the format of the filename. 	 *	 * FFID_ ------> Identifies the file as a shot record	 * 101 --------> The FFID of the shot record	 * %843066991 -> Number of seconds since Jan 1, 1970 (a time stamp)	 *	 * .SEIS ------> Filename extension for SeisNet Seismic Data files	 *	 * Encoding this information in the filename makes sorting much easier	 * for real time applications	 */        if(!check_filename(inname_ptr[ifile])) {           fprintf(stderr,"*** skipping input file \"%s\"\n",inname_ptr[ifile]);           continue;        }        /* open next input file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -