Smart questions
Smart people
 Find A ForumFind An Expert
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips now!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Just copy and paste the

#### Feedback

"...I'm so glad I found this site... Now I can get some sleep, because my problem is solved..."

#### Geography

Where in the world do Tek-Tips members come from?

# Use DQDAGS to calculate integral

 Forum Search FAQs Links Jobs Whitepapers MVPs
 lurese (Programmer) 3 Jun 12 16:27
 Hi, I use the ISML function DQDAGS to calculate integral. The function F1, F2 need to return arrays. I don't know how to deal with it. The following is part of the code. thanks for every help.lur****************************..............        DO 55 I=1, N_ZONE       A(I) = 0.078D0 + 0.02D0 * (I-1)       B(I) = 0.078D0 + 0.02D0 * (I)55    ENDDO        DO 60 N = 1, N_TEXP           INTEGR1(N)=0.0D0         INTEGR2(N)=0.0D0         INTEGR3(N)=0.0D0         DO 70 I =1, N_ZONE                         CALL DQDAGS (F1, A(I), B(I), ERRABS,ERRREL,ANS1(I, N),ERR1(I, N))       CALL DQDAGS (F2, A(I), B(I), ERRABS,ERRREL,ANS2(I, N),ERR2(I, N))       CALL DQDAGS (F3, A(I), B(I), ERRABS,ERRREL,ANS3(I, N),ERR3(I, N))                 70      ENDDO        INTEGR1(N)= INTEGR1(N) + ANS1(I, N)        INTEGR2(N)= INTEGR2(N) + ANS2(I, N)        INTEGR3(N)= INTEGR3(N) + ANS3(I, N)60    ENDDO ..............C     ****************************************************************      DOUBLE PRECISION FUNCTION F1(R, SPAREA, N_TEXP, N_ZONE)      DOUBLE PRECISION I, N, II, NN      DOUBLE PRECISION N_TEXP, N_ZONE      DOUBLE PRECISION R                     !integration variable              DOUBLE PRECISION SPAREA(N_ZONE, N_TEXP)        DO 80 N = 1, N_TEXP          DO 81 I = 1, N_ZONE        F1(I, N) = SPAREA(I, N) * R81    ENDDO80    ENDDO       RETURN        END FUNCTIONC     ****************************************************************C     ****************************************************************      DOUBLE PRECISION FUNCTION F2(R, N_TEXP,N_ZONE, HOLLIQ, THFILM, SPAREA, DIADRO)         DOUBLE PRECISION I, N, II, NN        DOUBLE PRECISION N_TEXP, N_ZONE      DOUBLE PRECISION R               !integration variable                   DOUBLE PRECISION HOLLIQ(N_TEXP)              DOUBLE PRECISION THFILM(N_TEXP)              DOUBLE PRECISION DIADRO(N_ZONE, N_TEXP)              DO 90 N = 1, N_TEXP         DO 100 I =1, N_ZONE              F2(I, N)  = 6.D0 * (HOLLIQ(N)- THFILM(N)) * R / DIADRO(I, N)                   100      ENDDO 90    ENDDO       RETURN        END FUNCTIONC     ****************************************************************C     ****************************************************************      DOUBLE PRECISION FUNCTION F3(R)      DOUBLE PRECISION R !integration variable               F3=  R       RETURN        END FUNCTIONC     ****************************************************************
 salgerman (Programmer) 3 Jun 12 16:42
 You see how you are using a variable inside your function that has the same name as the function? When what you want to return is not just a scalar but an array, you need to actually, explicitly, declare such variable and specify it as an array with dimensions, etc.
 lurese (Programmer) 3 Jun 12 16:52
 Hi Salgerman,I modify the code as following, but it still doesn't work.****************************.............. DO 55 I=1, N_ZONE A(I) = 0.078D0 + 0.02D0 * (I-1) B(I) = 0.078D0 + 0.02D0 * (I)55 ENDDO DO 60 N = 1, N_TEXP INTEGR1(N)=0.0D0 INTEGR2(N)=0.0D0 INTEGR3(N)=0.0D0 DO 70 I =1, N_ZONE CALL DQDAGS (F1, A(I), B(I), ERRABS,ERRREL,ANS1(I, N),ERR1(I, N)) CALL DQDAGS (F2, A(I), B(I), ERRABS,ERRREL,ANS2(I, N),ERR2(I, N)) CALL DQDAGS (F3, A(I), B(I), ERRABS,ERRREL,ANS3(I, N),ERR3(I, N)) 70 ENDDO INTEGR1(N)= INTEGR1(N) + ANS1(I, N) INTEGR2(N)= INTEGR2(N) + ANS2(I, N) INTEGR3(N)= INTEGR3(N) + ANS3(I, N)60 ENDDO ..............C **************************************************************** DOUBLE PRECISION FUNCTION F1(R, SPAREA, N_TEXP, N_ZONE) DOUBLE PRECISION I, N, II, NN DOUBLE PRECISION N_TEXP, N_ZONE DOUBLE PRECISION R !integration variable DOUBLE PRECISION SPAREA(N_ZONE, N_TEXP) F1 = SPAREA(I, N) * R RETURN END FUNCTIONC ****************************************************************C **************************************************************** DOUBLE PRECISION FUNCTION F2(R, N_TEXP,N_ZONE, HOLLIQ, THFILM, SPAREA, DIADRO) DOUBLE PRECISION I, N, II, NN DOUBLE PRECISION N_TEXP, N_ZONE DOUBLE PRECISION R !integration variable DOUBLE PRECISION HOLLIQ(N_TEXP) DOUBLE PRECISION THFILM(N_TEXP) DOUBLE PRECISION DIADRO(N_ZONE, N_TEXP) F2 = 6.D0 * (HOLLIQ(N)- THFILM(N)) * R / DIADRO(I, N) RETURN END FUNCTIONC ****************************************************************C **************************************************************** DOUBLE PRECISION FUNCTION F3(R) DOUBLE PRECISION R !integration variable F3= R RETURN END FUNCTIONC ****************************************************************
 gummibaer (Programmer) 3 Jun 12 19:08
