| New Reply |
Adding/Subtracting arrays in F77 |
Share Thread | Thread Tools |
| Jun7-12, 11:07 AM | #1 |
|
|
Adding/Subtracting arrays in F77
Hey, I'm new to fortran and I don't know how to add arrays. I opened a data file and assigned a different array to each number but if I type something like x(2)+x(3) it will not yield a result. This is probably a stupid question but thanks for any help you can offer.
|
| Jun7-12, 07:36 PM | #2 |
|
|
Please post your code. Can't help without seeing what the code is doing...can't take your word for it...sorry.
|
| Jun8-12, 02:10 PM | #3 |
|
|
I just have a very simple code as follows:
Code:
program test
integer i,j
character*14 x(10,7)
open (unit=3, file='dstest')
open (unit=8, file='dstestnew.data')
read (3,*) ((x(i,j), i=1,10), j=1,7)
cccc [operation]
close(unit=3)
close(unit=8)
end
|
| Jun8-12, 02:30 PM | #4 |
|
|
Adding/Subtracting arrays in F77
Short answer: Yes, you can do x(1,3)+x(4,4)
Long answer: You say that you are trying to see what operations you can do....why waste your time? How about you do a little bit of reading on fortran arrays? And find out for sure what it is that you can and cannot do? Please do not attempt to learn to program cluelessly by trial an error; sure, when something is not too clear, you can try variations of what they seem to be saying until you get it right and understand it. |
| Jun8-12, 02:39 PM | #5 |
|
|
edit: I have no idea why I wrote trying to figure out specific operations in my code... all I care about is the operation addressed in my question. |
| Jun8-12, 02:55 PM | #6 |
|
|
Or ... from the wording of your question ("add specific arrays") you seem to imply that x(1,3) and x(4,4) are themselves arrays? Is this so or did you mean elements? |
| Jun8-12, 02:59 PM | #7 |
|
|
You're right, I used poor vocab. I should have asked how to add specific elements of an array . Thanks for clarifying that. I understand that this is a fairly basic question but I don't think it is bad to seek help after I spent a few hours working on it. |
| Jun8-12, 03:22 PM | #8 |
Recognitions:
|
Sorry, but I still don't understand what you want to do.
If you show us some code you wrote that doesn't work, and a few lines of your data file, that mgiht help us work out what your problem is. Just saying Code:
cccc [operation] |
| Jun8-12, 03:33 PM | #9 |
|
Mentor
|
Your array contains character strings. You can't "add" character strings like you do numbers, in Fortran.
Do you want to concatenate the strings together, that is, combine e.g. 'abcde' and 'fghij' to produce 'abcdefghij'? In that case, you would use something like result = x(1,3) // x(4,4) Or do the strings contain a character-string representation of numbers (integers or reals)? In that case, you should have declared the array as INTEGER or REAL and read the numbers that way. There's no simple way to add numbers that are stored as digits in character strings. |
| Jun8-12, 03:49 PM | #10 |
|
|
Here's the operation I was trying to explain if any of you are curious and thanks for helping: Code:
program test integer i,j real x(10,7) open (unit=3, file='dstest') open (unit=8, file='dstestnew.data') read (3,*) ((x(i,j), i=1,10), j=1,7) sum=x(1,1)+x(2,2) write (8,*), 'x(2,2)=',x(2,2) write (8,*), 'x(1,1)=',x(1,1) write (8,*), 'x(1,1)+x(2,2)=',sum close(unit=3) close(unit=8) end |
| Jun8-12, 07:55 PM | #11 |
|
|
Well...this time, you have declared your matrix x as a REAL, as opposed to CHARACTER*14!!!
|
| New Reply |
| Thread Tools | |
Similar Threads for: Adding/Subtracting arrays in F77
|
||||
| Thread | Forum | Replies | ||
| Subtracting this vector - as opposed to adding it | Introductory Physics Homework | 5 | ||
| Adding and Subtracting Vectors | Introductory Physics Homework | 4 | ||
| Adding/Subtracting 3 Vectors | Introductory Physics Homework | 3 | ||
| Vectors, Adding, Subtracting. | Introductory Physics Homework | 5 | ||
| binary adding/subtracting, am i doing this right? | Engineering, Comp Sci, & Technology Homework | 1 | ||