Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
TempestOnlineMapIO.cpp File Reference
#include "FiniteElementTools.h"
#include "moab/Remapping/TempestOnlineMap.hpp"
#include "moab/TupleList.hpp"
#include "netcdfcpp.h"
+ Include dependency graph for TempestOnlineMapIO.cpp:

Go to the source code of this file.

Enumerations

enum  MapFileFormat { MAP_FORMAT_UNKNOWN = 0 , MAP_FORMAT_CLASSIC = 1 , MAP_FORMAT_NETCDF4 = 2 }
 

Functions

void print_progress (const int barWidth, const float progress, const char *message)
 
static int detectMapFileNetCDFFormat (const char *path)
 Inspect the file header to classify NetCDF format. Reads only the first 8 bytes — relies on the well-known "CDF\\xNN" and HDF5 magic signatures. Returns MAP_FORMAT_UNKNOWN if the file cannot be opened or the signature does not match. Safe to call from a single rank. More...
 

Variables

static constexpr int BUFFERED_READ_NNZ_THRESHOLD = 3000000
 NNZ threshold: maps with nS <= this value use the buffered read strategy. Maps with nS > this value use direct parallel I/O (if available). Default 3M entries corresponds to ~36 MB of raw data (row+col+S). More...
 
static constexpr int BUFFERED_READ_CHUNK_BYTES = 64 * 1024
 Buffer size in bytes for each chunk read by rank 0 in buffered mode. Each sparse matrix entry is 12 bytes (2 ints + 1 double), so 64KB holds ~5461 entries. Larger buffers reduce the number of read+scatter rounds but increase peak memory on rank 0. More...
 

Enumeration Type Documentation

◆ MapFileFormat

Enumerator
MAP_FORMAT_UNKNOWN 
MAP_FORMAT_CLASSIC 
MAP_FORMAT_NETCDF4 

Definition at line 1306 of file TempestOnlineMapIO.cpp.

1307 {
1308  MAP_FORMAT_UNKNOWN = 0,
1309  MAP_FORMAT_CLASSIC = 1, // CDF-1, CDF-2, CDF-5
1310  MAP_FORMAT_NETCDF4 = 2 // NetCDF-4 / HDF5
1311 };

Function Documentation

◆ detectMapFileNetCDFFormat()

static int detectMapFileNetCDFFormat ( const char *  path)
static

Inspect the file header to classify NetCDF format. Reads only the first 8 bytes — relies on the well-known "CDF\\xNN" and HDF5 magic signatures. Returns MAP_FORMAT_UNKNOWN if the file cannot be opened or the signature does not match. Safe to call from a single rank.

References:

Definition at line 1322 of file TempestOnlineMapIO.cpp.

1323 {
1324  std::FILE* fp = std::fopen( path, "rb" );
1325  if( !fp ) return MAP_FORMAT_UNKNOWN;
1326 
1327  unsigned char magic[8] = { 0 };
1328  const size_t nread = std::fread( magic, 1, sizeof( magic ), fp );
1329  std::fclose( fp );
1330 
1331  if( nread < 4 ) return MAP_FORMAT_UNKNOWN;
1332 
1333  // Classic NetCDF families: 'C','D','F' + version byte (0x01, 0x02, or 0x05)
1334  if( magic[0] == 'C' && magic[1] == 'D' && magic[2] == 'F' )
1335  {
1336  if( magic[3] == 0x01 || magic[3] == 0x02 || magic[3] == 0x05 ) return MAP_FORMAT_CLASSIC;
1337  }
1338 
1339  // HDF5 signature (used by NetCDF-4)
1340  if( nread >= 8 && magic[0] == 0x89 && magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F' && magic[4] == 0x0D &&
1341  magic[5] == 0x0A && magic[6] == 0x1A && magic[7] == 0x0A )
1342  {
1343  return MAP_FORMAT_NETCDF4;
1344  }
1345 
1346  return MAP_FORMAT_UNKNOWN;
1347 }

References MAP_FORMAT_CLASSIC, MAP_FORMAT_NETCDF4, and MAP_FORMAT_UNKNOWN.

Referenced by moab::TempestOnlineMap::ReadParallelMap().

◆ print_progress()

void print_progress ( const int  barWidth,
const float  progress,
const char *  message 
)

Definition at line 1246 of file TempestOnlineMapIO.cpp.

1247 {
1248  std::cout << message << " [";
1249  int pos = barWidth * progress;
1250  for( int i = 0; i < barWidth; ++i )
1251  {
1252  if( i < pos )
1253  std::cout << "=";
1254  else if( i == pos )
1255  std::cout << ">";
1256  else
1257  std::cout << " ";
1258  }
1259  std::cout << "] " << int( progress * 100.0 ) << " %\r";
1260  std::cout.flush();
1261 }

Variable Documentation

◆ BUFFERED_READ_CHUNK_BYTES

constexpr int BUFFERED_READ_CHUNK_BYTES = 64 * 1024
staticconstexpr

Buffer size in bytes for each chunk read by rank 0 in buffered mode. Each sparse matrix entry is 12 bytes (2 ints + 1 double), so 64KB holds ~5461 entries. Larger buffers reduce the number of read+scatter rounds but increase peak memory on rank 0.

Definition at line 1300 of file TempestOnlineMapIO.cpp.

Referenced by moab::TempestOnlineMap::ReadParallelMap().

◆ BUFFERED_READ_NNZ_THRESHOLD

constexpr int BUFFERED_READ_NNZ_THRESHOLD = 3000000
staticconstexpr

NNZ threshold: maps with nS <= this value use the buffered read strategy. Maps with nS > this value use direct parallel I/O (if available). Default 3M entries corresponds to ~36 MB of raw data (row+col+S).

Definition at line 1294 of file TempestOnlineMapIO.cpp.

Referenced by moab::TempestOnlineMap::ReadParallelMap().