epoll

linux源码:http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v2.6/

转:http://oldblog.donghao.org/2009/08/linuxiapolliepollaueouaeaeeio.html

转:http://blog.chinaunix.net/uid-27024249-id-3988524.html

fs/eventpoll.c中

1、epoll_create函数:

SYSCALL_DEFINE1(epoll_create1, int, flags)
{
	int error;
	struct eventpoll *ep = NULL;

	/* Check the EPOLL_* constant for consistency.  */
	BUILD_BUG_ON(EPOLL_CLOEXEC != O_CLOEXEC);
	
	//O_CLOEXEC 就等于EPOLL_CLOEXEC (打开的文件描述符在执行exec调用新程序中关闭,且为原子操作)	
	if (flags & ~EPOLL_CLOEXEC)
		return -EINVAL;
	/*
	 * Create the internal data structure ("struct eventpoll").
	 * 创建内核数据结构体 struct eventpoll
	 */
	error = ep_alloc(&ep);
	if (error < 0)
		return error;
	/*
	 * Creates all the items needed to setup an eventpoll file. That is,
	 * a file structure and a free file descriptor.
	 * 创建的所有iteam(fd,file) 都需要安装一个eventpool文件
	  File callbacks that implement the eventpoll file behaviour 
	static const struct file_operations eventpoll_fops = {
		.release	= ep_eventpoll_release,
		.poll		= ep_eventpoll_poll
	};
	创建一个fd,和一个file,将eventpoll_fops绑在file->f_op上,将ep绑在file->private_data上
	 */
	error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep,
				 flags & O_CLOEXEC);
	if (error < 0)
		ep_free(ep);

	return error;
}
anon_inode_getfd //找到
int anon_inode_getfd(const char *name, const struct file_operations *fops,
		     void *priv, int flags)
{
	int error, fd;
	struct file *file;
	//获取一个未使用的fd
	error = get_unused_fd_flags(flags);
	if (error < 0)
		return error;
	fd = error;

	// 将ep做为参数priv设置到file的结构中 file->private_data = priv;
	// 将fops作为新建文件的file -> f_op 注意是fs.h中的struct file
	file = anon_inode_getfile(name, fops, priv, flags);
	if (IS_ERR(file)) {
		error = PTR_ERR(file);
		goto err_put_unused_fd;
	}
	//将file和fd关联起来,fdt->fd[fd]=file
	fd_install(fd, file);

	return fd;

err_put_unused_fd:
	put_unused_fd(fd);
	return error;
}
//创建file并且绑定一些数据priv-->eventpoll
struct file *anon_inode_getfile(const char *name,
				const struct file_operations *fops,
				void *priv, int flags)
{
	struct qstr this;
	struct dentry *dentry;
	struct file *file;
	int error;

	if (IS_ERR(anon_inode_inode))
		return ERR_PTR(-ENODEV);

	if (fops->owner && !try_module_get(fops->owner))
		return ERR_PTR(-ENOENT);

	/*
	 * Link the inode to a directory entry by creating a unique name
	 * using the inode sequence number.
	 */
	error = -ENOMEM;
	this.name = name;
	this.len = strlen(name);
	this.hash = 0;
	dentry = d_alloc(anon_inode_mnt->mnt_sb->s_root, &this);
	if (!dentry)
		goto err_module;

	/*
	 * We know the anon_inode inode count is always greater than zero,
	 * so we can avoid doing an igrab() and we can use an open-coded
	 * atomic_inc().
	 */
	atomic_inc(&anon_inode_inode->i_count);

	dentry->d_op = &anon_inodefs_dentry_operations;
	/* Do not publish this dentry inside the global dentry hash table */
	dentry->d_flags &= ~DCACHE_UNHASHED;
	d_instantiate(dentry, anon_inode_inode);

	error = -ENFILE;
	file = alloc_file(anon_inode_mnt, dentry,
			  FMODE_READ | FMODE_WRITE, fops);
	if (!file)
		goto err_dput;
	file->f_mapping = anon_inode_inode->i_mapping;

	file->f_pos = 0;
	file->f_flags = O_RDWR | (flags & O_NONBLOCK);
	file->f_version = 0;
	file->private_data = priv;

	return file;

err_dput:
	dput(dentry);
err_module:
	module_put(fops->owner);
	return ERR_PTR(error);
}


