g.findfile.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <h2>DESCRIPTION</h2>
  2. <em>g.findfile</em> is designed for Bourne shell or Python scripts
  3. that need to search for mapset <em>elements</em>, including: raster,
  4. vector maps, region definitions
  5. and <em><a href="i.group.html">imagery</a></em> groups.
  6. <p>The list of <b>element</b> names to search for is not fixed; any
  7. subdirectory of the mapset directory is a valid <b>element</b> name.
  8. <p>However, the user can find the list of standard GRASS <b>element</b>
  9. names in the file <tt>$GISBASE/etc/element_list</tt>. This is the file
  10. which <em><a href="g.remove.html">g.remove</a></em>, <em><a href="g.rename.html">g.rename</a></em>
  11. and <em><a href="g.copy.html">g.copy</a></em> use to determine which files
  12. need to be deleted/renamed/copied for a given entity type.
  13. <h2>NOTES</h2>
  14. <em>g.findfile</em> writes four lines to standard output:
  15. <div class="code"><pre>
  16. name='<em>file_name</em>'
  17. mapset='<em>mapset_name</em>'
  18. file='<em>unix_filename</em>'
  19. fullname='<em>grass_fullname</em>'
  20. </pre></div>
  21. The output is <em>Bash</em> commands to set the variable
  22. <em>name</em> to the GRASS data base file name,
  23. <em>mapset</em> to the mapset in which the file resides,
  24. and <em>file</em> to the full UNIX path name for the named
  25. file. These variables may be set in the <em>Bash</em>
  26. as follows:
  27. <div class="code"><pre>
  28. eval `g.findfile element=name mapset=name file=name`
  29. </pre></div>
  30. <h2>EXAMPLES</h2>
  31. <h3>SHELL</h3>
  32. <b>Raster map example:</b>
  33. <div class="code"><pre>
  34. eval `g.findfile element=cell file=elevation`
  35. </pre></div>
  36. If the specified file (here: raster map) does not exist, the variables
  37. will be set as follows:
  38. <div class="code"><pre>
  39. name=
  40. mapset=
  41. fullname=
  42. file=
  43. </pre></div>
  44. The following is a way to test for this case:
  45. <div class="code"><pre>
  46. if [ ! "$file" ]
  47. then
  48. exit 1
  49. fi
  50. </pre></div>
  51. <p>
  52. <b>Vector map example (including error message):</b>
  53. <div class="code"><pre>
  54. eval `g.findfile element=vector file="$G_OPT_V_INPUT"`
  55. if [ ! "$file" ] ; then
  56. g.message -e "Vector map <$G_OPT_V_INPUT> not found"
  57. exit 1
  58. fi
  59. </pre></div>
  60. <h3>PYTHON</h3>
  61. See <em><a href="https://grass.osgeo.org/grass80/manuals/libpython/">Python
  62. Scripting Library</a></em> for more info.
  63. <p>
  64. Note: The Python tab in the <em>wxGUI</em> can be used for entering the
  65. following code:
  66. <p>
  67. <div class="code"><pre>
  68. import grass.script as gcore
  69. gcore.find_file('elevation', element = 'cell')
  70. </pre></div>
  71. <h2>SEE ALSO</h2>
  72. <em>
  73. <a href="g.filename.html">g.filename</a>,
  74. <a href="g.gisenv.html">g.gisenv</a>,
  75. <a href="g.mapsets.html">g.mapsets</a>,
  76. <a href="g.parser.html">g.parser</a>
  77. </em>
  78. <h2>AUTHOR</h2>
  79. Michael Shapiro,
  80. U.S.Army Construction Engineering Research Laboratory