home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 241_01 / message1.cs < prev    next >
Text File  |  1987-08-31  |  5KB  |  146 lines

  1. /*
  2. HEADER:         CUG241;
  3. TITLE:          Simple weather predictor expert system to demonstrate
  4.                 the IFRUN, ANDTHENRUN, etc., keywords. 
  5. DATE:           12/30/85;
  6. VERSION:
  7. DESCRIPTION:   "Source code for a simple Expert System.  Main program.";
  8. KEYWORDS:       Artificial Intelligence, expert systems, weather predictor;
  9. SYSTEM:         MS-DOS or UNIX System V;
  10. FILENAME:       MESSAGE1.C;
  11. WARNINGS:      "User-supported, author requests non-commercial use"
  12. AUTHORS:        George Hageman - Softman Enterprizes; 
  13. COMPILERS:      Microsoft C V3.00 or UNIX System V Portable C Compiler;
  14. REFERENCES:     AUTHOR:   William F. Clocksin, Christopher S. Mellish;
  15.                 TITLE:    "Programming in Prolog";
  16.  
  17.                 AUTHOR:   Mitch Derick, Linda Derick;
  18.                 TITLE:    "MVP-FORTH Expert-2 Tutorial";
  19.  
  20.                 AUTHOR:   Jack Park;
  21.                 TITLE:    "Expert Systems & the Weather - Dr. Dobb's Journal";
  22.                 CITATION:  "April 1984, pp. 24-28."
  23.  
  24.                 AUTHOR:   Jack Park;
  25.                 TITLE:    "MVP-FORTH Expert System Toolkit";
  26.  
  27.                 AUTHOR:   C. H. Ting;
  28.                 TITLE:    "Inside F83";
  29.  
  30.                 AUTHOR:   Patrick H. Winston, Berthold Klaus, Paul Horn;
  31.                 TITLE:    "LISP"
  32. ENDREF
  33. */
  34.  
  35. #include <stdio.h>
  36.  
  37. #include "routine.h"
  38. #include "weather.h"    /* common definitions for direction and stuff */
  39.  
  40.  
  41. int main()
  42. /*
  43. **    note that argv[1] is a pointer to our array of common value
  44. */
  45.  
  46. {
  47. char    string[20] ;
  48. int    test ;
  49. int    value[20] ;
  50. FILE    *dataFile ;
  51.  
  52. dataFile = fopen("WEATHER.DAT","wb") ;
  53.  
  54. for(test = 0 ; test < 20 ; test++)
  55.     value[test] = 0 ;
  56.  
  57. /*
  58. **    value[0] = barometric pressure * 100
  59. **    value[1] = condition of pressure
  60. **        1-steady, 2-rise_slow, 3-rise_fast, 4-fall-slow, 5-fall-fast
  61. **    value[2] = direction of ground wind 
  62. **        1-n, 2-ne, 3-e, 4-se, 5-s, 6-sw, 7-w, 8-nw
  63. **
  64. */
  65.  
  66. printf("\n \nWEATHER EXPERT: \n") ;
  67. printf("\n This program attempts to prove one of the following:");
  68. printf("\n\tthe weather is ok\n\tthe weather is improving\n\tthe weather is deteriorating\n");
  69. printf("\nNot all weather cases are included in the forecast algorithm.");
  70. printf("\n\nBefore we attempt a forecast, I need some data\n What is the barometric pressure reading?\n");
  71. test = 0 ;
  72. while((test < 2000) || (test > 4000))
  73.     {
  74.     printf("\n(Type in the pressure as an integer (BP*100) 30.1 = 3010...?");
  75.     scanf("%d",&value[0]) ;
  76.     test = value[0] ;
  77.     }
  78. printf("\n\t Thankyou!,  \n\n Now I need to know how the barometer is acting\n");
  79. test = 0;
  80. while((test <1) || (test >5))
  81.     {
  82.     printf("\n\t Please input the correct number for the following:\n");
  83.     printf("\n\t 1 -- It is steady\n\t 2 -- It is rising slowly\n\t 3 -- It is rising rapidly") ;
  84.     printf("\n\t 4 -- It is falling slowly\n\t 5 -- It is falling rapidly \n?");
  85.     scanf("%d",&value[1]);
  86.     test = value[1] ;
  87.     }
  88. test = 0 ;
  89. printf("\n\t Thankyou,") ;
  90. while((test < 1) || ( test > 8 ) )
  91.     {
  92.     printf("\n\nNow I need the wind direction, which direction is it blowing from?\n");
  93.     printf("<n, ne, e, se, s, sw, w, nw>?") ;
  94.     scanf("%s",string) ;
  95.     if(0 == strcmp(string,"n"))
  96.         value[2]=NORTH ;
  97.     if(0 == strcmp(string,"ne"))
  98.         value[2]=NORTH_EAST ;
  99.     if(0 == strcmp(string,"e"))
  100.         value[2]=EAST ;
  101.     if(0 == strcmp(string,"se"))
  102.         value[2]=SOUTH_EAST ;
  103.     if(0 == strcmp(string,"s"))
  104.         value[2]=SOUTH ;
  105.     if(0 == strcmp(string,"sw"))
  106.         value[2]=SOUTH_WEST ;
  107.     if(0 == strcmp(string,"w"))
  108.         value[2]=WEST ;
  109.     if(0 == strcmp(string,"nw"))
  110.         value[2]=NORTH_WEST ;
  111.     if(0 == strcmp(string,"N"))
  112.         value[2]=NORTH ;
  113.     if(0 == strcmp(string,"NE"))
  114.         value[2]=NORTH_EAST ;
  115.     if(0 == strcmp(string,"E"))
  116.         value[2]=EAST ;
  117.     if(0 == strcmp(string,"SE"))
  118.         value[2]=SOUTH_EAST ;
  119.     if(0 == strcmp(string,"S"))
  120.         value[2]=SOUTH ;
  121.     if(0 == strcmp(string,"SW"))
  122.         value[2]=SOUTH_WEST ;
  123.     if(0 == strcmp(string,"W"))
  124.         value[2]=WEST ;
  125.     if(0 == strcmp(string,"NW"))
  126.         value[2]=NORTH_WEST ;
  127.     test = value[2] ;
  128.     }
  129. printf("\n\n\n\n For the next question, you should stand outside with your back");
  130. printf("\nto the surface wind.  You now must observe the direction the");
  131. printf("\nupper level clouds are moving.  You observe them to be moving") ;
  132. printf("\nfrom your right, from your left, or in a direction parallel") ;
  133. printf("\nto that which your are facing.\n") ;
  134. printf("\nUse this information to answer the following question.  If you");
  135. printf("\nare unable to see the upper level clouds, answer no to the following");
  136. printf("\nquestion.\n\n") ;
  137. fwrite(value,2,20,dataFile) ;
  138. fclose(dataFile) ;
  139. exit(RETURN_ROUTINE_TRUE) ;
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.