<br><br><div class="gmail_quote">On Tue, Oct 13, 2009 at 8:37 PM, Andrew Maclean <span dir="ltr"><<a href="mailto:andrew.amaclean@gmail.com">andrew.amaclean@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Darren<br>
I am not sure whether replacing grep with find is worthwhile. For VTK<br>
the search time went from 0.5s to 9.6s when using the grep option.<br>
Would you mind if I put this in as a comment so that people can<br>
uncomment it if they wish?<br>
<br></blockquote><div><br>Using the find command is fine (and looks like it is MUCH faster). Also note that it might be lifted out of the for loops and placed directly after the declaration of the examplePath and testingPath. In fact, if both the example and testing paths are below a root vtk path (as they often are), there could be one path variable and one declaration of the cxx, tcl, py variables to hold the results of the find commands on that root directory. If there is only one root directory, that would eliminate one of the for loops.<br>
<br>(I find it convenient to see the output split up for the example and testing paths. There could be several cxx, tcl, py variables that are specific to each path. The order of the for loops could be switched around -- paths first, then key-words.)<br>
<br>Anyhow, have fun with it!<br><br>Best, Darren<br><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
What do people think?<br>
BTW the VTK version is Examples/SearchScript.sh.<br>
<br>
Regards<br>
Andrew<br>
<br>
<br>
On Wed, Oct 14, 2009 at 5:28 AM, Darren Weber<br>
<div><div></div><div class="h5"><<a href="mailto:darren.weber.lists@gmail.com">darren.weber.lists@gmail.com</a>> wrote:<br>
><br>
> Hi Luis,<br>
><br>
> This version below uses 'grep' options to replace the 'find' utility; the<br>
> grep options provide a case-insensitive search (-i) and recursion through<br>
> directories (-r), with an include pattern to identify file types (.cxx,<br>
> .tcl, .py). The script now has a 'continue' statement if the itkPath<br>
> doesn't exist. (I don't have commit rights to the cvs.)<br>
><br>
> #####BEGIN SCRIPT<br>
> #!/bin/bash<br>
><br>
> if [ $# -lt 1 ]; then<br>
> echo "$0 'search term' ['search term' ...]"<br>
> exit 1<br>
> fi<br>
><br>
> itkExamplePath="/opt/local/share/InsightToolkit/examples"<br>
> itkTestingPath="/opt/local/share/InsightToolkit/testing"<br>
><br>
> for term in $@; do<br>
> echo<br>
> echo "Search term: ${term}"<br>
> for itkPath in "${itkExamplePath}" "${itkTestingPath}"; do<br>
> if [ ! -d ${itkPath} ]; then<br>
> echo "Path not found: ${itkPath}"<br>
> echo "Modify script at $0"<br>
> continue<br>
> fi<br>
> echo "Searching ITK files in: ${itkPath}"<br>
> grep -l -E -i -r --include='*.cxx' --regexp=${term} ${itkPath}<br>
> grep -l -E -i -r --include='*.tcl' --regexp=${term} ${itkPath}<br>
> grep -l -E -i -r --include='*.py' --regexp=${term} ${itkPath}<br>
> done<br>
> done<br>
> #####END SCRIPT<br>
><br>
><br>
><br>
> This is an example run on my OSX-MacPorts system (with InsightToolkit @<br>
> 3.16.0):<br>
><br>
> $ itkSearchExamples.bash 'itkImageRegistrationMethod'<br>
> Search term: itkImageRegistrationMethod<br>
> Searching ITK files in: /opt/local/share/InsightToolkit/examples<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration12.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration13.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration14.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration15.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration4.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration6.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration7.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration8.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration1.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration10.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration11.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration12.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration13.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration14.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration15.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration16.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration17.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration18.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration1o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration2.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration2o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration3.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration3o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration4.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration4o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration5.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration5o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration6.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration6o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration7.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration7o.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration8.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration9.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistrationHistogramPlotter.cxx<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration3.tcl<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration4.tcl<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration5.tcl<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration3.py<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration4.py<br>
> /opt/local/share/InsightToolkit/examples/Registration/ImageRegistration5.py<br>
> Searching ITK files in: /opt/local/share/InsightToolkit/testing<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkAlgorithmsHeaderTest.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkAlgorithmsPrintTest4.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkAlgorithmsTests.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_1.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_10.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_11.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_12.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_13.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_14.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_15.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_16.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_2.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_3.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_4.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_5.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_6.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_7.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_8.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkImageRegistrationMethodTest_9.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkMultiResolutionImageRegistrationMethodTest_1.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkMultiResolutionImageRegistrationMethodTest_2.cxx<br>
> /opt/local/share/InsightToolkit/testing/Code/Algorithms/itkPointSetToImageRegistrationTest_1.cxx<br>
><br>
><br>
><br>
> Regards,<br>
> Darren<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Mon, Oct 12, 2009 at 6:40 PM, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>><br>
> wrote:<br>
>><br>
>> Hi Darren,<br>
>><br>
>> Thanks for the script.<br>
>><br>
>> It has now been committed to the CVS repository as<br>
>><br>
>> Insight/Examples/SearchScript.sh<br>
>><br>
>> ---<br>
>><br>
>> The second script,<br>
>> are you suggesting it as a separate script ?<br>
>> or as an improvement to the first one ?<br>
>><br>
>><br>
>> Please let us know,<br>
>><br>
>><br>
>> Thanks<br>
>><br>
>><br>
>> Luis<br>
>><br>
>><br>
>> ----------------------------<br>
>> On Mon, Oct 12, 2009 at 4:15 PM, Darren Weber<br>
>> <<a href="mailto:darren.weber.lists@gmail.com">darren.weber.lists@gmail.com</a>> wrote:<br>
>> ><br>
>> > Hi Luis,<br>
>> ><br>
>> > Please feel free to distribute it with the LGPL license (or a BSD<br>
>> > license,<br>
>> > or something that is compatible with the ITK license and general OSI<br>
>> > principles).<br>
>> ><br>
>> > For a more portable solution, the itk*Path variables might be obtained<br>
>> > automatically (how?). The search path could be an input parameter (but<br>
>> > that<br>
>> > almost defeats the convenience of this bash wrapper around a grep<br>
>> > process).<br>
>> ><br>
>> > The grep command options list the files where the search term is found<br>
>> > (not<br>
>> > the lines of those files where the search term occurs). For a bit more<br>
>> > value, it's possible to modify the script so that the entire grep loop<br>
>> > returns an array of file paths, which could be piped into something<br>
>> > like:<br>
>> > less -p ${searchTerm} ${fileArray}[@]<br>
>> > Then less would provide the means to page through the files.<br>
>> ><br>
>> > Here is another variation on the same thing - this one searches the<br>
>> > testing<br>
>> > path and it includes the .tcl and .py example files in the search. It<br>
>> > might<br>
>> > be called 'itkSearchFiles.bash' ?<br>
>> ><br>
>> > ###### BEGIN SCRIPT<br>
>> > #!/bin/bash<br>
>> ><br>
>> > if [ $# -lt 1 ]; then<br>
>> > echo "$0 'search term' ['search term' ...]"<br>
>> > exit 1<br>
>> > fi<br>
>> ><br>
>> > itkExamplePath="/opt/local/share/InsightToolkit/examples"<br>
>> > itkTestingPath="/opt/local/share/InsightToolkit/testing/Code"<br>
>> ><br>
>> > for term in $@; do<br>
>> > echo<br>
>> > echo "Search term: ${term}"<br>
>> > for itkPath in "${itkExamplePath}" "${itkTestingPath}" ; do<br>
>> > if [ ! -d ${itkPath} ]; then<br>
>> > echo "Path not found: ${itkPath}"<br>
>> > fi<br>
>> > echo "Searching ITK files in: ${itkPath}"<br>
>> > grep -l -E -e ${term} ${itkPath}/*/*.cxx<br>
>> > grep -l -E -e ${term} ${itkPath}/*/*.tcl<br>
>> > grep -l -E -e ${term} ${itkPath}/*/*.py<br>
>> > done<br>
>> > done<br>
>> > ###### END SCRIPT<br>
>> ><br>
>> ><br>
>> > Take care,<br>
>> > Darren<br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > On Mon, Oct 12, 2009 at 12:26 PM, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Hi Darren,<br>
>> >><br>
>> >> This is really useful !<br>
>> >><br>
>> >> Thank you for sharing it.<br>
>> >><br>
>> >> Do you see any reason for not adding this to the CVS<br>
>> >> repository and distribute it along with ITK ?<br>
>> >><br>
>> >> Please let us know,<br>
>> >><br>
>> >><br>
>> >> Thanks<br>
>> >><br>
>> >><br>
>> >> Luis<br>
>> >><br>
>> >><br>
>> >> ---------------------------------------<br>
>> >> On Mon, Oct 12, 2009 at 2:15 PM, Darren Weber<br>
>> >> <<a href="mailto:darren.weber.lists@gmail.com">darren.weber.lists@gmail.com</a>> wrote:<br>
>> >> ><br>
>> >> > This is a short bash script (grep does the work) to search for terms<br>
>> >> > in<br>
>> >> > the<br>
>> >> > InsightToolkit example files. It's a convenience wrapper that stores<br>
>> >> > the<br>
>> >> > path to the example files (.cxx in this case), the syntax of the grep<br>
>> >> > call,<br>
>> >> > and allows multiple terms to be given at once. Modify the example<br>
>> >> > search<br>
>> >> > path for your purposes (it could be modified to search for the tcl or<br>
>> >> > python<br>
>> >> > examples too). Modify the grep call as you like.<br>
>> >> ><br>
>> >> > #### BEGIN SCRIPT<br>
>> >> > #!/bin/bash<br>
>> >> ><br>
>> >> > if [ $# -lt 1 ]; then<br>
>> >> > echo "$0 'search term' ['search term' ...]"<br>
>> >> > exit 1<br>
>> >> > fi<br>
>> >> ><br>
>> >> > # Search the CXX files<br>
>> >> > itkExamplePath="/opt/local/share/InsightToolkit/examples/*/*.cxx"<br>
>> >> > echo "Searching ITK .cxx files in: ${itkExamplePath}"<br>
>> >> ><br>
>> >> > for term in $@; do<br>
>> >> > echo<br>
>> >> > echo "Search term: ${term}"<br>
>> >> > grep -l -E -e ${term} ${itkExamplePath}<br>
>> >> > done<br>
>> >> > #### END SCRIPT<br>
>> >> ><br>
>> >> > This is an example call on my platform:<br>
>> >> ><br>
>> >> > $ itkSearchExamples.bash 'TransformWriter' 'TransformReader'<br>
>> >> > Searching ITK .cxx files in:<br>
>> >> > /opt/local/share/InsightToolkit/examples/*/*.cxx<br>
>> >> ><br>
>> >> > Search term: TransformWriter<br>
>> >> > /opt/local/share/InsightToolkit/examples/IO/TransformReadWrite.cxx<br>
>> >> ><br>
>> >> > Search term: TransformReader<br>
>> >> > /opt/local/share/InsightToolkit/examples/IO/TransformReadWrite.cxx<br>
>> >> ><br>
>> >> ><br>
>> >> > /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration14.cxx<br>
>> >> ><br>
>> >> ><br>
>> >> > /opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration8.cxx<br>
>> >> ><br>
>> >> > Take care,<br>
>> >> > Darren<br>
>> >> ><br>
>> >> ><br>
>> >> > _____________________________________<br>
>> >> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >> ><br>
>> >> > Visit other Kitware open-source projects at<br>
>> >> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> >> ><br>
>> >> > Please keep messages on-topic and check the ITK FAQ at:<br>
>> >> > <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
>> >> ><br>
>> >> > Follow this link to subscribe/unsubscribe:<br>
>> >> > <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
>> >> ><br>
>> >> ><br>
>> ><br>
>> ><br>
><br>
><br>
> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
<br>
<br>
<br>
</div></div><div><div></div><div class="h5">--<br>
___________________________________________<br>
Andrew J. P. Maclean<br>
Centre for Autonomous Systems<br>
The Rose Street Building J04<br>
The University of Sydney 2006 NSW<br>
AUSTRALIA<br>
Ph: +61 2 9351 3283<br>
Fax: +61 2 9351 7474<br>
URL: <a href="http://www.acfr.usyd.edu.au/" target="_blank">http://www.acfr.usyd.edu.au/</a><br>
___________________________________________<br>
</div></div></blockquote></div><br>