Fanning Software Consulting

Storing Associated File Variables

QUESTION: I'm having a problem using associated file variables. I have a series of files that contain arrays of unsigned integers. I'm trying to use Assoc to be able to access the arrays, but I so far have had no luck in getting it to work.

The error that I'm getting is File expression not allowed in this context:(UINT FILE). I get this error when I try to execute the Assoc statement. I've checked for an error when the file is opened, but have detected none.

Can anybody point out what I'm doing wrong? Here is the code.

pro fileSet::createAssociation, filename,samples
    openu,1,filename, ERROR = err
    IF (err NE 0) then PRINTF, -2, !ERROR_STATE.MSG
    self.sonarData =  assoc(1,uintarr(samples))
end

ANSWER: Humm. Yes, the error message is not really all that helpful in this case. The problem here is that whatever it is that ASSOC returns (i.e., an associated variable), can't be stored in the self.sonarData variable field. This is probably because self.sonarData is an integer, or long integer, or something else quite sensible, and the associated variable isn't any of these things. In fact, it's not even a variable in any normal sense of the term. In any case, it's not anything that at first glance can be stored in a structure field, which certainly has to be declared as something. :-(

Jeff Guerber has come to the rescue, however, by pointing out that an associated variable can be stored in a pointer! (No one I've talked to seems to know why this is the case. It's part of the Mystery, I guess. In any case, we shouldn't look gift horses in the mouth.) Your problem can be solved by making the self.sonarData field a pointer.

Google
 
Web Coyote's Guide to IDL Programming