[Dart-dev] [3297] DART/trunk/ncep_obs/prep_bufr/blk_ublk: Latest version of the block/ unblock program; it is now a simple, single

nancy at subversion.ucar.edu nancy at subversion.ucar.edu
Wed Apr 9 15:09:52 MDT 2008


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20080409/0b2be6f5/attachment.html
-------------- next part --------------
Modified: DART/trunk/ncep_obs/prep_bufr/blk_ublk/README_cwordsh
===================================================================
--- DART/trunk/ncep_obs/prep_bufr/blk_ublk/README_cwordsh	2008-04-09 19:36:41 UTC (rev 3296)
+++ DART/trunk/ncep_obs/prep_bufr/blk_ublk/README_cwordsh	2008-04-09 21:09:52 UTC (rev 3297)
@@ -1,51 +1,52 @@
-This file describes how to compile and run the NCEP cwordsh utility,
+This file explains how to compile and run the NCEP cwordsh utility,
 which is described in detail at
-http://www.ncep.noaa.gov/NCO/DMQAB/Decoders/BUFRLIB/cwordsh/,
+http://www.nco.ncep.noaa.gov/sib/decoders/BUFRLIB/cwordsh/,
 and whose usage is governed by the terms and conditions of the disclaimer
-viewable at http://www.nws.noaa.gov/disclaimer.html
+http://www.nws.noaa.gov/disclaimer.html
 
-1.  **This step has alread been completed if the "install.sh" script
-    has been run. (See the README file up one directory) ** 
-    If you haven't already done so, download, compile, and build the NCEP
+1.  If you haven't already done so, download, compile, and build the NCEP
     BUFRLIB software on the same system upon which you plan to run cwordsh.
     The BUFRLIB software is available via the web page
-    http://www.ncep.noaa.gov/NCO/DMQAB/Decoders/BUFRLIB/
+    http://www.nco.ncep.noaa.gov/sib/decoders/BUFRLIB/
     
-2.  Edit the file "cwordsh.make" and set the variable 
-    BUFRLIB to point to the location of the
-    compiled BUFRLIB archive library from step #1.  **This variable has
-    been preset to point to the archive library created during the 
-    execution of the "install.sh" script. **
+2.  Set the environment variable BUFRLIB to point to the location of the
+    compiled BUFRLIB archive library from step #1.
 
-2.  Edit the file "cwordsh.make" and set the variable CPLAT to the name of
-    the type of system upon which you plan to run.  This variable is used to
-    set the names of the FORTRAN and C compilers for the system as
-    well as to appropriately initialize the FORTRAN <-> C interface, which
-    is not standard across the multitude of existing UNIX platform types.
-    For example, some systems require a trailing underscore to be appended
-    to a FORTRAN routine name when calling it from a C function, while others 
-    require the name to be capitalized, and still others require no special
-    changes at all.  The file "cwordsh.make" contains pre-included logic for
-    several of the more popular system types such as sgi, aix, hp, etc.,
-    in which case the variable CPLAT needs only to be set to the relevant type.
-    However, if you are working on a system which isn't already represented in
-    the file, then you need to add the appropriate logic for your system
-    so that the necessary FORTRAN routines can be properly called from within C,
-    and you also need to supply the names of the FORTRAN and C compilers for
-    your local system.  
+3.  Compile the source file "cwordsh.f" and link it to BUFRLIB in order
+    to create the executable file "cwordsh.x".  In general, no special
+    compiler flags are required, so something similar to the following:
 
-3.  Run the command "./cwordsh.make" to build the executable "cwordsh.x"
-    within the current directory.  If you wish for the executable to be
-    written out to a different location, you may modify the variable CWRD
-    within the "cwordsh.make" script.
+    $FC -o cwordsh.x cwordsh.f $BUFRLIB
 
