[Thread Prev][Thread Next][Index]

Re: reading binary data



Hi Peter,
            Have a look at Ch2 Sec4. BINARY DATA in Ferret user manual.
There you can see details and usage for all the options used for reading 
binary data. Following two examples will explain you the very basic 
method.

   In your case you have to make corrections in your fortran script

      1. check variable declarion- declare "arcc1" as 4 dimensional
                                           variable.
      2. correct your file "open" and "write" statements as described 
                        in any of the examples given here.
           
   and in ferret script
           
      3. correct set data (file/format....) statement according to
                      wether the data is "sequential" or "stream"
              for /ORDER see 
                       Ch2 Sec5.1. Reading ASCII files ; Example 7
              /COLUMNS...tells Ferret the number of data values per record.
                this is an optional argument and required only if the number
                of data values per record is greater than the number of 
                variables being read. So in your case it is not needed.
                see 
                   Ch2 Sec5.1. Reading ASCII files ; Example 1(b)

 Comments : It will be convenient for later use if you are converting the 
            binary to netcdf. After reding in the binary data properly in a 
            ferret session issue the following command to save the variables 
            to a netcdf file;
                save/file="./outputfile.nc"/append var1, var2, var3        

                For details see Ref Sec29. SAVE in user manual.
                 
            Try to give some meaningfull "Subject" to your e-mails to the
                       mailing list ...so that it will not go unnoticed.

Hope this helps...

With Regards 

Jaison 

------------------------------------------------------------------------
Examples
.........               

"sequential" binary data
=========================

fortran script : 
---------------
         IMPLICIT NONE
         INTEGER  i,j,k,l,ni,nj,nk,nt
         PARAMETER  (ni=10,nj=10,nk=10,nt=10)
         REAL      pi, conc(ni,nj,nk,nt)

         pi = 22/7
         open(unit=20,form="unformatted",access='sequential',
     #        file='seq_binary.dat')
         DO i = 1, ni
              DO j = 1, nj
                   DO k = 1, nk
                        DO l = 1, nt
                            conc(i,j,k,l) = sin (i*j*k*l*pi/180)
                            write(20) conc(i,j,k,l) ! note that "write" 
                                                    ! does have only file
                                                    ! unit
                        END DO
                   END DO
              END DO
         END DO

         END 

ferret script to read seq_binary.dat:
------------------------------------
	define axis/x=1:10:1 xax
  	define axis/y=1:10:1 yax
	define axis/z=1:10:1 zax
	define axis/t=1:10:1 tax
	define grid/x=xax/y=yax/z=zax/t=tax mygrid

	file/format=unf/var=conc/grid=mygrid  "seq_binary.dat"

	list/x=10/y=10/k=10 conc

"stream" binary data
====================

fortran script :
---------------
	 IMPLICIT NONE
         INTEGER  i,j,k,l,ni,nj,nk,nt
         PARAMETER  (ni=10,nj=10,nk=10,nt=10)
         REAL      pi, conc(ni,nj,nk,nt)

         pi = 22/7
         open(unit=20,file='stream_binary.dat',form='unformatted',
     #        access='direct',recl=ni*nj*nk*4)
         DO i = 1, ni
              DO j = 1, nj
                   DO k = 1, nk
                        DO l = 1, nt
                            conc(i,j,k,l) = sin (i*j*k*l*pi/180)
                        END DO
                   END DO
              END DO
         END DO
         DO l = 1,nt
              write(20,rec=l)(((conc(i,j,k,l),i=1,ni),j=1,nj),k=1,nk)
         END DO

         END

ferret script to read stream_binary.dat
---------------------------------------
  	define axis/x=1:10:1 xax
	define axis/y=1:10:1 yax
	define axis/z=1:10:1 zax
	define axis/t=1:10:1 tax
	define grid/x=xax/y=yax/z=zax/t=tax mygrid

	file/format=stream/var=conc/grid=mygrid  "stream_binary.dat"

	list/x=10/y=10/k=10 conc

---------------------------------------------------------------------

On Fri, 23 Apr 2004, LZG wrote:

> Hi Kessler,
>
> Do you still remember me? I ever asked you about how to read in a binary
> file of 3 dimensional model output using ferret. Then, the problem was
> solved by the method you provided. But when I extend the method to a
> 4-dimensional variable, it can't get through again.
> 
> The problem is:
> 
> I have a binary model output "Myfile" in which stored a 3 dimensional
> variable named as conc(300, 166, 8).  There are total of 10 conc( ) in the
> "myfile" respective for 10 times of model output. 
> 
> In FORTRAN, I write the model output
> 
> Do t=1, 10
> 
> ...... 
> 
>      Write (1121) (((arcc1(i,j,k),i=1,300),j=1,166),k=1,8)
> 
> ......
> 
> Enddo
> 
> Then in ferret, I read in the binary file "Myfile"
> 
>   define axis/x=1:300:1 xax
> 
>   define axis/y=1:166:1 yax
> 
>   define axis/z=1:8:1   zax
> 
>   define axis/t=1:10:1  tax
> 
>   define grid/x=xax/y=yax/z=zax/t=tax mygrid
> 
>   file/format=unf/var=conc/grid=mygrid/col=`300*166*8*10`/ord=xyzt  "Myfile"
> 
>   list/x=150/y=114/t=1 conc
> 
> The result is: Every time, when I execute the program, then ferret will run
> to the step of "file/format......   ", and then quit out of ferret directly.
> 
> What's the problem? How to solve it?
> 
> Peter           
-- 
___________________________________________________

    Jaison Kurian                           
    Centre for Atmospheric and Oceanic Sciences
    Indian Institute of Science
    B A N G A L O R E   560 012
    Ph: +91-80-3942505
        +91-80-3600450
    Fax:+91-80-3600865
___________________________________________________




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement