void sf_setformat (sf_file file, const char* format) /*< Set file format. --- format has a form "form_type", i.e. native_float, ascii_int, etc. >*/ { if (NULL != strstr(format,"float")) { sf_settype(file,SF_FLOAT); } else if (NULL != strstr(format,"int")) { sf_settype(file,SF_INT); } else if (NULL != strstr(format,"complex")) { sf_settype(file,SF_COMPLEX); } else if (NULL != strstr(format,"uchar") || NULL != strstr(format,"byte")) { sf_settype(file,SF_UCHAR); } else if (NULL != strstr(format,"short")) { sf_settype(file,SF_SHORT); } else if (NULL != strstr(format,"long")) { sf_settype(file,SF_LONG); } else if (NULL != strstr(format,"double")) { sf_settype(file,SF_DOUBLE); } else { sf_settype(file,SF_CHAR); } if (0 == strncmp(format,"ascii_",6)) { sf_setform(file,SF_ASCII); } else if (0 == strncmp(format,"xdr_",4)) { sf_setform(file,SF_XDR); } else { sf_setform(file,SF_NATIVE); } }
int main(int argc, char* argv[]) { int n1, n2, i2, esize; off_t pos; struct skey *sorted; float *unsorted; char *trace, *header; sf_file in, head, out; sf_init (argc,argv); in = sf_input ("in"); out = sf_output ("out"); header = sf_getstring("head"); /* header file */ if (NULL == header) { header = sf_histstring(in,"head"); if (NULL == header) sf_error("Need head="); } head = sf_input(header); if (SF_FLOAT != sf_gettype(head)) sf_error("Need float header"); n2 = sf_filesize(head); unsorted = sf_floatalloc(n2); sorted = (struct skey*) sf_alloc(n2,sizeof(struct skey)); sf_floatread(unsorted,n2,head); for (i2 = 0; i2 < n2; i2++) { sorted[i2].key = unsorted[i2]; sorted[i2].pos = i2; } free (unsorted); sf_fileclose(head); qsort(sorted,n2,sizeof(struct skey),key_compare); if (!sf_histint(in,"n1",&n1)) n1=1; esize = sf_esize(in); n1 *= esize; trace = sf_charalloc(n1); sf_unpipe(in,((off_t) n1)*((off_t) n2)); sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); pos = sf_tell(in); for (i2=0; i2<n2; i2++) { sf_seek(in,pos+(sorted[i2].pos)*n1,SEEK_SET); sf_charread(trace,n1,in); sf_charwrite(trace,n1,out); } exit(0); }
int main(int argc, char* argv[]) { int n1, is, ns, nf, esize, pad; off_t i2, n2; char *trace, *zero; sf_file in, shift; sf_init(argc,argv); in = sf_input("in"); shift = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(in,1); if (!sf_histint(in,"esize",&esize)) { esize=sf_esize(in); } else if (0>=esize) { sf_error("cannot handle esize=%d",esize); } if (!sf_getint("ns",&ns)) sf_error("Need ns="); /* number of shifts */ if (!sf_getint("nf",&nf)) nf = 1; /* offset of first shift */ if ((nf+ns-1) >= n1) sf_error("(nf+ns-1)=%d is too large",nf+ns-1); sf_putint(shift,"n2",ns); sf_shiftdim(in, shift, 2); sf_fileflush(shift,in); sf_setform(in,SF_NATIVE); sf_setform(shift,SF_NATIVE); n1 *= esize; trace = sf_charalloc(n1); zero = sf_charalloc(n1); memset(zero,0,n1); for (i2=0; i2 < n2; i2++) { sf_charread(trace,n1,in); for (is=nf; is <= (nf+ns-1); is++) { pad = is*esize; sf_charwrite(zero,pad,shift); sf_charwrite(trace,n1-pad,shift); } } exit(0); }
void sf_out(sf_file out /* output file */, int axis /* join axis */, const char *iname /* name of the input file */) /*< prepare output >*/ { char *oname, cmdline[SF_CMDLEN]; int ndim; off_t n[SF_MAX_DIM]; sf_file inp; FILE *ofile=NULL; ofile = sf_tempfile(&oname,"w+b"); fclose(ofile); snprintf(cmdline,SF_CMDLEN,"%s %s --dryrun=y < %s > %s", command,splitcommand,iname,oname); sf_system(cmdline); inp = sf_input(oname); ndim = sf_largefiledims (inp,n); if (axis > ndim) axis=ndim; snprintf(nkey,5,"n%d",axis); axis--; sizes(inp,axis,ndim,n,&size1,&size2); sf_setformat(out,sf_histstring(inp,"data_format")); sf_fileflush(out,inp); sf_setform(out,SF_NATIVE); sf_rm(oname,true,false,false); }
int main(int argc, char* argv[]) { int i, id, dim, n[SF_MAX_DIM], nd; kiss_fft_cpx *din; float *dout; sf_file fin, fout; sf_init(argc,argv); fin = sf_input("in"); fout = sf_output("out"); if (SF_COMPLEX != sf_gettype(fin)) sf_error("Need complex input"); dim = sf_filedims (fin,n); nd = 1; for (i=0; i < dim; i++) nd *= n[i]; din = (kiss_fft_cpx*) sf_complexalloc(nd); dout = sf_floatalloc(nd); sf_floatread((float*)din,nd*2,fin); for (id=0; id < nd; id++) { dout[id] = hypotf(din[id].r,din[id].i); } sf_settype(fout, SF_FLOAT); sf_setform(fout, SF_NATIVE); sf_floatwrite(dout,nd,fout); exit(0); }
void sf_join(sf_file out /* output file */, int job /* job number */) /*< join outputs >*/ { int i, chunk; off_t i2, left, nbuf; char *iname, *oname; sf_file in; iname = inames[job]; oname = onames[job]; in = sf_input(oname); sf_histint(in,nkey,&chunk); sf_setform(in,SF_NATIVE); for (i2=0; i2 < size2; i2++) { nbuf=BUFSIZ; for (left=chunk*size1; left > 0; left -= nbuf) { if (nbuf > left) nbuf=left; sf_charread(buffer,nbuf,in); sf_charwrite(buffer,nbuf,out); } } sf_fileclose(in); sf_rm(iname,true,false,false); sf_rm(oname,true,false,false); for (i=0; i < inpargc; i++) { iname = inpnames[job][i]; sf_rm(iname,true,false,false); } }
int main(int argc, char* argv[]) { off_t pos; bool sign, half; int nsx, nsy, nmx, nmy, nhx, nhy, nmhx, nmhy, nt; int isx, isy, imx, imy, ihx, ihy; float osx, osy, dsx, dsy, omx, omy, dmx, dmy, ohx, ohy, dhx, dhy, dmhx, dmhy, binx, biny; float s_xmin, s_ymin, r_xmin, r_ymin, s_xmax, s_ymax, r_xmax, r_ymax, survey_xmin, survey_ymin, survey_xmax, survey_ymax; char *trace, *zero; sf_file in, out; sf_init(argc,argv); in = sf_input ( "in"); out = sf_output("out"); sf_warning("WARNING: This 3-D CMP sorting code is not yet ready for use--this message will be removed when it is. "); if (!sf_histint (in,"n1",&nt)) sf_error("No n1= in input"); /* Number of samples per trace */ if (!sf_histint (in,"n2",&nhx)) sf_error("No n2= in input"); /* Number of offsets per shot gather in x-direction*/ if (!sf_histfloat(in,"o2",&ohx)) sf_error("No o2= in input"); /* First offset x-component */ if (!sf_histfloat(in,"d2",&dhx)) sf_error("No d2= in input"); /* Offset increment in x-direction */ if (!sf_histint (in,"n3",&nhy)) sf_error("No n3= in input"); /* Number of offsets per shot gather in y-direction*/ if (!sf_histfloat(in,"o3",&ohy)) sf_error("No o3= in input"); /* First offset y-component */ if (!sf_histfloat(in,"d3",&dhy)) sf_error("No d3= in input"); /* Offset increment in y-direction */ if (!sf_histint (in,"n4",&nsx)) sf_error("No n4= in input"); /* Number of sources along x-direction*/ if (!sf_histfloat(in,"d4",&dsx)) sf_error("No d4= in input"); /* Source spacing in x-direction*/ if (!sf_histfloat(in,"o4",&osx)) sf_error("No o4= in input"); /* First source x-coordinate*/ if (!sf_histint (in,"n5",&nsy)) sf_error("No n5= in input"); /* Number of sources along y-direction*/ if (!sf_histfloat(in,"d5",&dsy)) sf_error("No d5= in input"); /* Source spacing in y-direction*/ if (!sf_histfloat(in,"o5",&osy)) sf_error("No o5= in input"); /* First source y-coordinate*/ if (!sf_getfloat("binx",&binx)) sf_error("No x bin size specified. Please set binx="); /*Number of bins along x-direction*/ if (!sf_getfloat("biny",&biny)) sf_error("No y bin size specified. Please set biny="); /*Number of bins along y-direction*/ if (!sf_getbool("positive",&sign)) sign=true; /* initial offset orientation: yes is generally for off-end surveys, where the first offsets are positive. no is generally for split-spread surveys with first negative then positive offsets. */ if (!sf_getbool("half",&half)) half=true; /* if y, the second axis is half-offset instead of full offset*/ if (!half) { dhx /= 2; ohx /= 2; dhy /= 2; ohy /= 2; } s_xmin = osx; s_ymin = osy; s_xmax = osx+(nsx*dsx); s_ymax = osy+(nsy*dsy); r_xmin = s_xmin+2*ohx; r_ymin = s_ymin+2*ohy; r_xmax = s_xmax+2*(ohx+dhx*nhx); r_ymax = s_ymax+2*(ohy+dhy*nhy); if (s_xmin <= r_xmin){ survey_xmin = s_xmin; }else{ survey_xmin = r_xmin; } if (s_ymin <= r_ymin){ survey_ymin = s_ymin; }else{ survey_ymin = r_ymin; } if (s_xmax <= r_xmax){ survey_xmax = r_xmax; }else{ survey_xmax = s_xmax; } if (s_ymax <= r_ymax){ survey_ymax = r_ymax; }else{ survey_ymax = s_ymax; } dmx = (survey_xmax - survey_xmin)/binx; dmy = (survey_ymax - survey_ymin)/biny; omx = survey_xmin + dmx/2.; omy = survey_ymin + dmy/2.; nmx = binx; nmy = biny; nmhx = (int)(nhx*nsx/nmx); nmhy = (int)(nhy*nsy/nmy); dmhx = dhx; dmhy = dhy; sf_putint (out,"n2",nmhx); sf_putint (out,"n3",nmhy); sf_putfloat(out,"d2",dmhx); sf_putfloat(out,"d3",dmhy); sf_putint (out,"n4",nmx); sf_putint (out,"n5",nmy); sf_putfloat(out,"d4",dmx); sf_putfloat(out,"d5",dmy); sf_putfloat(out,"o4",omx); sf_putfloat(out,"o5",omy); sf_putstring(out,"label3","hx"); sf_putstring(out,"label4","hy"); sf_putstring(out,"label5","mx"); sf_putstring(out,"label6","my"); nt *= sf_esize(in); trace = sf_charalloc(nt); zero = sf_charalloc(nt); memset(zero,0,nt); sf_fileflush(out,in); sf_setform( in,SF_NATIVE); sf_setform(out,SF_NATIVE); sf_unpipe(in,(off_t) nsx*nsy*nhx*nhy*nt); pos = sf_tell(in); for (isx=0; isx < nsx; isx++) { for (isy=0; isy < nsy; isy++) { for (ihx=0; ihx < nhx; ihx++) { for (ihy=0; ihy < nhy; ihy++) { imx = (int)((isx + ihx)/2.0); imy = (int)((isy + ihy)/2.0); if (isx >= 0 && isx < nsx && ihx < nhx) { if (isy >= 0 && isy < nsy && ihy < nhy) { sf_seek(in,pos+((isx*nhx+ihx)+(isy*nhy+ihy))*nt,SEEK_SET); sf_charread(trace,nt,in); sf_charwrite(trace,nt,out); } } else { sf_charwrite(zero,nt,out); } } } } } exit(0); }
int main(int argc, char* argv[]) { sf_file in, out; char *buf, *buf2, key[5]; /* Want them to be arbitrary, neither float nor complex */ /* Just pretend they are character pointers so we multiply offsets ourselves.*/ int i, dim, dim1, dim2, rot[SF_MAX_DIM], esize; int mem; /* for avoiding int to off_t typecast warning */ off_t n[SF_MAX_DIM], pos=0, pos3=0, memsize, *k1 = NULL, *k2 = NULL; size_t n1, i1, i2, i3, n2, n3, size; bool verb; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); dim = sf_largefiledims(in,n); esize = sf_esize(in); if (!sf_getbool("verb",&verb)) verb=false; /* Verbosity flag */ if (!sf_getint("memsize",&mem)) mem=sf_memsize(); /* Max amount of RAM (in Mb) to be used */ memsize = (off_t) mem * (1<<20); /* convert Mb to bytes */ dim2=0; for (i=0; i < dim; i++) { snprintf(key,5,"rot%d",i+1); if (!sf_getint(key,rot+i)) rot[i]=0; /*( rot#=(0,0,...) length of #-th axis that is moved to the end )*/ if (rot[i] < 0) rot[i] += n[i]; if (rot[i] >= n[i]) sf_error("rot%d=%d must be smaller than n%d=%d", i,rot[i],i,n[i]); if (rot[i]) dim2=i; } dim2++; /* dim2 is the last dimension involved */ sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); n1=n2=n3=1; dim1=0; for (i=0; i < dim; i++) { if (i < dim2) { size = n1*n[i]; if (1==n2 && size*esize < memsize) { n1=size; dim1=i; } else { n2*=n[i]; } } else { n3 *= n[i]; } } dim1++; /* dim1 is the last dimension that fits in memory, n1 is the size up to this dimension n2 is the size of other dimensions involved n3 is the size of all other dimensions so that n1*n2*n3 is the total data size */ buf = sf_charalloc(n1*esize); buf2 = sf_charalloc(n1*esize); if (n1>1) { k1 = sf_largeintalloc(n1); rotate(n1,dim1,n,rot,k1); } if (n2>1) { if (verb) sf_warning("Going out of core..."); sf_unpipe(in,n1*n2*n3*esize); /* prepare for random access */ pos = sf_tell(in); k2 = sf_largeintalloc(n2); rotate(n2,dim2-dim1,n+dim1,rot+dim1,k2); } if (verb) sf_warning("n1=%d, n2=%d, n3=%d", (int) n1,(int) n2,(int) n3); /* k1 is a table for in-core reversal k2 is a table for out-of-core reversal */ for (i3=0; i3 < n3; i3++) { if (n2 > 1) pos3 = pos+(off_t) i3*n2*n1*esize; for (i2=0; i2 < n2; i2++) { if (n2 > 1) /* if out of core */ sf_seek(in,pos3+k2[i2]*n1*esize,SEEK_SET); sf_charread(buf,n1*esize,in); for (i1=0; i1 < n1; i1++) { memcpy(buf2+k1[i1]*esize,buf+i1*esize,esize); } sf_charwrite(buf2,n1*esize,out); } } exit (0); }
int main(int argc, char* argv[]) { int j, n1, n2, i2, ni, axis, esize; float f; off_t i3, n3; size_t n; sf_file in, out; char key1[7], key2[7], *val, *trace; sf_init (argc, argv); in = sf_input ("in"); out = sf_output ("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"esize",&esize)) sf_error("No esize= in input"); if (!sf_getint("axis",&axis)) axis=2; /* which axis to spray */ n = (size_t) esize; for (j=0; j < axis-1; j++) { sprintf(key2,"n%d",j+1); if (!sf_histint(in,key2,&ni)) break; n *= ni; } if (!sf_getint("n",&n2)) sf_error("Need n="); /* Size of the newly created dimension */ sprintf(key1,"n%d",axis); sf_putint(out,key1,n2); if (sf_getfloat("d",&f)) { /* Sampling of the newly created dimension */ sprintf(key1,"d%d",axis); sf_putfloat(out,key1,f); } if (sf_getfloat("o",&f)) { /* Origin of the newly created dimension */ sprintf(key1,"o%d",axis); sf_putfloat(out,key1,f); } if (NULL != (val = sf_getstring("label"))) { /* Label of the newly created dimension */ sprintf(key1,"label%d",axis); sf_putstring(out,key1,val); } if (NULL != (val = sf_getstring("unit"))) { /* Units of the newly created dimension */ sprintf(key1,"unit%d",axis); sf_putstring(out,key1,val); } n3 = sf_shiftdim(in, out, axis); sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); trace = sf_charalloc (n); for (i3=0; i3 < n3; i3++) { sf_charread (trace, n, in); for (i2=0; i2 < n2; i2++) { sf_charwrite(trace, n, out); } } exit (0); }
int main (int argc, char* argv[]) { int i, j, nj, dim, ntr, itr, esize; int beg[SF_MAX_DIM], end[SF_MAX_DIM]; off_t n[SF_MAX_DIM], n2[SF_MAX_DIM]; size_t n0, n20, beg0, end0; sf_file in, out; float o, d; char key[10], key2[10], *tr, *zero; bool inside; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); dim = sf_largefiledims(in,n); sf_expandpars(out); ntr=1; for (j=0; j < SF_MAX_DIM; j++) { i=j+1; if (j>=dim) { n[j]=1; } sprintf(key,"beg%d",i); if(!sf_getint(key,beg+j)) { /*( beg#=0 the number of zeros to add before the beginning of #-th axis )*/ beg[j]=0; } else if (beg[j]<0) { sf_error("negative beg=%d",beg[j]); } sprintf(key,"end%d",i); sprintf(key2,"n%d",i); if(!sf_getint(key,end+j)) { /*( end#=0 the number of zeros to add after the end of #-th axis )*/ sprintf(key,"n%dout",i); if (sf_getint(key,&nj) || sf_getint(key2,&nj)) { /*( n# the output length of #-th axis - padding at the end )*/ if (0==nj) for (nj++; nj < n[j]; nj *= 2) ; end[j]=nj-n[j]-beg[j]; if (end[j]<0) sf_error("negative end=%d",end[j]); } else { end[j]=0; } } n2[j]=n[j]+beg[j]+end[j]; if (j>0) ntr *= n2[j]; if (n2[j] != n[j]) sf_putint(out,key2,n2[j]); if (beg[j] > 0) { sprintf(key,"o%d",i); if (sf_histfloat(in,key,&o)) { sprintf(key2,"d%d",i); if (sf_histfloat(in,key2,&d)) sf_putfloat(out,key,o-d*beg[j]); } } if (n2[j] > 1 && j >= dim) dim=i; } if (!sf_histint(in,"esize",&esize)) { esize=sf_esize(in); } else if (0>=esize) { sf_error("cannot handle esize=%d",esize); } sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); n[0] *= esize; n0 = (size_t) n[0]; n2[0] *= esize; n20 = (size_t) n2[0]; beg[0] *= esize; beg0 = (size_t) beg[0]; end[0] *= esize; end0 = (size_t) end[0]; tr = sf_charalloc(n20); zero = sf_charalloc(n20); memset(zero,0,n20); if (beg0>0) memcpy(tr,zero,beg0); if (end0>0) memcpy(tr+beg0+n0,zero,end0); for (itr=0; itr < ntr; itr++) { inside = true; for (nj=j=1; j < dim; nj *= n2[j], j++) { i = (itr/nj)%n2[j]; if (i < beg[j] || i >= beg[j]+n[j]) { inside = false; break; } } if (inside) { sf_charread (tr+beg0,n0,in); sf_charwrite(tr,n20,out); } else { sf_charwrite(zero,n20,out); } } exit (0); }
int main(int argc, char* argv[]) { int esize, shift; off_t size; size_t i, nleft, nbuf, e_size, len, bufsiz; sf_file real, cmplx; char *rbuf, *cbuf, *rformat, *cformat, *prog; sf_init(argc,argv); cmplx = sf_input ( "in"); real = sf_output("out"); if (SF_COMPLEX != sf_gettype(cmplx)) { sf_error("wrong input type"); } cformat = sf_histstring(cmplx,"data_format"); len = strlen(cformat)+1; rformat = sf_charalloc(len); memcpy(rformat,cformat,len); strcpy(strstr(rformat,"complex"),"float"); sf_setformat(real,rformat); if (!sf_histint(real,"esize",&esize)) esize=4; if (esize <= 0) sf_error("wrong esize=%d",esize); e_size = (size_t) esize; size = sf_filesize (cmplx); sf_fileflush(real,cmplx); sf_setform(real ,SF_NATIVE); sf_setform(cmplx,SF_NATIVE); prog = sf_getprog(); if ( NULL != strstr(prog,"real")) { shift=0; } else if (NULL != strstr(prog,"imag")) { shift=esize; } else { sf_warning("neither real nor imag, assume real"); shift=0; } bufsiz = sf_bufsiz(cmplx); rbuf = sf_charalloc(bufsiz); cbuf = sf_charalloc(2*bufsiz); for (nleft=size*e_size; nleft > 0; nleft -= nbuf) { nbuf = (bufsiz < nleft)? bufsiz: nleft; sf_charread(cbuf,2*nbuf,cmplx); for (i=0; i < nbuf; i += e_size) { memcpy(rbuf+i,cbuf+2*i+shift,e_size); } sf_charwrite(rbuf,nbuf,real); } exit (0); }
int main (int argc, char *argv[]) { off_t *table, nleft, nbuf, n[SF_MAX_DIM], f[SF_MAX_DIM]; int i, esize, dim, n1, n2, n3, m1, i2, i1, j1, jump; int m[SF_MAX_DIM], j[SF_MAX_DIM]; float a, d[SF_MAX_DIM], o[SF_MAX_DIM]; char key[7], *buf, buf0[BUFSIZ], *zero; bool verb; sf_file in=NULL; sf_file out=NULL; sf_init (argc,argv); in = sf_input ("in"); out = sf_output ("out"); esize = sf_esize(in); dim = sf_largefiledims(in,n); for (i=0; i < dim; i++) { /* get o's */ snprintf(key,3,"o%d",i+1); if (!sf_histfloat(in,key,o+i)) o[i]=0.; /* get d's */ snprintf(key,3,"d%d",i+1); if (!sf_histfloat(in,key,d+i)) d[i]=1.; /* get j's */ snprintf(key,3,"j%d",i+1); if (!sf_getint(key,j+i)) { /*( j#=(1,...) jump in #-th dimension )*/ snprintf(key,3,"d%d",i+1); if (sf_getfloat(key,&a)) { /*( d#=(d1,d2,...) sampling in #-th dimension )*/ j[i] = 0.5 + a/d[i]; } else { j[i] = 1; } } /* get f's */ snprintf(key,3,"f%d",i+1); if (!sf_getlargeint(key,f+i)) { /*( f#=(0,...) window start in #-th dimension )*/ snprintf(key,5,"min%d",i+1); if (sf_getfloat(key,&a)) { /*( min#=(o1,o2,,...) minimum in #-th dimension )*/ f[i] = 0.5 + (a - o[i]) / d[i]; } else { f[i] = 0; } } if (f[i] < 0) { f[i] = n[i]+f[i]; #if defined(__cplusplus) || defined(c_plusplus) if (f[i] < 0) sf_error("Negative f%d=%ld", i+1,(long int) f[i]); #else if (f[i] < 0) sf_error("Negative f%d=%lld", i+1,(long long int) f[i]); #endif } /* new values for o and d */ o[i] += f[i]*d[i]; d[i] *= j[i]; /* get n's */ snprintf(key,3,"n%d",i+1); if (!sf_getint(key,m+i)) { /*( n#=(0,...) window size in #-th dimension )*/ snprintf(key,5,"max%d",i+1); if (sf_getfloat(key,&a)) { /*( max#=(o1+(n1-1)*d1,o2+(n1-1)*d2,,...) maximum in #-th dimension )*/ m[i] = 1.5 + (a - o[i]) / d[i]; } else { m[i] = 1.5 + (n[i] - 1 - f[i]) / j[i]; } } while (1+(m[i]-1)*j[i] > n[i]) m[i]--; } if (!sf_getbool("verb",&verb)) verb=false; /* Verbosity flag */ if (verb) { for (i=0; i < dim; i++) { if (m[i] != n[i]) sf_warning("Cutting f%d=%d j%d=%d n%d=%d min%d=%g max%d=%g", i+1,f[i],i+1,j[i],i+1,m[i], i+1,o[i],i+1,o[i]+(m[i]-1)*d[i]); } } sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); /* Now do the actual work */ n2 = n3 = 1; for (i=1; i < dim; i++) { n2 *= m[i]; n3 *= n[i]; } m1 = m[0]*esize; n1 = (1+(m[0]-1)*j[0])*esize; jump = (j[0]-1) * esize; n[0] *= esize; f[0] *= esize; buf = sf_charalloc (n1); zero = sf_charalloc (n1); table = (off_t*) sf_alloc (n2+1,sizeof(off_t)); memset(zero,0,n1); seektable(dim,n,m,f,j,n1,n2,n3,table); for (i2=0; i2 <= n2; i2++) { for (nleft=table[i2]; nleft > 0; nleft -= nbuf) { nbuf = (BUFSIZ < nleft)? BUFSIZ: nleft; sf_charread (buf0,nbuf,in); sf_charwrite (buf0,nbuf,out); } if (i2==n2) break; sf_charread(buf,n1,in); if (jump) { for (i1=j1=0; i1 < m1; j1 += jump) { memset(buf+j1,0,esize); j1 += esize; i1 += esize; } sf_charwrite(buf,n1,out); } else { sf_charwrite(zero,n1,out); } } exit (0); }