/usr/share/gnudatalanguage/astrolib/dbedit.pro is in gdl-astrolib 2018.02.16+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | ;+
; NAME:
; DBEDIT
;
; PURPOSE:
; Interactively edit specified fields in an IDL database.
; EXPLANATION:
; The value of each field is displayed, and the user has the option
; of changing or keeping the value. Widgets will be used if they
; are available.
;
; CALLING SEQUENCE:
; dbedit, list, [ items ]
;
; INPUTS:
; list - scalar or vector of database entry numbers. Set list = 0 to
; interactively add a new entry to a database. Set list = -1 to edit
; all entries.
;
; OPTIONAL INPUTS:
; items - list of items to be edited. If omitted, all fields can be
; edited.
;
; KEYWORDS:
; BYTENUM = If set, treat byte variables as numbers instead of
; characters.
;
; COMMON BLOCKS:
; DB_COM -- contains information about the opened database.
; DBW_C -- contains information intrinsic to this program.
;
; SIDE EFFECTS:
; Will update the database files.
;
; RESTRICTIIONS:
; Database must be opened for update prior to running
; this program. User must be running DBEDIT from an
; account that has write privileges to the databases.
;
; If one is editing an indexed item, then after all edits are complete,
; DBINDEX will be called to reindex the entire item. This may
; be time consuming.
;
; Cannot be used to edit items with multiple values
;
; EXAMPLE:
; Suppose one had new parallaxes for all stars fainter than 5th magnitude
; in the Yale Bright Star Catalog and wanted to update the PRLAX and
; PRLAX_CODE fields with these new numbers
;
; IDL> !priv=2
; IDL> dbopen, 'yale_bs', 1 ;Open catalog for update
; IDL> list = dbfind( 'v>5') ;Find fainter than 5th magnitude
; IDL> dbedit, list, 'prlax, prlax_code' ;Manual entry of new values
;
; PROCEDURE:
; (1) Use the cursor and point to the value you want to edit.
; (2) Type the new field value over the old field value.
; (3) When you are done changing all of the field values for each entry
; save the entry to the databases by pressing 'SAVE ENTRY TO DATABASES'.
; Here all of the values will be checked to see if they are the correct
; data type. If a field value is not of the correct data type, it will
; not be saved.
;
; Use the buttons "PREV ENTRY" and "NEXT ENTRY" to move between entry
; numbers. You must save each entry before going on to another entry in
; order for your changes to be saved.
;
; Pressing "RESET THIS ENTRY" will remove any unsaved changes to the
; current entry.
;
;REVISION HISTORY:
; Adapted from Landsman's DBEDIT
; added widgets, Melissa Marsh, HSTX, August 1993
; do not need to press return after entering each entry,
; fixed layout problem on SUN,
; Melissa Marsh, HSTX, January 1994
; Only updates the fields which are changed. Joel Offenberg, HSTX, Mar 94
; Corrected test for changed fields Wayne Landsman HSTX, Mar 94
; Removed a couple of redundant statements W. Landsman HSTX Jan 96
; Converted to IDL V5.0 W. Landsman September 1997
; Replace DATAYPE() with size(/TNAME) W. Landsman November 2001
; Work for entry numbers > 32767 W. Landsman December 2001
; Added /BYTENUM William Thompson 13-Mar-2006
; Use DIALOG_MESSAGE for error messages W. Landsman April 2006
; Assume since V5.5, remove VMS support W. Landsman Sep 2006
;-
;----------------------------------------------------------------
;event handler for main part of program
pro widgetedit_event,event
common db_com,qdb,QITEMS,QDBREC
common dbw_c,liston,main,holder,widlabel,widtext,middle,nitems,names,$
it,itnum,dtype,numvals,sbyte,nbytes,buts,prevbut,but2,resetbut,$
endbut,nextbut,mid,minlist,maxlist,savebut,bigmid,entry,wid_warn,$
holder0,widtext0,widlabel0,thislist,nlist,wereat,newflag,bytenum
CASE event.id OF
endbut: widget_control,event.top,/destroy ;destory main widget--end session
prevbut:begin ;go to previous entry
if wereat ne 0 then wereat= wereat-1
liston = thislist[wereat]
widedit
end
nextbut:begin ;go to next entry
if wereat lt nlist-1 then wereat = wereat+1 else $
widget_control,event.top,/destroy ;end session
liston = thislist[wereat]
widedit
end
resetbut:begin ;reset this entry
liston = liston
widedit
end
savebut: begin ;save entry to databases
;update database
for i = 0, nitems -1 do begin
widget_control,widtext[i],get_value=val
;test value
valid = 0
oldval = dbxval(entry,dtype[i],numvals[i],sbyte[i],nbytes[i])
on_ioerror,BADVAL
IF (strtrim(oldval[0],2) ne (strtrim(val[0],2))) THEN BEGIN
oldval[0] = strtrim(val,2)
valid = 1
dbxput,oldval,entry,dtype[i],sbyte[i],nbytes[i]
print,strcompress('Entry ' + string(liston) +': ' + $
names[i] + ' = ' + string(val))
newflag[ wereat, i ] = 1b
BADVAL: if (not valid) then begin
result = dialog_message(title='Bad Value',/ERROR, $
'Item '+ strcompress(names[i],/rem) + $
' must be of type ' + size(oldval[0],/TNAME) )
str = dbxval(entry,dtype[i],numvals[i],sbyte[i],nbytes[i])
if (dtype[i] eq 1) and keyword_set(bytenum) then str=fix(str)
str = ' '+string(str[0])
widget_control,widtext[i],set_value=str
endif
endIF
on_ioerror,NULL
endfor
if (liston EQ 0) then begin
dbwrt,entry,0,1 ;new entry
endif else begin
dbwrt,entry
endelse
widedit
;create widget telling the user that the changes have been made.
end
else: ;donothing
endcase
end
;--------------------------------------------------------------------
pro widedit
;program that makes "middle" of main widget (field values)
common db_com,qdb,QITEMS,QDBREC
common dbw_c,liston,main,holder,widlabel,widtext,middle,nitems,names,$
it,itnum,dtype,numvals,sbyte,nbytes,buts,prevbut,but2,resetbut,$
endbut,nextbut,mid,minlist,maxlist,savebut,bigmid,entry,wid_warn,$
holder0,widtext0,widlabel0,thislist,nlist,wereat,newflag,bytenum
;get entry number
dbrd, liston, entry
;get field values for this entry
widget_control, widtext0, set_value=string(liston)
for i = 0,nitems-1 do begin
str = dbxval(entry,dtype[i],numvals[i],sbyte[i],nbytes[i])
if (dtype[i] eq 1) and keyword_set(bytenum) then str=fix(str)
str = ' '+string(str[0])
widget_control,widtext[i],set_value=str
endfor
;check to see if this entry is the minimum or maximum entry
if (liston EQ minlist) then widget_control,prevbut,sensitive=0 else $
widget_control,prevbut,sensitive=1
if (liston EQ maxlist) then widget_control,nextbut,sensitive=0 else $
widget_control,nextbut,sensitive=1
end
;-------------------------------------------------------------------------
;main program
pro dbedit,list,items,bytenum=k_bytenum
compile_opt idl2
common db_com,qdb,QITEMS,QDBREC
;Nitems - Number elements in input list
;Thislist - Sorted list of entry numbers
;Minlist - Minimum input entry number
;Maxlist - Maximum input entry number
;Liston - The current entry number being edited (scalar)
;wereat - The index of ThisList vector being edited, i.e. Thislist(wereat)=LIston
;dtype - data type(s) (1=string,2=byte,4=i*4,...)
;sbyte - starting byte(s) in entry
;numvals - number of data values for item(s)
; NOTE: dtype, sbyte, numvals are dimensioned for *all* entries
common dbw_c,liston,main,holder,widlabel,widtext,middle,nitems,names,$
it,itnum,dtype,numvals,sbyte,nbytes,buts,prevbut,but2,resetbut,$
endbut,nextbut,mid,minlist,maxlist,savebut,bigmid,entry,wid_warn,$
holder0,widtext0,widlabel0,thislist,nlist,wereat,newflag,bytenum
On_error,2
if N_params() LT 1 then begin
print,'Syntax - dbedit, list, [ items ]'
return
endif
;Set the value of bytenum
bytenum = keyword_set(k_bytenum)
;make sure widgets are available
if (!D.FLAGS AND 65536) EQ 0 then begin
dbedit_basic, list, items
return
endif
;check to make sure database is open
;first check to see if there is an open database
s = size(qdb)
if (s[0] EQ 0) then begin
result = dialog_message(/ERROR, title='NOT OPEN FOR UPDATE', $
'No database has been opened')
goto, PROEND
endif
;check to make sure the database is opened for update
dbname = db_info('NAME',0)
if not db_info('UPDATE') then begin
result = dialog_message(/ERROR, title='NOT OPEN FOR UPDATE', $
'Database ' + dbname + ' must be opened for update.')
goto,PROEND
endif
;check parameters
zparcheck, 'DBEDIT', list, 1, [1,2,3], [0,1], 'Database entry numbers'
;get items. If items not specified use all items except ENTRY
if ( N_params() LT 2 ) then begin
nitems = db_info('ITEMS',0) -1
items = indgen(nitems) + 1
endif
nlist = N_elements(list)
if nlist gt 1 then begin ;sort entry numbers
sar = sort(list)
thislist = list[sar]
endif else begin
thislist = lonarr(1)
thislist[0] = list
endelse
;edit all entries? get number of entries
if ( list[0] EQ -1 ) then begin
nlist = db_info('ENTRIES',0)
if nlist le 0 then begin
print,'Empty database cannot be edited. Use list=0 to add new entry'
goto, PROEND
endif
thislist = lindgen(nlist) + 1
endif
minlist = min(thislist, max = maxlist)
nentry = db_info('ENTRIES',0)
if (maxlist gt nentry) then begin
result = dialog_message(title='INVALID ENTRY NUMBER',/ERROR, $
dbname + ' entry numbers must be less than ' + strtrim(nentry+1,2) )
goto, PROEND
endif
nitems = db_info('ITEMS',0) -1
allitems = indgen(nitems) + 1
;get information about items
db_item,allitems,itnum,ivalnum,dtype,sbyte,numvals,nbytes
nvalues = db_item_info('nvalues')
db_item,items,it
nit = n_elements(it) ;Number of items to be edited
names = db_item_info('name',itnum) ;Get names of each item
newflag = bytarr(nlist,nitems) ;Keeps track of fields actually updated
wereat = 0
liston = thislist[wereat]
dbrd,liston,entry
;create widget and display
main = widget_base(/COLUMN,title='Widgetized Database Editor')
w1 = widget_label(main,value='****** ' + dbname + ' ******')
bigmid = widget_base(main,/column,x_scroll_size=325,y_scroll_size=650)
butbase = widget_base(main,/column,/frame)
savebut = widget_button(butbase,value='SAVE THIS ENTRY')
buts = widget_base(butbase,/row)
prevbut = widget_button(buts,value='<- PREV ENTRY')
but2 = widget_base(buts,/column)
resetbut = widget_button(but2,value='RESET THIS ENTRY')
endbut = widget_button(but2,value='END SESSION')
nextbut = widget_button(buts,value='NEXT ENTRY ->')
widlabel = lonarr(nitems+1)
widtext = lonarr(nitems+1)
holder = lonarr(nitems+1)
mid = widget_base(bigmid,/column)
holder0 = widget_base(mid,/row)
widlabel0 =widget_label(holder0,value=' ENTRY NUMBER ',/frame)
num = string(liston)
widtext0 = widget_label(holder0,value=num)
middle = widget_base(mid,/column)
for i = 0,nitems-1 do begin
ed = 'N'
str1 = names[i]
for j = 0, N_elements(it)-1 do begin
if it[j] EQ itnum[i] then ed = 'Y'
endfor
str = dbxval(entry,dtype[i],numvals[i],sbyte[i],nbytes[i])
if (dtype[i] eq 1) and keyword_set(bytenum) then str=fix(str)
str = ' ' + string(str[0])
if ed eq 'Y' then begin
holder[i] = widget_base(middle,/row)
widlabel[i] = widget_label(holder[i],value = str1,/frame)
widtext[i] = widget_text(holder[i],/frame,value=str,/edit)
endif else begin
holder[i] = widget_base(middle,/row)
widlabel[i] = widget_label(holder[i],value = str1,/frame)
widtext[i] = widget_label(holder[i],value=str)
endelse
endfor
if (liston EQ minlist) then widget_control,prevbut,sensitive=0 else $
widget_control,prevbut,sensitive=1
if (liston EQ maxlist) then widget_control,nextbut,sensitive=0 else $
widget_control,nextbut,sensitive=1
widget_control,main,/realize
xmanager,'widgetedit',main
newitem = total(newflag, 1)
indexnum = where(newitem, nindex)
if ( nindex GT 0 ) then begin ;Any mods made?
indexnum = itnum[indexnum]
indextype = db_item_info('INDEX',indexnum);Index type of modified fields
good = where(indextype GE 1, Ngood) ;Which fields are indexed?
if Ngood GT 0 then begin
message, 'Now updating index file', /INF
dbindex, indexnum[good]
endif
dbopen,strlowcase(dbname),1
endif
PROEND:
return
end
|