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.
Hi Izaro, > I have problems with reading a netcdf file with fortran 77. > > My problem is this: > > I have to translate a netcdf reading program from MATLAB to FORTRAN 77. It might help to look at these simple example programs that do the same thing, one in MATLAB and the other for Fortran-77: http://www.unidata.ucar.edu/software/netcdf/examples/programs/simple_xy_rd.m http://www.unidata.ucar.edu/software/netcdf/examples/programs/simple_xy_rd.f These are from one of the six example programs available in several programming languages, including Fortran-77 and MATLAB: http://www.unidata.ucar.edu/software/netcdf/examples/programs/ > Do you know which method uses the nf_get_var_real command to read the > variable?And, which is the order it follows? The nf_get_var_real program reads the data from the disk with the first Fortran dimension varying fastest. I beleive MATLAB also uses the same ordering (called "column major") with the first dimension varying fastest. These are the opposite of the output of CDL (from ncdump), which has the last dimension varying fastest (as in C or Java). So if "ncdump -f foo.nc" shows the data structure like this: dimensions: eta_rho = 136 ; x_rho = 157 ; variables: float lon_rho(eta_rho, x_rho) ; then to read in the whole variable at once into a Fortran array, it should be dimensioned in the other order, as REAL Lon_rho(157,136) and you should assume the first dimension corresponds to x_rho and the second to eta_rho. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: YNF-841048 Department: Support netCDF Priority: Normal Status: Closed