home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xgas / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-17  |  2.7 KB  |  98 lines

  1. /*
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided that
  6.  * the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of M.I.T. not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  M.I.T. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  16.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  18.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  19.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20.  */
  21.  
  22. /*
  23.  * util.c
  24.  *   Feb. 6, 1990: Larry Medwin
  25.  *   gas: Copyright 1990 Larry Medwin: @(#)util.c    1.2 2/9/90
  26.  */
  27.  
  28. #include "xgas.h"
  29.  
  30. /*
  31.  * V EQUILIBRIUM
  32.  * What is magnitude of molecule velocity at wall temperature?
  33.  *   velocity is in mm/microsec
  34.  */
  35. float vEquilibrium( temperature)
  36.     float temperature;
  37. {
  38.     return (float) (1.0e-5 * sqrt( (double)(2.0 * KB * temperature / MASS)));
  39. }
  40.  
  41. /* CHANGE TEMPERATURE OF ONE CHAMBER */
  42. void changeTemp( w, chamber, sliderpos)    /* ARGSUSED */
  43.     Widget w;
  44.     Box *chamber;
  45.     float *sliderpos;
  46. {
  47.     Arg wargs[1];
  48.     char str[10];
  49.     float chamberTmp = MAXTEMP * (1.0 - *sliderpos);
  50.  
  51.     /* Make new temperature string */
  52.     chamber->temperature = chamberTmp;
  53.     sprintf( str, "%.1f K", chamberTmp);
  54.  
  55.     /* Tell the widget */
  56.     XtSetArg( wargs[0], XtNlabel, str);
  57.     XtSetValues( chamber->display, wargs, 1);
  58. }
  59.  
  60. /*
  61.  *  FRAND -- random number routine
  62.  *  Return a floating point number n such that n >= min and n < max
  63.  *    if (min == max), return min
  64.  */
  65. float frand(min, max)
  66.     float min, max;
  67. {
  68.     float n;
  69.  
  70.     n = (rand() & 0x7fff) / 32768.0;
  71. /*    n = ((float)rand()) / 32768.0;*/
  72.     return n * (max - min) + min;
  73. }
  74.  
  75. /*
  76.  * ERROR handler
  77.  *   This is a good place to put a breakpoint.
  78.  */
  79. error( message, time)
  80.     char *message;
  81.     float time;
  82. {
  83.     printf("Error at time = %6.3f msec: %s\n", 1.0e-3 * time, message);
  84.     exit(-1);
  85. }
  86.  
  87. /*
  88.  * QUIT_CALLBACK
  89.  *   is adapted from Douglas A. Young's
  90.  */
  91. void quit_callback(w, client_data, call_data) /* ARGSUSED */
  92.      Widget     w;
  93.      caddr_t    client_data;
  94.      caddr_t    call_data;
  95. {
  96.    exit(0);
  97. }
  98.