iwanfly网友曾在一段时间前发过贴探讨过这个问题http://bbs.pfan.cn/post-312402.html当时思路不是很清晰现思考结果如下,虽然比较麻烦,但最终还是解决了读取数据的问题,前提是知道每行最大的数据个数,比如7个。不知道论坛上的网友是否有更好的方法,不吝赐教。测试数据如下:12 89 7712 999 878 777398 789 765 98 76578 8912 89 7712 999 878 777398 789 765 98 765。。。。总共78144行。大概需要5,6秒时间把数据全部读进。program mainimplicit noneinteger,allocatable :: int_array(:,:),temp_array(:,:)integer :: count,length,step,i,ierrcharacter*256 :: str_one_recordopen(100,file='data.txt')count=0step=100000length=stepallocate(int_array(length,7))int_array=0do while(.not. eof(100)) count=count+1 loop1: do i=7,1,-1 read(100,'(A)',advance='no',eor=168) str_one_record168 read(str_one_record,*,end=999) int_array(count,1:i) exit loop1999 backspace 100 int_array(count,1:i)=0 end do loop1 if(mod(count,step)==0) then allocate(temp_array(length,7)) temp_array=0 temp_array=int_array deallocate(int_array) length=length+step allocate(int_array(length,7)) int_array=0 int_array(1:length-step,:)=temp_array deallocate(temp_array) end if end doallocate(temp_array(length,7))temp_array=0temp_array=int_arraydeallocate(int_array)allocate(int_array(count,7))int_array=0int_array(1:count,:)=temp_array(1:count,:)deallocate(temp_array)!下面处理int_array中数据deallocate(int_array)close(100)pauseend program mainiwanfly网友曾在一段时间前发过贴探讨过这个问题http://bbs.pfan.cn/post-312402.html当时思路不是很清晰现思考结果如下,虽然比较麻烦,但最终还是解决了读取数据的问题,前提是知道每行最大的数据个数,比如7个。不知道论坛上的网友是否有更好的方法,不吝赐教。测试数据如下:12 89 7712 999 878 777398 789 765 98 76578 8912 89 7712 999 878 777398 789 765 98 765。。。。总共78144行。大概需要5,6秒时间把数据全部读进。program mainimplicit noneinteger,allocatable :: int_array(:,:),temp_array(:,:)integer :: count,length,step,i,ierrcharacter*256 :: str_one_recordopen(100,file='data.txt')count=0step=100000length=stepallocate(int_array(length,7))int_array=0do while(.not. eof(100)) count=count+1 loop1: do i=7,1,-1 read(100,'(A)',advance='no',eor=168) str_one_record168 read(str_one_record,*,end=999) int_array(count,1:i) exit loop1999 backspace 100 int_array(count,1:i)=0 end do loop1 if(mod(count,step)==0) then allocate(temp_array(length,7)) temp_array=0 temp_array=int_array deallocate(int_array) length=length+step allocate(int_array(length,7)) int_array=0 int_array(1:length-step,:)=temp_array deallocate(temp_array) end if end doallocate(temp_array(length,7))temp_array=0temp_array=int_arraydeallocate(int_array)allocate(int_array(count,7))int_array=0int_array(1:count,:)=temp_array(1:count,:)deallocate(temp_array)!下面处理int_array中数据deallocate(int_array)close(100)pauseend program main

评论