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

[netCDF #OJK-166732]: read in large 3 dim matrix



Hello,

I notice your file has the '.h5' suffix, which suggests it is an hdf5 file and 
not a netCDF file.  Is this correct? What is the output if you run 'ncdump -k 
[filename]'?

-Ward

> hi support,
> 
> i'm a really newbie in c programming and tried to adapt the example 
> simple_xy_rd.c for my purposes. but i have a problem to read in a large 
> matrix from a netcdf file:
> 
> my netcdf file looks like:
> 
> netcdf ECA_EXAA_ATL_NOM_1B_20190914T011647Z_20200315T110000Z_26139D {
> 
> dimensions:
>         dimensionHeight2_hr = 56 ;
>         dimensionSensingTime = 20910 ;
>         dimensionReg_Err = 2 ;
> 
> float MIEinp_Signal_hr(dimensionHeight2_hr, dimensionReg_Err, 
> dimensionSensingTime) ;
>        MIEinp_Signal_hr:units = "1/(sr*m)" ;
> 
> data:
> 
> MIEinp_Signal_hr =
>   1.821708e-06, 5.182378e-07, 3.982096e-07, 5.066408e-07, 1.011924e-06,
>     -9.572153e-08, -2.309762e-07, 1.285006e-06, 8.763676e-07, -2.059509e-07,
>   ...
> 
> }
> 
> here my test.c
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include <netcdf.h>
> 
> /* This is the name of the data file we will read. */
> #define FILE_NAME 
> "ECA_EXAA_ATL_NOM_1B_20190914T011647Z_20200315T110000Z_26139D.h5"
> 
> #define dimensionHeight2_hr 56
> #define dimensionSensingTime  20910
> #define dimensionReg_Err 2
> 
> /* Handle errors by printing an error message and exiting with a
>  * non-zero status. */
> #define ERRCODE 2
> #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
> 
> 
> int
> main()
> {
>    /* This will be the netCDF ID for the file and data variable. */
>    int ncid, varid;
>    float 
> signal_mie[dimensionHeight2_hr][dimensionReg_Err][dimensionSensingTime];
> 
>    /* Loop indexes, and error handling. */
>    int x, y, z, retval;
> 
>    /* Open the file. NC_NOWRITE tells netCDF we want read-only access
>     * to the file.*/
>    if ((retval = nc_open(FILE_NAME, NC_NOWRITE, &ncid)))
>       ERR(retval);
> 
>    /* Get the varid of the data variable, based on its name. */
>    if ((retval = nc_inq_varid(ncid, "MIEinp_Signal_hr", &varid)))
>       ERR(retval);
> 
>    /* Read the data. */
>    if ((retval = nc_get_var_float(ncid, varid, &signal_mie[0][0][0])))
>       ERR(retval);
> 
> 
>    /* Close the file, freeing all resources. */
>    if ((retval = nc_close(ncid)))
>       ERR(retval);
> 
>    printf("*** SUCCESS reading example file %s!\n", FILE_NAME);
>    return 0;
> }
> 
> g++ -o test test.c -lnetcdff -lnetcdf
> ./test
> *Segmentation fault (core dumped) *
> 
> it's not possible to initial this big 3-d matrix
> float signal_mie[dimensionHeight2_hr][dimensionReg_Err][dimensionSensingTime];
> 
> is there another way to read this variable into a c vector?
> 
> 
> OS:
> 
> CentOS Linux release 7.8.2003 (Core)
> gcc --version
> gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
> 
> netcdf.x86_64 4.3.3.1-5.el7                @epel
> netcdf-cxx.x86_64 4.2-8.el7                    @epel
> netcdf-cxx-devel.x86_64 4.2-8.el7                    @epel
> netcdf-devel.x86_64 4.3.3.1-5.el7                @epel
> netcdf-fortran.x86_64 4.2-16.el7                   @epel
> netcdf-fortran-devel.x86_64 4.2-16.el7                   @epel
> 
> many thanks for helping and best regards,
> 
> katja
> 
> 
> --
> 
> Tel. 975-1989
> Tel. +49 8153 28 1989
> 
> 
> 


Ticket Details
===================
Ticket ID: OJK-166732
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.