text file reading, FORTRAN
Huamei Yin
huamei at UALBERTA.CA
Fri Jan 6 13:16:43 EST 2006
Thank you. Dr. Sahai. I really appreciate it. And thank you all again, GrADS
users.
Quoting "Dr. A. K. Sahai" <sahai at TROPMET.RES.IN>:
> Hi Yin
> enclosed alongwith the full version of the program based on the
> suggestion made by Dr. Michael. This runs in Fortran-90.
>
>
>
> !PROGRAMM TO READ COMMA DELIMINATED STATION DATA
> !TWO CONSECUTIVE COMMAS DENOTE MISING DATA
> PROGRAM READ_ST
> CHARACTER(LEN=1200) :: longstring,restofstring,finally
> CHARACTER(LEN=20) :: stname
> INTEGER ::loc1,loc2,iostatus,len_string
> INTEGER ::first,i,j,ic,line
> REAL ::B
> REAL,ALLOCATABLE ::A(:)
> open (10,file='st.dat') !input file
> line=1
> do
> !Read the whole line into a single character variable
> read(10,'(a)',end=20) longstring
> !Use an internal read to get the first variable
> read(longstring,*) first
> !Get the location of the comma after the first parameter
> loc1=index(longstring,',')
> !Make a new string without the first parameter
> restofstring=longstring(loc1+1:len_trim(longstring))
> !Get the location of the comma after the station name
> loc2=index(restofstring,',')
> !Get the station name
> stname=restofstring(1:loc2-1)
> !Make a new string without the station name
> finally=restofstring(loc2+1:len_trim(restofstring))
> !Use internal read for the rest of the parameters
> ic=0
> do
> read(finally,*,iostat=iostatus)(b,i=1,ic)
> if (iostatus/=0)exit
> ic=ic+1
> enddo
> len_string=ic-1
> IF(.not. ALLOCATED(a)) ALLOCATE(a(1:len_string))
> read(finally,*)(a(i),i=1,len_string)
> write(6,*)'---line ', line,' is'
> write(6,*)first,stname(1:len_trim(stname)),a
> line=line+1
> enddo
>
> 20 stop
> end PROGRAM READ_ST
>
>
>
> Huamei Yin wrote:
>
>> Thanks, Youhua, bhatt and Dave,
>>
>> The data lines in my file are like the following and I am reading it in
>> FORTRAN(windows version):
>>
>> 1100030,AB FORD A,49.033,-122.367,0.3,-2.9,,,,0,,59.6,,466.14,89.44
>> 3010010,ABEE AGDM,54.283,-112.967,-1.3,-20.4,,,,0.4,24,22.5,,21.4,19.45
>>
>> I cannot replace all commas with spaces. In that way, the station names
>> will be
>> truncated. And there are missing records between commas.
>>
>> Dave, could you please tell me more about the parser? What command
>> should I use?
>> Thanks again.
>>
>> Huamei
>
> --
> ===============================================================================
> 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 at tropmet.res.in
> ===============================================================================
>
>
>
More information about the gradsusr
mailing list