You are on page 1of 21

Proiectarea Asistata de Calculator pentru Avionica

Elemente de limbaj C -II; Aplicatii de calcul complexe

Elmente delimbaj C II Exemple de aplicatii de calcul ;


Aplicatie pentru calcul balistic Aplicatie pentru transformare coordonate GPS

Aplicatie calcul balistic


Functia principala void main() Functia STEP void step(double ga0,double hi0) Functia de citire date initiale void cit()

Functia F

Functia RK4 void RK4()

Functia LIN

Functia atms

Functia Cx

definitii
include<stdio.h> #include<math.h> /* P H Y S I C A L C O N S T A N T S */ #define TZERO 288.15 /* sea-level temperature, deg K */ #define PZERO 101325.0 /* sea-level pressure, N/sq.m */ #define RHOZERO 1.225 /* sea-level density, kg/cu.m */ #define AZERO 340.294 /* speed of sound at S.L. m/sec */ #define BETAVISC 1.458E-6 /* viscosity constant */ #define SUTH 110.4 /* Sutherland's constant deg K */ #define pi 3.1415926536 #define Rp 6356766.0 // raza pamintului in metri // constante double rg=180./pi; double rmi = 3000./pi; double grm = 3000./180.;

Date comune
//date comune int ist; double inc, ga0, hi0,m,S,d,alp,bep,yc,poo,too,doo,eps,V0,xpv,zpv; // incarcatura double y[6],yp[6],rez[7],t,dummy,tb,xb,zb,xpt,ypt,zpt,xt,yt,zt,gamin, gamax, distm; // elemente program de calcul // Prototipuri void cit(); double g0(); void step( double, double); void RK4(double t,double tfin,double y[6], double eps);//prototipul functiei de integrare Runge-Kutta de ordinul 4 cu pas variabil void F(double t, double y[6]); // prototipul functiei de calcul derivate void atms (double, double, double, double , double*, double*, double*, double*); double Cx(double ); double lin(int ,double xl[],double yl[],double ); void SimpleAtmosphere(const double, double*, double*, double*); double MetricViscosity(const double); FILE *pfw, *pfr;

