NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: Variable length arrays

Hi Lombardi,

Occasionally, I use malloc in FORTRAN programs.
But when I don't, I make a big static allocation in the main program,
and then do the I/O in subroutines, with variable length arrays.

For example

        real mat(1000000)
        ...
        nx = 5
        ny = 6
        nz = 7
        call scribere(mat,nx,ny,nz)

The subroutine looks like this

        subroutine scribere(myarray,n1,n2,n3)
        real myarray(n1,n2,n3)
        ...
        call ncvpt( CDFID, varid, START, count, myarray, ICODE )

You can make input subroutines that use this same feature.
Please write to me if you have more questions.

Bill

> Hi,
> I'm a fortran netcdf new user, and I neeed some help.
> 
> Since i fortran (not using the non-standard malloc) you have to 
> define the arrays at compile time, I' m used to do it using 
> dimension bigger than the maximum expected.
> 
> For istance:
>               real mat(100,100,100)
>       
> for beeing ready to have space for any array up to this dimension
> 
> Let now assume my real data is a 5*6*7 array (that is I used only
> part of tha available space) filled in this way:
> 
>               do i=1,5
>                  do j=1,6
>                     do k=1,7
>                        mat(i,j,k)=......
>                     enddo
>                  enddo
>               enddo
>       
> How do i vrite this (5*6*7) variable in a netcdf file?
> I suppose using NCVPT or NCVPTG but I have not been able to do it.
> 
> In another program I
> need to read the (5*6*7) data in a bigger array ready to contain 
> any-sized data.
> Here again I suppose I need to use NCVGT or NCVGTG but I did'nt 
> find out the way.
> 
> Please don't tell me to read the manual becouse I've already done it
> but it is to difficult for me to find out the way to use
> the arrays STRIDE and IMAP described there.
> 
> 
> 
> Thank a lot from Italy
> 
> Emanuele Lombardi
> mail:         ENEA AMB-CLIM-NUM
>       I-00060 S.M. di Galeria (RM) ITALY
> email:        lele@xxxxxxxxxxxxxxxxxxxxxxxxx
> tel   +39 6 30483366
> fax   +39 6 30483591
>       
> 


-- 
   William Weibel                           weibel@xxxxxxxxxxxxxx
   UCLA Department of Atmospheric Sciences  Tel. (310)206-4441       \\\\/
   Los Angeles, CA  90095-1565              Fax  (310)206-5219        O-O
   U.S.A.                                                              |
                                                                       - 
   'Why,' said the Dodo, 'the best way to explain it is to do it.'
                                Alice's Adventures in Wonderland
 |||| | | | |  |  |  |   |   |    |    |    |   |   |  |  |  |  | | | | | ||||

  • 1996 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: