FORTRAN による 'unformatted' のバイナリファイルを読み込むことはできますか?
Mostra commenti meno recenti
以下は FORTRAN により生成されたデータファイルを 16 進数で表示した例です。
0000000 0000 0048 4920 616d 2061 2067 656e 6975
0000020 7320 6772 6f75 6e64 686f 6721 2020 5275
0000040 6e21 2020 5275 6e21 2020 5275 6e21 2020
0000060 2020 2020 2020 2020 2020 2020 2020 2020
0000100 2020 2020 2020 2020 2020 2020 0000 0048
0000120 0000 000c 3f8c cccd 400c cccd 4053 3333
0000140 0000 000c 0000 0008 0000 0004 0000 0005
0000160 0000 0008
C 言語によるフラットバイナリのファイル内の同様のデータが本ソリューションに添付されています。以下はこのファイルからデータを読み込むためのプログラム例です。
program wrt_bin
character*72 name
real*4 xsource, zsource, dt
integer*4 ntrace, nt
name='I am a genius groundhog! Run! Run! Run!'
xsource=1.1
zsource=2.2
dt=3.3
ntrace=4
nt=5
open(unit=11, file='wrt_bin.bin', form='unformatted',
+ status='new')
WRITE(11) NAME
WRITE(11) XSOURCE,ZSOURCE,DT
WRITE(11) NTRACE,NT
close(11)
end
以下はフラットバイナリデータを生成するための C コードです。
#include<stdio.h>
#include<stdlib.h>
void main()
{
char name[72];
int ntrace, nt;
double xsource, zsource, dt;
FILE *fp;
sprintf(name," I am a genius groundhog! Run! Run! Run!");
xsource=1.1;
zsource=2.2;
dt=3.3;
ntrace=4;
nt=5;
fp=fopen("wrt_binc.bin", "wb");
fwrite(name, sizeof(char), 72, fp);
fwrite(&xsource, sizeof(double), 1, fp);
fwrite(&zsource, sizeof(double), 1, fp);
fwrite(&dt, sizeof(double), 1, fp);
fwrite(&ntrace, sizeof(int), 1, fp);
fwrite(&nt, sizeof(int), 1, fp);
fclose(fp);
}
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su 低水準ファイル I/O in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!