WAVEWATCH III  beta 0.0.1
ww3_trck.F90
Go to the documentation of this file.
1 
5 !
6 #include "w3macros.h"
7 
8 !/ ------------------------------------------------------------------- /
15 PROGRAM w3trck
16  !/
17  !/ +-----------------------------------+
18  !/ | WAVEWATCH III NOAA/NCEP |
19  !/ | H. L. Tolman |
20  !/ | FORTRAN 90 |
21  !/ | Last update : 05-Mar-2014 |
22  !/ +-----------------------------------+
23  !/
24  !/ 14-Jan-1999 : Final FORTRAN 77 ( version 1.18 )
25  !/ 21-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
26  !/ 25-Jan-2001 : Flat grid version ( version 2.06 )
27  !/ 20-Aug-2003 : Sequential file version ( version 3.04 )
28  !/ 29-Jun-2006 : Adding file name preamble. ( version 3.09 )
29  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
30  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
31  !/ (W. E. Rogers & T. J. Campbell, NRL)
32  !/ 05-Mar-2014 : Now calls W3SETG for pointer def. ( version 4.18 )
33  !/
34  !/ Copyright 2009 National Weather Service (NWS),
35  !/ National Oceanic and Atmospheric Administration. All rights
36  !/ reserved. WAVEWATCH III is a trademark of the NWS.
37  !/ No unauthorized use without permission.
38  !/
39  ! 1. Purpose :
40  !
41  ! Convert direct access track output file to free-format
42  ! readable sequential file.
43  !
44  ! 2. Method :
45  !
46  ! Info read from track_o.ww3, written to track.ww3.
47  !
48  ! 3. Parameters :
49  !
50  ! 4. Subroutines used :
51  !
52  ! Name Type Module Description
53  ! ----------------------------------------------------------------
54  ! W3NMOD Subr. W3GDATMD Set number of model.
55  ! W3NOUT Subr. W3ODATMD Set number of model for output.
56  ! ----------------------------------------------------------------
57  !
58  ! 5. Called by :
59  !
60  ! None, stand-alone program.
61  !
62  ! 6. Error messages :
63  !
64  ! 7. Remarks :
65  !
66  ! 8. Structure :
67  !
68  ! See source code.
69  !
70  ! 9. Switches :
71  !
72  ! !/S Enable subroutine tracing.
73  !
74  ! 10. Source code :
75  !
76  !/ ------------------------------------------------------------------- /
77  USE w3gdatmd, ONLY : w3nmod, w3setg, flagll, xfr
78  USE w3odatmd, ONLY : w3nout, w3seto, fnmpre
79  USE w3servmd, ONLY : itrace, nextln, extcde
80 #ifdef W3_S
81  USE w3servmd, ONLY : strace
82 #endif
83  USE w3timemd, ONLY : stme21
84  !
85  USE w3odatmd, ONLY: ndso, ndse, ndst
86  use constants, only: file_endian
87  !
88  IMPLICIT NONE
89  !/
90  !/ ------------------------------------------------------------------- /
91  !/ Local parameters
92  !/
93  CHARACTER*34, PARAMETER :: &
94  idtst = 'WAVEWATCH III TRACK OUTPUT SPECTRA'
95  !
96  INTEGER :: ndsi, ndsinp, &
97  ndsout, ndstrc, ntrace, nk, nth, &
98  nspec, ierr, mk, mth, &
99  nrec, iloc, ispec, time(2), ttst(2), &
100  ilast, nzero, ik, ith, iwzero, ich, &
101  iwdth, j
102 #ifdef W3_S
103  INTEGER, SAVE :: ient = 0
104 #endif
105  INTEGER :: lineln = 81
106  REAL :: th1, dth, x, y, dw, cx, cy, wx, wy, &
107  ust, as, value
108  REAL :: scale = 0.001
109  REAL :: factor
110  REAL, ALLOCATABLE :: sig(:), dsip(:), spec(:,:)
111  CHARACTER :: comstr*1, idstr*34, tststr*3, &
112  stime*23, string*81, empty*81, &
113  part*9, zeros*9, trckid*32
114  !
115  DATA empty(01:40) / ' ' /
116  DATA empty(41:81) / ' ' /
117  !/
118  !/ ------------------------------------------------------------------- /
119  !/
120  !
121  ! 1.a Initialize data structure
122  !
123  CALL w3nmod ( 1, 6, 6 )
124  CALL w3setg ( 1, 6, 6 )
125  CALL w3nout ( 6, 6 )
126  CALL w3seto ( 1, 6, 6 )
127  !
128  ! 1.b IO set-up.
129  !
130  ndsi = 10
131  ndsinp = 11
132  ndsout = 51
133  !
134  ndstrc = 6
135  ntrace = 10
136  CALL itrace ( ndstrc, ntrace )
137  !
138 #ifdef W3_S
139  CALL strace ( ient, 'W3TRCK' )
140 #endif
141  !
142  WRITE (ndso,900)
143  !
144  j = len_trim(fnmpre)
145  OPEN (ndsi,file=fnmpre(:j)//'ww3_trck.inp',status='OLD', &
146  err=805,iostat=ierr)
147  READ (ndsi,'(A)',END=806,ERR=807) comstr
148  IF (comstr.EQ.' ') comstr = '$'
149  WRITE (ndso,901) comstr
150  !
151  CALL nextln ( comstr , ndsi , ndse )
152  READ (ndsi,*,END=806,ERR=807) NK, nth
153  nspec = nk * nth
154  WRITE (ndso,902) nk, nth
155  !
156  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157  ! 2. Open and test input data file
158  !
159  WRITE (ndso,920)
160  !
161  OPEN (ndsinp,file=fnmpre(:j)//'track_o.ww3',form='UNFORMATTED', convert=file_endian, &
162  status='OLD',err=800,iostat=ierr)
163  READ (ndsinp,err=801,iostat=ierr) idstr, flagll, mk, mth, xfr
164  !
165  IF ( flagll ) THEN
166  factor = 1.
167  ELSE
168  factor = 1.e-3
169  END IF
170  !
171  IF ( idstr .NE. idtst ) GOTO 810
172  IF ( nk.NE.mk .OR. nth.NE.mth ) GOTO 811
173 
174  ALLOCATE ( sig(mk), dsip(mk), spec(mk,mth) )
175  !
176  READ (ndsinp,err=801,iostat=ierr) th1, dth, sig, dsip
177  !
178  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179  ! 3. Open output file and prepare
180  !
181  WRITE (ndso,930)
182  !
183  OPEN (ndsout,file=fnmpre(:j)//'track.ww3', &
184  form='FORMATTED',err=802,iostat=ierr)
185  !
186  WRITE (ndsout,980,err=803,iostat=ierr) idstr
187  WRITE (ndsout,981,err=803,iostat=ierr) mk, mth, th1, dth
188  WRITE (ndsout,982,err=803,iostat=ierr) sig
189  WRITE (ndsout,983,err=803,iostat=ierr) dsip
190  !
191  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
192  ! 4. Process data
193  !
194  iloc = 0
195  ispec = 0
196  READ (ndsinp,END=444, ERR=801,IOSTAT=IERR) ttst
197  backspace(ndsinp)
198  WRITE (ndso,940)
199  !
200 400 CONTINUE
201  !
202  ! 4.a Read/write basic data
203  !
204  READ (ndsinp,END=444, ERR=801,IOSTAT=IERR) TIME, X, Y, TSTSTR, &
205  trckid
206  IF ( flagll ) THEN
207  WRITE (ndsout,984,err=803,iostat=ierr) &
208  time, factor*x, factor*y, tststr, trckid
209  ELSE
210  WRITE (ndsout,974,err=803,iostat=ierr) &
211  time, factor*x, factor*y, tststr, trckid
212  END IF
213  !
214  IF ( time(1).EQ.ttst(1) .AND. time(2).EQ.ttst(2) ) THEN
215  iloc = iloc + 1
216  IF ( tststr .EQ. 'SEA' ) ispec = ispec + 1
217  ENDIF
218  IF ( time(1).NE.ttst(1) .OR. time(2).NE.ttst(2) ) THEN
219  CALL stme21 ( ttst , stime )
220  WRITE (ndso,941) stime, iloc, ispec
221  iloc = 1
222  ispec = 0
223  IF ( tststr .EQ. 'SEA' ) ispec = ispec + 1
224  ttst(1) = time(1)
225  ttst(2) = time(2)
226  ENDIF
227  !
228  ! 4.b Check if sea point
229  !
230  IF ( tststr .NE. 'SEA' ) GOTO 400
231  !
232  ! 4.c Read all data
233  !
234  READ (ndsinp,err=801,iostat=ierr) dw, cx, cy, wx, wy, ust, as, &
235  spec
236  IF ( ust .LT. 0. ) ust = -1.0
237  !
238  ! 4.d Write the basic stuff
239  !
240  WRITE (ndsout,985,err=803,iostat=ierr) &
241  dw, cx, cy, wx, wy, ust, as, scale
242  !
243  ! 4.e Start of integer packing
244  !
245  string = empty
246  ilast = 0
247  nzero = 0
248  !
249  ! 4.e.1 Loop over spectrum
250  !
251  DO ik=1, nk
252  DO ith=1, nth
253  VALUE = max( 0.1 , 1.1*spec(ik,ith)/scale )
254  iwdth = 2 + max( 0 , int( alog10(VALUE) ) )
255  !
256  ! 4.e.2 Put value in string and test overflow
257  !
258  IF ( iwdth .GT. 9 ) THEN
259  iwdth = 9
260  part = ' 99999999'
261  ELSE
262  WRITE (part,987) nint(spec(ik,ith)/scale)
263  IF ( part(11-iwdth:11-iwdth) .EQ. ' ' ) &
264  iwdth = iwdth - 1
265  ENDIF
266  !
267  ! 4.e.3 It's a zero, wait with writing
268  !
269  IF ( part(8:9) .EQ. ' 0' ) THEN
270  nzero = nzero + 1
271  ELSE
272  !
273  ! 4.e.4 It's not a zero, write unwritten zeros
274  !
275  IF ( nzero .NE. 0 ) THEN
276  IF ( nzero .EQ. 1 ) THEN
277  zeros = ' 0'
278  iwzero = 2
279  ELSE
280  WRITE (zeros,'(I7,A2)') nzero, '*0'
281  iwzero = 4
282  DO
283  ich = 10 - iwzero
284  IF ( zeros(ich:ich) .NE. ' ' ) THEN
285  iwzero = iwzero + 1
286  ELSE
287  EXIT
288  ENDIF
289  END DO
290  ENDIF
291  IF ( ilast+iwzero .GT. lineln ) THEN
292  WRITE (ndsout,986,err=803,iostat=ierr) &
293  string(2:ilast)
294  string = empty
295  ilast = 0
296  ENDIF
297  string(ilast+1:ilast+iwzero) = &
298  zeros(10-iwzero:9)
299  ilast = ilast + iwzero
300  nzero = 0
301  ENDIF
302  !
303  ! 4.e.5 It's not a zero, put in string
304  !
305  IF ( ilast+iwdth .GT. lineln ) THEN
306  WRITE (ndsout,986,err=803,iostat=ierr) &
307  string(2:ilast)
308  string = empty
309  ilast = 0
310  ENDIF
311  !
312  string(ilast+1:ilast+iwdth) = part(10-iwdth:9)
313  ilast = ilast + iwdth
314  !
315  ENDIF
316  !
317  END DO
318  END DO
319  !
320  ! ..... End of loop over spectrum (4.e.1)
321  !
322  ! 4.e.6 Write trailing zeros
323  !
324  IF ( nzero .NE. 0 ) THEN
325  IF ( nzero .EQ. 1 ) THEN
326  zeros = ' 0'
327  iwzero = 2
328  ELSE
329  WRITE (zeros,'(I7,A2)') nzero, '*0'
330  iwzero = 4
331  DO
332  ich = 10 - iwzero
333  IF ( zeros(ich:ich) .NE. ' ' ) THEN
334  iwzero = iwzero + 1
335  ELSE
336  EXIT
337  ENDIF
338  END DO
339  ENDIF
340  IF ( ilast+iwzero .GT. lineln ) THEN
341  WRITE (ndsout,986,err=803,iostat=ierr) &
342  string(2:ilast)
343  string = empty
344  ilast = 0
345  ENDIF
346  string(ilast+1:ilast+iwzero) = zeros(10-iwzero:9)
347  ilast = ilast + iwzero
348  nzero = 0
349  ENDIF
350  !
351  ! 4.e.7 Write last line
352  !
353  IF ( ilast .NE. 0 ) THEN
354  WRITE (ndsout,986,err=803,iostat=ierr) string(2:ilast)
355  ENDIF
356  !
357  ! ... Loop back to top
358  !
359  GOTO 400
360  !
361  ! 4.f All data done, write last batch info
362  !
363 444 CONTINUE
364  !
365  CALL stme21 ( ttst , stime )
366  WRITE (ndso,941) stime, iloc, ispec
367  !
368  GOTO 888
369  !
370  ! Escape locations read errors :
371  !
372 800 CONTINUE
373  WRITE (ndse,1000) ierr
374  CALL extcde ( 1 )
375  !
376 801 CONTINUE
377  WRITE (ndse,1001) ierr
378  CALL extcde ( 2 )
379  !
380 802 CONTINUE
381  WRITE (ndse,1002) ierr
382  CALL extcde ( 3 )
383  !
384 803 CONTINUE
385  WRITE (ndse,1003) ierr
386  CALL extcde ( 4 )
387  !
388 805 CONTINUE
389  WRITE (ndse,1004) ierr
390  CALL extcde ( 5 )
391  !
392 806 CONTINUE
393  WRITE (ndse,1005) ierr
394  CALL extcde ( 6 )
395  !
396 807 CONTINUE
397  WRITE (ndse,1006) ierr
398  CALL extcde ( 7 )
399  !
400 810 CONTINUE
401  WRITE (ndse,1010) idstr, idtst
402  CALL extcde ( 5 )
403  !
404 811 CONTINUE
405  WRITE (ndse,1011) mk, mth, nk, nth
406  CALL extcde ( 6 )
407  !
408 888 CONTINUE
409  !
410  WRITE (ndso,999)
411  !
412  ! Formats
413  !
414 900 FORMAT (/15x,' *** WAVEWATCH III Track output post.*** '/ &
415  15x,'==============================================='/)
416 901 FORMAT ( ' Comment character is ''',a,''''/)
417 902 FORMAT ( ' Spectral grid size is ',i3,' by ',i3// &
418  ' Opening files : '/ &
419  ' -----------------------------------------------')
420 920 FORMAT ( ' Input file ...')
421 930 FORMAT ( ' Output file ...')
422 940 FORMAT (/' Processing data : '/ &
423  ' -----------------------------------------------')
424 941 FORMAT ( ' ',a,' :',i6,' points and',i6,' spectra.')
425  !
426 980 FORMAT (a)
427 981 FORMAT (2i6,2e13.5)
428 982 FORMAT (7e11.4)
429 983 FORMAT (7e11.4)
430 984 FORMAT (i8.8,i7.6,2f9.3,2x,a3,2x,a32)
431 974 FORMAT (i8.8,i7.6,2(f9.2,'E3'),2x,a3,2x,a32)
432 985 FORMAT (f8.1,2f6.2,2f8.2,f9.5,f7.2,e12.5)
433 986 FORMAT (a)
434 987 FORMAT (i9)
435  !
436 999 FORMAT (/' End of program '/ &
437  ' ========================================='/ &
438  ' WAVEWATCH III Track output '/)
439  !
440 1000 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
441  ' ERROR IN OPENING INPUT DATA FILE'/ &
442  ' IOSTAT =',i5/)
443  !
444 1001 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
445  ' ERROR IN READING FROM INPUT DATA FILE'/ &
446  ' IOSTAT =',i5/)
447  !
448 1002 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
449  ' ERROR IN OPENING OUTPUT DATA FILE'/ &
450  ' IOSTAT =',i5/)
451  !
452 1003 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
453  ' ERROR IN WRITING TO OUTPUT FILE'/ &
454  ' IOSTAT =',i5/)
455  !
456 1004 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
457  ' ERROR IN OPENING INPUT FILE'/ &
458  ' IOSTAT =',i5/)
459  !
460 1005 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
461  ' ERROR IN READING FROM INPUT FILE'/ &
462  ' IOSTAT =',i5/)
463  !
464 1006 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
465  ' ERROR IN OPENING OUTPUT FILE'/ &
466  ' IOSTAT =',i5/)
467  !
468 1010 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
469  ' UNEXPECTED ID STRING IN INPUT : ',a/ &
470  ' SHOULD BE : ',a/)
471  !
472 1011 FORMAT (/' *** WAVEWATCH III ERROR IN W3TRCK : '/ &
473  ' UNEXPECTED SPECTRAL DIMENSIONS : ',2i4/ &
474  ' SHOULD BE : ',2i4/)
475  !/
476  !/ End of W3TRCK ----------------------------------------------------- /
477  !/
478 END PROGRAM w3trck
w3servmd::nextln
subroutine nextln(CHCKC, NDSI, NDSE)
Definition: w3servmd.F90:222
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3servmd
Definition: w3servmd.F90:3
w3trck
program w3trck
Convert direct access track output file to free-format readable sequential file.
Definition: ww3_trck.F90:15
w3odatmd::w3seto
subroutine w3seto(IMOD, NDSERR, NDSTST)
Definition: w3odatmd.F90:1523
w3timemd::stme21
subroutine stme21(TIME, DTME21)
Definition: w3timemd.F90:682
w3odatmd
Definition: w3odatmd.F90:3
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition: CMakeLists.txt:3
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3odatmd::ndso
integer, pointer ndso
Definition: w3odatmd.F90:456
w3gdatmd::w3nmod
subroutine w3nmod(NUMBER, NDSE, NDST, NAUX)
Definition: w3gdatmd.F90:1433
w3gdatmd::xfr
real, pointer xfr
Definition: w3gdatmd.F90:1232
w3odatmd::ndst
integer, pointer ndst
Definition: w3odatmd.F90:456
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3gdatmd
Definition: w3gdatmd.F90:16
constants::file_endian
character(*), parameter file_endian
FILE_ENDIAN Filled by preprocessor with 'big_endian', 'little_endian', or 'native'.
Definition: constants.F90:86
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3odatmd::w3nout
subroutine w3nout(NDSERR, NDSTST)
Definition: w3odatmd.F90:561
w3servmd::itrace
subroutine itrace(NDS, NMAX)
Definition: w3servmd.F90:91
w3timemd
Definition: w3timemd.F90:3
w3gdatmd::flagll
logical, pointer flagll
Definition: w3gdatmd.F90:1219