For Programmers: Free Programming Magazines  


Home > Archive > Fortran > January 2008 > Error while reading in pointer Location









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Error while reading in pointer Location
Ravindra Vidhate

2008-01-26, 4:29 am

Hi,

I have following lines of code

integer err_d1,ind_d1
pointer (ptr_d1,td1)
real*8 td1(*)

err_d1=0
call sys_alloc(nbent*nbvent,ptr_d1,err_d1)
read(isolu,rec=irec,err=980) <- Crashes here
+ (td1(in),in=1,nbent*nbvent)
do in=1,nbent*nbvent
dm(lpsol0+in-1)=dble(td1(in))
enddo
call sys_free(ptr_d1,err_d1)

In the function sys_alloc I am allocating memory to the ptr_d1. It
crashes the application when it executes the read statement.

Can any please help me on this .

Ravindra
Louis Krupp

2008-01-26, 4:29 am

Ravindra Vidhate wrote:
> Hi,
>
> I have following lines of code
>
> integer err_d1,ind_d1
> pointer (ptr_d1,td1)
> real*8 td1(*)
>
> err_d1=0
> call sys_alloc(nbent*nbvent,ptr_d1,err_d1)
> read(isolu,rec=irec,err=980) <- Crashes here
> + (td1(in),in=1,nbent*nbvent)
> do in=1,nbent*nbvent
> dm(lpsol0+in-1)=dble(td1(in))
> enddo
> call sys_free(ptr_d1,err_d1)
>
> In the function sys_alloc I am allocating memory to the ptr_d1. It
> crashes the application when it executes the read statement.
>
> Can any please help me on this .


What kind of "crash" do you get?

Are you sure sys_alloc is successful in allocating memory?

Louis
fj

2008-01-26, 8:17 am

On 26 jan, 11:22, Louis Krupp <lkr...@pssw.nospam.com.invalid> wrote:
> Ravindra Vidhate wrote:
>
>
>
>
>
>
> What kind of "crash" do you get?
>
> Are you sure sys_alloc is successful in allocating memory?
>
> Louis


Could you also precise how the file isolu is opened, what is the value
of irec and what happens at the label 980.

In summary, let us see your complete program source please!

James Van Buskirk

2008-01-26, 7:21 pm

"Ravindra Vidhate" <ravividhate@gmail.com> wrote in message
news:32e9e9e8-c733-42e2-972b-b956c5457543@s27g2000prg.googlegroups.com...

> call sys_alloc(nbent*nbvent,ptr_d1,err_d1)


> In the function sys_alloc I am allocating memory to the ptr_d1. It
> crashes the application when it executes the read statement.


You need an explicit interface to sys_alloc in the scope of the
caller for this to work. Since you didn't post it I will assume
that you are not aware of this problem. Proposed solution:

change

subroutine sys_alloc(...)
....
end
to

module sys_alloc_mod
subroutine sys_alloc(...)
end subroutine sys_alloc ! Note change on this line too
end module sys_alloc_mod

this include the line

use sys_alloc_mod

in the calling program, right up there at the beginning of
the specification part, just before the IMPLICIT NONE
statement.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Richard Maine

2008-01-26, 7:21 pm

James Van Buskirk <not_valid@comcast.net> wrote:

> "Ravindra Vidhate" <ravividhate@gmail.com> wrote in message
> news:32e9e9e8-c733-42e2-972b-b956c5457543@s27g2000prg.googlegroups.com...
>
>
>
> You need an explicit interface to sys_alloc in the scope of the
> caller for this to work.


Really? Did you notice that this is not an f90 pointer, but rather a
Cray pointer. I don'ty think that Cray pointers have much to do with
explicit interfaces (since they are from an era before then). It
wouldn't surprise me at all to find out that the problem is in this
call. In fact, I'd lay good odds on it. But between the fact that I
don't know Cray pointers very well and the fact that the OP didn't
provide any useful information about this procedure, I can't comment
much more usefully.

To the OP. Saying that you are trying to allocate memory, but that it
doesn't work, does not count as anywhere near enough information. You
would actually have to show the code - not just say what you think it
ought to be doing. Showing just the code for the main program (and not
all of that either) is *NOT* enough. The odds are prety much zero that
the problem is actually in the READ statement.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Gary Scott

2008-01-26, 7:21 pm

Ravindra Vidhate wrote:
> Hi,
>
> I have following lines of code
>
> integer err_d1,ind_d1
> pointer (ptr_d1,td1)
> real*8 td1(*)
>
> err_d1=0
> call sys_alloc(nbent*nbvent,ptr_d1,err_d1)
> read(isolu,rec=irec,err=980) <- Crashes here
> + (td1(in),in=1,nbent*nbvent)
> do in=1,nbent*nbvent
> dm(lpsol0+in-1)=dble(td1(in))
> enddo
> call sys_free(ptr_d1,err_d1)
>
> In the function sys_alloc I am allocating memory to the ptr_d1. It
> crashes the application when it executes the read statement.
>
> Can any please help me on this .
>
> Ravindra

Suggest showing the value of err_d1 (and its definition)...maybe the
allocation failed and you have an error code which describes why.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
James Van Buskirk

2008-01-26, 7:21 pm

"Richard Maine" <nospam@see.signature> wrote in message
news:1ibbmkz.7mn9t11swl0w3N%nospam@see.signature...

> James Van Buskirk <not_valid@comcast.net> wrote:


[color=darkred]
> Really? Did you notice that this is not an f90 pointer, but rather a
> Cray pointer.


No, I did not! Mega-ouch... I always read pointer as Fortran pointer
if Seymour's adjective is absent.

> I don'ty think that Cray pointers have much to do with
> explicit interfaces (since they are from an era before then). It
> wouldn't surprise me at all to find out that the problem is in this
> call. In fact, I'd lay good odds on it. But between the fact that I
> don't know Cray pointers very well and the fact that the OP didn't
> provide any useful information about this procedure, I can't comment
> much more usefully.


> To the OP. Saying that you are trying to allocate memory, but that it
> doesn't work, does not count as anywhere near enough information. You
> would actually have to show the code - not just say what you think it
> ought to be doing. Showing just the code for the main program (and not
> all of that either) is *NOT* enough. The odds are prety much zero that
> the problem is actually in the READ statement.


All right, my next candidate is declaring the dummy argument
corresponding to actual argument ptr_d1 as default integer on a
64-bit machine, but you're right in that a complete compilable
example takes away much of the guesswork. There is so much
opportunity for things to go wrong in the omitted code.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Gary Scott

2008-01-26, 7:21 pm

Gary Scott wrote:

> Ravindra Vidhate wrote:
>
>
> Suggest showing the value of err_d1 (and its definition)...maybe the
> allocation failed and you have an error code which describes why.
>

One more thing, not knowing what sys_alloc does, some allocations
require the value to be a multiple of some base size like 512 bytes or
4096 bytes, etc. Some automatically round up, some issue an error if
you don't specify an exact multiple value.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com