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

[netCDF #AFZ-136343]: NetCDF error



The bottom line is this: you need to allocate enough memory
to contain the data you are reading. In this case, the memory
is the C variable Vec and it needs to be large enough to hold
all of the data you are reading. If it less then you will probably
get some kind of memory error or segfault or something.
If you do not have room to allocate all the needed memory, then
you will need to read in the variable in pieces.


> I set nf=2000 and tried  but it didn't work. Also segmentation fault. .. Even 
> when I set count vector {40, 3000, 3}, segmentation error occured. But When I 
> tried {1, 3000, 3}, It worked. So I thought NetCDF can't afford very big 
> data. 
> 
> 
> ?? ??? ?????? ?????.
> -------- ?? ??? --------?? ??: Unidata netCDF Support <address@hidden> ??: 
> 18/4/27  ?? 4:52  (GMT+09:00) ?? ??: address@hidden ??: address@hidden ??: 
> [netCDF #AFZ-136343]: NetCDF error
> the primary problem is that you are not allocating memory
> big enough to hold the total contents of the "coordinates" variable.
> You have allocated:
>   float Vec[3*na*40] where na = 3000.
> But in fact you need to allocate
>   float Vec[2*na*nf]
> 
> This means that memory past the Vec variable will be overwritten
> which is probably causing the fault.
> 
> 
> 
> > I'm trying to read trajectory data made by Molecular Dynamics program 
> > 'AMBER', whose file format is NetCDF.I tried to read variable called 
> > "coordinates".
> > The dimensions of coordinates are as follow:
> > dimensions
> > frame = UNLIMITED ; // (20000 currently)        spatial = 3 ;        atom = 
> > 3000 ;
> > variablesfloat coordinates(frame, atom, spatial) ; 
> > I tried to read and write the data by following C language code, but 
> > segmentation fault occured. If I reduced data size that I try to read by 
> > changing count vector, It worked. Are data size which can be read at once 
> > limited? then Are there any way to read whole data?
> >
> > #include <stdio.h>#include <netcdf.h>
> > #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}#define 
> > FILE_NAME "w1000.tp3.nvtmd2.nc"
> > intmain(){int ncid, retval, VecCoord;int na=3000, nf=20000;static size_t 
> > iv_strt[] = {0, 0, 0};static size_t iv_cnt[] = {20000, 3000, 3}; // 1, 2, 
> > 3float Vec[3*na*40];int i, j, rec, k, l;
> > /*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);
> >   if ((retval = nc_inq_varid(ncid, "coordinates", &VecCoord)))    
> > ERR(retval);
> >   if ((retval = nc_get_vara_float(ncid, VecCoord,iv_strt, iv_cnt, &Vec[0])))
> >
> >
> >
> > if ((retval=nc_close(ncid)))   ERR(retval);
> > FILE *fout;//fout= fopen("home/janghm17/NetCDF/DataFile.txt", "wt");
> >
> > fout= fopen("DataFile.txt", "wt");  if(fout==NULL) {      printf("Error: 
> > Can't open output file.\n");          exit(1);            }           
> > printf("start\n");
> >             for(j=0; j<na*40; j++){              fprintf(fout, "%f %f 
> > %f\n", Vec[3*j], Vec[3*j+1], Vec[3*j+2]);              }              
> > printf("end\n");
> >                 fclose(fout); return 0;}
> >
> > Thanks,
> >
> >
> 
> =Dennis Heimbigner
>   Unidata
> 
> 
> Ticket Details
> ===================
> Ticket ID: AFZ-136343
> Department: Support netCDF
> Priority: Normal
> Status: Open
> ===================
> 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.
> 
> 
> 
> 
> 

=Dennis Heimbigner
  Unidata


Ticket Details
===================
Ticket ID: AFZ-136343
Department: Support netCDF
Priority: Normal
Status: Open
===================
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.