Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
LEN of subroutine variables
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
mrestelli@gmail.com  
View profile  
 More options Aug 20 2007, 9:29 am
Newsgroups: comp.lang.fortran
From: "mreste...@gmail.com" <mreste...@gmail.com>
Date: Mon, 20 Aug 2007 13:29:51 -0000
Local: Mon, Aug 20 2007 9:29 am
Subject: LEN of subroutine variables
Hello,
   I would like to ask you if the following code is legal (notice the
LEN type parameter of MOD_B_STRING):

module mod_a
 implicit none
 character(len=100) :: mod_a_string
end module mod_a

module mod_b
 use mod_a
 implicit none

contains

 subroutine mod_b_sub()
  character(len=len(trim(mod_a_string))+2) :: &
    mod_b_string

   mod_b_string = trim(mod_a_string) // '!!'
   write(*,*) mod_b_string

 end subroutine mod_b_sub
end module mod_b

program test_string

 use mod_a
 use mod_b

 implicit none

 mod_a_string = 'Hello'
 call mod_b_sub()

end program test_string

When this code is compiled with gfortran or ifort, it behaves "as
expected", in that it prints Hello!! (no warning even when using all
the debugging options). Also, valgrind shows no errors.  With pgf,
however, the code compiles with no errors but at runtime produces a
huge blank output. Here, valgrind complains about "Conditional jump or
move depends on uninitialised value(s)" at CALL MOD_B_SUB().

(more details:
gfortran --version
 GNU Fortran 95 (GCC) 4.1.2 (Gentoo 4.1.2)
ifort --version
 ifort (IFORT) 9.1 20061101
pgf95 -V
 pgf95 6.1-1 32-bit target on x86 Linux)

Thank you!
   Marco Restelli


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Aug 20 2007, 12:45 pm
Newsgroups: comp.lang.fortran
From: Richard Maine <nos...@see.signature>
Date: Mon, 20 Aug 2007 09:45:47 -0700
Local: Mon, Aug 20 2007 12:45 pm
Subject: Re: LEN of subroutine variables
On Mon, 20 Aug 2007 06:29:51 -0700, mreste...@gmail.com wrote
(in article <1187616591.093651.68...@k79g2000hse.googlegroups.com>):

>    I would like to ask you if the following code is legal (notice the
> LEN type parameter of MOD_B_STRING):

  [code elided]

Yes, that looks fine. It is even ok in f90. (This is an area where things got
progressively more liberal with each version of the standard, but this one
looks ok for f90 and later).

> When this code is compiled with gfortran or ifort, it behaves "as
> expected", in that it prints Hello!! (no warning even when using all
> the debugging options). Also, valgrind shows no errors.

Good.

>  With pgf, however,...

I'd suggest a bug report. Pgf isn't the most robust compiler out there. It is
better than it used to be, but still has plenty of room to go.

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

________________________________________________

 Hogwasher, Premier News and Mail for OS X
      http://www.asar.com/cgi-bin/product.pl?58/hogwasher.html
________________________________________________


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Problems with unformatted reads with FORTRAN 77 and Fortran 95" by Paul Hilscher
Paul Hilscher  
View profile  
 More options Aug 20 2007, 1:26 pm
Newsgroups: comp.lang.fortran
From: Paul Hilscher <p.hilsc...@gmx.net>
Date: Mon, 20 Aug 2007 19:26:18 +0200
Local: Mon, Aug 20 2007 1:26 pm
Subject: Problems with unformatted reads with FORTRAN 77 and Fortran 95
Hello,

I'm trying to port a data saving routine from a FORTRAN 77 program to
Fortran 95 but stuck with the following read problem :

FORTRAN 77 'unform_types.f':

program main
      implicit none
      integer :: i = 7, j, k
      open(unit=12,file='Itype77.dat',status='replace',            
     %             form='unformatted')
      write(12),i
      close(12)

      open(unit=12,file='Itype95.dat',form='unformatted')
      read(12),j
      close(12)
      write(*,*) 'Itype95', j

      open(unit=12,file='Itype77.dat',form='unformatted')
      read(12),k
      close(12)
      write(*,*) 'Itype77', k

      end program main

the "ported" Fortran 95 Code 'unform_types.f95' :

 program main
      implicit none
      integer(kind=4) :: i = 7, j, k
      open(unit=12,file='Itype95.dat',status='replace', &
                   form='unformatted')
      write(12),i
      close(12)

      open(unit=12,file='Itype95.dat',form='unformatted')
      read(12),j
      close(12)
      write(*,*) 'IType95', j

      open(unit=12,file='Itype77.dat',form='unformatted')
      read(12),k
      close(12)
      write(*,*) 'IType77', k

      end program main

*Compiling with:
philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$ ls -l Itype*
-rw-r--r-- 1 philscher philscher 12 2007-08-20 19:17 Itype77.dat
-rw-r--r-- 1 philscher philscher 20 2007-08-20 19:17 Itype95.dat
philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$

 f95  -o for95 unform_types.f95 &
 f77  -o for77 unform_types.f

*and running, produces following results on my machine

philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$ ./for77
 Itype95 0
 Itype77 7
philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$

*and

philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$ ./for95
 IType95           7
 IType77           4
philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$

philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$ ls -l Itype*
-rw-r--r-- 1 philscher philscher 12 2007-08-20 19:17 Itype77.dat
-rw-r--r-- 1 philscher philscher 20 2007-08-20 19:17 Itype95.dat
philscher@Ariel:~/Science/HiWi - MPIA/Hydrocode/FortranBox$

*Why are the results different ? The programs produces Itype*.dat files
that are different in size. I played around with the integer(kind=...)
parameter in the F-95 Code but never get the desired result. I think the
problem lies that Fortran-95 uses a 8-byte long record header, while
F-77 uses only 4-byte. But why is this so and what should I do to get
things work ?

Thanks for reading & helping

Paul


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gordon Sande  
View profile  
 More options Aug 20 2007, 1:53 pm
Newsgroups: comp.lang.fortran
From: Gordon Sande <g.sa...@worldnet.att.net>
Date: Mon, 20 Aug 2007 17:53:27 GMT
Local: Mon, Aug 20 2007 1:53 pm
Subject: Re: Problems with unformatted reads with FORTRAN 77 and Fortran 95
On 2007-08-20 14:26:18 -0300, Paul Hilscher <p.hilsc...@gmx.net> said:

Probably. Why does it matter? Unformatted i/o is intended to be read in
by the same program (or at least one of its close relatives). Reading
by diferent programs that have different record conventions, as you
describe, is always a bother. There may be "compiler" options that
inform the run time system of your preferences. RTFM very carefully.
Some vendors have utilities that will convert the record headers or
you can do it yourself if this is going to be an ongoing bother.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Aug 20 2007, 2:37 pm
Newsgroups: comp.lang.fortran
From: Richard Maine <nos...@see.signature>
Date: Mon, 20 Aug 2007 11:37:24 -0700
Local: Mon, Aug 20 2007 2:37 pm
Subject: Re: Problems with unformatted reads with FORTRAN 77 and Fortran 95
On Mon, 20 Aug 2007 10:26:18 -0700, Paul Hilscher wrote
(in article <1187630777.20834.17.camel@Ariel>):

> I think the
> problem lies that Fortran-95 uses a 8-byte long record header, while
> F-77 uses only 4-byte. But why is this so and what should I do to get
> things work ?

This is a function of the particular compilers involved - not of f77 versus
f95 in general. Unless I missed it, you didn't mention the particular
compilers you used. As Gordon mentioned, unformatted I/O is not generally
guaranteed to be interoperable between different compilers. This is *NOT*
related to f77 versus f90. There were f77 compilers with many, many different
variants of unformatted file formats... not to speak of the detail that there
were historically lots of different binary data representations. Things have
converged quite a bit today; there are still multiple variants, but not
nearly as many as there used to be.

I wonder if you are using gFortran for your f95 compiler. Most f95 compilers
go out of their way to use a scheme that is compatible with the most common
existing practices. I seem to recall that gFortran had (has?) an option
related to this, but that the default was to be incompatible. I thought that
a poor choice, but...

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

________________________________________________

 Hogwasher, Premier News and Mail for OS X
      http://www.asar.com/cgi-bin/product.pl?58/hogwasher.html
________________________________________________


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Powers  
View profile  
 More options Aug 20 2007, 3:01 pm
Newsgroups: comp.lang.fortran
From: Craig Powers <eni...@hal-pc.org>
Date: Mon, 20 Aug 2007 15:01:20 -0400
Local: Mon, Aug 20 2007 3:01 pm
Subject: Re: Problems with unformatted reads with FORTRAN 77 and Fortran 95

Richard Maine wrote:

> I wonder if you are using gFortran for your f95 compiler. Most f95 compilers
> go out of their way to use a scheme that is compatible with the most common
> existing practices. I seem to recall that gFortran had (has?) an option
> related to this, but that the default was to be incompatible. I thought that
> a poor choice, but...

If I'm not mistaken, gfortran has somewhat recently switched to using
the ifort scheme for extended record sizes, with compatibility options
for the original extended record size usage.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Hilscher  
View profile  
 More options Aug 20 2007, 5:19 pm
Newsgroups: comp.lang.fortran
From: Paul Hilscher <phils...@ix.urz.uni-heidelberg.de>
Date: Mon, 20 Aug 2007 23:19:07 +0200
Local: Mon, Aug 20 2007 5:19 pm
Subject: Re: Problems with unformatted reads with FORTRAN 77 and Fortran 95
Dnia 20-08-2007, pon o godzinie 15:01 -0400, Craig Powers napisał(a):
> Richard Maine wrote:

> > I wonder if you are using gFortran for your f95 compiler. Most f95 compilers
> > go out of their way to use a scheme that is compatible with the most common
> > existing practices. I seem to recall that gFortran had (has?) an option
> > related to this, but that the default was to be incompatible. I thought that
> > a poor choice, but...

> If I'm not mistaken, gfortran has somewhat recently switched to using
> the ifort scheme for extended record sizes, with compatibility options
> for the original extended record size usage.

Indeed, with gfortran -frecord-marker=4 everything works fine, thanks a
lot for the hint !
According to the gfortran manual they changed this to be
the new default value for version 4.2.1+, so bad luck for me ubuntu came
with version 4.1 ;)

Paul


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google