The purpose of this function is to provide a portable way of finding the source directory of a program distribution. The directory that is returned is the directory in which the source file using cgSourceDir() resides. The program is useful for distributing applications that have a large number of files in specific program directories (e.g., source, resources, data, etc.).
Utilities
nomark: in, optional, type=boolean, default=0 Normally, the source directory name is returned with a final path separator added to the end of the directory name. Setting this keyword will suppress this final path separator. oneup: in, optional, type=boolean, default=0 Setting this keyword will return the directory just above the source directory in the file hierarchy. twoup: in, optional, type=boolean, default=0 Setting this keyword will return the directory two directories above the source directory in the file hierarchy.
Assume that your application files (and source programs) reside in this root directory:: ../app You have placed a DATA directory immediately under the APP directiory, and a RESOURCES directory immedately under the DATA directory. Your directory structure looks like this:: ../app ; Contains your application and source (*.pro) files. ../app/data ; Contains your application data files. ...app/data/resources ; Contains your application resource files. The end user can install the APP directory wherever he or she likes. In your program, you will identify the DATA and RESOURCES directory like this:: ; Get icon image in resources directory. filename = Filepath(Root_Dir=cgSourceDir(), Subdirectory=['data','resources'], 'myicon.tif') ; Get default image in data directory. filename = Filepath(Root_Dir=cgSourceDir(), Subdirectory='data', 'ctscan.tif') Alternatively, you might set up an application directory structure like this:: ../app ; Contains your application files. ../app/source ; Contains your application source (*.pro) files. ../app/data ; Contains your application data files. ...app/data/resources ; Contains your application resource files. In this case, you would use the ONEUP keyword to find your data and resource files, like this:: ; Get icon image in resources directory. filename = Filepath(Root_Dir=cgSourceDir(/ONEUP), Subdirectory=['data','resources'], 'myicon.tif') ; Get default image in data directory. filename = Filepath(Root_Dir=cgSourceDir(/ONEUP), Subdirectory='data', 'ctscan.tif')
FANNING SOFTWARE CONSULTING:: David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: david@idlcoyote.com Coyote's Guide to IDL Programming: http://www.idlcoyote.com
Change History:: Written by: David W. Fanning, 23 November 2003. Based on program SOURCEROOT, written by Jim Pendleton at RSI (http://www.rsinc.com/codebank/search.asp?FID=35). Added ONEUP keyword. 10 December 2003. DWF. Added TWOUP keyword. 8 June 2007. DWF. Added NOMARK keyword. 8 June 2007. DWF. Renamed from ProgramRootDir and updated to cgSourceDir. 27 Jan 2014. DWF.
Copyright (c) 2003-2014, Fanning Software Consulting, Inc.