replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - UNDEF
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

UNDEF
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 08, 2012 5:50 am    Post subject: UNDEF Reply with quote

Hi there,

I have a routine that accesses binary-data in an array.
I have Full checking code ticked.

One of my routines crashes with:

Error 112, Reference to undefined variable, array element or function result (/UNDEF)

Indeed my array does have UNDEFINED in them.
However, I was told a while back to use "cFTN95$INHIBIT_CHECK 11" in order to "turn off" UNDEF for a file. Since I am using the ".f95" extension for my code I attempted to use "!FTN95$INHIBIT_CHECK 11" (as the first line of my source-file) but this appears not to work since I get the error as show above.

Please advise.

Marz
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Thu Nov 08, 2012 9:58 am    Post subject: Reply with quote

You can disable checking options via a comment embedded directive but number 11 does not relate to /UNDEF.

Try

!FTN95$OPTIONS(-UNDEF)

and look at a /LIST or /EXPLIST to see if it has worked.

Better still, do not use /UNDEF on the command line (use /CHECK rather than /CHECKMATE).

Even better, are you sure that you need to switch this off. What will happen at runtime if values are not set?
Back to top
View user's profile Send private message AIM Address
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 08, 2012 6:57 pm    Post subject: Reply with quote

I do not recall the exact wording that was used when I was told to use "cFTN95$INHIBIT_CHECK 11", but in the ".for" file it "appeared" to have worked.

I have no idea what /LIST and /EXPLIST are, and have no idea how to look at them in order to see if it has worked.

I do not myself explicitly use "/UNDEF" on the command line, I am using the IDE to write and debug my code.

I do not know if I "need" to switch /UNDEF off. If I knew how to read in a binary-file and access the data without having to do so then I would have already done so.

The values in the binary-file can be such that an UNDEFINED value is present when read into an array. So in the case for these particular routines I most certainly DO want an UNDEFINED value to "happen".

Regards

Marz
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Thu Nov 08, 2012 8:39 pm    Post subject: Reply with quote

When you install FTN95, the installation includes a file FTN95.CHM, which is a searchable Windows help file. In it is information on many things you will find helpful. One of the sections in this document describes compiler options. While it is easier to use compiler options in a command-line environment, you can invoke them when you are compiling through PLATO. The two listing options are described as follows:

/LIST [<filename>] more...
Produces a source listing file. If <filename> is not provided, the name is created by replacing the source-suffix with .LIS, e.g. with FOO.F90, the map file would be FOO.LIS.

/EXPLIST [<filename>]
Generate a listing file containing a symbolic assembler listing. <filename> is the optional name of the .LIS file. /EXPLIST is equivalent to /LIST but causes each source statement to be followed by the assembler statements corresponding to the instructions into which it was compiled.

If you generate a listing file you can look at it using any application that can read plain text files. If you don't understand assembly language, /EXPLIST isn't going to be very helpful.

There is nothing intrinsically wrong with having undefined values in any variable, but if you actually use those values in any conventional sort of arithmetic, you don't have a clue as to what the result will be, and the chance is that your program will produce nonesense. Many programs do this anyway, but it is difficult to believe that it is your intention!

The pattern of bits that signals a value is undefined in a floating point number may be perfectly valid if interpreted (say) as characters, or graphics, but then you need to access the relevant bytes in the right way.

Good luck!

Eddie
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Nov 10, 2012 11:11 am    Post subject: Re: Reply with quote

LitusSaxonicum wrote:

There is nothing intrinsically wrong with having undefined values in any variable, but if you actually use those values in any conventional sort of arithmetic, you don't have a clue as to what the result will be *snip*


The result will be undefined but you might not realise it Smile

I try to define only the variables I need in a particular scope and leave all the other variables that are in scope undefined. This way, if I make a mistake and reference one of the undefined varables in an expression, the run-time checking (/CHECKMATE) will show me my error.

For debugging, I also put a call in the program to explicitly undefine variables that should not be referenced, e.g.

Code:

call set_undefined(a)
call set_undefined(b)


where set_undefined is simply

Code:

subroutine set_undefined(var)
real, intent(out) :: var !< make var undefined using /CHECKMATE
end subroutine set_undefined


I actually have a collection of set_undefined in a module with one generic INTERFACE to handle all variable types and kinds.

In the following loop, a and tmp do not need to be carried from one loop iteration to the next, so are made undefined.

Code:

s = 0.0
do i=1, 100

    ! lose values when loop is entered and at last iteration
    ! comment out in production code.
   call set_undefine(a)
   call set_undefine(tmp)



   ! Inadvertant reference of a or tmp here will give an error




   a = real(i)
   tmp = a**2  ! An error would occur here if i forgot to define a
   s = s + tmp ! An error would occur here if i forgot to define tmp

end do


This is extra work, but it helps to document the code and saves time during debugging.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Sat Nov 10, 2012 1:32 pm    Post subject: Reply with quote

David,

Some useful ideas here, and food for thought, but probably too sophisticated for the needs of the original poster. I am certainly going to think about these approaches.

