Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个整数数组
int(4) :: idate ! 1979 March 1st 00hrs write(*,*)idate ! prints ' 0 3 1 1979'
我想idate保存在一个不同的变量(仅限整数/整数数组)中,它将日期打印为:
idate
1979030100
无需将其更改为字符/字符串。
这可以做到吗。如果这是微不足道的,请原谅我,但我已经花了很多时间在它上面。
你可以这样做:
integer :: date_as_int ... date_as_int = idate(1)*10**6 + idate(2)*10**4 + idate(3)*10**2 + idate(4)
你甚至可能逃脱
date_as_int = sum(idate*10**[6,4,2,0])
或者
date_as_int = dot_product(idate, 10**[6,4,2,0])
方括号语法来自 Fortran 2003。对于较旧的编译器[6,4,2,0],应替换为(/6,4,2,0/).
[6,4,2,0]
(/6,4,2,0/)