[netcdfgroup] Ragged Arrays in Fortran and netcdf4

Roy Mendelssohn Roy.Mendelssohn at noaa.gov
Wed Apr 2 17:35:53 MDT 2008


Hi All:

I am working on creating a netcdf4 file with the structure we are  
trying to achieve.  I have a file with Box10 groups and B0x2  
subgroups, works great.  Now I am trying to do ragged arrays.  Below  
is the only fortran example I can find that does ragged arrays.  It  
is only writing one,1-dimensional array, so I am unsure what I do  
when I am writing an N-dimensional ragged array.   Do I just write  
each "column" in a loop - if so how does it know that it is writing  
to the same structure?  Or if I can do multiple "columns" at once,  
how do I set that up.  More realistic examples would be very helpful,  
including an example that writes an N-dimensional ragged array, and  
an example that adds one more column to an existing ragged array.   
Even just the fortran equivalent of the program tst_vl.c would be  
very helpful

It is clear how to do it in C (I set up an array of structures of the  
given form), but not in either version of FORTRAN.

Thanks,

-Roy


C     This is part of the netCDF package.
C     Copyright 2008 University Corporation for Atmospheric Research/ 
Unidata.
C     See COPYRIGHT file for conditions of use.

C     This program tests netCDF-4 variable functions from fortran, even
C     more, even more.

C     $Id: ftst_vars4.F,v 1.9 2008/03/10 17:24:35 ed Exp $

       program ftst_vars4
       implicit none
       include 'netcdf.inc'

C     This is the name of the data file we will create.
       character*(*) FILE_NAME
       parameter (FILE_NAME='ftst_vars4.nc')

C     NetCDF IDs.
       integer ncid, vlen_typeid

       integer max_types
       parameter (max_types = 1)

C     Need these to read type information.
       integer num_types, typeids(max_types)
       integer base_type, base_size, num_members, member_value
       character*80 type_name, member_name
       integer type_size, nfields, class

C     Information for the vlen type we will define.
       character*(*) vlen_type_name
       parameter (vlen_type_name = 'vlen_type')

C     Some data about and for the vlen.
       integer vlen_len, vlen_len_in
       parameter (vlen_len = 5)
       integer data1(vlen_len), data1_in(vlen_len)

C     These must be big enough to hold the stuct nc_vlen in netcdf.h.
       integer vlen(10), vlen_in(10)

C     Loop indexes, and error handling.
       integer x, retval, index(1)

       print *,'*** Testing VLEN types.'

       do x = 1, vlen_len
          data1(x) = x
       end do

C     Create the netCDF file.
       retval = nf_create(FILE_NAME, NF_NETCDF4, ncid)
       if (retval .ne. nf_noerr) call handle_err(retval)

C     Create the vlen type.
       retval = nf_def_vlen(ncid, vlen_type_name, nf_int, vlen_typeid)
       if (retval .ne. nf_noerr) call handle_err(retval)

C     Set up the vlen with this helper function, since F77 can't deal
C     with pointers.
       retval = nf_put_vlen_element(ncid, vlen_typeid, vlen,
      &     vlen_len, data1)
       if (retval .ne. nf_noerr) call handle_err(retval)

C     Write the vlen attribute.
       retval = nf_put_att(ncid, NF_GLOBAL, 'att1', vlen_typeid, 1,  
vlen)
       if (retval .ne. nf_noerr) call handle_err(retval)

C     Close the file.
       retval = nf_close(ncid)
       if (retval .ne. nf_noerr) call handle_err(retval)


**********************
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division	
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."





More information about the netcdfgroup mailing list