gislib.dox 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. /*! \page gislib GRASS GIS Library
  2. <!-- doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 2/2004, 2005, 2006
  4. -->
  5. by GRASS Development Team (http://grass.osgeo.org)
  6. \tableofcontents
  7. \par Subpages
  8. - \subpage gislib_cmdline_parsing
  9. This chapter is divided as follows:
  10. - \subpage gislibintro
  11. - \subpage init
  12. - \subpage diag
  13. - \subpage envir
  14. - \subpage dbaseaccess
  15. - \subpage Fully_Qualified_File_Names
  16. - \subpage finding
  17. - \subpage Legal_File_Names
  18. - \subpage Opening_an_Existing_Database_File_for_Reading
  19. - \subpage Opening_an_Existing_Database_File_for_Update
  20. - \subpage Creating_and_Opening_a_New_Database_File
  21. - \subpage Database_File_Management
  22. - \subpage Region
  23. - \subpage Database_Region
  24. - \subpage Active_Module_Region
  25. - \subpage Projection_Information
  26. - \subpage Latitude_Longitude_Databases
  27. - \subpage Coordinates
  28. - \subpage Global_Wraparound
  29. - \subpage Miscellaneous
  30. - \subpage Calculations
  31. - \subpage Raster_Area_Calculations
  32. - \subpage Polygonal_Area_Calculations
  33. - \subpage Distance_Calculations
  34. - \subpage General_Plotting_Routines
  35. - \subpage Temporary_Files
  36. - \subpage String_Manipulation_Functions
  37. - \subpage Enhanced_UNIX_Routines
  38. - \subpage Running_in_the_Background
  39. - \subpage Partially_Interruptible_System_Call
  40. - \subpage ENDIAN_test
  41. - \subpage Miscellaneous
  42. - \subpage GIS_Library_Data_Structures
  43. - \subpage struct_Cell_head
  44. - \subpage struct_Categories
  45. - \subpage struct_Colors
  46. - \subpage struct_History
  47. - \subpage struct_Range
  48. - \subpage Loading_the_GIS_Library
  49. - \subpage TimeStamp_functions
  50. - \subpage Memory_Allocation
  51. \section gislibintro Introduction
  52. The <em>GIS Library</em> is the primary programming library provided
  53. with the GRASS system. <b>Programs must use this libary to access the
  54. GIS database.</b> It contains the routines which locate, create, open,
  55. rename, and remove GRASS database files. It contains the routines
  56. which read and write raster files. It contains routines which
  57. interface the user to the database, including prompting the user,
  58. listing available files, validating user access, etc. It also has
  59. some general purpose routines (string manipulation, user information,
  60. etc.) which are not tied directly to database processing.
  61. It is assumed that the reader has read \ref location for a general
  62. description of GRASS databases, \ref Raster_File_Processing for
  63. details about raster map layers in GRASS, and \ref Region_and_Mask
  64. (<b>???</b>) which discusses regions and masks. The routines in the
  65. <em>GIS Library</em> are presented in functional groupings, rather
  66. than in alphabetical order. The order of presentation will, it is
  67. hoped, provide a better understanding of how the library is to be
  68. used, as well as show the interrelationships among the various
  69. routines. Note that a good way to understand how to use these routines
  70. is to look at the source code for GRASS modules which use them. Most
  71. routines in this library require that the header file <b>grass/gis.h</b> be
  72. included in any code using these routines. Therefore, programmers
  73. should always include this file when writing code using routines from
  74. this library:
  75. \code
  76. #include <grass/gis.h>
  77. \endcode
  78. <b>Note:</b> All routines and global variables in this library,
  79. documented or undocumented, start with the prefix <b>G_</b>. To avoid
  80. name conflicts, programmers should not create variables or routines in
  81. their own modules which use this prefix.
  82. \subsection init Library Initialization
  83. It is <B>mandatory</B> that the system be initialized before any other
  84. library routines are called.
  85. G_gisinit() initialize GIS library.
  86. This routine reads the user's GRASS environment file into memory and
  87. makes sure that the user has selected a valid database and mapset. It
  88. also initializes hidden variables used by other routines. If the
  89. user's database information is invalid, an error message is printed
  90. and the module exits. The <b>program_name</b> is stored for later
  91. recall by G_program_name(). It is recommended that argv[0] be
  92. used for the program_name:
  93. \code
  94. int main (int argc, char **argv)
  95. {
  96. G_gisinit(argv[0]);
  97. }
  98. \endcode
  99. \subsection diag Diagnostic Messages
  100. The following routines are used by other routines in the library to
  101. report warning and error messages. They may also be used directly by
  102. GRASS programs.
  103. - G_fatal_error() print error message and exit
  104. - G_debug() print debug message
  105. - G_warning() print warning message and continue
  106. These routines report errors to the user. The normal mode is to write
  107. the <em>message</em> to the screen (on the standard error
  108. output). G_warning() will return and G_fatal_error() will exit.
  109. If the standard error output is not a tty device, then the message is
  110. mailed to the user instead.
  111. If the file GIS_ERROR_LOG exists (with write permission), in either
  112. the user's home directory or in the <tt>$GISBASE</tt> directory, the
  113. messages will also be logged to this file.
  114. While most applications will find the normal error reporting quite
  115. adequate, there will be times when different handling is needed. For
  116. example, graphics modules may want the messages displayed graphically
  117. instead of on the standard error output. If the programmer wants to
  118. handle the error messages differently, the following routines can be
  119. used to modify the error handling:
  120. - G_set_error_routine() change error handling
  121. This routine provides a different error handler for G_fatal_error()
  122. and G_warning(). The <em>handler</em> routine must be defined as
  123. follows:
  124. \code
  125. int handler(char *message, int fatal)
  126. \endcode
  127. where <i>message</i> is the message to be handled and <i>fatal</i>
  128. indicates the type of error:
  129. - 1 (fatal error)
  130. - or 0 (warning).
  131. <b>Note:</b> The handler only provides a way to send the message
  132. somewhere other than to the error output. If the error is fatal, the
  133. module will exit after the handler returns.
  134. - G_unset_error_routine() reset normal error handling
  135. This routine resets the error handling for G_fatal_error() and
  136. G_warning() back to the default action.
  137. - G_sleep_on_error() sleep on error
  138. - G_suppress_warnings() suppress warnings
  139. \subsection envir Environment and Database Information
  140. The following routines return information about the current database
  141. selected by the user. Some of this information is retrieved from the
  142. user's GRASS environment file. Some of it comes from files in the
  143. database itself. See \ref Environment_Variables for a discussion of
  144. the GRASS environment.
  145. The following four routines can be used freely by the programmer:
  146. - G_location() current location name
  147. Returns the name of the current database location. This routine should
  148. be used by modules that need to display the current location to the
  149. user. See \ref Locations for an explanation of locations.
  150. - G_mapset() current mapset name
  151. Returns the name of the current mapset in the current location. This
  152. routine is often used when accessing files in the current mapset. See
  153. \ref Mapsets for an explanation of mapsets.
  154. - G_myname() location title
  155. Returns a one line title for the database location. This title is read
  156. from the file MYNAME in the PERMANENT mapset. See also \ref
  157. Permanent_Mapset for a discussion of the PERMANENT mapset.
  158. - G_gisbase() top level module directory
  159. Returns the full path name of the top level directory for GRASS
  160. programs. This directory will have subdirectories which will contain
  161. modules and files required for the running of the system. Some of
  162. these directories are:
  163. \verbatim
  164. bin commands run by the user
  165. etc modules and data files used by GRASS commands
  166. html help files
  167. \endverbatim
  168. The use of G_gisbase() to find these subdirectories enables GRASS modules
  169. to be written independently of where the GRASS system is actually installed
  170. on the machine. For example, to run the module <i>sroff</i> in the GRASS
  171. <tt>etc</tt> directory:
  172. \code
  173. char command[200];
  174. sprintf(command, "%s/etc/sroff", G_gisbase());
  175. G_spawn(command, "sroff", NULL);
  176. \endcode
  177. The following two routines return full path UNIX directory names. They
  178. should be used only in special cases. They are used by other routines
  179. in the library to build full UNIX file names for database
  180. files. <B>The programmer should not use the next two routines to
  181. bypass the normal database access routines.</B>
  182. - G_gisdbase() top level database directory
  183. Returns the full UNIX path name of the directory which holds the
  184. database locations. See \ref GISDBASE for a full explanation of this
  185. directory.
  186. - G_location_path() current location directory
  187. Returns the full UNIX path name of the current database location. For
  188. example, if the user is working in location <I>spearfish</I> in the
  189. <tt>/home/user/grassdata</tt> database directory, this routine will
  190. return a string which looks like
  191. <tt>/home/user/grassdata/spearfish</tt>.
  192. These next routines provide the low-level management of the
  193. information in the user's GRASS environment file. <B>They should not
  194. be used in place of the higher level interface routines described
  195. above.</B>
  196. - G_getenv()
  197. - G__getenv()
  198. These routines look up the variable <em>name</em> in the GRASS
  199. environment and return its value (which is a character string). If
  200. <em>name</em> is not set, G_getenv() issues an error message and calls
  201. exit(). G__setenv() just returns the NULL pointer.
  202. - G_setenv()
  203. - G__setenv()
  204. These routines set the the GRASS environment variable <em>name</em> to
  205. <em>value</em>. If <em>value</em> is NULL, the <em>name</em> is unset.
  206. Both routines set the value in module memory, but only G_setenv()
  207. writes the new value to the user's GRASS environment file.
  208. \section dbaseaccess Fundamental Database Access Routines
  209. The routines described in this section provide the low-level interface
  210. to the GRASS database. They search the database for files, prompt the
  211. user for file names, open files for reading or writing, etc. The
  212. programmer should never bypass this level of database interface. These
  213. routines must be used to access the GRASS database unless there <b>are
  214. other higher level library routines which perform the same
  215. function</b>. For example, routines to process raster files (see \ref
  216. Raster_File_Processing), vector files (see \ref
  217. Vector_File_Processing), etc., should be used instead.
  218. In the descriptions below, the term database <i>element</i> is used.
  219. Elements are subdirectories within a mapset and are associated with a
  220. specific GRASS data type. For example, raster files live in the "cell"
  221. and "fcell" element. See \ref Elements for more details.
  222. \subsection Fully_Qualified_File_Names Fully Qualified File Names
  223. All GRASS routines which access database files must be given both the
  224. file name and the mapset where the file resides. Often the name and
  225. the mapset are 2 distinct character strings. However, there is a need
  226. for a single character string which contains both the name and the
  227. mapset (e.g., for interactive interfacing to command-line
  228. programs). This form of the name is known as the <em>fully qualified
  229. file name</em> and is built by the following routine:
  230. - G_fully_qualified_name()
  231. Returns a fully qualified name for the file <i>name</i> in
  232. <i>mapset</i> Currently this string is in the form <i>name@mapset</i>,
  233. but the programmer should pretend not to know this and always call
  234. this routine to get the fully qualified name.
  235. The following example shows how an interactive version of <tt>d.rast</tt>
  236. interfaces with the command-line version of <tt>d.rast</tt>:
  237. \code
  238. #include <stdlib.h>
  239. #include <grass/gis.h>
  240. int main(int argc, char *argv[])
  241. {
  242. char name[GNAME_MAX], *mapset, *fqn;
  243. char command[1024];
  244. G_gisinit(argv[0]);
  245. mapset = G_ask_cell_old("", name);
  246. if (mapset == NULL)
  247. exit(EXIT_SUCCESS);
  248. fqn = G_fully_qualified_name(name, mapset);
  249. sprintf(command, "d.rast map='%s'", fqn);
  250. G_spawn(command, "d.rast", NULL);
  251. exit(EXIT_SUCCESS);
  252. }
  253. \endcode
  254. \subsection finding Finding Files in the Database
  255. Command line driven module requires a database file name as one of the
  256. command arguments. In this case, the programmer must search the
  257. database to find the mapset where the file resides.
  258. The following routines search the database for files:
  259. - G_find_file()
  260. Look for the file <i>name</i> under the specified <i>element</i> in
  261. the database. The <i>mapset</i> parameter can either be the empty
  262. string "", which means search all the mapsets in the user's current
  263. mapset search path, or it can be a specific mapset, which means. Look
  264. for the file only in this one mapset (for example, in the current
  265. mapset).
  266. If found, the mapset where the file lives is returned. If not found,
  267. the NULL pointer is returned.
  268. If the user specifies a fully qualified file name, (i.e, a name that
  269. also contains the mapset; see \ref Fully_Qualified_File_Names) then
  270. G_find_file() modifies <em>name</em> by eliminating the mapset from
  271. the <em>name</em>.
  272. For example, to find a "paint/labels" file anywhere in the database:
  273. \code
  274. char name[GNAME_MAX];
  275. char *mapset;
  276. if ((mapset = G_find_file("paint/labels", name, "")) == NULL)
  277. /* not found */
  278. \endcode
  279. To check that the file exists in the current mapset:
  280. \code
  281. char name[GNAME_MAX];
  282. if (G_find_file("paint/labels", name, G_mapset()) == NULL)
  283. /* not found */
  284. \endcode
  285. \subsection Legal_File_Names Legal File Names
  286. Not all names that a user may enter will be legal files for the GRASS
  287. databases. The routines which create new files require that the new
  288. file have a legal name. If the name is obtained from the command line,
  289. the programmer must check that the name is legal. The following
  290. routine checks for legal file names:
  291. - G_legal_filename()
  292. \subsection Opening_an_Existing_Database_File_for_Reading Opening an Existing Database File for Reading
  293. The following routines open the file <i>name</i> in <i>mapset</i> from
  294. the specified database <i>element</i> for <b>reading</b> (but not for
  295. writing). The file <i>name</i> and <i>mapset</i> can be obtained using
  296. G_find_file().
  297. The database file <i>name</i> under the <i>element</i> in the
  298. specified <i>mapset</i> is opened for reading (but not for writing).
  299. - G_open_old()
  300. The UNIX open() routine is used to open the file. If the file does not
  301. exist, -1 is returned. Otherwise the file descriptor from the open()
  302. is returned.
  303. - G_fopen_old()
  304. The UNIX fopen() routine, with "r" read mode, is used to open the
  305. file. If the file does not exist, the NULL pointer is
  306. returned. Otherwise the file descriptor from the fopen() is returned.
  307. \subsection Opening_an_Existing_Database_File_for_Update Opening an Existing Database File for Update
  308. The following routines open the file <i>name</i> in the current mapset
  309. from the specified database <i>element</i> for <b>writing</b>. The
  310. file must exist. Its <i>name</i> can be obtained using G_find_file().
  311. The database file <i>name</i> under the <i>element</i> in the current
  312. mapset is opened for reading and writing.
  313. - G_open_update()
  314. The UNIX open() routine is used to open the file. If the file does not
  315. exist, -1 is returned. Otherwise the file is positioned at the end of
  316. the file and the file descriptor from the open() is returned.
  317. - G_fopen_append()
  318. The UNIX fopen() routine, with "a" append mode, is used to open the
  319. file. If the file does not exist, the NULL pointer is
  320. returned. Otherwise the file is positioned at the end of the file and
  321. the file descriptor from the fopen() is returned.
  322. \subsection Creating_and_Opening_a_New_Database_File Creating and Opening a New Database File
  323. The following routines create the new file <i>name</i> in the current
  324. mapset (GRASS does not allow files to be created outside the current
  325. mapset; see \ref Database_Access_Rules) under the specified database
  326. <i>element</i> and open it for writing. The database <i>element</i> is
  327. created, if it does not already exist.
  328. The file <i>name</i> is obtained noninteractively (e.g., from the
  329. command line), G_legal_filename() should be called first to make sure
  330. that <i>name</i> is a valid GRASS file name. <b>Warning:</b> It is not
  331. an error for <i>name</i> to already exist. However, the file will be
  332. removed and recreated empty. G_find_file() could be used to see if
  333. <i>name</i> exists.
  334. The database file <i>name</i> under the <i>element</i> in the current
  335. mapset is created and opened for writing (but not reading).
  336. - G_open_new()
  337. The UNIX open() routine is used to open the file. If the file does not
  338. exist, -1 is returned. Otherwise the file is positioned at the end of
  339. the file and the file descriptor from the open() is returned.
  340. - G_fopen_new()
  341. The UNIX fopen() routine, with "w" write mode, is used to open the
  342. file. If the file does not exist, the NULL pointer is
  343. returned. Otherwise the file is positioned at the end of the file and
  344. the file descriptor from the fopen() is returned.
  345. \subsection Database_File_Management Database File Management
  346. The following routines allow the renaming and removal of database
  347. files in the current mapset (These functions only apply to the current
  348. mapset since GRASS does permit users to modify things in mapsets other
  349. than the current mapset; see \ref Database_Access_Rules).
  350. - G_rename() rename a database file
  351. - G_remove() remove a database file
  352. <b>Note:</b> These functions only apply to the specific <i>element</i>
  353. and not to other "related" elements. For example, if <i>element</i> is
  354. "cell", then the specified raster file will be removed (or renamed),
  355. but the other support files, such as "cellhd" or "cats", will not. To
  356. remove these other files as well, specific calls must be made for each
  357. related <i>element</i>.
  358. \section Region Region
  359. The region concept is explained in \ref Region. It can be thought of as a
  360. two-dimensional matrix with known boundaries and rectangular cells.
  361. There are logically two different regions. The first is the database
  362. region that the user has set in the current mapset. The other is the
  363. region that is active in the module. This active module region is what
  364. controls reading and writing of raster file data. The vector map
  365. export does not take care for the active region settings.
  366. The routines described below use a GRASS data structure
  367. <tt>Cell_head</tt> to hold region information. This structure is
  368. defined in the "gis.h" header file. It is discussed in detail under
  369. \ref GIS_Library_Data_Structures.
  370. \subsection Database_Region Database Region
  371. Reading and writing the user's database region are done by the
  372. following routines:
  373. Note: Previous versions of GRASS called this the "window". Due to
  374. overuse of this term (database window, graphics window, etc.), the
  375. term was changed to "region". However, to maintain compatibility with
  376. existing programs, library routine names were not changed - hence the
  377. term "window" is used in the routine name (where "region" should
  378. probably be used instead).
  379. - G_get_window()
  380. Reads the database region as stored in the WIND file in the user's
  381. current mapset into region.
  382. An error message is printed and exit() is called if there is a problem
  383. reading the region.
  384. <b>Note:</b> GRASS applications that read or write raster files should
  385. not use this routine since its use implies that the active module
  386. region will not be used. Programs that read or write raster file data
  387. (or vector data) can query the active module region using
  388. G_window_rows() and G_window_cols().
  389. - G_put_window()
  390. Writes the database region file (WIND) in the user's current mapset
  391. from region.
  392. <b>Warning:</b> Since this routine actually changes the database
  393. region, it should only be called by modules which the user knows will
  394. change the region. It is probably fair to say that only the
  395. <tt>g.region</tt> should call this routine.
  396. There is another database region. This region is the default region
  397. for the location. The default region provides the user with a
  398. "starting" region, i.e., a region to begin with and return to as a
  399. reference point. The GRASS modules <tt>g.region</tt> allow the user to
  400. set their database region from the default region (see \ref
  401. Permanent_Mapset for a discussion of the default region). The
  402. following routine reads this region:
  403. - G_get_default_window()
  404. \subsection Active_Module_Region Active Module Region
  405. The <em>active module region</em> is the one that is used when reading
  406. and writing raster file data. This region determines the resampling
  407. when reading raster data. It also determines the extent and resolution
  408. of new raster files.
  409. Initially the active module region and the user's database region are
  410. the same, but the programmer can make them different. The following
  411. routines manage the active module region.
  412. - G_window_rows() number of rows in active region
  413. - G_window_cols() number of columns in active region
  414. These routines return the number of rows and columns (respectively) in
  415. the active module region. Before raster files can be read or written,
  416. it is necessary to known how many rows and columns are in the active
  417. region. For example:
  418. \code
  419. int nrows, cols;
  420. int row, col;
  421. nrows = G_window_rows();
  422. ncols = G_window_cols();
  423. for (row = 0; row < nrows; row++) {
  424. /* read row ... */
  425. for (col = 0; col < ncols; col++) {
  426. /* process col ... */
  427. }
  428. }
  429. \endcode
  430. - G_set_window() set the active region
  431. This routine sets the active region from given region. Setting the
  432. active region does not change the WIND file in the database. It simply
  433. changes the region for the duration of the module.
  434. However, the new region setting is not retained across the UNIX exec()
  435. call. This implies that G_set_window() cannot be used to set the
  436. region for a module to be executed using the system() or popen()
  437. routines.
  438. <b>Note:</b> This routine overrides the region as set by the user. Its
  439. use should be very limited since it changes what the user normally
  440. expects to happen. If this routine is not called, then the active
  441. region will be the same as what is in the user's WIND file.
  442. <b>Warning:</b> Calling this routine with already opened raster files
  443. has some side effects. If there are raster files which are open for
  444. reading, they will be read into the newly set region, not the region
  445. that was active when they were opened. However, CELL buffers allocated
  446. for reading the raster files are not automatically reallocated. The
  447. module must reallocate them explicitly. Also, this routine does not
  448. change the region for raster files which are open for writing. The
  449. region that was active when the open occurred still applies to these
  450. files.
  451. - G_get_set_window() get the active region
  452. Gets the values of the currently active region into region. If
  453. G_set_window() has been called, then the values set by that call are
  454. retrieved. Otherwise the user's database region is retrieved.
  455. <b>Note:</b> For modules that read or write raster data, and really
  456. need the full region information, this routine is preferred over
  457. G_get_window(). However, since G_window_rows() and G_window_cols()
  458. return the number of rows and columns in the active region, the
  459. programmer should consider whether or not the full region information
  460. is really needed before using this routine.
  461. - G_align_window() align two regions
  462. Modifies the input region to align to the reference region. The
  463. resolutions in region are set to match those in refefence region and
  464. the region edges (north, south, east, west) are modified to align with
  465. the grid of the reference region.
  466. The <i>region</i> may be enlarged if necessary to achieve the
  467. alignment. The north is rounded northward, the south southward, the
  468. east eastward and the west westward.
  469. - G_col_to_easting()
  470. Converts a column relative to a region to an easting.
  471. <b>Note:</b> col is a double: col+0.5 will return the easting for the
  472. center of the column; col+0.0 will return the easting for the western
  473. edge of the column; and col+1.0 will return the easting for the
  474. eastern edge of the column.
  475. - G_row_to_northing()
  476. Converts a row relative to a region to a northing.
  477. <b>Note:</b> row is a double: row+0.5 will return the northing for the
  478. center of the row; row+0.0 will return the northing for the northern
  479. edge of the row; and row+1.0 will return the northing for the southern
  480. edge of the row.
  481. - G_easting_to_col()
  482. Converts an easting relative to a region to a column.
  483. <b>Note:</b> The result is a double. Casting it to an integer will
  484. give the column number.
  485. - G_northing_to_row()
  486. Converts a northing relative to a region to a row.
  487. <b>Note:</b> the result is a double. Casting it to an integer will
  488. give the row number.
  489. \section Projection_Information Projection Information
  490. The following routines return information about the cartographic
  491. projection and zone. See \ref Region for more information about these
  492. values.
  493. - G_projection()
  494. This routine returns a code indicating the projection for the active
  495. region. The current values are:
  496. - PROJECTION_XY - unreferenced x,y (imagery data)
  497. - PROJECTION_UTM - UTM
  498. - PROJECTION_SP - State Plane
  499. - PROJECTION_LL - Latitude-Longitude
  500. - PROJECTION_OTHER - Other (more than 121 projections are supported)
  501. - G_database_projection_name()
  502. Returns a pointer to a string which is a printable name for projection
  503. code (as returned by G_projection()).
  504. - G_database_unit_name()
  505. Returns a string describing the database grid units.
  506. - G_database_units_to_meters_factor()
  507. Returns a factor which converts the grid unit to meters (by
  508. multiplication). If the database is not metric (eg. imagery) then 0.0
  509. is returned.
  510. - G_zone()
  511. This routine returns the zone for the active region. The meaning for
  512. the zone depends on the projection. For example zone 18 for projection
  513. type 1 would be UTM zone 18.
  514. \subsection Latitude_Longitude_Databases Latitude-Longitude GIS Databases
  515. GRASS supports databases in a longitude-latitude grid using a
  516. projection where the x coordinate is the longitude and the y
  517. coordinate is the latitude. This projection is called the Equidistant
  518. Cylindrical Projection (also known as Plate Carree). ECP has the
  519. property that <em>where am I</em> and <em>row-column</em> calculations
  520. are identical to those in planimetric grids (like UTM, Universal
  521. Transverse Mercator Projection). This implies that normal GRASS
  522. registration and overlay functions will work without any special
  523. considerations or modifications to existing code. However, the
  524. projection is not planimetric. This means that distance and area
  525. calculations are no longed Euclidean.
  526. Also, since the world is round, maps may not have edges in the
  527. east-west direction, especially for global databases. Maps may have
  528. the same longitude at both the east and west edges of the
  529. display. This feature, called global wraparound, must be accounted for
  530. by GRASS modules (particularly vector based functions, like plotting).
  531. What follows is a description of the GIS Library routines that are
  532. available to support latitude-longitude databases.
  533. \subsection Coordinates Coordinates
  534. Latitudes and longitudes are specified in degrees. Northern latitudes
  535. range from 0 to 90 degrees, and southern latitudes from 0 to
  536. -90. Longitudes have no limits since longitudes ±360 degrees are
  537. equivalent.
  538. Coordinates are represented in ASCII using the format
  539. <tt>dd:mm:ssN</tt> or <tt>dd:mm:ssS</tt> for latitudes,
  540. <tt>ddd:mm:ssE</tt> or <tt>ddd.mm.ssW</tt> for longitudes, and
  541. <tt>dd.mm.ss</tt> for grid resolution. For example, 80:30:24N
  542. represents a northern latitude of 80 degrees, 30 minutes, and 24
  543. seconds. 120:15W represents a longitude 120 degrees and 15 minutes
  544. west of the prime meridian. 30:15 represents a resolution of 30
  545. degrees and 15 minutes. These next routines convert between ASCII
  546. representations and the machine representation for a coordinate. They
  547. work both with latitude-longitude projections and planimetric
  548. projections.
  549. <b>Note:</b> In each subroutine, the programmer must specify the
  550. projection number. If the projection number is PROJECTION_LL (defined
  551. in "gis.h"), then latitude-longitude ASCII format is invoked.
  552. Otherwise, a standard floating-point to ASCII conversion is made.
  553. - G_format_easting() easting to ASCII
  554. - G_format_northing() northing to ASCII
  555. Converts the double representation of the given coordinate to its
  556. ASCII representation.
  557. - G_format_resolution()
  558. Converts the double representation of the resolution to its
  559. ASCII representation.
  560. - G_scan_easting() ASCII easting to double
  561. - G_scan_northing() ASCII northing to double
  562. Converts the ASCII coordinate string in to its double representation.
  563. - G_scan_resolution() ASCII resolution to double
  564. Converts the ASCII "resolution" string to its double representation
  565. (into resolution).
  566. The following are examples of how these routines are used.
  567. \code
  568. double north;
  569. char buf[50];
  570. G_scan_northing(buf, north, G_projection()); /* ASCII to double */
  571. G_format_northing(north, buf, G_projection()); /* double to ASCII */
  572. G_format_northing(north, buf, -1); /* double to ASCII */
  573. /* This last example forces floating-point ASCII format */
  574. \endcode
  575. \subsection Global_Wraparound Global Wraparound
  576. These next routines provide a mechanism for determining the relative
  577. position of a pair of longitudes. Since longitudes of ±360 are
  578. equivalent, but GRASS requires the east to be bigger than the west,
  579. some adjustment of coordinates is necessary.
  580. - G_adjust_easting()
  581. Returns east larger than west. If the region projection is
  582. PROJECTION_LL, then this routine returns an equivalent <i>east</i>
  583. that is larger, but no more than 360 degrees larger, than the
  584. coordinate for the western edge of the region. Otherwise no adjustment
  585. is made and the original <i>east</i> is returned.
  586. - G_adjust_east_longitude()
  587. This routine returns an equivalent <i>east</i> that is larger, but no
  588. more than 360 larger than the <i>west</i> coordinate.
  589. This routine should be used only with latitude-longitude coordinates.
  590. - G_shortest_way()
  591. Returns shortest way between eastings.
  592. \subsection Miscellaneous Miscellaneous
  593. - G_ellipsoid_name()
  594. This routine returns a pointer to a string containing the name for the
  595. ellipsoid in the GRASS ellipsoid table. It can be used as follows:
  596. \code
  597. int n;
  598. char *name;
  599. for(n = 0; name = G_ellipsoid_name(n); n++)
  600. fprintf(stdout, "%s\n", name);
  601. \endcode
  602. - G_get_ellipsoid_by_name()
  603. This routine returns the semi-major axis (in meters) and
  604. eccentricity squared for the named ellipsoid.
  605. - G_get_ellipsoid_parameters()
  606. This routine returns the semi-major axis (in meters) and the
  607. eccentricity squared for the ellipsoid associated with the
  608. database. If there is no ellipsoid explicitly associated with the
  609. database, it returns the values for the WGS 84 ellipsoid.
  610. - G_meridional_radius_of_curvature()
  611. Returns the meridional radius of curvature at a given longitude:
  612. \f$
  613. \rho = \frac{a (1-e^2)}{(1-e^2\sin^2 lon)^{3/2}}
  614. \f$
  615. - G_transverse_radius_of_curvature()
  616. Returns the transverse radius of curvature at a given longitude:
  617. \f$
  618. \nu = \frac{a}{(1-e^2\sin^2 lon)^{1/2}}
  619. \f$
  620. - G_radius_of_conformal_tangent_sphere()
  621. Returns the radius of the conformal sphere tangent to ellipsoid at a
  622. given longitude:
  623. \f$
  624. r = \frac{a (1-e^2)^{1/2}}{(1-e^2\sin^2 lon)}
  625. \f$
  626. - G_pole_in_polygon()
  627. For latitude-longitude coordinates, this routine determines if the
  628. polygon contains one of the poles.
  629. \section Calculations Calculations
  630. \subsection Raster_Area_Calculations Raster Area Calculations
  631. The following routines perform area calculations for raster maps.
  632. They are based on the fact that while the latitude-longitude grid is
  633. not planimetric, the size of the grid cell at a given latitude is
  634. constant. The first routines work in any projection.
  635. - G_begin_cell_area_calculations()
  636. This routine must be called once before any call to
  637. G_area_of_cell_at_row(). It can be used in either planimetric
  638. projections or the latitude-longitude projection.
  639. - G_area_of_cell_at_row()
  640. This routine returns the area in square meters of a cell in the
  641. specified row. This value is constant for planimetric grids and varies
  642. with the row if the projection is latitude-longitude.
  643. - G_begin_zone_area_on_ellipsoid()
  644. Initializes raster area calculations for an ellipsoid.
  645. - G_area_for_zone_on_ellipsoid()
  646. Returns the area between latitudes scaled by the factor passed to
  647. G_begin_zone_area_on_ellipsoid().
  648. - G_begin_zone_area_on_sphere()
  649. Initializes raster area calculations for a sphere.
  650. - G_area_for_zone_on_sphere()
  651. Returns the area between latitudes.
  652. \subsection Polygonal_Area_Calculations Polygonal Area Calculations
  653. These next routines provide area calculations for polygons. Some of
  654. the routines are specifically for latitude-longitude, while others
  655. will function for all projections.
  656. However, there is an issue for latitude-longitude that does not occur
  657. with planimetric grids. Vector/polygon data is described as a series
  658. of x,y coordinates. The lines connecting the points are not stored but
  659. are inferred. This is a simple, straight-forward process for
  660. planimetric grids, but it is not simple for latitude-longitude. What
  661. is the shape of the line that connects two points on the surface of a
  662. globe?
  663. One choice (among many) is the shortest path from <tt>x1,y1</tt> to
  664. <tt>x2,y2</tt>, known as the geodesic. Another is a straight line on
  665. the grid. The area routines described below assume the
  666. latter. Routines to work with the former have not yet been developed.
  667. - G_begin_polygon_area_calculations()
  668. This initializes the polygon area calculation routines. It is used
  669. both for planimetric and latitude-longitude projections.
  670. - G_area_of_polygon()
  671. Returns the area in square meters of the polygon. It is used both for
  672. planimetric and latitude-longitude projections.
  673. <B>Note.</B> If the database is planimetric with the non-meter grid,
  674. this routine performs the required unit conversion to produce square
  675. meters.
  676. - G_planimetric_polygon_area()
  677. Return the area in map units of the polygon,
  678. - G_begin_ellipsoid_polygon_area()
  679. This initializes the polygon area calculations for the ellipsoid.
  680. - G_ellipsoid_polygon_area()
  681. Returns the area in square meters of the polygon for latitude-longitude
  682. grids.
  683. <b>Note:</b> This routine assumes grid lines on the connecting the
  684. vertices (as opposed to geodesics).
  685. \subsection Distance_Calculations Distance Calculations
  686. Two routines perform distance calculations for any projection.
  687. - G_begin_distance_calculations()
  688. Initializes the distance calculations. It is used both for the
  689. planimetric and latitude-longitude projections.
  690. - G_distance()
  691. This routine computes the distance between two points in meters.
  692. - G_begin_geodesic_distance()
  693. Initializes the distance calculations for the ellipsoid. It is used
  694. only for the latitude-longitude projection.
  695. - G_geodesic_distance() geodesic distance
  696. Calculates the geodesic distance between two points in meters.
  697. The calculation of the geodesic distance is fairly costly. These next
  698. three routines provide a mechanism for calculating distance with two
  699. fixed latitudes and varying longitude separation.
  700. - G_set_geodesic_distance_lat1() set the first latitude.
  701. - G_set_geodesic_distance_lat2() set the second latitude.
  702. - G_geodesic_distance_lon_to_lon()
  703. Calculates the geodesic distance between two points set by
  704. G_set_geodesic_distance_latl() and G_set_geodesic_distance_lat2().
  705. \section General_Plotting_Routines General Plotting Routines
  706. The following routines form the foundation of a general purpose line
  707. and polygon plotting capability.
  708. - G_bresenham_line()
  709. Draws a line from one point to another using Bresenham's
  710. algorithm. A routine to plot points must be provided, as is defined
  711. as: <tt>point(x, y)</tt> plot a point at x,y.
  712. This routine does not require a previous call to G_setup_plot() to
  713. function correctly, and is independent of all following routines.
  714. - G_setup_plot()
  715. Initializes the plotting capability. This routine must be called once
  716. before calling the G_plot_*() routines described below.
  717. - G_plot_line()
  718. Plots line between latlon coordinates. This routine handles global
  719. wrap-around for latitude-longitude databases. See G_setup_plot() for
  720. the required coordinate initialization procedure.
  721. - G_plot_polygon()
  722. Plots filled polygon with n vertices. See G_setup_plot() for the
  723. required coordinate initialization procedure.
  724. - G_plot_area()
  725. Plots multiple polygons. Like G_plot_polygon(), except it takes a set
  726. of polygons, each with n vertices, where the number of polygons is
  727. specified with the <i>rings</i> argument. It is especially useful for
  728. plotting vector areas with interior islands.
  729. - G_plot_where_en()
  730. The pixel coordinates <i>x,y</i> are converted to map coordinates
  731. <i>east,north</i>. See G_setup_plot() for the required coordinate
  732. initialization procedure.
  733. - G_plot_where_xy()
  734. The map coordinates <i>east,north</i> are converted to pixel
  735. coordinates <i>x,y</i>. See G_setup_plot() for the required
  736. coordinate initialization procedure.
  737. - G_plot_fx()
  738. \section Temporary_Files Temporary Files
  739. Often it is necessary for modules to use temporary files to store
  740. information that is only useful during the module run. After the
  741. module finishes, the information in the temporary file is no longer
  742. needed and the file is removed. Commonly it is required that
  743. temporary file names be unique from invocation to invocation of the
  744. module. It would not be good for a fixed name like "/tmp/mytempfile"
  745. to be used. If the module were run by two users at the same time, they
  746. would use the same temporary file. In addition systematic use of the
  747. /tmp directory could leave the system vulnerable to symlink attacks.
  748. The following routine generates temporary file names which are unique
  749. within the module and across all GRASS programs.
  750. - G_tempfile()
  751. This routine returns a pointer to a string containing a unique file
  752. name that can be used as a temporary file within the
  753. module. Successive calls to G_tempfile() will generate new names.
  754. Only the file name is generated. The file itself is not created. To
  755. create the file, the module must use standard UNIX functions which
  756. create and open files, e.g., creat() or fopen().
  757. The programmer should take reasonable care to remove (unlink) the file
  758. before the module exits. However, GRASS database management will
  759. eventually remove all temporary files created by G_tempfile() that
  760. have been left behind by the modules which created them.
  761. <b>Note:</b> The temporary files are created in the GRASS database
  762. rather than under <tt>/tmp</tt>. This is done for two reasons. The
  763. first is to increase the likelihood that enough disk is available for
  764. large temporary files since /tmp may be a very small file system. The
  765. second is so that abandoned temporary files can be automatically
  766. removed (but see the warning below).
  767. <b>Warning:</b> The temporary files are named, in part, using the
  768. process id of the module. GRASS database management will remove these
  769. files only if the module which created them is no longer
  770. running. However, this feature has a subtle trap. Programs which
  771. create child processes (using the UNIX fork(), see also G_fork()
  772. routine) should let the child call G_tempfile(). If the parent does it
  773. and then exits, the child may find that GRASS has removed the
  774. temporary file since the process which created it is no longer
  775. running.
  776. \section String_Manipulation_Functions String Manipulation Functions
  777. This section describes some routines which perform string manipulation.
  778. Strings have the usual C meaning: a NULL terminated array of characters.
  779. These next 3 routines remove unwanted white space from a single string.
  780. - G_squeeze()
  781. Leading and trailing white space is removed from the string and
  782. internal white space which is more than one character is reduced to a
  783. single space character. White space here means spaces, tabs,
  784. linefeeds, newlines, and formfeeds.
  785. - G_strip()
  786. Leading and trailing white space is removed from the string. White
  787. space here means only spaces and tabs. There is no return value.
  788. - G_chop()
  789. Chop leading and trailing white spaces: space, &#92;f, &#92;n, &#92;r,
  790. &#92;t, &#92;v.
  791. The next routines replaces character(s) from string.
  792. - G_strchg()
  793. Replace all occurencies of character in string with new.
  794. This next routine copies a string to allocated memory.
  795. - G_store()
  796. This routine allocates enough memory to hold the string, and returns a
  797. pointer to the allocated memory.
  798. The next 2 routines convert between upper and lower case.
  799. - G_tolcase()
  800. Upper case letters in the string are converted to their lower case
  801. equivalent.
  802. - G_toucase()
  803. Lower case letters in the string are converted to their upper case
  804. equivalent.
  805. - G_trim_decimal()
  806. This routine remove trailing zeros from decimal number for example:
  807. 23.45000 would come back as 23.45.
  808. - G_index()
  809. - G_rindex()
  810. Get position of delimiter.
  811. - G_strcasecmp()
  812. - G_strncasecmp()
  813. String compare ignoring case (upper or lower).
  814. - G_strcasestr()
  815. Return a pointer to the first occurrence of subString in mainString,
  816. or NULL if no occurrences are found.
  817. - G_strdup()
  818. Returns a pointer to a string that is a duplicate of the string given
  819. to G_strdup. The duplicate is created using malloc. If unable to
  820. allocate the required space, NULL is returned.
  821. \section Enhanced_UNIX_Routines Enhanced UNIX Routines
  822. A number of useful UNIX library routines have side effects which are
  823. sometimes undesirable. The routines here provide the same functions as
  824. their corresponding UNIX routine, but with different side effects.
  825. \subsection Running_in_the_Background Running in the Background
  826. The standard UNIX <em>fork()</em> routine creates a child process which is a
  827. copy of the parent process. The fork() routine is useful for placing a
  828. module into the background. For example, a module that gathers input
  829. from the user interactively, but knows that the processing will take a
  830. long time, might want to run in the background after gathering all the
  831. input. It would fork() to create a child process, the parent would
  832. exit() allowing the child to continue in the background, and the user
  833. could then do other processing.
  834. However, there is a subtle problem with this logic. The fork() routine does not
  835. protect child processes from keyboard interrupts even if the parent is no longer
  836. running. Keyboard interrupts will also kill background processes that do not
  837. protect themselves.
  838. <i>Note:</i> Programmers who use Bash know that programs run in the
  839. background (using & on the command line) are not automatically
  840. protected from keyboard interrupts. To protect a command that is run
  841. in the background, Bash users must do nohup command &. Programmers
  842. who use the C Shell (or other variants) do not know, or forget that
  843. the C-shell automatically protects background processes from keyboard
  844. interrupts.
  845. Thus a module which puts itself in the background may never finish if
  846. the user interrupts another module which is running at the keyboard.
  847. \subsection Partially_Interruptible_System_Call Partially Interruptible System Call
  848. The UNIX <em>system()</em> call allows one program, the parent, to
  849. execute another UNIX command or module as a child process, wait for
  850. that process to complete, and then continue. The problem addressed
  851. here concerns interrupts. During the standard system() call, the child
  852. process inherits its responses to interrupts from the parent. This
  853. means that if the parent is ignoring interrupts, the child will ignore
  854. them as well. If the parent is terminated by an interrupt, the child
  855. will be also.
  856. Note that code which uses system() or popen() tends to be error-prone,
  857. particularly on Windows. We strongly discourage anyone from using
  858. either system() or popen() in the GRASS code. If you don't need to
  859. communicate with the child process via a pipe, you can use G_spawn()
  860. or G_spawn_ex(). These provide similar functionality to system() but
  861. without the shell getting in the way (using the shell creates problems
  862. if filenames or other arguments contain spaces or other characters
  863. which are significant to the shell). If you need to communicate via a
  864. pipe, you can either use G_spawn_ex() and manage the pipe yourself, or
  865. use popen(). See also G_popen_read() and G_popen_write() which do most of
  866. the work for you. Alternatively, you can use a temporary file rather
  867. than a pipe for communicating with the child process.
  868. \subsection ENDIAN_test ENDIAN test
  869. To test if the user's machine is little or big ENDIAN, the following
  870. function is provided:
  871. - G_is_little_endian()
  872. Test if machine is little or big endian.
  873. \subsection Miscellaneous Miscellaneous
  874. A number of general purpose routines have been provided.
  875. - G_date()
  876. Returns a pointer to a string which is the current date and time. The
  877. format is the same as that produced by the UNIX <tt>date</tt> command.
  878. - G_home()
  879. Returns a pointer to a string which is the full path name of the
  880. user's home directory.
  881. - G_percent()
  882. This routine prints a percentage complete message to stderr. Example:
  883. \code
  884. #include<grass/gis.h>
  885. #include<grass/glocale.h>
  886. int row;
  887. int nrows;
  888. nrows = 1352; /* 1352 is not a special value - example only */
  889. G_message(_("Percent complete:"));
  890. for (row = 0; row < nrows; row++)
  891. G_percent(row, nrows, 10);
  892. \endcode
  893. This will print completion messages at 10% increments; i.e., 10%, 20%,
  894. 30%, etc., up to 100%. Each message does not appear on a new line, but
  895. rather erases the previous message. After 100%, a new line is printed.
  896. - G_program_name()
  897. Routine returns the name of the module as set by the call to
  898. G_gisinit().
  899. - G_whoami()
  900. Returns a pointer to a string which is the user's login name.
  901. \section GIS_Library_Data_Structures GIS Library Data Structures
  902. Some of the data structures, defined in the "gis.h" header file and used
  903. by routines in this library, are described in the sections below.
  904. \subsection struct_Cell_head struct Cell_head
  905. The raster header data structure is used for two purposes. It is used
  906. for raster header information for raster map. It also used to hold
  907. region values.
  908. See documentation of Cell_head structure for details.
  909. The <tt>format</tt> and <tt>compressed</tt> fields apply only to
  910. raster headers. The <tt>format</tt> field describes the number of
  911. bytes per raster data value and the <tt>compressed</tt> field
  912. indicates if the raster file is compressed or not. The other fields
  913. apply both to raster headers and regions. The geographic boundaries
  914. are described by <tt>north, south, east</tt> and <tt>west</tt>. The
  915. grid resolution is described by <tt>ew_res</tt> and
  916. <tt>ns_res</tt>. The cartographic projection is described by
  917. <tt>proj</tt> and the related zone for the projection by
  918. <tt>zone</tt>. The <tt>rows</tt> and <tt>cols</tt> indicate the number
  919. of rows and columns in the raster map, or in the region. See \ref
  920. Raster_Header_File for more information about raster headers, and \ref
  921. Region for more information about regions.
  922. The routines described in \ref Raster_Header_File use this structure.
  923. \subsection struct_Categories struct Categories
  924. The <i>Categories</i> structure contains a title for the map layer,
  925. the largest category in the map layer, an automatic label generation
  926. rule for missing labels, and a list of category labels.
  927. \code
  928. struct Categories
  929. {
  930. CELL ncats; /* total number of categories */
  931. CELL num; /* the highest cell values. Only exists
  932. for backwards compatibility = (CELL)
  933. max_fp_values in quant rules */
  934. char *title; /* name of data layer */
  935. char *fmt; /* printf-like format to generate labels */
  936. float m1; /* multiplication coefficient 1 */
  937. float a1; /* addition coefficient 1 */
  938. float m2; /* multiplication coefficient 2 */
  939. float a2; /* addition coefficient 2 */
  940. struct Quant q; /* rules mapping cell values to index in
  941. list of labels */
  942. char **labels; /* array of labels of size num */
  943. int *marks; /* was the value with this label was used? */
  944. int nalloc;
  945. int last_marked_rule;
  946. };
  947. \endcode
  948. This structure should be accessed using the routines described in
  949. \ref Raster_Category_File.
  950. \subsection struct_Colors struct Colors
  951. The color data structure holds red, green, and blue color intensities
  952. for raster categories. The structure has become so complicated that it
  953. will not be described in this manual.
  954. \code
  955. struct Colors
  956. {
  957. int version; /* set by read_colors: -1=old, 1=new */
  958. DCELL shift;
  959. int invert;
  960. int is_float; /* defined on floating point raster data? */
  961. int null_set; /* the colors for null are set? */
  962. unsigned char null_red;
  963. unsigned char null_grn;
  964. unsigned char null_blu;
  965. int undef_set; /* the colors for cells not in range are set? */
  966. unsigned char undef_red;
  967. unsigned char undef_grn;
  968. unsigned char undef_blu;
  969. struct _Color_Info_ fixed;
  970. struct _Color_Info_ modular;
  971. DCELL cmin;
  972. DCELL cmax;
  973. int organizing;
  974. };
  975. \endcode
  976. The routines described in \ref Raster_Color_Table must be used
  977. to store and retrieve color information using this structure.
  978. \subsection struct_History struct History
  979. The History structure is used to document raster files. The
  980. information contained here is for the user. It is not used in any
  981. operational way by GRASS.
  982. See documentation of History structure for details.
  983. The <i>mapid</i> and <i>mapset</i> are the raster file name and
  984. mapset, <i>title</i> is the raster file title, <i>creator</i> is the
  985. user who created the file, <i>maptype</i> is the map type (which
  986. should always be "raster"), <i>datasrc_1</i> and <i>datasrc_2</i>
  987. describe the original data source, <i>keywrd</i> is a one-line data
  988. description and <i>edhist</i> contains <i>edlinecnt</i> lines of user
  989. comments.
  990. The routines described in \ref Raster_History_File use this structure.
  991. However, there is very little support for manipulating the contents of
  992. this structure. The programmer must manipulate the contents directly.
  993. <b>Note:</b> Some of the information in this structure is not
  994. meaningful. For example, if the raster file is renamed, or copied
  995. into another mapset, the <i>mapid</i> and <i>mapset</i> will no longer
  996. be correct. Also the <i>title</i> does not reflect the true raster
  997. file title. The true title is maintained in the category file.
  998. <b>Warning:</b> This structure has remained unchanged since the inception of
  999. GRASS. There is a good possibility that it will be changed or eliminated in
  1000. future releases.
  1001. \subsection struct_Range struct Range
  1002. The <i>Range</i> (<i>FPRange</i> for floating point raster maps)
  1003. structure contains the minimum and maximum values which occur in a
  1004. raster file.
  1005. \code
  1006. struct Range
  1007. {
  1008. CELL min;
  1009. CELL max;
  1010. int first_time; /* whether or not range was updated */
  1011. };
  1012. struct FPRange
  1013. {
  1014. DCELL min;
  1015. DCELL max;
  1016. int first_time; /* whether or not range was updated */
  1017. };
  1018. \endcode
  1019. The routines described in \ref Raster_Range_File should be used to access
  1020. this structure.
  1021. \section Loading_the_GIS_Library Loading the GIS Library
  1022. The library is loaded by specifying $(GISLIB) in the Makefile. The
  1023. following example is a complete Makefile which compiles code that uses
  1024. this library:
  1025. <b>Makefile for $(GISLIB)</b>
  1026. \verbatim
  1027. MODULE_TOPDIR = ../..
  1028. PGM = r.info
  1029. LIBES = $(GISLIB)
  1030. DEPENDENCIES = $(GISDEP)
  1031. include $(MODULE_TOPDIR)/include/Make/Module.make
  1032. default: cmd
  1033. \endverbatim
  1034. See \ref Compiling_and_Installing_GRASS_Modules for a complete
  1035. discussion of Makefiles.
  1036. \section TimeStamp_functions Timestamp functions
  1037. This structure is defined in "gis.h", but there should be no reason to access its
  1038. elements directly:
  1039. \code
  1040. struct TimeStamp {
  1041. DateTime dt[2]; /* two datetimes */
  1042. int count;
  1043. };
  1044. \endcode
  1045. Using the G_*_timestamp() routines reads/writes a timestamp file in
  1046. the cell_misc/rastername mapset element.
  1047. A TimeStamp can be one DateTime, or two DateTimes representing a
  1048. range. When preparing to write a TimeStamp, the programmer should
  1049. use one of:
  1050. - G_set_timestamp() to set a single DateTime
  1051. - G_set_timestamp_range() to set two DateTimes
  1052. - G_read_raster_timestamp to read raster timestamp
  1053. - G_read_vector_timestamp to read vector timestamp
  1054. - G_get_timestamps() to copy TimeStamp into Datetimes
  1055. Use to copy the TimeStamp information into Datetimes, so the members
  1056. of struct TimeStamp shouldn't be accessed directly.
  1057. - count=0 means no datetimes were copied
  1058. - count=1 means 1 datetime was copied into dt1
  1059. - count=2 means 2 datetimes were copied
  1060. - G_init_timestamp()
  1061. Sets ts-&gt;count = 0, to indicate no valid DateTimes are in TimeStamp.
  1062. - G_set_timestamp()
  1063. Copies a single DateTime to a TimeStamp in preparation for writing
  1064. (overwrites any existing information in TimeStamp).
  1065. - G_set_timestamp_range()
  1066. Copies two DateTimes (a range) to a TimeStamp in preparation for
  1067. writing (overwrites any existing information in TimeStamp).
  1068. - G_write_raster_timestamp()
  1069. - G_write_vector_timestamp()
  1070. - G_write_grid3_timestamp()
  1071. - G_format_timestamp()
  1072. - G_scan_timestamp()
  1073. - G_remove_raster_timestamp()
  1074. - G_remove_vector_timestamp()
  1075. - G_remove_grid3_timestamp()
  1076. Only timestamp files in current mapset can be removed.
  1077. - G_read_grid3_timestamp()
  1078. See \ref DateTime_Library for a complete discussion of GRASS datetime
  1079. routines.
  1080. \section Memory_Allocation Memory Allocation
  1081. The following routines provide memory allocation capability. They are
  1082. simply calls to the UNIX suite of memory allocation routines malloc(),
  1083. realloc() and calloc(), except that if there is not enough memory,
  1084. they print a diagnostic message to that effect and then call exit().
  1085. - G_malloc ()
  1086. Allocates a block of memory at least <i>size</i> bytes which is
  1087. aligned properly for all data types. A pointer to the aligned block is
  1088. returned.
  1089. - G_realloc()
  1090. Changes the <i>size</i> of a previously allocated block of memory at
  1091. <i>ptr</i> and returns a pointer to the new block of memory. The
  1092. <i>size</i> may be larger or smaller than the original size. If the
  1093. original block cannot be extended "in place", then a new block is
  1094. allocated and the original block copied to the new block.
  1095. <b>Note:</b> If <i>ptr</i> is NULL, then this routine simply allocates
  1096. a block of <i>size</i> bytes. This routine works around broken
  1097. realloc() routines, which do not handle a NULL <i>ptr</i>.
  1098. - G_calloc()
  1099. Allocates a properly aligned block of memory <i>n</i>*<i>size</i>
  1100. bytes in length, initializes the allocated memory to zero, and returns
  1101. a pointer to the allocated block of memory.
  1102. - G_free()
  1103. Use the G_free() routine to release memory allocated by
  1104. these routines.
  1105. */