GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
opencell.c File Reference

GIS Library - open raster (cell) file functions. More...

#include <rpc/types.h>
#include <rpc/xdr.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <grass/config.h>
#include "G.h"
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for opencell.c:

Go to the source code of this file.

Macros

#define FP_NBYTES   G__.fp_nbytes
 
#define FP_TYPE   G__.fp_type
 
#define FORMAT_FILE   "f_format"
 

Functions

int G_open_cell_old (const char *name, const char *mapset)
 Open an existing integer raster map (cell) More...
 
int G__open_cell_old (const char *name, const char *mapset)
 Lower level function, open cell files, supercell files, and the MASK file. More...
 
int G_open_cell_new (const char *name)
 Opens a new cell file in a database (compressed) More...
 
int G_open_cell_new_random (const char *name)
 Opens a new cell file in a database (random mode) More...
 
int G_open_cell_new_uncompressed (const char *name)
 Opens a new cell file in a database (uncompressed) More...
 
int G_want_histogram (int flag)
 Save histogram for newly create raster map (cell) More...
 
int G_set_cell_format (int n)
 Sets the format for subsequent opens on new integer cell files (uncompressed and random only). More...
 
int G_cellvalue_format (CELL v)
 Get cell value format. More...
 
int G_open_fp_cell_new (const char *name)
 Opens new fcell file in a database. More...
 
int G_open_fp_cell_new_uncompressed (const char *name)
 Opens new fcell file in a database (uncompressed) More...
 
int G__reallocate_work_buf (int bytes_per_cell)
 Allocate/enlarge the work data buffer needed by get_map_row and put_map_row() More...
 
int G__reallocate_null_buf (void)
 Allocate/enlarge the null data buffer needed by get_map_row() and for conversion in put_row. More...
 
int G__reallocate_mask_buf (void)
 Allocate/enlarge the mask buffer needed by get_map_row() More...
 
int G__reallocate_temp_buf (void)
 Allocate/enlarge the temporary buffer needed by G_get_raster_row[_nomask]. More...
 
int G_set_fp_type (RASTER_MAP_TYPE map_type)
 Set raster map floating-point data format. More...
 
int G_raster_map_is_fp (const char *name, const char *mapset)
 Check if raster map is floating-point. More...
 
RASTER_MAP_TYPE G_raster_map_type (const char *name, const char *mapset)
 Determine raster data type. More...
 
RASTER_MAP_TYPE G_get_raster_map_type (int fd)
 Determine raster type from descriptor. More...
 
RASTER_MAP_TYPE G__check_fp_type (const char *name, const char *mapset)
 Determines whether the floating points cell file has double or float type. More...
 
int G_open_raster_new (const char *name, RASTER_MAP_TYPE wr_type)
 Opens a new raster map. More...
 
int G_open_raster_new_uncompressed (const char *name, RASTER_MAP_TYPE wr_type)
 Opens a new raster map (uncompressed) More...
 
int G_set_quant_rules (int fd, struct Quant *q)
 Sets quant translation rules for raster map opened for reading. More...
 

Detailed Description

GIS Library - open raster (cell) file functions.

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
USACERL and many others

Definition in file opencell.c.

Macro Definition Documentation

#define FORMAT_FILE   "f_format"

Definition at line 954 of file opencell.c.

Referenced by G__check_fp_type().

#define FP_NBYTES   G__.fp_nbytes

Definition at line 381 of file opencell.c.

Referenced by G_open_fp_cell_new(), G_open_fp_cell_new_uncompressed(), and G_set_fp_type().

#define FP_TYPE   G__.fp_type

Definition at line 383 of file opencell.c.

Referenced by G_open_fp_cell_new(), G_open_fp_cell_new_uncompressed(), and G_set_fp_type().

Function Documentation

RASTER_MAP_TYPE G__check_fp_type ( const char *  name,
const char *  mapset 
)

Determines whether the floating points cell file has double or float type.

Parameters
namemap name
mapsetmapset where map name lives
Returns
raster type (fcell, dcell)

Definition at line 1053 of file opencell.c.

References FORMAT_FILE, G__file_name_misc(), G_find_cell2(), G_find_key_value(), G_free_key_value(), G_read_key_value_file(), G_strip(), G_warning(), NULL, and xmapset.

Referenced by G_raster_map_type().

