如何以字符的形式读取实数 [英] How to read real numbers as characters

查看:189
本文介绍了如何以字符的形式读取实数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一个实数的数组做一些算术运算,后来我必须把它作为字符变量的输入来读取。我使用了read语句,但仍然出现错误:
$ b

I want to do some arithmetic operation to an array of real number and later I have to read it as an input for character variable. I used read statement still I get the error as


单元规范必须是整数或字符变量。

UNIT SPECIFICATION MUST BE AN INTEGER OR CHARACTER VARIABLE.

我也验证了格式描述符。这是我的一段代码

I also verified the format descriptor. Here is my piece of code

 real::la(10), sl
 integer::i
 character(len=5)::lat
 character(len=7)::station

 sl=11.25

 do i=1,10
   la = sl+ (i*0.25)
   read(la(i),'(F5.2)')lat
   station= lat//'xx'
 end do 


推荐答案

当您有

When you have

read(la(i),'(F5.2)') lat

你要求从单元 la(i)(外部文件)读入字符变量 lat 。这不是你想要的,但也是错误的。这个错误会导致你看到的错误信息:单位数字必须是一个整数。

you are asking to read from the unit la(i) (external file) into the character variable lat. This isn't what you want, but is also wrong. This wrongness results in the error message you see: the unit number must be an integer.

但是,纠正 la 而不是你想要做的。

However, correcting la to integer is not what you want to do.

相反,你想要对字符变量 lat

Instead, you want to do an internal write to the character variable lat:

write(lat, '(F5.2)') la(i)

这篇关于如何以字符的形式读取实数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