The business of the scope of a variable is far more complex when using modules in Fortran 90 et seq than it was in Fortran 77 and earlier, although even the latter could get you in trouble. (The facilities provided in the newer standards are solutions to problems that I don't have, and some of them produce problems that I never had before!)

Eddie
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Wed Nov 14, 2012 12:32 am    Post subject: Reply with quote

The post was not "too sophisticated" for me, I understand it well. I am however unsure if anyone has understood my problem "sufficiently".

I have binary data that I read into an Integer*1 array.
Each element of this array is not necessarily a single entity with respect to the function that is accessing it. Many elements may be required to form a number that it requires.

For example, the function may need to extract:

array(73) at bit-positions 3 to 7
and
array(74) at bit-positions 0 to 5

in order to retrieve an 11-bit number.

The problem is that each element of the array may have a bit-pattern that implies "undefined", so when the function reads the data into an Integer*1 the error as stated in the original post occurs.

Marz
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Nov 14, 2012 2:46 am    Post subject: Reply with quote

For the code that requires this range of values, don't use compiler options that select /UNDEF.
Once you are confident this code works correctly, why do you continue with /CHECK. I'd recommend using only /DEBUG.

John
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Wed Nov 14, 2012 11:49 am    Post subject: Reply with quote

You have to store and define 8 bits at a time in your integer*1 array. You can store 6 bits for example with 2 leading bits set to 0.

You should be able to use TRANSFER to avoid the interpretation of a bit pattern as an undefined value.

What form is the binary data in?

Can we see a line or two of code which gives the error?
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Wed Nov 14, 2012 8:58 pm    Post subject: Reply with quote

"Too sophisticated" wasn't intended to be insulting. But your remark:

Quote:
I have no idea what /LIST and /EXPLIST are, and have no idea how to look at them in order to see if it has worked.


does rather suggest that your requirements were basic, and I apologise if this was a misunderstanding.

If your array variable is integer, then you shouldn't ever get 'undefined' - because all possible bit patterns in an integer*1 (one byte) are valid values (00000000 to 11111111 and everything in between represent the integers from -128 to +127). Whether you set bits yourself, or they are just random 'junk', the combination of bits in an integer*1 is always a valid combination. Hence I don't understand why any part of FTN95 would throw a fit when presented with any values in integer*1 format. Equally, character*(1) is always valid, and represents characters for 0 to 255 in whatever character set you want.

You should only get a runtime error of undefined if you access a combination of bytes as real*something (4, 8 or 10 bytes), so my next guess is that you aren't always referring to the elements in that array as integer.

Your latest explanation refers to 11 bits extracted from 2 consecutive bytes, so my alternate guess is that Error 112 comes about if you are trying to squeeze that 11-bit combination back into an 8-bit space! In that case, the reference isn't to an undefined variable or array element when you access it, but to a function result.

However if you do not post any code, the true problem may never be found, as no-one here can do more than just guess at to the real nature of the problem. If you cannot extract the problem in just a few lines of code, it is possible to post a longer code in dropbox or its equivalent. There are clearly several people here who would like to help.

E
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 15, 2012 6:53 pm    Post subject: Reply with quote

@JohnCampbell:

When I am confident that some code works correctly I want to continue with /UNDEF because I will no doubt be writing more new code, which I am less confident about.
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 15, 2012 7:06 pm    Post subject: Reply with quote

@davidb

One defining and necessary condition of the program/data is that ALL 8-bits are used.

Here is the line (and associations) that causes trouble:

Header-file Start
Type(Structure)
.
.
.
Integer*1, Pointer :: pstData(Smile
End Type(Structure)
Header-file End

Subprogram Start
!! Passed
Type(Structure), INTENT(INOUT) :: pstTileDataP

!! Locals
Integer*4 :: iByteOffsetL
Integer*1 :: i1Value1L
.
.
.
i1Value1L = pstTileDataP%pstData(iByteOffsetL + 1)
.
.
.
Subprogram End


The value in the array at pstData(iByteOffsetL + 1) is: Z'80'_1 == 128

Marz
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 15, 2012 7:08 pm    Post subject: Reply with quote

Thanks to all who are trying to help with this Very Happy
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 15, 2012 7:17 pm    Post subject: Reply with quote

@LitusSaxonicum

I believe that my requirements are quite basic Very Happy

When I examine arrays that are of the Integer 1,2 and 4 bytes nature, I notice the following:

1) 1-Byte: UNDEFINED pattern == Hex(80) == 128
2) 2-Byte: UNDEFINED pattern == Hex(8080) == 32896
3) 1-Byte: UNDEFINED pattern == Hex(80808080) == 2155905152


I Consequently struggle to know how to reply to your statement of:

"If your array variable is integer, then you shouldn't ever get 'undefined' - because all possible bit patterns in an integer*1 (one byte) are valid values (00000000 to 11111111 and everything in between represent the integers from -128 to +127). Whether you set bits yourself, or they are just random 'junk', the combination of bits in an integer*1 is always a valid combination."

Regarding "trying to squeeze that 11-bit combination back into an 8-bit space", the error occurs when I read the data from the Integer*1 array into an Integer*1 local variable, and therefore the functionality of the function does not matter at that point.

I thank you for your time and consideration on the matter
Very Happy

Marz
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Thu Nov 15, 2012 7:21 pm    Post subject: Reply with quote

Further to this problem, I tried putting in the line:

!FTN95$OPTIONS(-UNDEF)

in order to switch off UNDEF for a module, and it "worked". It does however have an undesirable side-effect in that I can no longer debug through that module. Any attempt to F7 into it is ignored, and when I "find" the routine (within the debugger) it returns a window with Assembly-Language therein.

When I remove the line shown abouve, then I am again able to debug the code, but of course the UNDEF problem occurs - lol

Is this "normal" behaviour?

TIA

Marz
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group