PDA

View Full Version : Reading a String from a file into an array


W.E.T.
04-21-2004, 04:44 PM
Alrite,

I have a little problem. I didnt notice it at first but when I read a string from an external file into an array the program stops reading from a row/column when it sees a space. Is there a way to make it comma delimited instead??? I have set character too:


character*100

Also, I let the user enter the name of the input file themselves, is there a way to use my own valiadtion if the file does not exsist, instead of the the program throwing up and error and exiting the program???

Thanks

Nick

W.E.T.
04-21-2004, 04:47 PM
By the way, I am using Fortran 77

Thanks

W.E.T.
04-21-2004, 05:00 PM
OK, before u ask, no I dont like talking to myself :p

I have just read from previous posts that you cannot stop reading a record via a comma and I have it working using quotations around the data but I have so much data. How would I go about putting quotations around every entry within my file.

Any ideas will be greatly appreciated

Nick

tzeis
04-21-2004, 05:49 PM
The easiest way I know of to quickly add quotes to all the character data in your file is to use a regular expression search and replace command. If you have Visual Studio, the find/replace dialog has a regular expression checkbox. If you don't have VS, you can download an editor called GVim, which has powerful editing capabilities, including regular expression support.

You also have the option of reading each line of data into a character variable using the "Axxx" format, where "xxx" is the length of the character variable you are using. You can then parse the line by looking for the commas. This is pretty easy if you are using a Fortran 90 compiler, because you can use the INDEX function.