/* Copyright (c) Colorado School of Mines, 2011.*/
/* All rights reserved. */
/* SEGYWRITE: $Revision: 1.54 $ ; $Date: 2011/11/16 17:43:20 $ */
#ifdef SUXDR /* begin if SUXDR */
#include "su_xdr.h"
#else /* else if not SUXDR */
#include "su.h"
#include "segy.h"
#include "tapebhdr.h"
#endif /* end if SUXDR */
#include "tapesegy.h"
#include "bheader.h"
/*********************** self documentation **********************/
char *sdoc[] = {
" ",
" SEGYWRITE - write an SEG-Y tape ",
" ",
" segywrite <stdin tape= ",
" ",
" Required parameters: ",
" tape= tape device to use (see sudoc segyread) ",
" ",
" Optional parameter: ",
" verbose=0 silent operation ",
" =1 ; echo every 'vblock' traces ",
" vblock=50 echo every 'vblock' traces under verbose option ",
" buff=1 for buffered device (9-track reel tape drive) ",
" =0 possibly useful for 8mm EXABYTE drive ",
" conv=1 =0 don't convert to IBM format ",
" ebcdic=1 convert text header to ebcdic, =0 leave as ascii ",
" hfile=header ebcdic card image header file ",
" bfile=binary binary header file ",
" trmin=1 first trace to write ",
" trmax=INT_MAX last trace to write ",
" endian=1 =0 for little-endian machines (PC's, DEC,etc...)",
" errmax=0 allowable number of consecutive tape IO errors ",
" format= override value of format in binary header file ",
" ",
" Note: The header files may be created with 'segyhdrs'. ",
" ",
" ",
" Note: For buff=1 (default) tape is accessed with 'write', for buff=0 ",
" tape is accessed with fwrite. Try the default setting of buff=1 ",
" for all tape types. ",
" Caveat: may be slow on an 8mm streaming (EXABYTE) tapedrive ",
" Warning: segyread or segywrite to 8mm tape is fragile. Allow time ",
" between successive reads and writes. ",
" Precaution: make sure tapedrive is set to read/write variable blocksize",
" tapefiles. ",
" ",
" For more information, type: sudoc <segywrite> ",
" ",
NULL};
/*
* Warning: may return the error message "efclose: fclose failed"
* intermittently when segyreading/segywriting to 8mm EXABYTE tape,
* even if actual segyread/segywrite is successful. However, this
* may indicate that your tape drive has been set to a fixed block
* size. Tape drives should be set to variable block size before reading
* or writing tapes in the SEG-Y format.
*
* Credits:
* SEP: Einar Kjartansson
* CWP: Jack, Brian, Chris
* : John Stockwell (added EXABYTE functionality)
* Notes:
* Brian's subroutine, float_to_ibm, for converting IEEE floating
* point to IBM floating point is NOT portable and must be
* altered for non-IEEE machines. See the subroutine notes below.
*
* On machines where shorts are not 2 bytes and/or ints are not
* 4 bytes, routines to convert SEGY 16 bit and 32 bit integers
* will be required.
*
* The program, segyhdrs, can be used to make the ascii and binary
* files required by this code.
*/
/**************** end self doc ***********************************/
/* typedefs */
#ifdef SUXDR /* begin if SUXDR */
#if defined(_CRAYMPP) /* begin if _CRAYMPP */
typedef short fourbyte;
#else /* else if SUXDR but not _CRAYMPP */
typedef int fourbyte;
#endif /* end if _CRAYMPP */
#endif /* end if SUXDR */
/* subroutine prototypes */
#ifdef SUXDR /* begin if SUXDR */
static void float_to_ibm(fourbyte *from, fourbyte *to, int n, int endian);
#else /* if not SUXDR */
static void float_to_ibm(int from[], int to[], int n, int endian);
static void bhed_to_tapebhed(const bhed *bhptr, tapebhed *tapebhptr);
static void
segy_to_tapesegy(const segy *trptr, tapesegy *tapetrptr, size_t nsegy);
/* globals */
tapesegy tapetr;
tapebhed tapebh;
#endif /* end if SUXDR */
/* globals */
segy tr;
bhed bh;
int
main(int argc, char **argv)
{
cwp_String tape; /* name of raw tape device */
cwp_String hfile; /* name of ebcdic header file */
cwp_String bfile; /* name of binary header file */
#ifdef SUXDR /* begin SUXDR */
int j; /* counter */
FILE *headerfp; /* file pointer to header file */
#else /* else if not SUXDR */
FILE *pipefp; /* file pointer for popen read */
#endif /* end if SUXDR */
FILE *tapefp=NULL; /* file pointer for tape */
FILE *binaryfp; /* file pointer for bfile */
int tapefd=0; /* file descriptor for tape buff=0 */
int i; /* counter */
int ns; /* number of data samples */
size_t nsegy; /* size of whole trace in bytes */
int itr; /* current trace number */
int trmax; /* last trace to write */
int trmin; /* first trace to write */
int verbose; /* echo every ... */
int vblock; /* ... vblock traces with verbose=1 */
int buff; /* buffered or unbuffered device */
int endian; /* =0 little endian; =1 big endian */
int conv; /* =1 IBM format =0 don't convert */
int ebcdic=1; /* =1 ebcdic =0 don't convert */
int errmax; /* max consecutive tape io errors */
int errcount = 0; /* counter for tape io errors */
int format = 0; /* tape format */
cwp_Bool format_set = cwp_false; /* tape format */
#ifdef SUXDR /* begin if SUXDR */
#if defined(CRAY) /* begin if defined CRAY */
#if defined(_CRAYMPP) /* begin if defined _CRAYMPP */
fourbyte imone = -1; /* constant for Fortran linkage */
fourbyte fns; /* for Fortran CRAYMPP linkage */
#else /* CRAY but not _CRAYMPP */
int ier; /* CRAY ibmfloat error flag */
fourbyte ione = -1; /* constant for Fortran linkage */
#endif /* end if _CRAYMPP */
#endif /* end if SUXDR and CRAY but not _CRAYMPP */
char ebcbuf[EBCBYTES+1];/* ebcdic data buffer */
char bhbuf[BNYBYTES]; /* binary reel header buffer */
char *trbuf; /* output trace buffer */
XDR bhed_xdr, bhbuf_xdr;/* for handling binary reel header */
XDR trhd_xdr;
unsigned int trstart; /* "offset" of trhd stream buffer */
#else /* not Cray and not SUXDR */
char cmdbuf[BUFSIZ]; /* dd command buffer */
char ebcbuf[EBCBYTES]; /* ebcdic data buffer */
#endif /* end if SUXDR */
/* Initialize */
initargs(argc, argv);
requestdoc(1);
/* Get parameters */
MUSTGETPARSTRING("tape", &tape);
if (!getparstring("hfile", &hfile)) hfile = "header";
if (!getparstring("bfile", &bfile)) bfile = "binary";
if (!getparint ("trmin", &trmin)) trmin = 1;
if (!getparint ("trmax", &trmax)) trmax = INT_MAX;
if (!getparint ("verbose", &verbose)) verbose = 0;
if (!getparint ("vblock", &vblock)) vblock = 50;
if (!getparint ("buff", &buff)) buff = 1;
if (!getparint ("conv", &conv)) conv = 1;
if (!getparint ("ebcdic", &ebcdic)) ebcdic = 1;
if (!getparint("endian", &endian)) {
union { short s; char c[2]; } testend;
testend.s = 1;
endian = (testend.c[0] == '\0') ? 1 : 0;
}
if (!getparint ("errmax", &errmax)) errmax = 0;
if (getparint("format", &format)) format_set = cwp_true;
checkpars();
/* Check parameters */
if (trmin < 1 || trmax < 1 || trmax < trmin)
err("bad trmin/trmax values, trmin = %d, trmax = %d",
trmin, trmax);
/* Get first trace early to be sure that binary file is ready */
gettr(&tr);
/* Open files - first the tape */
if (buff) tapefd = eopen(tape, O_WRONLY | O_CREAT | O_TRUNC, 0666);
else tapefp = efopen(tape, "w");
if (verbose) warn("tape opened successfully ");
#ifdef SUXDR /* begin SUXDR */
/* Open ascii header file */
headerfp = efopen(hfile, "r");
if (verbose) warn("header file opened successfully");
/* - binary header file */
binaryfp = efopen(bfile, "r");
xdrstdio_create(&bhed_xdr,binaryfp,XDR_DECODE);
xdrmem_create(&bhbuf_xdr,bhbuf,BNYBYTES,XDR_ENCODE);
if (verbose) warn("binary file opened successfully");
/* Read ascii header into buffer and blank newlines & nulls */
memset(&(ebcbuf[0]),0,EBCBYTES);
if (ebcdic==1) {
for(i = 0; i<EBCBYTES; i += 80) {
fgets(&(ebcbuf[i]),81, headerfp);
j = (int) strlen(&(ebcbuf[i]));
ebcbuf[i+j] = ' ';
j--;
}
/* Convert to EBC
segywrite.zip_segy_segy 读写_segywrite_segy格式数据读写
版权申诉
76 浏览量
2022-09-14
23:24:36
上传
评论
收藏 6KB ZIP 举报
御道御小黑
- 粉丝: 61
- 资源: 1万+
最新资源
- STC15单片机串口2使用程序例子
- 读取日志的excel生成周报 用python3开发weekplan-master.zip
- python 读取excel数据导入dbimport-data-master.zip
- K折交叉验证BP神经网络,多输入多输出BP神经网络(代码完整,数据齐全)
- B07训练原图.zip
- python-对Excel数据处理做可视化分析.zip
- 人工智能大作业-无人机图像目标检测的python源代码+文档说明.zip
- 基于GoogLeNet实现Cifar-10图像分类项目python源码(高分项目).zip
- 数据库 sql 面试题目及答案解析.docx
- 汽车常见 10 种传感器故障后的表现与解决措施.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0