line continuation character


rrevathy25
06-29-2009, 05:44 AM
In my fortran program & is not working....i mean to see it does now continue to the next line..i dont know why.All other things are working like ! for comment etc.. only & is not working..

And i need to use it as i hav huge line to execute for example
sig 3489 0 78 100 98.00 34.56000N 23.89760E 98 n.a n.a n.a n n n n 23.000 34 67 srs

this just one line lik ts many lines arer thier i need to read such type of data n print it...but & s not working when i want contiue

davekw7x
06-29-2009, 10:04 AM
In my fortran program & is not working..

I suggest the following:


1. Show us some code.

2. Tell us what you expected to happen.

3. Tell us what happened.

4. Tell us what you don't understand about the difference between 2 and 3.

Regards,

Dave

rrevathy25
06-30-2009, 04:36 AM
PROGRAM y
CHARACTER(12):: x*5,a*1,b*1,g*4,h*4,i*4,j*4,k*4,l,m,n,o,p
INTEGER:: c,d,e,q,r,s
REAL:: f,u,v
OPEN(unit=8, file="catalog.dat",status="old")
OPEN(unit=11,file="ggg.dat")
DO
READ(8,77,END=88,ERR=88) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k
&
&,l,m,n,o,p


77 FORMAT(A5,1x,I4,1x,4(I3,1x),F6.2,1x,F8.4,A1,2x,F8. 4,A1,2x, &
&I3,1x,A4,2x,A4,1x,A4,2x,A4,2x,A4,2x,A4,1x,A4,2x,A5 , &
&1x,A3,2x,A12)

IF(h.eq." n.a" .and. j.eq." n.a".and.k.eq." n.a".and. &
&l.eq." n.a".and.n.eq." n.a".and.p.eq." n.a") THEN
h=""
j=""
k=""
l=""
n=""
p=""

WRITE(11,77) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k,l,m,n,o,p
ELSE
WRITE(11,77) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k,l,m,n,o,p

END IF
END DO
88 CLOSE(8)
CLOSE(11)

END PROGRAM y
This is the code ,y & is not working..
Then this prgram is giving blank output

My catalog file contains
SIG 25 0 0 0 0 0.00 33.0000N 72.0000E 0 n n.a n n.a n.a n.a n n.a n n.a
SIG 50 0 0 0 0 0.00 37.0000N 68.5000E 0 n n.a n n.a n.a n.a n n.a n n.a
SIG 460 0 0 0 0 0.00 20.3000N 100.0000E 0 n n.a n n.a n.a n.a n n.a T n.a
SIG 765 0 0 0 0 0.00 35.2000N 60.4000E 25 n n.a n n.a n.a n.a n 7.5 10 n.a


Why is it so i want to replace all n.a by blank space("")..This program must work its not...pls tell me whats the problem

davekw7x
06-30-2009, 09:32 AM
...
This is the code
It's a little overkill to use an ampersand at the end of a line as we do in Fortran 90 and a continuation character in column 7 of the next line as we do in Fortran 77 (and earlier), but as far as I know, it works even if you use both. At least it does with GNU gfortran.

However, I think it's a little more elegant if you only use one of the styles:


READ(8,77,END=88,ERR=88) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k &
,l,m,n,o,p
.
.
.
77 FORMAT(A5,1x,I4,1x,4(I3,1x),F6.2,1x,F8.4,A1,2x,F8. 4,A1,2x, &
I3,1x,A4,2x,A4,1x,A4,2x,A4,2x,A4,2x,A4,1x,A4,2x,A5 , &
1x,A3,2x,A12)
.
.
.
IF(h.eq." n.a" .and. j.eq." n.a".and.k.eq." n.a".and. &
l.eq." n.a".and.n.eq." n.a".and.p.eq." n.a") THEN



Anyhow, what makes you think that the continuation character is not working?

Here's a suggestion: Print out the values of the variables that you are reading. In other words: make the program tell you exactly what it is seeing at each step to make sure it reads what you think it should.

Maybe something like the following. Note that enclose the strings with<> brackets when I print them like this so that I can see exactly what each string contains. See Footnote.




.
.
INTEGER line_number
.
.
line_number = 0
DO
READ(8,77,END=88,ERR=88) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k &
,l,m,n,o,p
line_number = line_number + 1
77 FORMAT(A5,1x,I4,1x,4(I3,1x),F6.2,1x,F8.4,A1,2x,F8. 4,A1,2x, &
I3,1x,A4,2x,A4,1x,A4,2x,A4,2x,A4,2x,A4,1x,A4,2x,A5 , &
1x,A3,2x,A12)
write(*,'("Line ", I0)') line_number
write(*,*) " x=<", x, ">"
write(*,'(" c=",I0,", d=",I0,", q=",I0,", r=",I0,", s=",I0)') &
c, d, q, r, s
write(*,*) " f=", f
write(*,*) " u=", u
write(*,*) " a=<",a,">"
write(*,*) " v=", v
write(*,*) " b =<",b,">"
write(*,*) " g =<",g,">"
write(*,*) " h =<",h,">"
write(*,*) " i =<",i,">"
write(*,*) " j =<",j,">"
write(*,*) " k =<",k,">"
write(*,*) " l =<",l,">"
write(*,*) " m =<",m,">"
write(*,*) " n =<",n,">"
write(*,*) " o =<",o,">"
write(*,*) " p =<",p,">"
.
.



Regards,

Dave

Footnote: When comparing strings, do leading spaces count? How about trailing spaces?

rrevathy25
07-01-2009, 05:48 AM
Thanks i got it working now....Do you know how to delete juck values or characters in a file. If so tell me..i am reading data but i am getting a junk character with the end of one row its not even , it looks like tat i tried removing the , from the entire file.but still its thier.
My file contains data lik
NEI 2001 10 20 14 40 21.22 18.8150N 92.4360E 33 n 4.40 n n.a n.a n.a n n.a n n.a
NEI 2001 10 20 20 5 5.87 39.3920N 75.0340E 33 n 4.30 n n.a n.a n.a n n.a n n.a
NEI 2001 10 21 13 24 8.55 37.1630N 71.8790E 107 n 4.60 n n.a n.a� n.a n n.a n n.a
NEI 2001 10 22 14 18 13.76 1.6080N 99.6690E 33 n 4.20 n n.a n.a� n.a n n.a n n.a
NEI 2001 10 25 17 5 49.89 22.7130N 94.7110E 138 n 4.50 n n.a n.a� n.a n n.a n n.a
NEI 2001 10 26 23 27 16.93 35.8040N 69.9560E 200 n 4.10 n n.a n.a� n.a n n.a n n.a
NEI 2001 10 27 19 30 26.91 36.1320N 70.5690E 77 n 5.10 n n.a n.a� n.a n n.a n n.a

See in this file thier a junk character near n.a whats that.i thought its a , & tried to removing from entire file but still its thier.can anyone pls help me out to rectify this problem

davekw7x
07-01-2009, 10:18 AM
...i am getting a junk character..
The "junk" appears to be the hex sequence ef bf bd (UTF-8 encoding of Unicode Replacement Character ???)

If you just want to delete non-ascii bytes (anything with an integer value greater than or equal 127), you could read the file a line at a time into a string and then write out all characters whose integer values are less than 127.

With GNU gfortran, the following works for me:

!
! Eliminate any non-ascii characters from a file
!
! davekw7x
!
program scrub

implicit none

!
! A string to hold each line from the file.
! The len value must be no less than the length
! of the longest line
!
character(len=1024) :: line

integer :: i
integer :: lineno
integer :: length

open(unit=8, file="file_with_non_ascii_chars.txt", status="old")
open(unit=9, file="scrubbed_file.txt")

lineno = 0
do
read(8,'(a)',end=1000,err=1001) line
lineno = lineno+1
!
! get length not counting trailing spaces
!
length = len_trim(line)
do i=1,length
if (ichar(line(i:i)) < 127) then
write(9,'(a)', advance="no") line(i:i)
end if
enddo
write(9,*)
enddo
1000 write(*,'("Number of lines read = ", I0)') lineno
stop

1001 write(*,'("Error reading line ",I0)') lineno
stop

end program scrub


The "scrubbed" file from your example is

NEI 2001 10 20 14 40 21.22 18.8150N 92.4360E 33 n 4.40 n n.a n.a n.a n n.a n n.a
NEI 2001 10 20 20 5 5.87 39.3920N 75.0340E 33 n 4.30 n n.a n.a n.a n n.a n n.a
NEI 2001 10 21 13 24 8.55 37.1630N 71.8790E 107 n 4.60 n n.a n.a n.a n n.a n n.a
NEI 2001 10 22 14 18 13.76 1.6080N 99.6690E 33 n 4.20 n n.a n.a n.a n n.a n n.a
NEI 2001 10 25 17 5 49.89 22.7130N 94.7110E 138 n 4.50 n n.a n.a n.a n n.a n n.a
NEI 2001 10 26 23 27 16.93 35.8040N 69.9560E 200 n 4.10 n n.a n.a n.a n n.a n n.a
NEI 2001 10 27 19 30 26.91 36.1320N 70.5690E 77 n 5.10 n n.a n.a n.a n n.a n n.a


Regards,

Dave

rrevathy25
07-02-2009, 10:44 PM
wow it working.....thanks a lot lot... but i still hav a problem i need to read data in format as we are reading as string ...the numbers dont come in a format
for example for the same data i need to remove all n.a ya..i got that also but few numbers are thier its not in order as shown below

PDE-W 2001 7 14 18 36 8.32 24.4550N 102.6600E 33 n 4.6 n 4.3 n
n
NEI 2001 7 15 0 4 27.02 23.7050N 70.3670E 10 n 4.20 n n
n
NEI 2001 7 15 5 2 12.55 36.4180N 70.5210E 33 n 4.00 n n
n
NEI 2001 7 15 6 31 23.58 29.8650N 68.1520E 16 n 4.40 n n
n
NEI 2001 7 15 17 37 16.06 36.6090N 71.1360E 232 n 3.80 n n
n
PDE-W 2001 7 15 19 28 28.72 27.7000N 101.0720E 33 n 3.7 n n
n
NEI 2001 7 16 16 7 18.02 33.0140N 73.1210E 50 n 5.10 n 5.1 4.5 n n 4.77e+23
NEI 2001 7 16 16 12 46.75 27.9570N 85.1780E 33 n 5.00 n n
n



My file contains a huge amount of such data..i remove n.a but now i want n to come in a order & even the number 5.1 4.5 come in a format from first line....its deflecting lik

n
n
n
n
n
n
n
n
or
n
5.6
5.78
6.7
n
n
n
etc.......
i just showed one row which is writin in this format but what i want is it should be in the same format as for aboue row example it should print as
n
n
n
n
n
n
n
or
n
5.6
5.78
6.7
n
n
n
etc..
If you know how to print data in this format for all rows which cotains n & numbers tell me...

davekw7x
07-04-2009, 09:29 AM
...i still hav a problem...

Go back to the original file. Scrub it of all non-ascii characters.

Are all of the columns aligned? If they are not, then you have some more work to do. You can "tokenize" the line by writing a function or finding a Fortran string library that contains such a function. (Use your favorite search engine.)

If the columns are all aligned, then consider the following.

If a field is a number on some lines and a non-numeric string on others, then that field must be read as a string.
For example, if a field contains the four character string " n.a" and you want to make it blanks, then assign a four-character string of spaces " " to that string. I'm not sure why you want to do this, but in order to proceed reasonably, I suggest that doing it this way leaves all of the columns aligned in the output file so that you can read it back with the same format that you used with the original

If a field can be numeric on some lines, you can still print out the string in the output file without converting it to a numeric value.

If you need the numeric value in your program, then inspect each such field to see whether it can has " n.a". If it is not and you know that the number will be in f4.1 format, for example, then you can use an f4.1 format specifier to convert the string to a real number by using the string as an "internal file." Look in your book or see, for example, http://www.ibiblio.org/pub/languages/fortran/ch2-11.html

Regards,

Dave

rrevathy25
07-06-2009, 12:58 AM
No not all columns are alligned.only few columns are alligned .I tried it by your way but its not still in proper format..what to do...