2、插入是红黑树,查找是相当的快

epoll_ctl函数:

SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
		struct epoll_event __user *, event)
{
	int error;
	struct file *file, *tfile;
	struct eventpoll *ep;
	struct epitem *epi;
	struct epoll_event epds;

	error = -EFAULT;
	// 如果不是EPOLL_CTL_DEL操作 将用户态的数据event拷贝到内核态的对象epds上
	if (ep_op_has_event(op) &&
	    copy_from_user(&epds, event, sizeof(struct epoll_event)))
		goto error_return;

	/* Get the "struct file *" for the eventpoll file */
	error = -EBADF;
	file = fget(epfd); // 还记得关联函数吗? fd_install(newfd, newfile);
	if (!file)
		goto error_return;

	/* Get the "struct file *" for the target file */
	tfile = fget(fd);
	if (!tfile)
		goto error_fput;

	/* The target file descriptor must support poll */
	// 由accept->tipc_create f_op如果是TCP则是 stream_ops 如果是UDP则是 msg_ops 对应的poll都是系统poll
	error = -EPERM;
	if (!tfile->f_op || !tfile->f_op->poll)
		goto error_tgt_fput;
	
	/*
	 * We have to check that the file structure underneath the file descriptor
	 * the user passed to us _is_ an eventpoll file. And also we do not permit
	 * adding an epoll file descriptor inside itself.
	 */
	// 防止修改自己,file必须是eventpoll file
	/*
	static inline int is_file_epoll(struct file *f)
	{
		return f->f_op == &eventpoll_fops;
	}
	*/
	error = -EINVAL;
	if (file == tfile || !is_file_epoll(file))
		goto error_tgt_fput;

	/*
	 * At this point it is safe to assume that the "private_data" contains
	 * our own data structure.
	 取出eventpool
	 */
	ep = file->private_data;

	mutex_lock(&ep->mtx);

	/*
	 * Try to lookup the file inside our RB tree, Since we grabbed "mtx"
	 * above, we can be sure to be able to use the item looked up by
	 * ep_find() till we release the mutex.
	 */
	epi = ep_find(ep, tfile, fd);

	error = -EINVAL;
	switch (op) {
	case EPOLL_CTL_ADD:
		if (!epi) {
			epds.events |= POLLERR | POLLHUP;
			error = ep_insert(ep, &epds, tfile, fd);
		} else
			error = -EEXIST; // 如果epi在ep->rbr(红黑树)中了,表示已经存在插入操作失败
		break;
	case EPOLL_CTL_DEL:
		if (epi)
			error = ep_remove(ep, epi);
		else
			error = -ENOENT;
		break;
	case EPOLL_CTL_MOD:
		if (epi) {
			epds.events |= POLLERR | POLLHUP;
			error = ep_modify(ep, epi, &epds);
		} else
			error = -ENOENT;
		break;
	}
	mutex_unlock(&ep->mtx);

error_tgt_fput:
	fput(tfile);
error_fput:
	fput(file);
error_return:

	return error;
}

3、

epoll_wait函数:

SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
		int, maxevents, int, timeout)
{
	int error;
	struct file *file;
	struct eventpoll *ep;

	/* The maximum number of event must be greater than zero */
	if (maxevents <= 0 || maxevents > EP_MAX_EVENTS)
		return -EINVAL;

	/* Verify that the area passed by the user is writeable */
	if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) {
		error = -EFAULT;
		goto error_return;
	}

	/* Get the "struct file *" for the eventpoll file */
	error = -EBADF;
	file = fget(epfd);
	if (!file)
		goto error_return;

	/*
	 * We have to check that the file structure underneath the fd
	 * the user passed to us _is_ an eventpoll file.
	 */
	error = -EINVAL;
	if (!is_file_epoll(file))
		goto error_fput;

	/*
	 * At this point it is safe to assume that the "private_data" contains
	 * our own data structure.
	 */
	ep = file->private_data;

	/* Time to fish for events ... */
	error = ep_poll(ep, events, maxevents, timeout);

error_fput:
	fput(file);
error_return:

	return error;
}

