Fixing "Keyword parameters not allowed" Error in IDL Function

Click For Summary
SUMMARY

The discussion centers on resolving the "Keyword parameters not allowed" error encountered in an IDL function. The user attempts to define a function named histimage that accepts a keyword parameter binsize, but faces a compile error due to incorrect syntax. The correct approach involves using if keyword_set(x) then and ensuring proper syntax for conditional statements. The solution emphasizes the necessity of adhering to IDL's keyword handling conventions.

PREREQUISITES
  • Understanding of IDL (Interactive Data Language) programming
  • Familiarity with keyword parameters in IDL functions
  • Basic knowledge of conditional statements in programming
  • Experience with array manipulation in IDL
NEXT STEPS
  • Review IDL documentation on keyword parameters and their usage
  • Learn about conditional statements in IDL and their syntax
  • Explore best practices for defining functions in IDL
  • Investigate common compile errors in IDL and their solutions
USEFUL FOR

ID developers, programmers working with IDL functions, and anyone troubleshooting keyword parameter issues in IDL.

big man
Messages
241
Reaction score
0

Homework Statement


I've created a function inside IDL and I want to be able to specify the binsize.
That is, I want to have:

result = myfunction(array, keyword)

Whenever I add the keyword in the brackets there it says:

"Keyword parameters not allowed in call."


2. Relevant code

FUNCTION histimage, array, binsize=x

If KEYWORD_SET(x) then $

count = uintarr(256/x)
array = array*(1/x)
array=round(array)

*end if else begin
count = uintarr(256)

for j = 0,255 do begin
for k = 0,255 do begin
count(array(j,K)) = count(array(j,k)) + 1
endfor
endfor

Return, count

END

Histimage is the name of my function and binsize is the keyword. The point in the code where there is a * shows where I get a compile error as well. I can't see why I get this error and was hoping that someone could tell me if I've used incorrect syntax.
 
Physics news on Phys.org
Hi, hope this isn't too late to be of help, I stumbled across this looking for help on keyword syntax.

In IDL I think you need:

if keyword_set(x) then blah
if not keyword_set(x) then bleh

I think that's why you're getting a compile error at "endif else begin", as it's not the correct syntax for the keyword_set function.
 

Similar threads

Replies
7
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 24 ·
Replies
24
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K