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