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.
>To: address@hidden >From: "Hui Du" <address@hidden> >Subject: Re: 20040504: Problems with reading my data >Organization: ? >Keywords: 200405042102.i44L2FtK015907 Hi Hui Du, > I am trying to read data from a netcdf file. But it turned out crazy ... > When I use the same fortran program to read another different fille, it > works well. The only modification I made is changing the dimension size ... > iv=4 > k=1 > call rdncdf2d(ncidin,iv,k,data) ... > subroutine rdncdf2d(ncidin,id,itime,data) ... > start(3)=itime > call ncvgt(ncidin,id,start,count,data,rcode) ... > There are some difference between these two file in that one has scale > factor and offset, the other does not. I see a couple of possible problems. 1. You are assuming that the library handles scale and offset attributes for you in unpacking values. For the C and Fortran libraries, that's not the case. The scale_factor and add_offest attributes are just a convention that you must handle in your calling code. So you will have to detect if these attributes exist and if so, explicitly unpack the data using the specified values. 2. You are assuming the variable ID of the variable you want is 4 (iv = 4). Are you sure that the variable you want from the second file has the same variable ID? The ID is just assigned to be the order in which variables are defined, so if more or less variables are defined for the second file or if variables are defined in a different order, the assumption that iv=4 identifies the variable you want could be wrong. You could instead use the ncvinq() function to find out which variable ID corresponds to a particular named variable. Also, in the future I suggest that you send questions such as this to "address@hidden" rather than to the whole netcdfgroup mailing list, which is mainly intended for announcements and discussion. Thanks. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu/staff/russ