          SUBROUTINE (IMG.IDS,FILE.PATHS,BRS,ARCHIVES,ERR.MSGS,ARCH.TYPES)
** Version# 9.0001[1] - 09/19/2011 - 03:36pm - SMITJR - eclipse

*** SUBROUTINE - IMG.PATH.GET
*-------------------------------------------------------------------------*
*** This progam will constuct network paths where you can access an image.
*** You can either specify which archive you want to transfer an image from
*** or allow this routine to determine which archive is closest to the
*** user.
***
*** NOTE - If you want to create a new path to transfer an image to use
*** IMG.PATH.MAKE.
*-------------------------------------------------------------------------*
*** IMG.IDS    - AM list of image ids                                -[IN]
*** FILE.PATHS - AM list of paths to closest storage location.       -(OUT)
*** BRS        - AM list of local branchs (Branchs are VM)           -(OUT)
***              These branches are the storage locations local branchs
*** ARCHIVES   - Pass in a AM list of archives to create path to. -(IN/OUT)
***              If blank then will create a path that is local to user
***              Will return the archive that was used
*** ERR.MSGS   - AM list of err messages                             -(OUT)
*** ARCH.TYPES - AM List of archive types (a=read only o=offline)    -(OUT)
*-------------------------------------------------------------------------*
          ERR.MSGS   = ''
          FILE.PATHS = '\\192.168.1.100\exports\msds\'
          ARCH.TYPES = ''
          BRS        = ''

          FATAL.ERR = ''
          UT.OPEN.FILE "IMG.XREF",IMGFILE,FATAL.ERR,YES
          IF FATAL.ERR THEN RETURN
          UT.OPEN.FILE "IMG.ARCHIVES",ARCFILE,FATAL.ERR,YES
          IF FATAL.ERR THEN RETURN

          *** Get a list of local imaging storage locations
          IMG.LOCAL.GET LOCAL.IDS

          *** loop through every image id and look for the most accessable
          *** storage location. First look for at local storage location
          *** If no local locations then look for a remote storage location
          ID.CT    = DCOUNT(IMG.IDS,AM)
          FOR IDN  = 1 TO ID.CT
             IMG.ID    = IMG.IDS<IDN>
             ARCH.ID   = ARCHIVES<IDN>
             FILE.PATH = ''

             IF NOT(IMG.ID) THEN
                ERR.MSGS<IDN> = "Empty image id passed in"
                CONTINUE
             END

             READ XREF FROM IMGFILE,IMG.ID ELSE
                MSG  = IMG.ID:' could not be found in image xref file.'
                ERR.MSGS<IDN> = MSG
                CONTINUE
             END

             * Find the archive that we are attempting to transfer image
             * ids from
             ARCH.REC = ''
             IF ARCH.ID THEN
                READ ARCH.REC FROM ARCFILE,ARCH.ID ELSE
                   MSG  = ARCH.ID:' could not be found in image '
                   MSG := 'archive file.'
                   ERR.MSGS<IDN> = MSG
                   CONTINUE
                END
             END ELSE
                * look for a local storage loacation
                ARC.CT   = DCOUNT(XREF<7>,VM)
                FOR ARCN = 1 TO ARC.CT
                   CUR.ID = XREF<7,ARCN>
                   LOCATE CUR.ID IN LOCAL.IDS<1> SETTING NADA THEN
                      READ ARCH.REC FROM ARCFILE,CUR.ID ELSE CONTINUE
                      ARC.TYPE = OCONV(ARCH.REC<1>,'MCU')
                      IF ARC.TYPE # 'O' THEN
                         ARCH.ID = CUR.ID
                         EXIT
                      END
                   END
                NEXT ARCN

                IF NOT(ARCH.ID) THEN
                   * No local storage locations were found. Look for remote
                   * locations that are not offline
                   FOR ARCN = 1 TO ARC.CT
                      CUR.ID   = XREF<7,ARCN>
                      READ ARCH.REC FROM ARCFILE,CUR.ID ELSE CONTINUE
                      ARC.TYPE = OCONV(ARCH.REC<1>,'MCU')
                      IF ARC.TYPE # 'O' THEN
                         ARCH.ID = CUR.ID
                         EXIT
                      END
                   NEXT ARCN
                END

                IF NOT(ARCH.ID) THEN
                   * No local storage locations were found Look for offline
                   FOR ARCN = 1 TO ARC.CT
                      CUR.ID   = XREF<7,ARCN>
                      READ ARCH.REC FROM ARCFILE,CUR.ID ELSE CONTINUE
                      ARCH.ID = CUR.ID
                      EXIT
                   NEXT ARCN
                END
             END

             IF NOT(ARCH.ID) OR NOT(ARCH.REC) THEN
                MSG = "No legitimate archives were found for ":IMG.ID
                ERR.MSGS<IDN> = MSG
                CONTINUE
             END

             LOCATE ARCH.ID IN XREF<7> SETTING XPOS THEN
                PATH.EXT  = XREF<16,XPOS>
             END ELSE
                PATH.EXT = ''
             END

             FILE.TYPE = XREF<2>
             NET.PATH  = ARCH.REC<2>

             FILE.PATH = NET.PATH:'\'
             IF PATH.EXT THEN
                FILE.PATH := PATH.EXT:'\'
             END
             FILE.PATH := IMG.ID
             IF FILE.TYPE#'' THEN
                FILE.PATH := '.':FILE.TYPE
             END
             CONVERT '/' TO '\' IN FILE.PATH

             FILE.PATHS<IDN> = FILE.PATH
             ARCH.TYPES<IDN> = OCONV(ARCH.REC<1>,'MCU')
             BRS<IDN>        = ARCH.REC<3>
             ARCHIVES<IDN>   = ARCH.ID
          NEXT IDN

          RETURN
!SMITJR~09/19/11~15:36
