- 积分
- 821
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-10-25
- 最后登录
- 1970-1-1
|
发表于 2019-12-4 08:05:17
|
显示全部楼层
- /////////////////////////////////////////////////////////////
- // //
- // 读取全部雷达基数据最终形式,并实用 //
- // //
- /////////////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- //#define RGates 460 //S BAND 反射率距离库数
- //#define VGates 920 //S BAND 速度距离库数
- //#define WGates 920 //S BAND 谱宽距离库数
- void pause()
- { char c;
- printf("\nPlease enter any key; then go on...\n");
- c=getchar();
- }
- int main(void)
- {
- //雷达信息头
- //第一段定义 传输信息类型说明,共14类
- char Unused1[14]; //1~14未用 文件数据变量的定义
- // char DigitalRadarData; //1数字化雷达数据(综合了反射率,径向风速或速度谱宽)
- // char RadarDataCollectionStatus //2RDA雷达数据采集 状态数据
- // char DisplayOrMaintenanceData //3显示/维护数据
- // char ConsoleSignal //4控制台信号 RDA—RPG雷达产品生成
- // char MaintenanceData //5维护记录数据
- // char ControlInstruction //6RDA控制指令
- // char VolumeScanMode //7体扫模式
- // char ErrorCorrection //8纠错
- // char DataRequest //9数据请求
- // char ConsoleInformation //10控制台信息 RPG—RDA
- // char LoopTestRDA //11环路测试 RDA—RPG
- // char LoopTestRPG //12环路测试 RPG-RDA
- // char ErrorMessageFilter //13错误信息过滤分流 RPG-RDA
- // char EditedErrorMessageFilter //14编辑后的错误信息分流 RPG-RDA
- //第二段定义 报头数据项名称及内容描述
- // unsigned short int MessageSize; //12~13数据报长度,表示记录长度,双字节单位表示
- // char ChannelID; //14 RDA冗余通道,RDA信号传输通道号(=0,1,2),对冗余通道配置
- unsigned short int MessageType; //15~16报文类型 记录数据类型,具体说明见6.1
- // char Unused2[12]; //17~28未用
- short int IDSequence; //17~18报文顺序号 记录顺序号,0~0x7FFF之间循环表示
- unsigned short int MessageGenerationDate; //19~20 记录产生日期,以1/1/1970以来
- // 的Julian日期表示
- unsigned long int MessageGenerationTime; //21~24 记录产生的GMT时间(毫秒)
- char Unused2[4];//25~28未用
- // short int MessageSegmentsNumber; //25~26报文段数 记录传输分段段数
- // short int MessageSegmentNumber; //27~28报文段号 记录传输段号
-
- //第三段定义 第一类报文
- unsigned long int RadialCollectionTime; //29~32 Zulu参考时间,
- // 径向资料采集的GMT时间(毫秒)
- unsigned short int RadialCollectionDate; //33~34 修正的Julian日期,
- // 径向资料采集日期,以1/1/1970以来的Julian日期表示
- unsigned short int UnambiguousRange; //35~36 无模糊区,不模糊距离,单位:0.1Km
- unsigned short int AzimuthAngle; //37~38 方位角,实际值=(value>>3)*0.043945(度)
- unsigned short int AzimuthNumber; //39~40 方位值,当前仰角内径向数据序号
- unsigned short int RadialStatus; //41~42 径向数据状态,径向位置参数(=0,1,2,3,4)
- short int ElevationAngle;//43~44 仰角, 实际值
- //第四段定义
- short int ElevationNumber; //45~46 仰角编号,体积扫描仰角数目
- short int FirstGateRangeOfRef;//47~48 反射率数据第一个距离库的实际距离,
- // 第一个强度库的距离(米)
- short int FirstGateRangeOfDoppler;//49~50 多普勒数据第一个距离库的实际距离,
- // 第一个速度\谱宽库的距离(米)
- short int ReflectivityGateSize; //51~52 警戒距离,反射率数据距离库长\强度库长(米)
- short int DopplerGateSize; //53~54 多普勒数据距离库长,速度\谱宽库长(米)
- short int ReflectivityGates;//55~56 反射率距离\强度库数
- short int DopplerGates;//57~58 多普勒距离库数,速度\谱宽库数
- short int SectorNumber;//59~60 cut内的扇区号
- float CalibrationConstant;//61~64 系统增益标校常数(dB)
- unsigned short int RefPointer;//65~66 反射率数据指针(偏离雷达数据头的字节数),
- // 表示第一个反射率数据的位置,从雷达数据头到强度数据开始的字节数
- unsigned short int VelPointer;//67~68 速度数据指针(偏离雷达数据头的字节数),
- // 表示第一个速度数据的位置,从雷达数据头到速度数据开始的字节数
- unsigned short int SWPointer;//69~70 谱宽数据指针(偏离雷达数据头的字节数),
- // 表示第一个谱宽数据的位置,从雷达数据头到谱宽数据开始的字节数
- short int VelResolution;//71~72 多普勒速度分辨率:2=0.5m/s,4=1.0m/s
- short int VCP;//73~74体扫VCP方式(11、21、31、32)
- char Unused3[8];//75~82 未用。
- unsigned short int RefPlaybackPointer;//83~84 用于回放的反射率数据指针,同33,
- // 强度数据指针(用于RDA回放)
- unsigned short int VelPlaybackPointer;//85~86 用于回放的速度数据指针,同34,
- // 速度数据指针(用于RDA回放)
- unsigned short int SWPlaybackPointer;//87~88 用于回放的谱宽数据指针,同35,
- // 谱宽数据指针(用于RDA回放)
- short int NyquistVelocity;//89~90 Nyquist速率(0.01m/s)不模糊速度
- char Unused4[38];//91~128 未用。
- // short int AAF;//91~92 Atmospheric Attenuation Factor(0.001 dB/Km)大气衰减因子
- // short int TOVER;//93~94没有距离折叠两个回波功率之间最小差值(0.1瓦)
-
- unsigned char BaseData[2300]; //129~2428基数据部分2300字节
- // char *pData;
- char Unused5[4]; //2429~2432 说明记录中三个基本数据是否存在,或者某个数据的库数是否有损失的情况。
- // 出现这些情况时,仍然按2432个字节传输,有最后四个字节说明。
- double Ldata[2300]; //******yuanlai char******
- float UnRange;
- float AzAngle;
- float ElAngle;
- float NyVelocity;
-
- int i,k;
- /* FILE *fnamelist
- char filename1[80],filename2[80],filename3[80];
- int fi,f2,f3,f4;
- for(f1=0,f1<=9,f1++)
- {
- for(f2=0,f2<=9,f2++)
- {
- for(f3=0,f3<=9,f3++)
- {
- for(f4=0,f4<=9,f4++)
- {
- filename1=
- // int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,sum;
- */
- FILE *fp,*fpout,*fpnumber;
-
- if((fp=fopen("2009060312.32A","rb"))==NULL)
- {
- printf("%s\n","2009060312.32A不存在,请确认其位置。");
- exit(1);
- }
- if((fpout=fopen("2009060312.32A.out","w"))==NULL)
- {
- printf("%s\n","2009060312.32A.out不存在,请确认其位置。");
- exit(2);
- }
- /* if((fpgates=fopen("E:\\data\\2009060315.10ADopplerGates.txt","w"))==NULL)
- {
- printf("%s\n","E:\\readdata\\DopplerGates.txt不存在,请确认其位置。");
- exit(3);
- }
- */
- if((fpnumber=fopen("2009060312.32ADopplerGatesNumber.txt","w"))==NULL)
- {
- printf("%s\n","E:\\readdata\\DopplerGates.txt不存在,请确认其位置。");
- exit(4);
- }
-
- //程序段的开始部分
- k=1;
- // while(cha=getc(fp)!=EOF)
- // for(k=1;k<5885&&RadialStatus!=4;) //k++) 5885
- do
- {
- // fread("%s%d%s",ch,&MessageSize,ChannelID);
- // if(cha=getc(fp)==EOF&&fp>12l){printf("k=%d\n",k);break;}
- // printf("This is the %d number\n",k);
- fprintf(fpout,"\nThis is the %d number\n",k);
-
- for(i=1;i<=14;i++)
- fread( &Unused1[i-1],sizeof(char),1,fp);
- // printf("%u ",ch[i-1]);
- // printf("\n");
- //原来有的 fread(&MessageSize,sizeof(unsigned short int),1,fp);//12~13 表示记录长度,双字节单位表示
- // printf("This is massageSize:%u\n",MessageSize);
- // fprintf(fpout,"This is massageSize:\n%u\n",MessageSize);
- // pause();
-
- //原来有的 fread(&ChannelID,sizeof(char),1,fp);//14 信号传输通道号(=0,1,2)
- // printf("This is ChannelID:%d\n",ChannelID);
-
- fread( &MessageType,sizeof(unsigned short int),1,fp);//15~16 记录数据类型,具体说明见6.1
- // printf("MessageType:%u\n",MessageType);
-
-
- // for(i=1;i<=12;i++)
- // fread( &Unused2[i-1],sizeof(char),1,fp);//17~28 未用。
- fread(&IDSequence,sizeof(short int),1,fp);//17~18 记录顺序号,0~0x7FFF之间循环表示
- // printf("IDSequence:%X\n",IDSequence);
-
- fread(&MessageGenerationDate,sizeof(unsigned short int),1,fp);
- //19~20 记录产生日期,以1/1/1970以来的 Julian日期表示
- // fprintf(fpout,"This is MessageGenerationDate:\n%u\n",MessageGenerationDate);
- // printf("MessageGenerationDate:%u\n",MessageGenerationDate);
-
-
- fread(&MessageGenerationTime,sizeof(unsigned long int),1,fp);//21~24 记录产生的GMT时间(毫秒)
- // fprintf(fpout,"This is MessageGenerationTime:\n%u\n",MessageGenerationTime);
- // printf("MessageGenerationTime:%u\n",MessageGenerationTime);
- for(i=1;i<=4;i++)
- fread( &Unused2[i-1],sizeof(char),1,fp);//25~28 未用。
- // fread(&MessageSegmentsNumber, sizeof(short int),1,fp);//25~26 记录传输分段段数
- // printf("MessageSegmentsNumber:%u\n",MessageSegmentsNumber);
-
- // fread(&MessageSegmentNumber, sizeof(short int),1,fp); //27~28 记录传输段号
- // printf("MessageGenerationTime:%u\n",MessageSegmentNumber);
- // pause();
- fread( &RadialCollectionTime, sizeof(unsigned long int),1,fp); //29~32 径向资料采集的GMT时间(毫秒)
- fprintf(fpout,"This is RadialCollectionTime:\n%u\n",RadialCollectionTime);
- // printf("RadialCollectionTime:%u\n",RadialCollectionTime);
-
-
- fread( &RadialCollectionDate, sizeof(unsigned short int),1,fp);
- //33~34 径向资料采集日期,以1/1/1970以来的Julian日期表示
- fprintf(fpout,"This is RadialCollectionDate:\n%u\n",RadialCollectionDate);
- // printf("RadialCollectionDate:%u\n",RadialCollectionDate);
-
- fread( &UnambiguousRange, sizeof(unsigned short int),1,fp);//35~36 不模糊距离,单位:0.1Km
- UnRange=(float)(UnambiguousRange*0.1);
- fprintf(fpout,"This is UnambiguousRange:\n%f\n",UnRange);
- // printf("UnambiguousRange:%u\n",UnambiguousRange);
-
- fread( &AzimuthAngle, sizeof(unsigned short int),1,fp);//37~38 方位角,实际值=(value>>3)*0.043945(度)
- // AAngle=(short int)((AzimuthAngle>>3)*0.043945/360*366+0.5);//**********重大不同*************
- // AzAngle=(float)((AzimuthAngle/8.)*(180./4096.));
- AzAngle=(float)((AzimuthAngle>>3)*(180./4096.));
- if(AzAngle<0) AzAngle=0.;
- if(AzAngle>=360) AzAngle=360.;
- // printf("%d",AzimuthAngle);
- // pause();
- fprintf(fpout,"This is AzimuthAngle:\n%f\n",AzAngle);
- // printf("AzimuthAngle:%u\n",AzimuthAngle);
-
-
- fread( &AzimuthNumber, sizeof(unsigned short int),1,fp);//39~40 本层仰角扫描的径向数
- fprintf(fpout,"This is AzimuthNumber:\n%u\n",AzimuthNumber);
- // printf("AzimuthNumber:%u\n",AzimuthNumber);
-
-
- fread( &RadialStatus, sizeof(unsigned short int),1,fp);//41~42 径向位置参数(=0,1,2,3,4)
- fprintf(fpout,"This is RadialStatus:\n%u\n",RadialStatus);
- // printf("RadialStatus:%d\n",RadialStatus);
-
- fread( &ElevationAngle, sizeof(short int),1,fp);
- ElAngle=(float)((ElevationAngle>>3)*(180./4096.));
- // pause();
- fprintf(fpout,"This is ElevationAngle:\n%f\n",ElAngle); //43~44 仰角, 实际值
- // printf("ElevationAngle:%d\n",ElevationAngle);
-
- fread( &ElevationNumber,sizeof(short int),1,fp); //45~46 体积扫描仰角数 编号
- fprintf(fpout,"This is ElevationNumber:\n%d\n",ElevationNumber);
- // printf("ElevationNumber:%d\n",ElevationNumber);
- fread( &FirstGateRangeOfRef,sizeof(short int),1,fp);//47~48第一个强度库的距离(米)
- fprintf(fpout,"This is FirstGateRangeOfRef:\n%d\n",FirstGateRangeOfRef);
- // printf("FirstGateRangeOfRef:%d\n",FirstGateRangeOfRef);
- fread( &FirstGateRangeOfDoppler,sizeof(short int),1,fp);//49~50 第一个速度\谱宽库的距离(米)
- fprintf(fpout,"This is FirstGateRangeOfDoppler:\n%d\n",FirstGateRangeOfDoppler);
- // printf("FirstGateRangeOfDoppler:%d\n",FirstGateRangeOfDoppler);
-
- fread( &ReflectivityGateSize,sizeof(short int),1,fp); //51~52 强度库长(米)
- fprintf(fpout,"This is ReflectivityGateSize:\n%d\n",ReflectivityGateSize);
- // printf("ReflectivityGateSize:%d\n",ReflectivityGateSize);
- fread( &DopplerGateSize,sizeof(short int),1,fp); //53~54速度\谱宽库长(米)
- fprintf(fpout,"This is DopplerGateSize:\n%d\n",DopplerGateSize);
- // printf("DopplerGateSize:%d\n",DopplerGateSize);
-
- fread( &ReflectivityGates,sizeof(short int),1,fp);//55~56 强度库数
- fprintf(fpout,"This is ReflectivityGates:\n%d\n",ReflectivityGates);
- // printf("ReflectivityGates:%d\n",ReflectivityGates);
- fread( &DopplerGates,sizeof(short int),1,fp);//57~58 速度\谱宽库数
- fprintf(fpout,"This is DopplerGates:\n%d\n",DopplerGates);
- // printf("DopplerGates:%d\n",DopplerGates);
- // if(0<DopplerGates<=320) a=a+1;
- /* if(320<DopplerGates<=420) b=b+1;
- else if(420<DopplerGates<=520) c=c+1;
- else if(520<DopplerGates<=620) d=d+1;
- else if(620<DopplerGates<=720) e=e+1;
- else if(720<DopplerGates<=820) f=f+1;
- else if(820<DopplerGates<=920) g=g+1;
- else h=h+1;
- sum=a+b+c+d+e+f+g;
- fprintf(fpgates,"a=%d\nb=%d\nc=%d\nd=%d\ne=%d\nf=%d\ng=%d\nh=%d\nsum=%d\n",a,b,c,d,e,f,g,h,sum);
-
- */
- fread( &SectorNumber,sizeof(short int),1,fp);//59~60 cut内的扇区数
- fprintf(fpout,"This is SectorNumber:\n%d\n",SectorNumber);
- fread( &CalibrationConstant,sizeof(float),1,fp);//61~64 系统增益标校常数(dB)
- fprintf(fpout,"This is CalibrationConstant:\n%f\n",CalibrationConstant);
- fread( &RefPointer,sizeof(unsigned short int),1,fp);//65~66从雷达数据头到强度数据开始的字节数
- fprintf(fpout,"This is RefPointer:\n%u\n",RefPointer);
- fread( &VelPointer,sizeof(unsigned short int),1,fp);//67~68从雷达数据头到速度数据开始的字节数
- fprintf(fpout,"This is VelPointer:\n%u\n",VelPointer);
- fread( &SWPointer,sizeof(unsigned short int),1,fp);//69~70从雷达数据头到谱宽数据开始的字节数
- fprintf(fpout,"This is SWPointer:\n%u\n",SWPointer);
- fread( &VelResolution,sizeof(short int),1,fp);//71~72 速度分辨率:2=0.5m/s,4=1.0m/s
- fprintf(fpout,"This is VelResolution:\n%d\n",VelResolution);
- // printf("VelResolution:%d\n",VelResolution);
-
- fread( &VCP,sizeof(short int),1,fp);//73~74体扫VCP方式(11、21、31、32)
- fprintf(fpout,"This is VCP:\n%d\n",VCP);
- // printf("VCP:%d\n",VCP);
- for(i=1;i<=8;i++)
- fread( &Unused3[i-1],sizeof(char),1,fp);//75~82 未用。
- // for(i=1;i<=4;i++)
- // printf("Unused[%1d]:%d\n",i-1,Unused[i-1]);
- fread( &RefPlaybackPointer,sizeof(unsigned short int),1,fp);//83~84强度数据指针(用于RDA回放)
- // fprintf(fpout,"This is RefPlaybackPointer:\n%u\n",RefPlaybackPointer);
- // printf("RefPlaybackPointer:%u\n",RefPlaybackPointer);
- fread( &VelPlaybackPointer,sizeof(unsigned short int),1,fp);//85~86 速度数据指针(用于RDA回放)
- // fprintf(fpout,"This is VelPlaybackPointer:\n%u\n",VelPlaybackPointer);
- // printf("VelPlaybackPointer:%u\n",VelPlaybackPointer);
- fread( &SWPlaybackPointer,sizeof(unsigned short int),1,fp);//87~88 谱宽数据指针(用于RDA回放)
- // fprintf(fpout,"This is SWPlaybackPointer:\n%u\n",SWPlaybackPointer);
- // printf("SWPlaybackPointer:%u\n",SWPlaybackPointer);
- fread( &NyquistVelocity,sizeof(short int),1,fp);//89~90 Nyquist不模糊速率(0.01m/s)
- NyVelocity=(float)(NyquistVelocity*0.01);
- fprintf(fpout,"This is NyquistVelocity:\n%f\n",NyVelocity);
- // printf("NyquistVelocity:%d\n",NyquistVelocity);
- for(i=1;i<=38;i++)
- fread( &Unused4[i-1],sizeof(char),1,fp);//91~128 未用。
- // fread( &AAF,sizeof(short int),1,fp);//91~92 Atmospheric Attenuation Factor(0.001 dB/Km)
- // printf("AAF:%d\n",AAF);
- // fread( &TOVER,sizeof(short int),1,fp);//93~94没有距离折叠两个回波功率之间最小差值(0.1瓦)
- // printf("TOVER:%d\n",TOVER);
-
- fprintf(fpnumber,"%d %d %d\n",AzimuthNumber,ElevationNumber,DopplerGates);
-
- for(i=1;i<=2300;i++)
- fread( &BaseData[i-1],sizeof(unsigned char),1,fp);
- // fprintf(fpout,"%u\t",BaseData[i-1]);
- // for(i=1;i<=2300;i++)
- // {
- // printf("%d ",Mydata[i-1]);
- // if(i%20==0)
- // fprintf(fpout,"\n");
- if(ReflectivityGates!=0)
- {
- fprintf(fpout,"This is the %d ReflectivityData:\n",k);
- for(i=RefPointer-99;i<=RefPointer-100+ReflectivityGates;i++)
- {
- if(BaseData[i-1]==(char)0)
- {
- // BaseData[i-1]='0'; //无回波
- Ldata[i-1]=-999.0;
- }
- else if(BaseData[i-1]==(char)1) //*******(char *)1 **********
- {
- // BaseData[i-1]='1'; //回波信号低于信噪比,数据是模糊的
- Ldata[i-1]=999.0;
- }
- else
- {
-
- Ldata[i-1]=((BaseData[i-1]-2.0)/2.-32.0);
- }
- fprintf(fpout,"%10.4f\t",Ldata[i-1]);
- }
- }
- else
- fprintf(fpout,"This is the %d ReflectivityData:\n",k);
- if(DopplerGates!=0)
- {
- fprintf(fpout,"\nThis is the %d DopplerVelocityData:\n",k);
-
- for(i=VelPointer-99;i<=VelPointer-100+DopplerGates;i++)
- {
-
- if(BaseData[i-1]==(char)0) //*******(char *)0 **********
- {
- // BaseData[i-1]='0'; //无回波
- Ldata[i-1]=-999.0;
- }
- else if(BaseData[i-1]==(char)1) //*******(char *)1 **********
- {
- // BaseData[i-1]='1'; //回波信号低于信噪比,数据是模糊的
- Ldata[i-1]=999.0;
- }
- else
- {
- if(VelResolution==2) //0.5m/s
- Ldata[i-1]=((BaseData[i-1]-2.0)/2.0-63.5);
- else if(VelResolution==4) //1.0m/s
- Ldata[i-1]=((BaseData[i-1]-2.0)-127.0);
- // else
- // Ldata[i-1]=((Mydata[i-1]-2)/2.0-63.5);
- }
- fprintf(fpout,"%10.4f\t",Ldata[i-1]);
- }
- }
- else
- fprintf(fpout,"\nThis is the %d DopplerVelocityData:\n",k);
- if(DopplerGates!=0)
- {
- fprintf(fpout,"\nThis is the %d SWData:\n",k);
-
- for(i=SWPointer-99;i<=SWPointer-100+DopplerGates;i++)
- {
-
- if(BaseData[i-1]==(char)0) //*******(char *)0 **********
- {
- // BaseData[i-1]='0'; //无回波
- Ldata[i-1]=-999.0;
- }
- else if(BaseData[i-1]==(char)1) //*******(char *)1 **********
- {
- // BaseData[i-1]='1'; //回波信号低于信噪比,数据是模糊的
- Ldata[i-1]=999.0;
- }
- else
- {
- Ldata[i-1]=((BaseData[i-1]-2.0)/2.0-63.5);
- }
- fprintf(fpout,"%10.4f\t",Ldata[i-1]);
- }
- }
- else
- fprintf(fpout,"\nThis is the %d SWData:\n",k);
- // printf("\n输出保留位数::");
- // pause();
- // }
-
- for(i=1;i<=4;i++)
- {
- fread( &Unused5[i-1],sizeof(char),1,fp);
- // fprintf(fpout,"%c",Unused5[i-1]);
- }
- k++;
-
-
- }
- //while (k<5885&&RadialStatus!=4);
- while (RadialStatus!=4);
-
- // while (k<2000);
- }
复制代码 |
|