用c语言写的简单的计算方位角的程序
#include "string.h"#include "ctype.h"
#include "mathf.h"
#include <stdlib.h>
#include <stdio.h>
#include <fxlib.h>
#include <math.h>
#include <stdarg.h>
#include <dispbios.h>
int cur_row=1;
char buf={0};
double a,b,c,d,e,f,g,h,i,j,k,l,m,n;
unsigned char *sp1=" ";
void message(char *msg)//send message
{
locate(1,8);
Print(sp1);
Print((unsigned char *)msg);
}
int printf(const char *cpFormat, ...)//show string in current line
{
char cpBuffer={0};
int i=0;
va_list pArgList;
va_start(pArgList, cpFormat);
vsprintf(cpBuffer, cpFormat, pArgList);
va_end(pArgList);
cpBuffer=0;
if(cur_row>7)
{
int x,y,dot;
for(x=0;x<=127;x++)
for(y=0;y<=55;y++)
Bdisp_SetPoint_VRAM (x,y,Bdisp_GetPoint_VRAM(x,y+8));
Bdisp_PutDisp_DD;
cur_row=7;//current line
}
//clean up screen below current line
for (i=cur_row;i<=8;i++)
{
locate(1,i);
Print(sp1);
}
locate(1,cur_row);
Print((unsigned char *)cpBuffer);
cur_row++;
return cur_row;
}
void cls()
{
int i=0;
cur_row=1;
for (i=1;i<=8;i++)
{
locate(1,i);
Print(sp1);
}
}
void pause()
{
unsigned int key;
locate(1,8);
Print((unsigned char *)" - Disp -");
do
{
GetKey(&key);
}
while(!key);
}
//file system"\\\\fls0\\" "\\\\crd0\\"
FONTCHARACTER *ToFileName(const char *f1)
{
static FONTCHARACTER f2={0};
int p=0;
while(f2=f1)p++;
return f2;
}
int CloseFile(int Handle)
{
return Bfile_CloseFile(Handle);
}
int OpenFile(char *FileName)
{
return Bfile_OpenFile(ToFileName(FileName),_OPENMODE_READ_SHARE);
}
int ReadFile( int handle, char *buf, int Size, int ReadPos)
{
return Bfile_ReadFile(handle,buf,Size,ReadPos);
}
int WriteFile(int handle ,char *buf,int size)
{
return Bfile_WriteFile(handle,buf,size);
}
int SeekFile(int handle,int pos)
{
return Bfile_SeekFile(handle,pos);
}
int FileSize(int handle){
return Bfile_GetFileSize(handle);
}
int CreateFile( char *FileName, int size)
{
return Bfile_CreateFile( ToFileName(FileName), size);
}
int DeleteFile(char *FileName)
{
return Bfile_DeleteFile(ToFileName(FileName));
}
//==========angle fuction=============================
double dfmtod(double dfm)
{
double a,b,c,temp;
while(dfm<0)dfm+=360;
while(dfm>=360)dfm-=360;
a=(int)dfm;
temp=(dfm-a)*100;
b=(int)temp;
c=(temp-b)*100;
return (a+b/60+c/60/60);
}
double dtodfm(double d)
{
double a,b,c,temp;
while(d<0)d+=360;
while(d>=360)d-=360;
a=(int)d;
temp=(d-a)*60;
b=(int)temp;
c=(temp-b)*60;
return(a+b/100+c/10000);
}
double deg(double x)// change to deg
{
return (180*x/3.1415926535);
}
double rad(double x) // change to rad
{
return (x/180*3.1415926535);
}
double pol(double x1,double y1)// get azimuth
{
double d1=sqrt(x1*x1+y1*y1);
double c1=acos(x1/d1);
if(y1<0)c1=-c1;
return c1;
}
//=====input data==============================
double input(double num){
const int len = 14;
unsigned int key;
char c={0},ds;
//sprintf(c,"%.4f", num);
if(cur_row>7)
{
{
int x,y,dot;
for(x=0;x<=127;x++)
for(y=0;y<=55;y++)
Bdisp_SetPoint_VRAM (x,y,Bdisp_GetPoint_VRAM(x,y+8));
Bdisp_PutDisp_DD;
}
cur_row=7;
}
for (i=cur_row;i<=8;i++)
{
locate(1,i);
Print(sp1);
}
goto start;
while (1){
int n=strlen(c);
GetKey(&key);
switch(key)
{
case KEY_CTRL_EXE:
if (c) {
locate(1,cur_row);
sprintf(ds,"%s ",c);
Print((unsigned char*)ds);
cur_row++;
return atof(c);
}
else{
locate(1,cur_row);
sprintf(ds,"%.4f ",num);
Print((unsigned char*)ds);
cur_row++;
return num;
}
case KEY_CTRL_AC:
c=0;
break;
case KEY_CTRL_DEL:
if(n)c=0;
break;
case KEY_CHAR_0:
case KEY_CHAR_1:
case KEY_CHAR_2:
case KEY_CHAR_3:
case KEY_CHAR_4:
case KEY_CHAR_5:
case KEY_CHAR_6:
case KEY_CHAR_7:
case KEY_CHAR_8:
case KEY_CHAR_9:
if(n<len){
c=key;
c=0;
}
break;
case KEY_CHAR_DP:
if(!strchr(c, '.') && n<len){
c='.';
c = 0;
}
break;
case KEY_CHAR_MINUS:
case KEY_CHAR_PMINUS:
if (c == '-'){
char buf={0};
strcpy(buf,c);
strcpy(c,buf+1);
}
else if(n<len){
char buf={0};
strcpy(buf,c);
sprintf(c,"-%s",buf);
}
break;
}
start:
locate(1,cur_row);
sprintf(ds,"%s_ ",c);
Print((unsigned char*)ds);
}
}
int area_clear(int left, int top, int right, int bottom, int sel)
{
DISPBOX box;
box.left=left;
box.top=top;
box.right=right;
box.bottom=bottom;
if (sel)
{
//drawing dox
Bdisp_DrawLineVRAM (left , top , right, top);
Bdisp_DrawLineVRAM (left , bottom, right, bottom);
Bdisp_DrawLineVRAM (left , top , left , bottom);
Bdisp_DrawLineVRAM (right, top , right, bottom);
}
//clear area
else Bdisp_AreaClr_DDVRAM (&box);
}
//drawing menu
int menu (char *buf){ //tab split buf;
int rows=n,i=0,j=0,index=0;
unsigned key=0;
char s={0};
int n=sscanf(buf,"%s%s%s%s%s%s%s%s%s%s",s,s,s,s,s,s,s,s,s,s);
if (n<3|| n>10)return 0;
for(i=0;i<n;i++)s=0;
Bdisp_PutDisp_DD();
SaveDisp( SAVEDISP_PAGE1);
area_clear(4,1,125,63,0);
area_clear(4,1,124,63,2);
Bdisp_DrawLineVRAM (125, 2, 125, 63);
Bdisp_DrawLineVRAM (4, 12, 124, 12);
PrintXY(7,3,(unsigned char*)s,0);
index=1;
while(1)
{
if(index>=n)index=1;
if(index<1)index=n-1;
j=index>=7?7:1;
for(i=j;i<=j+5;i++)
{
int x,y,sel;
char buf;
x=7;
y=(i-j)*8+14;
sel=(index!=i?0:1);
if (i<n)sprintf(buf,"%-19s",s);
else sprintf(buf,"%-19s"," ");
PrintXY(x,y,(unsigned char *)buf,sel);
}
GetKey(&key);
switch(key){
case KEY_CTRL_UP:
case KEY_CTRL_LEFT:
index--;
break;
case KEY_CTRL_DOWN:
case KEY_CTRL_RIGHT:
index++;
break;
case KEY_CTRL_EXE:
case KEY_CTRL_F1:
RestoreDisp (SAVEDISP_PAGE1);
Bdisp_PutDisp_DD();
return(index);
}
}
}
double jf_cos(double A1,double B1,double C1,double X2){
double t1, t2, S2=0.0, S1, eps=0.00001;
double ep=100;
if (A1)
{
double h=X2;
double temp1=C1;
double temp2=A1*X2*X2+B1*X2+C1;
{
S1=t1=h*(cosf(temp1)+cosf(temp2))/2.0;
while (ep>=eps)
{
double p=0;
int n=1, k=0;
for (k=0;k<n;k++)
{
int x=(k+0.5)*h;
temp1=A1*x*x+B1*x+C1;
p+=cosf(temp1);
}
t2=(t1+h*p)/2;
S2=(4.0*t2-t1)/3;
ep=fabs(S2-S1);
t1=t2; S1=S2;
n=n+n; h=h/2;
}
}
}
else if (B1) S2=(sinf(B1*X2+C1)-sinf(C1))/B1;
else S2=cosf(C1)*(X2);
return S2;
}
double jf_sin(double A1,double B1,double C1,double X2)
{
return jf_cos(A1,B1,C1-1.570796,X2);
}
/*****************************************************************/
int AddIn_main(int isAppli, unsigned short OptionNum)
{
double x1=0,y1=0,x2=0,y2=0;
double ret=0;
char buf={0};
//==========================================
cls();
printf("X1=%.4f",x1);
x1=input(x1);
printf("Y1=%.4f",y1);
y1=input(y1);
while(1)
{
cls();
printf("X2=%.4f",x2);
x2=input(x2);
printf("Y2=%.4f",y2);
y2=input(y2);
ret=pol(x2-x1,y2-y1);
printf("Angle=%.4f",ret);
pause();
sprintf(buf,"=======Result==========\tX1=%.4f\tY1=%.4f\tX2=%.4f\tY2=%.4f\tAngle=%.4f\t===================Exit\tHelp\tAbout",x1,y1,x2,y2,ret);
menu(buf);
}
return 1;
}
//****************************************************************************
//************** ****************
//************** Notice! ****************
//************** ****************
//**************Please do not change the following source.****************
//************** ****************
//****************************************************************************
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
//****************************************************************************
//InitializeSystem
//
//param : isAppli : 1 = Application / 0 = eActivity
// OptionNum : Option Number (only eActivity)
//
//retval: 1 = No error / 0 = Error
//
//****************************************************************************
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section
主要是要用c语言写一些常用测量程序,9860的c语言缺少基本的输入语句以及菜单命令 值得我学习,我也很喜欢代码。因为我觉得那是人类灵魂之精华。 建议直接上传代码文件
主要包括一个输入数字的input函数,一个显示字符串的printf函数,一个菜单函数,一个计算cos(a*x*x+b*x+c)这种形式的积分计算函数,用于线元法计算时会用到,cls(),pause()函数,求方位角函数等,以后写程序时可以作为代码模板使用
页:
[1]