Exemplo n.º 1
0
CompletionOrderEditor::CompletionOrderEditor(KPIM::LdapSearch *ldapSearch,
        QWidget *parent, const char *name)
    : KDialogBase(parent, name, true, i18n("Edit Completion Order"), Ok | Cancel, Ok, true),
      mConfig("kpimcompletionorder"), mDirty(false)
{
    mItems.setAutoDelete(true);
    // The first step is to gather all the data, creating CompletionItem objects
    QValueList< LdapClient * > ldapClients = ldapSearch->clients();
    for(QValueList<LdapClient *>::const_iterator it = ldapClients.begin(); it != ldapClients.end(); ++it)
    {
        //kdDebug(5300) << "LDAP: host " << (*it)->host() << " weight " << (*it)->completionWeight() << endl;
        mItems.append(new LDAPCompletionItem(*it));
    }
    KABC::AddressBook *addressBook = KABC::StdAddressBook::self(true);
    QPtrList<KABC::Resource> resources = addressBook->resources();
    for(QPtrListIterator<KABC::Resource> resit(resources); *resit; ++resit)
    {
        //kdDebug(5300) << "KABC Resource: " << (*resit)->className() << endl;
        ResourceABC *res = dynamic_cast<ResourceABC *>(*resit);
        if(res)      // IMAP KABC resource
        {
            const QStringList subresources = res->subresources();
            for(QStringList::const_iterator it = subresources.begin(); it != subresources.end(); ++it)
            {
                mItems.append(new KABCImapSubResCompletionItem(res, *it));
            }
        }
        else     // non-IMAP KABC resource
        {
            mItems.append(new SimpleCompletionItem(this, (*resit)->resourceName(),
                                                   (*resit)->identifier()));
        }
    }

#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, so no separate item if using them
    // Add an item for distribution lists
    mItems.append(new SimpleCompletionItem(this, i18n("Distribution Lists"), "DistributionLists"));
#endif

    // Now sort the items, then create the GUI
    mItems.sort();

    QHBox *page = makeHBoxMainWidget();
    mListView = new KListView(page);
    mListView->setSorting(-1);
    mListView->addColumn(QString::null);
    mListView->header()->hide();

    for(QPtrListIterator<CompletionItem> compit(mItems); *compit; ++compit)
    {
        new CompletionViewItem(mListView, *compit);
        kdDebug(5300) << "  " << (*compit)->label() << " " << (*compit)->completionWeight() << endl;
    }

    QVBox *upDownBox = new QVBox(page);
    mUpButton = new KPushButton(upDownBox, "mUpButton");
    mUpButton->setIconSet(BarIconSet("up", KIcon::SizeSmall));
    mUpButton->setEnabled(false);   // b/c no item is selected yet
    mUpButton->setFocusPolicy(StrongFocus);

    mDownButton = new KPushButton(upDownBox, "mDownButton");
    mDownButton->setIconSet(BarIconSet("down", KIcon::SizeSmall));
    mDownButton->setEnabled(false);   // b/c no item is selected yet
    mDownButton->setFocusPolicy(StrongFocus);

    QWidget *spacer = new QWidget(upDownBox);
    upDownBox->setStretchFactor(spacer, 100);

    connect(mListView, SIGNAL(selectionChanged(QListViewItem *)),
            SLOT(slotSelectionChanged(QListViewItem *)));
    connect(mUpButton, SIGNAL(clicked()), this, SLOT(slotMoveUp()));
    connect(mDownButton, SIGNAL(clicked()), this, SLOT(slotMoveDown()));
}
Exemplo n.º 2
0
int
main (int argc, char **argv)
{
	int 	nt,nzt,nxt,nz,nxo,nxs,ns,nx,nr,is,ixo,ixs;
	int 	ls,jtr,mtr,tracl,mzmax;
	off_t nseek;
	float   ft,fzt,fxt,fz,fx,fxo,fs,fxs,dt,dzt,dxt,dz,dx,dxo,ds,dxs,
		ext,ezt,es,ex,ez,xo,s,xs,xg,fpeak;	
	float 	v0,dvz;
	float 	fmax,angmax,offmax,rmax,aperx;
	float **mig,**migi,***ttab,**tb,**pb,**cosb,**sigb,**tsum,**tt;
	
	char *infile="stdin",*outfile="stdout",*ttfile,*jpfile;
	FILE *infp,*outfp,*ttfp,*jpfp;
	Wavelet *w;


	/* hook up getpar to handle the parameters */
	initargs(argc, argv);
	requestdoc(1);

	/* open input and output files	*/
	if( !getparstring("infile",&infile)) {
		infp = stdin;
	} else  
		if ((infp=fopen(infile,"r"))==NULL)
			err("cannot open infile=%s\n",infile);
	if( !getparstring("outfile",&outfile)) {
		outfp = stdout;
	} else { 
		outfp = fopen(outfile,"w");
	}
	efseeko(infp,(off_t) 0,SEEK_CUR);
	warn("Got A");
	efseeko(outfp,(off_t) 0,SEEK_CUR);
	if( !getparstring("ttfile",&ttfile))
		err("must specify ttfile!\n");
	if ((ttfp=fopen(ttfile,"r"))==NULL)
		err("cannot open ttfile=%s\n",ttfile);
	if( !getparstring("jpfile",&jpfile)) {
		jpfp = stderr;
	} else  
		jpfp = fopen(jpfile,"w");

	/* get information for seismogram traces */
	if (!getparint("nt",&nt)) nt = 501;
	if (!getparfloat("dt",&dt)) dt = 0.004;
	if (!getparfloat("ft",&ft)) ft = 0.0;
	if (!getparfloat("fmax",&fmax)) fmax = 1.0/(4*dt);
	fpeak = 0.2/dt;
	if (!getparint("nxs",&nxs)) nxs = 101;
	if (!getparfloat("dxs",&dxs)) dxs = 15;
	if (!getparfloat("fxs",&fxs)) fxs = 0.0;
	if (!getparint("nxo",&nxo)) nxo = 1;
	if (!getparfloat("dxo",&dxo)) dxo = 50;
	if (!getparfloat("fxo",&fxo)) fxo = 0.0;
	
	/* get traveltime table parameters	*/
	if (!getparint("nxt",&nxt)) err("must specify nxt!\n");
	if (!getparfloat("fxt",&fxt)) err("must specify fxt!\n");
	if (!getparfloat("dxt",&dxt)) err("must specify dxt!\n");
	if (!getparint("nzt",&nzt)) err("must specify nzt!\n");
	if (!getparfloat("fzt",&fzt)) err("must specify fzt!\n");
	if (!getparfloat("dzt",&dzt)) err("must specify dzt!\n");
	if (!getparint("ns",&ns)) err("must specify ns!\n");
	if (!getparfloat("fs",&fs)) err("must specify fs!\n");
	if (!getparfloat("ds",&ds)) err("must specify ds!\n");
	ext = fxt+(nxt-1)*dxt;
	ezt = fzt+(nzt-1)*dzt;
	es = fs+(ns-1)*ds;

	/* check source and receiver coordinates */
 	for (ixs=0; ixs<nxs; ++ixs) {
		xs = fxs+ixs*dxs;
		for (ixo=0; ixo<nxo; ++ixo) {
			xg = xs+fxo+ixo*dxo;
			if (fs>xs || es<xs || fs>xg || es<xg) 
		err("shot or receiver lie outside of specified (x,z) grid\n");
		}
	} 

	/* get migration section parameters	*/
	if (!getparint("nx",&nx)) err("must specify nx!\n");
	if (!getparfloat("fx",&fx)) err("must specify fx!\n");
	if (!getparfloat("dx",&dx)) err("must specify dx!\n");
	if (!getparint("nz",&nz)) err("must specify nz!\n");
	if (!getparfloat("fz",&fz)) err("must specify fz!\n");
	if (!getparfloat("dz",&dz)) err("must specify dz!\n");
	ex = fx+(nx-1)*dx;
	ez = fz+(nz-1)*dz;
	if(fxt>fx || ext<ex || fzt>fz || ezt<ez) 
		err(" migration section is out of traveltime table!\n");

	if (!getparfloat("v0",&v0)) v0 = 1500;
	if (!getparfloat("dvz",&dvz)) dvz = 0;
	if (!getparfloat("angmax",&angmax)) angmax = 60.;
	if  (angmax<0.00001) err("angmax must be positive!\n");
	mzmax = dx*sin(angmax*PI/180.)/dz;
	if(mzmax<1) mzmax = 1;
	if (!getparfloat("aperx",&aperx)) aperx = 0.5*nxt*dxt;

	if (!getparint("ls",&ls))	ls = 1;
	if (!getparint("mtr",&mtr))	mtr = 100;

	fprintf(jpfp,"\n");
	fprintf(jpfp," Modeling parameters\n");
	fprintf(jpfp," ================\n");
	fprintf(jpfp," infile=%s \n",infile);
	fprintf(jpfp," outfile=%s \n",outfile);
	fprintf(jpfp," ttfile=%s \n",ttfile);
	fprintf(jpfp," \n");
	fprintf(jpfp," nzt=%d fzt=%g dzt=%g\n",nzt,fzt,dzt);
	fprintf(jpfp," nxt=%d fxt=%g dxt=%g\n",nxt,fxt,dxt);
 	fprintf(jpfp," ns=%d fs=%g ds=%g\n",ns,fs,ds);
	fprintf(jpfp," \n");
	fprintf(jpfp," nz=%d fz=%g dz=%g\n",nz,fz,dz);
	fprintf(jpfp," nx=%d fx=%g dx=%g\n",nx,fx,dx);
	fprintf(jpfp," \n");
	fprintf(jpfp," nxs=%d fxs=%g dxs=%g\n",nxs,fxs,dxs);
	fprintf(jpfp," nxo=%d fxo=%g dxo=%g\n",nxo,fxo,dxo);
	fprintf(jpfp," \n");
	
	/* compute reference traveltime and slowness  */
	offmax = MAX(ABS(fxo),ABS(fxo+(nxo-1)*dxo));
	rmax = MAX(es-fxt,ext-fs);
	rmax = MIN(rmax,0.5*offmax+aperx);
	nr = 2+(int)(rmax/dx);
	tb = ealloc2float(nzt,nr);
	pb = ealloc2float(nzt,nr);
	sigb = ealloc2float(nzt,nr);
	cosb = ealloc2float(nzt,nr);
	timeb(nr,nzt,dx,dzt,fzt,dvz,v0,tb,pb,sigb,cosb);

	fprintf(jpfp," nt=%d ft=%g dt=%g fpeak=%g \n",nt,ft,dt,fpeak);
	fprintf(jpfp," v0=%g dvz=%g \n",v0,dvz);
 	fprintf(jpfp," aperx=%g angmax=%g offmax=%g\n",aperx,angmax,offmax);
 	fprintf(jpfp," mtr=%d ls=%d\n",mtr,ls);
	fprintf(jpfp," ================\n");
	fflush(jpfp);

	/* allocate space */
	mig = ealloc2float(nz,nx);
	migi = ealloc2float(nz+2*mzmax,nx);
	ttab = ealloc3float(nzt,nxt,ns);
	tt = ealloc2float(nzt,nxt);
	tsum = ealloc2float(nzt,nxt);


	/* make wavelet */
	makericker(fpeak,dt,&w);

	/* set constant segy trace header parameters */
	memset((void *) &tr, 0, sizeof(segy));
	tr.trid = 1;
	tr.counit = 1;
	tr.ns = nt;
	tr.dt = 1.0e6*dt;
	tr.delrt = 1.0e3*ft;

	fprintf(jpfp," read traveltime tables \n");
	fflush(jpfp);

	/* compute traveltime residual	*/
	for(is=0; is<ns; ++is){
		nseek = (off_t) nxt*nzt*is;
		efseeko(ttfp,nseek*((off_t) sizeof(float)),SEEK_SET);
		fread(ttab[is][0],sizeof(float),nxt*nzt,ttfp);
		s = fs+is*ds;
		resit(nxt,fxt,dxt,nzt,nr,dx,tb,ttab[is],s);		
	}

	fprintf(jpfp," read migration section \n");
	fflush(jpfp);

	/* read migration section	*/
	fread(mig[0],sizeof(float),nx*nz,infp);

	/* integrate migration section for constructing anti-aliasing 
		filter	*/
	integ(mig,nz,dz,nx,mzmax,migi);
                       
	fprintf(jpfp," start synthesis ... \n");
	fprintf(jpfp," \n");
	fflush(jpfp);
	
	jtr = 0;
	/* loop over shots  */
	for (ixs=0,xs=fxs,tracl=0; ixs<nxs; ++ixs,xs+=dxs) {
		/* loop over offsets */
		for (ixo=0,xo=fxo; ixo<nxo; ++ixo,xo+=dxo) {
	    		float as,res;
	    		int is;
			xg = xs+xo; 
			/* set segy trace header parameters */
			tr.tracl = tr.tracr = ++tracl;
			tr.fldr = 1+ixs;
			tr.tracf = 1+ixo;
			tr.offset = NINT(xo);
			tr.sx = NINT(xs);
			tr.gx = NINT(xg);

	    		as = (xs-fs)/ds;
	    		is = (int)as;
			if(is==ns-1) is=ns-2;
			res = as-is;
			if(res<=0.01) res = 0.0;
			if(res>=0.99) res = 1.0;
			sum2(nxt,nzt,1-res,res,ttab[is],ttab[is+1],tsum);

	    		as = (xg-fs)/ds;
	    		is = (int)as;
			if(is==ns-1) is=ns-2;
			res = as-is;
			if(res<=0.01) res = 0.0;
			if(res>=0.99) res = 1.0;
			sum2(nxt,nzt,1-res,res,ttab[is],ttab[is+1],tt);
			sum2(nxt,nzt,1,1,tt,tsum,tsum);
				fflush(jpfp);

			/* make one trace */
			maketrace(tr.data,nt,ft,dt,xs,xg,mig,migi,aperx,
			  nx,fx,dx,nz,fz,dz,mzmax,ls,angmax,v0,fmax,w,
			  tb,pb,sigb,cosb,nr,tsum,nxt,fxt,dxt,nzt,fzt,dzt);
			
			/* write trace */
			fputtr(outfp,&tr);

	        	jtr++;
	        	if((jtr-1)%mtr ==0 ){
				fprintf(jpfp," generated trace %d\n",jtr);
				fflush(jpfp);
	    		}
		}
	}


	fprintf(jpfp," generated %d traces in total\n",jtr);


	fprintf(jpfp," \n");
	fprintf(jpfp," output done\n");
	fflush(jpfp);

	efclose(jpfp);
	efclose(outfp);

	    
	free2float(tsum);
	free2float(tt);
	free2float(pb);
	free2float(tb);
	free2float(cosb);
	free2float(sigb);
	free3float(ttab);
	free2float(mig);
	free2float(migi);

	return(CWP_Exit());
}