C CENTER FOR OCEAN-ATMOSPHERIC PREDICTION STUDIES, C THE FLORIDA STATE UNIVERSITY C C DIRECT ALL QUESTIONS TO: nscat-anim@coaps.fsu.edu C C****************************************************************** C Version: 1.2 C Author: Josh Grant C Date: July 5th, 2001 C Modifications: Added one argument to the function. Now the function is C called with 7 arguments. The last argument added is used C for setting the missing values of the dataset. This C argument list is getting longer than I would like and the C function might be completely changed very soon. C****************************************************************** C C****************************************************************** C Version: 1.1 C Author: Josh Grant C Date: February 16th, 2001 C Modifications: Added two arguments to the function. Now the C subroutine is called with 6 arguments. The last C two were added to store the latitude and longitude C values of the points. Updated the example program C below to reflect the new changes. C****************************************************************** C C****************************************************************** C Subroutine: readncdf_1d C Version: 1.0 C Author: Josh Grant C Date: September 1st, 2000 C Purpose: Reads 1 degree gridded NetCDF file and stores in arrays C****************************************************************** C C DATA IN MATRIX BEGINS IN SOUTHERN HEMISPHERE. 'LAT' IS THE C DIMENSION OF THE VERTICAL WHILE 'LON' IS THE DIMENSION OF THE C HORIZONTAL. MATRICES U(LAT, LON) AND V(LAT, LON) BEGIN AT THE C UPPER LEFT-HAND PORTION OF THE MATRIX (REPRESENTING THE SOUTHWESTERN C CORNER OF THE WORLD MAP) AND END AT THE LOWER RIGHT-HAND PORTION OF C THE MATRIX (REPRESENTING THE NORTHEASTERN CORNER OF THE WORLD MAP) C C C THERE ARE SEVEN INPUTS FOR THIS FUNCTION; C C input Name of the NetCDF file you wish to convert to ASCII C u Holds the u wind component values as a 2D array C v Holds the v wind component values as a 2D array C lat_num Holds the number of latitudes that were read C lats Holds the latitude values in an array C lons Holds the longitude values in an array C missing the value you would like all missing values set to C C Example: Reads the file and prints the u and v component to the screen C------------------------------------------ C PROGRAM DRIVER C C character*31 input C real u(360, 180), v(360, 180), lats(180), lons(360) C real missing C integer i, j, LAT, LON, latsize C C LON = 360 C input = 'ndir/gcv_NSCAT_1997077.nc' C missing = 9999.0 C C CALL readncdf_1d(input, u, v, latsize, lats, lons, missing) C C DO i = 1, latsize C DO j = 1, LON C PRINT 100,lats(i), ',', lons(j), ' = (', u(j,i), C + ', ', v(j,i), ')' C END DO C END DO C C 100 FORMAT(F6.2,A1,F7.2,A4,F8.2,A2,F8.2,A1) C C END C------------------------------------------- C C When compiling entire project you may need to add the following: C -L/usr/local/netcdf/lib32 -lnetcdf C or if using object 64 code C -L/usr/local/netcdf/lib64 -lnetcdf subroutine readncdf_1d(input, u, v, lat_num, lats, lons, missing) INCLUDE '/usr/local/include/netcdf.inc' PARAMETER(LAT = 180) PARAMETER(LON = 360) character*31 input, latname(1) integer ncid, u_id, v_id, RCODE, latid, latsize(1), lat_num integer lat_id, lon_id, lonsize(1) integer*2 u_temp(LON, LAT), v_temp(LON, LAT), u_miss(1), v_miss(1) real u_sfactor(1), v_sfactor(1), u_miss_real, v_miss_real real u(LON, LAT), v(LON, LAT), lats(LAT), lons(LON) real missing integer start(2), count(2), lat_lon_start(1) integer i, j data start /1, 1/ data count /LON, LAT/ data lat_lon_start /1/ data lonsize /LON/ C OPENS NETCDF FOR READING AND OTHER TWO FILES FOR WRITING. ncid = NCOPN(input, NCNOWRIT, RCODE) u_id = NCVID(ncid, 'u', RCODE) v_id = NCVID(ncid, 'v', RCODE) lat_id = NCVID(ncid, 'lat', RCODE) lon_id = NCVID(ncid, 'lon', RCODE) latid = ncdid(ncid, 'lat', RCODE) call ncdinq(ncid, latid, latname(1), latsize(1), RCODE) count(2) = latsize(1) lat_num = latsize(1) C GETS THE lat and lon VALUES FROM THE OPENED FILE. call NCVGT(ncid, lat_id, lat_lon_start, latsize, lats, RCODE) call NCVGT(ncid, lon_id, lat_lon_start, lonsize, lons, RCODE) C GETS THE U AND V VALES FROM THE OPENED FILE. call NCVGT(ncid, u_id, start, count, u_temp, RCODE) call NCVGT(ncid, v_id, start, count, v_temp, RCODE) C CONVERTS ARRAY VALUES INTO REAL NUMBERS do i = 1, LON do j = 1, LAT u(i,j) = real(u_temp(i,j)) v(i,j) = real(v_temp(i,j)) end do end do C RETRIEVES THE SCALE FACTOR AND THEN MULTIPLIES THE ELEMENTS C (WHICH AREN'T MISSING) BY THE SCALE FACTOR call NCAGT(ncid, u_id, 'scale_factor', u_sfactor(1), RCODE) call NCAGT(ncid, v_id, 'scale_factor', v_sfactor(1), RCODE) call NCAGT(ncid, u_id, 'missing_value', u_miss(1), RCODE) call NCAGT(ncid, v_id, 'missing_value', v_miss(1), RCODE) u_miss_real = real(u_miss(1)) v_miss_real = real(v_miss(1)) do j = 1, lat_num do i = 1, LON if (u(i,j) .ne. u_miss_real) then u(i,j) = u(i,j) * u_sfactor(1) else u(i,j) = missing end if if (v(i,j) .ne. v_miss_real) then v(i,j) = v(i,j) * v_sfactor(1) else v(i,j) = missing end if end do end do call NCCLOS(ncid, RCODE) end