Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I need to write large data to file without formatting them. The following program demonstrates what happens if compiled with: Intel(R) Fortran Compiler for 32-bit applications, Version 8.1 Build 20041019Z Package ID: l_fc_pu_8.1.021 Copyright (C) 1985-2004 Intel Corporation. All rights reserved. program unform implicit none integer, dimension(:,:), pointer :: kdata integer :: n1,n2 n1=10; n2=264448 allocate(kdata(n1,n2)); kdata=1 open(unit=77,file="test.bin",form="UNFORMATTED") write(unit=77) n1 write(unit=77) n2 write(unit=77) kdata close(77) deallocate(kdata) open(unit=77,file="test.bin",form="unformatted") read(unit=77) n1 read(unit=77) n2 allocate(kdata(n1,n2)) read(unit=77) kdata close(unit=77) end program unform In line "write(unit=77) kdata" I get a segmentation fault. If I change the pointer attribute of kdata into allocatable everything works fine. However, I need the pointer attribute in my real code. In addition if I let kdata be "allocatable" but modify its output according to write(unit=77) kdata(:,:) the same segmantation fault occurs. Many thanks in advance, Matthias Moeller
Post Follow-up to this messageMatthias Möller wrote: > I need to write large data to file without formatting them. The following program demonstrates what happens if compiled with: (snip) > n1=10; n2=264448 > allocate(kdata(n1,n2)); kdata=1 > open(unit=77,file="test.bin",form="UNFORMATTED") > write(unit=77) n1 > write(unit=77) n2 > write(unit=77) kdata > close(77) Remember that each UNFORMATTED write writes one record to the file. It might require enough buffer space for the largest record written, which is huge in your case. I don't know that there is any magical record size, but I might suggest keeping it below about 64K bytes, or 16K elements assuming four byte data. For your case, I would probably try: open(unit=77,file="test.bin",form="UNFORMATTED") write(unit=77) n1,n2 do 1 i=1,n2 1 write(unit=77) (kdata(j,i),j=1,n1) close(77) Without knowing the possible values for n1, it is hard to say. This might make the record length a little small, but if n1 can get to the 100's or 1000's it is probably about right. If n1 is always 10 then you could write multiple columns (or is it rows, I forget) to each record. As data is in memory with the leftmost subscript varying fastest, you should write it out that way, as shown above. -- glen
Post Follow-up to this messageThanks for your help. I wonder where to get version 8.1.027. The latest version which can be downloaded from Intel is 8.1.024 Matthias Moeller > Your program is running out of stack due to a stack temporary created by t he > compiler. I haven't tried your case, but we did make some changes in this > area since the compiler you're using. 8.1.027 is current. The alternativ e is > to raise your stacksize limit. > > > Steve Lionel > Software Products Division > Intel Corporation > Nashua, NH > > User communities for Intel Software Development Products > http://softwareforums.intel.com/ > Intel Fortran Support > http://developer.intel.com/software/products/support/
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.