C+ C NAME: C smei_frm_write C PURPOSE: C Write or update SMEI frame as Fits file. C CATEGORY: C gen/for/lib C CALLING SEQUENCE: subroutine smei_frm_write(cFrm, hdr, cDest, bdig, bnodups) C INPUTS: C cFrm C hdr C cDest C bdig C bnodups C INCLUDE: include 'filparts.h' include 'openfile.h' include 'smei_frm_hdr.h' include 'smei_frm_layout.h' include 'ftspar.h' C CALLS: C say_fts, iGetLun, iFreeLun, itrim, smei_frm_path C iFilePath, iSetFileSpec, iGetFileSpec C Say, Str2Str, Int2Str, FTCLOS, FTNOPN, FTGISZ, FTGPVE C iOSDeleteFile, iCheckDirectory, iOSSpawnCmd, smei_frm_fts C smei_frm_fts_axis, smei_frm_fts_eph, smei_frm_fts_base C PROCEDURE: C MODIFICATION HISTORY: C FEB-2005, Paul Hick (UCSD/CASS) C JUL-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Introduced smei_frm_fts call to write new Fits file C- character cFrm *(*) double precision hdr (*) character cDest*(*) logical bdig logical bnodups character cSay*9 /'frm_write'/ character cSeverity /'E'/ real frame (SMEI__FRM_NPIX) character cFile*(FIL__LENGTH) character cSrce*(FIL__LENGTH) character cLast*(FIL__LENGTH) /' '/ save cLast integer nAxes(2) logical anyf integer Str2Str integer smei_frm_path double precision datan2d double precision dasind character cStr *(FIL__LENGTH) character cType*10 integer tt (2) ! Create filename for new gzipped Fits file i = iSetFileSpec(cFrm) i = iGetFileSpec(FIL__NAME,FIL__NAME,cStr ) i = iGetFileSpec(FIL__TYPE,FIL__TYPE,cType) ! This also fills tt and icam (extracted from cStr) in addition to cDest i = smei_frm_path(bdig, cStr, tt, icam, cDest, cFile) if (bdig .and. cLast .ne. cFile) then ! Create new directory if it doesn't exist if (iCheckDirectory(cFile) .ne. 1) then n = iOSSpawnCmd('mkdir -p '//cFile,0) if (iCheckDirectory(cFile) .ne. 1) call Say(cSay,'E','#'//cFile,'error creating directory') call Say(cSay,'I','#'//cFile,'created new directory') end if end if cLast = cFile i = i+Str2Str(cStr , cFile(i+1:)) i = i+Str2Str('.fts.gz' , cFile(i+1:)) if (cFile .eq. cFrm) then ! Update existing Fits file if (iOSSpawnCmd('gunzip '//cFile,0) .eq. 0) & call Say(cSay,'E','#'//cFile,'gunzip failed') iFile = itrim(cFile)-len('.gz') iU = iGetLun(cFile(:iFile)) istat = 0 call FTNOPN(iU, cFile(:iFile), FTS__WRITE, istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) ! Update the header using info in hdr call smei_frm_fts_axis(iU, hdr) call smei_frm_fts_eph (iU, hdr) call smei_frm_fts_base(iU, hdr) call FTCLOS(iU, istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) iU = iFreeLun(iU) if (iOSSpawnCmd('gzip '//cFile(:iFile),0) .eq. 0) & call Say(cSay,'E','#'//cFile(:iFile),'gzip failed') else ! We need the original data to write into a new ! Fits file, so read cFrm again istat = 0 iU = iGetLun(cFrm) call FTNOPN(iU, cFrm, FTS__READONLY, istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) call FTGISZ(iU, 2, nAxes, istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) anyf = .FALSE. call FTGPVE(iU, 1, 1, nAxes(1)*nAxes(2), 0, frame, anyf, istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) call FTCLOS(iU,istat) if (istat .ne. 0) call say_fts(cSay,cSeverity,istat) iU = iFreeLun(iU) ! And write a new Fits file call smei_frm_fts(cFile,nAxes(1),nAxes(2),2,frame,hdr) ! Remove the original file if it was in the same directory. ! The files must be in the same directory, but have different ! names (i.e. have a different file type). if (bNoDups .and. cFile .ne. cFrm) then i = iSetFileSpec(cFrm) i = iGetFileSpec(0,FIL__NAME,cSrce) i = iSetFileSpec(cFile) i = iGetFileSpec(0,FIL__NAME,cStr ) if (cStr .eq. cSrce) i = iOSDeleteFile(cFrm) end if end if return end