[85] | 1 | function getget, name, charvar, count=count, offset=offset, stride=stride, coordmean=coordmean, anomaly=anomaly |
---|
| 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
---|
| 3 | ; name: char |
---|
| 4 | ; charvar: char |
---|
| 5 | ; count: 4 elements array ; The dimensions of the sub-image |
---|
| 6 | ; offset: 4 elements array ; A variable that contains the offset for the sub-image |
---|
| 7 | ; stride: 4 elements array ; Create a variable to be used as a value for the STRIDE keyword |
---|
| 8 | ; coordmean: 1 to 4 elements array (dimension 1 is 1) |
---|
| 9 | ; anomaly: a non-null element that would be filled with mean |
---|
| 10 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | ;print, charvar |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | nosave = 1 ;; comment to get an IDL data file |
---|
| 17 | notime = 1 ;; comment to get mention of time taken |
---|
| 18 | if (n_elements(notime) eq 0) then timetime = SYSTIME(1) |
---|
| 19 | |
---|
| 20 | ; |
---|
| 21 | ; MINIMAL ARGUMENTS |
---|
| 22 | ; |
---|
| 23 | if (n_elements(name) eq 0) then stop |
---|
| 24 | if (n_elements(charvar) eq 0) then stop |
---|
| 25 | |
---|
| 26 | ; |
---|
| 27 | ; IDL DATA DIRECTORY |
---|
| 28 | ; |
---|
| 29 | name_idl = charvar+name+'.idl' |
---|
| 30 | if (n_elements(coordmean) ne 0) then begin |
---|
| 31 | nc = n_elements(coordmean) |
---|
| 32 | for i=0,nc-1 do begin |
---|
| 33 | name_idl = string(coordmean(i),'(I0)')+name_idl |
---|
| 34 | endfor |
---|
| 35 | endif |
---|
| 36 | name_idl = './idl_dat/'+name_idl |
---|
| 37 | |
---|
| 38 | ; |
---|
| 39 | ; TEST IF FILE EXISTS |
---|
| 40 | ; |
---|
| 41 | openr,unit,name_idl,/get_lun,error=err |
---|
| 42 | |
---|
| 43 | ; |
---|
| 44 | ; IF IDL FILE EXISTS, THAT IS RATHER SIMPLE |
---|
| 45 | ; |
---|
| 46 | IF (err EQ 0) THEN BEGIN |
---|
| 47 | |
---|
| 48 | print, 'read from file' |
---|
| 49 | free_lun,unit |
---|
| 50 | restore, filename=name_idl |
---|
| 51 | |
---|
| 52 | ; |
---|
| 53 | ; IF IDL FILE DOES NOT EXIST, WELL, READ NETCDF |
---|
| 54 | ; |
---|
| 55 | ENDIF ELSE BEGIN |
---|
| 56 | |
---|
| 57 | ; |
---|
| 58 | ; check save directory |
---|
| 59 | ; |
---|
| 60 | if (n_elements(nosave) eq 0) then SPAWN, 'mkdir -p idl_dat' |
---|
| 61 | |
---|
| 62 | ; |
---|
| 63 | ; open file |
---|
| 64 | ; |
---|
| 65 | id=ncdf_open(name) |
---|
| 66 | |
---|
| 67 | ; |
---|
| 68 | ; get dimensions |
---|
| 69 | ; |
---|
| 70 | var = intarr(4) |
---|
| 71 | NCDF_DIMINQ, id, NCDF_DIMID(id, 'west_east' ), toto, titi & var(0) = titi |
---|
| 72 | NCDF_DIMINQ, id, NCDF_DIMID(id, 'south_north' ), toto, titi & var(1) = titi |
---|
| 73 | NCDF_DIMINQ, id, NCDF_DIMID(id, 'bottom_top' ), toto, titi & var(2) = titi |
---|
| 74 | NCDF_DIMINQ, id, NCDF_DIMID(id, 'Time' ), toto, titi & var(3) = titi |
---|
| 75 | ;print, var |
---|
| 76 | |
---|
| 77 | ; |
---|
| 78 | ; define default data windows |
---|
| 79 | ; |
---|
| 80 | if (n_elements(offset) le 3) then offset=[0,0,0,0] |
---|
| 81 | if (n_elements(stride) le 3) then stride=[1,1,1,1] |
---|
| 82 | if (n_elements(count) le 3) then count=intarr(4) |
---|
| 83 | w = where(count eq 0) & if (w(0) ne -1) then count[w] = var[w] / stride[w] |
---|
| 84 | |
---|
| 85 | ; |
---|
| 86 | ; read variable |
---|
| 87 | ; |
---|
| 88 | varid=ncdf_varid(id,charvar) ;& print, 'get '+charvar |
---|
| 89 | if (n_elements(notime) eq 0) then timetime = SYSTIME(1) ;& help, /memory |
---|
| 90 | ncdf_varget, id, varid, invar, count=count, offset=offset, stride=stride & if (n_elements(notime) eq 0) then print, SYSTIME(1) - timetime, ' s' ;& help, /memory |
---|
| 91 | ncdf_close, id |
---|
| 92 | |
---|
| 93 | ; |
---|
| 94 | ; OPTIONAL: ANOMALY (value is returned in the keyword) |
---|
| 95 | ; |
---|
| 96 | if (n_elements(anomaly) ne 0) then begin |
---|
| 97 | anomaly=TOTAL(TOTAL(invar,1),1)/float(var[0])/float(var[1]) |
---|
| 98 | for i=0,var[0]-1 do for j=0,var[1]-1 do invar(i,j,*,*) = TEMPORARY(invar(i,j,*,*)) - anomaly ; coute cher ; pas tant |
---|
| 99 | endif |
---|
| 100 | |
---|
| 101 | ; |
---|
| 102 | ; OPTIONAL: MEAN |
---|
| 103 | ; |
---|
| 104 | if (n_elements(coordmean) ne 0) then begin |
---|
| 105 | for i=0,nc-1 do begin |
---|
| 106 | print, 'mean over dimension '+string(coordmean(i),'(I0)')+' - '+string(var(coordmean(i)),'(I0)')+' elements' |
---|
| 107 | invar=total(TEMPORARY(invar),coordmean(i))/var(coordmean(i)) |
---|
| 108 | endfor |
---|
| 109 | endif |
---|
| 110 | |
---|
| 111 | ; |
---|
| 112 | ; SAVE |
---|
| 113 | ; |
---|
| 114 | if (n_elements(nosave) eq 0) then save, invar, filename=name_idl |
---|
| 115 | |
---|
| 116 | ENDELSE |
---|
| 117 | |
---|
| 118 | if (n_elements(notime) eq 0) then print, SYSTIME(1) - timetime, ' s' |
---|
| 119 | |
---|
| 120 | ; |
---|
| 121 | ; RETURN FIELD |
---|
| 122 | ; |
---|
| 123 | return, invar |
---|
| 124 | |
---|
| 125 | end |
---|