-4.  The script "cwordsh" will now run the "cwordsh.x" executable that was
-    created in step #3.  The script takes three arguments, the first of which
-    is the string "block" or "unblk", depending on whether the script is to
-    be used to block or unblock a file, respectively.  The second argument
-    is the input file to be blocked or unblocked, and the third argument is
-    the name of the output file that is the final unblocked or blocked copy
-    of the input file, depending on the case!  Note that, if you previously
-    modified the variable CWRD within the script "cwordsh.make"
-    (within step #3), then it must be likewise modified within this
-    "cwordsh" script as well!
+    where $FC points to the local FORTRAN 77 compiler, should suffice for
+    most systems.
+    
+4.  Set the environment variable CWRD to point to the directory containing
+    the compiled "cwordsh.x" executable from step #3.
+
+5.  The script "cwordsh" will now run the "cwordsh.x" executable that was
+    created in step #3.  The script reads three strings from standard input; 
+    the first is the string "block" or "unblk" to block or unblock a file, 
+    respectively.  The second string is the input filename and the third
+    string is the output filename.  e.g:
+
+    echo 'block' > in
+    echo 'prepqm.in' >> in
+    echo 'prepqm.out' >> in
+    ./cwordsh.x < in
+
+    this also works (but it's important that the last EOF start in
+    column 1 - no whitespace is allowed in front of it):
+
+    ./cwordsh.x <<EOF
+    block
+    prepqm.in
+    prepqm.out
+    EOF
+
+    NOTE: in spite of the wording of the original documentation, this
+    program does not take command line arguments (e.g. this does not work:
+    'cwordsh.x block in out')  plus, each string must be on a separate line.
+    this does *not* work either:  echo 'block in out' | ./cwordsh.x
+
+    

Added: DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.f
===================================================================
--- DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.f	                        (rev 0)
+++ DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.f	2008-04-09 21:09:52 UTC (rev 3297)
@@ -0,0 +1,118 @@
+C$$$  MAIN PROGRAM DOCUMENTATION BLOCK
+C  
+C MAIN PROGRAM:  CWORDSH
+C   PRGMMR: J. ATOR          ORG: NP12        DATE: 2005-11-29
+C
+C ABSTRACT: CONVERTS BINARY BYTE STREAM BUFR FILES BACK AND FORTH
+C   FROM A FORTRAN BLOCKED FORMAT.
+C
+C PROGRAM HISTORY LOG:
+C 1999-08-19  J. WOOLLEN  ORIGINAL VERSION FOR IMPLEMENTATION
+C 2004-03-19  D. KEYSER   INCREASED SIZE OF ARRAY MBAY FROM 3000 WORDS
+C                         TO 5000 WORDS TO ALLOW IT TO PROCESS BUFR
+C                         MESSAGES WITH UP TO 20K BYTES
+C 2005-11-29  J. ATOR     REWRITTEN USING BUFRLIB C I/O LOGIC TO HANDLE
+C                         ANY INPUT BUFR FILES (INCLUDING FILES WHICH
+C                         CONTAIN EXTRANEOUS CHARACTERS (E.G. BULLETIN
+C                         HEADERS) AND/OR WHICH PREVIOUSLY REQUIRED THE
+C                         USE OF APPLICATION PROGRAM GRABBUFR) AND TO
+C                         REMOVE DIRECT LINKS TO BUFRLIB COMMON BLOCKS
+C
+C USAGE:
+C   INPUT FILES:
+C     UNIT 05  - STANDARD INPUT (OPERATION TYPE, INPUT FILENAME,
+C                OUTPUT FILENAME)
+C
+C   OUTPUT FILES: 
+C     UNIT 06  - STANDARD OUTPUT PRINT
+C     UNIT 51  - BLOCKED FORTRAN FILE OUTPUT FOR BLOCKING OPERATION
+C
+C   SUBPROGRAMS CALLED:
+C     LIBRARY:
+C       BUFRLIB  - CCBFL    COBFL    CRBMG    CWBMG    PADMSG
+C
+C ATTRIBUTES:
+C   LANGUAGE: FORTRAN 77
+C   MACHINE:  IBM SP
+C
+C$$$
+
+      program cwordsh
+
+      parameter(mxbufr=150000)
+      parameter(mxbufrd4=mxbufr/4)
+
+      character*80 bfile,ufile
+      character*8  cword
+      character*1  bufr(mxbufr)
+      dimension    mbay(mxbufrd4)
+      equivalence  (bufr(1),mbay(1))
+ 
+c     Read and process the input arguments.
+ 
+      read(5,'(a)') cword
+      if(cword.eq.'block') then
+         read(5,'(a)') ufile
+         read(5,'(a)') bfile
+      elseif(cword.eq.'unblk') then
+         read(5,'(a)') bfile
+         read(5,'(a)') ufile
+      else
+         print*,'cword must be block or unblk'
+         stop
+      endif
+ 
+c     Open the input and output files.
+
+      if(cword.eq.'block') then
+         print*,'blocking from: ',ufile
+         print*,'           to: ',bfile
+         call cobfl(ufile,'r')
+         open(51,file=bfile,form='unformatted')
+      else
+         print*,'unblocking from: ',bfile
+         print*,'             to: ',ufile
+         call cobfl(bfile,'r')
+         call cobfl(ufile,'w')
+      endif
+
+c     Read the next message from the input file.
+
+      call crbmg(bufr,mxbufr,nbyt,ierr)
+      do while(ierr.ge.0)
+        if(ierr.eq.0) then
+
+c         Pad the end of the message with zeroed-out bytes up to the
+c         next 8-byte boundary.
+
+          call padmsg(mbay,mxbufrd4,npbyt)
+          ntbyt = nbyt + npbyt
+
+c         Write the message plus padding to the output file...
+
+          if(cword.eq.'block') then
+
+c           using a FORTRAN write.
+
+            write(51) (bufr(i),i=1,ntbyt)
+          else
+
+c           using a C write.
+
+            call cwbmg(bufr,ntbyt,ierw)
+            if(ierw.ne.0) print*,'return value from cwbmg was ',ierw
+          endif
+        else
+          print*,'return value from crbmg was ',ierr,
+     .           '; message not written to output'
+        endif
+        call crbmg(bufr,mxbufr,nbyt,ierr)
+      enddo
+
+c     Close the input and output files.
+
+      call ccbfl
+      if(cword.eq.'block') close(51)
+ 
+      stop
+      end

Deleted: DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.make
===================================================================
--- DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.make	2008-04-09 19:36:41 UTC (rev 3296)
+++ DART/trunk/ncep_obs/prep_bufr/blk_ublk/cwordsh.make	2008-04-09 21:09:52 UTC (rev 3297)
@@ -1,208 +0,0 @@
- 
-#  ------------------------------------------------------------------------
-#  This script will make cwordsh.x which FORTRAN "blocks" or "unblocks" 
-#  BUFR files on a number of standard computing platforms. Stictly speaking,
-#  real BUFR files are "unblocked". That is, they contain a byte stream
-#  containing only allowable BUFR constructs.
-#
-#  On some platforms it is advantagous to use the FORTRAN
-#  blocked structure for I/O efficiency, and on some platforms, when
-#  using FORTRAN I/O, the unblocked structure is FORTRAN UN-readable.
-#
-#  NOTE: The script is set up to run in the Bourne shell. If you are a
-#  C-shell user, enter 'sh ./cwordsh'.
-#  ------------------------------------------------------------------------
-
-#  ------------------------------------------------------------------------
-# <next few lines under version control, do not edit>
-# $URL$
-# $Id$
-# $Revision$
-# $Date$
-#  ------------------------------------------------------------------------
- 
-set -eua
- 
-#  ------------------------------------------------------------------------
-#  CPLAT - platform type (sgi,linux,aix,sun,hp,cray,etc.)
-#  ------------------------------------------------------------------------
- 
-CPLAT=macosx
-BUFRLIB=../lib/bufrlib.a
- 
-#  different platforms use different link name protocols
-#  -----------------------------------------------------
- 
-if [ $CPLAT = sgi ]
-then
-   openrb=openrb_
-   openwb=openwb_
-   crdbfr=crdbufr_
-   cwrbfr=cwrbufr_
-   lenmsg=lenm_
-   cc=cc; ff=f77
-elif [ $CPLAT = linux ]
-then
-   openrb=openrb_
-   openwb=openwb_
-   crdbfr=crdbufr_
-   cwrbfr=cwrbufr_
-   lenmsg=lenm_
-   cc=gcc; ff=g77
-elif [ $CPLAT = intel ]
-then
-   openrb=openrb_
-   openwb=openwb_
-   crdbfr=crdbufr_
-   cwrbfr=cwrbufr_
-   lenmsg=lenm_
-   cc=icc; ff=ifort 
-elif [ $CPLAT = aix ]
-then
-   openrb=openrb
-   openwb=openwb
-   crdbfr=crdbufr
-   cwrbfr=cwrbufr
-   lenmsg=lenm
-   cc=cc; ff=f77
-elif [ $CPLAT = sun ]
-then
-   openrb=openrb_
-   openwb=openwb_
-   crdbfr=crdbufr_
-   cwrbfr=cwrbufr_
-   lenmsg=lenm_
-   cc=cc; ff=f77
-elif [ $CPLAT = hp  ]
-then
-   openrb=openrb
-   openwb=openwb
-   crdbfr=crdbufr
-   cwrbfr=cwrbufr
-   lenmsg=lenm
-   cc=cc; ff=f77
-elif [ $CPLAT = macosx  ]
-then
-   openrb=openrb_
-   openwb=openwb_
-   crdbfr=crdbufr_
-   cwrbfr=cwrbufr_
-   lenmsg=lenm_
-   cc=gcc; ff=gfortran
-elif [ $CPLAT = cray ]
-then
-   openrb=OPENRB
-   openwb=OPENWB
-   crdbfr=CRDBUFR
-   cwrbfr=CWRBUFR
-   lenmsg=LENM
-   cc=cc; ff=f90
-fi
- 
-#  compile the c part of the program
-#  ---------------------------------
- 
-cat <<eof>ccwords.c; $cc -c ccwords.c
-#include <stdio.h>
-FILE *pb;
-void $openrb (ufile) char *ufile; { pb = fopen( ufile , "rb" ); }
-void $openwb (ufile) char *ufile; { pb = fopen( ufile , "wb" ); }
-int  $crdbfr (bufr)
-int  *bufr;
-{  int  nwrd; int  nb;
-   nb = sizeof(bufr);
-   if((nwrd=fread(bufr,nb,8/nb,pb))!=0)
-   {  nwrd = $lenmsg(bufr);
-      fread(bufr+8/nb,nb,nwrd-8/nb,pb);
-      return nwrd;
-   }
-   else
-      return -1;
-}
-int  $cwrbfr (bufr)
-int  *bufr;
-{  int  nwrd; int  nb;
-   nb = sizeof(bufr);
-   nwrd = $lenmsg(bufr);
-   fwrite(bufr,nb,nwrd,pb);
-}
-eof
- 
-#  compile the fortran part of the program
-#  ---------------------------------------
- 
-cat <<eof>fcwords.f; $ff -c fcwords.f 
-      program fcwords
-      common /hrdwrd/ nb,nbitw,nrev,iord(8)
-      character*80 bfile,ufile
-      character*8  cword
-      character*1  zbyte
-      dimension    mbay(3000),iufile(20)
-      equivalence  (zbyte,izero)
-      equivalence  (ufile,iufile)
-      integer      crdbufr,cwrbufr
-      data         izero/0/
-
-      do i=1,80
-      ufile(i:i) = zbyte
-      enddo
- 
-      read(5,'(a)') cword
-      if(cword.eq.'block') then
-         read(5,'(a)') ufile
-         read(5,'(a)') bfile
-      elseif(cword.eq.'unblk') then
-         read(5,'(a)') bfile
-         read(5,'(a)') ufile
-      else
-         print*,'cword must be block or unblk'
-         call exit(8)
-      endif
-
-      do i=1,80
-      if(ufile(i:i).eq.' ') ufile(i:i) = zbyte
-      enddo
- 
-      open(8,file=bfile,form='unformatted')
-      call wrdlen
-
-      if(cword.eq.'block') then
-         print*,'blocking ',ufile,' to ',bfile
-         call openrb(iufile)
-         do while(crdbufr(mbay).ge.0)
-         write(8) (mbay(i),i=1,lenm(mbay))
-         enddo
-      endif
- 
-      if(cword.eq.'unblk') then
-         print*,'unblocking ',bfile,' to ',ufile
-         call openwb(iufile)
-1        read(8,end=2)(mbay(i),i=1,8/nb),(mbay(i),i=1+8/nb,lenm(mbay))
-         iwt = cwrbufr(mbay)
-         goto 1
-2        continue
-      endif
- 
-      stop
-      end
-c-----------------------------------------------------------------------
-      function lenm(mbay)
-      common /hrdwrd/ nb,nbitw,nrev,iord(8)
-      dimension mbay(*)
-      lenm = (1+iupb(mbay,5,24)/8)*8/nb
-      return
-      end
-c-----------------------------------------------------------------------
-eof
- 
-#  link and load the executable
-#  ----------------------------
-
-CWRD=.
- 
-$ff -o $CWRD/cwordsh.x fcwords.o ccwords.o $BUFRLIB
-
-#  clean up
-#  --------
-
-rm -f fcwords.[fo] ccwords.[co]


More information about the Dart-dev mailing list