📄 readeosdlg.cpp
字号:
// readeosDlg.cpp : implementation file
//
#include "stdafx.h"
#include "readeos.h"
#include "readeosDlg.h"
#include "windowsx.h"
#include <io.h>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <winuser.h.>
#include <string.h>
#include <math.h>
#include <float.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadeosDlg dialog
CReadeosDlg::CReadeosDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReadeosDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReadeosDlg)
m_Ch1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CReadeosDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReadeosDlg)
DDX_Control(pDX, IDC_Sat, m_Static);
DDX_Control(pDX, IDC_BROWSE2, m_MyBrowse);
DDX_Control(pDX, IDC_EDIT5, m_edit5);
DDX_Text(pDX, IDC_EDIT5, m_Ch1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReadeosDlg, CDialog)
//{{AFX_MSG_MAP(CReadeosDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadeosDlg message handlers
BOOL CReadeosDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CreateProgress(NULL, 100, 100, FALSE);
width=height=bandnum=0;
xllcorner=yllcorner=xrrcorner=yrrcorner=pxsize=pysize=0.0;
// 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;
count=0;
// m_PrCtl.SetRange(0,100);
// m_PrCtl.SetPos(0);
HICON m_myicon=(HICON)::LoadImage(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(129),IMAGE_ICON,0,0,0);
m_MyBrowse.SetIcon(m_myicon);
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CReadeosDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CReadeosDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CReadeosDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CReadeosDlg::OnBrowse2()
{
#ifndef _MAC
CFileDialog dlg( TRUE,NULL,NULL,
OFN_READONLY|OFN_FILEMUSTEXIST|OFN_SHAREAWARE,
"txt Files (*.txt)|*.txt|All Files (*.*)|*.*||");
#else
CFileDialog dlg( TRUE,_T("LDF"),_T("*.ldf"),
OFN_READONLY|OFN_FILEMUSTEXIST|OFN_SHAREAWARE,
"local files (*.ldf )|*.ldf|local files (*.ld2 )|*.ld2|VIX (*.vix)|*.vix|All Files (*.*)|*.*||");
#endif
char name[250]="";
GetCurrentDirectory( 250, name);
dlg.m_ofn.lpstrInitialDir=name;
if( dlg.DoModal()==IDOK )
{
m_Ch1 = dlg.GetPathName();
m_edit5.SetWindowText( m_Ch1);
}
return true;
}
BOOL CReadeosDlg::ReadndWriteEnviFile(LPCTSTR pszPathName, BOOL Rw )
{
if(Rw)
{
FILE *fpo;
if((fpo=fopen(pszPathName,"w"))==NULL)
{
AfxMessageBox("不能创建hdr文件",MB_OK,0);
return FALSE;
}
fprintf(fpo,"%s\n","ENVI");
fprintf(fpo,"%s\n","description = {");
fprintf(fpo,"File Imported into ENVI.[%s]}\n", "By Bendor");
fprintf(fpo,"samples = %d\n",width);
fprintf(fpo,"lines = %d\n",height);
fprintf(fpo,"bands = 4\n");
fprintf(fpo,"header offset = 0\n");
fprintf(fpo,"file type = ENVI Standard\n");
fprintf(fpo,"data type = 4\n");
fprintf(fpo,"interleave = bsq\n");
fprintf(fpo,"sensor type = MODIS\n");
fprintf(fpo,"byte order = 0\n");
int start=1;
fprintf(fpo,"map info = {Geographic Lat/Lon, %d, %d, %.8f, %.8f, %e, %e, WGS-84, units=Degrees}\n",\
start,start,xllcorner,yllcorner,pxsize,pysize);
fprintf(fpo,"band names = {\n");
fprintf(fpo," modis(band %d)}\n",bandnum);
fprintf(fpo,"wavelength = {\n");
if(bandnum==1)
fprintf(fpo," 3.740000}\n");
if(bandnum==2)
fprintf(fpo," 10.820000}\n");
if(bandnum==6)
fprintf(fpo," 12.000000}\n");
fclose(fpo);
}
if(!Rw)
{
FILE *fh;
if((fh=fopen(pszPathName,"rb"))==NULL)
{
AfxMessageBox("不能打开ENVI头信息文件,请用户自定义!",MB_OK,0);
return FALSE;
}
char b[1000],a[90],cc[20];
int w;
CString s,str,ss;
fseek(fh,0L,SEEK_END);
fpos_t pos;
fgetpos( fh, &pos );
fseek(fh,0L,SEEK_SET);
fread(b,sizeof(char), pos, fh );
s=b;
sscanf(b, "%s", str );
if(str.IsEmpty()!=0)
{
int n = s.Find("时间:");
ASSERT( n != -1 );
pos=n+strlen("时间:");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%s%s%s",b,a,cc);
n = s.Find("通道:");
ASSERT( n != -1 );
pos=n+strlen("通道:");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%d",&w);
bandnum=w;
int j=0;
char aa[30];
int nn=str.FindOneOf( _T("的说明") );
strncpy(aa, str, nn );
//f.TrimRight(nn);
_strnset( aa, ' ', 8 );
j = sprintf( buffer," %s", aa);
j += sprintf( buffer + j, " %s %s %s %d", b,a,cc, bandnum);
// str.Empty();
_itoa( w, a, 10 );
strcat(b,"ch");
strcat(b,a);
filename=b;
str.Empty();
n = s.Find("左上角经度: ");
ASSERT( n != -1 );
pos=n+strlen("左上角经度: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&xllcorner);
n = s.Find("左上角纬度: ");
ASSERT( n != -1 );
pos=n+strlen("左上角纬度: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&yllcorner);
n = s.Find("右下角经度: ");
ASSERT( n != -1 );
pos=n+strlen("右下角经度: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&xrrcorner);
n = s.Find("右下角纬度: ");
ASSERT( n != -1 );
pos=n+strlen("右下角纬度: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&yrrcorner);
n = s.Find("经度分辨率(点距): ");
ASSERT( n != -1 );
pos=n+strlen("经度分辨率(点距): ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&pxsize);
n = s.Find("纬度分辨率(点距): ");
ASSERT( n != -1 );
pos=n+strlen("纬度分辨率(点距): ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%f",&pysize);
n = s.Find("X方向(从西到东)点数: ");
ASSERT( n != -1 );
pos=n+strlen("X方向(从西到东)点数: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%d",&width);
n = s.Find("Y方向(从北到南)点数: ");
ASSERT( n != -1 );
pos=n+strlen("Y方向(从北到南)点数: ");
fseek(fh,pos,SEEK_SET);
fscanf( fh, "%d",&height);
fclose(fh);
return 1;
}
else
{
AfxMessageBox("不能打开ENVI头信息文件,请用户自定义!",MB_OK,0);
return FALSE;
}
fclose(fh);
// }
return 0;
}
return 1;
}
//*******************************************************************************
void CReadeosDlg::OnOK()
{
//ReadProcess();
CalNdvi(0,0,"d:\\noaa\\MOD02HKMA10409140459_PRJ.ld2","d:\\noaa\\test.txt");
//NdviProcess();
CDialog::OnOK();
}
void CReadeosDlg::initvari()
{
// width=height=bandnum=0;
// xllcorner=yllcorner=xrrcorner=yrrcorner=pxsize=pysize=0.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -