<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi Yin
<br> enclosed alongwith the full version of the program based on the
suggestion made by Dr. Michael. This runs in Fortran-90.
<br>
<br>
<p>!PROGRAMM TO READ COMMA DELIMINATED STATION DATA
<br>!TWO CONSECUTIVE COMMAS DENOTE MISING DATA
<br>PROGRAM READ_ST
<br>CHARACTER(LEN=1200) :: longstring,restofstring,finally
<br>CHARACTER(LEN=20) :: stname
<br>INTEGER ::loc1,loc2,iostatus,len_string
<br>INTEGER ::first,i,j,ic,line
<br>REAL ::B
<br>REAL,ALLOCATABLE ::A(:)
<br>open (10,file='st.dat') !input file
<br>line=1
<br>do
<br>!Read the whole line into a single character variable
<br> read(10,'(a)',end=20) longstring
<br>!Use an internal read to get the first variable
<br> read(longstring,*) first
<br>!Get the location of the comma after the first parameter
<br> loc1=index(longstring,',')
<br>!Make a new string without the first parameter
<br> restofstring=longstring(loc1+1:len_trim(longstring))
<br>!Get the location of the comma after the station name
<br> loc2=index(restofstring,',')
<br>!Get the station name
<br> stname=restofstring(1:loc2-1)
<br>!Make a new string without the station name
<br> finally=restofstring(loc2+1:len_trim(restofstring))
<br>!Use internal read for the rest of the parameters
<br> ic=0
<br> do
<br> read(finally,*,iostat=iostatus)(b,i=1,ic)
<br> if (iostatus/=0)exit
<br> ic=ic+1
<br> enddo
<br> len_string=ic-1
<br> IF(.not. ALLOCATED(a)) ALLOCATE(a(1:len_string))
<br> read(finally,*)(a(i),i=1,len_string)
<br> write(6,*)'---line ', line,' is'
<br> write(6,*)first,stname(1:len_trim(stname)),a
<br> line=line+1
<br>enddo
<p>20 stop
<br>end PROGRAM READ_ST
<br>
<br>
<p>Huamei Yin wrote:
<blockquote TYPE=CITE>Thanks, Youhua, bhatt and Dave,
<p>The data lines in my file are like the following and I am reading it
in
<br>FORTRAN(windows version):
<p>1100030,AB FORD A,49.033,-122.367,0.3,-2.9,,,,0,,59.6,,466.14,89.44
<br>3010010,ABEE AGDM,54.283,-112.967,-1.3,-20.4,,,,0.4,24,22.5,,21.4,19.45
<p>I cannot replace all commas with spaces. In that way, the station names
<br>will be
<br>truncated. And there are missing records between commas.
<p>Dave, could you please tell me more about the parser? What command
<br>should I use?
<br>Thanks again.
<p>Huamei</blockquote>
<pre>--
==============================================================================
Dr. Atul Kumar Sahai
Scientist-D
Climate & Global Modelling Division
Indian Institute of Tropical Meteorology
Homi Bhabha Road, Pune 411 008, India
Phone: +91-20-2589-3600 ext 302 (Off); +91-20-2588-3821 (Res)
Fax: +91-20-2589-3825
email: sahai@tropmet.res.in
==============================================================================</pre>
</html>