[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
20011122: reading and writing a netcdf file
- Subject: 20011122: reading and writing a netcdf file
- Date: Tue, 27 Nov 2001 17:42:34 -0700
>From: "Devendra Singh" <address@hidden>
>Organization: ?
>Keywords: 200111220941.fAM9fqN08618 netCDF Fortran
Devendra,
>I have downloaded the netcdf files and generated a fortran template file for
>reading my netcdf file. It has read all the variables correctly. I wish to
>write the output in the following ascii format
>corrospoinding to each latitude and longitude , the temperature values of
>all 42 pressure levels like
>
>lat lon pres_levels(1 to 42)
>
>up to end of file.
>
>format(2f8.2,42f7.2)
>
>I tried to do it but could not get through. I have done some modification
>which start at line 255 and end at line 266. I could do the modification of
>the two dimensional latitude and longitude into single dimension but could
>not write the temperature values for all the pressure levels against these
>lat/lon position.I am attaching the readnet.f fortran template file
>alongwith netcdf file. I request you to kindly insert one write statement
>in the said routine for writing the output in the said format.
Typically, our support does not extend to helping users write
applications. We simply do not have resources to provide that level of
service. I was, however, interested in the data file that you were
trying to read (satellite retrievals).
Now, a couple of comments about your code:
1) you define ndims and nvars in PARAMETER statements at the beginning
of readnet.f. You then use these in an ncinq call:
call ncinq(ncid,ndims,nvars,ngatts,recdim,rcode)
The problem with this is that the second and third parameters to
a ncinq call get filled with return values by ncinq:
FORTRAN Interface: NCINQ
SUBROUTINE NCINQ(INTEGER NCID, INTEGER NDIMS, INTEGER NVARS,
* INTEGER NGATTS, INTEGER RECDIM, INTEGER RCODE)
NCID
NetCDF ID, returned from a previous call to NCOPN or NCCRE.
NDIMS
Returned number of dimensions defined for this netCDF file.
NVARS
Returned number of variables defined for this netCDF file.
NGATTS
Returned number of global attributes defined for this netCDF
file.
RECDIM
Returned ID of the unlimited dimension, if there is one for this
netCDF file. If
no unlimited size dimension has been defined, -1 is returned for
the value of
RECDIM.
RCODE
Returned error code. If no errors occurred, 0 is returned.
In standard Fortran, items declared in PARAMETER statements are not
modifiable. When attempting to run your code on a Solaris 2.6
system using Sun's WS6 Fortran compiler, I get a core dump because
of the use of items declared in PARAMETER statements in ncinq.
The solution is to get rid of the PARAMETER declaration of nvars
and change the ncinq call to use modifiable parameters:
call ncinq(ncid,nndims,nvars,ngatts,recdim,rcode)
2) The write you want to make can be done with list directed write
statements. Here is one idea:
your code:
do i=1,Along_Track*Across_Track
write(100,110)x(i),y(i)
enddo
110 format(16x,7f8.2,/,16x,7f8.2,/,16x,7f8.2/,16x,7f8.2,
1 /,16x,7f8.2/,16x,7f8.2,/)
equivalent code:
write(100,110) (x(i),y(i),i=1,Across_Track*Along_Track)
110 format(16x,2f8.2)
From your original format statement, it seems like you are wanting to
do something like:
c do j=1,Along_Track
c do i=1,Across_Track
c k=(j-1)*Across_Track+i
c x(k)=latitude(i,j)
c y(k)=longitude(i,j)
c enddo
c enddo
c do i=1,Along_Track*Across_Track
c write(100,110)x(i),y(i)
c enddo
c110 format(16x,7f8.2,/,16x,7f8.2,/,16x,7f8.2/,16x,7f8.2,
c 1 /,16x,7f8.2/,16x,7f8.2,/)
do j = 1, Along_Track
do i = 1, Across_Track
write(100,110)
& latitude(i,j),longitude(i,j),(Temperature_Retrieval(i,k,j),
& k=1,Pres_Levels)
enddo
enddo
110 format(2f8.2,42f7.2)
>with kindest regards,
>Devendra Singh
Tom Yoksas