/[ascend]/trunk/base/generic/compiler/units.h
ViewVC logotype

Diff of /trunk/base/generic/compiler/units.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 965 by johnpye, Fri Apr 21 07:22:20 2006 UTC revision 966 by johnpye, Thu Dec 14 14:04:54 2006 UTC
# Line 20  Line 20 
20      Ascend Units Type definitions.      Ascend Units Type definitions.
21    
22      Requires:      Requires:
     #include <stdio.h>  
     #include "utilities/ascConfig.h"  
23      #include "fractions.h"      #include "fractions.h"
24      #include "compiler.h"      #include "compiler.h"
25      #include "dimen.h"      #include "dimen.h"
26  *//*  *//*
27      by Tom Epperly      by Tom Epperly 8/18/89
28      8/18/89      Last in CVS: $Revision: 1.10 $ $Date: 1998/02/05 16:38:40 $ $Author: ballan $
     Version: $Revision: 1.10 $  
     Version control file: $RCSfile: units.h,v $  
     Date last modified: $Date: 1998/02/05 16:38:40 $  
     Last modified by: $Author: ballan $  
29  */  */
30    
31  #ifndef ASC_UNITS_H  #ifndef ASC_UNITS_H
32  #define ASC_UNITS_H  #define ASC_UNITS_H
33    
34    #include <stdio.h>
35  #include <utilities/ascConfig.h>  #include <utilities/ascConfig.h>
36    
37  #ifdef _HPUX_SOURCE  #ifdef _HPUX_SOURCE
# Line 49  Line 44 
44  /**< to shut up the hp lexer */  /**< to shut up the hp lexer */
45    
46  /**  /**
47   *  Value in system units = value in given units * conversion_factor.      Value in system units = value in given units * conversion_factor.
48   */   */
49  struct Units {  struct Units {
50    double conversion_factor; /**< to convert from units to system units */    double conversion_factor; /**< to convert from units to system units */
# Line 59  struct Units { Line 54  struct Units {
54  };  };
55    
56  /**  /**
57   * Temporary structure for parsing unit definitions in ascParse.y.      Temporary structure for parsing unit definitions in ascParse.y.
58   */   */
59  struct UnitDefinition {  struct UnitDefinition {
60    symchar *new_name;    symchar *new_name;
# Line 70  struct UnitDefinition { Line 65  struct UnitDefinition {
65    
66  #define UNITS_HASH_SIZE (1023)  #define UNITS_HASH_SIZE (1023)
67  /**<  /**<
68   *  size of the hash table for unit structs      size of the hash table for unit structs
69   */   */
70    
71  /*  /*
# Line 105  ASC_DLLSPEC(struct Units *) g_units_hash Line 100  ASC_DLLSPEC(struct Units *) g_units_hash
100    
101  extern void InitUnitsTable(void);  extern void InitUnitsTable(void);
102  /**<  /**<
103   *  <!--  void InitUnitsTable()                                        -->      This routine initializes some internal variables, so that all the
104   *  This routine initializes some internal variables, so that all the      other units functions may be called.  It must be called once and
105   *  other units functions may be called.  It must be called once and      only once when the program is starting up.
106   *  only once when the program is starting up.      Must be called after dimensions table initiatialization.
107   *  Must be called after dimensions table initiatialization.  */
  */  
108    
109  extern void DestroyUnitsTable(void);  extern void DestroyUnitsTable(void);
110  /**<  /**<
111   *  <!--  void DestroyUnitsTable()                                     -->      This routine can be called to deallocate all of the units in the table.
112   *  This routine can be called to deallocate all of the units in the table.  */
  */  
113    
114  extern struct UnitDefinition *CreateUnitDef(symchar *new_name,  extern struct UnitDefinition *CreateUnitDef(symchar *new_name,
115                                              CONST char *unitsexpr,                                              CONST char *unitsexpr,
116                                              CONST char *filename,                                              CONST char *filename,
117                                              int linenum);                                              int linenum);
118  /**<  /**<
  * <!--  udptr = CreateUnitDef(new_name,unitsexpr,filename,linenum);   -->  
  * <!--  new_name should be from the symbol table.                     -->  
  * <!--  unitsexpr is a string that we will copy, so it does not       -->  
  * <!--  need to be persistent.                                        -->  
  * <!--  filename should be persistent.                                -->  
119   *  Create a new unit definition.   *  Create a new unit definition.
120   *  @param new_name  Should be from the symbol table.   *  @param new_name  Should be from the symbol table.
121   *  @param unitsexpr A string that we will copy, so it does not   *  @param unitsexpr A string that we will copy, so it does not
# Line 138  extern struct UnitDefinition *CreateUnit Line 126  extern struct UnitDefinition *CreateUnit
126    
127  extern void DestroyUnitDef(struct UnitDefinition *udp);  extern void DestroyUnitDef(struct UnitDefinition *udp);
128  /**<  /**<
  * <!--  DestroyUnitDef(udp);                                          -->  
129   * Destroys udp and its unitsexpr.   * Destroys udp and its unitsexpr.
130   */   */
131    
132  extern void ProcessUnitDef(struct UnitDefinition *udp);  extern void ProcessUnitDef(struct UnitDefinition *udp);
133  /**<  /**<
  * <!--  ProcessUnitDef(udp);                                          -->  
134   * Attempts to add the info in udp to the units table.   * Attempts to add the info in udp to the units table.
135   * messages to ascerr if not possible.   * messages to ascerr if not possible.
136   */   */
137    
138  ASC_DLLSPEC(CONST struct Units*) LookupUnits(CONST char *c);  ASC_DLLSPEC(CONST struct Units*) LookupUnits(CONST char *c);
139  /**<  /**<
  *  <!--  const struct Units *LookupUnits(c)                           -->  
  *  <!--  const char *c;                                               -->  
140   *  Check the units library for units with a description string which   *  Check the units library for units with a description string which
141   *  matches c.  If it is found, this function will return a non-NULL pointer;   *  matches c.  If it is found, this function will return a non-NULL pointer;
142   *  otherwise, it returns NULL to indicate that units c are undefined.   *  otherwise, it returns NULL to indicate that units c are undefined.
# Line 161  ASC_DLLSPEC(CONST struct Units*) LookupU Line 145  ASC_DLLSPEC(CONST struct Units*) LookupU
145    
146  extern CONST struct Units *DefineUnits(symchar *c, double conv, CONST dim_type *dim);  extern CONST struct Units *DefineUnits(symchar *c, double conv, CONST dim_type *dim);
147  /**<  /**<
  *  <!--  const struct Units *DefineUnits(c,conv,dim)                  -->  
  *  <!--  const char *c;                                               -->  
  *  <!--  double conv;                                                 -->  
  *  <!--  const dim_type *dim;                                         -->  
148   *  Define the units c with conversion factor conv and dimensions *dim.   *  Define the units c with conversion factor conv and dimensions *dim.
149   *  This assumes that *dim was the value returned by FindOrAddDim.  This   *  This assumes that *dim was the value returned by FindOrAddDim.  This
150   *  will check to prevent duplicate entries.  The resulting unit structure is   *  will check to prevent duplicate entries.  The resulting unit structure is
# Line 185  ASC_DLLSPEC(CONST struct Units*) FindOrD Line 165  ASC_DLLSPEC(CONST struct Units*) FindOrD
165                                               unsigned long * CONST pos,                                               unsigned long * CONST pos,
166                                               int * CONST error_code);                                               int * CONST error_code);
167  /**<  /**<
  *  <!--  struct Units *FindOrDefineUnits(c,pos,error_code)            -->  
  *  <!--  CONST char *c;                                               -->  
  *  <!--  unsigned long * const pos;                                   -->  
  *  <!--  int * const error_code;                                      -->  
168   *  This function will attempt to parse the string c into a units   *  This function will attempt to parse the string c into a units
169   *  description.  If the unit type has been defined before, the corresponding   *  description.  If the unit type has been defined before, the corresponding
170   *  units pointer will be returned.  If this type hasn't been defined before,   *  units pointer will be returned.  If this type hasn't been defined before,
# Line 222  ASC_DLLSPEC(CONST struct Units*) FindOrD Line 198  ASC_DLLSPEC(CONST struct Units*) FindOrD
198    
199  ASC_DLLSPEC(char**) UnitsExplainError(CONST char *unitsexpr, int code, int pos);  ASC_DLLSPEC(char**) UnitsExplainError(CONST char *unitsexpr, int code, int pos);
200  /**<  /**<
  *  <!--  errv = UnitsExplainError(unitsexpr,code,pos);                -->  
201   *  Returns an array of strings which may be helpful in   *  Returns an array of strings which may be helpful in
202   *  explaining the error.   *  explaining the error.
203   *  - errv[0] is a message.   *  - errv[0] is a message.
# Line 235  ASC_DLLSPEC(char**) UnitsExplainError(CO Line 210  ASC_DLLSPEC(char**) UnitsExplainError(CO
210    
211  #define UnitsDescription(u) ((u)->description)  #define UnitsDescription(u) ((u)->description)
212  /**<  /**<
  *  <!--  macro UnitsDescription(u)                                    -->  
  *  <!--  struct Units *u;                                             -->  
213   *  Returns the string description attribute of a units structure.   *  Returns the string description attribute of a units structure.
214   */   */
215    
216  #define UnitsConvFactor(u) ((u)->conversion_factor)  #define UnitsConvFactor(u) ((u)->conversion_factor)
217  /**<  /**<
  *  <!--  macro UnitsConvFactor(u)                                     -->  
  *  <!--  struct Units *u;                                             -->  
218   *  Returns the conversion factor for a given units structure.   *  Returns the conversion factor for a given units structure.
219   */   */
220    
221  #define UnitsDimensions(u) ((u)->dim)  #define UnitsDimensions(u) ((u)->dim)
222  /**<  /**<
  *  <!--  macro UnitsDimensions(u)                                     -->  
  *  <!--  struct Units *u;                                             -->  
223   *  Returns the dimensions of the units structure.   *  Returns the dimensions of the units structure.
224   */   */
225    
226  ASC_DLLSPEC(char *) UnitsStringSI(struct Units *up);  ASC_DLLSPEC(char *) UnitsStringSI(struct Units *up);
227  /**<  /**<
  *  <!--  UnitsStringSI(up);                                           -->  
228   *  Returns the SI form of the units for the dimensionality of up.   *  Returns the SI form of the units for the dimensionality of up.
229   *  Wild = *, Dimensionless = "", NULL up --> NULL return.   *  Wild = *, Dimensionless = "", NULL up --> NULL return.
230   *  Caller is responsible for freeing the string returned.   *  Caller is responsible for freeing the string returned.

Legend:
Removed from v.965  
changed lines
  Added in v.966

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22