問題タブ [fortran95]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
pointers - 行列の対角線にポインタを割り当てる方法は?
REAL*8 MATRIX(100,100)
主対角線または上三角形だけからポインターを作成したいという行列があります。どうやってするか?
目的は、クリーンな「名前付き」の方法でこれらの要素に簡単にアクセスすることです。
floating-point - Fortran でのデータ型の不一致
Fortran 95 で初歩的なアルゴリズムを作成し、Richardson 外挿として知られる手順で補強された中心差分を使用して関数 (コードで規定されている例) の勾配を計算しました。
単精度では問題なく動作し、まともな結果が得られます。しかし、コードに示されているように倍精度に変更しようとすると、代入ステートメントを主張してコンパイルしようとするとエラーが発生します。
型の不一致が発生していreal(4)/real(8)
ます。倍精度のいくつかの異なる宣言を試み、コード内のすべての適切な倍精度定数を で追加しましたが、d0
毎回同じエラーが発生します。f
関数がどのように単精度数を生成する可能性があるかについて、私は少し困惑しています。
valgrind - 2 行目をファイルに出力するときに valgrind でエラーが発生する
コード内の障害を見つけるために valgrind を使用しています。私が使用するコマンドは
コードのみでコードをコンパイルします-g
。単一の書き込み行を指す多くのエラーが発生します (出力された 3 つの値は初期化され、適切に定義されています)。
すべてConditional jump or move depends on uninitialised value(s)
エラーがあります。上記の行は、1 つのファイルに出力される一連の行の 2 行目です。エラーの最後に、さらに 2 つ取得します。1 つはファイルを開く行を指しています。
resStep
は整数です。エラーはSyscall param write(buf) points to uninitialised byte(s)
です。最後にAddress 0x52d83f4 is 212 bytes inside a block of size 8,344 alloc'd
、ファイルをフラッシュすると (ファイルを閉じる前に) エラーが発生します。
ここにはロジックが見つかりません。問題が誤った方法でファイルを開くことにある場合、最初の行でエラーが発生しませんか?
これをコンパイルするために f95 を使用します。gcc のバージョンは 4.1.2 です。どれもアップグレードできません。
format - 指数値の出力方法
出力ファイルで科学的形式を使用すると、2.45E+01 ではなく 0.245E+02 が得られます。
Fortranで後の形式で出力するには?
更新:
@Bálint Aradi の回答によると、x = 24.5
取得するには設定する必要がありまし2.45E+01
た。
fortran - DOS または Fortran で Notepad++ ファイルを読み取るにはどうすればよいですか?
Mac と PC の両方で Fortran 95 プログラムを使用して読み取ろうとしている Notepad++ で作成されたテキスト ファイルを受け取りました。読み取り行は次のとおりです。
行の長さがわからないので、入力の長さを 512 と定義しました。メモ帳以外のファイルでは、行末が見つかったときに読み取りが「停止」し、自動的に次のテキスト行に進みます。notepad++ ファイルでは、キャリッジ リターンをスキップして 512 文字を読み取ります。PC で dos エディターを使用してファイルを開くと、改行記号 (ASCII char 13) が表示されますが、行間に改行がなく、すべて互いに追加されています。
ichar(13)
andを検索してichar(10)
、行の先頭にバックスペースし、次の行に強制的に進めようとしました。で読み込んでformat '(a,/')'
いますが、何も動作させることができませんでした。
fortran - FORTRAN encountering premature EOL
~~SOLVED, See Edit4)
I am creating an input file with Java on OSX, when I try to run the FORTRAN program that reads the input file, I encounter EOF on the first line:
where line 37 starts:
I read that this could be a problem with the OS's EOL character, and I've run into it before but can't remember how I fixed it. I am using "\n" in the Java code.
I also tried writing a simple file from the FORTRAN code, in TextWrangler I opened it and saw some leading character (diamond shaped) so I copied that to my Java code but to no avail.
Also, if I edit a text in Eclipse and run it with the FORTRAN program, it works.
Please help,
Thanks in advance
Edit1) Here is the Hexdump of input2.txt, I don't see anything strange, however my eye is untrained.
those zeros are okay for now, little bug in the java code but FORTRAN should still give me NaN in the calculation.
Edit2) Hex dump from test file:
I've had this problem before, a guy successfully tested the file by explicitly setting EOL to ^M (instead of Unix's ^J), however, I don't know how to do this with java, shouldn't the EOL convention be the same if the program.f is compiled on the same machine?
Edit3) Ok, it seems the file was being written to my "/Users/Tricknology/" directory instead of the location from where I ran the program. However, this led me to a problem.
is too long, and
produces:
(spaces included)
Anyone know of a way to make this work? I think that is the root of the problem.
Edit4) Found the solution:
I changed the read line to
where
and it works. Thank you everyone, I hope this helps someone else save a lot of time in the future.