davekw7x
07-06-2009, 08:06 AM
..what to do...If you don't know where the fields are in the input lines and it happens that some lines have more fields than others, I have pretty reached the limit of what I can think of to try to help. You should try to get a local knowledgeable person to help organize your data base.



Regards,

Dave

heaths
07-06-2009, 07:17 PM
I was having this same problem until today. I thought that was the issue, then I found this post - sure enough it works now.
simulationcredit (http://simulationcredit1.com)

rrevathy25
07-07-2009, 02:20 AM
i some how managed to get it in right format but i have a small help from you people to ask..
for example for the given data given below
NEI 2001 9 23 12 25 37.75 12.3990N 95.2290E 33 0.00 4.30 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 12 25 45.14 12.4580N 95.1870E 33 0.00 4.70 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 14 47 56.30 24.3840N 94.7360E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 25 14 56 43.91 11.9070N 80.2380E 10 0.00 5.50 0.00 0.00 5.40 5.50 0.00 0.00 0 1.59e+24
NEI 2001 9 27 22 40 11.53 26.8030N 87.5940E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 0.00 5.20 0.00 0.00 0.00 0.00 0.00 0.00 0
For this data its is in specified format but i just want to remove 0.00 from every colmn..if i do tat using sed command the format is interuppted.. i mean its again in disorder..i want it to be in format & also remove just 0.00 with a blank space thier

how to do it..if anyone knows give me the code..

davekw7x
07-07-2009, 09:14 AM
i
For this data its is in specified format but i just want to remove 0.00 from every colmn.....
There is no reason you can't use my previous suggestion about reading a string as an "internal file" to do the deed, but if doing it in sed is acceptable, some people might try something like:

Here's your input file. I called this file d2.txt

NEI 2001 9 23 12 25 37.75 12.3990N 95.2290E 33 0.00 4.30 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 12 25 45.14 12.4580N 95.1870E 33 0.00 4.70 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 14 47 56.30 24.3840N 94.7360E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 25 14 56 43.91 11.9070N 80.2380E 10 0.00 5.50 0.00 0.00 5.40 5.50 0.00 0.00 0 1.59e+24
NEI 2001 9 27 22 40 11.53 26.8030N 87.5940E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 0.00 5.20 0.00 0.00 0.00 0.00 0.00 0.00 0


Here's the sed command that I used (just copy/paste it onto your command line):

sed -e 's/0.00/ /g' <d2.txt >d3.txt

Here are the output lines in file d3.txt after that command:

NEI 2001 9 23 12 25 37.75 12.3990N 95.2290E 33 4.30 0
NEI 2001 9 23 12 25 45.14 12.4580N 95.1870E 33 4.70 0
NEI 2001 9 23 14 47 56.30 24.3840N 94.7360E 33 4.10 0
NEI 2001 9 25 14 56 43.91 11.9070N 80.2380E 10 5.50 5.40 5.50 0 1.59e+24
NEI 2001 9 27 22 40 11.53 26.8030N 87.5940E 33 4.10 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 5.20 04.10 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 5.20 0


All occurrences of 0.00 are replaced by four spaces. This works as shown for the lines you posted. It may or may not be applicable to the entire file, and I wouldn't recommend it. For example if one of the entries had been "30.0050N", you wouldn't want to make the substitution. So you might try


sed -e 's/\<0.00\>/ /g' <d2.txt >d3.txt


This substitutes four spaces for words that consist of "0.00". That is, any field that contains 0.00 as a sub-field will not be altered, the substitution is made only if the entire field is "0.00".

Regards,

Dave

davekw7x
07-07-2009, 10:18 AM
OK, I am going to try one more time. My last post on the subject:

There is no reason you can't use my previous suggestion about reading a string as an "internal file" to do the deed, but if doing it in sed is acceptable, some people might try something like:

Here's your input file. I called this file d2.txt

NEI 2001 9 23 12 25 37.75 12.3990N 95.2290E 33 0.00 4.30 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 12 25 45.14 12.4580N 95.1870E 33 0.00 4.70 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 23 14 47 56.30 24.3840N 94.7360E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 25 14 56 43.91 11.9070N 80.2380E 10 0.00 5.50 0.00 0.00 5.40 5.50 0.00 0.00 0 1.59e+24
NEI 2001 9 27 22 40 11.53 26.8030N 87.5940E 33 0.00 4.10 0.00 0.00 0.00 0.00 0.00 0.00 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 0.00 5.20 0.00 0.00 0.00 0.00 0.00 0.00 0


Here's the sed command that I used (just copy/paste it onto your command line):

sed -e 's/0\.00/ /g' <d2.txt >d3.txt

Here are the output lines in file d3.txt after that command:

NEI 2001 9 23 12 25 37.75 12.3990N 95.2290E 33 4.30 0
NEI 2001 9 23 12 25 45.14 12.4580N 95.1870E 33 4.70 0
NEI 2001 9 23 14 47 56.30 24.3840N 94.7360E 33 4.10 0
NEI 2001 9 25 14 56 43.91 11.9070N 80.2380E 10 5.50 5.40 5.50 0 1.59e+24
NEI 2001 9 27 22 40 11.53 26.8030N 87.5940E 33 4.10 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 5.20 04.10 0
NEI 2001 9 28 4 37 56.67 33.3050N 75.8510E 33 5.20 0


All occurrences of "0.00" are replaced by four spaces. This works as shown for the lines you posted. It may or may not be applicable to the entire file, and I wouldn't recommend it. For example if one of the entries had been "30.0050N", you wouldn't want to make the substitution. So you might try


sed -e 's/\<0\.00\>/ /g' <d2.txt >d3.txt


This substitutes four spaces for words that consist of "0.00". That is, any field that contains 0.00 as a sub-field will not be altered; the substitution is made only if the entire field is "0.00".


If your original file had a field like " n.a" and you wanted to replace it with four spaces, you could use sed directly instead of replacing " .na" with "0.00" and then replacing "0.00" with four spaces. But I don't have a clue as to what the heck you really, really need to do.

Bottom line: If you expect to read the result in Fortran with fixed format, the columns must be aligned. If you make substitutions in the files (with Fortran, sed, or any blooming thing else) for whatever reason, the columns must stay aligned.

If the original file does not have all of the columns aligned, then you could, maybe, use awk to separate the fields and make substitutions and write a file with columns all aligned. Or, maybe awk followed by sed, or just about a million other things.

Maybe this is hard, maybe easy, but, in my opinion, no one (no one) can tell you what will work on your file by trying to follow your posts here.




Regards,

Dave

rrevathy25
07-07-2009, 10:59 PM
Ya as you said my file contained n.a which was a character.but i replaced it with blank space & then i read ts file making those colums as real value So i got the perfect format as i have shown in previous post.then you asked why i need to do such thing I want this file to do a map so i am trying on it.. i tried using the same sed command for my .dat file but nothing is getting replaced.So any program or any small function is thier to be included in my program given below to replace 0.00 to blank " " .


PROGRAM yy
CHARACTER(13):: x*5,a*1,b*1,p,qq*4
INTEGER:: c,d,e,q,r,s,o
REAL:: f,u,v,h,j,k,l,n,m,i,g
OPEN(unit=8, file="ggg.dat",status="old")
OPEN(unit=21,file="y.dat")
DO
READ(8,77,END=88,ERR=88) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k &
&,l,m,n,o,p
77 FORMAT(A5,1x,I4,1x,4(I3,1x),F6.2,1x,F8.4,A1,2x,F8. 4,A1,1x, &
&I4,1x,F4.2,2x,F4.2,1x,f4.2,2x,F4.2,2x,F4.2,1x,F5.2 ,1x,F4.2
&,2x,F5.2,1x,I3,1x,A12)
WRITE(21,77) x,c,d,q,r,s,f,u,a,v,b,e,g,h,i,j,k,l,m,n,o,p
END DO
88 CLOSE(8)
CLOSE(21)
END PROGRAM yy


One more thing how to just replace a specific column i mean to say i just want to replace 0.00 to something in only 5th & 6th column without interupting the whole file or format.