.

mewestside의 이미지

코드 내용은 아래와 같이 첨부합니다..

make와 관련된 파일들도 첨부를 하겠습니다...

제가 잘 안되는 부분은 함수를 만들어서 넣는 부분입니다..

계산하는 과정을 main 함수에 쭈욱 넣었는데..

XCOR 함수를 따로 만들어서 넣는 과정이 필요할 듯해서 넣을려고 하는데..

잘 안되서 이렇게 질문을 드립니다.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "sacdata.h"
 
long int read_sac(char *fname, SAC_DATA *sdata, float *beg, float *dt);
 
SAC_DATA ew, ns;
 
float XCOR(long int npts, float *ew.fdat[], float *ns.fdat[]);
 
int main(int argc, char *argv[])
{
	int i, j, k;
	float bege, begn, dt;
	float coeff;
 
	coeff = 0;
 
	if( argc < 3 )
	{
		fprintf(stderr,"Usage: %s e.sac n.sac\n",argv[0]);
		return -1;
	}
 
	read_sac(argv[1],&ew,&bege,&dt);
	read_sac(argv[2],&ns,&begn,&dt);
 
	coeff = XCOR(ew.npts, &ew.fdat[], &ns.fdat[]);
 
	fprintf(stdout, "  coe : %.2f\n", coeff);
 
	return 0;
}
 
float XCOR(long int npts, float *ew.fdat[], float *ns.fdat[])
{
	int i, j, k;
	float bege, begn, dt;
	float ewsum, nssum, ewavg, nsavg;
	float ewsq, nssq, ewd, nsd;
	float ewns, r;
	float npts;
 
	ewsum = 0.,   nssum = 0.,   ewavg = 0.,   nsavg = 0.;
	ewsq = 0.,   nssq = 0.,   ewd = 0.,   nsd = 0.;
	ewns = 0.,   r = 0.,   npts = 0.;
 
	/////////////// Phase info. ///////////////
 
	npts = ew.npts;
 
	for (i=0; i<npts; i++)
	{
		if (ew.fdat[i] > 0)
		{
		    	ew.fdat[i] = 1.;
		}
			else if (ew.fdat[i] < 0)
		{
			ew.fdat[i] = -1.;
		}
			else
		{
			ew.fdat[i] = 0;
		}
	}
 
	for (i=0; i<npts; i++)
	{
		if (ns.fdat[i] > 0)
		{
			ns.fdat[i] = 1.;
		}
		else if (ns.fdat[i] < 0)
		{
			ns.fdat[i] = -1.;
		}
		else
		{
			ns.fdat[i] = 0;
		}
	}
 
 
	////////// Average //////////
 
	for (i=0; i<npts; i++)
	{
		ewsum += ew.fdat[i];
	}
 
	for (i=0; i<npts; i++)
	{
		nssum += ns.fdat[i];
	}
 
	ewavg = ewsum / npts;
	nsavg = nssum / npts;
 
 
	////////// Standard Deviation ///////////
 
	for (i=0; i<npts; i++)
	{
		ewsq += (ew.fdat[i] - ewavg) * (ew.fdat[i] - ewavg);
	}
 
	for (i=0; i<npts; i++)
	{
		nssq += (ns.fdat[i] - nsavg) * (ns.fdat[i] - nsavg);
	}
 
	ewd = sqrt (ewsq / npts);
	nsd = sqrt (nssq / npts);
 
 
	///////// crosscorrelation coefficient /////////
 
	for (i=0; i<npts; i++)
	{
		ewns += ((ew.fdat[i] - ewavg) / ewd) * ((ns.fdat[i] - nsavg) / nsd);
	}
 
	r = ewns / npts;
 
	return r;
}	
File attachments: 
첨부파일 크기
Package icon coding.zip14.29 KB

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.