static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
		   int maxevents, long timeout)
{
	int res, eavail;
	unsigned long flags;
	long jtimeout;
	wait_queue_t wait;

	/*
	 * Calculate the timeout by checking for the "infinite" value (-1)
	 * and the overflow condition. The passed timeout is in milliseconds,
	 * that why (t * HZ) / 1000.
	 */
	jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ?
		MAX_SCHEDULE_TIMEOUT : (timeout * HZ + 999) / 1000;

retry:
	spin_lock_irqsave(&ep->lock, flags);

	res = 0;
	if (list_empty(&ep->rdllist)) {
		/*
		 * We don't have any available event to return to the caller.
		 * We need to sleep here, and we will be wake up by
		 * ep_poll_callback() when events will become available.
		 */
		init_waitqueue_entry(&wait, current);
		wait.flags |= WQ_FLAG_EXCLUSIVE;
		__add_wait_queue(&ep->wq, &wait);

		for (;;) {
			/*
			 * We don't want to sleep if the ep_poll_callback() sends us
			 * a wakeup in between. That's why we set the task state
			 * to TASK_INTERRUPTIBLE before doing the checks.
			 */
			set_current_state(TASK_INTERRUPTIBLE);
			if (!list_empty(&ep->rdllist) || !jtimeout)
				break;
			if (signal_pending(current)) {
				res = -EINTR;
				break;
			}

			spin_unlock_irqrestore(&ep->lock, flags);
			jtimeout = schedule_timeout(jtimeout);
			spin_lock_irqsave(&ep->lock, flags);
		}
		__remove_wait_queue(&ep->wq, &wait);

		set_current_state(TASK_RUNNING);
	}
	/* Is it worth to try to dig for events ? */
	eavail = !list_empty(&ep->rdllist) || ep->ovflist != EP_UNACTIVE_PTR;

	spin_unlock_irqrestore(&ep->lock, flags);

	/*
	 * Try to transfer events to user space. In case we get 0 events and
	 * there's still timeout left over, we go trying again in search of
	 * more luck.
	 */
	if (!res && eavail &&
	    !(res = ep_send_events(ep, events, maxevents)) && jtimeout)
		goto retry;

	return res;
}


static int ep_send_events(struct eventpoll *ep,
			  struct epoll_event __user *events, int maxevents)
{
	struct ep_send_events_data esed;

	esed.maxevents = maxevents;
	esed.events = events;

	return ep_scan_ready_list(ep, ep_send_events_proc, &esed);
}

static int ep_scan_ready_list(struct eventpoll *ep,
			      int (*sproc)(struct eventpoll *,
					   struct list_head *, void *),
			      void *priv)
{
	int error, pwake = 0;
	unsigned long flags;
	struct epitem *epi, *nepi;
	LIST_HEAD(txlist);

	/*
	 * We need to lock this because we could be hit by
	 * eventpoll_release_file() and epoll_ctl().
	 */
	mutex_lock(&ep->mtx);

	/*
	 * Steal the ready list, and re-init the original one to the
	 * empty list. Also, set ep->ovflist to NULL so that events
	 * happening while looping w/out locks, are not lost. We cannot
	 * have the poll callback to queue directly on ep->rdllist,
	 * because we want the "sproc" callback to be able to do it
	 * in a lockless way.
	 */
	spin_lock_irqsave(&ep->lock, flags);
	list_splice_init(&ep->rdllist, &txlist);
	ep->ovflist = NULL;
	spin_unlock_irqrestore(&ep->lock, flags);

	/*
	 * Now call the callback function. 
	 */
	error = (*sproc)(ep, &txlist, priv);//ep_send_events_proc

	spin_lock_irqsave(&ep->lock, flags);
	/*
	 * During the time we spent inside the "sproc" callback, some
	 * other events might have been queued by the poll callback.
	 * We re-insert them inside the main ready-list here.
	 */
	for (nepi = ep->ovflist; (epi = nepi) != NULL;
	     nepi = epi->next, epi->next = EP_UNACTIVE_PTR) {
		/*
		 * We need to check if the item is already in the list.
		 * During the "sproc" callback execution time, items are
		 * queued into ->ovflist but the "txlist" might already
		 * contain them, and the list_splice() below takes care of them.
		 */
		if (!ep_is_linked(&epi->rdllink))
			list_add_tail(&epi->rdllink, &ep->rdllist);
	}
	/*
	 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after
	 * releasing the lock, events will be queued in the normal way inside
	 * ep->rdllist.
	 */
	ep->ovflist = EP_UNACTIVE_PTR;

	/*
	 * Quickly re-inject items left on "txlist".
	 */
	list_splice(&txlist, &ep->rdllist);

	if (!list_empty(&ep->rdllist)) {
		/*
		 * Wake up (if active) both the eventpoll wait list and
		 * the ->poll() wait list (delayed after we release the lock).
		 */
		if (waitqueue_active(&ep->wq))
			wake_up_locked(&ep->wq);
		if (waitqueue_active(&ep->poll_wait))
			pwake++;
	}
	spin_unlock_irqrestore(&ep->lock, flags);

	mutex_unlock(&ep->mtx);

	/* We have to call this outside the lock */
	if (pwake)
		ep_poll_safewake(&ep->poll_wait);

	return error;
}


