/**********
Copyright © 1996 Norlinvest Ltd. All rights reserved.
Visual Code Model Generator, EDSpice, EDWin, EE Designer, CompCAD,
CAD 1000, CAD ABC and Visionics are trade marks of Norlinvest Ltd.
Copyright © 1983 - 1996.
*
*
Copyright 1990 Regents of the University of California.  All rights reserved.
Author: 1986 Thomas L. Quarles
**********/

#ifndef IFSIMULATOR
#define IFSIMULATOR

#include "MIFparse.h"
#include "MIFcmdat.h"

#ifdef __STDC__

typedef void GENERIC;

#else

typedef char GENERIC;

#endif

typedef struct sIFparm {
    char *keyword;
    int id;
    long int dataType;
    char *description;
} IFparm;


typedef GENERIC *IFuid;

#define UID_ANALYSIS 0x1
#define UID_TASK 0x2
#define UID_INSTANCE 0x4
#define UID_MODEL 0x8
#define UID_SIGNAL 0x10
#define UID_OTHER 0x20


#define IF_FLAG 0x1
#define IF_INTEGER 0x2
#define IF_REAL 0x4
#define IF_COMPLEX 0x8
#define IF_NODE 0x10
#define IF_STRING 0x20
#define IF_INSTANCE 0x40
#define IF_PARSETREE 0x80

#define IF_SELECT 0x800
#define IF_VSELECT 0x400

#define IF_VECTOR 0x8000

#define IF_FLAGVEC     (IF_FLAG|IF_VECTOR)
#define IF_INTVEC      (IF_INTEGER|IF_VECTOR)
#define IF_REALVEC     (IF_REAL|IF_VECTOR)
#define IF_CPLXVEC     (IF_COMPLEX|IF_VECTOR)
#define IF_NODEVEC     (IF_NODE|IF_VECTOR)
#define IF_STRINGVEC   (IF_STRING|IF_VECTOR)
#define IF_INSTVEC     (IF_INSTANCE|IF_VECTOR)

#define IF_REQUIRED 0x4000

#define IF_VARTYPES 0x80ff

#define IF_SET 0x2000
#define IF_ASK 0x1000

#define IF_UNIMP_MASK (~0xfff)

#define IF_REDUNDANT	0x0010000
#define IF_PRINCIPAL	0x0020000
#define IF_AC		0x0040000
#define IF_AC_ONLY	0x0080000
#define IF_NOISE	0x0100000
#define IF_NONSENSE	0x0200000

#define IF_SETQUERY	0x0400000
#define IF_ORQUERY	0x0800000
#define IF_CHKQUERY	0x1000000

#define IF_UNINTERESTING 0x2000000

typedef struct sIFparseTree {
    int numVars;           
    int *varTypes;  
    union uIFvalue * vars;  
#ifdef __STDC__
    int ((*IFeval)(struct sIFparseTree*,double,double*,double*,double*));
#else
    int ((*IFeval)());    
#endif /* STDC */
} IFparseTree;


typedef void * IFnode;

typedef struct sIFcomplex {
    double real;
    double imag;
} IFcomplex;

typedef union uIFvalue {
    int iValue;   
    double rValue; 
    IFcomplex cValue;
    char *sValue; 
    IFuid uValue;
    IFnode nValue; 
    IFparseTree *tValue; 
    struct {
        int numValue; 
        union {
            int *iVec;  
            double *rVec;
            IFcomplex *cVec;
            char **sVec;
            IFuid *uVec;
            IFnode *nVec;
        }vec;
    }v;
} IFvalue;

typedef struct sIFdevice {
    char *name; 
    char *description;

    int *terms; 
    int *numNames; 
    char **termNames;
    int *numInstanceParms;
    IFparm *instanceParms;

    int *numModelParms; 
    IFparm *modelParms;

    int	flags;
    void ((*cm_func)(Mif_Private_t *));

    int num_conn;
    Mif_Conn_Info_t  *conn;

    int num_param;     
    Mif_Param_Info_t *param;  

    int num_inst_var;    
    Mif_Inst_Var_Info_t *inst_var; 

} IFdevice;


typedef struct sIFanalysis {
    char *name;  
    char *description;

    int numParms;  
    IFparm *analysisParms; 

} IFanalysis;

