This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: Maureen Cribb <address@hidden> >Keywords: 199506051445.AA05554 ncvarput Hi Maureen, > While running the attached C program, the following error message > appears at the point where a hyperslab of values is being read into > the netCDF variable,T : > ncvarput: Invalid edge length 180 > > It would appear that I'm incorrectly defining the edge lengths ... > can you suggest what I'm doing wrong? Yes, it looks like you need to start your indexing at 0 rather than 1, since you are using C rather than Fortran. Specifically, where you have: > start[1]=0; > start[2]=0; > start[3]=k; > > /* put all 360x180 values at one particular level */ > count[1]=360; > count[2]=180; > count[3]=1; > > ncvarput(ncid,t_id,start,count,(void*) T); you want instead: start[0]=0; start[1]=0; start[2]=k; /* put all 360x180 values at one particular level */ count[0]=360; count[1]=180; count[2]=1; A few more suggestions: > /* to compile: > CC -o insee insee.c +w -L/opt/netcdf/lib -lnetcdf > -I/opt/netcdf/include/netcdf.inc > */ I think the include option should be -I/opt/netcdf/include since it should name a directory, not a file. > #include <stdio.h> > #include <stdlib.h> > #include "/opt/netcdf/include/netcdf.h" The latter include statement should just be #include <netcdf.h> given the correct include option on the compile line. > void main(void); > > void main(void){ > > FILE *the_data; > int lon_id,lat_id,z_id,t_id,ncid; > int lat_inc,i,j,k,m,z[2]; > long int start[3],count[3]; > float lg[360],lt[180],T[360][180]; > > static long lg_start[]={0}; > static long lg_count[]={360}; > static long lt_start[]={0}; > static long lt_count[]={180}; > static long z_start[]={0}; > static long z_count[]={2}; > > the_data=fopen("test.obj","r"); > ncid=ncopen("test.nc",NC_WRITE); > > /* get variable id #s */ > lon_id=ncvarid(ncid,"lon"); > lat_id=ncvarid(ncid,"lat"); > z_id=ncvarid(ncid,"z"); > t_id=ncvarid(ncid,"T"); > > /* fill lat, lon, z arrays */ > for(i=0; i<360; i++) > lg[i]=i+0.5; > > ncvarput(ncid,lon_id,lg_start,lg_count,(void*) lg); > > for(i=0; i<180; i++) > lt[i]=i-89.5; > > ncvarput(ncid,lat_id,lt_start,lt_count,(void*) lt); > > z[1]=0; > z[2]=-10; Again, the indexing should start at 0. z[2] does not exist. ______________________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu