Exemple #1
0
int
main(int argc, char **argv)
{
	cwp_String key1,key2,key3;	/* panel/trace/flag key		*/
	cwp_String type1,type2,type3;	/* type for panel/trace/flag key*/
	int index1,index2,index3;	/* indexes for key1/2/3		*/
	Value val1,val2,val3;		/* value of key1/2/3		*/
	double dval1=0.0,dval2=0.0,dval3=0.0;	/* value of key1/2/3	*/
	double c;			/* trace key spacing		*/
	double dmin,dmax,dx;		/* trace key start/end/spacing	*/
	double panelno=0.0,traceno=0.0;
	int nt;				/* number of samples per trace	*/
	int isgn;			/* sort order			*/
	int iflag;			/* internal flag:		*/
					/* -1	exit			*/
					/* 0	regular mode		*/
					/* 1	first time		*/
					/* 2	trace out of range	*/

	/* initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* get parameters */
	if (!getparstring("key1", &key1)) key1 = "ep";
	if (!getparstring("key2", &key2)) key2 = "tracf";
	if (!getparstring("key3", &key3)) key3 = "trid";
	if (!getpardouble("val3", &dval3)) dval3 = 2.;
	if (!getpardouble("d", &dx)) dx = 1.;
	if (!getpardouble("min", &dmin)) err("need lower panel boundary MIN");
	if (!getpardouble("max", &dmax)) err("need upper panel boundary MAX");
        checkpars();

	/* check parameters */
	if (dx==0) err("trace spacing d cannot be zero");
	if (dmax<dmin) err("max needs to be greater than min");

	if (dx<0) {
		isgn = -1;
	} else {
		isgn = 1;
	}

	/* get types and index values */
	type1  = hdtype(key1);
	type2  = hdtype(key2);
	type3  = hdtype(key3);
	index1 = getindex(key1);
	index2 = getindex(key2);
	index3 = getindex(key3);

	/* loop over traces */
	iflag = 1;
	while (iflag>=0) {

		if (gettr(&tr)) {
			/* get header values */
			gethval(&tr, index1, &val1);
			gethval(&tr, index2, &val2);
			dval1 = vtod(type1, val1);
			dval2 = vtod(type2, val2);
			/* Initialize zero trace */
			nt = tr.ns;
			memset( (void *) nulltr.data, 0, nt*FSIZE);
			if ( iflag==1 ) {
				panelno = dval1;
				traceno = dmin - dx;
			}
			iflag = 0;
			if ( dval2<dmin || dval2>dmax ) iflag = 2;
/*	fprintf(stderr,"if=%d, dmin=%8.0f, dmax=%8.0f\n",iflag,dmin,dmax);*/
		} else {
			iflag = -1;	/* exit flag */
		}
/*	fprintf(stderr,"if=%d, dval1=%8.0f, dval2=%8.0f\n",iflag,dval1,dval2);*/

		/* if new panel or last trace --> finish the previous panel */
		if ( panelno!=dval1 || iflag==-1 ) {
/*	fprintf(stderr,"finish previous\n");*/
			for (c=traceno+dx; isgn*c<=isgn*dmax; c=c+dx) {
					assgnval(type2, &val2, c);
					puthval(&nulltr, index2, &val2);
					assgnval(type3, &val3, dval3);
					puthval(&nulltr, index3, &val3);
					puttr(&nulltr);
			}
			traceno = dmin - dx;	/* reset to pad present panel */

			panelno = dval1; /* added by Ted Stieglitz 28Nov2012*/

		}

		/* if trace within boundaries --> pad the present panel */
		if ( iflag==0 ) {
/*	fprintf(stderr,"pad present, trn=%5.0f,dval2=%5.0f\n",traceno,dval2);*/
			memcpy( (void *) &nulltr, (const void *) &tr, 240);
			for (c=traceno+dx; isgn*c<isgn*dval2; c=c+dx) {
					assgnval(type2, &val2, c);
					puthval(&nulltr, index2, &val2);
					assgnval(type3, &val3, dval3);
					puthval(&nulltr, index3, &val3);
					puttr(&nulltr);
			}
		}

		/* write the present trace and save header indices */
		if ( iflag==0 ) {
			puttr(&tr);
			panelno = dval1;
			traceno = dval2;
		}

	}

	return(CWP_Exit());
}
Exemple #2
0
int main(int argc, char **argv)
{
	char *plotcmd;		/* build pswigb command for popen	*/
	float *trbuf;		/* trace buffer				*/
	FILE *plotfp;		/* fp for plot data			*/
	int nt;			/* number of samples on trace	  	*/
	int ntr;		/* number of traces			*/
	int verbose;		/* verbose flag				*/
	float d1;		/* time/depth sample rate		*/
	float d2;		/* trace/dx sample rate			*/
	float f1;		/* tmin/zmin			   	*/
	float f2;		/* tracemin/xmin			*/
	cwp_Bool seismic;	/* is this seismic data?		*/
	cwp_Bool have_ntr=cwp_false;/* is ntr known from header or user?	*/
	char *tmpdir;		/* directory path for tmp files		*/
	cwp_Bool istmpdir=cwp_false;/* true for user given path		*/

	char *cwproot;		/* value of CWPROOT environment variable*/
	char *bindir;		/* directory path for tmp files		*/

	/* Support for irregularly spaced data */
	cwp_String key;		/* header key word with x2 information  */
	cwp_String type1=NULL;	/* ... its type				*/
	int index1=0;		/* ... its index			*/
	Value val;		/* value of key				*/
	Value scale;		/* Value of scaler			*/
	cwp_String type2=NULL;	/* ... its type				*/
	int index2=0;		/* ... its index			*/
	cwp_Bool isDepth=cwp_false;	/* Is this key a type of depth?		*/
	cwp_Bool isCoord=cwp_false;	/* Is this key a type of coordinate?	*/
	cwp_Bool irregular=cwp_false;  /* if true, reading x2 from header	*/ 
	cwp_String x2string;	/* string of x2 values			*/
	off_t x2len;		/* ... its length 			*/
	cwp_String style;	/* style parameter			*/


	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);
	
	/* Get info from first trace */
	if (!gettr(&tr)) err("can't get first trace");
	seismic = ISSEISMIC(tr.trid); 
	nt = tr.ns;
	ntr = tr.ntr;
	if (ntr) have_ntr = cwp_true; 

	if (!getparint("verbose", &verbose))    verbose=0;
	if (!getparfloat("d1", &d1)) {
		if      (tr.d1)  d1 = tr.d1;
		else if (tr.dt)  d1 = ((double) tr.dt)/1000000.0;
		else {
			if (seismic) {
				d1 = 0.004;
				warn("tr.dt not set, assuming dt=0.004");
			} else { /* non-seismic data */
				d1 = 1.0;
				warn("tr.d1 not set, assuming d1=1.0");
			}
		}
	}


	if (!getparfloat("f1", &f1)) {
		if      (tr.f1)     f1 = tr.f1;
		else if (tr.delrt)  f1 = (float) tr.delrt/1000.0;
		else		f1 = 0.0;
	}

	/* Get or set ntr */
	if (getparint("n2", &ntr) || getparint("ntr", &ntr)) have_ntr = cwp_true;
	if (!getparfloat("d2", &d2)) d2 = (tr.d2) ? tr.d2 : 1.0;


	if (!getparfloat("f2", &f2)) {
		if	(tr.f2)	f2 = tr.f2;
		else if (tr.tracr)  f2 = (float) tr.tracr;
		else if (tr.tracl)  f2 = (float) tr.tracl;
		else if (seismic)   f2 = 1.0;
		else		    f2 = 0.0;
	}

	if (!getparstring("style", &style)) style = "seismic";
	 	
	if (getparstring("key", &key)) {
		type1 = hdtype(key);
		if ( (index1 = getindex(key)) == -1 )
			err("%s: keyword not in segy.h: '%s'", __FILE__, key);
		irregular = cwp_true;
		isDepth = IS_DEPTH(key);
		isCoord = IS_COORD(key);
		if (isDepth) {
		   index2 = getindex("scalel");
		   type2 = hdtype("scalel");
		} else if (isCoord) {
		   index2 = getindex("scalco");
		   type2 = hdtype("scalco");
		}
	}


	/* Look for user-supplied tmpdir */
	if (!getparstring("tmpdir",&tmpdir) &&
	    !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir="";
	if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK))
		err("you can't write in %s (or it doesn't exist)", tmpdir);

	/* See if CWPBIN environment variable is not set */
	if (!(bindir = getenv("CWPBIN"))) { /* construct bindir from CWPROOT */

		bindir = (char *) emalloc(BUFSIZ);

		/* Get value of CWPROOT environment variable */
		if (!(cwproot = getenv("CWPROOT"))) cwproot ="" ;
		if (STREQ(cwproot, "")) {
			warn("CWPROOT environment variable is not set! ");
			err("Set CWPROOT in shell environment as per instructions in CWP/SU Installation README files");
		}
		/* then bindir = $CWPROOT/bin */
		sprintf(bindir, "%s/bin", cwproot);
	}
	strcat(bindir,"/");   /* put / at the end of bindir */


	/* Allocate trace buffer */
	trbuf = ealloc1float(nt);


	if (!have_ntr || irregular ) { /* count traces */
		if (verbose) {
			if (irregular) {
				warn("trace spacing from header field %s",key);
				warn("... getting positions");

			} else {
				warn("n2 not getparred and "
				     "ntr header field not set");
				warn("....  counting traces");
			}
		}

		/* Create temporary "file" to hold data */
		if (STREQ(tmpdir,"")) {
			datafp = etmpfile();
			if (irregular) x2fp = etmpfile();
			if (verbose) warn("using tmpfile() call");
		} else { /* user-supplied tmpdir */
			char directory[BUFSIZ];
			strcpy(directory, tmpdir);
			strcpy(datafile, temporary_filename(directory));
			strcpy(x2file, temporary_filename(directory));
			/* Handle user interrupts */
			signal(SIGINT, (void (*) (int)) closefiles);
			signal(SIGQUIT, (void (*) (int)) closefiles);
			signal(SIGHUP,  (void (*) (int)) closefiles);
			signal(SIGTERM, (void (*) (int)) closefiles);
			datafp = efopen(datafile, "w+");
			if (irregular) x2fp = efopen(x2file, "w+");
			istmpdir=cwp_true;		
			if (verbose)
			      warn("putting temporary files in %s", directory);
		}

		/* Loop over input data and read to temporary file */
		ntr = 0;
		if(irregular ) {
		     float x,xmin=FLT_MAX,xmax=-FLT_MAX;

		     fprintf(x2fp,"x2=");
		     do {
			if(ntr) fprintf(x2fp,",");
			++ntr;
			gethval(&tr,index1,&val);
			if (isDepth || isCoord) {
			   gethval(&tr,index2,&scale);
			   x = (float) (vtod(type1,val) *
				 pow(10.0,vtod(type2,scale)));
			} else
			   x = vtof(type1,val);
			fprintf(x2fp,"%g",x);
			xmin = MIN(xmin,x);
			xmax = MAX(xmax,x);
			if (isDepth && STREQ(style,"vsp")) {
				int i;
				for (i = 0; i < nt; ++i) tr.data[i] *= -1.0;
			}
			efwrite(tr.data, FSIZE, nt, datafp);
		     } while (gettr(&tr));

		     /* Flip vertical axis if style = vsp */
		     if (isDepth && STREQ(style,"vsp")) {
			fprintf(x2fp," x2beg=%g x2end=%g",xmax,xmin);
			style = "normal";
		     }

		     if(xmin==xmax) {
			warn("values in header %s all equal,",key);
			warn("using f2=%f d2=%f",f2,d2);
			irregular=cwp_false;
			have_ntr=cwp_false;
			efclose(x2fp);
			if (istmpdir) eremove(x2file);
		     }

		} else {
			do {
				++ntr;
				efwrite(tr.data, FSIZE, nt, datafp);
			} while (gettr(&tr));
			/* Save naive user */
			if (STREQ(style,"vsp")) {
				style = "normal";
				warn("style=vsp requires key= to be set");
			}
		}


	}

	/* Set up pswigb command line */
	if (irregular ) {
		x2len = (off_t) eftell( x2fp );
		x2string = (char *) emalloc( ++x2len );
		rewind(x2fp);
		fread(x2string,sizeof(char),x2len,x2fp);
		plotcmd = (char *) emalloc(x2len+BUFSIZ);
		if (STREQ(style,"vsp")) {
			style = "normal";
		}
		sprintf(plotcmd, "%spswigb n1=%d d1=%f f1=%f %s style=%s", bindir,
			   nt, d1, f1, x2string, style);
		free(x2string);
	} else {
		if (STREQ(style,"vsp")) {
			style = "normal";
		}
		plotcmd = (char *) emalloc(BUFSIZ);
		sprintf(plotcmd,
			"%spswigb n1=%d n2=%d d1=%f d2=%f f1=%f f2=%f style=%s", bindir,
			   nt, ntr, d1, d2, f1, f2, style);
	}


	for (--argc, ++argv; argc; --argc, ++argv) {
		if (strncmp(*argv, "d1=", 3) && /* skip those already set */
		    strncmp(*argv, "d2=", 3) &&
		    strncmp(*argv, "f1=", 3) &&
		    strncmp(*argv, "f2=", 3) &&
		    strncmp(*argv, "style=", 6)){
		    
			strcat(plotcmd, " ");   /* put a space between args */
			strcat(plotcmd, "\"");  /* user quotes are stripped */
			strcat(plotcmd, *argv); /* add the arg */
			strcat(plotcmd, "\"");  /* user quotes are stripped */
		}
	}


	/* Open pipe to pswigb and send the traces */
	plotfp = epopen(plotcmd, "w");
	free(plotcmd);

	if (!have_ntr || irregular) { /* send out stored traces one by one */
		rewind(datafp);
		{ register int itr;
			for (itr = 0; itr < ntr; ++itr) {
				efread (trbuf, FSIZE, nt, datafp);
				efwrite(trbuf, FSIZE, nt, plotfp);
			}
		}
	} else { /* just pump out traces and let pswigb do the work */
		do {
			efwrite(tr.data, FSIZE, nt, plotfp);
		} while (gettr(&tr));
	}


	/* Clean up */
	epclose(plotfp);
	if (!have_ntr) {
		efclose(datafp);
		if (istmpdir) eremove(datafile);
	}
	if (irregular) {
		efclose(x2fp);
		if (istmpdir) eremove(x2file);
	}

	return EXIT_SUCCESS;
}
Exemple #3
0
BOOL CPreStylePag::GetTextStyleProperty(
                       CString  strTSName,
                       CString &strShxFile,
                       CString &strBigFile,
                       double  &dHeight,
                       double  &dWidthFactor,
                       double  &dAngleByDegree,
                       short   &iGenerationFlag)
{
    CMObject obj, tsobj;
    long     i, nCount;
    CString  strtmp;

    //进行参数检查和初始化
    strTSName.TrimLeft();
    strTSName.TrimRight();
    strTSName.MakeUpper();
    if(strTSName.GetLength() <= 0) return FALSE;

    try
    {
        if(FindAcad() == FALSE)
        {
            return FALSE;
        }
        
        //SETUP-1: 获取ACAD文本样式列表
        obj = EDIBAcad::objAcadDoc.GetPropertyByName(
                                      _T("TextStyles"));
        
        //SETUP-2: 获取样式对象

		nCount = (long)obj.GetPropertyByName(_T("Count"));
		for( i = 0; i < nCount; i++)
		{
			tsobj = obj.Invoke(_T("Item"), 1, &_variant_t(i));
			strtmp = vtos(tsobj.GetPropertyByName(_T("Name")));
			strtmp.TrimLeft();
            strtmp.TrimRight();
			strtmp.MakeUpper();
			if(strtmp == strTSName)
			{
                //获得目标样式的属性值
                strShxFile      = vtos(tsobj.GetPropertyByName(
                                 _T("FontFile")));   //获得字体文件名
                strBigFile      = vtos(tsobj.GetPropertyByName(
                                 _T("BigFontFile")));//获得大字体文件名
                
                dHeight         = vtod(tsobj.GetPropertyByName(
                                 _T("Height")));     //获得字体高度

                dWidthFactor    = vtod(tsobj.GetPropertyByName(
                                 _T("Width")));      //获得宽度比例因子***

                dAngleByDegree  = vtod(tsobj.GetPropertyByName(
                                 _T("ObliqueAngle")));        //获得字体倾斜角度
                dAngleByDegree  *= 180.0;
                dAngleByDegree  /= 3.14159265359;
                if(dAngleByDegree > 270.0) dAngleByDegree -= 360;
                
                iGenerationFlag = vtoi(tsobj.GetPropertyByName(
                                 _T("TextGenerationFlag")));  //获得字体生成字段
                iGenerationFlag &= 0x06;

                return TRUE;
			}
		}
    }
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
    }
    return FALSE;
}