semsudin BIH
Član broj: 13751 Poruke: 58 *.pppoe07-1790.bih.net.ba.
Sajt: www.hostbih.com
|
ma neki kod za konvertovanje vremena i izracunavanje nekih parametara, to treba da konvertujem ali nece, evo primjera koda sa pointerima, jedna funkcijau C koju ja treba da pretvorim u PHP, posto bi se to trebalo da izvrsava na webu:
#include <fstream>
#include <iostream>
#include <stdlib.h>
//#include <conio.h>
#include <math.h>
using namespace std;
#define pi 3.1415926535897932
#define DToR (pi / 180)
#define RToH (12 / pi)
#define EarthRadius 6378.14
void GetRatior(int yg,int mg,int dg,double param[],double *IshRt,double *FajrRt);
/*------------------------- Sun ------------------------------------------*/
double atanxy(double x,double y);
void EclipToEquator(double lmdr,double betar,double &alph, double &dltr);
double RoutinR2(double M,double e);
double GCalendarToJD(int yg,int mg, double dg );
double SunParamr(int yg,int mg, int dg,double ObsLon,double ObsLat, double TimeZone,
double *Rise,double *Transit,double *Setting,double *RA,double *Decl,int *RiseSetFlags);
/*=====================================================================*/
/* Computation for the Sun */
/*=====================================================================*/
double atanxy(double x,double y)
{
double argm;
if(x==0) argm=0.5*pi; else argm=atan(y/x);
if(x>0 && y<0) argm=2.0*pi+argm;
if(x<0) argm=pi+argm;
return argm;
}
void EclipToEquator(double lmdr,double betar,double &alph, double &dltr)
{
/*
Convert Ecliptic to Equatorial Coordinate
p.40 No.27, Peter Duffett-Smith book
input: lmdr,betar in radians
output: alph,dltr in radians
*/
double eps=23.441884; // (in degrees) this changes with time
double sdlt,epsr;
double x,y,alpr;
double rad=0.017453292; // =pi/180.0
epsr=eps*rad; // convert to radians
sdlt=sin(betar)*cos(epsr)+cos(betar)*sin(epsr)*sin(lmdr);
dltr=asin(sdlt);
y=sin(lmdr)*cos(epsr)-tan(betar)*sin(epsr);
x=cos(lmdr);
alph=atanxy(x,y);
}
double RoutinR2(double M,double e)
{
/*
Routine R2:
Calculate the value of E
p.91, Peter Duffett-Smith book
*/
double dt=1,dE,Ec;
Ec=M;
while(fabs(dt)>1e-9)
{
dt=Ec-e*sin(Ec)-M;
dE=dt/(1-e*cos(Ec));
Ec=Ec-dE;
}
return Ec;
}
double SunParamr(int yg,int mg, int dg,double ObsLon,double ObsLat, double TimeZone,
double *Rise,double *Transit,double *Setting,double *RA,double *Decl,int *RiseSetFlags)
{
/*
p.99 of the Peter Duffett-Smith book
*/
double UT,ET,y,L,e,M,omg;
double eps,T,JD,Ec;
double tnv,v,tht;
double K,angl,T1,T2,H,cH;
*RiseSetFlags=0;
JD=GCalendarToJD(yg,mg,dg);
T=(JD+ TimeZone/24.0 - 2451545.0) / 36525.0;
L=279.6966778+36000.76892*T+0.0003025*T*T; // in degrees
while(L>360) L=L-360;
while(L<0) L=L+360;
L=L*pi/180.0; // radians
M=358.47583+35999.04975*T-0.00015*T*T-0.0000033*T*T*T;
while(M>360) M=M-360;
while(M<0) M=M+360;
M=M*pi/180.0;
e=0.01675104-0.0000418*T-0.000000126*T*T;
Ec=23.452294-0.0130125*T-0.00000164*T*T+0.000000503*T*T*T;
Ec=Ec*pi/180.0;
y=tan(0.5*Ec);
y=y*y;
ET=y*sin(2*L)-2*e*sin(M)+4*e*y*sin(M)*cos(2*L)-0.5*y*y*sin(4*L)-5*0.25*e*e*sin(2*M);
UT=ET*180.0/(15.0*pi); // from radians to hours
Ec=RoutinR2(M,e);
tnv=sqrt((1+e)/(1-e))*tan(0.5*Ec);
v=2.0*atan(tnv);
tht=L+v-M;
EclipToEquator(tht,0,*RA,*Decl);
K=12-UT-TimeZone+ObsLon*12.0/pi; // (Noon)
*Transit=K;
/* Sunrise and Sunset*/
angl=(-0.833333)*DToR; // Meeus p.98
T1=(sin(angl)-sin(*Decl)*sin(ObsLat));
T2=(cos(*Decl)*cos(ObsLat)); // p.38 Hour angle for the Sun
cH=T1/T2;
if(cH>1) {*RiseSetFlags=16;cH=1;} /*At this day and place the sun does not rise or set */
H=acos(cH);
H=H*12.0/pi;
*Rise=K-H; // Sunrise
*Setting=K+H; // SunSet
return JD;
}
int OmAlQrahr(int yg,int mg,int dg, double param[], double lst[])
{
int flag=1,flagrs,problm=0;
double RA,Decl;
double Rise,Transit,Setting;
double SINd,COSd;
double act,H,angl,K,cH;
double X,MaxLat;
double H0,Night,IshRt,FajrRt;
double HightCorWest=0,HightCorEast=0;
double IshFix,FajrFix;
/*
Main Local variables:
RA= Sun's right ascension
Decl= Sun's declination
H= Hour Angle for the Sun
K= Noon time
angl= The Sun altitude for the required time
flagrs: sunrise sunset flags
0:no problem
16: Sun always above horizon (at the ploes for some days in the year)
32: Sun always below horizon
*/
/* Compute the Sun various Parameters */
SunParamr(yg,mg,dg,-param[1],param[2],-param[5],
&Rise,&Transit,&Setting,&RA,&Decl,&flagrs);
/* Compute General Values */
SINd=sin(Decl)*sin(param[2]);
COSd=cos(Decl)*cos(param[2]);
/* Noon */
K=Transit;
/* Compute the height correction */
HightCorWest=0;HightCorEast=0;
if(flagrs==0 && fabs(param[2])<0.79 && (param[4]!=0 || param[3]!=0))
{ /* height correction not used for problematic places above 45deg*/
H0=H=0;
angl=-0.83333*DToR; /* standard value angl=50min=0.8333deg
for sunset and sunrise */
cH=(sin(angl)-SINd)/(COSd);
H0=acos(cH);
X=EarthRadius*1000.0; /* meters */
angl=-0.83333*DToR+(0.5*pi-asin(X/(X+param[3]))); /* */
cH=(sin(angl)-SINd)/(COSd);
HightCorWest=acos(cH);
HightCorWest=(H0-HightCorWest)*(RToH);
angl=-0.83333*DToR+(0.5*pi-asin(X/(X+param[4])));
cH=(sin(angl)-SINd)/(COSd);
HightCorEast=acos(cH);
HightCorEast=(H0-HightCorEast)*(RToH);
}
/* Modify Sunrise,Sunset and Transit for problematic places*/
if(!(flagrs==0 && fabs(Setting-Rise)>1 && fabs(Setting-Rise)<23))
{
problm=1;
if(param[2]<0) MaxLat= -fabs(param[9]); else MaxLat= fabs(param[9]);
/* Recompute the Sun various Parameters using the reference param[9] */
SunParamr(yg,mg,dg,-param[1],MaxLat,-param[5],
&Rise,&Transit,&Setting,&RA,&Decl,&flagrs);
K=Transit; /* exact noon time */
/* ReCompute General Values for the new reference param[9]*/
SINd=sin(Decl)*sin(MaxLat);
COSd=cos(Decl)*cos(MaxLat);
}
/*-------------------------------------------------------------*/
if(K<0) K=K+24;
lst[2]=Rise-HightCorEast; /* Sunrise - Height correction */
lst[3]=K+param[0];
lst[5]=Setting+HightCorWest+param[0];
/*-------------------------------------------------------------*/
if(problm) /* For places above 65deg */
act=param[8]+tan(fabs(Decl-MaxLat));
else /* no problem */
act=param[8]+tan(fabs(Decl-param[2])); /*In the standard
equations abs() is not used,
but it is required for -ve latitude */
angl=atan(1.0/act);
cH=(sin(angl)-SINd)/(COSd);
if(fabs(cH)>1.0)
{
H=3.5;
flag=0;
}
else
{
H=acos(cH);
H=H*RToH;
}
lst[4]=K+H+param[0];
/*-------------------------------------------------------------*/
angl=-param[6];
cH=(sin(angl)-SINd)/(COSd);
if(fabs(param[2])<0.83776) /*If latitude<48deg */
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[1]=K-(H+HightCorEast)+param[0];
lst[7]=lst[1];
}
else
{ /* Get fixed ratio, data depends on latitutde sign*/
if(param[2]<0)
GetRatior(yg,12,21,param,&IshFix,&FajrFix);
else
GetRatior(yg,6,21,param,&IshFix,&FajrFix);
if(fabs(cH)>(0.45+1.3369*param[6]))
{
Night=24-(Setting-Rise); /* Night Length */
lst[1]=Rise-Night*FajrFix;
}
else
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[1]=K-(H+HightCorEast)+param[0];
}
lst[7]=lst[1];
if(fabs(cH)>1)
{
GetRatior(yg,mg,dg,param,&IshRt,&FajrRt);
Night=24-(Setting-Rise); /* Night Length */
lst[7]=Rise-Night*FajrRt;
}
else
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[7]=K-(H+HightCorEast)+param[0];
}
}
/*-------------------------------------------------------------*/
if(param[7]!=0)
{
angl=-param[7];
cH=(sin(angl)-SINd)/(COSd);
if(fabs(param[2])<0.83776) /*If latitude<48deg */
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[6]=K+(H+HightCorWest+param[0]);
lst[8]=lst[6];
}
else
{
if(fabs(cH)>(0.45+1.3369*param[6])) /* A linear equation I have interoduced */
{
Night=24-(Setting-Rise); /* Night Length */
lst[6]=Setting+Night*IshFix;
}
else
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[6]=K+(H+HightCorWest+param[0]);
}
if(fabs(cH)>1.0)
{ /* The problem occurs for places above -+48 in the summer */
GetRatior(yg,mg,dg,param,&IshRt,&FajrRt);
Night=24-(Setting-Rise); /* Night Length */
lst[8]=Setting+Night*IshRt; /* According to the general ratio rule*/
}
else
{
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[8]=K+(H+HightCorWest+param[0]);
}
}
}
else
{
lst[6]=lst[5]+param[10];
lst[8]=lst[6];
}
angl=param[11];
cH=(sin(angl)-SINd)/(COSd);
if((fabs(param[2])<1.134 || flagrs==0) && fabs(cH)<=1.0) /*If latitude<65deg */
{ /* no problem */
H=acos(cH);
H=H*RToH; /* convert radians to hours */
lst[9]=K-(H+HightCorEast)+param[0];
}
else
{
lst[9]=lst[2]+0.25; /* If no Sunrise add 15 minutes */
}
return flag;
}
void GetRatior(int yg,int mg,int dg,double param[],double *IshRt,double *FajrRt)
{
int flagrs;
double RA,Decl;
double Rise,Transit,Setting;
double SINd,COSd;
double H,angl,cH;
double MaxLat;
double FjrRf,IshRf;
double Night;
if(param[2]<0) MaxLat= -fabs(param[9]); else MaxLat= fabs(param[9]);
SunParamr(yg,mg,dg,-param[1],MaxLat,-param[5],
&Rise,&Transit,&Setting,&RA,&Decl,&flagrs);
SINd=sin(Decl)*sin(MaxLat);
COSd=cos(Decl)*cos(MaxLat);
Night=24-(Setting-Rise); /* Night Length */
/* Fajr */
angl=-param[6];
cH=(sin(angl)-SINd)/(COSd);
H=acos(cH);
H=H*RToH; /* convert radians to hours */
FjrRf=Transit-H-param[0];
/* Isha */
if(param[7]!=0)
{
angl=-param[7];
cH=(sin(angl)-SINd)/(COSd);
H=acos(cH);
H=H*RToH; /* convert radians to hours */
IshRf=Transit+H+param[0];
}
else
{
IshRf=Setting+param[10];
}
*IshRt=(IshRf-Setting)/Night;
*FajrRt=(Rise-FjrRf)/Night;
return;
}
[Ovu poruku je menjao semsudin dana 22.02.2006. u 01:01 GMT+1]
|