|
本帖最后由 max533 于 2015-8-24 21:14 编辑
下面是我的一個程序,但我不清楚為什麼forall和where在這個案例上的應用。為什麼forall可以,但where不行。
分別在line57和line60,如果使用forall的話,在螢幕上就只能顯示4個字的字串。如果使用where的話,在螢幕上就只能顯示3個字的字串。
程式的相關附件在壓縮檔中。
先在這邊感謝各位高手。
[Fortran] 纯文本查看 复制代码 01 | program add_gamit_station_info |
04 | integer :: count , stat , err , err 2 , i , stat 2 , stat 3 , k , stat 4 |
05 | character :: example_line * 300 , filename * 30 , line * 300 , site * 4 |
06 | character ( len = 300 ) , allocatable :: example_line_array ( : ) |
07 | character ( len = 4 ) , allocatable :: example_site_array ( : ) |
09 | open ( 11 , file = 'list.txt' ) |
10 | close ( 11 , status = 'delete' ) |
11 | call system ( 'dir /b *.info > list.txt' ) |
12 | open ( 11 , file = 'list.txt' ) |
13 | open ( 22 , file = 'station_cwb.info.db' ) |
14 | open ( 33 , file = 'station_expt.info.db' ) |
17 | read ( 22 , * , iostat = stat 4 ) example_line |
22 | read ( 22 , '(a300)' , iostat = stat ) example_line |
29 | allocate ( example_line_array ( count ) , stat = err ) |
32 | write ( * , * ) 'The example_line_array allocated sucessfully.' |
34 | write ( * , * ) 'The example_line_array failed to allocate.' |
37 | allocate ( example_site_array ( count ) , stat = err 2 ) |
40 | write ( * , * ) 'The example_site_array allocated sucessfully.' |
42 | write ( * , * ) 'The example_site_array failed to allocate.' |
48 | read ( 22 , * , iostat = stat 4 ) example_line |
52 | read ( 22 , '(a300)' ) example_line_array ( i ) |
60 | forall ( i = 1 : count : 1 ) example_site_array ( i ) = example_line_array ( i ) ( 2 : 5 ) |
63 | write ( * , * ) example_site_array ( i ) |
71 | read ( 11 , * , iostat = stat 2 ) filename |
73 | open ( 44 , file = trim ( filename ) ) |
76 | read ( 44 , * , iostat = stat 4 ) line |
81 | read ( 44 , '(a300)' , iostat = stat 3 ) line |
84 | if ( any ( example_site_array == site ) ) cycle |
85 | write ( 33 , '(a4)' ) site |
|
|