📄 susplit.c
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved. *//* SUSPLIT */#include "su.h"#include "segy.h"#include "header.h"#include "bheader.h"#include "tapebhdr.h"/*********************** self documentation ******************************/char *sdoc[] = {" "," SUSPLIT - Split traces into different output files by keyword value "," "," susplit <stdin >stdout [options] "," "," Required Parameters: "," none "," "," Optional Parameters: "," key=cdp Key header word to split on (see segy.h) "," stem=split_ Stem name for output files "," middle=key middle of name of output files "," suffix=.su Suffix for output files "," numlength=3 Length of numeric part of filename "," verbose=0 =1 to echo filenames, etc. "," close=0 =1 to close files before opening new ones "," ",NULL};/* Credits: * Geocon: Garry Perratt hacked together from various other codes *//**************** end self doc *******************************************/segy tr;intmain(int argc, char **argv){ cwp_String key; /* header key word from segy.h */ Value ns_v; /* value of numsamps */ int ns_i; /* numsamps as int */ int numlength; /* length of split key number format */ char format[10]; /* output filename format */ Value val; /* value of key */ int val_i; /* key value as integer */ int lastval_i=0; /* last key value as integer */ cwp_String type; /* key's type */ char filename[999]; /* output file name */ int index; /* index of key */ cwp_String stem; /* output file stem */ cwp_String middle; /* output file middle */ cwp_String suffix; /* output file suffix */ FILE *fileout=NULL; /* pointer to output file */ int recl; /* record length */ char *trbuf=NULL; /* output trace buffer */ int init; /* initialisation flag for first efopen */ int verbose; /* =1 to echo filenames, etc. */ int close; /* =1 to close files before opening a new one */ /* Initialize */ initargs(argc, argv); requestdoc(1); init=0; /* Default parameters; User-defined overrides */ if (!getparstring("key", &key)) key="cdp"; if (!getparstring("stem", &stem)) stem="split_"; if (!getparstring("middle", &middle)) middle=key; if (!getparstring("suffix", &suffix)) suffix=".su"; if (!getparint("numlength", &numlength)) numlength=3; if (!getparint("verbose",&verbose)) verbose=0; if (!getparint("close",&close)) close=0; /* Evaluate time bounds from getpars and first header */ if (!gettr(&tr)) err("can't get first trace"); /* trace record length is numsamps * 4 + 240 */ type = hdtype("ns"); index = getindex("ns"); gethval(&tr, index, &ns_v); ns_i = vtoi(type, ns_v); recl = ns_i * FSIZE + HDRBYTES; trbuf = (char *) alloc1(recl, sizeof(char)); type = hdtype(key); index = getindex(key); if (verbose) warn("key is %s",key); /* Main loop over traces */ do { gethval(&tr, index, &val); val_i = vtoi(type, val); if (val_i!=lastval_i || init==0) { if (init==0) init=1; else if (close) efclose(fileout); (void)sprintf(format, "%%s%%s%%0%dd%%s",numlength); (void)sprintf(filename, format, stem, middle, val_i, suffix); if (verbose) warn("output file is %s",filename); fileout = efopen(filename, "ab"); } fwrite(&tr,sizeof(char),recl,fileout); lastval_i = val_i; } while (gettr(&tr)); return(CWP_Exit());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -