Assignments of Elements between differently ranked arrays (fortran95)

mardi 29 avril 2014

Hello everybody/reader,



Thank you for reading my post, i have been known to be long winded but i put a abridged version of my question and sectional labels so it can be skimmed easily for relevant information.



note: I Wrote a very explanatory post, which had sections and was written very nicely but i lost it because when i went to post it i put int he wrong password and when i went back it was gone and it didn't save in a draft somewhere(or did it?). This is a bit lazier and more poorly written but the question is this:



I am coding in Fortran 95



THE SHORT VERSION:



Can i assign the value of a single element from a rank 1 array to be the value of a rank zero variable.

Such as: Alpha = Z(1:1), Beta = Z(1:2)



Can i re-define the structure of an array to an equivalent array

Such as: A(n:1) --> A(n) or A(1:n) ---> A(n)







THE LONG VERSION/THE SET UP AND CONTEXT



Using a chebyshev routine i acquired the zero values for a function which plots the trajectories of a mass. the functions do loop ends when (f(1) >= xfinal) and gives as the result the difference between the y(3) value and the desired y(3) value(y(3) is the y axis value, y(1) is the x axis value). It is a boundary value problem, given v0, x0, y0, xfinal, and yfinal find the angle which makes this true. The chebyshev yields the zero values in the form z0(1:iz0) where z0 is the array of the angles which are solutions to the problem, and iz0 is an integer for the number of solutions(which is 2).



I want to extract the values from z0 and assign them to a variable and run the rk4step function to plot the trajectories which solve the problem. I have technically completed the assignment of finding the zero values using the "shoot" method. But, i want to plot them and i could only do it by using human power to read the printed values and manually put them into a new program. There must be a way to do this else it could become very annoying/cumbersome in a more complex problem.



I tried to do



Alpha = zo(1:1)

alpha2 = zo(1:2)



But it says the ranks don't match so it won't compile



I tried



Alpha(1) = zo(1:1)



same thing



i tried



Alpha(1:1) = z0(1:1)



but then it fails when



y(2) = mass*v0*cos(alpha(1:1)



because the ranks don't match again



THE QUESTIONS



Can i extract the value from the array z0 and assign it to a variable defined in a different way(rank 0) or do i have to change all my variables to match?



Can I re-define my z0(1:iz0) to be some new array formatted as z02(iz0) so that it matches the format of y(n_eq)?





THE RANT:

What if this program had multiple subroutines which had variables defined differently, and they are interconnected, and i couldn't use the value from one routine in the other routine just because one can not extract the values from a rank 2 array and put them into a rank 1 array, or from a rank 1 array into a rank 0 array.



This seems like a very limiting thing, I have heard of something called a "leading dimensional array" when we did matrices, must i use the highest dimensional array throughout all the program or is there a way to split the arrays, or down-rank the values in them for use in simpler/lower dimensional programs?



so far, for the most part, online i have read the answer is NO, i cannot assign values to differently ranked variables. But i did find something called "array slicing"??? but i couldn't figure out how to apply it to my problem as the examples it gave seemed irrelevant.





0 commentaires:

Enregistrer un commentaire