⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioroutin.c

📁 解吸SEED格式的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		dmax= dmin= *dpt;		while(n_data_pts--)		{			dmax= MAXI(dmax,*dpt);			dmin= MINI(dmin,*dpt);			++dpt;		}		((fabs((float)dmax) > fabs((float)dmin)) ? (head->record.maxamp= (float) dmax) : (head->record.maxamp= (float) -dmin));	}	else {		fpt= (float *)data;		max= min= *fpt;		while(n_data_pts--)		{			max= MAXI(max,*fpt);			min= MINI(min,*fpt);			++fpt;		}		((fabs((double)max) > fabs((double)min)) ? (head->record.maxamp= max) : (head->record.maxamp= -min));	}	return(0);}/*	xdr_gethead *		gets the next header from the xdr stream pointed to by *		xdrs and returns this header in the structure head. *		xdrs is assumed to be positioned at the next header, *		and does not search. *	returns: *			1		->	no error *			-1		->	not enough head to read *			-2		->	bad data type */int	xdr_gethead(head,xdrs)	XDR	*xdrs;	ahhed	*head;{	int	ierr = 0;	if((ierr = xdr_ahhead(xdrs, head)) == 1)	{		if((head->record.type < TYPEMIN) || (head->record.type > TYPEMAX))		{			get_null_head(head);			ierr = -2;	/* bad data type */			ah_errno= AE_DTYPE;		}	}	else		/* not enough head */	{		get_null_head(head);		ierr = -1;		ah_errno= AE_RHED;	}	return(ierr);}/*	xdr_puthead *		writes the header head onto the xdr stream pointed to by *		xdrs. *	returns: *			1		->	no error *			-1		->	error writing header */int	xdr_puthead(head,xdrs)	XDR	*xdrs;	ahhed	*head;{	int	ierr = 0;	if((ierr= xdr_ahhead(xdrs, head)) != 1)	{		ah_errno= AE_WHED;		ierr= -1;	}	return(ierr);}/*	xdr_tohead *		positions the read/write head to the beginning of the *		n-th header in the xdr stream pointed to by xdrs. *	returns: *			n	->	no error *			-1	->	not enough heads *			-2	->	bad seek */int	xdr_tohead(n,xdrs)	XDR	*xdrs;	int	n;{	ahhed	head;	int	i,ierr,j;	float	float_dum;	double	double_dum;	complex complex_dum;	tensor	tensor_dum;/* be warned: the following xdr_setpos call may not work at all 	*//* depending on the stream.  The use of 0 to get to the beginning 	*//* works empirically, but is not documented  ... sigh	- dws		*/	xdr_setpos(xdrs, (u_int) 0);	for(i=1; i<n; ++i)	{		if(xdr_gethead(&head,xdrs) == 1)		{			switch (head.record.type) {			case FLOAT:				for (j = 0; j < head.record.ndata; j++) {					if (!xdr_float(xdrs, &float_dum)) {						ierr = -2;	/* bad seek */						ah_errno= AE_RHED;						return(ierr);					}				}				break;			case COMPLEX:			case VECTOR:				for (j = 0; j < head.record.ndata; j++) {					if (!xdr_float(xdrs, &complex_dum.i) ||					    !xdr_float(xdrs, &complex_dum.r)) {						ierr = -2;	/* bad seek */						ah_errno= AE_RHED;						return(ierr);					}				}				break;			case TENSOR:				for (j = 0; j < head.record.ndata; j++) {					if (!xdr_float(xdrs, &tensor_dum.xx) ||					    !xdr_float(xdrs, &tensor_dum.yy) ||					    !xdr_float(xdrs, &tensor_dum.xy)) {						ierr = -2;	/* bad seek */						ah_errno= AE_RHED;						return(ierr);					}				}				break;			case 5:				for (j = 0; j < 4 * head.record.ndata; j++) {					if (!xdr_float(xdrs, &float_dum)) {						ierr = -2;	/* bad seek */						ah_errno= AE_RHED;						return(ierr);					}				}				break;			case DOUBLE:				for (j = 0; j < head.record.ndata; j++) {					if (!xdr_double(xdrs, &double_dum)) {						ierr = -2;	/* bad seek */						ah_errno= AE_RHED;						return(ierr);					}				}				break;			default:				ierr = -2;	/* bad seek */				ah_errno= AE_DTYPE;				return(ierr);			}		}		else		{			ierr = -1;	/* not enough head */			ah_errno= AE_RHED;			return(ierr);		}	}	return(i);	/* success */}/*	xdr_getdata *		reads from the xdr stream pointed to by xdrs into *		the array pointed to by array.  It assumes that *		the read/write head is positioned correctly  *		(i.e., right after the header), and does not *		search.  Works for any allowed data type. *	returns: *			number of elements read	->	OK *			-1			->	error */int	xdr_getdata(head,array,xdrs)	ahhed	*head;	char	*array;	XDR	*xdrs;{	int ierr = 0;	float *pfloat;	double	*pdouble;	complex *pcomplex;	tensor	*ptensor;	int i;	switch(head->record.type) {	case FLOAT:		pfloat = (float *) array;		for (i = 0; i < head->record.ndata; i++) {			if (! xdr_float(xdrs, pfloat++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case COMPLEX:	case VECTOR:		pcomplex = (complex *) array;		for (i = 0; i < head->record.ndata; i++) {			if (!xdr_float(xdrs, &(pcomplex->r)) ||			    !xdr_float(xdrs, &(pcomplex++->i))) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case TENSOR:		ptensor = (tensor *) array;		for (i = 0; i < head->record.ndata; i++) {			if (!xdr_float(xdrs, &(ptensor->xx)) ||			    !xdr_float(xdrs, &(ptensor->yy)) ||			    !xdr_float(xdrs, &(ptensor++->xy))) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case 5:		pfloat = (float *) array;		for (i = 0; i < 4 * head->record.ndata; i++) {			if (! xdr_float(xdrs, pfloat++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case DOUBLE:		pdouble = (double *) array;		for (i = 0; i < head->record.ndata; i++) {			if (! xdr_double(xdrs, pdouble++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	default:		ierr = -1;		ah_errno= AE_DTYPE;		return(ierr);	}	return(ierr);}/*	xdr_putdata *		writes array to the xdr stream pointed to by xdrs. *		Works for any allowed data type. *	returns: *			number of elements written	->	OK *			-1			->	error */int	xdr_putdata(head,array,xdrs)	ahhed	*head;	char	*array;	XDR	*xdrs;{	int	ierr = 0;	float *pfloat;	double	*pdouble;	complex *pcomplex;	tensor	*ptensor;	int i;	switch(head->record.type) {	case FLOAT:		pfloat = (float *) array;		for (i = 0; i < head->record.ndata; i++) {			if (! xdr_float(xdrs, pfloat++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case COMPLEX:	case VECTOR:		pcomplex = (complex *) array;		for (i = 0; i < head->record.ndata; i++) {			if (!xdr_float(xdrs, &(pcomplex->r)) ||			    !xdr_float(xdrs, &(pcomplex++->i))) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case TENSOR:		ptensor = (tensor *) array;		for (i = 0; i < head->record.ndata; i++) {			if (!xdr_float(xdrs, &(ptensor->xx)) ||			    !xdr_float(xdrs, &(ptensor->yy)) ||			    !xdr_float(xdrs, &(ptensor++->xy))) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case 5:		pfloat = (float *) array;		for (i = 0; i < 4 * head->record.ndata; i++) {			if (! xdr_float(xdrs, pfloat++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	case DOUBLE:		pdouble = (double *) array;		for (i = 0; i < head->record.ndata; i++) {			if (! xdr_double(xdrs, pdouble++) ) {				ah_errno= AE_RDATA;				ierr = -1;				return(ierr);			}			++ierr;		}		break;	default:		ierr = -1;		ah_errno= AE_DTYPE;		return(ierr);	}	return(ierr);}/*	xdr_putrecord *		writes head and array to the xdr stream pointed to by xdrs. *		Works for any allowed data type. *	returns: *			0	->	OK *			-1	->	error writing header *			-2	->	error writing data */int	xdr_putrecord(head,array,xdrs)	ahhed	*head;	char	*array;	XDR	*xdrs;{	int	ierr = 0;	(xdr_puthead(head,xdrs) == 1) ? ((xdr_putdata(head,array,xdrs) < 0) ? (ierr = -2) : (ierr = 0)) : (ierr = -1);	if(ierr)		ah_errno= AE_WRECORD;	return(ierr);}/*	xdr_getrecord *		gets header and data from the xdr stream pointed to by *		xdrs and puts them in head and array.  It assumes *		that the read/write head is positioned at the beginning *		of the header, and does not search.  Obviously, calling *		routine must have allocated enough space. *	returns: *			0	->	OK *			-1	->	error reading header *			-2	->	error reading data */int	xdr_getrecord(head,array,xdrs)	ahhed	*head;	char	*array;	XDR	*xdrs;{	int	ierr = 0;	(xdr_gethead(head,xdrs) == 1) ? ((xdr_getdata(head,array,xdrs) < 0) ? (ierr = -2) : (ierr = 0)) : (ierr = -1);	if(ierr)		ah_errno= AE_RRECORD;	return(ierr);}/* *	xdr_getrecord2 *		gets header and data from the xdr stream pointed to by *		xdrs and puts them in head and array.  It assumes *		that the read/write head is positioned at the beginning *		of the header, and does not search (although it does *		some error checking).  Space for array is allocated, so *		be sure to pass a pointer to the data pointer. Got it? *	returns: *			0	->	ok *			-1	->	error reading record *			-2	->	error allocating space for data */int	xdr_getrecord2(head,array,xdrs)	ahhed	*head;	char	**array;	XDR	*xdrs;{	int	ierr = 0;	int	xdr_gethead();	char	*mkdatspace();	if(xdr_gethead(head, xdrs) != 1) {		ierr = -1;		return(ierr);	}	*array= mkdatspace(head);	if(*array == NULL)	{		ierr= -2;		return(ierr);	}	if(xdr_getdata(head,*array,xdrs) < 0)		ierr= -1;	return(ierr);}/*	xdr_gogethead *		gets n-th header from the xdr stream pointed to by *		xdrs and returns this header in the structure *		head. *	returns: *			0	->	OK *			-1	->	stream not long enough *			-2	->	error reading header */int	xdr_gogethead(n,head,xdrs)	int	n;	ahhed	*head;	XDR	*xdrs;{	int	ierr = 0;	(xdr_tohead(n,xdrs) == n) ? ((xdr_gethead(head,xdrs) < 1) ? (ierr = -2) : (ierr = 0)) : (ierr = -1);	return(ierr);}/*	xdr_gogetrecord *		gets n-th record (header and data) from the xdr stream *		pointed to by xdrs and places it in head and array. *		Calling routine must allocate enough space. *	returns: *			0	->	OK *			-1	->	stream not long enough *			-2	->	error reading record */int	xdr_gogetrecord(n,head,array,xdrs)	int	n;	ahhed	*head;	char	*array;	XDR	*xdrs;{	int	ierr = 0;	(xdr_tohead(n,xdrs) == n) ? ((xdr_getrecord(head,array,xdrs) < 0) ? (ierr = -2) : (ierr = 0)) : (ierr = -1);	return(ierr);}xdr_ahhead(xdrsp, ahheadp)XDR *xdrsp;ahhed *ahheadp;{	u_int l;	char **pp, *p;	float *pf;	char **ppf;	l = CODESIZE;	p = ahheadp->station.code;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, (u_int) CODESIZE))		return(0);	l = CHANSIZE;	p = ahheadp->station.chan;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, CHANSIZE))		return(0);	l = STYPESIZE;	p = ahheadp->station.stype;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, STYPESIZE))		return(0);	if (!xdr_float(xdrsp, &ahheadp->station.slat))		return(0);	if (!xdr_float(xdrsp, &ahheadp->station.slon))		return(0);	if (!xdr_float(xdrsp, &ahheadp->station.elev))		return(0);	if (!xdr_float(xdrsp, &ahheadp->station.DS))		return(0);	if (!xdr_float(xdrsp, &ahheadp->station.A0))		return(0);	for (l = 0; l < NOCALPTS; l++) {		if (!xdr_float(xdrsp, &ahheadp->station.cal[l].pole.r))			return(0);		if (!xdr_float(xdrsp, &ahheadp->station.cal[l].pole.i))			return(0);		if (!xdr_float(xdrsp, &ahheadp->station.cal[l].zero.r))			return(0);		if (!xdr_float(xdrsp, &ahheadp->station.cal[l].zero.i))			return(0);	}	if (!xdr_float(xdrsp, &ahheadp->event.lat))		return(0);	if (!xdr_float(xdrsp, &ahheadp->event.lon))		return(0);	if (!xdr_float(xdrsp, &ahheadp->event.dep))		return(0);	if (!xdr_short(xdrsp, &ahheadp->event.ot.yr))		return(0);	if (!xdr_short(xdrsp, &ahheadp->event.ot.mo))		return(0);	if (!xdr_short(xdrsp, &ahheadp->event.ot.day))		return(0);	if (!xdr_short(xdrsp, &ahheadp->event.ot.hr))		return(0);	if (!xdr_short(xdrsp, &ahheadp->event.ot.mn))		return(0);	if (!xdr_float(xdrsp, &ahheadp->event.ot.sec))		return(0);	l = COMSIZE;	p = ahheadp->event.ecomment;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, COMSIZE))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.type))		return(0);	if (!xdr_long(xdrsp, &ahheadp->record.ndata))		return(0);	if (!xdr_float(xdrsp, &ahheadp->record.delta))		return(0);	if (!xdr_float(xdrsp, &ahheadp->record.maxamp))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.abstime.yr))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.abstime.mo))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.abstime.day))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.abstime.hr))		return(0);	if (!xdr_short(xdrsp, &ahheadp->record.abstime.mn))		return(0);	if (!xdr_float(xdrsp, &ahheadp->record.abstime.sec))		return(0);	if (!xdr_float(xdrsp, &ahheadp->record.rmin))		return(0);	l = COMSIZE;	p = ahheadp->record.rcomment;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, COMSIZE))		return(0);	l = LOGSIZE;	p = ahheadp->record.log;	pp = &p;	if (!xdr_bytes(xdrsp, pp, &l, LOGSIZE))		return(0);	l = NEXTRAS;	pf = ahheadp->extra;	ppf = (char **) &pf;	if (!xdr_array(xdrsp, ppf, &l, NEXTRAS, sizeof(float),		(xdrproc_t) xdr_float))		return(0);		return(1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -