Академический Документы
Профессиональный Документы
Культура Документы
INDICE
1.
Requerimiento
2.
3.
4.
5.
5.1.
5.2.
5.3.
5.4.
5.5.
6.
6.1
6.2
6.3
6.4
Lectura/salida de Datos
Lectura de datos grib
Lectura de datos NetCDF
Lectura de datos bin
Lectura de informacin
5.4.1. Lectura desde el teclado
5.4.2. Lectura desde un scrip usando una funcin
5.4.3. Lectura desde un scrip usando comandos del sistema
5.4.4. Lectura desde un archivo externo
5.4.5. Lectura desde la consola (uso del mouse)
Salida de informacin
5.5.1. Impresin en pantalla
5.5.2. Impresin en un archivo
Generacin de datos binario
Desde un archivo nc o grib
6.1.1. Caso 1: file en formato NetCDF
6.1.2. Caso 2: file en formato grib
6.1.3. Caso 3: file en formato geotiff
Desde la consola ingresando datos
6.2.1. Caso a: Datos temporales
6.2.2. Caso b: Datos espaciales
6.2.3. Caso c: Datos espacio-temporales
Usando una funcin o ecuacin
Desde un archivo
7.
8.
9.
1.
2.
Requerimiento:
3.
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/wave/prod/ >> prod/wave.20141016/
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/
>> gfs.2014101612/
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/
>> sst.20141014/
http://www.esrl.noaa.gov/psd/data/gridded/
http://www.esrl.noaa.gov/psd/data/reanalysis/
http://www.esrl.noaa.gov/webswitch.html
http://www.cpc.ncep.noaa.gov/products/wesley/reanalysis.html
http://nomads.ncep.noaa.gov/
http://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/
http://www.cpc.ncep.noaa.gov/products/wesley/reanalysis.html
http://nomads.ncep.noaa.gov:9090/dods/gfs_hd/ >> gfs_hd20141016/gfs_hd_00z
http://nomads.ncep.noaa.gov:9090/dods/rtofs/
http://nomads.ncdc.noaa.gov/
http://nomads.ncdc.noaa.gov/data/
ftp://eclipse.ncdc.noaa.gov/pub/OI-daily-v2/NetCDF/
>> 2014/AVHRR/
4.
Con programacin bashell (cshell, kshell), matlab, python, idl, ncl, perl, java, php
(archivo en la que se incluye funciones y comandos).
Modo1 de descarga
en el scrip modo1.gs
'reinit'
dia=18;mes=11;ano=2014;hor=06z
serv='http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs'ano%mes%dia'/gfs_'hor
arch='/home/jorge/Lab_grads/Datos/PERU_06z.bin'
'sdfopen 'serv
'set lat -25 10';'set lon -95 -55'
'set gxout fwrite'
'set fwrite /home/jorge/Lab_grads/Datos/modo1.bin'
'set t 1'
'd prmslmsl'
'd ugrd10m'
'd vgrd10m'
'd tmp2m'
'disable fwrite'
4.2.1
Modo2 de descarga
en el scrip get_var.gs
'reinit'
dia=18;mes=11;ano=2014;hor=06z
serv='http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs'ano%mes%dia'/gfs_'hor
arch='/home/jorge/Lab_grads/Datos/PERU_06z.bin'
'sdfopen 'serv
'set lat -25 10';'set lon -95 -55'
lev.1=850;lev.2=700;lev.3=500
lev.4=400;lev.5=300;lev.6=250;lev.7=200
'set gxout fwrite'
'set fwrite 'arch
t=1;tp=0;tmaxp=24
while(t<=tmaxp)
'set t 't
'd ugrd10m'
'd vgrd10m'
'd tmp2m'
'd rh2m'
'd apcpsfc'
say ' u /850,..., 250, 200 hPa VALIDO '%dia%mes%ano' +'tp' hrs'
z=1
while(z<=7)
'set lev 'lev.z
'd ugrdprs'
z=z+1
endwhile
say ' v /850,... , 250,200 hPa VALIDO '%dia%mes%ano' +'tp' hrs'
z=1
while(z<=7)
'set lev 'lev.z
'd vgrdprs'
z=z+1
endwhile
say ' tmp /850,..., 250,200 hPa VALIDO '%dia%mes%ano' +'tp' hrs'
z=1
while(z<=7)
'set lev 'lev.z
'd tmpprs'
z=z+1
endwhile
say ' rh /850,..., 250,200 hPa VALIDO '%dia%mes%ano' +'tp' hrs'
z=1
while(z<=7)
'set lev 'lev.z
'd rhprs'
z=z+1
endwhile
say ' PP,u,v,T,rh (10m) VALIDO '%dia%mes%ano' +'tp' hrs'
t=t+2;tp=tp+6
endwhile
'disable fwrite'
5
5.
Lectura/salida de Datos
5.1 Lectura de datos grib
Requiere de un controlador de datos ctl y de un index (mapeo), uso de gribmap que
invoca al ctl y genera el index. Mayor detalle de la estructura del ctl observe el
siguiente link http://grads.iges.org/grads/gadoc/aboutgriddeddata.html
En el caso de no contar con el archivo ctl, deber crearse, comnmente con g2ctl.pl
que invoca al aplicativo wgrib2 (32 o 64 bits).
Si hay problemas para leer la data grib2 debido al procesador (32 bits), se podr
convertir a grib1 usando el aplicativo cnvgrib.
en un terminal
:~> cd /usr/local/bin/
:~> perl g2ctl /home/jorge/Lab_grads/Datos/xxxx.grib2 > /home/jorge/Lab_grads/ctl/yyy.ctl
gfs.t12z.pgrbf00.grib2
gfs.t12z.pgrbf03.grib2
gfs.t12z.pgrbf06.grib2
gfs.t12z.pgrbf09.grib2
gfs.t12z.pgrbf12.grib2
gfs.t12z.pgrbf15.grib2
O convertimos a grib1
:~/Lab_grads> /usr/local/bin/cnvgrib -g21 Datos/grib_nc/gfs.t12z.pgrbf00.grib2Datos/grib_nc/
gfs.t12z.pgrfb00.grb1
:~/Lab_grads> /usr/local/bin/gribctl Datos/grib_nc/gfs.t12z.pgrfb00.grb >ctl/gfs_pgrfb_g1.ctl
Luego: generar el index y abrir el archivo grib con grads (previamente verificamos
en el ctl creado el enrutamiento al archivo binario)
:~> /usr/local/bin/gribmap -e -i ctl/gfs_pgrbf_00z.ctl
En el entorno GrADS
:~> grads (enter)
ga>!gribmap -e -i ctl/archi.ctl (enter)
ga> open ctl/archi.ctl (enter)
6
undef 9.999E20
title GFS_DODS-NOMADS / Feb 2011 - JOR
xdef 41 linear -95.00 1.0
ydef 36 linear -25.00 1.0
zdef 7 levels 850 700 500 400 300 250 200
tdef 12 linear 06z18NOV2014 6hr
vars 9
u10m 1 100 viento zonal superficie
v10m 1 100 viento meridional superficie
tmp2m 1 100 temperatura superficial
rh2m 1 100 humedad relativa superficial
rain
1 100 precipitacion acumulada c/6 hrs
ugrd 7 100 viento zonal 850,700,500,400,300,250,200 hPa
vgrd 7 100 viento meridional 850,700,500,400,300,250,200 hPa
tmp
7 100 temperatura 850,700,500,400,300,250,200 hPa
rh
7 100 humedad relativa 850,700,500,400,300,250,200 hPa
endvars
if (tph='')
say 'Use: trocio T P H'
return
else
temp= subwrd(tph,1)
pres= subwrd(tph,2)
hum= subwrd(tph,3)
endif
say 'temp= 'temp' pres= 'pres' hum= 'hum
say ' OK continua con los calculo'
pull s
continua con comandos GrADS
en el entorno GrADS ejecutamos y ensayamos
ga->run gs/trocio 20 1012 85
5.4.3 Lectura desde un scrip usando comandos del sistema
en el scrip fsistema.gs
* Ejercicio de lectura de datos con comandos del sistema
ructl='/home/jorge/Lab_grads/ctl/Peru_06z.ctl'
'reinit'
'open 'ructl
query file
rec_lin=sublin(result,1)
rec_wrd=subwrd(rec_lin,1)
rec_str=substr(rec_wrd,2,3)
say 'aaaaaaaaaaaaa 'rec_lin
say 'bbbbbbbbbbb 'rec_wrd
say 'cccccccccccc 'rec_str
pull s
q dim
q time
q gxinfo
q config
*.. variante, usando while
n=1;max=100
while (n<=max)
rec_lin=sublin(result,n)
if (rec_lin='')
say ' Termino de las lineas ';n=max
else
say strlen (rec_lin)' aaaaaaaaaaaaa 'rec_lin
say strlen (rec_lin)' xxx 'aa
pull s
endif
n=n+1
endwhile
9
en el entorno GrADS
ga->run gs/fsistema ejecutamos y ensayamos
5.4.4 Lectura desde un archivo externo
Considerando un archivo ascii con extensin prn ubicado en:
/home/jorge/Lab_grads/Datos/Station.prn
La lectura consta de 2 lineas, la primera retorna el cdigo y la 2da los datos
Los cdigos de retorno son:
0 ok (existe la linea)
1 error de apertura
2 final del archivo
8 archivo abierto para escritura
9 I/O error
En el scrip station.gs
* Scrip para leer datos de un archivo
'reinit'
archi_stn='/home/jorge/Lab_grads/Datos/Station.prn'
result=read(archi_stn)
........ lee el primer registro
linea1=subline(result,1)
........ retorna el cdigo
linea2=subline(result,2)
........ lee la linea de datos
col1=subwrd(linea2,1)
........ 1ra columna de la linea de datos
col4=subwrd(linea2,4)
........ 4ta columna de la linea de datos
say 'codigo= 'linea1
say 'datos = 'linea2
say 'col1 = 'col1
say 'col4 = 'col4
pull s
Para mltiples registros o lectura de todo el archivo
n=1;max=1000
while (n<=max)
result=read(archi_stn); linea1=subline(result,1)
if (linea1=2)
n=max
else
linea2=subline(result,2)
col1=subwrd(linea2,1)
say 'col2 = 'col2
say 'col3 = 'col3
say 'col4 = 'col4
pull s
endif
n=n+1
endwhile
close(archi_stn)
10
rug='/home/jorge/Lab_grads/'
ructl=rug'ctl/Peru_06z.ctl'
rusal=rug'Datos/salida1.txt'
'open 'ructl
* Impresion en un archivo de Temp de todo el dominio 2D, niv: 500, t: 4 ......
'set t 4'
'set lev 500'
'set gxout print'
'set prnopts %6.1f 5 1'
'd tmp'
datos=result
rc=write(rusal,datos)
* para adicionar rc=write(rusal,datos, append)
say 'xxxx '
pull s
en el entorno GrADS ejecutamos
ga->run gs/display_archi
6.
Extraemos datos de temperatura superficial del aire para una regin limitada de
Per, limitado por lat: 20 0 Sur / lon: 80 a 60 Oeste / 4 tiempos (1 dia)
En el scrip extrae_nc.gs
* Extraccion de datos desde un archivo nc global
'reinit'
archi_nc='/home/jorge/Lab_grads/Datos/air.sig995.1948.nc'
archi_bin='/home/jorge/Lab_grads/Datos/air.sig995.1948.bin'
*...............................................................................................
'sdfopen 'archi_nc
'set lat -20 0'; 'set lon -80 -60'
'set gxout fwrite'
'set fwrite 'archi_bin
tt=0
while (tt<=4)
'd air'
tt=tt+1
endwhile
'disable fwrite'
en el entorno GrADS ejecutamos
13
ga->run gs/extrae_nc
6.1.2 Caso 2 : file en formato grib pgbh00.gdas.201406.00z.grib2, extrado desde
http://nomads.ncdc.noaa.gov/modeldata/cfsv2_analysis_monthlymeans_pgb/2014/201406/
Generamos el ctl con perl y wgrib2 (64 bits), luego mapeamos con grib2map
Para 32 bits el archivo gfs.t12z.pgrbf00.grib2 que se extrajo previamente
Extraemos la presin superficial, temperatura del aire en 700 hpa, u, v en 500
hpa y geoptencial en 300 hpa para una regin limitada de Per, limitado por lat:
20 0 Sur / lon: 90 a 55 Oeste / tiempo inicial / res 1x1 lat/lon
En el scrip extrae_grb.gs
* Extraccion de datos desde un archivo grib global
'reinit'
archi_grb='/home/jorge/Lab_grads/Datos/grib_nc/gfs.t12z.pgrbf00.grib2'
archi_bin='/home/jorge/Lab_grads/Datos/grib_nc/gfs.t12z.pgrbf00.bin'
*...............................................................................................
'open 'archi_grb
'set lat -20 0'; 'set lon -90 -55'
'set gxout fwrite'
'set fwrite 'archi_bin
'd skip(PRESsfc,1,1)'
'd skip(TMPprs(lev=700),1,1)'
'd skip(UGRDprs(lev=500),1,1)'
'd skip(VGRDprs(lev=500),1,1)'
'd skip(HGTprs(lev=300),1,1)'
'disable fwrite'
en el entorno GrADS ejecutamos
ga->run gs/extrae_grb
6.1.3 Caso 3 : file en formato geotiff, convierte el mapa de GrADS (versiones 2.0 o
superiores) a un formato georreferenciado, el mismo que puede utilizarse
directamente en SIGs
Pejm, si deseamos extraer un rea con datos de temperatura superficial (2m)
desde el archivo grib2 a formato geotiff
en el scrip extrae_geo.gs
* Extraccion de formato grib a formato geotiff
'open 'archi_grb
'set lat -20 0'; 'set lon -90 -55'
'set geotiff TEMP_sfc'
'set gxout geotiff'
'd TMP2m'
6.2 Desde la consola ingresando datos
14
endvars
Caso a2: 2 variables C/u 24 horas en un nivel (nivel 0)
Datos 1D, z=1, t=24, modificamos
tdef 24 linear 12z17oct2014 1hr
vars 2
tmp1 1 100
tmp2 1 100
Caso a3: 1 variables C/u 24 horas en 2 niveles (0, 2)
Datos 2D, z=2, t=24, modificamos
zdef 2 levels 0 2 (linear 0 2)
tdef 24 linear 12z17oct2014 1hr
vars 1
tmp 2 100
Caso a4: 1 variables C/u 12 horas en 4 niveles (1,2,3,4)
Datos 2D, z=4, t=12, modificamos
zdef 4 levels 1 2 3 4 (linear 1 1)
tdef 12 linear 12z17oct2014 1hr
vars 1
tmp 4 100
Caso a5: 2 variables C/u 8 horas en 3 niveles (0, 3, 5)
Datos 2D, z=3, t=8, modificamos
zdef 3 levels 0 3 5
tdef 8 linear 12z17oct2014 1hr
vars 2
tmp1 3 100
tmp2 3 100
Caso a6: 3 variables C/u 8 horas / 1ra var:1 nivel, la 2da var: 2 niveles: (0,2),
la 3ra var: 3 niveles (0, 2, 4)
Datos 2D, z=3, t=8, modificamos
zdef 3 levels 0 2 4
(linear 0 2)
tdef 8 linear 12z17oct2014 1hr
vars 1
tmp1 1 100 .. 1ra variable
tmp2 2 100 .. 2da variable en 2 niveles
tmp2 3 100 .. 3ra variable en 3 niveles
6.2.2 CASO b: Datos espaciales de un zona (48 datos)
Caso b1: una variable para un tiempo (1 hora) en un nivel (nivel 0)
Datos 2D, 8X x 6Y, DX=DY=1, Ini_XY=0, z=1, t=1
16
tmp2 2 100
Luego en el entorno GrADS leemos el archivo bin con el ctl (y sus modificaciones)
ga>open ctl/datos_bin.ctl
ga> (operar comandos grads)
Nota: si se presenta un error de lectura del file datos_bin.ctl
Entonces en la linea de comando de un terminal subdirectorio ctl, ejecutar
:~> sed -e 's/$/\r/' datos_bin.ctl > aa.ctl
:~> mv aa.ctl datos_bin.ctl
6.3 Usando una funcin o ecuacin
Ejm: generacin de lineas de corriente y campo de velocidades para un flujo
potencial incompresible
Para una fuente potencial en el seno de un campo de velocidades infinito, la funcin
de variable compleja del movimiento esta definida como:
F(z) = VZ + C lnZ ,
Z = x + iy
(Funcin Potencial)
(Funcin Corriente)
(componente velocidad zonal)
(componente velocidad zonal)
(velocidad resultante)
(presin neta)
xmin=-40;xmax=60;ymin=-40;ymax=40
*.................................................................
'open 'ructl
* ... almacenamiento de los datos en binario
'set gxout fwrite'
'set fwrite 'archi_bin
var=1;maxv=5
while (var<=maxv)
y=ymin
while (y<=ymax)
x=xmin
while (x<=xmax)
if (var=1)
say ' calculo de Si: funcion potencial'
if (x=0 & y=0)
Si=nil
'd 'Si
else
aa= x*x+y*y; lna=math_log(aa)
Si = Uo*x+(C/2)*lna
'd 'Si
endif
endif
if (var=2)
say ' calculo de Fi: funcion corriente'
ang_rad=ang(x,y)
atna=subwrd(ang_rad,1)
Fi = Uo*y+C*atna
'd 'Fi
endif
if (var=3)
say ' calculo de u: componente zonal'
if (x=0 & y=0)
u=nil
'd 'u
else
u=Uo + C*x/(x*x+y*y)
'd 'u
endif
endif
if (var=4)
say ' calculo de v: componente meridional'
if (x=0 & y=0)
v=nil
'd 'v
else
v=C*y/(x*x+y*y)
'd 'v
endif
20
endif
if (var=5)
say ' calculo de Pn: presion neta'
if (x=0 & y=0)
Pn=nil
'd 'Pn
else
Vc2=(u*u+v*v)
Pn=(ro/2)*(Uo*Uo+Vc2)
'd 'Pn
endif
endif
x=x+1
endwhile
y=y+1
endwhile
var=var+1
enwhile
'disable fwrite'
'close 1'
* Generamos el controlador Fpote_bin.ctl
l0='* Controlador generado para leer Flujo Potencial';lixo=write(ructl_bin,l0)
l1='dset 'archi_bin;lixo=write(ructl_bin,l1)
l2='options little_endian';lixo=write(ructl_bin,l2)
l3='undef 9.999E20';lixo=write(ructl_bin,l3)
l4='title Flujo Potencial / Oct 2004 - JOR';lixo=write(ructl_bin,l4)
l5='xdef 'limx+1' linear 'xmin' 'dx;lixo=write(ructl_bin,l5)
l6='ydef 'limy+1' linear 'ymin' 'dy;lixo=write(ructl_bin,l6)
l7='zdef 1 levels 1';lixo=write(ructl_bin,l7)
l8='tdef 1 linear 00z10oct2004 1hr';lixo=write(ructl_bin,l8)
l9='vars 5';lixo=write(ructl_bin,l9)
l10='Si 1 100';lixo=write(ructl_bin,l10)
l11='Fi 1 100';lixo=write(ructl_bin,l11)
l12='u 1 100';lixo=write(ructl_bin,l12)
l13='v 1 100';lixo=write(ructl_bin,l13)
l14='Pn 1 100';lixo=write(ructl_bin,l14)
l15='endvars';lixo=write(ructl_bin,l15)
close(ructl_bin)
'!sh /home/jorge/Lab_grads/util/ctrl.sh'
return
function ang(xp,yp)
* determinacion del angulo
pi=3.141516
if (xp>=0 & yp=0);ddr=0;endif
if (xp=0 & yp>0);ddr=pi/2;endif
if (xp>0 & yp>0);ddr=math_atan2(yp,xp);endif
if (xp<0 & yp=0);ddr=pi;endif
21
'd si'
'set cint 1';'set ccolor 1';'d mag(u,v)'
'set gxout vector'
'set arrlab off'
'set ccolor 6'
'set arrscl 0.6 45'
'd skip(u,4);v'
'close 1'
'set string 1 c 6';'set strsiz 0.18'
'draw string 5.6 8.0 SEMI-OVALO DE RANKINE EN FLUJO UNIFORME'
'set strsiz 0.15';'set font 1'
'draw string 7.0 4.9 Uo = 'Uo
'draw string 7.0 4.6 In = 'In
'draw string 7.0 4.3 Xs = 'Xs
'draw string 7.0 4.0 Fs = 'Fs
'draw string 7.0 3.7 b = 'b
'set string 1 c 5';'set strsiz 0.10'
'draw string 7.5 0.4 IMF-UNMSM, Nov 07 - JOtiniano'
'printim 'archi' white'ddr=math_atan2(yp,xp)
en el entorno GrADS ejecutamos
ga->run gs/ Fpote_graf1
Caso b) modificar el scrip Fpote_graf.gs para sombrear el semi-ovalo
En el scrip Fpote_graf2.gs
* **** SEMI-OVALO DE RANKINE EN FLUJO UNIFORME *****
'reinit'
'clear'
rulab_grd='/home/jorge/Lab_grads/'
ructl_bin=rulab_grd'ctl/Fpote_bin.ctl'
Uo=10; C=50;ro=1000;pi=3.1415926;pii=pi/180
xmin=-40;xmax=60;ymin=-40;ymax=40
archi=rulab_grd'gif/Graf_pote.gif'
*.................................................................
'open 'ructl_bin
'set mpdraw off'
'set grads off';'set grid on'
'set xaxis 'xmin' 'xmax
'set yaxis 'ymin' 'ymax
'set gxout contour'
'set cterp on'
'set cint 30'
'set ccolor 4';'d fi'
'set ccolor 8';'d si'
'set cint 1'
'set ccolor 1';'d mag(u,v)'
'set gxout vector'
23
rulab_grd='/home/jorge/Lab_grads/'
ructl=rulab_grd'ctl/Peru_06z.ctl'
archi_txt=rulab_grd'Datos/TEMP_Ene2010.txt'
archi_bin=rulab_grd'Datos/Tempe_bin.dat'
ructl_bin=rulab_grd'ctl/Tempe_bin.ctl'
nil=9.999E20
*.................................................................
'open 'ructl
* Lectura y almacenamiento de los datos txt en binario
'set gxout fwrite'
'set fwrite 'archi_bin
rc=read(archi_txt);rc=read(archi_txt);rc=read(archi_txt);rc=read(archi_txt)
nf=1;fmax=31;n=0
while (nf<=fmax)
rec=read(archi_txt);linea=sublin(rec,2)
nc=2;cmax=25
while (nc<=cmax)
dato=subwrd(linea,nc)
'd 'dato
n=n+1;nc=nc+1
endwhile
nf=nf+1
endwhile
'disable fwrite'
'close 1';close(archi_txt)
* Generamos el controlador ctl para la data bin creada
l0='* Controlador generado para leer Datos de Temperatura';lixo=write(ructl_bin,l0)
l1='dset 'archi_bin;lixo=write(ructl_bin,l1)
l2='options little_endian';lixo=write(ructl_bin,l2)
l3='undef 'nil;lixo=write(ructl_bin,l3)
l4='title Temperatura SPCL Ene 2010';lixo=write(ructl_bin,l4)
l5='xdef 1 linear 1 1';lixo=write(ructl_bin,l5)
l6='ydef 1 linear 1 1';lixo=write(ructl_bin,l6)
l7='zdef 1 levels 1';lixo=write(ructl_bin,l7)
l8='tdef 'n' linear 00z01oct2010 1hr';lixo=write(ructl_bin,l8)
l9='vars 1';lixo=write(ructl_bin,l9)
l10='temp 1 100';lixo=write(ructl_bin,l10)
l11='endvars';lixo=write(ructl_bin,l11)
close(ructl_bin)
'!sh /home/jorge/Lab_grads/util/ctrl.sh'
return
en el entorno GrADS ensayamos
ga->run gs/leetxt_cnvbin
7.
26
7.1 Mascara con comando cmax y cmin: oculta los valores en punto de grilla por
encima o por debajo de un valor especificado. Consideramos el archivo
PERU_06z.bin
En la linea de comando GrADS ensayamos
ga-> reinit
ga-> open ctl/peru_bin.ctl
ga-> q file
ga-> set gxout shaded
ga-> set cmax 267
ga-> d tmp
ga-> c
ga-> set cmax 267
ga-> set cmin 264
ga-> d tmp
7.2 Sombreado con comando clevs y ccols: sombrea (shaded) rangos de valores
especificado en clevs con matiz de colores especificado en ccols
En la linea de comando GrADS ensayamos
ga-> reinit
ga-> open ctl/peru_bin.ctl
ga-> set gxout shaded
ga-> d tmp10m-273
ga-> c
ga-> set clevs 12 14 16 18 22 26 30
ga-> set ccols 2 4 6 8 10 12 14 15
ga-> d tmp10m-273
ga-> run /usr/local/lib/gs/cbar
7.3 Mascara con comando maskout: oculta la variable en los puntos de grilla para
cierta condicin especificada
En el entorno GrADS ensayamos
ga-> define mask= maskout(tmp,tmp-273)
ga-> d mask
ga->define maskz=maskout(tmp, hgt-z)
donde hgt es la altura geopotencial del modelo y z es la topografia (del etopo)
Entonces es necesario contar con la data binaria de hgt y de z
La hgt lo extraemos con GDS DODS desde http://nomads.ncep.noaa.gov/, para la
misma rea y mismo intervalo y tiempos
Los datos binarios de hgt y z se pueden tener archivos independientes con sus
respectivos ctl o adicionados al archivo principal PERU_06z.bin (solo para el
tiempo=1, osea tdef 1) y modificar el ctl agregando las nuevas variables
La adicin puede hacerse directamente con el scrip gs modificando la linea
27
z=1
while(z<=7)
'set lev 'lev.z
'd hgtprs'
z=z+1
endwhile
t=t+2;tp=tp+6
endwhile
'disable fwrite'
en el entorno GrADS ejecutamos
ga->run gs/get_hgt
Modificamos el ctl, modificamos vars 10 y adicionamos al final hgt 7 99 altura
geopotencial (solo para tdef 1). Para tdef >1 cambiara la estructura.
Usaremos la data binaria individual de hgt con su respectivo ctl (extraer sin -ap)
Ahora construimos la data binaria para la topografa (rea e intervalo similares)
http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO5/TOPO/ETOPO5/
http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO2/NVODS/
ructl=rulab_grd'ctl/Peru_06z.ctl'
archi_txt=rulab_grd'Datos/ETOPO/etopo5.xyz'
archi_bin=rulab_grd'Datos/ETOPO/topo_bin.dat'
ructl_bin=rulab_grd'ctl/topo_bin.ctl'
nil=9.999E20
*.................................................................
'open 'ructl
* lectura de la cabecera del archivo etopo5
n=1
while (n<=7)
rc=read(archi_txt)
n=n+1
endwhile
* almacenamos los datos en binario
'set gxout fwrite'
'set fwrite 'archi_bin
nf=1;maxf=36
while(nf<=maxf)
nc=1;maxc=40
while(nc<=maxc)
rec=read(archi_txt);fin=sublin(rec,1);xyz=sublin(rec,2)
x=subwrd(xyz,1);y=subwrd(xyz,2);z=subwrd(xyz,3)
'd 'z
snc=1;smaxc=11
while(snc<=smaxc)
rec=read(archi_txt)
snc=snc+1
endwhile
nc=nc+1
endwhile
rec=read(archi_txt);fin=sublin(rec,1);xyz=sublin(rec,2)
x=subwrd(xyz,1);y=subwrd(xyz,2);z=subwrd(xyz,3)
'd 'z
snf=1;smaxf=(12*40+1)*11
while(snf<=smaxf)
rec=read(archi_txt)
snf=snf+1
endwhile
nf=nf+1
endwhile
'disable fwrite'
'close 1';close(archi_txt)
*..........................................................................................................................
* Generamos el controlador ctl
l0='* Controlador generado para Datos de Topografia';lixo=write(ructl_bin,l0)
l1='dset 'archi_bin;lixo=write(ructl_bin,l1)
l2='options little_endian';lixo=write(ructl_bin,l2)
l3='undef 'nil;lixo=write(ructl_bin,l3)
l4='title Topografia / ETOPO60';lixo=write(ructl_bin,l4)
29
'open 'ctl2
'open 'ctl3
'set mpdset lowres.per'
'set dfile 1';'set lev 700';'set t 1'
'define tp=tmp'
'define up=ugrd'
'define vp=vgrd'
'set dfile 2';'set lev 700';'set t 1'
'define hp=hgt'
'set dfile 3';'set lev 0';'set t 1'
'define zp=z'
'set gxout shaded'
'd maskout(tp,hp-zp)'
'set gxout contour'
'd maskout(tp,hp-zp)'
'set gxout vector'
'set arrlab off' ; 'set ccolor 6' ; 'set arrscl 0.2 45'
'd skip(maskout(up,hp-zp),3);maskout(vp,hp-zp)'
* ....................................
'set string 1 c 5';'set strsiz 0.15'
'draw title USO DEL MASKOUT'
'set string 1 c 5';'set strsiz 0.10'
'draw string 7.5 0.4 IMF-UNMSM, Nov 07 - JOtiniano'
'printim 'archi' white'
return
en el entorno GrADS ejecutamos
ga->run gs/mask1
7.4 Mascara con scrip basemap.gs: oculta los puntos de grilla de zona de tierra o de
mar
Se requiere contar con el scrip gs (/usr/local/lib/gs/basemap.gs)
En el entorno GrADS ensayamos
ga->reinit
ga->open ctl/Peru_06z.ctl
ga->d tmp
ga->run /usr/local/lib/gs/basemap L 0 1 (tierra color blanco linea negra)
ga->run /usr/local/lib/gs/basemap L 4 2 (tierra colo azul linea roja)
ga->run /usr/local/lib/gs/basemap L 15 2 M (tierra color gris linea roja)
ga->run /usr/local/lib/gs/basemap O 0 1 (mar color blanco linea negra)
ga->run /usr/local/lib/gs/basemap O 4 2 (mar colo azul linea roja)
ga->run /usr/local/lib/gs/basemap O 15 2 M (mar color gris linea roja)
7.5 Sombreado con topografa: sombrea o superpone un zona sobre el grfico
principal (uso del comando draw polyf y draw line)
En el scrip mask2.gs
31
ini=-95;fin=-55;n=1;topo=''
While (ini<=fin)
'set lon 'ini
'd lon';xg=subwrd(result,4)
'd z';flz=subwrd(result,4)
**
pp=niv(flz)
if (flz<=0)
yg=850
'q w2xy 'xg' 'yg; xp=subwrd(result,3); yp=subwrd(result,6)
topo=topo' 'xp' 'yp
if (n=1);x0=xp;y0=yp;endif
else
rc=math_exp(-1.17*flz/10000)
yg=1014.78*rc
if (yg>=850); yg=850;endif
'q w2xy 'xg' 'yg; xp=subwrd(result,3); yp=subwrd(result,6)
topo=topo' 'xp' 'yp
if (n=1);x0=xp;y0=yp;endif
endif
ini=ini+1;n=n+1
endwhile
* topo=topo' 'x0' 'y0
'set line 41 1 3'; 'draw polyf 'topo
'set line 4 1 6'; 'draw line 'topo
return
En el entorno GrADS ejecutamos
ga>run gs/mask2
El perfil puede mejorarse si la resolucin de la topografa es mayor, como en el caso
de usar la topografa cada 10 minutos (DX=0.166666666667)
Es necesario leer el etopo.xyz y convertirlo los datos de profundidad a binario ..Datos/ETOPO/etopo_peru.bin, y su ctl ..ctl/topo_peru.ctl
En el scrip mask2.gs modificamos la linea
corte=rulab_grd'gs/corte_lat.gs' por corte=rulab_grd'gs/corte2_lat.gs'
En donde el scrip corte2_lat.gs lee la topografa cada 10 minutos
* **** INCLUSION DEL PERFIL LATITUDINAL DE LA CORDILLERA *****
* cambio de z(topo) a p(nivel de presion) p = 1014.78*exp(-1.17*10^-4*z)
rutop='/home/jorge/Lab_grads/ctl/topo_peru.ctl'
'open 'rutop
'set rgb 21 255 250 170'
'set rgb 31 230 255 225'
'set rgb 41 225 255 255'
'set rgb 62 255 200 200'
'set rgb 72 240 220 210'
'set rgb 73 244 184 104'
'set rgb 74 250 190 250'
33
34
'open ctl/peru_bin.ctl'
'set mpdset hires'
'set rgb 90 100 100 100'
'set rgb 91 50 50 50'
'set rgb 92 200 200 200'
while (1)
'set button 1 4 91 92 2 6 92 91 6'
'draw button 1 1.5 8.0 2 0.5 Temperatura'
'draw button 2 4.0 8.0 2 0.5 Viento'
'draw button 3 6.5 8.0 2 0.5 Precipitacion'
'set button 4 7 44 47 0'
'draw button 10 1.2 0.75 2 0.5 >> SALIR <<'
'q pos'
*
*
*
*
*
36
say result
pull s
menu=subwrd(result,7)
'set vpage 2.5 10 0 8'
Grafico de Temperatura
if (menu=1)
'clear'
'set gxout contour'
'd tmp'
endif
Grafico de Viento
if (menu=2)
'clear'
'set gxout vector'
'd skip(ugrd,3);vgrd'
endif
Grafico de Precipitacion
if (menu=3)
'clear'
'set gxout shaded'
'set cmin 2'
'd rain'
'run /usr/local/lib/gs/cbar'
'set gxout contour'
'd rain'
'set gxout vector'
'd skip(ugrd,2);vgrd'
endif
'set vpage off'
if (menu=10);return;endif
return; break: regresa al entorno GrADS
*
*
*
*
*
*
*
*
'q pos'
say result
click Graf 2D x-y > temperatura > 850 > + 06z
Position = 2.7189 6.90292 1 3 1 1 11 2 21 2 -1 -1
click Graf 2D x-y > temperatura > 500 > + 18z
Position = 2.59451 6.95616 1 3 1 1 11 4 21 4 -1 -1
click Graf 2D x-y > viento > 200 > + 12z
Position = 2.1147 6.95616 1 3 1 2 11 8 21 3 -1 -1
click Graf 2D x-y > precipitacion
Position = 2.09693 7.02714 1 3 1 3 -1 -1 -1 -1 -1 -1
*
*
*
*
if (it2=8);niv=200;endif
if (it3=2);tp=2;endif
if (it3=3);tp=3;endif
if (it3=4);tp=4;endif
if (it3=5);tp=5;endif
* control de tp para la precipitacion
if (it3=1)
niv=850
if (it2=2);tp=2;endif
if (it2=3);tp=3;endif
if (it2=4);tp=4;endif
if (it2=5);tp=5;endif
endif
'set grads off';'set grid on'
'set arrlab off';'set csmooth on'
'set lev 'niv
'set t 'tp
'query time'
fecha=subwrd(result,3)
* Variable Temperatura
if (it1=1)
'set gxout contour'
'd tmp-273'
'draw title TEMPERATURA (C) - Nivel:'niv' - Valido:'fecha
endif
* Variable Viento
if (it1=2)
'set gxout contour'
'd mag(ugrd,vgrd)'
'set gxout vector'
'd skip(ugrd,3);vgrd'
'draw title VIENTO (m/s) - Nivel:'niv' - Valido:'fecha
endif
* Variable Precipitacion
if (it1=3)
'set gxout shaded'
'set cmin 2'
'd rain'
'run /usr/local/lib/gs/cbar'
'set gxout contour'
'd rain'
'set gxout vector'
'd skip(ugrd,2);vgrd'
'draw title PRECIPITACION (mm) - Nivel:'niv' - Valido:'fecha
endif
return
function ven_b2(it1,it2,it3)
'clear'
if (it2=2);aero='SPRU';la=08.10;lo=79.04;endif
if (it2=3);aero='SPIM';la=12.00;lo=77.10;endif
if (it2=4);aero='SPSO';la=13.75;lo=76.29;endif
if (it2=5);aero='SPTN';la=18.08;lo=70.30;endif
if (it3=2);niv=850;endif
if (it3=3);niv=700;endif
if (it3=4);niv=500;endif
if (it3=5);niv=400;endif
40
if (it3=6);niv=300;endif
if (it3=7);niv=250;endif
if (it3=8);niv=200;endif
'set grads off';'set grid on'
'set arrlab off';'set csmooth on'
'set lat -'la; 'set lon -'lo
'set lev 'niv
'set t 1'
'query time'
fecha=subwrd(result,3)
'set t 1 last'
* Variable Temperatura
if (it1=1)
'd smth9(tmp)-273'
'draw title TEMPERATURA (C) vel:'niv' - Valido:'fecha
endif
* Variable Humedad
if (it1=2
'd smth9(rh)'
'draw title HUMEDAD (%) - Nivel:'niv' - Valido:'fecha
endif
'set t 1'
return
function vlt_b3(it1,it2,it3)
'clear'
if (it2=2);la=20;endif
if (it2=3);la=16;endif
if (it2=4);la=12;endif
if (it2=5);la=08;endif
if (it3=2);tp=2;endif
if (it3=3);tp=3;endif
if (it3=4);tp=4;endif
if (it3=5);tp=5;endif
'set grads off';'set grid on'
'set arrlab off';'set csmooth on'
'set lat -'la;'set lon -95 -55';niv=850
'set lev 'niv
'set t 'tp
'query time'
fecha=subwrd(result,3)
'set lev 850 200'
* Variable Temperatura
if (it1=1)
'set gxout contour'
'd tmp-273'
'set gxout contour'
'draw title TEMPERATURA (C) - Nivel:'niv' - Valido:'fecha
endif
* Variable Humedad
if (it1=2)
'set gxout shaded'
'set clevs 10 20 30 40 50 60 70 80 90'
'set ccols 0 5 11 4 10 3 7 12 8 2 15'
'd rh'
41
'run /usr/local/lib/gs/cbarn'
'set gxout contour'
'd rh'
*
'run gs/corte2_lat.gs'
'draw title HUMEDAD (%) - Nivel:'niv' - Valido:'fecha
endif
return
42
ga>open goes/ir4_header_xy.ctl
ga>d pix
ga>c
ga>set mpdraw off
ga>set xaxis 1 1200 100
ga>set yaxis 1 862 50
ga>d pix
ga>set gxout shaded
ga>set mpdraw off
ga>set xaxis 1 1200 100
ga>set yaxis 1 862 50
ga>d pix
9.2. Lectura directa sobre un sistema georeferenciado lat-lon aproximado
Modificamos el controlador ctl para montar sobre un sistema coordenado
cartesiano LatxLon, indicando la Lat inical y su incremento, la Lon inicial y su
incremento.
Para Lat_ini, dlat es necesario conocer las coordenadas Lon que corresponde al
primer y ultimo pixel de la 1ra linea (osea Lon para x=1 y para x=1200)
Para Lon_ini, dlon es necesario conocer las coordenadas Lat que corresponde al
primer y ultimo pixel de la 1ra columna (osea Lon para y=1 y para y=862)
Extraemos el archivo de coordenadas de cada pixel de la imagen, para el Per
>wget -nd http://goes.gsfc.nasa.gov/goeseast/peru/maps/peru_1006011745_G13I01_L_int.nav.gz
write(2,12) data
format (2(1x,i6))
enddo
end
43
Ejecutamos
>./goesnav.exe
Abrimos el archivo goesnav_peru.txt y verificamos
Para x= 1
Lon= -98.29
Para x= 1200 Lon= -51.81
===> dlon = (98.29-51.81)/(1200-1) = 0.038765638
Para y= 1
Lat= 12.95
Para y= 862 Lat= -19.47
===> dlat = (12.95+19.47)/(862-1) = 0.037653891
en el ctl ir4_header_lalo.ctl
* Controlador CTL para leer imag tiff descompress
dset /home/jorge/Lab_grads/goes/latest.tif
options yrev little_endian
undef 9999
fileheader 8
xdef 1200 linear -98.29 0.038765638
ydef 862 linear -19.47 0.037653891
zdef 1 levels 1
tdef 1 linear 15:45z18nov2014 30mn
vars 1
pix 0 -1,40,1 pixel
endvars
En el entorno GrADS ensayamos
ga>open goes/ir4_header_lalo.ctl
ga>d pix
ga>c
ga>set mpdset lowres.pe
ga>set gxout shaded
ga>d pix
9.3. Lectura de imagen reproyectada sobre un sistema georeferenciado lat-lon
Como los pixeles de la imagen TIFF corresponden a una grilla variable
(curvilinea), es necesario reproyectarla a la grilla cartesiana de GrADS, entonces
cada pixel de la imagen delimitado por sus coordenadas Lat, Lon deber
reproyectarse al pixel coordenado Lat, Lon de GrADS mas cercano.
En el programa fuente reproyeccion_pe.f
C ==================DIC 2007 JOtiniano====================
C Programa para reproyectar los pixeles de la grilla variable de la
C imagen IR4 GOES a una grilla regular ortogonal (cartesiana) de GrADS
program reproyeccion
byte data_byte, data(1034408),data_fin(1034400),data2(1200,862),
& dataf_lat(1200,872), dataf_lon(1270,872)
real grilla_lat(1200,862), grilla_lon(1200,862),
& grilla_lon2(1200,872)
44
C
c
45
dataf_lat(i,k)=data2(i,j)
grilla_lon2(i,k)=grilla_lon(i,j)
l=l+1
elseif ((my_grid_lat(k).lt.grilla_lat(i,j)).and.
&
(my_grid_lat(k).gt.grilla_lat(i,j+1))) then
dif_1=abs(grilla_lat(i,j)-my_grid_lat(k))
dif_2=abs(my_grid_lat(k)-grilla_lat(i,j+1))
if (dif_2.gt.dif_1) then
dataf_lat(i,k)=data2(i,j)
grilla_lon2(i,k)=grilla_lon(i,j)
l=l+1
else
dataf_lat(i,k)=data2(i,j+1)
grilla_lon2(i,k)=grilla_lon(i,j+1)
l=l+1
endif
endif
enddo
enddo
enddo
write(*,*) "Reproyectando en el eje X"
do j=1, 872
l=1
do i=1,1200
do k=l, 1270
if (my_grid_lon(k).eq.grilla_lon2(i,j)) then
dataf_lon(k,j)=dataf_lat(i,j)
l=l+1
elseif ((my_grid_lon(k).gt.grilla_lon2(i,j)).and.
&
(my_grid_lon(k).lt.grilla_lon2(i+1,j))) then
dif_1=abs(grilla_lon2(i,j)-my_grid_lon(k))
dif_2=abs(my_grid_lon(k)-grilla_lon2(i+1,j))
if (dif_2.gt.dif_1) then
dataf_lon(k,j)=dataf_lat(i,j)
l=l+1
else
dataf_lon(k,j)=dataf_lat(i+1,j)
l=l+1
endif
endif
enddo
enddo
enddo
C
compilamos el programa
>gfortran -o repro_pe.exe reproyeccion_pe.f
Ejecutamos
>./repro_pe.exe
Modificamos el ctl ir4_header_lalo.ctl de acuerdo con la nueva grilla regular
En el ctl para la grilla regular ir4_goes.ctl
* Controlador CTL para leer imag tiff descompress
dset /home/jorge/Lab_grads/goes/latest.bin
options yrev little_endian
undef 9999
xdef 1270 linear -99.64679733 0.038765638
ydef 872 linear -19.695923497 0.037653891
zdef 1 levels 1
tdef 1 linear 15:45z18nov2014 30mn
vars 1
pix 0 -1,40,1 pixel
endvars
En el entorno GrADS ensayamos
ga>open goes/ir4_goes.ctl
ga>d pix
ga>c
ga>set mpdset lowres.pe
ga>set gxout shaded
ga>d pix
En el scrip ir4_goes.gs incluimos ademas el campo de vientos en 500Hpa del
archivo PERU_06z.bin
'reinit'
ru='/home/jorge/Lab_grads/'
rugds=ru'ctl/Peru_06z.ctl'
rugoes=ru'goes/ir4_goes.ctl'
rugif=ru'goes/ir4_goes.gif'
cbar='/usr/local/lib/gs/cbar2'
*..........................
'open 'rugoes
'clear'
'set mpdset lowres.per'
'set map 1 1 0.1'
********** IMAGEN REGION PERU **********
'set lat -19 1';'set lon -84 -66'
'set ylopts 1 9 0.10'; 'set xlopts 1 9 0.10'
'd lat';'d lon'
'set t 1'
'q time'
47
rec = subwrd(result,3)
hhg = substr(rec,1,2)%substr(rec,4,2)
h1g = substr(rec,1,2)+substr(rec,4,2)/60
ddg = substr(rec,7,2)
mmg = substr(rec,9,3)
yyg = substr(rec,12,4)
'set gxout shaded'
'set csmooth on'
'd pix'
'run 'cbar
'close 1'
****** INCLUSION DE VIENTOS 500 HPA - NOMADS-GDS **********
'open 'rugds
'set lat -19 1';'set lon -84 -66'
'set t 1';'set lev 500'
'q time'
rec = subwrd(result,3)
hhmi = substr(rec,1,2)
ddmi = substr(rec,4,2)
mmmi = substr(rec,6,3)
yymi = substr(rec,9,4)
'set t 2'
'q time'
rec = subwrd(result,3)
hhm = substr(rec,1,2)
ddm = substr(rec,4,2)
mmm = substr(rec,6,3)
yym = substr(rec,9,4)
'set gxout vector'
'set arrscl 0.2';'set ccolor 1'
'd skip(ugrd,3,3); vgrd'
'set string 1 c 10';'set strsiz 0.14'
'draw string 4.3 10.84 LABORATORIO GRADS - UNALM'
'set strsiz 0.10'
'draw string 4.3 10.64 GOES 13 IR4 - 'ddg' 'mmg' 'yyg' 'hhg'UTC
Fuente:
NASA'
'draw string 4.3 10.44 Wind C.I. 'ddmi%mmmi%yymi'_'hhmi'UTC Valido: 'ddm
%mmm%yym'_'hhm'UTC LEV: 500HPA Fuente: MODEL GFS'
'set display color white'
'printim 'rugif' gif x850 y950'
'close 1'
return
En el entorno GrADS ejecutamos
ga>run gs/ir4_goes
Mejoramos la resolucin del grfico (1000x1250), la densidad de los vectores de
viento, ademas insertamos los aeropuertos y la paleta de topes de nubes
48
En el scrip ir4_goes.gs
Modificamos el color del perfil (color blanco)
'set map 0 1 0.1'
Eliminamos la etiqueta GrADS insertando (para cada open)
'set grads off'
Aadimos la paleta de topes de nubes (matiz_a.gs previamente
desarrollada)
* 'd pix'
'run 'ru'/gs/matiz_a';'d pix'
'run 'cbar
'run 'ru'/gs/matiz_b';'d pix'
'set string 1 c 6';'set strsiz 0.10'
'draw string 1.15 0.20 FL >>';'draw string 2.15 0.20 30000'
'draw string 3.00 0.20 34000';'draw string 4.10 0.20 37000'
'draw string 5.47 0.20 41000';'draw string 6.55 0.20 45000'
'draw string 7.57 0.20 49000'
'set string 0 c 05'; 'set strsiz 0.08'
'set gxout line';'set line 0'
'run 'ru'/gs/aerop'
Modificamos el color y aumentamos la densidad del campo de vientos
'set arrscl 0.2';'set ccolor 7'
'd skip(ugrd,1,1); vgrd'
Modificamos y aumentamos la resolucin del grfico
'printim 'rugif' gif x1000 y1250'
En el entorno GrADS ejecutamos nuevamente
ga>run gs/ir4_goes
49