1 /* lexfn.h 2 3 Written by Don Maszle 4 15 October 1991 5 6 Copyright (c) 1991-2017 Free Software Foundation, Inc. 7 8 This file is part of GNU MCSim. 9 10 GNU MCSim is free software; you can redistribute it and/or 11 modify it under the terms of the GNU General Public License 12 as published by the Free Software Foundation; either version 3 13 of the License, or (at your option) any later version. 14 15 GNU MCSim is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with GNU MCSim; if not, see <http://www.gnu.org/licenses/> 22 23 Header file for input definitions. 24 */ 25 26 #ifndef LEXFN_H_DEFINED 27 28 /* ---------------------------------------------------------------------------- 29 Inclusions */ 30 31 #include "lex.h" 32 33 /* ---------------------------------------------------------------------------- 34 Constants */ 35 36 /* Input Function constants */ 37 38 #define IFN_NULL 0 39 #define IFN_CONSTANT 1 40 #define IFN_PERDOSE 2 41 #define IFN_PEREXP 3 42 #define IFN_NDOSES 4 43 #define IFN_SPIKES 5 44 #define IFN_EVENTS 6 45 #define IFN_PERTRANS 7 46 47 /* ---------------------------------------------------------------------------- 48 Typedefs */ 49 50 /* IFN: Predefined input functions 51 52 The parameters of interest vary depending on the type of the function. 53 I know, this should really be a union, but they are kind of messy and 54 this needs to be redone more intelligently anyway. 55 56 At any point in time, dVal is the current value (this is calculated 57 for a given point in time by CalcInputs(). For pulsed inputs, bOn 58 flags whether or not the pulse is active. Dependencies of IFN parms on 59 on model parameters are respected via the handle fields 60 61 Here is what the parms mean: 62 63 IFN_CONSTANT dMag is the constant 64 65 -- Periodic functions: Period = dTper, magnitude = dMag, start time = dT0 66 67 IFN_PERDOSE Periodic dose lasting dTexp 68 IFN_PEREXP Periodic exponential with decay constant dDecay 69 IFN_PERTRANS Periodic transit (analytical multicompartment) Savic model 70 Savic et al., J Pharmacokinet Pharmacodyn. 2007, 34:711. 71 72 -- Multiple pulse functions: 73 74 IFN_NDOSES nDoses of rgMags[] starting at rgT0s[] 75 IFN_SPIKES nDoses spikes of rgMags[] at time rgT0s[] 76 IFN_EVENTS nDoses discontinuities in a state variable 77 */ 78 79 typedef struct tagIFN { 80 /* Bookkeeping */ 81 82 int iType; /* One of the IFN_ types */ 83 BOOL bOn; /* TRUE if exposure is On */ 84 double dTStartPeriod; /* Start of current period */ 85 double dVal; /* Current value: CalcInputs updates */ 86 87 /* Periodic functions */ 88 89 double dMag; /* Magnitude of input */ 90 double dTper; /* Duration of Period */ 91 double dT0; /* Starting time of exposure */ 92 double dTexp; /* Exposure duration */ 93 94 /* For exponential inputs, the exponential decay rate 95 Exposure lasts for N_TAU_EXPOSE Tau periods. (tau=1/Decay) 96 After this, input is considered to be neglible. */ 97 double dDecay; 98 99 /* For Savic's transit model inputs 100 dMag * ((dDecay * t)^n) * exp(-dDecay * t) / n! 101 with n! = SQRT2PI * (n^(n+0.5)) *exp(-n) 102 So we need n, the number of virtual transit compartments (as a double) */ 103 double dNcpt; 104 105 /* Dependencies for the periodic parms */ 106 107 HANDLE hMag; /* Handle to magnitude */ 108 HANDLE hTper; /* Handle to period */ 109 HANDLE hT0; /* Handle to starting time */ 110 HANDLE hTexp; /* Handle to exposure time */ 111 HANDLE hDecay; /* Handle to exponential decay rate */ 112 HANDLE hNcpt; /* Handle to the number of virtual compartments */ 113 114 /* Multiple dose inputs */ 115 116 int nDoses; /* Number of doses of Spikes */ 117 int iDoseCur; /* Current Dose */ 118 119 /* For value input */ 120 PDOUBLE rgT0s; /* Array of start times */ 121 PDOUBLE rgMags; /* Array of magnitudes */ 122 123 /* For variable input */ 124 HANDLE *rghT0s; /* Handles to start times */ 125 HANDLE *rghMags; /* Handles to magnitudes */ 126 127 /* For events */ 128 HANDLE target_state; 129 PINT rgOper; /* Array of operation types */ 130 131 } IFN, *PIFN; /* struct tagIFN */ 132 133 134 /* ---------------------------------------------------------------------------- 135 Prototypes */ 136 137 BOOL DefDepParm (PSTR szLex, PDOUBLE pdValue, HANDLE *phvar); 138 139 int GetFnType (PSTR szName); 140 BOOL GetInputArgs (PINPUTBUF pibIn, PIFN pifn, int n); 141 BOOL GetInputFn (PINPUTBUF pibIn, PSTR sz, PIFN pifn); 142 BOOL GetNDoses (PINPUTBUF pibIn, PSTR szLex, PIFN pifn); 143 BOOL GetNNumbers (PINPUTBUF pibIn, PSTR szLex, int nNumbers, PDOUBLE rgd); 144 BOOL GetSpikes (PINPUTBUF pibIn, PSTR szLex, PIFN pifn); 145 BOOL GetEvents (PINPUTBUF pibIn, PSTR szLex, PIFN pifn); 146 147 void InitIFN (PIFN pifn); 148 149 #define LEXFN_H_DEFINED 150 #endif 151 152 /* End */ 153 154