Would be not too bad an idea, if you could be more specific on what did not work. Did you receive compiler-errors, runtime errors or is it you just did not receive the expected result ?

Personally, I i am doubting if you can have functions to return arrays as a result. I think using subroutines would be better in this case. For instance, instead of your function f1 you could write:

#### CODE

subroutine EvalF1 (F1, R, SPARAREA, N_TEXP, N_ZONE) DOUBLE PRECISION F1 (N_TEXP, N_ZONE) ! declaration of f1 as array DOUBLE PRECISION I, N, II, NN ! <----- you use these as integers !?!? DOUBLE PRECISION N_TEXP, N_ZONE ! <----- you use these as integers !?!? DOUBLE PRECISION R !integration variable DOUBLE PRECISION SPAREA(N_ZONE, N_TEXP) DO 80 N = 1, N_TEXP DO 81 I = 1, N_ZONE F1(I, N) = SPAREA(I, N) * R 81 ENDDO 80 ENDDO RETURN END

You should rethink the types of your variables. Double precision as indices is not the best choice.

Norbert

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.

 salgerman (Programmer) 3 Jun 12 19:50
lurese:

I don't see where you declared your "function" variables to be arrays...for example, your original F1 function should look something like this:

#### CODE

C **************************************************************** DOUBLE PRECISION FUNCTION F1(R, SPAREA, N_TEXP, N_ZONE) double precision F1(N_ZONE, N_TEXP) DOUBLE PRECISION I, N, II, NN DOUBLE PRECISION N_TEXP, N_ZONE DOUBLE PRECISION R !integration variable DOUBLE PRECISION SPAREA(N_ZONE, N_TEXP) DO 80 N = 1, N_TEXP DO 81 I = 1, N_ZONE F1(I, N) = SPAREA(I, N) * R 81 ENDDO 80 ENDDO RETURN END FUNCTION
 salgerman (Programmer) 3 Jun 12 20:21
 Like Norbert said, you need to be more specific as to what exactly is not working...post the entire code if you need to, use "code" and "/code" tags enclosed each in square brackets (like these ones "[" and "]") or include it as an attachment if it is too large.
 lurese (Programmer) 4 Jun 12 11:25
According to the suggestions you gave, I post all the code here. Since the ISML function QDAGA require the function F1, F2, F3 to be the eternal, I can not declare it as a array. I modify the variable type with I, N, II, NN according to gummibaer's suggestion.
Thanks.

#### CODE --> English

 lurese (Programmer) 4 Jun 12 11:29
compiling information:

#### CODE -->

--------------------Configuration: interfacial area - Win32 Debug-------------------- Compiling Fortran... D:\Fortran\1_Interfacial area\interfacial area2012-06-01\ae.for D:\Fortran\1_Interfacial area\interfacial area2012-06-01\ae.for(413) : Warning: Variable SPAREA is used before its value has been defined F1 = SPAREA(II, NN) * R ------------^ ae.obj - 0 error(s), 1 warning(s)

#### CODE -->

READ INPUT DATA ........................ ................................... done *** WARNING ERROR 2 from DQDAGS. Roundoff error has been detected. The *** requested tolerances, ERRABS = 1.000000000000000D-05 and ERRREL *** = 1.000000000000000D-05, cannot be reached. *** WARNING ERROR 2 from DQDAGS. Roundoff error has been detected. The *** requested tolerances, ERRABS = 1.000000000000000D-05 and ERRREL *** = 1.000000000000000D-05, cannot be reached. *** WARNING ERROR 2 from DQDAGS. Roundoff error has been detected. The *** requested tolerances, ERRABS = 1.000000000000000D-05 and ERRREL *** = 1.000000000000000D-05, cannot be reached. *** WARNING ERROR 2 from DQDAGS. Roundoff error has been detected. The *** requested tolerances, ERRABS = 1.000000000000000D-05 and ERRREL *** = 1.000000000000000D-05, cannot be reached. forrtl: severe (161): Program Exception - array bounds exceeded Image PC Routine Line Source interfacial area. 0040310B F1 409 ae.for interfacial area. 00404B94 Unknown Unknown Unknown interfacial area. 00403E80 Unknown Unknown Unknown interfacial area. 00403BD9 Unknown Unknown Unknown interfacial area. 00403862 Unknown Unknown Unknown interfacial area. 00403032 MASSTR 361 ae.for interfacial area. 004021C8 INTERAREA 146 ae.for interfacial area. 004511D9 Unknown Unknown Unknown interfacial area. 004366C9 Unknown Unknown Unknown kernel32.dll 7C817077 Unknown Unknown Unknown Press any key to continue
 salgerman (Programmer) 4 Jun 12 11:57
 lurese: please refer to my "3 Jun 12 19:50" post ...you have done nothing about that. Please read it and acknowledge that you understand it.
 salgerman (Programmer) 4 Jun 12 12:04
 lurese: by the way, that source code as posted, shows that within the F1 function you keep overwriting the value of F1 with a scalar value, over and over and over within the nested do loops....you are totally missing something, here...again, refer to my post and suggested F1 calculation

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!