⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readeosdlg.cpp

📁 能够读取卫星数据ldf文件格式
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//	ww=4183;hh=1967;
	ww=4143;hh=1927;
//	xll=78.295;
//	yll=36.50;
	xll=78.395;
	yll=36.490;
	xrr=99.210;
	yrr=26.665;
//	m_PrCtl.SetRange(0,100);
//	m_PrCtl.SetPos(0);

}
//*******************************************************************************
BOOL CReadeosDlg::readbatch(LPCTSTR in1)

{
FILE *fh;
   char bufer[90];
   CString ss;
   ss=in1;
  if(ss.IsEmpty( )!=0)
  {
	AfxMessageBox("请输入文件名!",MB_OK,0);
	return 0;
   }
 if( (fh = fopen( in1 ,"rt" )) ==NULL)
   {
    AfxMessageBox("不能打开输入文件。",MB_OK,0);
	return 0;
   }
  while( !feof( fh ) )
   {
	  count++;
 fscanf(fh,"%s",bufer);
 sprintf(bndtypes[count-1].Band_Name,"%s",bufer);
  }
 return 1;
}
//*******************************************************************************
BOOL CReadeosDlg::readtxt(int w,int h,char *in1,char *out)

{
CRect rect;
FILE *fh,*fo;
   DWORD dwI;
   int wd,hg;
   char bufer[90];
   float32 *ch=NULL;
   unsigned long dwBytes;
   int xpos,ypos;
 if( (fh = fopen( in1 ,"rb" )) ==NULL)
   {
    AfxMessageBox("不能打开输入文件。",MB_OK,0);
	return 0;
   }
	 if( (fo = fopen( out,"wb")) ==NULL )
   {
    AfxMessageBox("不能创建输出文件。",MB_OK,0);
	return 0;
   }
   	
	wd=w+1;
	hg=h+1;
	fscanf(fh,"%s",bufer);
	  dwBytes=wd*hg*4;
	 if(ch!=NULL)GlobalFreePtr(ch);
	 ch=(float32 *)GlobalAllocPtr( GPTR,dwBytes); 
     xpos=int((xll-xllcorner)/pxsize);
	 ypos=int((yllcorner-yll)/pysize);
	xpos=xpos+1;
	ypos=ypos+1;
	ww=ww+xpos;
	hh=hh+ypos;
	rect.SetRect( xpos, ypos, ww, hh);
	 while( !feof( fh ) )
   {
      // Attempt to read in 10 bytes: 
	for(int i=0;i<hg;i++)
	{

//	m_PrCtl.SetPos(i*200/hg);
	for(int j=0;j<wd;j++)
	{
	 dwI=i *(wd) +j;
     fscanf(fh,"%f",&ch[dwI]);
  if(rect.PtInRect(CPoint(j,i))!=0&&ch[dwI] <10.0)
	{
		
	//	if(ch1<0)ch[dwI]=0;
		fwrite(&ch[dwI],sizeof(float32), 1,fo);
	}

//	}
	}
 if( ferror( fh ) )    
	 {
       AfxMessageBox("数据读错误。",MB_OK,0);
	   return 0;
      }
	}

	}
	 return 1;
 GlobalFreePtr(ch);
 fclose( fo );
 fclose( fh );
}
//*******************************************************************************

//#include "ProgressBar.h"
 BOOL CReadeosDlg::CreateProgress(LPCTSTR strMessage, int nSize /*=100*/, 
						  int MaxValue /*=100*/, BOOL bSmooth /*=FALSE*/)
 {
	BOOL bSuccess = FALSE;
	DWORD dwStyle = WS_CHILD|WS_VISIBLE;
   #ifdef PBS_SMOOTH	 
	if (bSmooth)
		dwStyle |= PBS_SMOOTH;
    #endif
	 	CRect		rc ;
	this->GetDlgItem (IDC_DUMY)->GetWindowRect (&rc) ;
	this->GetDlgItem (IDC_DUMY)->DestroyWindow () ;
	this->ScreenToClient (&rc) ;
	bSuccess = m_wndProgress.Create (dwStyle,  rc, this, 1) ;
	ASSERT(bSuccess);
	if (!bSuccess)
		return FALSE;
	m_wndProgress.SetRange (0, MaxValue) ;
	m_wndProgress.SetStep(1);
	}

//*******************************************************************************
BOOL CReadeosDlg::readbna(int w,int h,char *in1,char *out)

