Re: Fortran wrapper

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue, 8 Aug 2006 16:39:42 -0600 (MDT)

>Hi! I am trying to write a Fortran 90 wrapper function to read data from
>a binary file. The problem is that the size of the array to be read is
>not know a priory but it is read from the file itself. In f90, I would
>allocate the array just before it is read. Can I do that with WRAPIT?
>All the web-page examples have predefined dimensions in the arrays...
>_______________________________________________

I would think you could. I think you would have
    one f90 routine that reads the sizes. The info
    is returned to NCL, then you specify the array
    
    external RDBINARY "./rdb.so"
    
    This rdb.f file only opens the file once.
    A f77 stub file ...

C NCLFORTSTART
    subroutine getsize(fName, n)
    character*(*) fName
    integer n
C NCLEND
    integer ientry
    data ientry /0/
    save ientry
    
    if (ientry.eq.0) then
        open(file=fName,...)
        ientry = 1
    end if
    
    call getsizes90 (...,n)
    
    return
    end

---NCL
    
    nsize = 0 ; n1 = 0
                                         ; n2 = 0
    RDBINARY::getsize("foo.bin", nsize) ; getsize("foo.bin", n1, n2)
    
    x1 = new ( nsize, "float") ; x1 = new (/n1,n2/), "float)
    
    RDBINARY::getdata("foo.bin", x1) ; getdata("foo.bin", x1)
    
    RDBINARY::getsize("foo.bin", nsize) ; getsize("foo.bin", n1, n2)
    
    x2 = new ( nsize, "float") ; x2 = new (/n1,n2/), "float)
    
    RDBINARY::getdata("foo.bin", x2) ; getdata("foo.bin", x2)
    
    If there are many different array sizes
    I'd probably put the getsize/getdata stuff
    into a function and then return the array.
    

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Aug 08 2006 - 16:39:42 MDT

This archive was generated by hypermail 2.2.0 : Wed Aug 09 2006 - 08:25:35 MDT