[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #YGV-657220]: Read Multiple netCDFfile

Hi Soumik,

Sorry to have taken so long to respond to your question.
> I am a new netCDF user.Can anybody please tell me how I can read multiple
> .nc files with a single Fortran code. Suppose I have temp_01.nc,temp_02.nc
> etc. and I want to read them together in a single Fortran code.

The simplest answer is that you can open each file separately, by calling 
the nf90_open function once for each file.  This will give you back a
different netCDF ID for each file, and then you can use those netCDF ID's
in subsequent calls to read the data from all the open files, something

    integer, parameter :: NFILES = 3
  ! Array of netCDF IDs
    integer :: ncid(NFILES)
  ! Open the files
    nf90_open("temp_01.nc", nf90_nowrite, ncid(1))
    nf90_open("temp_02.nc", nf90_nowrite, ncid(2))
    nf90_open("temp_03.nc", nf90_nowrite, ncid(3))
  ! Read from file i using ncid(i)
    nf90_inq_varid(ncid(i), VAR_NAME, ...)

If you actually want all the data to look like it comes from one file,
there are two approaches:

  1.  Use a utility program, such as the ncrcat or ncecat utlities
      from the NCO (netCDF operators) package to merge the separate
      files into one file and then read from that.  See
  2.  Put the files on a TDS server and create an NcML file that
      aggregates the separate files to make them look like a single
      file, accessed by having your client program access data through
      the NcML wrapper on the server.  See

> Also I need to know how can I deal with scale factor and add offset values
> without defining them manually ? Currently I am manually defining scale
> factor and offset.So it is taking a long time to do it manually.

If you are writing data, you can use another NCO program, ncpdq or
ncap, to automatically calculate the scale factor and add offset
values and supply the appropriate attributes:



Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu

Ticket Details
Ticket ID: YGV-657220
Department: Support netCDF
Priority: High
Status: Closed

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.