Re: removing blanks from a file
- From: tholen@xxxxxxxxxxxx
- Date: Thu, 29 Jun 2006 23:48:14 GMT
Luka Djigas writes:
Greetings
English is not my mother language, so I'd like to apologize in
advance, if this sounds a little funny to you.
Since fortran programmers are running thin in my part of the world,
and since looks like there's a good deal of them here, I was wondering
if you could help me with a little problem I'm having (searched
google, found some half solutions but nothing concrete)
I have a file, which is the output of one of my programs. It's a
script file, and therefore it's not supposed to have blanks in it.
The file looks something like this
1.0, 1.0, 1.0
1.0, 1.0, 1.0
....
and it would be good if it looked like this
1.0,1.0,1.0
1.0,1.0,1.0
....
I tried something like this
CHARACTER(1) :: CH
INTEGER(4) :: IOEND=0
OPEN(1,FILE='FILE.TXT')
DO WHILE (IOEND/=-1)
READ(1, "(A1)", IOSTAT=IOEND, ADVANCE="NO")CH
IF CH=CHAR(49)
CH=CHAR(50)
WRITE(1, "(A1)", ADVANCE="NO")CH
END DO
CLOSE(1)
END
If you try it you will see that it has some drawbacks.
Please, if anyone has some ideas how to solve this problem, I'd be
very grateful, if he/she would share them.
Use two strings, each declared with a length corresponding to the longest
line you will encounter in the file. One string will be input, the other
output.
Use two character counters, one for the input string, one for the output
string. Use a DO loop to scan each character of the input string. If
that character is a non-blank, increment the character count for the
output string and copy that character to the output string. When done
scanning that line, write the output string to the output file, perhaps
using the TRIM function to eliminate trailing blanks.
.
- References:
- removing blanks from a file
- From: Luka Djigas
- removing blanks from a file
- Prev by Date: removing blanks from a file
- Next by Date: Re: Fortran refactoring
- Previous by thread: removing blanks from a file
- Next by thread: Re: removing blanks from a file
- Index(es):
Relevant Pages
|
|