Checking for Package Existence???

I suggest a convention for user developed packages that are to provide functions to which other users can interface. I propose, the package should include a directive #define PACKAGE_PackageName (at the top). This will standardize and streamline how a user can test for existence ...

#ifdef PACKAGE_PackageName
   <code segment to compile when package exists>
#else
   <code segment to compile when package does not exist>
#endif


What do others think?
I initially proposed a convention that will not work because #define is local to the given procedure file.

So, here is my problem ...

Procedure File A -> IndependentModule=IMProcA
This procedure file contains a function called DoItA()

Procedure File B -> ModuleName=MNProcB
This procedure file contains a function called DoItB()

Function DoItB()
#if(exists("IMProcA#DoItA")==6)
    DoItA()
#else
    DoMyLocal()
#endif
    return 0
end


(1) When procedure file A is loaded and compiled BEFORE or AT THE SAME TIME that procedure file B is loaded and compiled, the function DoItB() calls DoItA().

(2) When procedure file B is loaded and compiled without procedure file A, DoItB() calls DoMyLocal().

(3) When procedure file B is loaded and compiled, AND THEN procedure file A is loaded and recompiled, DoItB() calls DoMyLocal().

How can I force DoItB() to recall DoItA() in (3)?

Basically, I want to write a procedure that will be aware whether a package is loaded or not, regardless of when the package was loaded - before, during, or after the procedure is compiled.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
I would like to additionally suggest the ability to check for constant and strconstant definitions. Right now, neither:

#if exists("myConstant")

or

#ifdef myConstant

can do this. I'd like to know whether constants are set so I can bypass parts of my code that use them.

Rick
RGerkin wrote:
I would like to additionally suggest the ability to check for constant and strconstant definitions .... so I can bypass parts of my code that use them.


You may have already worked this out ... one suggestion is, when you are defining the constants, also define an associated symbol and test for its existence ...

#define kSetFitConstants
Constant kFitA = 1
Constant kFitB = 2
...

#ifdef kSetFitConstants
   <code when constants defined>
#else
   <code when constants not defined>
#endif


Alternatively, if you need this to work across multiple procedure files (for example, because one procedure file is a module of functions with constants that may or may not be #included for a main procedure file), using a dummy function should work ...

ProcFile A
Constant kFitA = 1
...
Function k_SetFitConstantsA()
    return 0
end
... (rest of procedure file) ...


ProcFile B
#if(exists("k_SetFitConstantsA")==6)
  <... code to run when module A with constants is #included ...>
#else
...
#endif


I agree otherwise with your suggestion. Testing #if(exists("ConstantName")==??) would be more direct. It would also be a reasonable way to have a standardized way to set/test for a package, rather than depending on testing for specific functions within a package ...

ProcFile ScreenSizer.ipf
Constant kPACKAGE_ScreenSizer=1
(... code for ScreenSizer package ...)


ProcFile XXX.ipf
#if(exists("kPACKAGE_ScreenSizer")==???)
  <... code if ScreenSizer package #included ...>
#else
  <... code if ScreenSizer package not #included ...>
#endif


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH