$!************************************************************************    
$!                                                                            
$!_TITLE CDCOPY - Command file to copy CDROM files to magnetic disk           
$!                                                                            
$!_DESCR                                                                      
$!                                                                            
$!     The CDCOPY command file is to be used by VAX/VMS systems for           
$!     copying data files from CDROM media to VMS magnetic disk media.        
$!     This command file is used in conjunction with the VFS-ISO 9660         
$!     MOUNT field test kit which allows VMS interface with the CDROM         
$!     ISO volume and directory standard.                                     
$!                                                                            
$!     The current VMS interface to CDROMs (VFS field test kit) has           
$!     problems with files that have extended attribute records with          
$!     a print control value of 0. The dcl COPY command, and other            
$!     DCL commands, generates an error message when trying to access         
$!     these kinds of files. The dcl CONVERT utility will properly            
$!     copy these files to the VMS environment. The CDCOPY command            
$!     file will create an appropriate FDL file for the given input           
$!     CDROM file and then execute the CONVERT utility.                       
$!                                                                            
$!     The CDCOPY command file will convert fixed-length, variable-length,    
$!     and stream record files. If a file on the CDROM does not contain an    
$!     extended attribute record, then the command file assumes the file      
$!     is a stream record file and converts it accordingly.                   
$!                                                                            
$!                                                                            
$!     HOW TO RUN THE COMMAND FILE:                                           
$!                                                                            
$!     You can run the CDCOPY command file with the following command:        
$!                                                                            
$!     $@CDCOPY  in-spec out-spec                                             
$!                                                                            
$!     where 'in-spec' is the input file specification and 'out-spec'         
$!     is the output file specification. Wild card file specifications        
$!     are permitted.  Shown below are a few examples of how to run           
$!     the command file (the CDROM device name is assumed to be DUD7:):       
$!                                                                            
$!     $@CDCOPY DUD7:[000000]AAREADME.TXT *                                   
$!     $@CDCOPY DUD7:[INDEX]IMGINDEX.TAB *                                    
$!     $@CDCOPY DUD7:[MG05NXXX]*.IMG *                                        
$!     $@CDCOPY DUD7:[GAZETTER]GAZETTER.TAB OUT:TEST.TAB                      
$!                                                                            
$!                                                                            
$!_HIST Eric Eliason, USGS Flagstaff, Original Version                        
$!      Helen B. Mortensen, 4-27-92  Uses EXCHANGE/NETWORK instead of CONVERT 
$!      Eric Eliason, 8-06-93, Add error message when file not found.         
$!                             Add ability to recognize record attribute and  
$!                                 apply to output file.                      
$!*************************************************************************   
$        PFILE = ""                                                         ! 
$        FILESPEC = P1                                                      ! 
$        OFILE = P2                                                         ! 
$        IF P1.EQS.""   -                                                   ! 
         THEN           -                                                   ! 
           INQUIRE FILESPEC "Enter CDROM input file specification"          ! 
$!       ENDIF                                                              ! 
$        IF P2.EQS.""   -                                                   ! 
         THEN           -                                                   ! 
           INQUIRE OFILE   "Enter output magnetic disk device "             ! 
$!       ENDIF                                                              ! 
$        FIRST_TIME = 0                                                     ! 
$LOOP:                                                                      ! 
$        IFILE = F$SEARCH(FILESPEC)                                         ! 
$        IF IFILE.EQS.PFILE .AND. FIRST_TIME.EQ.0 THEN GOTO NOFILE          ! 
$        FIRST_TIME = 1                                                     ! 
$        IF IFILE.EQS.PFILE THEN GOTO DONE                                  ! 
$        PFILE = IFILE                                                      ! 
$        IF IFILE.EQS."" THEN GOTO DONE                                     ! 
$        MRS = F$FILE_ATTRIBUTES(IFILE,"MRS")                               ! 
$        RFM = F$FILE_ATTRIBUTES(IFILE,"RFM")                               ! 
$        RAT = F$FILE_ATTRIBUTES(IFILE,"RAT")                               ! 
$        RECATR = "NONE"                                                    ! 
$        IF RAT .EQS. "CR" THEN RECATR = "CARRIAGE_RETURN"                  ! 
$        IF RFM .EQS. "FIX" THEN GOTO FIX                                   ! 
$        IF RFM .EQS. "VAR" THEN GOTO VAR                                   ! 
$        IF RFM .EQS. "UDF" THEN GOTO UDF                                   ! 
$        GOTO ERROR                                                         ! 
$FIX:    OPEN/WRITE  T CD.FDL                                               ! 
$        WRITE T "RECORD"                                                   ! 
$        WRITE T "   BLOCK_SPAN       YES"                                  ! 
$        WRITE T "   CARRIAGE_CONTROL ",RECATR                              ! 
$        WRITE T "   FORMAT           FIXED"                                ! 
$        WRITE T "   SIZE            ",MRS                                  ! 
$        CLOSE T                                                            ! 
$        WRITE SYS$OUTPUT "Copy ",IFILE," to ",OFILE                        ! 
$        WRITE SYS$OUTPUT "fixed-length record file is assumed"             ! 
$        GOTO CVT                                                           ! 
$VAR:    OPEN/WRITE T CD.FDL                                                ! 
$        WRITE T "RECORD"                                                   ! 
$        WRITE T "   BLOCK_SPAN       YES"                                  ! 
$        WRITE T "   CARRIAGE_CONTROL ",RECATR                              ! 
$        WRITE T "   FORMAT           VARIABLE"                             ! 
$        WRITE T "   SIZE             0"                                    ! 
$        CLOSE T                                                            ! 
$        WRITE SYS$OUTPUT "variable-length record file is assumed"          ! 
$        WRITE SYS$OUTPUT "Copy ",IFILE," to ",OFILE                        ! 
$        GOTO CVT                                                           ! 
$UDF:    OPEN/WRITE T CD.FDL                                                ! 
$        WRITE T "RECORD"                                                   ! 
$        WRITE T "   BLOCK_SPAN       YES"                                  ! 
$        WRITE T "   CARRIAGE_CONTROL ",RECATR                              ! 
$        WRITE T "   FORMAT           STREAM"                               ! 
$        WRITE T "   SIZE             0"                                    ! 
$        CLOSE T                                                            ! 
$        WRITE SYS$OUTPUT "Copy ",IFILE," to ",OFILE                        ! 
$        WRITE SYS$OUTPUT "file has undefined format, stream file assumed"  ! 
$        GOTO CVT                                                           ! 
$CVT:                                                                       ! 
$        WRITE SYS$OUTPUT " "                                               ! 
$!       CONVERT/FDL=CD.FDL 'IFILE' 'OFILE'                                 ! 
$        EXCHANGE/NETWORK/FDL=CD.FDL 'IFILE' 'OFILE'                        ! 
$        DELETE CD.FDL;                                                     ! 
$        GOTO LOOP                                                          ! 
$                                                                           ! 
$DONE:                                                                      ! 
$        EXIT                                                               ! 
$NOFILE:                                                                    ! 
$        WRITE SYS$ERROR FILESPEC," does not exist"                         ! 
$        EXIT                                                               ! 
$ERROR:                                                                     ! 
$        WRITE SYS$ERROR IFILE," has unexpected record format, can not copy"! 
$        WRITE SYS$ERROR "CDCOPY terminates"                                ! 
$        EXIT                                                               !