galaxytraveler
Aerospace
- Mar 14, 2012
- 2
How to do find and replace in Fortran or ideas for a different way of solving the problem
BACKGROUND
I am reading in a column of asteroid diameters from a file, some of the asteroids are however not spherical but can be e.g. potato shaped, and then instead of a diameter I get something like "250x23x75.5" or if just two sides are known I get something like "250x23".
What I need to do with these values are to take the non-spherical ones and calculate the diameter of a sphere with equal volume.
THE PROBLEM
My problem is that I don't know how to take a value like "diameter = 250x23x75.5" and get the individual numbers out so I can calculate anything.
MY OWN IDEAS
I have been considering doing an "find and replace" of all the x to *, so I can directly use it in the calculations. But I am not sure how to do "find and replace", or if I will have problems using a string in a formula. And then how I can be sure to insert "250x23" into a different formula than "250x23x75.5".
For the find and replace I have considered turning each value into an array, so e.g. "250x23" would be the array (2,5,0,x,2,3) and then running a if loop on it, to search for X's and replace them. But I am not sure how to do this either, and it seems like a complicated way of doing something so simple.
I hope someone are willing to give me some new ideas.
BACKGROUND
I am reading in a column of asteroid diameters from a file, some of the asteroids are however not spherical but can be e.g. potato shaped, and then instead of a diameter I get something like "250x23x75.5" or if just two sides are known I get something like "250x23".
What I need to do with these values are to take the non-spherical ones and calculate the diameter of a sphere with equal volume.
THE PROBLEM
My problem is that I don't know how to take a value like "diameter = 250x23x75.5" and get the individual numbers out so I can calculate anything.
MY OWN IDEAS
I have been considering doing an "find and replace" of all the x to *, so I can directly use it in the calculations. But I am not sure how to do "find and replace", or if I will have problems using a string in a formula. And then how I can be sure to insert "250x23" into a different formula than "250x23x75.5".
For the find and replace I have considered turning each value into an array, so e.g. "250x23" would be the array (2,5,0,x,2,3) and then running a if loop on it, to search for X's and replace them. But I am not sure how to do this either, and it seems like a complicated way of doing something so simple.
I hope someone are willing to give me some new ideas.