Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:04:04+00:00 2026-06-16T05:04:04+00:00

I’ve got a program below which creates an array inside the first subroutine (CALCONE)

  • 0

I’ve got a program below which creates an array inside the first subroutine (CALCONE) then I want to pass that into the next subroutine (CALCTWO) then output it to file in the main program. I don’t know where to put the INTENT(IN), INTENT(OUT) statements because the array needs to be allocated IN subroutine CALCONE (because in my program the length is determined in CALCONE) – I have left my attempt out to avoid confusion. Could someone help put them in the correct place. Once I have a template, I’ll understand how it works for future. Thanks.

I’ve simplified the program and the variables represent other things which cannot be moved around. I just need a way to move an array between subroutines then write it out at the end of the main program.

 program TEST
 implicit none

 integer a,b,c,d,reclen

 a = 1
 b = 2
 c = 3
 d = 4

 call CALCONE(a,b,c,d,array)

 call CALCTWO(e,f,g,h,array)

 inquire(iolength=reclen)array 
 open(unit=8,file='array_output.dat', &
   form="unformatted",access="stream")
 write(unit=8)array       
 close(unit=8)

 END PROGRAM TEST

 SUBROUTINE CALCONE(adummy,bdummy,cdummy,ddummy,arraydummy)
 IMPLICIT NONE

 integer i,j,k
 integer e,f,g,h,N
 !ALLOCATE ARRAY HERE OR IN MAIN PROGRAM?
 real*8,   allocatable  :: arraydummy(:,:)

 e = a + 1
 f = b + 1
 g = c + 1
 h = d + 1

 ! N can only be is calculated here

 allocate(arraydummy(1:N,1:3))

 !POPULATE 'arraydummy'
 !PASS ARRAY BACK OUT TO NEXT SUBROUTINE FOR FURTHER PROCESSING IN CALCTWO
 END SUBROUTINE CALCTWO

 SUBROUTINE CALCTWO(edummy,fdummy,gdummy,hdummy,arraydummy)
 IMPLICIT NONE

 integer e,f,g,h
 !DEFINE HERE ALSO? i.e.
 !real*8,   allocatable  :: arraydummy(:,:)

 e = a + 1
 f = b + 1
 g = c + 1
 h = d + 1

 arraydummy = arraydummy*e*f*g*h

 END SUBROUTINE CALCTWO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:04:07+00:00Added an answer on June 16, 2026 at 5:04 am

    You do not have to allocate the the array in the main program, but you definitely have to declare it there and you have to pass it as an argument (which you do). Notice, that symbol array is not defined in the main program.

    Be sure to privide en explicit interface to the subs. Because you use advanced features (allocatable dummy arguments) it is necessary. Best is to put them in a module.

    The array has to be defined as a dummy argument in both. I declared it as intent(out) in the first one, because it is allocated at the beginning. It is not strictly necessary.

    Another option would be to declare the array in the module and let it be shared by the module procedures.

    DISCLAIMER: I did not try to compile it.

     module subs
       integer,parameter :: rp = kind(1d0)
    
    
       contains
    
    
    
    
       SUBROUTINE CALCONE(adummy,bdummy,cdummy,ddummy,arraydummy)
       IMPLICIT NONE
    
       integer i,j,k
       integer e,f,g,h,N
       !ALLOCATE ARRAY HERE OR IN MAIN PROGRAM?
       real(rp),   allocatable, intent(out) :: arraydummy(:,:)
    
       e = a + 1
       f = b + 1
       g = c + 1
       h = d + 1
    
       !N can only be is calculated here
    
        allocate(arraydummy(1:N,1:3))
    
       !POPULATE 'arraydummy'
       !PASS ARRAY BACK OUT TO NEXT SUBROUTINE FOR FURTHER PROCESSING IN CALCTWO
       END SUBROUTINE CALCTWO
    
       SUBROUTINE CALCTWO(edummy,fdummy,gdummy,hdummy,arraydummy)
       IMPLICIT NONE
    
       integer e,f,g,h
       !DEFINE HERE ALSO? i.e.
       real(rp),   allocatable, intent(inout)  :: arraydummy(:,:)
    
       e = a + 1
       f = b + 1
       g = c + 1
       h = d + 1
    
       arraydummy = arraydummy*e*f*g*h
    
       END SUBROUTINE CALCTWO
    
    
     end module subs
    
     program TEST
    
     use subs
    
     implicit none
    
     integer a,b,c,d,reclen
    
     real(rp),allocatable :: array
    
     a = 1
     b = 2
     c = 3
     d = 4
    
     call CALCONE(a,b,c,d,array)
    
     call CALCTWO(e,f,g,h,array)
    
     inquire(iolength=reclen)array 
     open(unit=8,file='array_output.dat', &
       form="unformatted",access="stream")
     write(unit=8)array       
     close(unit=8)
    
     END PROGRAM TEST
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.