.PROC,CRELIB*I,
LFN "- Local File Name of NOS records" = (*F),
PFN "- Permanent File Name of NOS file"= (*N=,*F),
UN "- User Name of NOS file"           = (*N=,*F),
L "- file to which Library is written" = (*N=,*F),
N "- Name of library"                  = (*N=,*F),
I "- LIBEDIT input directive file"     = (*N=0,*F),
.
.HELP
 The CRELIB procedure CREates a user LIBrary file from NOS records.
 Requires CATALOG binaries with GENCAT entry point.

 Parameter   Default   Description
   Name       Value

   lfn                 local file name containing NOS records
  [pfn]       lfn      permanent file name of the stored file
  [un]                 user name in which file resides
  [l]         lfn      file to which the library is written
  [n]          l       name stored in library directory
  [i]          0       file containing LIBEDIT directives

.HELP,LFN
 The LFN parameter selects the name by which the NOS file is accessed.
.HELP,PFN
 The PFN parameter selects the name by which the NOS file is stored.
 The default is the value specified for the LFN parameter.
.HELP,UN
 The UN parameter specifies the User Name location of the file.
 The default value is the User Name in which this procedure executes.
.HELP,L
 The L parameter names a file to which the library is written.
 The default is the value specified for the LFN parameter.
.HELP,N
 The N parameter specifies a name saved in the library directory.
 The default is the value specified for the L parameter.
.HELP,I
 The I parameter names a file containing LIBEDIT directives.
 The default is to not use LIBEDIT directives.
.ENDHELP
.IFE,$N$.EQ.$$,SETLIBNAME.
  .IFE,$L$.EQ.$$,USEPFN.
    .IFE,$PFN$.EQ.$$,SETPFN.
      $REVERT,EX.CRELIB,LFN,LFN,UN,LFN,LFN,I.
    .ELSE,SETPFN.
      $REVERT,EX.CRELIB,LFN,PFN,UN,PFN,PFN,I.
    .ENDIF,SETPFN.
  .ELSE,USEPFN.
    .IFE,$PFN$.EQ.$$,SETPFN.
      $REVERT,EX.CRELIB,LFN,LFN,UN,L,L,I.
    .ELSE,SETPFN.
      $REVERT,EX.CRELIB,LFN,PFN,UN,L,L,I.
    .ENDIF,SETPFN.
  .ENDIF,USEPFN.
.ENDIF,SETLIBNAME.
.IFE,$I$.NE.$0$,DIRECTIVES.
  GETFILE,I,I,,READ,A=YES.
.ENDIF,DIRECTIVES.
GETFILE,LFN,PFN,UN,,A=YES.
.IFE,$I$.NE.$0$,DIRECTIVES.
  $LIBEDIT,B=LFN,#N=LFN,P=0,#L=YYYYERR,LO=E,#I=I,U=L,D,NI.
  $REWIND,YYYYERR.
  $COPYEI,YYYYERR,OUTPUT.
.ELSE,DIRECTIVES.
  UPDVER,DATE+,TIME+,LFN,L,CREATE.
  $LIBEDIT,B=DISVER,#N=LFN,P=LFN,#L=YYYYERR,LO=EM,#I=I,U=L.
.ENDIF,DIRECTIVES.
$UNLOAD,ZZZZZG2,DISVER,YYYYERR,YYYYCRE.
$SKIP,NOERROR.
  $EXIT.
  $REWIND,LFN,YYYYERR.
  $COPYEI,YYYYERR,OUTPUT.
  $UNLOAD,ZZZZZG2,DISVER,YYYYERR,YYYYCRE.
  $REVERT,ABORT. CREATE L <-- PFN FAILED
$ENDIF,NOERROR.
$IFE,.NOT.((FILE(LFN,PM)).AND.(FILE(LFN,WR))),REWRITE.
  REPFILE,LFN,L,DEFINE=YES.
$ENDIF,REWRITE.
.IFE,$LFN$.NE.$L$,RETURNLFN.
  $UNLOAD,LFN.
.ENDIF,RETURNLFN.
.IFE,(($PFN$.NE.$L$).AND.($PFN$.NE.$$)),PURGEPFN.
  $PURGE,PFN/NA.
.ENDIF,PURGEPFN.
$REVERT. CREATED L <-- LFN (#I=I)
/EOR
