Fortran - Allocate array in subroutine

In summary, the conversation discusses a programming issue with allocating arrays in Fortran. The user is attempting to control software using Fortran and has successfully allocated a variable in a subroutine. They are now attempting to allocate an array in a loop, but are having trouble and are asking for advice and experiences from others. They mention using the statements "ALLOCATE" and "DEALLOCATE" and the issue with the status variables. They also mention potentially posting their code for others to review.
  • #1
luonganh89
12
0
I try to write a small program to allocate a variable in small subroutine and I've passed it, now i allocate array in a loop or many loops but i don't have any ideas about it.
Has anyone done like me , can share some experiences ??
 
Technology news on Phys.org
  • #2
luonganh89:

Welcome to the forum.

Please make another attempt to ask your question more clearly.

Maybe, if you are having a problem implementing something in fortran, post the source code, tell what you are trying to do, and how you think it should be done, etc.
 
  • #3
Thank your attention !

I've just passed it . My project is coupling 2 software together: abaqus and CFD code. I've controlled abaqus by using fortran. now I've tried to control CFD code (written by Fortran). I'm writting a sample code , if it runs succefully, i will apply it to my CFD code
 
  • #4
Hi !
Have you ever coded in Abaqus about Allocating Array ! Can share me some experience ?
 
  • #5
I don't use Abaqus.

You may want to consider visiting an Abaqus/CFD forum, if you don't get an answer here.
 
  • #6
It seems to be simple, But i can't explain how it run wrongly

I use statement:
ALLOCATE( CV(100), STAT = AllocateStatus)
IF (AllocateStatus /= 0) STOP "*** Not enough memory ***"
and

DEALLOCATE( CV, STAT = DeAllocateStatus)
IF (DeAllocateStatus /= 0) STOP "*** Trouble deallocating ***"
Abaqus always announces "*** Trouble deallocating ***" but
- when i don't use " IF (DeAllocateStatus /= 0) STOP "*** Trouble deallocating ***" it run successfully.
- when i don't use "DEALLOCATE( CV, STAT = DeAllocateStatus) IF (DeAllocateStatus /= 0) STOP "*** Trouble deallocating ***" it announces "Not enough memory"

can you explain something ?
 
  • #7
Is your code very large? can you post it? (use code tags if you do).

Are both status variables AllocateStatus and DeAllocateStatus explicitely declared integers?
 

FAQ: Fortran - Allocate array in subroutine

What is Fortran?

Fortran is a high-level programming language used primarily for scientific and numerical computing. It was first introduced in the 1950s and has since gone through several updates and revisions.

What does it mean to allocate an array in a subroutine?

Allocating an array in a subroutine means that memory is reserved for the array within the subroutine. This allows the subroutine to access and manipulate the array without interfering with other parts of the program.

Why is it important to allocate arrays in subroutines?

Allocating arrays in subroutines helps with code organization and improves the efficiency of the program. It also allows for better control over the data being manipulated and reduces the risk of errors caused by multiple parts of the program trying to access the same array at the same time.

How do you allocate an array in a Fortran subroutine?

To allocate an array in a Fortran subroutine, you can use the ALLOCATE statement followed by the array name and the desired dimensions. You can also specify other optional parameters, such as data type and initial values.

Can an allocated array in a Fortran subroutine be deallocated?

Yes, an allocated array in a Fortran subroutine can be deallocated using the DEALLOCATE statement. This frees up the memory previously reserved for the array and allows it to be used for other purposes.

Similar threads

Replies
4
Views
2K
Replies
5
Views
7K
Replies
4
Views
3K
Replies
2
Views
3K
Replies
59
Views
10K
Replies
8
Views
3K
Replies
5
Views
3K
Back
Top