OK,
this is the code:
// PROGRAM TO PARSE A BINARY FILE WITH DATASET OF 300 columns x 180 rows x 365 days x N years INTEGER VALUES
//
#define STRICT
#define WIN32_LEAN_AND_MEAN
//
#include <windows.h>
#include <stdio.h>
#define __ROW__ 180
#define __COLUMN__ 300
#define __DAY__ 365
//
typedef struct
{
INT iValue[__DAY__][__ROW__][__COLUMN__];
} YEAR, *LPYEAR;
//
int main(void)
{
// MAP FILE IN MEMORY
HANDLE hFile = CreateFile("test.bin", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if ( INVALID_HANDLE_VALUE == hFile )
{
return -1;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
if ( INVALID_FILE_SIZE == dwFileSize )
{
CloseHandle(hFile);
return -1;
}
HANDLE hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if ( NULL == hMapping )
{
CloseHandle(hFile);
return -1;
}
LPYEAR lpYear = (LPYEAR)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hMapping);
CloseHandle(hFile);
if ( NULL == lpYear )
{
return -1;
}
// FILESIZE
size_t iSize = 0;
MEMORY_BASIC_INFORMATION mbi = { 0 };
if ( VirtualQuery(lpYear, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) >= sizeof(MEMORY_BASIC_INFORMATION) )
{
iSize = min(dwFileSize, mbi.RegionSize);
}
else
{
iSize = dwFileSize;
}
// NUMBER OF YEARS IN FILE
INT iYears = iSize/sizeof(YEAR);
if ( iYears > 0 )
{
//
printf("filesize is %d\n", iSize);
printf("year founded on file: %d\n", iYears);
// SHOW VALUE OF
// FIRST YEAR
// FIRST DAY
// FIRST ROW
// FIRST COLUMN
printf("%d\n", lpYear[0].iValue[0][0][0]);
// SHOW VALUE OF
// FIRST YEAR
// LAST DAY
// LAST ROW
// 80th COLUMN
printf("%d\n", lpYear[0].iValue[__DAY__-1][__ROW__-1][80]);
}
//
UnmapViewOfFile(lpYear);
//
return 0;
}
Can this considered a valid approach or there is a another solution ?