-
Notifications
You must be signed in to change notification settings - Fork 9
/
brewsearch.ado
110 lines (79 loc) · 3.69 KB
/
brewsearch.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
********************************************************************************
* Description of the Program - *
* This is an ado wrapper around the brewColorSearch and brewNameSearch methods *
* of the brewsearch class. The program returns RGB values in returned macros. *
* *
* Data Requirements - *
* none *
* *
* System Requirements - *
* none *
* *
* Program Output - *
* r(rgb) - The normal color vision RGB value *
* r(achromatopsia) - The complete color loss RGB value *
* r(protanopia) - The RGB value for red color sight impairment *
* r(deuteranopia) - The RGB value for green color sight impairment *
* r(tritanopia) - The RGB value for blue color sight impairment *
* *
* Lines - *
* 109 *
* *
********************************************************************************
*! brewsearch
*! v 1.0.1
*! 03APR2016
// Drop program from memory if previously loaded
cap prog drop brewsearch
// Define program with rclass property
prog def brewsearch, rclass
// Set version to interpet Stata syntax
version 13.1
// Define syntax structure
syntax anything(name = color id = "Named Color or RGB triplet")
// Allowable arguments for return parameter
loc validreturns rgb achromatopsia protanopia deuteranopia tritanopia
// Create a new instance of a brewcolors object
qui: mata: brewsearch = brewcolors()
// For single word
if `: word count `color'' == 1 & regexm(`"`: word 1 of `color''"', ///
"[a-zA-Z]") == 0 {
// Search for the RGB values
qui: mata: brewsearch.brewColorSearch("`: word 1 of `color''")
} // End IF Block for single RGB string
// For single word
else if `: word count `color'' == 1 & regexm(`"`: word 1 of `color''"', ///
"[a-zA-Z]") == 1 {
// Search for the RGB values
qui: mata: brewsearch.brewNameSearch("`: word 1 of `color''")
} // End IF Block for single RGB string
// For all other cases
else {
// Loop over arguments passed to program
forv i = 1/`: word count `color'' {
// Store current word in local
loc theword `: word `i' of "`color'"'
// Check for RGB string by matching on string that does not contain letters
if regexm(`"`theword'"', "[a-zA-Z]") == 0 {
// Search for the RGB values
qui: mata: brewsearch.brewColorSearch("`theword'")
} // End IF Block for RGB string
// If not RGB String or varname assume it is a named color
else {
// Search for the RGB values
qui: mata: brewsearch.brewNameSearch("`theword'")
} // End ELSE Block for named colors
} // End Loop over arguments
} // End ELSE Block for multi word cases
// Return normal vision/baseline RGB string
ret loc rgb `rgb'
// Return total color blindness RGB string
ret loc achromatopsia `achromatopsia'
// Return red color blindness RGB string
ret loc protanopia `protanopia'
// Return green color blindness RGB string
ret loc deuteranopia `deuteranopia'
// Return blue color blindness RGB string
ret loc tritanopia `tritanopia'
// End program definition
end