-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbrewmeta.ado
159 lines (110 loc) · 5.03 KB
/
brewmeta.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
********************************************************************************
* Description of the Program - *
* This program is used to check the meta data available on different visual *
* properties of a given color palette for a specified number of colors. *
* *
* Data Requirements - *
* none *
* *
* System Requirements - *
* Active Internet Connection *
* *
* Program Output - *
* r(paletteName[#Max][#C]_print) - Print friendliness indicator *
* r(paletteName[#Max][#C]_photocopy) - Photocopier friendliness indicator *
* r(paletteName[#Max][#C]_lcd) - LCD Viewing friendliness indicator *
* r(paletteName[#Max][#C]_colorblind) - Colorblindness friendliness *
* *
* Lines - *
* 158 *
* *
********************************************************************************
*! brewmeta
*! v 1.0.1
*! 03APR2016
// Drop the program from memory if loaded
cap prog drop brewmeta
// Define the program as an rclass program
prog def brewmeta, rclass
// Specify the version number
version 13.1
// Define the syntax structure of the program
syntax anything(name = palette id = "palette name"), colorid(integer) ///
[colors(integer -12) PROPerties PROPerties2(string asis) ]
// Strip any quation marks from the palette name
loc palette : subinstr loc palette `"""' "", all
// Preserve the data in memory
preserve
// Check for the metadata dataset
cap confirm file `"`c(sysdir_personal)'b/brewmeta.dta"'
// If the file does not exist
if _rc != 0 | _rc == 603 {
// Print error message
di as err "Must first build the brewscheme database." _n ///
"Use the following command to do that: " as smcl {stata brewdb}
// Error out of the program
err 601
} // End IF Block for non-existent brewscheme DB
// If the file does exist
else {
// Load the dataset
qui: use `"`c(sysdir_personal)'b/brewmeta.dta"', clear
// Check the colors option
if `colors' < 2 {
// Get the maximum value of colors for the given palette
qui: su maxcolors if palette == "`palette'", meanonly
// Get maximum value for the palette
loc colors = `r(mean)'
} // End IF Block if max colors parameter is missing or invalid
// Validate the color ID parameter
if `colorid' > `colors' {
// Error out
di as err "Color ID > # of colors in the palette"
// Return error code
err 198
} // End IF Block for color ID validation check
// Check to make sure colors value is <= max colors for the palette
else {
// Get the maximum colors value for the palette
qui: su maxcolors if palette == "`palette'", meanonly
// Check the values
if `colors' > `r(mean)' {
// Error out of the program
di as err "Colors argument cannot exceed the max # of colors for the palette"
// Exit program
exit
} // End IF Block for validation check
} // End ELSE Block for the colors -> max colors validation
// If all/no option specified
if inlist("`properties2'", "all", "") {
// Loop over the property types
foreach x in colorblind lcd photocopy print meta {
// Get the characteristics
loc prop `: char _dta[`palette'`colors'`colorid'_`x']'
// Print to the screen
di as res `"The color `colorid' of palette `palette' with `colors' colors is `prop'"'
// Return the value
ret local `palette'`colors'`colorid'_`x' `"`prop'"'
} // End Loop over variables for characteristics
} // End IF Block over all properties
// other wise
else {
// Count the number of words in the string
loc prps `: word count `properties2''
// Set up loop to allow the command to generalize to multiple properties
forv i = 1/`prps' {
// Get the specific property value
loc pr`i' `: word `i' of `properties2''
// Get the characteristics
loc prop `: char _dta[`palette'`colors'`colorid'_`pr`i'']'
// Print to the screen
di as res `"The color `colorid' of palette `palette' with `colors' colors is `prop'"'
// Return the value
ret local `palette'`colors'`colorid'_`pr`i'' `"`prop'"'
} // End Loop to get properties
} // End ELSE Block for specified properties
} // End ELSE Block for existing brewscheme DB
// Return data to original state
restore
// End of Program
end