int G__open_cell_old ( const char *  name,
const char *  mapset 
)

Lower level function, open cell files, supercell files, and the MASK file.

Actions:

  • opens the named cell file, following reclass reference if named layer is a reclass layer.
  • creates the required mapping between the data and the window for use by the get_map_row family of routines.

Diagnostics: Errors other than actual open failure will cause a diagnostic to be delivered thru G_warning() open failure messages are left to the calling routine since the masking logic will want to issue a different warning.

Note: This routine does NOT open the MASK layer. If it did we would get infinite recursion. This routine is called to open the mask by G__check_for_auto_masking() which is called by G_open_cell_old().

Parameters
namemap name
mapsetmapset of cell file to be opened
Returns
open file descriptor
-1 if error

Definition at line 149 of file opencell.c.

References fileinfo::cellhd, fileinfo::cur_row, fileinfo::data, fd, G__allocate_null_bits(), G__check_format(), G__create_window_mapping(), G__init_window(), G__name_is_fully_qualified(), G__projection_name(), G__reallocate_mask_buf(), G__reallocate_null_buf(), G__reallocate_temp_buf(), G__reallocate_work_buf(), G_copy(), G_find_cell2(), G_get_cellhd(), G_get_gdal_link(), G_get_reclass(), G_open_old(), G_raster_map_type(), G_read_quant(), G_store(), G_warning(), fileinfo::gdal, fileinfo::io_error, fileinfo::map_type, fileinfo::mapset, fileinfo::min_null_row, fileinfo::name, render::name, fileinfo::nbytes, NULL, fileinfo::null_cur_row, fileinfo::null_file_exists, fileinfo::NULL_ROWS, NULL_ROWS_INMEM, fileinfo::null_work_buf, fileinfo::open_mode, OPEN_OLD, fileinfo::quant, fileinfo::reclass, fileinfo::reclass_flag, G__::window, XDR_DOUBLE_NBYTES, XDR_FLOAT_NBYTES, fileinfo::xdrstream, xmapset, and xname.

Referenced by G__check_for_auto_masking(), and G_open_cell_old().

int G__reallocate_mask_buf ( void  )

Allocate/enlarge the mask buffer needed by get_map_row()

Returns
0

Definition at line 885 of file opencell.c.

References G__::mask_buf, G__::mask_buf_size, n, and G__::window.

Referenced by G__open_cell_old(), and G_set_window().

int G__reallocate_null_buf ( void  )

Allocate/enlarge the null data buffer needed by get_map_row() and for conversion in put_row.

Returns
0

Definition at line 865 of file opencell.c.

References n, G__::null_buf, G__::null_buf_size, and G__::window.

Referenced by G__open_cell_old(), and G_set_window().

int G__reallocate_temp_buf ( void  )

Allocate/enlarge the temporary buffer needed by G_get_raster_row[_nomask].

Returns
0

Definition at line 906 of file opencell.c.

References n, G__::temp_buf, G__::temp_buf_size, and G__::window.

Referenced by G__open_cell_old(), and G_set_window().

int G__reallocate_work_buf ( int  bytes_per_cell)

Allocate/enlarge the work data buffer needed by get_map_row and put_map_row()

Parameters
bytes_per_cellnumber of bytes per cell
Returns
0

Definition at line 842 of file opencell.c.

References n, G__::window, G__::work_buf, and G__::work_buf_size.

Referenced by G__open_cell_old(), and G_set_window().

int G_cellvalue_format ( CELL  v)

Get cell value format.

Parameters
vcell
Returns
cell format

Definition at line 518 of file opencell.c.

RASTER_MAP_TYPE G_get_raster_map_type ( int  fd)

Determine raster type from descriptor.

Determines if the raster map is floating point or integer. Returns DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for integer maps, -1 if error has occured

Parameters
fdfile descriptor
Returns
raster data type

Definition at line 1038 of file opencell.c.

References fd, G__::fileinfo, and fileinfo::map_type.

Referenced by Gs_get_cat_label(), and N_read_rast_to_array_2d().

int G_open_cell_new ( const char *  name)

Opens a new cell file in a database (compressed)

Opens a new cell file name in the current mapset for writing by G_put_raster_row().

The file is created and filled with no data it is assumed that the new cell file is to conform to the current window.