3.2、默认是LT水平触发模式,ET边缘触发模式需要自己指定

static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
			       void *priv)
{
	struct ep_send_events_data *esed = priv;
	int eventcnt;
	unsigned int revents;
	struct epitem *epi;
	struct epoll_event __user *uevent;

	/*
	 * We can loop without lock because we are passed a task private list.
	 * Items cannot vanish during the loop because ep_scan_ready_list() is
	 * holding "mtx" during this call.
	 */
	for (eventcnt = 0, uevent = esed->events;
	     !list_empty(head) && eventcnt < esed->maxevents;) {
		epi = list_first_entry(head, struct epitem, rdllink);

		list_del_init(&epi->rdllink);
		// 由accept->tipc_create f_op对应(stream_ops/msg_ops)其中poll就是socket.c中的poll函数
		revents = epi->ffd.file->f_op->poll(epi->ffd.file, NULL) &
			epi->event.events;

		/*
		 * If the event mask intersect the caller-requested one,
		 * deliver the event to userspace. Again, ep_scan_ready_list()
		 * is holding "mtx", so no operations coming from userspace
		 * can change the item.
		 */
		if (revents) {
			if (__put_user(revents, &uevent->events) ||
			    __put_user(epi->event.data, &uevent->data)) {
				list_add(&epi->rdllink, head);
				return eventcnt ? eventcnt : -EFAULT;
			}
			eventcnt++;
			uevent++;
			if (epi->event.events & EPOLLONESHOT)
				epi->event.events &= EP_PRIVATE_BITS;
			else if (!(epi->event.events & EPOLLET)) { //意思是只要不是ET模式(即默认是LT模式)则继续加入rdlist列表,如果设置了ET则不再加入
				/*
				 * If this file has been added with Level
				 * Trigger mode, we need to insert back inside
				 * the ready list, so that the next call to
				 * epoll_wait() will check again the events
				 * availability. At this point, noone can insert
				 * into ep->rdllist besides us. The epoll_ctl()
				 * callers are locked out by
				 * ep_scan_ready_list() holding "mtx" and the
				 * poll callback will queue them in ep->ovflist.
				 */
				list_add_tail(&epi->rdllink, &ep->rdllist);
			}
		}
	}

	return eventcnt;
}


其中POLLXX 系列和EPOLLXX宏数值是一样的,可以自己 测试


看下socket.c中的poll函数

static unsigned int poll(struct file *file, struct socket *sock,
			 poll_table *wait)
{
	struct sock *sk = sock->sk;
	u32 mask;

	poll_wait(file, sk->sk_sleep, wait);

	if (!skb_queue_empty(&sk->sk_receive_queue) ||
	    (sock->state == SS_UNCONNECTED) ||
	    (sock->state == SS_DISCONNECTING))
		mask = (POLLRDNORM | POLLIN);
	else
		mask = 0;

	if (sock->state == SS_DISCONNECTING)
		mask |= POLLHUP;
	else
		mask |= POLLOUT;

	return mask;
}




