Fortran读取不同长度的数据
我有一个Fortran问题。我想读入不同长度的数据。 它们首先是:Fortran读取不同长度的数据,fortran,wget,Fortran,Wget,我有一个Fortran问题。我想读入不同长度的数据。 它们首先是: <TITLE>University of Wyoming - Radiosonde Data</TITLE> <LINK REL="StyleSheet" HREF="/resources/select.css" TYPE="text/css"> <BODY BGCOLOR="white"> <H2>08190 Barcelona Observations
<TITLE>University of Wyoming - Radiosonde Data</TITLE>
<LINK REL="StyleSheet" HREF="/resources/select.css" TYPE="text/css">
<BODY BGCOLOR="white">
<H2>08190 Barcelona Observations at 12Z 11 Feb 2015</H2>
<PRE>
-----------------------------------------------------------------------------
PRES HGHT TEMP DWPT RELH MIXR DRCT SKNT THTA THTE THTV
hPa m C C % g/kg deg knot K K K
-----------------------------------------------------------------------------
1012.0 98 14.0 -1.0 36 3.53 0 0 286.2 296.5 286.8
希望您能帮助我。一种方法是将每一行作为字符串读取,检查结尾并相应地进行处理:
character*1000 wholeline
do while( .true. )
read(33,'(a)')wholeline
if ( index(wholeline,'</PRE>' ).ne.0 )exit
read(wholeline,*)pres,height,tmp,tmp,dew ...
enddo
如果可以避免的话,我不喜欢故意抛出错误
顺便说一句,您不需要这种凌乱的格式,在本例中,list directed可以很好地工作。事实上,如果您所做的只是将数据传输到另一个文件,只需将字符串重写为:write34,'a'trimmwholeline
wget 'http://weather.uwyo.edu/cgi-bin/sounding?region=europe& TYPE=TEXT%3ALIST&YEAR=2015&MONTH=02&FROM=1112&TO=1112&STNM=08190' -0 data.dat
open(33, file=infilename, form='formatted',&
access='sequential',action='read')
open(34, file=outfilename, form='formatted',&
access='sequential',action='write')
read(33,'(11/)')
do i=1,77
read(33, '(f7.1,2x,i5,2x,a5,2x,a5,4x,a3,3x,f4.2,4x,a3,4x,a3)') pres,height,tmp,tmp_dew,rel_hum,mixing,wind_dir,wind_speed
write(34,'(f7.1,2x,i5,2x,a5,2x,a5,4x,a3,3x,f4.2,4x,a3,4x,a3)') pres,height,tmp,tmp_dew,rel_hum,mixing,wind_dir,wind_speed
end do
close(33)
close(34)
character*1000 wholeline
do while( .true. )
read(33,'(a)')wholeline
if ( index(wholeline,'</PRE>' ).ne.0 )exit
read(wholeline,*)pres,height,tmp,tmp,dew ...
enddo
do while( .true. )
read(33,*,err=100)pres,height,tmp,tmp,dew ...
enddo
100 continue