Reputation: 1174
I am using code similar to this - Read in coordinate variables to read in latitude and longitude from a netCDF file
call check( nf_inq_varid(ncid, LAT_NAME, lat_varid) )
call check( nf_inq_varid(ncid, LON_NAME, lon_varid) )
! Read the latitude and longitude data.
call check( nf_get_var(ncid, lat_varid, lats) )
call check( nf_get_var(ncid, lon_varid, lons) )
Both lats and lons are 1-Dimensional fortran arrays.
My initial data set is in geographical coordinates and I need to convert this into a rotated lat lon grid and I use the code in this URL Geographical to rotated lat lon grid.
The way this works is the following For each geographical latitude and longitude I get a rotated latitude. Ditto for rotated longitude.
Mathematically
f(latitude_geo,longitude_geo) = latitude_rot
f(latitude_geo,longitude_geo) = longitude_rot
So the rotated lat and lon arrays are two dimensional arrays. I want to be able to write the rotated lat and lon arrays back to the original netCDF file using nf_put_vara_real or nf_90_put_vara_real(f77 or f90 does not matter).
How can I do this since the original lat and lon arrays are 1-D arrays ? Is it possible to read the original 1-d arrays as 2-D arrays ?
Upvotes: 0
Views: 975
Reputation: 147
Your transformation creates 2-dimensional longitude and latitude values, so you need to define x
and y
as new running indices.
lon(lon) => lon(x,y)
lat(lat) => lat(x,y)
Basically, you describe the lon
and lat
as variable and add x
and y
as new dimensions. This way longitude and latitudes are mapped to the correct grid points.
If written correctly to a NetCDF file, it's content should be similar to this one:
netcdf example {
dimensions:
x = 360 ;
y = 180 ;
variables:
float x(x):
x:long_name = "x-dimension" ;
float y(y):
y:long_name = "y-dimension" ;
float lon(y, x) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
...
float lat(y, x) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
...
float data(y, x) ;
data:long_name = "your data name" ;
...
}
(Output via ncdump -h example.nc
)
Upvotes: 2