Jellyse
Jellyse

Reputation: 863

Count number of variables in netcdf file

I have a netcdf file

ncdisp('F:\Data\Coriolis\ArgoProfiles\ArgoProfiles\DataSelection_20191119_093255_9342316/argo-profiles-2902636.nc')
Source:
           F:\Data\Coriolis\ArgoProfiles\ArgoProfiles\DataSelection_20191119_093255_9342316\argo-profiles-2902636.nc
Format:
           classic
Global Attributes:
           title               = 'Argo float vertical profile'
           institution         = 'CSIO'
           source              = 'Argo float'
           history             = '2019-11-19T09:33:19Z creation'
           references          = 'http://www.argodatamgt.org/Documentation'
           comment             = ''
           user_manual_version = '3.03'
           Conventions         = 'Argo-3.0 CF-1.6'
           featureType         = 'trajectoryProfile'
Dimensions:
           DATE_TIME = 14
           STRING256 = 256
           STRING64  = 64
           STRING32  = 32
           STRING16  = 16
           STRING8   = 8
           STRING4   = 4
           STRING2   = 2
           N_PROF    = 2
           N_PARAM   = 3
           N_LEVELS  = 71
           N_CALIB   = 1
           N_HISTORY = 6     (UNLIMITED)
Variables:
    DATA_TYPE                   
           Size:       16x1
           Dimensions: STRING16
           Datatype:   char
           Attributes:
                       long_name  = 'Data type'
                       _FillValue = ' '
    FORMAT_VERSION              
           Size:       4x1
           Dimensions: STRING4
           Datatype:   char
           Attributes:
                       long_name  = 'File format version'
                       _FillValue = ' '
    HANDBOOK_VERSION            
           Size:       4x1
           Dimensions: STRING4
           Datatype:   char
           Attributes:
                       long_name  = 'Data handbook version'
                       _FillValue = ' '

And I would like to count the number of variables. In this case, the answer would be 3.

I tried to use

info=ncinfo(FilePath);
numel(info.Variables.Name)

But this gives me

2.6413e+96
Warning: Number of elements exceeds maximum flint 2^53-1.
The result may be inaccurate. 

Which is not correct. How do I find the number of variables in my netcdf file? My original netcdf file is a lot bigger and I can't count them by hand anymore.

Upvotes: 0

Views: 618

Answers (1)

Jellyse
Jellyse

Reputation: 863

@obchardon is right.

numel(info.Variables) counts the number of variables in the netcdf file.

Upvotes: 3

Related Questions