<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi Yin
<br>&nbsp;enclosed alongwith the full version of the program based on the
suggestion made by Dr. Michael. This runs in Fortran-90.
<br>&nbsp;
<br>&nbsp;
<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')&nbsp;&nbsp; !input file
<br>line=1
<br>do
<br>!Read the whole line into a single character variable
<br>&nbsp;&nbsp; read(10,'(a)',end=20) longstring
<br>!Use an internal read to get the first variable
<br>&nbsp;&nbsp; read(longstring,*) first
<br>!Get the location of the comma after the first parameter
<br>&nbsp;&nbsp; loc1=index(longstring,',')
<br>!Make a new string without the first parameter
<br>&nbsp;&nbsp; restofstring=longstring(loc1+1:len_trim(longstring))
<br>!Get the location of the comma after the station name
<br>&nbsp;&nbsp; loc2=index(restofstring,',')
<br>!Get the station name
<br>&nbsp;&nbsp; stname=restofstring(1:loc2-1)
<br>!Make a new string without the station name
<br>&nbsp;&nbsp; finally=restofstring(loc2+1:len_trim(restofstring))
<br>!Use internal read for the rest of the parameters
<br>&nbsp;&nbsp; ic=0
<br>&nbsp;&nbsp; do
<br>&nbsp;&nbsp;&nbsp; read(finally,*,iostat=iostatus)(b,i=1,ic)
<br>&nbsp;&nbsp;&nbsp; if (iostatus/=0)exit
<br>&nbsp;&nbsp;&nbsp; ic=ic+1
<br>&nbsp;&nbsp; enddo
<br>&nbsp;&nbsp; len_string=ic-1
<br>&nbsp;&nbsp; IF(.not. ALLOCATED(a)) ALLOCATE(a(1:len_string))
<br>&nbsp;&nbsp;&nbsp; read(finally,*)(a(i),i=1,len_string)
<br>&nbsp;&nbsp; write(6,*)'---line ', line,' is'
<br>&nbsp;&nbsp; write(6,*)first,stname(1:len_trim(stname)),a
<br>&nbsp;&nbsp; line=line+1
<br>enddo
<p>20&nbsp;&nbsp; stop
<br>end PROGRAM READ_ST
<br>&nbsp;
<br>&nbsp;
<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>--&nbsp;
 ==============================================================================
Dr. Atul Kumar Sahai
Scientist-D
Climate &amp; Global Modelling Division
Indian Institute of Tropical Meteorology
Homi Bhabha Road, Pune 411 008, India

Phone: +91-20-2589-3600 ext 302 (Off);&nbsp; +91-20-2588-3821 (Res)
Fax:&nbsp;&nbsp; +91-20-2589-3825
email: sahai@tropmet.res.in&nbsp;
 ==============================================================================</pre>
&nbsp;</html>