|
说明:我是想将年数据,按1-12月提取出来,写入12个txt中。运行结果是:8月的数据和原始年数据一模一样。其他月份看上去正常。接着我将数据写入month8.txt的命令注释掉,运存出来,month8.txt依旧和原始数据文件一样。再接着,我把open()语句中month8.txt的文件通道号改成了33(原先是28),在运行时,month8.txt这次是没有数据的,但是多出来一个fort.28文件,大小和原数据文件一样大。因为原始文件比较大,传不了,我上传一个小一点的版本。
[Fortran] 纯文本查看 复制代码 04 | character ( len = 512 ) :: cRead |
06 | character ( len = 20 ) :: wwlln_date , wwlln_time |
08 | character ( len = 5 ) :: timingerror |
09 | character ( len = 2 ) :: station |
14 | open ( 11 , file = '2014.txt' , status = 'old' , form = 'formatted' ) |
15 | open ( 12 , file = 'record.txt' , status = 'replace' ) |
16 | OPEN ( 21 , file = 'month1.txt' , status = 'replace' , form = 'formatted' ) |
17 | OPEN ( 22 , file = 'month2.txt' , status = 'replace' , form = 'formatted' ) |
18 | OPEN ( 23 , file = 'month3.txt' , status = 'replace' , form = 'formatted' ) |
19 | OPEN ( 24 , file = 'month4.txt' , status = 'replace' , form = 'formatted' ) |
20 | OPEN ( 25 , file = 'month5.txt' , status = 'replace' , form = 'formatted' ) |
21 | OPEN ( 26 , file = 'month6.txt' , status = 'replace' , form = 'formatted' ) |
22 | OPEN ( 27 , file = 'month7.txt' , status = 'replace' , form = 'formatted' ) |
23 | OPEN ( 33 , file = 'month8.txt' , status = 'replace' , form = 'formatted' ) |
24 | OPEN ( 29 , file = 'month9.txt' , status = 'replace' , form = 'formatted' ) |
25 | OPEN ( 30 , file = 'month10.txt' , status = 'replace' , form = 'formatted' ) |
26 | OPEN ( 31 , file = 'month11.txt' , status = 'replace' , form = 'formatted' ) |
27 | OPEN ( 32 , file = 'month12.txt' , status = 'replace' , form = 'formatted' ) |
30 | READ ( 11 , "(A512)" , iostat = status 1 ) cRead |
32 | CALL parserRead ( cRead ) |
36 | write ( * , * ) LEN_TRIM ( wwlln_date ) |
37 | if ( LEN_TRIM ( wwlln_date ) /= 10 ) then !这里是因为我的文件中大部分日期格式例如: 2014 / 08 / 12 ,但有的月份是 2014 / 8 / 10 或者 2014 / 8 / 1 |
38 | CALL specialread ( wwlln_date ) |
41 | READ ( wwlln_date ( 6 : 7 ) , "(I2)" ) month |
42 | write ( * , * ) wwlln_date , month |
45 | if ( month == 1 ) write ( 21 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
46 | if ( month == 2 ) write ( 22 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
47 | if ( month == 3 ) write ( 23 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
48 | if ( month == 4 ) write ( 24 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
49 | if ( month == 5 ) write ( 25 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
50 | if ( month == 6 ) write ( 26 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
51 | if ( month == 7 ) write ( 27 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
52 | if ( month == 8 ) write ( 33 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
53 | if ( month == 9 ) write ( 29 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
54 | if ( month == 10 ) write ( 30 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
55 | if ( month == 11 ) write ( 31 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
56 | if ( month == 12 ) write ( 32 , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
60 | if ( month 1 == j ) write ( i , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
72 | subroutine parserRead ( c ) |
77 | if ( c ( j : j ) == "/" ) c ( j : j ) = "|" |
79 | READ ( c , * ) wwlln_date , wwlln_time , lat , lon , timingerror , station |
80 | do j = 1 , LEN_TRIM ( wwlln_date ) |
81 | if ( wwlln_date ( j : j ) == "|" ) wwlln_date ( j : j ) = "/" |
83 | end subroutine parserRead |
85 | subroutine specialread ( d ) |
88 | READ ( d ( 6 : 6 ) , "(I1)" ) month 1 |
90 | end subroutine specialread |
|
|