Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > A Faster/Better...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 8209 of 8528
Post > Topic >>

A Faster/Better way?

by Infinity77 <andrea.gavana@[EMAIL PROTECTED] > May 5, 2008 at 09:54 AM

Hi All,

    I have an unformatted file, and I open it for reading in big
endian mode. The file has a repetitive structure (is a time step
re****t for a simulation): at the beginning of every time step, there
is this pseudo-declaration:

'PARAMS'
keyword number kind

where "keyword" is an 8 character string, "number" is an integer which
tells me how much data this time step contains, and "kind" is a 4
character string which tells me the data type (i.e., 'CHAR', 'REAL'
and so on). After this declaration, the data for the current time step
follows. As an example:

'PARAMS  '  4200 'REAL'
0.5372 3.7393 0.3273 .... (4200 real numbers)

With the file I am working on, this 4200 stays constant for every time
step in the simulation.
The numerical arrays are divided into blocks of up to 1000 items each:
so, in my previous example, I suppose I can not read the whole 4200
real numbers in one shot, I have to loop 4 times and read 1000 items
every time, plus read the remaining 200 as last step.

I have written the following routine to read and store the data from
this file. Is there anything I could do to speed up the reading/
storing of the data?

Thank you very much for your suggestions and comments. I apologize for
the long post.

Andrea.

! Begin Code

subroutine ReadSMSPEC(fileName, miniSteps, dimens, matrix)

	! PARAMETERS:
	! fileName: the file containing the data
	! miniSteps: the number of time steps in the simulation
	! dimens: the number of data in each time step
	! matrix: a dimens x miniStep 2D array of real data

	character*1000, intent(in) :: fileName
	integer, intent(in) :: miniSteps, dimens
	real(4), intent(out) :: matrix(dimens, miniSteps)

	integer keywordNumber, internalCount, readBuffer, matrixIndex

	character*8 keywordName
	character*4 keyworType

	logical feof

	! Open the file
	open(unit=1, file=fileName, form='UNFORMATTED', convert='BIG_ENDIAN')

	feof = .false.

	! The numerical arrays are divided into blocks of up to 1000 items
each
	readBuffer = int(dimens/1000)

	do while (.not.feof)

		! Read the keyword, number and kind
	    read(1, end=40) keywordName, keywordNumber, keywordType

		! I look for the 'PARAMS' keyword
	    if (keywordName == 'PARAMS') then

			! A new time step has been found
			! Increase the index in the matrix
			matrixIndex = matrixIndex + 1

		    internalCount = 0

			! Loop by reading a block of 1000 items
			! at a time

			do while (internalCount <= readBuffer)

				! Read a block of 1000 items until
				! you reach the end of this time step

				if (internalCount < readBuffer) then

					! We are still far from the last block,
					! Read 1000 items of data

		            read(1, end=40) matrix(1000*internalCount
+1:1000*(internalCount+1), matrixIndex)

		        else

					! We reached the last block of data:
					! Read the remaining data, which can be
					! less than 1000 items.

					read(1, end=40) matrix(1000*internalCount+1:dimens, matrixIndex)

				endif

				internalCount = internalCount + 1

			enddo

		endif

	enddo

40	continue

	close(1)
	return

end subroutine readSMSPEC

! End Code
 




 5 Posts in Topic:
A Faster/Better way?
Infinity77 <andrea.gav  2008-05-05 09:54:58 
Re: A Faster/Better way?
glen herrmannsfeldt <g  2008-05-05 10:16:53 
Re: A Faster/Better way?
Janne Blomqvist <foo@[  2008-05-06 11:48:45 
Re: A Faster/Better way?
glen herrmannsfeldt <g  2008-05-06 13:39:20 
Re: A Faster/Better way?
Janne Blomqvist <foo@[  2008-05-06 11:34:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 18 20:37:34 CDT 2008.