The file must be written sequentially. Use G_open_cell_new_random() for non sequential writes.

Note: the open actually creates a temporary file G_close_cell() will move the temporary file to the cell file and write out the necessary support files (cellhd, cats, hist, etc.).

Diagnostics: warning message printed if open fails

Warning: calls to G_set_window() made after opening a new cell file may create confusion and should be avoided the new cell file will be created to conform to the window at the time of the open.

Parameters
namemap name
Returns
open file descriptor ( >= 0) if successful
negative integer if error

Definition at line 417 of file opencell.c.

References OPEN_NEW_COMPRESSED.

Referenced by G_open_raster_new().

int G_open_cell_new_random ( const char *  name)

Opens a new cell file in a database (random mode)

See also G_open_cell_new().

Used for non sequential writes.

Parameters
namemap name
Returns
open file descriptor ( >= 0) if successful
negative integer if error

Definition at line 438 of file opencell.c.

References OPEN_NEW_RANDOM.

int G_open_cell_new_uncompressed ( const char *  name)

Opens a new cell file in a database (uncompressed)

See also G_open_cell_new().

Parameters
namemap name
Returns
open file descriptor ( >= 0) if successful
negative integer if error

Definition at line 457 of file opencell.c.

References OPEN_NEW_UNCOMPRESSED.

Referenced by G_open_raster_new_uncompressed().

int G_open_cell_old ( const char *  name,
const char *  mapset 
)

Open an existing integer raster map (cell)

Opens the existing cell file name in the mapset for reading by G_get_raster_row() with mapping into the current window.

This routine opens the raster map name in mapset for reading. A nonnegative file descriptor is returned if the open is successful. Otherwise a diagnostic message is printed and a negative value is returned. This routine does quite a bit of work. Since GRASS users expect that all raster maps will be resampled into the current region, the resampling index for the raster map is prepared by this routine after the file is opened. The resampling is based on the active module region.

Remarks
{See also The_Region.} Preparation required for reading the various raster file formats
{See Raster_File_Format for an explanation of the various raster file formats.} is also done.

Diagnostics: warning message printed if open fails.

Parameters
namemap name
mapsetmapset name where raster map name lives
Returns
nonnegative file descriptor (int)
-1 on failure

Definition at line 100 of file opencell.c.

References fd, G__check_for_auto_masking(), G__open_cell_old(), and G_warning().

Referenced by Gs_get_cat_label(), Gs_loadmap_as_bitmap(), Gs_loadmap_as_char(), Gs_loadmap_as_float(), Gs_loadmap_as_int(), Gs_loadmap_as_short(), IL_create_bitmask(), and N_read_rast_to_array_2d().

int G_open_fp_cell_new ( const char *  name)

Opens new fcell file in a database.

Opens a new floating-point map name in the current mapset for writing. The type of the file (i.e. either double or float) is determined and fixed at this point. The default is FCELL_TYPE. In order to change this default

Use G_set_fp_type() where type is one of DCELL_TYPE or FCELL_TYPE.

See warnings and notes for G_open_cell_new().

Parameters
namemap name
Returns
nonnegative file descriptor (int)
-1 on error

Definition at line 546 of file opencell.c.

References FP_NBYTES, FP_TYPE, getenv(), OPEN_NEW_COMPRESSED, XDR_DOUBLE_NBYTES, and XDR_FLOAT_NBYTES.

Referenced by G_open_raster_new(), IL_output_2d(), and IL_resample_output_2d().

int G_open_fp_cell_new_uncompressed ( const char *  name)

Opens new fcell file in a database (uncompressed)

See G_open_fp_cell_new() for details.

Parameters
namemap name
Returns
nonnegative file descriptor (int)
-1 on error

Definition at line 578 of file opencell.c.

References FP_NBYTES, FP_TYPE, getenv(), OPEN_NEW_UNCOMPRESSED, XDR_DOUBLE_NBYTES, and XDR_FLOAT_NBYTES.

Referenced by G_open_raster_new_uncompressed().

int G_open_raster_new ( const char *  name,
RASTER_MAP_TYPE  wr_type 
)

Opens a new raster map.

Opens a new raster map of type wr_type

See warnings and notes for G_open_cell_new().

Supported data types:

  • CELL_TYPE
  • FCELL_TYPE
  • DCELL_TYPE

