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

[netCDF #RMW-756210]: c program compilation problem



Hi Jason,

I suspect the problem is that you are trying to declare more than 2.8 GBytes of 
static array storage in the two arrays 

  float u_in[1][40][2001][4500], v_in[1][40][2001][4500];

and you would either need more memory, or provide some special compiler
options to permit declaring that much static data space in your program, or
allocate the memory at runtime using malloc(). Another possible solution would
be to use a 64-bit environment rather than a 32-bit environment for 
development.

I think this has nothing to do with netCDF, as you would probably get the same
error trying to compile your program without the netCDF function calls. 

--Russ

> To Whom it May Concern,
> 
> I am trying to use a c program to read data from a netcdf file:
> 
> #include <strings.h>
> #include <stdio.h>
> #include <string.h>
> #include <netcdf.h>
> 
> #define LAT_NAME "lat"
> #define LON_NAME "lon"
> #define TIME_NAME "time"
> #define TAU_NAME "tau"
> #define LAYER_NAME "depth"
> #define U_NAME "water_u"
> #define V_NAME "water_v"
> #define UNITS "units"
> #define U_UNITS "m/s"
> #define V_UNITS "m/s"
> #define LAT_UNITS "degrees_north"
> #define LON_UNITS "degrees_east"
> #define MAX_ATT_LEN 80
> 
> float u_in[1][40][2001][4500], v_in[1][40][2001][4500];
> char
> u_units_in[MAX_ATT_LEN],v_units_in[MAX_ATT_LEN],tau_units_in[MAX_ATT_LEN],time_units_in[MAX_ATT_LEN],layer_units_in[MAX_ATT_LEN];
> float lats_in[2001],lons_in[4500];
> int time_in[1],tau_in[1],layer_in[40];
> char lats_units_in[MAX_ATT_LEN],lons_units_in[MAX_ATT_LEN];
> 
> int main(int argC,char **argV)
> {
> 
> int ncid, u_varid, v_varid, time_varid,layer_varid, tau_varid;
> int lats_varid,lons_varid;
> int ndims_in,nvars_in,ngatts_in,unlimdimid_in;
> int lats,lons;
> int fd;
> char dName[128],tName[128],fName[128],uFname[20],vFname[20];
> int i,j;
> FILE *fdu=NULL, *fdv=NULL;
> 
> 
> if (argC < 3)
> {
> printf("********************MISSING
> ARGUMENTS**************************\n");
> printf("You did not run the program correctly.\n");
> 
> printf("--------------------------------------------------------------\n");
> 
> printf("Correct Useage: netcdf2txt <YYYYMMDD> <tau>\n");
> return(0);
> }
> sscanf(argV[1],"%s",dName);
> sscanf(argV[2],"%s",tName);
> sprintf(fName,"hycom_glb_911_%s00_t0%s_uv3z.nc",dName,tName);
> printf("fName is %s\n",fName);
> fd = nc_open(fName,NC_NOWRITE, &ncid);
> nc_inq(ncid, &ndims_in, &nvars_in, &ngatts_in, &unlimdimid_in);
> 
> nc_inq_varid(ncid, TIME_NAME, &time_varid);
> nc_get_var_int(ncid,time_varid,&time_in[0]);
> nc_get_att_text(ncid,time_varid, UNITS, time_units_in);
> printf("TIME_UNITS are %s\n",time_units_in);
> 
> nc_inq_varid(ncid, TAU_NAME, &tau_varid);
> nc_get_var_int(ncid,tau_varid,&tau_in[0]);
> nc_get_att_text(ncid,tau_varid, UNITS, tau_units_in);
> printf("TAU_UNITS are %s\n",tau_units_in);
> 
> nc_inq_varid(ncid, LAYER_NAME, &layer_varid);
> nc_get_var_int(ncid,layer_varid,&layer_in[0]);
> nc_get_att_text(ncid,layer_varid, UNITS, layer_units_in);
> printf("LAYER_UNITS are %s\n",layer_units_in);
> printf("%d\n",layer_in[0]);
> 
> nc_inq_varid(ncid, LAT_NAME, &lats_varid);
> nc_get_var_float(ncid,lats_varid,&lats_in[0]);
> nc_get_att_text(ncid,lats_varid, UNITS, lats_units_in);
> printf("LAT_UNITS are %s\n",lats_units_in);
> 
> nc_inq_varid(ncid, LON_NAME, &lons_varid);
> nc_get_var_float(ncid,lons_varid,&lons_in[0]);
> nc_get_att_text(ncid,lons_varid, UNITS, lons_units_in);
> printf("LONS_UNITS are %s\n",lons_units_in);
> 
> nc_inq_varid(ncid, U_NAME, &u_varid);
> nc_get_var_float(ncid,u_varid,&u_in[0][0][0][0]);
> nc_get_att_text(ncid,u_varid, UNITS, u_units_in);
> printf("U_UNITS are %s\n",u_units_in);
> 
> nc_inq_varid(ncid, V_NAME, &v_varid);
> nc_get_var_float(ncid,v_varid,&v_in[0][0][0][0]);
> nc_get_att_text(ncid,v_varid, UNITS, v_units_in);
> printf("V_UNITS are %s\n",v_units_in);
> }
> 
> However when I try to compile it, I get the following error message:
> 
> netcdf2txt4.o: In function `main':
> netcdf2txt4.c:(.text+0x221): relocation truncated to fit: R_X86_64_PC32
> against symbol `layer_in' defined in .bss section in netcdf2txt4.o
> collect2: error: ld returned 1 exit status
> make: *** [netcdf2txt4] Error 1
> 
> What does this error message mean and how to I resolve this issue?
> 
> Thank you for your time,
> 
> Jason
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: RMW-756210
Department: Support netCDF
Priority: Normal
Status: Closed