typedef struct sIFsimulator {
    char *simulator;     
    char *description;  
    char *version;     

#ifdef __STDC__
    int ((*newCircuit)(GENERIC **));  
    int ((*deleteCircuit)(GENERIC *));
    int ((*newNode)(GENERIC *,GENERIC**,IFuid));
    int ((*groundNode)(GENERIC*,GENERIC**,IFuid)); 
    int ((*bindNode)(GENERIC *,GENERIC*,int,GENERIC*));
    int ((*findNode)(GENERIC *,GENERIC**,IFuid));           
    int ((*instToNode)(GENERIC *,GENERIC *,int,GENERIC **,IFuid *));          
    int ((*setNodeParm)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));         
    int ((*askNodeQuest)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));        
    int ((*deleteNode)(GENERIC*,GENERIC*));          
    int ((*newInstance)(GENERIC*,GENERIC*,GENERIC**,IFuid));         
    int ((*setInstanceParm)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));     
    int ((*askInstanceQuest)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));    
    int ((*findInstance)(GENERIC*,int*,GENERIC**,IFuid,GENERIC*,IFuid));        
    int ((*deleteInstance)(GENERIC*,GENERIC*));      
    int ((*newModel)(GENERIC*,int,GENERIC**,IFuid));            
    int ((*setModelParm)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));        
    int ((*askModelQuest)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));       
    int ((*findModel)(GENERIC*,int*,GENERIC**,IFuid));           
    int ((*deleteModel)(GENERIC*,GENERIC*));         
    int ((*newTask)(GENERIC*,GENERIC**,IFuid));             
    int ((*newAnalysis)(GENERIC*,int,IFuid,GENERIC**,GENERIC*));         
    int ((*setAnalysisParm)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));     
    int ((*askAnalysisQuest)(GENERIC*,GENERIC*,int,IFvalue*,IFvalue*));    
    int ((*findAnalysis)(GENERIC*,int*,GENERIC**,IFuid,GENERIC*,IFuid));        
    int ((*findTask)(GENERIC*,GENERIC**,IFuid));            
    int ((*deleteTask)(GENERIC*,GENERIC*));          
    int ((*doAnalyses)(GENERIC*,int,GENERIC*));          
    char *((*nonconvErr)(GENERIC*,char *)); 
#else
    int ((*newCircuit)()); 
    int ((*deleteCircuit)()); 

    int ((*newNode)());  
    int ((*groundNode)());   
    int ((*bindNode)());  
    int ((*findNode)());  
    int ((*instToNode)());     
    int ((*setNodeParm)());  
    int ((*askNodeQuest)());  
    int ((*deleteNode)());   

    int ((*newInstance)());   
    int ((*setInstanceParm)());   
    int ((*askInstanceQuest)());
    int ((*findInstance)());  
    int ((*deleteInstance)()); 

    int ((*newModel)());  
    int ((*setModelParm)()); 
    int ((*askModelQuest)()); 
    int ((*findModel)());  
    int ((*deleteModel)()); 

    int ((*newTask)());   
    int ((*newAnalysis)());   
    int ((*setAnalysisParm)());     
    int ((*askAnalysisQuest)()); 
    int ((*findAnalysis)()); 
    int ((*findTask)()); 
    int ((*deleteTask)()); 

    int ((*doAnalyses)());  
    char *((*nonconvErr)());
#endif /* STDC */

    int numDevices;       
    IFdevice **devices;  

    int numAnalyses;   
    IFanalysis **analyses;  

    int numNodeParms;   
    IFparm *nodeParms;  

    int numSpecSigs;   
    char **specSigs; 

} IFsimulator;

typedef struct sIFfrontEnd {
#ifdef __STDC__
    int ((*IFnewUid)(GENERIC*,IFuid*,IFuid,char*,int,GENERIC**));    
    int ((*IFdelUid)(GENERIC*,IFuid,int));
    int ((*IFpauseTest)(void)); 
    double ((*IFseconds)(void));   
    int ((*IFerror)(int,char*,IFuid*));     
    int ((*OUTpBeginPlot)(GENERIC*,GENERIC*,IFuid,IFuid,int,
            int,IFuid*,int,GENERIC**));   
    int ((*OUTpData)(GENERIC*,IFvalue*,IFvalue*));        
    int ((*OUTwBeginPlot)(GENERIC*,GENERIC*,IFuid,IFuid,int,
            int,IFuid*,int,GENERIC**));   
    int ((*OUTwReference)(GENERIC*,IFvalue*,GENERIC**));   
    int ((*OUTwData)(GENERIC*,int,IFvalue*,GENERIC*));        
    int ((*OUTwEnd)(GENERIC*)); 
    int ((*OUTendPlot)(GENERIC*));      
    int ((*OUTbeginDomain)(GENERIC*,IFuid,int,IFvalue*));  
    int ((*OUTendDomain)(GENERIC*));    
    int ((*OUTattributes)(GENERIC *,IFuid*,int,IFvalue*));
#else /* not STDC */
    int ((*IFnewUid)()); 
    int ((*IFdelUid)()); 
    int ((*IFpauseTest)());
    double ((*IFseconds)()); 
    int ((*IFerror)());
    int ((*OUTpBeginPlot)());
    int ((*OUTpData)());
    int ((*OUTwBeginPlot)());
    int ((*OUTwReference)()); 
    int ((*OUTwData)());  
    int ((*OUTwEnd)()); 
    int ((*OUTendPlot)()); 
    int ((*OUTbeginDomain)());
    int ((*OUTendDomain)()); 
    int ((*OUTattributes)()); 
#endif /* STDC */
} IFfrontEnd;

#define _ERR_WARNING 0x1
#define ERR_FATAL 0x2
#define ERR_PANIC 0x4
#define ERR_INFO 0x8
#define RESUME 0
#define RESTART 1
#define SKIPTONEXT 2

#define OUT_SCALE_LIN   1
#define OUT_SCALE_LOG   2

#endif /*IFSIMULATOR*/
