fortran tips

1.  先定义类型,再定义存储大小

character a

dimension a(10)​

2.  获取当前时间​

第一种方法

program when 

 integer*4 today(3), now(3) 

 call idate(today) ! today(1)=day, (2)=month, (3)=year 

 call itime(now) ! now(1)=hour, (2)=minute, (3)=second 

 write ( *, 1000 ) today(2), today(1), today(3), now 

 1000 format ( 'Date ', i2.2, '/', i2.2, '/', i4.4, '; time ', & i2.2, ':', i2.2, ':', i2.2 )

 stop 

 end​

第二种方法

program now_time

integer date_time(8)       

character*10 b(3)       

call date_and_time(b(1), b(2), b(3), date_time)       

print *,’date_time    array values:’       

print *,’year=’,date_time(1)       

print *,’month_of_year=’,date_time(2)      

 print *,’day_of_month=’,date_time(3)       

print *,’time difference in minutes=’,date_time(4)       

print *,’hour of day=’,date_time(5)       

print *,’minutes of hour=’,date_time(6)       

print *,’seconds of minute=’,date_time(7)      

 print *,’milliseconds of second=’,date_time(8)      

 print *, ’DATE=’,b(1)      

 print *, ’TIME=’,b(2)       

print *, ’ZONE=’,b(3)

end

3.   数字转字符

      program tran

      integer i

      character*3 a

      i=500

      write(a,'(i3)') i

      print *, a // ' this is a test'

      end

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注