gislib.dox 55 KB

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