Functia principala
void main() { double epsd,dga,dhi,ga2,hi2,Dx2,Dz2,DDx,DDz,ga1,hi1,prag; double Dx1,Dz1,Dx0,Dz0,Dg,Dh,dung,dist,gam,him,xbm,zbm,xl,zl,eroare,ung_vert,u ng_oriz; int i; ist=0; pfw=fopen("rez.dat","w"); cit (); if(ist==1) return; epsd=1.; prag=0.00001; ga0=ga0*rmi; hi0=hi0*rmi;

Functia principala - continuare


fprintf(pfw,"solutia problemei\n"); fprintf(pfw,"inaltator = %13.3f [grade] \n",ung_vert);//solutia problemei fprintf(pfw,"directie = %13.3f [grade] \n",ung_oriz);//solutia problemei fclose(pfw); return; } } printf("problema nu are solutie, sistem divergent \n"); fprintf(pfw,"problema nu are solutie, sistem divergent \n"); fclose(pfw);
return;

Functia de citire date initiale


void cit() { double pres_sol, temp_sol,xpt,ypt,zpt,dd,dh,dgai,ee1,vint,gis,ddmin, ddmax ; // timpul final al integrarii; eroarea admisa de cacul; int inc; m=1.5; d=0.06; S=pi*d*d/4.; eps=0.01; // inc - incarcatura : 0,1,2,3 // vint - viteza vintului [m/s] // gis - gismentul directiei din care bate vintul [grade] // xpt,ypt,zpt coordonatele pozitiei de tragere [m] // xt, yt, zt - coordonatele obiectivului [m] pfr=fopen("par.dat","r"); fscanf(pfr,"%i\n%lf\n%lf\n%lf\n%lf\n",&inc,&vint,&gis,&pres_sol,&te mp_sol); //date de intrare fscanf(pfr,"%lf\n%lf\n%lf\n",&xpt,&ypt,&zpt); // date de intrare fscanf(pfr,"%lf\n%lf\n%lf\n",&xt,&yt,&zt); // date de intrare fclose(pfr); poo=pres_sol/760.; too=(temp_sol+273.)/288.15;

Functia STEP
void step(double ga0,double hi0) { double tfin; // timpul final al integrarii; eroarea admisa de cacul; t=0.; tfin=100.; y[0]=V0; y[1]=ga0; y[2]=hi0; y[3]=0.; y[4]=0.; y[5]=0.; ga0=ga0*rmi; // fprintf(pfw,"%13.3f%13.3f%13.3f%13.3f%13.3f%13.3f%13.3f\n",t,y[0]/100 .,y[1]*rg,y[2]*rg,y[3]/1000.,y[4]/1000.,y[5]/1000.);//solutia pe parcursul integrarii RK4(t,tfin,y,eps); return;

Functia RK4

void RK4(double t,double tfin,double y[], double eps) { double k1[100],k2[100],k3[100],k4[100],tet[100],y1[100],y2[100],y3[100],y4[100]; double t1,t2,t3,t4,h,tet_max,te1,te2,kk; int i,j,k; h=(tfin-t)/1000.; // valoarea de pornire a pasului k=0; j=0; for( i=0;t<=tfin;i++) { k++; t1=t+h/2.; t2=t+h/2.; t3=t+h; tet_max=0.; F( t, y ); for ( j=0; j<=5; j++) { k1[j]=h*yp[j]; y1[j]=y[j]+k1[j]/2.; } F( t1, y1 ); for ( j=0; j<=5; j++) { k2[j]=h*yp[j]; y2[j]=y[j]+k2[j]/2.; } F(t2,y2);

Functia F
void F(double t, double y[]) { double temp,pressure,density,asound,F0,Mach,V,ga, hi; V=y[0]; ga=y[1]; hi=y[2]; atms(y[4],poo,too,doo,&temp,&pressure,&density,&asound); Mach=V/asound; F0=density*V*V*S/2.; yp[0]=F0*Cx(Mach)/m-g0()*sin(ga); yp[1]=-g0()*cos(ga)/V; yp[2]=0.; yp[3]=V*cos(hi)*cos(ga)+xpv; yp[4]=V*sin(ga); yp[5]=V*sin(hi)*cos(ga)+zpv; return;

Functia Cx

double Cx(double Mach) { double xl[18] = {0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.9, 1.}; // Mach double yl[18] = { -0.6516223 ,-0.6370796, -0.6283845, -0.6245042, 0.6218819, -0.6199873, -0.6185613, -0.6174602, -0.6165971, -0.6159168, -0.6153825, -0.6149697, -0.6146623, -0.6144506, 0.6143311, -0.7189761, -0.8065761, -0.8982782,}; // Cx double u0[5]={750.,950.,1150.,1283.3 ,1333.3}; double i0[5]={0.91825,0.99547,0.908039,0.832119,0.96489}; double u1[6]={750.,933.3,1100.,1266.67, 1300., 1316.67}; double i1[6]={0.585481,0.59349,0.59941,0.637929,0.5686,0.635661}; double u2[8]={750., 883.3,1016.67, 1100., 1166.67, 1200., 1233.3, 1300.} ; double i2[8]={0.395741, 0.409279,0.3963, 0.40065, 0.41528, 0.415319, 0.408901, 0.36859}; double u3[2]={750.,1300.0}; double i3[2]={0.226101,0.226101}; double Cx; // Cx= lin(18, xl, yl, Mach); // if(inc==0) Cx=Cx*lin(5,u0,i0,ga0); if(inc==1) Cx=Cx*lin(6,u1,i1,ga0); return Cx;

Functia atms
void atms (double alt, double ppo, double pto, double pdo, double *temp, double *pressure, double *density, double *asound) { double altKm; double sigma,delta,theta; altKm=alt/1000.; SimpleAtmosphere(altKm, &sigma, &delta, &theta); *temp=TZERO*theta*pto; *pressure=PZERO*delta*ppo; *density=RHOZERO*sigma*pdo; *asound=AZERO*sqrt(theta)*sqrt(pto); }

Functia LIN
double lin(int n,double xl[],double yl[],double xx) { double yy; int i,i1; if(xx<xl[0]) { yy=yl[0]; return yy; } if(xx>xl[n-1]) { yy=yl[n-1]; return yy; } for(i=1;i<=n-1;i++) { i1=i-1; if((xx>=xl[i1])&&(xx<=xl[i]))

Aplicatie GPS
Functia principala int _tmain (int argc, _TCHAR* argv[])

//functie conversie coordonate UTM to Lat, Long

//functie conversie coordonate Lat, Long to UTM

Definitii de marimi
#include "stdafx.h" #include <math.h> //marimi utilizate pentru conversia de coordonate #define PI 3.14159265 #define FOURTHPI PI / 4 #define deg2rad PI / 180 #define rad2deg 180.0 / PI #define eqradius 6378137 #define eccentricity 0.00669438

Definire structura de date , prototipurile functiilor



struct utm //structura cu coordonatele UTM { double UTMNorthing; //y double UTMEasting; //x int UTMZone; };
struct gps //structura cu coordonatele geografice { double latitudine; double longitudine; short altitudine; double decl_magn; }; void LLtoUTM(double , double , double , struct utm *); void UTMtoLL(const double, const double , double , struct gps *); FILE *pfw, *pfr;

Functia principala
int _tmain(int argc, _TCHAR* argv[]) { double Lat, Long, LongOrigin; double Lat_gr, Lat_min, Lat_sec; double Long_gr, Long_min, Long_sec; // double LongO_gr, LongO_min, LongO_sec; struct utm valreturn; // { // double UTMNorthing; //y // double UTMEasting; //x // int UTMZone; // }; int i,nr_p; double x[100], y[100]; char text[200]; // double Lat=45.*deg2rad; // double Long=27.*deg2rad; // double LongOrigin=26.*deg2rad; fopen_s(&pfr,"par_gps.txt","r"); fopen_s(&pfw,"rez_gps.txt","w");

Functia principala - continuare


fscanf_s(pfr,"%s\n",&text,200); //comentariu fscanf_s(pfr,"%ld\n",&nr_p); //Latitudine Gr fprintf_s(pfw,"Solutia problemei\n"); for(i=0;i<nr_p;i++) { fscanf_s(pfr,"%lf%lf%lf%lf%lf%lf\n",&Lat_gr,&Lat_min,&Lat_sec,&Long_gr, &Long_min,&Long_sec); //Latitudine Gr Lat= Lat_gr+Lat_min/60.+Lat_sec/3600.; Long= Long_gr+Long_min/60.+Long_sec/3600.; LongOrigin= 0.0; //LongO_gr+LongO_min/60.+LongO_sec/3600.; LLtoUTM( Lat, Long, LongOrigin, &valreturn); if(i==0) {x[i]=valreturn.UTMEasting; y[i]=valreturn.UTMNorthing;}; if(i>0) {x[i]=valreturn.UTMEasting-x[0]; y[i]=valreturn.UTMNorthing-y[0];}; fprintf_s(pfw,"X_Est = %13.0f [m] Y_Nord= %13.0f [m] \n", x[i], y[i]);//solutia problemei }; fclose(pfr); fclose(pfw); return 0;
}

//functie conversie coordonate UTM to Lat, Long


//functie conversie coordonate UTM to Lat, Long void UTMtoLL(const double UTMNorthing, const double UTMEasting, double LongOrigin, struct gps *valreturn) { double k0 = 0.9996; double a = eqradius; double eccSquared = eccentricity; double eccPrimeSquared; double e1 = (1-sqrt(1-eccSquared))/(1+sqrt(1-eccSquared)); double N1, T1, C1, R1, D, M; double mu, phi1, phi1Rad; double Lat, Long; double x, y; x = UTMEasting - 500000.0; //remove 500,000 meter offset y = UTMNorthing; . Lat = phi1Rad - (N1*tan(phi1Rad)/R1)*(D*D/2-(.; valreturn->latitudine = Lat * rad2deg; Long = (D-(1+2*T1+C1)*.; valreturn->longitudine = LongOrigin + Long * rad2deg;
}

//functie conversie coordonate Lat, Long to UTM


void LLtoUTM(double Lat, double Long, double LongOrigin, struct utm *valreturn) { double a = eqradius; double eccSquared = eccentricity; double k0 = 0.9996; double eccPrimeSquared; double N, T, C, A, M; double LongOriginRad; double LongTemp = Long; double LatRad = Lat * deg2rad; double LongRad = LongTemp * deg2rad; LongOriginRad = LongOrigin * deg2rad; eccPrimeSquared = eccSquared / (1-eccSquared); .. valreturn->UTMEasting = (double)(k0 * N * (A + (1 - T + C) * A * A * A / 6.. * } valreturn->UTMNorthing = (double)(k0 * (M + N * tan(LatRad) * (A

You might also like