home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / rexx / age.rexx < prev    next >
OS/2 REXX Batch file  |  1994-01-25  |  7KB  |  230 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                            Age.rexx                                      */
  4. /*                                                                          */
  5. /* Written by: Peter Billing, RMB 1240, Yinnar 3869, Australia              */
  6. /*                                                                          */
  7. /* Last saved: Wednesday 29-Sep-93                                          */
  8. /*                                                                          */
  9. /* This script should tell you the Age of a person in the SCION database.   */
  10. /* It does except the date to be in the format DD MMM YYYY but as long as   */
  11. /* the year is the last 4 characters, it will give you an age within 1 year.*/
  12. /* The database must be running for this AREXX script to work.              */
  13. /*                                                                          */
  14. /****************************************************************************/
  15.  
  16. /* Return the Database Name */
  17.  
  18. options results
  19. /*test = show('P','SCIONGEN')
  20. if test = 0  then
  21. say
  22. say "I am sorry to say that the SCION Genealogist database is not available."
  23. say "Please start the SCION program BEFORE using this script."
  24. say
  25. exit */
  26.  
  27. myport = "SCIONGEN"
  28. address value myport
  29. getdbname
  30. dbname = upper(result)
  31. output = "STDOUT"
  32. gettotalirn
  33. total = result
  34.  
  35. say " "
  36. say center("Age.rexx",80)
  37. say
  38. say "The current database is called" dbname "and it has "total "people in it."
  39. say
  40. say "This script will give you the correct age of a person who has a"
  41. say "FULL birth date. If there is only a year or month and year you"
  42. say "will get an approximate within a year. If there is also a death"
  43. say "date, this will be used to calculate the persons age at death."
  44. say "The script will then tell you how long the person has been dead."
  45. say
  46. writech(stdout,"Type in the IRN of the person you are interested in or ALL ")
  47. pull irn
  48. writech(output,"Output to Screen or File. S/F ")
  49. pull out
  50. if out = "" then out ="S"
  51.  
  52. L1 = 17
  53. L2 = 13
  54. code1 = ""    /* Reverse video */
  55. code2 = ""    /* Normal Text */
  56. code3 = ""    /* Bold text*/
  57. code4 = ""    /* Italic text */
  58. code5 = ""
  59.  
  60. if irn ~= "ALL" then do
  61.   if irn = "" | irn > total | irn < 1 then exit
  62. end
  63. number = "a person"
  64. if irn = "ALL" then do
  65.   writech(stdout,"Do you want a sorted list Y/N ")
  66.   pull sorted
  67.  
  68.   if sorted = "" then sorted = "N"
  69.   if sorted = "Y" then do
  70.     file_name = "ram:sort"
  71.     open(sort_File,file_Name,"w")
  72.     do a = 1 to total
  73.       getlastname a
  74.       person = upper(result)
  75.       getfirstname a
  76.       person = person result a
  77.       writeln(sort_File,person)
  78.     end
  79.     close(sort_file)
  80.     address command "c:sort ram:sort ram:sort2"
  81.     file_name = "ram:sort2"
  82.     open(sort_File,file_Name,"r")
  83.   end
  84.   start = 1
  85.   finish = total
  86.   number = "ALL people"
  87. end
  88. else do
  89.   start = irn
  90.   finish = irn
  91. end
  92.  
  93. if out = "F" then do
  94.   filename = "RAM:Age_"irn"_"dbname".Scion"
  95.   open(w_file,filename,"w")
  96.   output = w_file
  97.   writeln(stdout,"")
  98.   writeln(stdout,"Writing file to" filename)
  99.   L1 = 25
  100.   L2 = 15
  101.   code1 = ""
  102.   code2 = ""
  103.   code3 = ""
  104.   code4 = ""
  105.   code5 = ""
  106. end
  107. heading = "List of "number" in the "dbname" database plus their age on "date()
  108.  
  109. day1   = subword(date(),1,1)
  110. Month1 = subword(date(),2,1)
  111. Year1  = subword(date(),3,1)
  112. CheckMonth(upper(Month1))  /* turn the month into a number */
  113. m1 = x
  114. writeln(output,"w"center(heading,80))
  115. writeln(output,"")
  116. writeln(output,"-------------------------------------------------------------------------------")
  117. do j = start to finish
  118. if sorted = "Y" then do
  119.   person = readln(sort_file)
  120.   irn = word(person,words(person))
  121. end
  122. else do
  123.   irn = j
  124. end
  125. if out = "F" then do
  126.   if j/5 = j%5 then writech(stdout,".")
  127.   if j/55 = j%55 then do
  128.     writeln(output," ")
  129.     writeln(output,center(heading,80))
  130.     writeln(output,"")
  131.     writeln(output,"-------------------------------------------------------------------------------")
  132.   end
  133. end
  134. MakeName(irn)
  135. person = name
  136. fix = 0
  137. birth = ""
  138. getbirthdate irn
  139. birth = result
  140. if length(birth) > 3 then do                  /* check if there is a date */
  141.   day2   = word(birth,1)                      /* if there is then continue */
  142.   Month2 = substr(word(birth,2),1,3)
  143.   Year2  = substr(birth,length(birth)-3,4)
  144.   CheckMonth(upper(Month2))
  145.   m2 = x
  146. end
  147. else do                                      /* no date */
  148.   writeln(output, right(irn,3) person code4"has no birth date."code2)            /* say so */
  149.   fix = 1
  150. end
  151.  
  152. if fix = 0 then do
  153. death = ""
  154. getdeathdate irn
  155. death = result
  156. if length(death) > 3 then do               /* is if the person has a death date */
  157.   day3   = word(death,1)                   /* if there is a date then work out */
  158.   Month3 = word(death,2)                   /* age at death */
  159.   Year3  = substr(death,length(death)-3,4)
  160.   CheckMonth(upper(Month3))
  161.   m3 = x
  162.   age = year3 - year2
  163.   if m3 < m2 then age = age -1
  164.   if m3 = m2 then do
  165.     if day3 < day2 then age = age -1
  166.    end
  167.    getsex irn
  168.    if result == "M" then sex = "he "
  169.    else sex = "she"
  170.    if result == "" then sex = "they"
  171.    writeln(output, right(irn,3) person "was"code3 right(age,2)code2" when" sex "died" right(year1-year3,3) "year's ago on" death)
  172. end
  173.  
  174. /* Person is still alive */
  175.  
  176. if length(death) < 3 & length(birth) > 3 then do /* check there is a bith date */
  177. age = year1 - year2                              /* work out the age using the year */
  178. if m1 < m2 then                                  /* if birth month is less than today */
  179.          age = age -1                            /* then person is a year younger */
  180. if m1 = m2 then do                               /* if the months are the same then */
  181.                                                  /*  check the days */
  182.    if day1 < day2 then do                        /* if birth day is less than today */
  183.      age = age -1                                /* then person is a year younger */
  184.      end
  185.      end
  186. if m1 = m2 & day1 = day2 then                  /* if day and month is the same as */
  187.   writeln(output, right(irn,3) person "is "code1 right(age,2)code2 "today."code5" Happy Birthday!!"code2)
  188.   else
  189.   if age < 106 then
  190.   writeln(output, right(irn,3) person "is "code1 right(age,2)code2 right(birth,14))
  191.   if age > 106 then
  192.   writeln(output,right(irn,3) person "has no death date and is over 105")
  193.  end
  194.  end
  195.  end
  196. if out = "F" then do
  197.   writeln(output,"w ")
  198.   close(w_file)
  199.   writeln(stdout,"")
  200.   writeln(stdout,"All Finished")
  201.   end
  202. exit
  203. /* end */
  204.  
  205. CheckMonth:
  206. parse arg m
  207. if m = "JAN" then x = 1
  208. if m = "FEB" then x = 2
  209. if m = "MAR" then x = 3
  210. if m = "APR" then x = 4
  211. if m = "MAY" then x = 5
  212. if m = "JUN" then x = 6
  213. if m = "JUL" then x = 7
  214. if m = "AUG" then x = 8
  215. if m = "SEP" then x = 9
  216. if m = "OCT" then x = 10
  217. if m = "NOV" then x = 11
  218. if m = "DEC" then x = 12
  219. return x
  220.  
  221. MakeName:
  222. parse arg irn
  223. getfirstname irn
  224. name = left(result,L1)
  225. getlastname irn
  226. name = name left(result,L2)
  227. return name
  228.  
  229.  
  230.