{"action":"opened","number":19,"pull_request":{"url":"https://api.github.com/repos/afni/afni/pulls/19","id":53781677,"html_url":"https://github.com/afni/afni/pull/19","diff_url":"https://github.com/afni/afni/pull/19.diff","patch_url":"https://github.com/afni/afni/pull/19.patch","issue_url":"https://api.github.com/repos/afni/afni/issues/19","number":19,"state":"open","locked":false,"title":"Add `choose` and `ifelse` to ccalc and friends","user":{"login":"ischwabacher","id":4306187,"avatar_url":"https://avatars.githubusercontent.com/u/4306187?v=3","gravatar_id":"","url":"https://api.github.com/users/ischwabacher","html_url":"https://github.com/ischwabacher","followers_url":"https://api.github.com/users/ischwabacher/followers","following_url":"https://api.github.com/users/ischwabacher/following{/other_user}","gists_url":"https://api.github.com/users/ischwabacher/gists{/gist_id}","starred_url":"https://api.github.com/users/ischwabacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ischwabacher/subscriptions","organizations_url":"https://api.github.com/users/ischwabacher/orgs","repos_url":"https://api.github.com/users/ischwabacher/repos","events_url":"https://api.github.com/users/ischwabacher/events{/privacy}","received_events_url":"https://api.github.com/users/ischwabacher/received_events","type":"User","site_admin":false},"body":"I've been wanting these functions for a while now, and I finally got around to doing something about it.\r\n\r\n- `choose(n,a,b,c,...)` chooses the n-th element of a,b,c,...\r\n    (e.g., `choose(2,a,b,c)` is `b`)\r\n- `ifelse(p,t,f)` is equivalent to `p ? t : f`\r\n\r\nI basically just copied the changes in a02241d7c4c9ac318b736db8b4d93e1123992109 and tweaked.\r\n\r\nThis change has been tested some and seems to work, but it should still be looked over by someone who knew Fortran this morning. Also regenerating `parser.c` might be necessary.\r\n\r\n```bash\r\n$ ./ccalc 'ifelse(0,1,2)'\r\n2.000000\r\n$ ./ccalc 'ifelse(1,1,2)'\r\n1.000000\r\n$ ./ccalc 'ifelse(7.5,1,2)'\r\n1.000000$ ./ccalc 'ifelse(0,1,2,3)'\r\n PARSER error  12: Wrong number of arguments     \r\n IFELSE(0,1,2,3) \r\n.............#\r\nparser error!\r\n$ ./ccalc 'ifelse(0,1)'\r\n PARSER error  12: Wrong number of arguments     \r\n IFELSE(0,1) \r\n...........#\r\nparser error!\r\n# If n < 1, error so return 0\r\n$ ./ccalc 'choose(0)'\r\n0.000000\r\n# If not enough args, error so return 0\r\n$ ./ccalc 'choose(1)'\r\n0.000000\r\n$ ./ccalc 'choose(-.3,1,2,3,4,5,6)'\r\n0.000000\r\n$ ./ccalc 'choose(1,1,2,3,4,5,6)'\r\n1.000000\r\n$ ./ccalc 'choose(5,1,2,3,4,5,6)'\r\n5.000000\r\n$ ./ccalc 'choose(5,10,20,30,40,50,60)'\r\n50.000000\r\n$ ./ccalc 'choose(7,10,20,30,40,50,60)'\r\n0.000000\r\n# Round down\r\n$ ./ccalc 'choose(4.9,10,20,30,40,50,60)'\r\n40.000000\r\n```","created_at":"2015-12-16T00:07:39Z","updated_at":"2015-12-16T00:07:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/afni/afni/pulls/19/commits","review_comments_url":"https://api.github.com/repos/afni/afni/pulls/19/comments","review_comment_url":"https://api.github.com/repos/afni/afni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/afni/afni/issues/19/comments","statuses_url":"https://api.github.com/repos/afni/afni/statuses/71efc755739b8641308e24fea1830fa6ae754324","head":{"label":"ischwabacher:ccalc-functions","ref":"ccalc-functions","sha":"71efc755739b8641308e24fea1830fa6ae754324","user":{"login":"ischwabacher","id":4306187,"avatar_url":"https://avatars.githubusercontent.com/u/4306187?v=3","gravatar_id":"","url":"https://api.github.com/users/ischwabacher","html_url":"https://github.com/ischwabacher","followers_url":"https://api.github.com/users/ischwabacher/followers","following_url":"https://api.github.com/users/ischwabacher/following{/other_user}","gists_url":"https://api.github.com/users/ischwabacher/gists{/gist_id}","starred_url":"https://api.github.com/users/ischwabacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ischwabacher/subscriptions","organizations_url":"https://api.github.com/users/ischwabacher/orgs","repos_url":"https://api.github.com/users/ischwabacher/repos","events_url":"https://api.github.com/users/ischwabacher/events{/privacy}","received_events_url":"https://api.github.com/users/ischwabacher/received_events","type":"User","site_admin":false},"repo":{"id":35622162,"name":"afni","full_name":"ischwabacher/afni","owner":{"login":"ischwabacher","id":4306187,"avatar_url":"https://avatars.githubusercontent.com/u/4306187?v=3","gravatar_id":"","url":"https://api.github.com/users/ischwabacher","html_url":"https://github.com/ischwabacher","followers_url":"https://api.github.com/users/ischwabacher/followers","following_url":"https://api.github.com/users/ischwabacher/following{/other_user}","gists_url":"https://api.github.com/users/ischwabacher/gists{/gist_id}","starred_url":"https://api.github.com/users/ischwabacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ischwabacher/subscriptions","organizations_url":"https://api.github.com/users/ischwabacher/orgs","repos_url":"https://api.github.com/users/ischwabacher/repos","events_url":"https://api.github.com/users/ischwabacher/events{/privacy}","received_events_url":"https://api.github.com/users/ischwabacher/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ischwabacher/afni","description":"Official AFNI source and documentation","fork":true,"url":"https://api.github.com/repos/ischwabacher/afni","forks_url":"https://api.github.com/repos/ischwabacher/afni/forks","keys_url":"https://api.github.com/repos/ischwabacher/afni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ischwabacher/afni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ischwabacher/afni/teams","hooks_url":"https://api.github.com/repos/ischwabacher/afni/hooks","issue_events_url":"https://api.github.com/repos/ischwabacher/afni/issues/events{/number}","events_url":"https://api.github.com/repos/ischwabacher/afni/events","assignees_url":"https://api.github.com/repos/ischwabacher/afni/assignees{/user}","branches_url":"https://api.github.com/repos/ischwabacher/afni/branches{/branch}","tags_url":"https://api.github.com/repos/ischwabacher/afni/tags","blobs_url":"https://api.github.com/repos/ischwabacher/afni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ischwabacher/afni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ischwabacher/afni/git/refs{/sha}","trees_url":"https://api.github.com/repos/ischwabacher/afni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ischwabacher/afni/statuses/{sha}","languages_url":"https://api.github.com/repos/ischwabacher/afni/languages","stargazers_url":"https://api.github.com/repos/ischwabacher/afni/stargazers","contributors_url":"https://api.github.com/repos/ischwabacher/afni/contributors","subscribers_url":"https://api.github.com/repos/ischwabacher/afni/subscribers","subscription_url":"https://api.github.com/repos/ischwabacher/afni/subscription","commits_url":"https://api.github.com/repos/ischwabacher/afni/commits{/sha}","git_commits_url":"https://api.github.com/repos/ischwabacher/afni/git/commits{/sha}","comments_url":"https://api.github.com/repos/ischwabacher/afni/comments{/number}","issue_comment_url":"https://api.github.com/repos/ischwabacher/afni/issues/comments{/number}","contents_url":"https://api.github.com/repos/ischwabacher/afni/contents/{+path}","compare_url":"https://api.github.com/repos/ischwabacher/afni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ischwabacher/afni/merges","archive_url":"https://api.github.com/repos/ischwabacher/afni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ischwabacher/afni/downloads","issues_url":"https://api.github.com/repos/ischwabacher/afni/issues{/number}","pulls_url":"https://api.github.com/repos/ischwabacher/afni/pulls{/number}","milestones_url":"https://api.github.com/repos/ischwabacher/afni/milestones{/number}","notifications_url":"https://api.github.com/repos/ischwabacher/afni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ischwabacher/afni/labels{/name}","releases_url":"https://api.github.com/repos/ischwabacher/afni/releases{/id}","created_at":"2015-05-14T16:22:05Z","updated_at":"2015-05-14T16:22:25Z","pushed_at":"2015-12-16T00:05:56Z","git_url":"git://github.com/ischwabacher/afni.git","ssh_url":"git@github.com:ischwabacher/afni.git","clone_url":"https://github.com/ischwabacher/afni.git","svn_url":"https://github.com/ischwabacher/afni","homepage":"http://afni.nimh.nih.gov/afni","size":163742,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"afni:master","ref":"master","sha":"530a876f9de9901f9345f30e767d633c7be35d55","user":{"login":"afni","id":8329700,"avatar_url":"https://avatars.githubusercontent.com/u/8329700?v=3","gravatar_id":"","url":"https://api.github.com/users/afni","html_url":"https://github.com/afni","followers_url":"https://api.github.com/users/afni/followers","following_url":"https://api.github.com/users/afni/following{/other_user}","gists_url":"https://api.github.com/users/afni/gists{/gist_id}","starred_url":"https://api.github.com/users/afni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afni/subscriptions","organizations_url":"https://api.github.com/users/afni/orgs","repos_url":"https://api.github.com/users/afni/repos","events_url":"https://api.github.com/users/afni/events{/privacy}","received_events_url":"https://api.github.com/users/afni/received_events","type":"Organization","site_admin":false},"repo":{"id":35209231,"name":"afni","full_name":"afni/afni","owner":{"login":"afni","id":8329700,"avatar_url":"https://avatars.githubusercontent.com/u/8329700?v=3","gravatar_id":"","url":"https://api.github.com/users/afni","html_url":"https://github.com/afni","followers_url":"https://api.github.com/users/afni/followers","following_url":"https://api.github.com/users/afni/following{/other_user}","gists_url":"https://api.github.com/users/afni/gists{/gist_id}","starred_url":"https://api.github.com/users/afni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afni/subscriptions","organizations_url":"https://api.github.com/users/afni/orgs","repos_url":"https://api.github.com/users/afni/repos","events_url":"https://api.github.com/users/afni/events{/privacy}","received_events_url":"https://api.github.com/users/afni/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/afni/afni","description":"Official AFNI source and documentation","fork":false,"url":"https://api.github.com/repos/afni/afni","forks_url":"https://api.github.com/repos/afni/afni/forks","keys_url":"https://api.github.com/repos/afni/afni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/afni/afni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/afni/afni/teams","hooks_url":"https://api.github.com/repos/afni/afni/hooks","issue_events_url":"https://api.github.com/repos/afni/afni/issues/events{/number}","events_url":"https://api.github.com/repos/afni/afni/events","assignees_url":"https://api.github.com/repos/afni/afni/assignees{/user}","branches_url":"https://api.github.com/repos/afni/afni/branches{/branch}","tags_url":"https://api.github.com/repos/afni/afni/tags","blobs_url":"https://api.github.com/repos/afni/afni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/afni/afni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/afni/afni/git/refs{/sha}","trees_url":"https://api.github.com/repos/afni/afni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/afni/afni/statuses/{sha}","languages_url":"https://api.github.com/repos/afni/afni/languages","stargazers_url":"https://api.github.com/repos/afni/afni/stargazers","contributors_url":"https://api.github.com/repos/afni/afni/contributors","subscribers_url":"https://api.github.com/repos/afni/afni/subscribers","subscription_url":"https://api.github.com/repos/afni/afni/subscription","commits_url":"https://api.github.com/repos/afni/afni/commits{/sha}","git_commits_url":"https://api.github.com/repos/afni/afni/git/commits{/sha}","comments_url":"https://api.github.com/repos/afni/afni/comments{/number}","issue_comment_url":"https://api.github.com/repos/afni/afni/issues/comments{/number}","contents_url":"https://api.github.com/repos/afni/afni/contents/{+path}","compare_url":"https://api.github.com/repos/afni/afni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/afni/afni/merges","archive_url":"https://api.github.com/repos/afni/afni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/afni/afni/downloads","issues_url":"https://api.github.com/repos/afni/afni/issues{/number}","pulls_url":"https://api.github.com/repos/afni/afni/pulls{/number}","milestones_url":"https://api.github.com/repos/afni/afni/milestones{/number}","notifications_url":"https://api.github.com/repos/afni/afni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/afni/afni/labels{/name}","releases_url":"https://api.github.com/repos/afni/afni/releases{/id}","created_at":"2015-05-07T08:50:23Z","updated_at":"2015-09-26T23:10:48Z","pushed_at":"2015-12-16T00:07:39Z","git_url":"git://github.com/afni/afni.git","ssh_url":"git@github.com:afni/afni.git","clone_url":"https://github.com/afni/afni.git","svn_url":"https://github.com/afni/afni","homepage":"http://afni.nimh.nih.gov/afni","size":163703,"stargazers_count":6,"watchers_count":6,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":3,"forks":10,"open_issues":3,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/afni/afni/pulls/19"},"html":{"href":"https://github.com/afni/afni/pull/19"},"issue":{"href":"https://api.github.com/repos/afni/afni/issues/19"},"comments":{"href":"https://api.github.com/repos/afni/afni/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/afni/afni/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/afni/afni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/afni/afni/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/afni/afni/statuses/71efc755739b8641308e24fea1830fa6ae754324"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":486,"deletions":401,"changed_files":4}}