CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Fortran, does anyone know how..

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 30, 2000, 05:52
Default Fortran, does anyone know how..
  #1
Frank Muldoon
Guest
 
Posts: n/a
if it is possible to pass an array to a subroutine without passing it's bounds and have the subroutine get the correct bounds? The following runs but gives bounds from 1 to 9 for a in the subroutine.

Thanks, Frank

real, dimension(2:10) :: a

a=1.2 a(2)=2.2

call sub(a) end

subroutine sub(a) real, dimension( :: a write(*,*)lbound(a,1),ubound(a,1) return end subroutine sub
  Reply With Quote

Old   June 30, 2000, 14:05
Default Re: Fortran, does anyone know how..
  #2
Nishikawa
Guest
 
Posts: n/a
One way to do something like that would be to use MODULE. Define the following module.

MODULE ARRAY_a

real, dimension(2:10) :: a

END MODULE ARRAY_a

The array "a" is then accessible to anywhere by just typing "USE ARRAY_a". Well, it's like a COMMON in Fortran77.

  Reply With Quote

Old   July 2, 2000, 05:20
Default Re: Fortran, does anyone know how..
  #3
Shigunov
Guest
 
Posts: n/a
It is possible to do so:

subroutine sub(a) real, dimension(2 :: a write(*,*)lbound(a,1),ubound(a,1) return end

subroutine sub

Then the bounds of a will be correct

With best regards
  Reply With Quote

Old   July 2, 2000, 12:21
Default Re: Fortran, does anyone know how..
  #4
John C. Chien
Guest
 
Posts: n/a
(1). I have been studying C/C++, and I can say that you are not using C/C++. (2).I don't think you are using f77 either, because "::" is the scope operator in C++, such as the member function of a class. (3). I can only say that you are using a new language, a version of Fortran or something like that. (4). If the language is not clearly defined, then it is not a good language. (5). If you have to use it (the only compiler available to you), then try to use only the standard features which are backward compatible to f77. (6). Trying to use new features of a language can only make the code less portable and very hard to read later on. (7). This is just a comment, and it does not solve your question right away.
  Reply With Quote

Old   July 2, 2000, 22:34
Default Re: Fortran, does anyone know how..
  #5
Nishikawa
Guest
 
Posts: n/a
Yes! That's it. But, just make sure that you have the interface:

INTERFACE

SUBROUTINE SUB(a)

real, dimension( :: a

END SUBROUTINE

END INTERFACE

in the main program. Without this, it won't work.

(If the subprogram is contained in a module, the interface is not necessary, of course.)

BTW, I'm assuming that you're using Fortran 90.
  Reply With Quote

Old   July 3, 2000, 15:55
Default Re: Fortran, does anyone know how..
  #6
Frank Muldoon
Guest
 
Posts: n/a
This will work for the case of a lower bound = 2. However I need to be able to call the subroutine with varying upper and lower bounds without passing in the bounds with the call. This is because of multigrid. It would seem like there should be away to do this. In answer to John C. Chien this is Fortran 90/95.

Thanks Frank
  Reply With Quote

Old   July 3, 2000, 16:23
Default Re: Fortran, does anyone know how..
  #7
Nishikawa
Guest
 
Posts: n/a
Well, how about using the data module as I said in my first message? This way, you can use "a" just as you defined in the module anywhere in the entire program. No need to pass the bounds as well as "a".
  Reply With Quote

Old   July 3, 2000, 18:34
Default Re: Fortran, does anyone know how..
  #8
Frank Muldoon
Guest
 
Posts: n/a
That is actually what I am currently doing. However that means that I have to have a separate subroutine to say compute the convective terms for each grid level in multigrid. This is because I have to have a separate module for each grid level in multigrid which will be accessed by a use statement in the respective subroutine. In general what I want is to have all dimension statements in one location (the module).

Thanks, Frank
  Reply With Quote

Old   July 3, 2000, 21:28
Default Re: Fortran, does anyone know how..,Thank your .
  #9
John C. Chien
Guest
 
Posts: n/a
(1). Thank you for letting me know that it is Fortran 90/95. (2). I did a brief Internet search and found a tutorial site. (3). In the tutorial, there is a simple sample written in f77 and Fortran 90. (4). All I can say is, I don't like the new language. (5). The f77 isIMENSION B(3) (6). DATA B/1.,2.,3./ (7). The f90 is: Real, DIMENSION(1:3) :: B=(/1.,2.,3./) (9). The main reason is: /1.,2.,3./ is the f77 approach. In C/C++, it is : {1.,2.,3.}. Now we have this double standard, that is : (/1.,2.,3./). (10). Also the scope definition (: in C/C++ is not the same as (: in Fortran 90/95. (11). The use of Real, DIMENSION(1:3) require the use of a comma (,) It becomes very hard to read the whole statement. (12). I think, the new language is not user-friendly. Well, that's my first impression. Now we need to learn three ways to initialize an array, /1,2,3/ , {1.2,3}, (/1.2,3/). And this is definitely not a user-friendly trend.
  Reply With Quote

Old   July 3, 2000, 22:15
Default Re: Fortran, does anyone know how..
  #10
Nishikawa
Guest
 
Posts: n/a
I guess I don't understand what you want to do.

If you store all the information in a single array, you'll need some pointers for each grid level (where the data start on a particular grid level. And in this case you must pass the bounds to subroutines to let them know to which grid it should access).

If you store a set of information separately for each grid, you can simplify your operations, but still you'll need to tell the code to which grid it should access, and what you're doing is one way. (But I don't think you need a subroutine for each data set(grid) to do the same thing. Just use the function SIZE, and the subroutine understands on which grid "a" is defined, provided the subroutine knows the size of each grid.)

Do you want to do without such pointers? I think you need something like that however you write a multigrid code. Or, am I missing something?

  Reply With Quote

Old   July 4, 2000, 04:40
Default Re: Fortran, does anyone know how..
  #11
Frank Muldoon
Guest
 
Posts: n/a
In general what I want is to have all dimension statements that contain bounds in one location (the module) of which there will be one for each grid. I would like to do the following:

!-----------------------------------------

module def

contains

subroutine sub1(a)

real, dimension( :: a

write(*,*)'sub1',lbound(a),ubound(a)

return

end subroutine sub1

end module def

program main

use def

real,allocatable, dimension( :: a

allocate(a(2:12))

a=1.0

call sub1(a)

end program main

!-----------------------------------------

However this returns bounds from 1 to 11 in the subroutine.

Another way of expressing what I want to do is below. It does not compile on a Alpha but does on an IBM SP2 and then gives bounds from 1 to 804400217

!-----------------------------------------

program main

real, dimension(2:12) :: a

a=1.0

call sub1(a)

end program main

subroutine sub1(a)

real, dimension( :: a

write(*,*)'sub1',lbound(a),ubound(a)

return

end subroutine sub1

!-----------------------------------------

Thanks,

Frank
  Reply With Quote

Old   July 28, 2000, 15:08
Default Re: Fortran, does anyone know how..
  #12
Chidu
Guest
 
Posts: n/a
Hi Frank,

Did you find out a way to do that? Infact I encountered a similar problem but in this case my array lower bound was fixed to 0 instead of the normal 1 and if I just defined this array as a(:, then I was unable to access the zeroth element inside the subroutine. I had to finally define it as a(0:, and then it worked!

I think there is a problem in F90 in this regard. Let me know if you find something.

Thanks. chidu...
  Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortran Compiler-CFX12.1 Araz CFX 13 March 27, 2017 06:37
Intrinsic Procedure 'ISNAN' in GNU FORTRAN 77 hawk Main CFD Forum 1 April 12, 2005 23:13
visual fortran Monica Main CFD Forum 1 August 28, 2004 21:45
Fortran77 or Fortran 90 Swapnil CFX 2 November 26, 2002 16:16
Why Favoring Fortran over C/C++? Zi-Wei Chiou Main CFD Forum 35 September 26, 2001 10:34


All times are GMT -4. The time now is 07:37.