Converting NARR Winds Into SWAN Format



Test files:

oman_uv.out



The specifications for the required SWAN input format were given in Kahatu's email from July 6, 2009:

Attached is a Fortran code I wrote to move from *.cdl to SWAN format.

The "write" statements are the key elements here - everything else is for piecing out the winds in the global hindcast that were over the GoM and then converting them to real numbers.

Outer loop is time. Inner loop is latitude from low to high (it's reversed in this code since the hindcast was written from north pole to south pole). Each line is U (positive east) or V (positive north), written from westernmost longitude to easternmost longitude. The format statement is just so I can have the entire range of longitudes on one line in the file.

As you can see, for each time step, all U's are written for the grid, followed by all V's. We then move to the next time step.

The time value is read it to the model from the input file. It doesn't get read in from the wind data. I specify the time extent of the winds and the time step there, and it reads it in from the wind file accordingly, interpolating as necessary to the computational time step.


The attached Fortran program is:

          program readwind
c
c         three damn guesses what this thing does
c
c         jmk 9/25/07
c
          parameter(nlon=192,nlat=94,ntime=1459)
          dimension nwindu(nlon,nlat,ntime),
     1              nwindv(nlon,nlat,ntime)
          dimension uw(nlon,nlat,ntime),vw(nlon,nlat,ntime)
c
c         open the U.cdl file
c
          open(10,file='u10.cdl')
          open(11,file='v10.cdl')
c
c         read a bunch of blank lines - data starts at
c         line 55
c
          do i=1,54
           write(*,*) i
           read(10,*)
           read(11,*)
          enddo
c
c         read in winds and look for the useful stuff
c
          do k=1,ntime
           do j=1,nlat
            do i=1,nlon
             read(10,*) nwindu(i,j,k)
             read(11,*) nwindv(i,j,k)
c             write(45,*) i,j,k,nwindu(i,j,k)
            enddo
           enddo
          enddo
c
c         useful stuff
c
          do i=140,151
           do j=31,39
            do k=1,1459
             ik=i-139
             jk=j-30
             kk=k
             uw(ik,jk,kk)=(float(nwindu(i,j,k))*0.01)+225.45
             vw(ik,jk,kk)=(float(nwindv(i,j,k))*0.01)+225.45
            enddo
           enddo
          enddo
          nigom=ik
          njgom=jk
          nkgom=kk
c
c        write it out
c
         open(20,file='gomwind.wnd')
         do k=1,nkgom
          do j=njgom,1,-1
           write(20,34)(uw(i,j,k),i=1,nigom)
          enddo
          do j=njgom,1,-1
           write(20,34)(vw(i,j,k),i=1,nigom)
          enddo
         enddo
34       format(500f10.5)
c
c        go now
c
         stop
         end

The Fortan-esque output can be handled/mangled via:

ncks -s '%10.5f\n' -C -v Uwind test.nc >& test.txt

which will provide output like the following:

   1.62087
   1.55334
   1.48874
   1.42873
   1.37572
   1.33052
   1.29274
...