'写;没有太多空间的声明 [英] 'Write; statement without a lot of spaces

查看:175
本文介绍了'写;没有太多空间的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

write 函数确实在columms之间打印了很多空格参数,最后给我一个非常大的文件。所以我如何修剪输出,以获得单个空间。

  open(unit = 1,file ='gfortran.txt ')
write(1,ERR = 1001)1,2,3


解决方案

您需要使用Fortran的编辑描述符控制输出格式。如果你只是想在一行写3个整数,那么你可以使用

$ $ $ $ $ $ c $ write(1,fmt ='(3i2)' ,err = 1001)1,2,3

它会将整数写入2个字符的宽字段在输出文件中。有许多你应该熟悉的编辑描述符的变体。几个例子:

  fmt ='(i4.2)'! 1整数被写入一个4字符宽的字段,至少有2位数字,因此如果需要,写入前导0 
fmt ='(6f9.4)'! 6个实数写入9个字符的字段中,小数点后有4个数字

还有更多除此之外,您的编译器文档将解释所有内容。


The write function does print the parameters with a lot of spaces between columms, this is giving me a very huge file in the end. so How do I trim the output, to like a single space.

open(unit=1,file='gfortran.txt')
write(1,ERR=1001)1,2,3 

解决方案

You need to take control of the output formatting using Fortran's edit descriptors. If you just want to write 3 integers on a line then you could use

write(1,fmt='(3i2)',err=1001) 1, 2, 3

which will write the integers into 2-character wide fields in the output file. There are many variations of the edit descriptors you should become familiar with. A couple of examples:

fmt='(i4.2)'  ! 1 integer is written into a 4-character wide field, with at least 2 digits so a leading 0 is written if necessary
fmt='(6f9.4)' ! 6 reals are written into 9-character fields, with 4 digits after the decimal point

There's a lot more besides this, your compiler documentation will explain everything.

这篇关于'写;没有太多空间的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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