高速公路坐标高程计算软件是在多年的施工放样工作中总结出来的一个很有效的程序。它是公路、铁路施工放样的好助手,可以帮你完成以前你用很大的精力和时间完成的计算。它能在工作中给予很大的方便,使你能从繁琐的计算工作中解脱出来,你只要按要求将已知的几个数据输入即可,并大大的提高了计算精确性和准确性。操作简便、实用,适合采用坐标法放样,如具有全站仪和测距仪的测量放线工作,快速准确定位,很有推广价值。 高速公路坐标高程计算软件可以帮你完成直线、圆曲线、缓和曲线(完全缓和曲线和不完全缓和曲线)、S形曲线、复曲线、试车场高速环道布劳斯曲线的中桩和任意长度、任意角度边桩坐标高程计算,并可根据你有要求加任意点的坐标计算方法根据曲线是否完整对称可以选择交点法计算和特殊点计算方法。生成的坐标成果可以直接通过数据线导入全站仪,也可以导入Excel中便于打印,导入AUTOCAD中生成DWG图形,根据线形是否平顺来检验坐标准确性。 高速公路坐标高程计算软件应用于公路、铁路、等坐标高程计算,可用来计算桥梁桩基、立柱、支座垫石、护栏、桥面系及涵洞通道坐标高程,可计算试车场高速环道布劳斯曲线坐标,是施工放样和图纸坐标高程复核的好帮手,还可以用来复核工程上广泛应用的可编程计算器CASIO 5800坐标高程避免出错。 他是一个免费软件,没有任何限制。附送CASIO4850,5800程序及算法。 高速公路坐标高程计算软件简要说明: 一、线元法计算平曲线(主程序) 1、J为起算点里程,C、D为起算点的X、Y坐标,F为起算点的切线方位角,R为圆曲线半径(左偏取负,右偏取正),A、B为第一、第二缓和曲线回旋参数,O为圆曲线长度,Ki为该分段的终点里程; 2、对于直线段或圆曲线段,起算点可取直线或圆曲线上的任意一点; 3、对于带第一、第二缓和曲线的平曲线段,起算点应取HY点; 4、K为所求点的里程,T、P为第一偏距、偏角,S、Z为第二偏距、偏角,偏角取从该点的切线顺时针旋转的夹角; 5、分段法则:直线单独分段;单一的圆曲线单独分段;缓和曲线1 圆曲线 缓和曲线2为一个整体单独分段,若不存在第一或第二缓和曲线(即不完全缓和曲线)仍然可以计算;若不存在圆曲线,则O取零; 6、对于两圆夹一段缓和曲线分段这种类型,缓和曲线应该分到半径较小的那个圆上,因为程序算法本来就是从HY和YH点小半径R向大半径∞方向进行推算的,不同于以往从ZH或HZ点计算,从ZH或HZ点推算是从大半径∞向小半径R方向进行推算的。这种情况下回旋参数A=根号下√abs(LsR1R2/(R1-R2)),Ls为缓和曲线长,R1,R2为半径。 7、若第一或者第二缓和曲线不存在,此时A或B可取零; 8、F、Q切线方位角输入输出均为度.分秒的格式,例如153°24′05.24″=153.240524。Q改变时,可按照新方位角为基准,结合第一第二偏距、偏角重新计算所求点; 9、输入平曲线参数后,默认为计算全线坐标,可修改来计算某段曲线,默认间距也可修改; 10、可参考CAD图《平曲线计算图例》; 11、生成的中桩CAD脚本设置成在世界坐标系下生成,注意的是世界坐标系与大地测量坐标系的区别是XY坐标是互换的,否则画出的图形与实际相反。先打开CAD,设置好图层名称、颜色,并设置为当前层,然后单击CAD的工具==》运行脚本==》选中生成的脚本文件即可。 12、输出的坐标结果可以导入到EXCEL中,操作办法为:打开EXCEL,然后把坐标数据复制到单元格里,然后单击数据==》分列==》选中分隔符号==》下一步==》选中TAB键和逗号==》下一步==》完成即可。下一次可直接在此表中粘贴,数据自动分列。 二、缓和曲线计算(辅助程序) 1、本程序为辅助程序,用来从ZH点或HZ点计算整条完全的缓和曲线,若不知道HY点X、Y、Q参数,可用此程序计算出来,然后输入平曲线参数; 2、参数设置参考平曲线计算3、导出到EXCEL的办法同平曲线计算; 三、直线计算(辅助程序) 1、本程序为辅助程序,若已知P1(X1,Y1),P1--》P2的距离I及方位角J(度.分秒格式),可计算坐标P2(X2,Y2)。 四、方位角计算 1、已知两点的坐标,可计算P1--》P2的距离及方位角; 2、角度可以进行加减运算。(单位:度.分秒格式) 五、竖曲线计算(主程序) 1、J为起算点里程,Y为起算点的高程,R为圆曲线半径(取绝对值),E、F为第一、第二坡度,不带%号,例如2.5%的坡度就输入2.5,上坡取正值,下坡取负值; 2、K为所求点的里程,T为边桩到设计高程点的斜距,I为横坡,向外流水取正,向中流水取负,G为边桩的高程3、分段法则:以两竖曲线之间直线段中间的任意一点为分界,如上图中的K1、K2、K3;注意分离式路基一般要单独分段,分段时如果从起点就开始变坡,第一个分段起点必须与终点里程应相同或小1毫米,否则程序不能计算第一个分段的横坡; 4、无论任何时候R不能取零,否则可能导致被零除的错误; 5、可参考CAD图《竖曲线计算图例》; 6、导出到EXCEL的办法同平曲线计算; 六、交点法点计算平曲线(辅助程序) 1、交点法计算平曲线功能,是用来计算对称的完全缓和曲线的,如果特征点里程与图纸不符,必须查明原因,比如是由断链或者不完全缓和曲线引起的。 2、最后一个交点如果R、Ls、T、L如果不知道,R随便输入一个不为零的数字比如111,Ls、T、L输入零就可以了。 高速公路坐标高程计算软件截图
安装后c盘有源代码。 高速公路坐标高程计算软件 高速公路坐标高程计算软件是在多年的施工放样工作中总结出来的一个很有效的程序。 它是公路、铁路施工放样的好助手,可以帮你完成以前你用很大的精力和时间完成的计算。 它能在工作中给予很大的方便,使你能从繁琐的计算工作中解脱出来,你只要按要求将已 知的几个数据输入即可,并大大的提高了计算精确性和准确性。操作简便、实用,适合采 用坐标法放样,如具有全站仪和测距仪的测量放线工作,快速准确定位,很有推广价值。 高速公路坐标高程计算软件可以帮你完成直线、圆曲线、缓和曲线(完全缓和曲线和 不完全缓和曲线)、S形曲线、复曲线、试车场高速环道布劳斯曲线的中桩和任意长度、任 意角度边桩坐标高程计算,并可根据你有要求加任意点的坐标计算方法根据曲线是 否完整对称可以选择交点法计算和特殊点计算方法。生成的坐标成果可以直接通过数据线 导入全站仪,也可以导入Excel中便于打印,导入AUTOCAD中生成DWG图形,根据线形是否平 顺来检验坐标准确性。 高速公路坐标高程计算软件应用于公路、铁路、等坐标高程计算,可用来计算桥梁桩基、 立柱、支座垫石、护栏、桥面系及涵洞通道坐标高程,可计算试车场高速环道布劳斯曲线坐 标,是施工放样和图纸坐标高程复核的好帮手,还可以用来复核工程上广泛应用的可编程计 算器CASIO 5800坐标高程避免出错。 他是一个免费软件,没有任何限制。附送CASIO4850,5800程序及算法。 下载地址:天空软件站,搜索高速公路坐标高程计算。 本软件简要说明: 一、线元法计算平曲线(主程序) 1、J为起算点里程,C、D为起算点的X、Y坐标,F为起算点的切线方位角,R为圆曲线半径 (左偏取负,右偏取正),A、B为第一、第二缓和曲线回旋参数,O为圆曲线长度,Ki为该 分段的终点里程; 2、对于直线段或圆曲线段,起算点可取直线或圆曲线上的任意一点; 3、对于带第一、第二缓和曲线的平曲线段,起算点应取HY点; 4、K为所求点的里程,T、P为第一偏距、偏角,S、Z为第二偏距、偏角,偏角取从该点的 切线顺时针旋转的夹角; 5、分段法则:直线单独分段;单一的圆曲线单独分段;缓和曲线1+圆曲线+缓和曲线2为一 个整体单独分段,若不存在第一或第二缓和曲线(即不完全缓和曲线)仍然可以计算; 若不存在圆曲线,则O取零; 6、对于两圆夹一段缓和曲线分段这种类型,缓和曲线应该分到半径较小的那个圆上,因为 程序算法本来就是从HY和YH点小半径R向大半径∞方向进行推算的,不同于以往从ZH或HZ点计算, 从ZH或HZ点推算是从大半径∞向小半径R方向进行推算的。 这种情况下回旋参数A=根号下√abs(Ls*R1*R2/(R1-R2)),Ls为缓和曲线长,R1,R2为半径。 7、若第一或者第二缓和曲线不存在,此时A或B可取零; 8、F、Q切线方位角输入输出均为度.分秒的格式,例如153°24′05.24″=153.240524。 Q改变时,可按照新方位角为基准,结合第一第二偏距、偏角重新计算所求点; 9、输入平曲线参数后,默认为计算全线坐标,可修改来计算某段曲线,默认间距也可修改; 10、可参考CAD图《平曲线计算图例》; 11、生成的中桩CAD脚本设置成在世界坐标系下生成,注意的是世界坐标系与大地测量坐标系 的区别是XY坐标是互换的,否则画出的图形与实际相反。先打开CAD,设置好图层名称、颜色, 并设置为当前层,然后单击CAD的工具==>运行脚本==>选中生成的脚本文件即可。 12、输出的坐标结果可以导入到EXCEL中,操作办法为:打开EXCEL,然后把坐标数据复制到 单元格里,然后单击数据==>分列==>选中分隔符号==>下一步==>选中TAB键和逗号==>下一步 ==>完成即可。下一次可直接在此表中粘贴,数据自动分列。 二、缓和曲线计算(辅助程序) 1、本程序为辅助程序,用来从ZH点或HZ点计算整条完全的缓和曲线, 若不知道HY点X、Y、Q参数,可用此程序计算出来,然后输入平曲线参数; 2、参数设置参考平曲线计算3、导出到EXCEL的办法同平曲线计算; 三、直线计算(辅助程序) 1、本程序为辅助程序,若已知P1(X1,Y1),P1-->P2的距离I及方位角J(度.分秒格式), 可计算坐标P2(X2,Y2)。 四、方位角计算 1、已知两点的坐标,可计算P1-->P2的距离及方位角; 2、角度可以进行加减运算。(单位:度.分秒格式) 五、竖曲线计算(主程序) 1、J为起算点里程,Y为起算点的高程,R为圆曲线半径(取绝对值),E、F为第一、 第二坡度,不带%号,例如2.5%的坡度就输入2.5,上坡取正值,下坡取负值; 2、K为所求点的里程,T为边桩到设计高程点的斜距,I为横坡,向外流水取正, 向中流水取负,G为边桩的高程3、分段法则:以两竖曲线之间直线段中间的任意一点为分界,如上图中的K1、K2、K3; 注意分离式路基一般要单独分段,分段时如果从起点就开始变坡,第一个分段起点必须 与终点里程应相同或小1毫米,否则程序不能计算第一个分段的横坡; 4、无论任何时候R不能取零,否则可能导致被零除的错误; 5、可参考CAD图《竖曲线计算图例》; 6、导出到EXCEL的办法同平曲线计算; 六、交点法点计算平曲线(辅助程序) 1、交点法计算平曲线功能,是用来计算对称的完全缓和曲线的,如果特征点里程与图纸不符, 必须查明原因,比如是由断链或者不完全缓和曲线引起的。 一般地,匝道用线元法,主线用交点法,因为匝道的线型不一定是标准的交点法线型,如果不是标准的交点法线型,用常规方法推算是不对的,交点法适用于缓1+圆+缓2这种线型,对于缓1+圆1+缓2+圆2这种,缓2是分到圆1还是圆2上是有区别的,如果缓2分到半径小的圆上就适用交点法,反之则不适用。 2、最后一个交点如果R、Ls、T、L如果不知道,R随便输入一个不为零的数字比如111, Ls、T、L输入零就可以了。 七、其他说明 1、本程序是在WINXP下编译的,如果在WIN98、WIN2000下运行提示少DLL文件的话可以从网 上下载,拷贝到%windir%\system及system32目录,并用示例的格式来注册。 2、本软件梦(QQ704728827)和陈晓猫(QQ43308724)共同编写完成,有错误欢迎指正。 EMAIL:liuzhao3@163.com。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值