;+ ; NAME: ; vu_image ; PURPOSE: ; Save the zbuffer into image files to be used for the IPS forecast Web page ; CATEGORY: ; I/O ; CALLING SEQUENCE: PRO vu_image, hdr, module, destination=destination, device=device, notwin=notwin, use_image=use_image, $ png=png, title=title, ut=ut, upto=upto ; INPUTS: ; hdr array[1]; type: structure ; scalar; type: string ; header structure or name of tomography file used ; to generate the plot ; module scalar; type: string ; module name describing the plot in the z-buffer ; e.g. 'earth_insitu_v', etc. ; OPTIONAL INPUTS: ; destination=destination ; scalar or array[2]; type: string ; If the first element is a valid directory then an ; image file is created in that directory with a name based ; on the module name. ; If a 2nd directory is specified a backup copy is written ; to subdirectory 'module' of this 2nd directory. ; If this keyword is not specified then the image is ; displayed on the terminal. ; gif=gif if set then images are saved as gif files ; png=png if set then images are saved as png files ; ; ut=ut scalar or array[1]; time; default: none ; time used in title for IDL window, or used in construction ; of image file name. Usually this is the forecast time. ; device=device scalar; type: string; default: none ; graphics device to switch to after the z-buffer has been read. ; /notwin if set then the call to 'view' is skipped, and the content of the ; Z-buffer is displayed directly using the 'tv' command. ; use_image=use_image ; scalar; type: string ; If keyword 'destination' is specified, then the image file (and optional ; backup copy) is by default created by reading the Z-buffer. ; If an image file is already created then its fully-qualified ; name can be specified in keyword 'use_image', bypassing reading ; the Z-buffer. The use_image file will be moved to 'destination[0]' ; and, optionally, a copy is placed in a subdirectory of 'destination[1]'. ; ; OUTPUTS: ; (Two image files) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; checkdir, IsType, SetFileSpec, GetFileSpec, view, do_file, reset_colors ; IsDisplay, SuperArray, Carrington, get_page, TimeGet, TimeUnit ; PROCEDURE: ; The current graphics device should be the z-buffer. The z-buffer is read by a simple ; tvrd(), and is then either displayed on the screen, or written to an image file. ; ; Two identical image files are created in subdirectories, 'www' and 'images/module' ; of the root directory $dat/nagoya. ; ; The file in 'www' is named 'module#.gif' where # is an integer digit, equal to the ; number of elements in nv3d_file. This file is used directly in the Web page. ; ; The file in 'images' is named 'nv3d_file[0]_#####.module#.gif. Here the 5-digit integer ; is the time differences in minutes between the system time and the time that file ; nv3d_file[0] was created. This file serves as a backup copy and can also be used to ; make movies from sequences of GIF files. ; MODIFICATION HISTORY: ; MAR-2000, Paul Hick (UCSD/CASS) ; MAY-2000, Paul Hick (UCSD/CASS) ; The skysweep map is now written only once for each tomography run (instead of each hour). ; AUG-2000, Paul Hick (UCSD/CASS) ; Added /speed and /density keywords. If one of these is set then '_v' or '_n' is added ; to the name of the gif files. ; Added 'destination' keyword to control destination of gif files. ; FEB-2001, Paul Hick (UCSD/CASS) ; Added the postfix _v or _n to the subdirectory in $dat/nagoya/image where the ; backup copy of the gif file is stored, i.e. density and velocity images are now ; stored in separate directories). ; APR-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu ; Removed check for modules skysweep, fore/aftcast (used to avoid unnecessarily writing files). ; Changed file name convention for the backup image file. The title keyword explicitly allows ; specification of a prefix, replacing the default name of the nv3d file name specified in 'hdr'. ; The forecast time is now encoded as a UT time string instead of a Carrington rotation. ;- InitVar, notwin, /key iswin = 1-notwin ndir = n_elements(destination) ndev = n_elements(device) InitVar, gif, /key InitVar, png, /key CASE 1 OF png : imgtype = '.png' gif : imgtype = '.gif' ELSE: BEGIN gif = 1 imgtype = '.gif' END ENDCASE dump_image = ndir NE 0 IF dump_image THEN dump_image = checkdir(destination[0]) IF IsType(title, /undefined) THEN BEGIN CASE IsType(hdr, /structure) OF 0: SetFileSpec, hdr[0] ; hdr is file name 1: SetFileSpec, hdr[0].file ; hdr is header structure ENDCASE title = GetFileSpec(from='name', upto='type') ENDIF IF strlen(title) NE 0 THEN title = title+'_' IF IsType(ut, /defined) THEN BEGIN InitVar, upto, TimeUnit(/second) title = title+TimeGet(Carrington(ut[0],/get_time),ymd=1-dump_image, _ydoy=dump_image, upto=upto)+'_' ENDIF title = title+module IF dump_image THEN BEGIN ; If one directory is specified a single file is written to this directory. ; If a second directory is specified an additional backup copy is written ; to subdirectory 'module' of the 2nd directory. ; The first directory receives the file for the web page. The image file ; is created by reading/writing the content of the Z-buffer, or by moving ; an existing image file (specified in 'use_image'). img = filepath(root=destination[0], module+imgtype) CASE IsType(use_image, /defined) OF 0: BEGIN catch, ierr CASE ierr OF 0 : get_page, img, /zbuffer, /freeze, /silent ELSE: message, /info, 'error writing '+img ENDCASE catch, /cancel END 1: BEGIN ok = do_file(/move, use_image[0], img) message, /info, use_image[0]+' --> '+img+': move '+(['error','ok'])[ok] END ENDCASE IF ndir EQ 2 THEN BEGIN ; The second directory is the backup directory (e.g $dat/nagoya/slow/image) ; Unless 'title' is set, the name of the backup image starts with 'file' (the name of the ; nv3d file used to create the plot). An identifier is appended for the time 'ut' at which ; the plot was created. img_save = filepath(root=destination[1], subdir=module, title+imgtype) ok = do_file(/copy, img, img_save) message, /info, '--> '+img_save+': copy '+(['error','ok'])[ok] ENDIF IF ndev NE 0 THEN set_plot, device ENDIF ELSE IF ndev NE 0 THEN BEGIN IF IsDisplay(device) THEN get_page, /zbuffer, /silent ;image = tvrd() ; Read the z-buffer ;tvlct, /get, r, g, b ;set_plot, device ; Switch graphics device ;IF IsDisplay() THEN BEGIN ;true_color = !d.n_colors gt 256 ;CASE true_color OF ;0: tvlct, r, g, b ;1: BEGIN ;image = SuperArray(image, 3, /trail) ;image[*,*,0] = r[image[*,*,0]] ;image[*,*,1] = g[image[*,*,1]] ;image[*,*,2] = b[image[*,*,2]] ;loadct, 0, /silent ;END ;ENDCASE ;CASE iswin OF ;0: tv, image, true=3*true_color ;1: view, in=image, title=' '+title, true=true_color ;ENDCASE ;ENDIF stretch ENDIF reset_colors RETURN & END