将文件读入fortran [英] Reading files into fortran

查看:129
本文介绍了将文件读入fortran的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在Fortran中编写了一些代码,该代码自身乘以一个方阵.但是我必须相乘的矩阵在文件中,并且在将其读入程序时遇到了一些问题.我认为是因为示例数据采用以下格式:

So I'm writing some code in Fortran that multiplies a square matrix by itself. But the matrix I have to multiply is in a file and I'm having some issues reading it into the program. I think its because the sample data is in the following format:

3

101

010

101

第一行是矩阵的维数,每行是矩阵中的now,但是条目之间没有空格.所以我想我的问题是,当我将这些行读取为2d数组时,该如何拆分这些行?

The first row is the dimension of the matrix, and each row is a now in the matrix, but there aren't spaces in between the entries. So I guess my question is how do I split up those rows as I read them into a 2d array?

推荐答案

将第一个数字读为N,并使用它来分配维度N乘N的数组.然后在该数组的时间读取一行: array (i, 1:N)) for i = 1 toN.请参见 Fortran:阅读将一排数字放入数组以使用格式.

Read in the first number as N and use it to allocate an array of dimension N by N. Then read a row at a time of this array: array (i, 1:N)) for i=1 to N. See Fortran: reading a row of numbers into an array for the format to use.

这篇关于将文件读入fortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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