本文介绍了Fortran 新手,关于写入文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Fortran 完全陌生,对编程也很陌生.我正在尝试编译其他人编写的脚本.这给我带来了一些问题.代码的上半部分是:

I am completely new to Fortran and pretty new to programming in general. I am trying to compile a script someone else has written. This is giving me a few problems. The top half of the code is:

C
C Open direct-access output file ('JPLEPH')
C
OPEN ( UNIT = 12,
. FILE = 'JPLEPH',
. ACCESS = 'DIRECT',
. FORM = 'UNFORMATTED',
. RECL = IRECSZ,
. STATUS = 'NEW' )


C
C Read and write the ephemeris data records (GROUP 1070).
C
CALL NXTGRP ( HEADER )

IF ( HEADER .NE. 'GROUP 1070' ) CALL ERRPRT(1070,'NOT HEADER')

NROUT = 0
IN = 0
OUT = 0


1 READ(*,'(2i6)')NRW,NCOEFF
if(NRW .EQ. 0) GO TO 1
READ (*,'(3D26.18)',IOSTAT =IN) (DB(K),K=1,NCOEFF)


DO WHILE ( ( IN .EQ. 0 )
. .AND. ( DB(2) .LT. T2) )

IF ( 2*NCOEFF .NE. KSIZE ) THEN
CALL ERRPRT(NCOEFF,' 2*NCOEFF not equal to KSIZE')
ENDIF

C
C Skip this data block if the end of the interval is less
C than the specified start time or if the it does not begin
C where the previous block ended.
C
IF ( (DB(2) .GE. T1) .AND. (DB(1) .GE. DB2Z) ) THEN

IF ( FIRST ) THEN
C
C Don't worry about the intervals overlapping
C or abutting if this is the first applicable
C interval.
C
DB2Z = DB(1)
FIRST = .FALSE.
ENDIF

IF (DB(1) .NE. DB2Z ) THEN
C
C Beginning of current interval is past the end
C of the previous one.

CALL ERRPRT (NRW, 'Records do not overlap or abut')
ENDIF

DB2Z = DB(2)
NROUT = NROUT + 1

print*,'Out =', OUT

WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)

print*,'Out2 =', OUT


IF ( OUT .NE. 0 ) THEN
CALL ERRPRT (NROUT,
. 'th record not written because of error')
ENDIF

所以,当我在屏幕上打印Out"和Out2"时,我发现 Out=0 和 Out2=110.因为它不再等于零,所以程序给了我一个错误.因此,我基本上想知道这里发生了什么:

So, when I print "Out" and "Out2" to the screen I find that Out=0 and Out2=110. As it is not longer equal to zero, the program gives me an error. Therefore I am basically wondering about what is happening here:

WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)

我假设 12 指的是我已经打开(并创建)并想要写入的文件.第一个括号的其余部分是做什么的?第二个有什么意义?这是否给了我想要放入文件的信息?以防万一,数据库在哪里填充?

I assume that 12 refers to the file I have opened (and created), and want to write to. What does the rest of the first brackets do? And what is the point of the second? Does that gives me the information I want to put in my file? In case, where does DB get filled with that?

通常我想知道出了什么问题?为什么 OUT 会改变值?(我需要t

Generally I am wondering what is going wrong? Why does OUT change value? (I need t

NCOEFF 在程序开始时定义为 Integer,而 DB: 定义为 DOUBLE PRECISION DB(3000), DB2Z/0.d0/,所以我假设 DB 是某种数组.

NCOEFF is defined as an Integer in the beginning of the programme, and DB: as DOUBLE PRECISION DB(3000), DB2Z/0.d0/ , so I assume DB is an array of some sort.

推荐答案

引用手册REC表示要读取或写入的记录号.按照建议,请参阅编译器随附的文档以获取更多说明.

To quote the handbook REC indicates the record number to be read or written. As advised, see the documentation which accompanies your compiler for further explanation.

(DB(K),K=1,NCOEFF) 表示DB中从1到NCOEFF的所有元素.您正在查看 io-implied-do 语句.

(DB(K),K=1,NCOEFF) means 'all the elements in DB from 1 to NCOEFF. You are looking at an io-implied-do statement.

这篇关于Fortran 新手,关于写入文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 02:03