From: Nathan on 2 Mar 2010 19:41 I am having a problem passing arrays into a subfunction. Here is how I call my subfunction CALL MIX1(NCOMP,CONC,TCFG,PCG,ACENG,TCMXFFG,PCMXFG,ACENMXFG,IER) NCOMP is an integer value, stating the number of components to pay attention to (max of 10) CONC, TCFG, PCG, and ACENG are all defined to be arrays of length 10 I.E.: DIMENSION CONC(10), TCFG(10), PCG(10), ACENG(10) TCMXFFG, PCMXFG, and ACENMXFG are single value variables that are returned from MIX1, and IER is an array of length 7 When I call MIX1 as above, only the first value of each array is being passed in, which is returning erroneous values for each output (except for IER, which catches the error information). I have been searching around for a while to no avail as to how to remedy my problem. Any help would be appreciated. If you need more information, I will be glad to supply it for you (if I can). -Nathan
From: e p chandler on 2 Mar 2010 20:17 "Nathan" <ngreco32(a)gmail.com> wrote in message news:6d5dfe3e-eaed-41d5-92c5-98e0bbadf88a(a)k2g2000pro.googlegroups.com... >I am having a problem passing arrays into a subfunction. > > Here is how I call my subfunction > CALL MIX1(NCOMP,CONC,TCFG,PCG,ACENG,TCMXFFG,PCMXFG,ACENMXFG,IER) > > NCOMP is an integer value, stating the number of components to pay > attention to (max of 10) > CONC, TCFG, PCG, and ACENG are all defined to be arrays of length 10 > I.E.: > DIMENSION CONC(10), TCFG(10), PCG(10), ACENG(10) > > TCMXFFG, PCMXFG, and ACENMXFG are single value variables that are > returned from MIX1, and IER is an array of length 7 > > When I call MIX1 as above, only the first value of each array is being > passed in, which is returning erroneous values for each output (except > for IER, which catches the error information). > > I have been searching around for a while to no avail as to how to > remedy my problem. > > Any help would be appreciated. If you need more information, I will be > glad to supply it for you (if I can). > > -Nathan 1. Well, you have not shown the declarations in the calling program, which are important! It would help if you would post the smallest program that demonstrates your bug. 2. Are you compiling code in separate source files? If you combine all of your source into one file, at least for a test program, it increases the chances that your compiler might detect some problems like argument mismatches that could be at fault. 3. Write a test sub program that has two arguments, one integer and one array. Try it with your calling program. Does it work? If it works, add more arguments. Does this help? -- Elliot
From: Richard Maine on 2 Mar 2010 20:42 Nathan <ngreco32(a)gmail.com> wrote: > I am having a problem passing arrays into a subfunction. ....[description elided] > Any help would be appreciated. If you need more information, I will be > glad to supply it for you (if I can). This has the most common problems of help requests. You are trying to describe the code. Don't describe it. Show it. We need to debug the code - not your descriptions. If you could decribe exactly what the code is doing with 100% accuracy, then you wouldn't need the help. So show the code. That includes all relevant declarations. Likewise, it is your conclusion that "only the first value of each array is being passed in". It is far better to show the raw data than your conclusion. You presumably based that conclusion on some data. Show that data. Best would be a self-contained example that could actually be compiled and run. But that's often difficult. Lacking that, at least show all of the relevant code. That certainly includes declarations, both in the caling and the called routine. It also includes all code that provides the data from which you are concluding that there is a problem. For example, if there are any output statements that you got data from, show them. If you got data from some debugger instead of from Fortran output,then tell us that (and include the exact debugger commands used.) It is quite possible that the problem is related to the debugger instead of the code. (P.S. There is no such thing as a subfunction; you mean subroutine). -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
From: jfh on 3 Mar 2010 15:48 On Mar 3, 2:42 pm, nos...(a)see.signature (Richard Maine) wrote: > Nathan <ngrec...(a)gmail.com> wrote: > > I am having a problem passing arrays into a subfunction. > > ...[Nathan's description and most of Richard's reply elided] > > (P.S. There is no such thing as a subfunction; you mean subroutine). Possibly, but when I read "subfunction" I assumed Nathan meant an internal function inside a function. That just emphasizes Richard's main point! John Harper
From: Nathan on 3 Mar 2010 17:37 I'm at work now. Here's MIX1 in it's entirety: ------------------------------------------------------------------------------------ SUBROUTINE MIX1(N,XIN,T,P,ACEN,TPC,PPC,ACENM,IER) CHA15410 C PURPOSE: CALCULATION OF PSEUDOCRITICAL TEMPERATURE, PSEUDOCRITICAL CHA15510 C PRESSURE, AND ACENTRIC FACTOR OF A MIXTURE. CHA15520 C CHA15530 C ARGUMENTS: CHA15540 C INPUT: CHA15550 C N NUMBER OF COMPONENTS IN THE MIXTURE. (INTEGER) CHA15560 C XIN() MOLE FRACTIONS OF THE COMPONENTS. (A VECTOR) CHA15570 C (REAL DOUBLE PRECISION) CHA15580 C T() CRITICAL TEMPERATURE (FAHRENHEIT) OF THE COMPONENTS. CHA15590 C (A VECTOR) (REAL DOUBLE PRECISION) CHA15600 C P() CRITICAL PRESSURES OF THE COMPONENTS, IN POUNDS PER CHA15610 C SQUARE INCH ABSOLUTE. (A VECTOR) (REAL DOUBLE PRECISION)CHA15620 C ACEN() ACENTRIC FACTORS OF THE COMPONENTS. (A VECTOR) CHA15630 C (REAL DOUBLE PRECISION) CHA15640 C CHA15650 C OUTPUT: CHA15660 C TPC PSEUDOCRITICAL TEMPERATURE (FAHRENHEIT) OF THE MIXTURE. CHA15670 C (REAL DOUBLE PRECISION) (RETURNED AS 0.0 IF ANY ERRORS CHA15680 C ARE ENCOUNTERED) CHA15690 C PPC PSEUDOCRITICAL PRESSURE OF THE MIXTURE, IN POUNDS PER CHA15700 C SQUARE INCH ABSOLUTE. (REAL DOUBLE PRECISION) (RETURNED CHA15710 C AS 0.0 IF ANY ERRORS ARE ENCOUNTERED) CHA15720 C ACENM ACENTRIC FACTOR OF THE MIXTURE. (REAL DOUBLE PRECISION) CHA15730 C (RETURNED AS 0.0 IF ANY ERRORS ARE ENCOUNTERED) CHA15740 C IER() ERROR PARAMETER VECTOR. (INTEGER) CHA15750 C IER(1) = 1 AT LEAST ONE OF IER(2) - IER(7) WAS NOT CHA15760 C ZERO. CHA15770 C IER(2) = 1 NUMBER OF COMPONENTS IS < OR = 0. CHA15780 C IER(3) = 1 THE SUM OF THE MOLE FRACTIONS IS NOT CHA15790 C 1.0 WITHIN TOLERANCE. CHA15800 C IER(4) = 1 A MOLE FRACTION IS < 0.0; OR FEWER THAN CHA15810 C TWO MOLE FRACTIONS ARE > 0.0. CHA15820 C IER(5) = 1 A COMPONENT TEMPERATURE IS TOO CHA15830 C LOW FOR A POSITIVE RANKINE TEMPERATURE. CHA15840 C IER(6) = 1 A COMPONENT PRESSURE IS < OR = 0.0. CHA15850 C IER(7) = 1 AN ACENTRIC FACTOR IS < OR = 0.0. CHA15860 C********************************************************************* CHA16050 IMPLICIT DOUBLE PRECISION (A-H,O- Z) CHA16060 DIMENSION XIN(*),T(*),P(*),ACEN(*) CHA16070 DIMENSION IER(7) CHA16080 DATA TOL/ 1.D-3/ CHA16090 C CHA16100 TPC = 0.0D0 CHA16110 PPC = 0.0D0 CHA16120 ACENM = 0.0D0 CHA16130 C CHA16140 C SET ERROR CODES TO ZERO. CHA16150 C CHA16160 DO 10 I = 1,7 CHA16170 IER(I) = 0 CHA16180 10 CONTINUE CHA16190 C CHA16200 C SET ERROR CODES CHA16210 IF (N .LE. 0)IER(2)=1 CHA16220 IF (IER(2).NE. 1)THEN CHA16230 SUMX = 0.D0 CHA16240 NN = 0 CHA16250 DO 15 I=1,N CHA16260 SUMX = SUMX + XIN(I) CHA16270 IF (XIN(I).LT. 0.D0)IER(4)=1 CHA16280 IF (XIN(I) .GT. 0.D0)NN = NN + 1 CHA16290 IF (T(I).LT.-459.67D0)IER(5)=1 CHA16300 IF (P(I).LE. 0.D0)IER(6)=1 CHA16310 IF (ACEN(I).LE. 0.D0)IER(7)=1 CHA16320 15 CONTINUE CHA16330 IF(DABS(SUMX - 1.D0) .GT. TOL)IER(3)=1 CHA16340 IF(NN .LT. 2) IER(4) = 1 CHA16350 ENDIF CHA16360 DO 20 I = 2,7 CHA16370 IF(IER(I) .EQ. 1) THEN CHA16380 IER(1) = 1 CHA16390 GOTO99 CHA16400 ENDIF CHA16410 20 CONTINUE CHA16420 C CHA16430 DO 30 I=1,N CHA16440 X = XIN(I)/ SUMX CHA16450 TPC = TPC + X*T(I) CHA16460 PPC = PPC + X*P(I) CHA16470 ACENM = ACENM + X*ACEN(I) CHA16480 30 CONTINUE CHA16490 C CHA16500 99 RETURN CHA16510 END ------------------------------------------------------------------------------------ Now for the data being passed in: NCOMP 6 conc(1) 279.041642672747 !Erroneous value, besides the point (I think) conc(2) 0.197642929291751 conc(3) 1.471079846220175E-002 conc(4) 1.471079846220175E-002 conc(5) 1.471079846220175E-002 conc(6) 1.471079846220175E-002 conc(7) 0.000000000000000E+000 conc(8) 0.000000000000000E+000 conc(9) 0.000000000000000E+000 conc(10) 0.000000000000000E+000 tcfg(1) 180.717024624348 tcfg(2) -181.430000000000 tcfg(3) 947.929986572266 tcfg(4) 947.929986572266 tcfg(5) 947.929986572266 tcfg(6) 947.929986572266 tcfg(7) -118.572222222222 tcfg(8) 0.000000000000000E+000 tcfg(9) 0.000000000000000E+000 tcfg(10) 0.000000000000000E+000 pcg(1) 0.250000000000000 pcg(2) 731.440000000000 pcg(3) 180.717024624348 pcg(4) 180.717024624348 pcg(5) 180.717024624348 pcg(6) 180.717024624348 pcg(7) -181.430000000000 pcg(8) 947.929986572266 pcg(9) 947.929986572266 pcg(10) 947.929986572266 aceng(1) 3.770000000000000E-002 aceng(2) 2.220000000000000E-002 aceng(3) 0.910000000000000 aceng(4) 0.910000000000000 aceng(5) 0.910000000000000 aceng(6) 3.451213951350862E-085 aceng(7) 6.013470022929141E-154 aceng(8) 6.013470016999068E-154 aceng(9) 6.013470016999068E-154 aceng(10) 6.013470016999068E-154 Outputs after the call (according to debugger as well as screen print): TCMXFFG 0.000000000000000E+000 PCMXFG 0.000000000000000E+000 ACENMXFG 0.000000000000000E+000 IER(1) 1 IER(2) 0 IER(3) 1 IER(4) 0 IER(5) 0 IER(6) 0 IER(7) 0 Now, after having written this and tested as some have suggested... I found that indeed it was the debugger only displaying the first value of the arrays whilst when running, it actually does pass in every element. I guess my problem now is trying to hunt down where a variable is "mysteriously" changing values... (Note the "erroneous" value of CONC(1)) I'll post my next question in a different thread, now that this part has been cleared. Thanks for your time and suggestions. The method was working afterall, but some values were being changed when I wasn't telling them to. -Nathan
|
Next
|
Last
Pages: 1 2 Prev: breakpoint in multiple file source code Next: COLLEGE HOT GIRLS FUNNY GAMES |