On CELL_TYPE calls G_open_cell_new() otherwise G_open_fp_cell_new().

Parameters
namemap name
wr_typeraster data type
Returns
nonnegative file descriptor (int)
-1 on error

Definition at line 1127 of file opencell.c.

References G_open_cell_new(), G_open_fp_cell_new(), and G_set_fp_type().

Referenced by N_write_array_2d_to_rast().

int G_open_raster_new_uncompressed ( const char *  name,
RASTER_MAP_TYPE  wr_type 
)

Opens a new raster map (uncompressed)

See G_open_raster_new().

Parameters
namemap name
wr_typeraster data type
Returns
nonnegative file descriptor (int)
-1 on error

Definition at line 1147 of file opencell.c.

References G_open_cell_new_uncompressed(), G_open_fp_cell_new_uncompressed(), and G_set_fp_type().

int G_raster_map_is_fp ( const char *  name,
const char *  mapset 
)

Check if raster map is floating-point.

Returns true (1) if raster map name in mapset is a floating-point dataset; false(0) otherwise.

Parameters
namemap name
mapsetmapset name
Returns
1 floating-point
0 int

Definition at line 969 of file opencell.c.

References G__file_name(), G_find_cell2(), G_warning(), and xmapset.

Referenced by G__read_cats(), G__write_cats(), G_read_colors(), Gs_numtype(), and gsd_put_legend().

RASTER_MAP_TYPE G_raster_map_type ( const char *  name,
const char *  mapset 
)

Determine raster data type.

Determines if the raster map is floating point or integer. Returns DCELL_TYPE for double maps, FCELL_TYPE for float maps, CELL_TYPE for integer maps, -1 if error has occured

Parameters
namemap name
mapsetmapset where map name lives
Returns
raster data type

Definition at line 1001 of file opencell.c.

References G__check_fp_type(), G__file_name(), G_find_cell2(), G_warning(), and xmapset.

Referenced by G__open_cell_old(), G__quant_import(), G_get_gdal_link(), G_read_fp_range(), G_read_range(), G_write_quant(), and G_write_range().

int G_set_cell_format ( int  n)

Sets the format for subsequent opens on new integer cell files (uncompressed and random only).

Warning: subsequent put_row calls will only write n+1 bytes per cell. If the data requires more, the cell file will be written incorrectly (but with n+1 bytes per cell)

When writing float map: format is -1

Parameters
nformat
Returns
0

Definition at line 497 of file opencell.c.

int G_set_fp_type ( RASTER_MAP_TYPE  map_type)

Set raster map floating-point data format.

This controls the storage type for floating-point maps. It affects subsequent calls to G_open_fp_map_new(). The type must be one of FCELL_TYPE (float) or DCELL_TYPE (double). The use of this routine by applications is discouraged since its use would override user preferences.

Parameters
typeraster data type
Returns
1 on success
-1 on error

Definition at line 937 of file opencell.c.

References FP_NBYTES, FP_TYPE, G_warning(), fileinfo::map_type, XDR_DOUBLE_NBYTES, and XDR_FLOAT_NBYTES.

Referenced by G_open_raster_new(), and G_open_raster_new_uncompressed().

int G_set_quant_rules ( int  fd,
struct Quant *  q 
)

Sets quant translation rules for raster map opened for reading.

Returned by G_open_cell_old(). After calling this function, G_get_c_raster_row() and G_get_map_row() will use rules defined by q (instead of using rules defined in map's quant file) to convert floats to ints.

Parameters
fdfile descriptor (cell file)
qpointer to Quant structure
Returns
0 success
-1 failure

Definition at line 1171 of file opencell.c.

References fd, G__::fileinfo, G_quant_add_rule(), G_quant_get_neg_infinite_rule(), G_quant_get_pos_infinite_rule(), G_quant_init(), G_quant_set_neg_infinite_rule(), G_quant_set_pos_infinite_rule(), G_quant_truncate(), G_warning(), fileinfo::open_mode, OPEN_OLD, and fileinfo::quant.

int G_want_histogram ( int  flag)

Save histogram for newly create raster map (cell)

If newly created cell files should have histograms, set flag=1 otherwise set flag=0. Applies to subsequent opens.

Parameters
flagflag indicator
Returns
0

Definition at line 476 of file opencell.c.

References tools::flag, and G__::want_histogram.