Checking for Package Existence???
jjweimer
#ifdef PACKAGE_PackageName
<code segment to compile when package exists>
#else
<code segment to compile when package does not exist>
#endif
<code segment to compile when package exists>
#else
<code segment to compile when package does not exist>
#endif
What do others think?
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()
#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
April 4, 2008 at 12:22 pm - Permalink
#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
April 5, 2008 at 02:09 pm - Permalink
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 ...
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
...
Function k_SetFitConstantsA()
return 0
end
... (rest of procedure file) ...
ProcFile B
<... 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
(... code for ScreenSizer package ...)
ProcFile XXX.ipf
<... code if ScreenSizer package #included ...>
#else
<... code if ScreenSizer package not #included ...>
#endif
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
April 8, 2008 at 05:51 am - Permalink