{
    int fh1;
	 FILE *fh2;
	 int xpos,ypos;
	CRect rect;
	 float32 *ch1=NULL;
       unsigned long dwBytes,dw;
      m_wndProgress.SetPos(0);
     m_wndProgress.SetRange(0,100);
    m_wndProgress.Invalidate( TRUE );

    if( (fh1 = _open(in1,_O_BINARY )) == -1 )
   {
        AfxMessageBox("不能打开输入文件。",MB_OK,0);
	return 0;
   }
	if( (fh2 = fopen( out,"ab")) ==NULL )
   {
    AfxMessageBox("不能创建输出文件。",MB_OK,0);
	return 0;
   }
    xpos=int(float(xll-xllcorner)/pxsize+0.5);
	ypos=int(float(yllcorner-yll)/pysize+0.5);
	ww=ww+xpos;
	hh=hh+ypos;
    dwBytes=h*(w*4);
	rect.SetRect( xpos, ypos, ww, hh);
	 if(ch1!=NULL)GlobalFreePtr(ch1);
	 ch1=(float32 *)GlobalAllocPtr( GPTR,dwBytes);
//	 fread(ch1,sizeof(float32),w*h,fh1);//read NDSI
	  _read( fh1,ch1,dwBytes);//read NDSI
	 DWORD dwI;
     for(int i=0;i<h;i++){
     for(int j=0;j<w;j++){
     dwI=i *(w) +j;
	 if(rect.PtInRect(CPoint(j,i))!=0&&ch1[dwI] <10.0)
	{
	 fwrite(&ch1[dwI],sizeof(float), 1,fh2);
	 }
	 }
     CString		sNum ;
	sNum.Format (_T("%i%%"),  i * 100 /h) ;
    m_wndProgress.SetPos(i * 100 / h);
	m_wndProgress.SetWindowText(sNum);
 }
	 m_wndProgress.SetPos(100);
   _close(fh1);
    fclose(fh2);
GlobalFreePtr(ch1);
     return 1;
}

//*************************************************************************
BOOL CReadeosDlg::CalNdvi(int w,int h,char *in1,char *out)
	 {
    	 FILE *fh2;
		 int fh1;
		uint16 *ch1=NULL,*ch2=NULL,*ch4=NULL,*ch6=NULL;
		float ndvi,ndsi;
		BYTE *ch3=NULL;
       unsigned long dwBytes;
    if( (fh1 = _open(in1,_O_BINARY )) == -1 )
   {
       AfxMessageBox("不能打开输入文件。",MB_OK,0);
    	return 0;
   }
	 if( (fh2 = fopen( out,"wb")) ==NULL )
   {
    AfxMessageBox("不能创建输出文件。",MB_OK,0);
	return 0;
   }
	 LocalFileHeader lfh;
	 _read( fh1,&lfh,sizeof(LocalFileHeader));//read ch1

	w=lfh.wWidth;
	h=lfh.wHeight;

	m_wndProgress.SetPos(0);
    m_wndProgress.SetRange(0,100);
    m_wndProgress.Invalidate( TRUE );
   	 dwBytes=	sizeof(uint16 ) * h*(w) ;
	 if(ch1!=NULL)GlobalFreePtr(ch1);
	 ch1=(uint16 *)GlobalAllocPtr( GPTR,dwBytes); 
	 if(ch2!=NULL)GlobalFreePtr(ch2);
	 ch2=(uint16 *)GlobalAllocPtr( GPTR,dwBytes);
	 if(ch4!=NULL)GlobalFreePtr(ch4);
	 ch4=(uint16 *)GlobalAllocPtr( GPTR,dwBytes); 
	 if(ch6!=NULL)GlobalFreePtr(ch6);
	 ch6=(uint16 *)GlobalAllocPtr( GPTR,dwBytes);
     ch3=new BYTE[w*h];
	 _read( fh1,ch1, dwBytes);//read ch1
	 _read( fh1,ch2, dwBytes);//read ch2
	 _read( fh1,ch4, dwBytes);//read ch4
	 _read( fh1,ch6, dwBytes);//read ch6     
	 DWORD dwI;
	 float fgd,swl,gwzzl;
	 fgd=swl=gwzzl=0.0;
     for(int i=0;i<h;i++){
     for(int j=0;j<w;j++){

      dwI=i *(w) +j;
	 ndvi=float(double(ch2[dwI]-ch1[dwI])/double(ch2[dwI]+ch1[dwI]));
	 ndsi=float(ch4[dwI]-ch6[dwI])/float(ch4[dwI]+ch6[dwI]);

	  fgd=float(205.03*ndvi-18.665);//计算覆盖度
	  swl=float(203.46*exp((double)(3.1755*ndvi)));//计算生物量
	  gwzzl=float(114.5*exp((double)(3.85*ndvi)));//计算干物质总量



   //   ch3[dwI]=BytScl( ndvi, -1,1 ) ; //10-255 sacle
	 if((ndsi>0.40&&ch2[dwI]>0.11&&ch4[dwI]>0.10&&ch6[dwI]<=0.20&&ch1[dwI]>0.20&&ndvi<0.10)\
		  ||(ndsi>0.00&&ndsi<0.4&&ndvi<=0.1))ch3[dwI]=205;//set snow

	 if((ch2[dwI]<0.11&&ndsi>0.40)||\
		 (ch1[dwI]<0.15&&ch2[dwI]<0.12&&ndsi>=0.000))ch3[dwI]=1;//1set water


	  if((ndsi>0.00&&ch6[dwI]>0.20&&ch2[dwI]>0.20)||(ndsi>0.40&&ch6[dwI]>0.10))ch3[dwI]=255;//set cloud
  //   if((ch1[dwI]>0.4&&ch2[dwI]<0.11)||(ch1[dwI]>0.000&&ch4[dwI]<=0.02))ch3[dwI]=1;//set water
//	 else if(ch1[dwI]>0.000&&ch1[dwI]<0.4&&ch5[dwI]>0.20)ch3[dwI]=3;//set cloud
//	 	 else if(ch1[dwI]>=0.40&&ch2[dwI]>=0.10&&ch4[dwI]>=0.11)ch3[dwI]=5;//set snow

	//	 if(ch2[dwI]<0.100&&ch4[dwI]<0.100&&(ch4[dwI]-ch2[dwI])>0.00)ch3[dwI]=1;//set water
	  if(ch2[dwI]==-999.0)ch3[dwI]=0;
     else if (ndsi<0.000)ch3[dwI]=ndvi*100+110;
//	 if(ch3[dwI]==205&&ch6[dwI]<0.10&&ndvi<0.0)ch3[dwI]=1;
	 //else ch3[dwI]=(ndvi*100+110);  //10-210 scale
//	 else
//	 if(ch2[dwI]==-999.00&&ch1[dwI]==-999.00) ch3[dwI]=3;//set background 
	 //	 fwrite(&ch3[dwI],sizeof(c.0har), 1,fh2);
      	 fwrite(&ch3[dwI],sizeof(char), 1,fh2);

//	 _write(fh2, &ndvi[dwI], sizeof(float) );
//	 fputc(ch3[dwI],fh3);
	 }
	CString		sNum ;
	sNum.Format (_T("%i%%"),  i * 100 /h) ;
    m_wndProgress.SetPos(i * 100 / h);
	m_wndProgress.SetWindowText(sNum);
	 }
//	 return 1;
 _close(fh1);
 fclose(fh2);
 GlobalFreePtr(ch1);
 GlobalFreePtr(ch2);
 GlobalFreePtr(ch4);
 GlobalFreePtr(ch6);
return 1;

 }
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
 char  CReadeosDlg:: BytScl( float ni, float minv, float maxv ) 
 {
	unsigned char  result;
	result=128+int((255.0+0.9999)*ni/(maxv-minv));//((Top + 1)*x - 1)/(Max - Min). 
//(Top + 0.9999)*x/(Max - Min). 
     return result;
 }
  
 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
BOOL CReadeosDlg:: WriteFileinfo(char *in1)
{
	FILE *fpo;
	if((fpo=fopen(in1,"at"))==NULL) 
	{
		AfxMessageBox("不能创建文件信息",MB_OK,0);
	    return FALSE;
	}
//	fprintf(fpo,"\t%s\t%s\t%s\n","文件名","接收时间","通道");
     fprintf(fpo,"%s\n",buffer);
   //  fprintf(fpo,"%s\n","description = {");
	 fclose(fpo);
	 return TRUE;
}


void CReadeosDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CReadeosDlg::NdviProcess()
{
  char *name;
  readbatch(m_Ch1);
  CString ss,s1; 
 for(int j=0;j<count;j++)
 {
  name=bndtypes[j].Band_Name;
   ss=name;
   int iBad = ss.FindOneOf(_T("1246"));    // dubious filename
	if (iBad != -1)	s1=ss.Left(ss.GetLength()-6);
	
   char ff[120],bd[30];
	    strcpy(ff,s1);
	  GetFileTitle( name,   bd,   30  );
	  strcat(ff,"Ndvi");
     filename="正在处理:  "+CString(bd);
    m_Static.SetWindowText(filename);
   CalNdvi(ww, hh,name,ff);
 }
 return 1;
}

BOOL CReadeosDlg::ReadProcess()
{
  char *name;
  char cname[30];
   readbatch(m_Ch1);
  CString ss,s1; 
 for(int j=0;j<count;j++)
 {
  name=bndtypes[j].Band_Name;
   ss=name;
  	 strcat(name,"246");
   int iBad = ss.FindOneOf(_T("ch"));    // dubious filename
	if (iBad != -1)	s1=ss.Left(iBad+2);
	
  for(int n=1;n<5;n++)
  {
       initvari();
	   int nn=0;
	   nn=n;
	   char dd[120],ff[120],bd[30];
	  	strcpy(dd,s1);
       char buffer[20];
	    strcpy(ff,name);
	   if(n==4)nn=6;
	   else if(n==3)nn=4;
	  _itoa(nn, buffer, 10 );
      strcat(dd,buffer);
	  GetFileTitle( dd,   bd,   30  );
	   strcpy(cname,dd);
	  strcat(cname,".说明");
     filename="正在处理:  "+CString(bd);
    m_Static.SetWindowText(filename);
    strcpy(name,ff);
  if(ReadndWriteEnviFile(cname, 0 )){
  WriteFileinfo("l:\\eosfile\\2005.1-12.txt");
  readbna(width,height,dd,ff);}
  } 
 } 
 return 1;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -