NEP 2.7.0
NetCDF Extension Pack
Loading...
Searching...
No Matches
Macros | Functions
geotifffile.c File Reference

GeoTIFF file format detection and operations. More...

#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netcdf.h>
#include "geotiffdispatch.h"
#include "nep_nc4.h"

Macros

#define GEOTIFF_KEY_DIRECTORY_TAG   34735
 
#define MAX_IFD_OFFSET   104857600
 
#define TIFF_IFD_ENTRY_SIZE   12
 
#define MAX_BUFFER_SIZE   1073741824
 
#define MAX_IFD_ENTRIES   4096
 

Functions

static unsigned short swap16 (unsigned short val)
 
static unsigned int swap32 (unsigned int val)
 
static int nc4_set_var_type (nc_type xtype, int endianness, size_t type_size, char *type_name, NC_TYPE_INFO_T **typep)
 
static int nc4_var_list_add_full (NC_GRP_INFO_T *grp, const char *name, int ndims, nc_type xtype, int endianness, size_t type_size, char *type_name, void *fill_value, int contiguous, size_t *chunksizes, void *format_var_info, NC_VAR_INFO_T **var)
 
static int read_tiff_header (FILE *fp, int *is_little_endian, int *is_bigtiff, unsigned int *ifd_offset)
 
static int check_geotiff_tags (FILE *fp, unsigned int ifd_offset, int is_little_endian, int is_bigtiff, int *has_geotiff_tags)
 
int NC_GEOTIFF_detect_format (const char *path, int *is_geotiff)
 

Detailed Description

GeoTIFF file format detection and operations.

This file implements GeoTIFF format detection for the NetCDF API. It validates TIFF magic numbers, headers, and GeoTIFF-specific tags to distinguish GeoTIFF files from regular TIFF files.

Author
Edward Hartnett
Date
2025-12-26

Macro Definition Documentation

◆ GEOTIFF_KEY_DIRECTORY_TAG

#define GEOTIFF_KEY_DIRECTORY_TAG   34735

GeoTIFF key directory tag

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   1073741824

Maximum buffer size for reading (1 GB)

◆ MAX_IFD_ENTRIES

#define MAX_IFD_ENTRIES   4096

Maximum number of IFD entries to process

◆ MAX_IFD_OFFSET

#define MAX_IFD_OFFSET   104857600

Maximum reasonable IFD offset (100 MB)

◆ TIFF_IFD_ENTRY_SIZE

#define TIFF_IFD_ENTRY_SIZE   12

TIFF IFD entry size

Function Documentation

◆ check_geotiff_tags()

static int check_geotiff_tags ( FILE *  fp,
unsigned int  ifd_offset,
int  is_little_endian,
int  is_bigtiff,
int *  has_geotiff_tags 
)
static

Check if IFD contains GeoTIFF tags.

Parameters
fpFile pointer.
ifd_offsetIFD offset.
is_little_endian1 if little-endian, 0 if big-endian.
is_bigtiff1 if BigTIFF, 0 if classic TIFF.
has_geotiff_tagsOutput: 1 if GeoTIFF tags found, 0 otherwise.
Returns
NC_NOERR on success, error code otherwise.

◆ nc4_set_var_type()

static int nc4_set_var_type ( nc_type  xtype,
int  endianness,
size_t  type_size,
char *  type_name,
NC_TYPE_INFO_T **  typep 
)
static

◆ nc4_var_list_add_full()

static int nc4_var_list_add_full ( NC_GRP_INFO_T *  grp,
const char *  name,
int  ndims,
nc_type  xtype,
int  endianness,
size_t  type_size,
char *  type_name,
void *  fill_value,
int  contiguous,
size_t *  chunksizes,
void *  format_var_info,
NC_VAR_INFO_T **  var 
)
static

◆ NC_GEOTIFF_detect_format()

int NC_GEOTIFF_detect_format ( const char *  path,
int *  is_geotiff 
)

◆ read_tiff_header()

static int read_tiff_header ( FILE *  fp,
int *  is_little_endian,
int *  is_bigtiff,
unsigned int *  ifd_offset 
)
static

Read and validate TIFF header.

Parameters
fpFile pointer.
is_little_endianOutput: 1 if little-endian, 0 if big-endian.
is_bigtiffOutput: 1 if BigTIFF, 0 if classic TIFF.
ifd_offsetOutput: IFD offset.
Returns
NC_NOERR on success, error code otherwise.

◆ swap16()

static unsigned short swap16 ( unsigned short  val)
static

Byte-swap a 16-bit value.

Parameters
valValue to swap.
Returns
Swapped value.

◆ swap32()

static unsigned int swap32 ( unsigned int  val)
static

Byte-swap a 32-bit value.

Parameters
valValue to swap.
Returns
Swapped value.