Viewing contents of file '../idllib/iuedac/iuelib/pro/bs_inout.pro'
;******************************************************************************
;+
;*NAME:
;
;      	BS_INOUT       (RDAF General Production Library)     Jan 30, 1983
; 
;*CLASS: 
;
;      	Data Editing
;
;*CATEGORY:
;
;       IUESIPS         NEWSIPS
;
;*PURPOSE:  
;
;      	Create an output IUESIPS LBLS or NEWSIPS-like SILO disk file based on
;       the input parameters, IMAGI and IMAGO when called by BSPOT.PRO
; 
;*CALLING SEQUENCE:
;
;      	BS_INOUT,IMAGI,IMAGO,IMAGET,NEWSIPS
;
;*PARAMETERS:
;
;      	IMAGI   (REQ) (I) (1) (S)
;               Input LBLS (or ELBL) file specified as a string.
; 
;      	IMAGO  	(REQ) (I) (1) (S)
;           	Any String  - Becomes name of output disk file and IMAGI is
;                             copied into IMAGO.
;           	' ' (blank) - On vms, output file has same name as input file 
;                             with version number incremented and IMAGI is 
;                             copied into it. On unix, same as 0 below.
;               0   - write over input file.
;
;      	IMAGET  (REQ) (O) (1) (S)
;               Name of output file.
;
;       NEWSIPS (REQ) (I) (0) (I)
;               Equals 0 for IUESIPS data.  Equals 1 for NEWSIPS data.
;
;*EXAMPLES:
;
;      	See BSPOT.PRO prolog.
;
;*SYSTEM VARIABLES USED:    
;
;       none
; 
;*INTERACTIVE INPUT:
;
;       If the output file already exists (and is not the input file), the user
;       will be asked if they wish to continue.
;
;*SUBROUTINES CALLED:
;
;	PARCHECK
;      	DECOMPOSE      
;       YESNO
;	PLATFORM
;
;*FILES USED:
;
;      	IMAGI   (I)
;          	Input required IUESIPS LBLS or NEWSIPS SILO disk file.
;
;      	IMAGO   (O)
;          	Output disk file.
;
;      	IMAGET  (O)
;          	Output disk file.
;
;*SIDE EFFECTS:
;
;      	Note the option that input file may be written over.  (See Parameter
;       List.)
;
;*NOTES:
;
;*PROCEDURE:
;
;      	IMAGI input IUESIPS LBLS or NEWSIPS SILO file is either copied into
;       IMAGO, or copied into output file of same name but version number (VMS
;       only) incremented, or is written over depending upon value of input
;       parameter IMAGI as entered by the user.  (See Parameter List.)
;
;*I_HELP nn:
;
;*MODIFICATION HISTORY:
;
;      	30-JAN-83 written by R.J. Panek
;      	10-MAR-88 HAA add RDAF Prolog
;       jan-10-90 jtb @gsfc modified for unix / sun idl version 1.2
;       4-10-91 KBC spawn correct system call based on operating system type
;                   for compatibility on SUN/VAX/DEC
;	7-22-91 PJL cleaned up; added npar equal 0 print and PARCHECK;
;		    tested on SUN and VAX; updated prolog
;       7-28-92 RWT correct error for imago=` ' for vms systems
;        4 Mar 94  PJL  added NEWSIPS are required parameter; added YESNO
;       29 Apr 94  PJL  set imaget equal to imago if no additions needed
;	 8 Jun 94  PJL  replaced !version with PLATFORM
;       11 Oct 94  PJL  add code for ncopy = 'NA'
;       29 Jan 95  REB  corrected error with imago=0, will now overwrite
;                       imagi as stated in documentaion
;       10 Feb 95  REB  NEWSIPS section: corrected imago=0 problem
;                       and made the imput extension the output extension
;-
;******************************************************************************
 pro bs_inout,imagi,imago,imaget,newsips
;
 npar = n_params(0)
 if (npar eq 0) then begin
    print,'BS_INOUT,IMAGI,IMAGO,IMAGET,NEWSIPS'
    retall
 endif  ; npar eq 0
 parcheck,npar,4,'BS_INOUT'
;
 platform,dummy,ncopy=ncopy,copymes=copymes
;
 same = 0  ; equals 1 if input and output files are the same
 if (newsips) then begin
;
;  NEWSIPS
;
decompose,imagi,disk,path,image,ext,vers
s=size(imago)
;
    if (s(1) eq 7) then begin
      if (strtrim(imago,2) eq '') then begin
         same=1
         temp = strpos(imagi,'.') 
         imaget = strmid(imagi,0,temp(0)) + ext  
        endif else begin
         temp = strpos(imago,'.')
         if (temp lt 0) then imaget = strtrim(imago,2) + ext else   $
            imaget = imago
        endelse  ; strtrim(imago,2) eq ''
    endif else begin 
    if (strtrim(imago,2) eq 0) then begin
       same=1
       imaget=imagi
       print,'WARNING: Input file will not be modified, no ' +   $
          'output file specified.'
    endif
;  
    im = imagi
    endelse
 endif else begin
;
;  IUESIPS
;
    d = '.dat'
    l = '.lab'
    decompose,imagi,disk,path,image,ext,vers
    im = disk + path + image + d                           ; data  file
    iml = disk + path + image + l                          ; label file
;
    s = size(imago)
    if (s(1) eq 7) then begin                              ; imago is a string
       if (imago eq '') then begin                         ; imago is a blank 
          imaget = im
          same = 1
;;;          if (!version.os eq 'vms') then begin
;;;             if (not(newsips)) then begin
;;;                spawn,'copy ' + im + vers + ' ' + im
;;;                spawn,'copy ' + iml + vers + ' ' + iml
;;;             endif  ; not(newsips)
;;;          endif else print,'WARNING:  Input file will be modified, no ' +   $
;;;             'output file specified.'
          if (strtrim(copymes.past,2) eq 'superseded') then begin
             if (not(newsips)) then begin
                if (ncopy ne 'NA') then begin
                   spawn,ncopy + im + vers + ' ' + im
                   spawn,ncopy + iml + vers + ' ' + iml
                endif else begin
                   print,'Please make new versions of ' + im + vers 
                   print,'and' + iml + vers 
                   answer = ''
                   read,'Please press RETURN to continue.',answer
                endelse  ; ncopy ne 'NA'
             endif  ; not(newsips)
          endif else print,'WARNING:  Input file will be modified, no ' +   $
             'output file specified.'
       endif else begin                                   ; imago not a blank 
          decompose,imago,disk,path,image,ext,vers
          imaget = disk + path + image + d + vers
       endelse  ; imago
    endif else begin                                    ; imago is a number
       if (imago eq 0) then begin                       ; imago equals zero.
          imaget = im
          same = 1
;;;          if (!version.os eq 'vms') then begin
;;;             if (not(newsips)) then begin
;;;                spawn,'copy ' + im + vers + ' ' + im
;;;                spawn,'copy ' + iml + vers + ' ' + iml
;;;             endif  ; not(newsips)
;;;          endif else print,'WARNING:  Input file will be modified, no ' +   $
;;;             'output file specified.'
;          if (strtrim(copymes.past,2) eq 'superseded') then begin
;             if (not(newsips)) then begin
;                if (ncopy ne 'NA') then begin
;                   spawn,ncopy + im + vers + ' ' + im
;                   spawn,ncopy + iml + vers + ' ' + iml
;                endif else begin
;                   print,'Please make new versions of ' + im + vers 
;                   print,'and' + iml + vers 
;                   answer = ''
;                   read,'Please press RETURN to continue.',answer
;                endelse  ; ncopy ne 'NA'
;             endif  ; not(newsips)
;          endif else print,'WARNING:  Input file will be modified, no ' +   $
          print,'WARNING:  Input file will be modified, no ' + $
             'output file specified.'
       endif else begin
          print,'Invalid output name specified: ',imago
          print,'ACTION:  Returning'
          retall
       endelse  ; imago
    endelse  ; s(1) eq 7
 endelse  ; newsips
;
;  if output file not defined with the same name as input file, see if output
;  file already exists
;
 if (not(same)) then begin
    temp = findfile(imaget,count=count)
    if (count gt 0) then begin
;;;       case (!version.os) of
;;;          'vms':  errmeg = 'superseded.'
;;;          else:  errmeg = 'overwritten.'
;;;       endcase  ; !version.os
       errmeg = strtrim(copymes.past,2)
       print,imaget + ' already exists.  It will be ' + errmeg + '.'
       answer = ''
       read,'Do you wish to continue (yes/no, default yes)?  ', answer
       yesno,answer
       if (not(answer)) then retall
    endif  ; count gt 0
;
;  if not newsips - copy imput file to output file
;
    if (not(newsips)) then begin
       errmeg = ' - will be ' + strtrim(copymes.past,2) + '.'
;
       decompose,imago,disk,path,image,ext,vers
       imaget = disk + path + image + d + vers
;
;  copy input file into output file
;
       if (ncopy ne 'NA') then begin
          spawn,ncopy + im + vers + ' ' + imaget
          spawn,ncopy + iml + vers + ' ' + disk + path + image + l + vers
       endif else begin
          print,'Please copy ' + im + vers + ' to ' + imaget + ' and '
          print,iml + vers + ' to ' + disk + path + image + l + vers
          answer = ''
          read,'Please press RETURN to continue.',answer
       endelse  ; ncopy ne 'NA'
    endif  ; not(newsips)
 endif ; not(same)
;
 print,'Output filename is ' + imaget
;
 return
 end  ; bs_inout