Вы находитесь на странице: 1из 49

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS

Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D


____________________________________________________________________________________________________

SISTEMA DE VISUALIZACION Y ANALISIS DE GRILLA


(Grid Analysis and Display System - GrADS)
Ing. Jorge OTINIANO R. / Noviembre 2014

Actualmente el estado futuro (pronstico) de las diferentes variables atmosfricas en una


regin o dominio espacial, representado por ecuaciones diferenciales que gobiernan el
movimiento, es solucionado mediante esquemas de integracin numrica (modelo numrico).
Este procedimiento requiere realizar enormes cantidades de clculos, igualmente los
resultados resultan de inmensas cantidades de informacin y para la administracin y anlisis
grfico necesitan de un software especial.
En la dcada del 90, el Center for Ocean-Land-Atmosphere Studies - USA, desarroll un
software orientado al fcil manejo y anlisis de informacin, el Sistema de visualizacin y
Anlisis de Grilla y por sus siglas en ingls GrADS, es una herramienta de escritorio
interactiva y que se utiliza para el acceso, manipulacin, y visualizacin fcil de datos
oceanogrficos, geolgicos, atmosfricos, etc, que resultan de simulaciones numricas y/o
tambin en un conjunto de datos estructurados en matrices de 2D(x,y), 3D(x,y,z), 4D(x,y,z,t).
Los diferentes formatos que lee GraDS son los siguientes: GRIB1, GRIB2, NetCDF, o HDFSDS, geoTiff, y datos binarios.
Los datos se pueden exhibir usando una variedad de tcnicas grficas: lneas y grficos de
barra, diagramas de dispersin, suavizar los contornos, contornos sombreados, lneas
aerodinmicas, vectores del viento, grficos grillados y sombreados, serie temporal para punto
de la grilla o estacin. Los grficos se pueden grabar en formato PostScrip o de imagen en
diferentes formatos gif, png, jpej, bmp. El GrADS proporciona al usuario la opcin para
controlar todos los aspectos de las salidas grficas.
El GrADS tiene una interfaz programable (lenguaje scripting) que permite usos sofisticados
del anlisis y aplicaciones para la visualizacin. Utiliza programas de procedimientos (script)
para usar botones y cuadro de mens en la visualizacin grfica. El GrADS puede ser
accionado o ejecutado en modo batch, y el lenguaje de programacin script facilita al usuario
utilizar accesos directos a lo largo de todo el ambiente de trabajo.
El GrADS es la principal herramienta interactiva usada por la comunidad cientifica y/o
organismos nacionales internacionales con propsitos operacionales, acadmicos y de
investigacin (NCEP-NOAA, CPTEC, NWS, NCAR, SENAMHI, CORPAC, DHN, IGP,
UNALM, UNMSM). Se distribuye y se descarga gratuitamente en diversos sistemas
operativos, UNIX, Linux y Windows. La plataforma Linux es la ms verstil, con desarrollo
y actualizacin permanente. El Home page de GrADS es http://grads.iges.org/
Para los ensayos se utilizar la versin GrADS ejecutable para Linux (GraDS 2,0,1 versin
estable). aplicaciones complejas requieren tener conocimiento de programacin.

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

INDICE
1.

Requerimiento

2.

Herramientas Similares a GrADS

3.

Fuente de datos / informacin

4.

Formas de descarga de datos


4.1. Descarga de archivo total
4.2. Descarga de archivo selectivo (descarga parcial) a formato bin
4.2.1. Modo1
4.2.2. Modo2

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.

Ocultar un rea uso de una mascara


7.1 Ocultar con comando cmax y cmin
7.2 Sombreado con comando clevs y ccols
7.3 Mascara con comando maskout
7.4 Mascara con scrip basemap.gs
7.5 Sombreado con topografa

8.

Desarrollo de entorno grfico (Uso de botones)


8.1. Uso de set button y draw button
8.2. Uso de set dropmenu y draw dropmenu

9.

Lectura de imgenes de satlite (formato tiff)


9.1. Lectura directa sobre un sistema cartesiano x-y
9.2. Lectura directa sobre un sistema georeferenciado lat-lon aproximado
9.3. Lectura de imagen reordenada sobre un sistema georeferenciado lat-lon

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

1.

2.

Requerimiento:

Instalacion: soft grads 32 o 64 bits (adicionales, convert, gfortran, wget, perl,


ImageMagick)

Habilidades: conocimiento de linux basico interactivo, programacin, estructuracion


matricial, protocolos de transferencia

Unidad de Trabajo: Pc, laptop, usb

Donde bajar el software: http://grads.iges.org/grads/downloads.html


Indice de funciones: http://grads.iges.org/grads/gadoc/gadocindex.html
Gua del usuario: http://grads.iges.org/grads/gadoc/users.html
Manual en PDF: ftp://grads.iges.org/grads/beta/doc/gadoc151.pdf
Gua rpida: http://grads.iges.org/grads/gadoc/reference_card.pdf
Gua para scripts: http://grads.iges.org/grads/gadoc/reference_card_scl.pdf

Herramientas Similares a GrADS

3.

NCAR Command Language (NCL) - http://www.ncl.ucar.edu/


Ferret - http://www.ferret.noaa.gov/Ferret/
Otros - http://www.unidata.ucar.edu/software/
http://www.unidata.ucar.edu/software/netcdf/software.html
http://sourceforge.net/projects/opengrads/files/

Fuente de datos / informacin

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/

http://grads.iges.org/grads/gds/gds.html (modo interactivo script gs / GDS DODS)

>> 2014/AVHRR/

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

4.

Formas de descarga de datos


4.1 Descarga de archivo total
Directo via el display de la web, en comando de linea
Servidores publicos ftp con user anonymous
ftp ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2014101612/gfs.t12z.pgrbf06.grib2

Servidores publicos ftp con user registrado o privados con certificado de


seguridad .. \> ftp -in ftp://[user[:password]@]host[:port]/path[/]
ftp (enter)
open IP o web ftp (10.168.45.1 o ftp://dominio.u)
usuario (enter)
password (enter)
Servidores http
wget -in http://[user[:password]@]host[:port]/path] [...]
wget http://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2014101612/gfs.t12z.pgrbf06.grib2

Con programacin bashell (cshell, kshell), matlab, python, idl, ncl, perl, java, php
(archivo en la que se incluye funciones y comandos).

4.2 Descarga de archivo selectivo (descarga parcial) a formato bin


Uso de scrip gs (diseo para extraer data selectiva estructurado en forma
personalizada) uso de GDS DODS (http://nomads.ncep.noaa.gov/)
4.2.1

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

O directamente dentro del terminal /home/jorge/Lab_grads/


:~> /usr/local/bin/g2ctl Datos/xxxx.grib2 > ctl/yyy.ctl

O convertimos de grib2 a grib1


:~> /usr/local/bin/cnvgrib -g21 Datos/xxx.grib2 Datos/xxx.grib1
:~> /usr/local/bin/gribctl Datos/xxx.grib1 > ctl/archi.ctl

Ejm, datos grib2 ciclo 12z (condicin inicial), extrados desde


http://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2014110312/

gfs.t12z.pgrbf00.grib2
gfs.t12z.pgrbf03.grib2
gfs.t12z.pgrbf06.grib2
gfs.t12z.pgrbf09.grib2
gfs.t12z.pgrbf12.grib2
gfs.t12z.pgrbf15.grib2

condicin inicial (anlisis, t=0)


forecast +03
forecast +06
forecast +09
forecast +12
forecast +15

:~/Lab_grads> /usr/local/bin/g2ctl Datos/grib_nc/gfs.t12z.pgrbf00.grib2 > ctl/gfs_pgrbf_00z.ctl


:~/Lab_grads> /usr/local/bin/g2ctl Datos/grib_nc/gfs.t12z.pgrbf03.grib2 > ctl/gfs_pgrbf_03z.ctl

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

ga> (operar comandos grads, . )


En el caso de renombrar todos los archivos grib secuencialmente con los anos,
meses o tiempos y abrirlos con un solo controlador ctl, se deber modificar el ctl de
acuerdo con la secuencia.
Modificamos el ctl
dset
/../../gfs.t12z.pgrbf%f2.grib2
option little endian template
tdef 6 linear 12Z01jun2014 3hr
mapeamos con gribmap y continuamos con comandos grads
5.2 Lectura de datos NetCDF
Lectura directa del archivo archi.nc
en la linea de comando GrADS
ga>sdfopen Datos/archi.nc (enter)
ga> q file (enter)
ga> (operar comandos grads)
5.3 Lectura de datos bin
Depende como fue estructurado la descarga de datos binario, y coherente con la
estructura se generara un controlador ctl para su lectura.

Controlador ctl para el modo1 (modo1.ctl), para un solo tiempo (tdef 1)


dset /home/jorge/Lab_grads/Datos/modo1.bin
options little_endian
undef 9.999E20
title GFS_DODS-NOMADS
xdef 41 linear -95.00 1.0
ydef 36 linear -25.00 1.0
zdef 1 levels 1000
tdef 1 linear 12z16OCT2014 3hr
vars 4
presion 0 100 presion superficial hPa
ugrd 0 100 viento zonal m/s
vgrd 0 100 viento meridional m/s
tmp 0 100 temperatura superficial K
endvars
..... option estructurado como una variable y 4 niveles
zdef 4 levels 1 2 3 4
vars 1
var 4 99 ppp (hPa), ugrd (m/s), vgrd (m/s), tmp(K)
endvars

Controlador ctl para el modo2 (Peru_06z.ctl)


dset /home/jorge/Lab_grads/Datos/PERU_06z.bin
options little_endian

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

En la linea de comando GrADS (no necesita del mapeo o index)


:~> grads (enter)
ga>open /home/jorge/Lab_grads/ctl/Peru_06z.ctl (enter)
ga> (operar comandos grads)
5.4 Lectura de informacin
En el entorno de un scrip grads input.gs
5.4.1 Lectura desde el teclado
* Ejercicio de lectura de lineas, palabras y letras
ructl='/home/jorge/Lab_grads/ctl/Peru_06z.ctl'
'reinit'
'open 'ructl
say 'Ingrese Lat_min Lat_max: '
pull minmax
say 'minlat maxlat 'minmax
o tambien
prompt 'Ingrese Lat_min Lat_max: '
pull minmax
say 'minlat maxlat 'minmax
continua con comandos GrADS
en el entorno GrADS ejecutamos y ensayamos
ga->run gs/input.gs
5.4.2 Lectura desde un scrip usando un funcin
Supongamos que se requiera el ingreso de 3 variables para ejecutarse T, P y H
en un scrip (T,P y H son valores de temperatura del aire, presin y humedad)
en el scrip trocio.gs
* Ejercicio de lectura de datos con funcion (debe estar en la primera linea)
function datos(tph)
8

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

en el entorno GrADS ejecutamos y ensayamos


ga->run gs/station
5.4.5 Lectura desde la consola (uso del mouse)
Uso del comando q pos (captura de coordenadas de pantalla en el entorno
GrADS, 8x11 vertical o 11x8 horizontal, variacin 0.01 x pixel)
En el scrip captura.gs
* captura de coordenadas de la consola
'reinit'
rug='/home/jorge/Lab_grads/'
ructl=rug'ctl/Peru_06z.ctl'
'q pos'
. espera un click con el mouse en la ventana GrADS
x1=subwrd(result,3) . captura la 3ra col - linea resultados (coord X=Lon)
y1=subwrd(result,4) . captura la 3ra col - linea resultados (coord Y=Lat)
* Con la ubicacin x1,y1, podemos tomar como referencia para escribir
'draw mark 3 'x1' 'y1' '0.2
'set font 5';'set string 1 c 10';'draw string 'x1+0.2' 'y1' PERU'
* Trazando una linea (mnimo 2 puntos)
'q pos'
x2 = subwrd(result,3); y2 = subwrd(result,4)
'set line 2 1 6'
'draw line 'x1' 'y1' 'x2' 'y2
* Si deseamos trazar una linea entre 2 puntos, pejm entre SPCL y SPST
* SPCL: Lat= 08.41 Sur / Lon= 74.60 W
* SPST: Lat= 06.45 Sur / Lon= 76.49 W
* Convertimos los pts georeferenciados a pts de pantalla
'q w2xy - 74.60 -08.41'; x1=subwrd(result,3); y1=subwrd(result,6)
'q w2xy -76.49 -06.45'; x2=subwrd(result,3); y2=subwrd(result,6)
'draw line 'x1' 'y1' 'x2' 'y2
* Trazando un rea con un fondo color predeterminado,
* delimitado por las coordenadas entre SPCL-SPST-SPJR-SPNC
'set rgb 31 230 255 225'
'set rgb 41 225 255 255'
a1='31 1 3';'set line 'a1
ptjr='-78.48 -07.14'; ptnc='-76.20 -09.90'
'q w2xy 'ptjr; x3=subwrd(result,3); y3=subwrd(result,6)
'q w2xy 'ptnc; x4=subwrd(result,3); y4=subwrd(result,6)
ptos=x1' 'y1' 'x2' 'y2' 'x3' 'y3' 'x4' 'y4; 'draw polyf 'ptos
'set line 2 1 6'; 'draw line 'ptos' 'x1' 'y1
b1='41 1 3'; b2='0.52 1.25 2.46 1.80'
11

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set line 'b1; 'draw recf 'b2


en el entorno GrADS ejecutamos
ga->run gs/captura
5.5 Salida de informacin
Considerando el dominio de la informacin variables meteorolgicas esquematizada
en una matriz de 41x36x7x13 (41 puntos de latitud: 25 grados Sur a 10 grados Norte,
36 de longitud: 95 a 55 grados Oeste, 7 niveles:850 700 500 400 300 250 200 y 13
tiempos, controlador ejem1.ctl, archivo bin PERU_12z.bin)
5.5.1 Impresion en pantallla
en el scrip display.gs
* Visualizacion de datos en pantalla
'reinit'
rug='/home/jorge/Lab_grads/'
ructl=rug'ctl/Peru_06z.ctl'
'open 'ructl
** Visualizacion de Temp de todo el dominio 2D, niv: 850, t: 1 ......
* Por defecto (imprime cada 8 col de Lon para todas las Lat - filas)
'set t 1'
'set lev 850'
'set gxout print'
'd tmp'
datos=result
say datos
* (o simplemente say result)
pull s
* Visualizacion personalizada (control del formato de imresion y dominio)
'set lon -65 -56'
'set t 4'
'set lev 500'
'set gxout print'
'set prnopts %7.1f 10 1'
'd tmp'
say result
pull s
en el entorno GrADS ejecutamos
ga->run gs/display
5.5.2 Impresion en un archivo
en el scrip display_archi.gs
* Impresion de datos en un archivo
'reinit'
12

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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.

Generacin de datos binario


6.1 Desde un archivo nc o grib
Extraccin de variables, para una zona especificada y diversos tiempos
6.1.1 Caso 1 : file en formato NetCDF air.sig995.1948.nc, extrado desde
http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.surface.html/

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

Supongamos que contamos con 48 datos de temperatura, creamos un archivo binario,


luego creamos diferentes combinaciones de ctl, para graficarlo con grads
En el scrip datos_bin.gs
* almacenamiento de datos en formato bin
'reinit'
rulab_grd='/home/jorge/Lab_grads/'
archi_bin=rulab_grd'Datos/datos_bin.dat'
ructl=rulab_grd'ctl/Peru_06z.ctl'
*.................................................................
'open 'ructl
prompt 'Ingrese el nro de datos= '
pull nd
* ... almacenamos los datos en binario
'set gxout fwrite'
'set fwrite 'archi_bin
n=1
while (n<=nd)
prompt 'ingrese el dato 'n' ='
pull val
'd 'val
n=n+1
endwhile
'disable fwrite'
'close 1'
en el entorno GrADS ejecutamos
ga->run gs/datos_bin
Confeccionamos el file datos_bin.ctl, y dependiendo de como hemos ingresado
(estructurado) los datos se estructura el ctl.
6.2.1 CASO a: Datos temporales de una Estacin o un punto (48 datos)
considerando que los 48 datos corresponden a 24 horas de
temperatura, solo variara el tiempo
Caso a1: una variable con 48 horas en un nivel (nivel 0)
Datos 1D, z=1, t=48
* Datos temporales de una Estacion
dset /home/jorge/Lab_grads/Datos/datos_bin.dat
options little_endian
undef 9.999E20
title Ejercicio Generacion de Datos bin / Nov 2014
xdef 1 levels 0 (linear 1 1)
ydef 1 levels 0 (linear 1 1)
zdef 1 levels 0 (linear 1 1)
tdef 48 linear 12z17oct2014 1hr
vars 1
tmp 1 100 (tmp 0 100 , tmp 1 99)
15

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

* Controlador generado para leer datos generados


dset /home/jorge/Lab_grads/Datos/datos_bin.dat
options little_endian
undef 9.999E20
title Ejercicio Generacion de Datos bin / Nov 2014
xdef 8 linear 0 1
ydef 6 linear 0 1
zdef 1 levels 0 (linear 1 1)
tdef 1 linear 12z17oct2014 1hr
vars 1
tmp 1 100 (tmp 0 100 , tmp 1 99)
endvars
Caso b2: 2 variables para 1 tiempo (1 hora) en un nivel (nivel 4)
Datos 2D, 6X x 4Y, DX=DY=1, Ini_XY=0, z=1, t=1,
modificamos
xdef 6 linear 0 1
ydef 4 linear 0 1
zdef 1 levels 4
( zdef 1 linear 4 1)
tdef 1 linear 12z17oct2014 1hr
vars 2
tmp1 1 100 (tmp1 0 100 , tmp1 1 99)
tmp2 1 100 (tmp2 0 100 , tmp2 1 99)
Caso b3: 1 variable para 1 tiempo (1 hora) en 2 niveles (nivel 0, 4)
Datos 3D, 6X x 4Y, DX=DY=1, Ini_XY=0, z=2, t=1,
modificamos
xdef 6 linear 0 1
ydef 4 linear 0 1
zdef 2 levels 0 4
( zdef 2 linear 0 4)
tdef 1 linear 12z17oct2014 1hr
vars 1
tmp 1 100 (tmp 0 100 , tmp 1 99)
Caso b4: 2 variables para 1 tiempo (1 hora) en 2 niveles (nivel 4)
Datos 3D, 6X x 4Y, DX=DY=1, Ini_XY=0, z=2, t=1,
modificamos
xdef 4 linear 0 1
ydef 3 linear 0 1
zdef 2 levels 0 4
( zdef 2 linear 0 4)
tdef 1 linear 12z17oct2014 1hr
vars 2
tmp1 1 100 (tmp1 0 100 , tmp1 1 99)
tmp2 1 100 (tmp2 0 100 , tmp2 1 99)
6.2.3 CASO c: Datos espacio-temporales de un zona (48 datos)
17

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

Caso c1: una variable para 2 tiempos (2 horas) en un nivel (nivel 0)


Datos 3D, 6X x 4Y, DX=DY=1, Ini_XY=0, z=1, t=2
* Controlador generado para leer datos generados
dset /home/jorge/Lab_grads/Datos/datos_bin.dat
options little_endian
undef 9.999E20
title Ejercicio Generacion de Datos bin / Nov 2014
xdef 6 linear 0 1
ydef 4 linear 0 1
zdef 1 levels 0 (linear 1 1)
tdef 2 linear 12z17oct2014 1hr
vars 1
tmp 1 100 (tmp 0 100 , tmp 1 99)
endvars
Caso c2: 2 variables para 2 horas en un nivel (nivel 4)
Datos 3D, 4X x 3Y, DX=DY=1, Ini_XY=0, z=1, t=2,
modificamos
xdef 4 linear 1 1
ydef 3 linear 1 1
zdef 1 levels 4
tdef 2 linear 12z17oct2014 1hr
vars 2
tmp1 1 100
tmp2 1 100
Caso c3: 1 variable para 2 horas en 2 niveles
Datos 4D, 4X x 3Y, DX=DY=1, Ini_XY=1, z=2, t=1,
modificamos
xdef 4 linear 0 1
ydef 3 linear 0 1
zdef 2 levels 0 4 (zdef 2 linear 0 4)
tdef 2 linear 12z17oct2014 1hr
vars 1
tmp 2 100
Caso c4: 2 variable para 2 horas en 2 niveles
Datos 4D, 4X x 3Y, DX=DY=1, Ini_XY=1, z=2, t=1,
modificamos
xdef 3 linear 0 1
ydef 2 linear 0 1
zdef 2 levels 0 4 (zdef 2 linear 0 4)
tdef 2 linear 12z17oct2014 1hr
vars 2
tmp1 2 100
18

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

sus componentes, potencial de velocidades y funcin corriente estn definidas


como:
Si = Ux + C/2 Ln (x2 + y2)
Fi = Uy + C Atn(y/x)
u = d(Fi)/dx = U + Cx / (x2 + y2)
v = d(Fi)/dy = Cy / (x2 + y2)
Vc = (u2 + v2)0.5
Pn = ro/2 (Uo2 + Vc2)

(Funcin Potencial)
(Funcin Corriente)
(componente velocidad zonal)
(componente velocidad zonal)
(velocidad resultante)
(presin neta)

V y C: velocidad de la corriente infinita e intensidad de la fuente


respectivamente.
Para U= 10 m/s y C= 50 m2/s, Calculamos Fi, Si, u, v, Pn en el dominio
bidimensional finito limitado por Xmin= -40, Xmax= +60 / Ymin= -40, Ymax= +40,
x=y=1, lo guardaremos en formato binario
Luego generaremos el ctl adecuado para estos datos, para operar con grads y graficar
las lineas de corriente, equipotenciales y campo de velocidades
En el scrip Fpote_bin.gs
* Generacin de data binaria para Si,Fi, u,v, Pn
'reinit'
rulab_grd='/home/jorge/Lab_grads/'
ructl=rulab_grd'ctl/peru_bin.ctl'
archi_bin=rulab_grd'Datos/Fpote_bin.dat'
ructl_bin=rulab_grd'ctl/Fpote_bin.ctl'
Uo=10; C=50;ro=1000;nil=9.999E20
dx=1;dy=1;limx=100;limy=80
19

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

if (xp<0 & yp>0);xp=math_abs(xp);ddr=pi-math_atan2(yp,xp);endif


if (xp<0 & yp<0)
xp=math_abs(xp);yp=math_abs(yp)
ddr=pi+math_atan2(yp,xp)
endif
if (xp=0 & yp<0);ddr=3*pi/2;endif
if (xp>0 & yp<0);yp=math_abs(yp);ddr=2*pi-math_atan2(yp,xp);endif
return(ddr)
en donde ctrl.sh es un scrip bashell para insertar el control de linea
#!/bin/bash
arch1=/home/jorge/Lab_grads/ctl/Fpote_bin.ctl
arch2=/home/jorge/Lab_grads/ctl/aa.ctl
sed -e 's/$/\r/' $arch1 > $arch2
rm -f $arch1
mv $arch2 $arch1
Luego en el entorno GrADS operamos y ensayamos
ga>open ctl/Fpote_bin.ctl
ga> comandos grads
Caso a) confeccionar un gs para graficar
En el scrip Fpote_graf1.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
xmin=-40;xmax=60;ymin=-40;ymax=40
archi=rulab_grd'gif/Graf_pote.gif'
Xs=-C/Uo;Fs=C*pi;b=2*C*pi/Uo
*.................................................................
'open 'ructl_bin
'set mpdraw off'
'set grads off';'set grid on'
'set xaxis 'xmin' 'xmax
'set yaxis 'ymin' 'ymax
'set gxout shaded'
'set clevs 0'
'd maskout(fi,'Fs'-fi)'
'd maskout(fi,fi-'Fs')'
'set gxout contour'
'set cterp on'
'set cint 30'
'set ccolor 4'
'd fi'
'set ccolor 8'
22

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set arrlab off'


'set ccolor 6'
'set arrscl 0.6 45'
'd skip(u,4);v'
** sombrear el semi-cuerpo
xs=-C/Uo;ys=0;Fs=C*pi;b=2*C*pi/Uo
xoyo=xs' 'ys; 'q w2xy 'xoyo; x0=subwrd(result,3); y0=subwrd(result,6)
xnyn=xmax-1' 'b/2; 'q w2xy 'xnyn; xnp=subwrd(result,3); ynp=subwrd(result,6)
xnyn=xmax-1' -'b/2; 'q w2xy 'xnyn; xnm=subwrd(result,3); ynm=subwrd(result,6)

xmym=xmax-1' '0; 'q w2xy 'xmym; xm=subwrd(result,3); ym=subwrd(result,6)


amax=math_atan2(ynp,xnp)*180/pi
areap=x0' 'y0;arean=x0' 'y0
an=89
while (an>=amax)
minl=0;maxl=2*xmax
F=1000;i=1;cmax=10000
while (i<cmax)
rl=(minl+maxl)/2
xl=rl*math_cos(an*pii)-math_abs(xs)
yl=rl*math_sin(an*pii)
ang_rad=ang(xl,yl)
atna=subwrd(ang_rad,1)
Fl=Uo*yl+C*atna
F=Fs-Fl
if (F>0)
minl=rl
else
maxl=rl
endif
F=math_abs(F)
if (F<0.001)
xlyl=xl' 'yl; 'q w2xy 'xlyl; xr=subwrd(result,3); yr=subwrd(result,6)
areap=areap' 'xr' 'yr
xlyl=xl' -'yl; 'q w2xy 'xlyl; xr=subwrd(result,3); yr=subwrd(result,6)
arean=arean' 'xr' 'yr
i=cmax
endif
i=i+1
endwhile
an=an-1
if (an<amax)
areap=areap' 'xnp' 'ynp
arean=arean' 'xnm' 'ynm
endif
endwhile
areap=areap' 'xm' 'ym
arean=arean' 'xm' 'ym
24

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'draw polyf 'areap


'set line 2 1 6'
'draw line 'areap
'set line 1'
'draw polyf 'arean
'set line 2 1 6'
'draw line 'arean
'close 1'
'set string 4 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'
return
function ang(xp,yp)
* determinacio del angulo
pi=3.1415926
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
if (xp<0 & yp>0);xp=math_abs(xp);ddr=pi-math_atan2(yp,xp);endif
if (xp<0 & yp<0)
xp=math_abs(xp);yp=math_abs(yp)
ddr=pi+math_atan2(yp,xp)
endif
if (xp=0 & yp<0);ddr=3*pi/2;endif
if (xp>0 & yp<0);yp=math_abs(yp);ddr=2*pi-math_atan2(yp,xp);endif
return(ddr)
en el entorno GrADS ejecutamos
ga->run gs/Fpote_graf2
6.4 Desde un archivo
Supongamos que tenemos un archivo con datos horarios de temperatura de un mes
TMP_Ene2010.txt. Entonces construimos un scrip gs para leer, convertir a binario,
confeccionar el ctl para luego graficar con GrADS, el registro completo
En el scrip leetxt_cnvbin.gs
* Lectura de datos txt desde un archivo y generacin a data binaria
'reinit'
25

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

Ocultar o sombrear un rea uso de una mascara

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set fwrite -ap /../archi.bin'


o desde la linea de comando con
:~/home/jorge/Lab_grads/Datos/>cat arch1.bin arch2.bin arch3.bin >arch4.bin
En el scrip gs get_hgt.gs (extrae la altura geopoencial para 7 niveles)
* Extraccion de altura geopotencial desde NOMADS
'reinit'
dia=18;mes=11;ano=2014;hor=06z
'sdfopen http://nomads.ncep.noaa.gov:9090/dods/gfs/gfs'ano%mes%dia'/gfs_'hor
'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 /home/jorge/Lab_grads/Datos/hgtperu_06z.bin'
*'set fwrite -ap /home/jorge/Lab_grads/Datos/PERU_06z.bin'
t=1 ; tp=0 ; tmaxp=12
while(t<=tmaxp)
'set t 't
say ' hgt /850,..., 250, 200 hPa VALIDO '%dia%mes%ano' +'tp' hrs'

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/

Del archivo etopo5.xyz (DS=0.0833, 5 minutos), extraemos la topografa que


corresponden a los puntos de grilla del archivo PERU_06z.bin (DS=60 minutos)
construimos un scrip gs para leer el archivo etopo5.xyz y convertir a binario
en el scrip extrae_z.gs
* Generacin de data binaria del archivo etopo5.xyz
'reinit'
rulab_grd='/home/jorge/Lab_grads/'
28

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

l5='xdef 41 linear -95.000 1.0';lixo=write(ructl_bin,l5)


l6='ydef 36 linear -25.000 1.0';lixo=write(ructl_bin,l6)
l7='zdef 1 levels 1';lixo=write(ructl_bin,l7)
l8='tdef 1 linear 00z01oct2010 1hr';lixo=write(ructl_bin,l8)
l9='vars 1';lixo=write(ructl_bin,l9)
l10='z 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 ejecutamos
ga->run gs/extrae_z
Ahora leemos los 3 archivos binarios, PERU_06z.bin, hgtperu_06z.bin, topo_bin.dat
en el entorno GrADS ensayamos
ga->reinit
ga->open ctl/Peru_06z.ctl
ga->open ctl/hg_bin.ctl
ga->open ctl/topo_bin.ctl
ga->set dfile 1
ga->set lev 700
ga->set t 1
ga->define tp=tmp
ga->set dfile 2
ga->set lev 700
ga->set t 1
ga->define hp=hgt
ga->set dfile 3
ga->set lev 0
ga->set t 1
ga->define zp=z
ga->set gxout shaded
ga->d maskout(tp,hp-zp)
ga->set gxout contour
ga->d maskout(tp,hp-zp)
o construimos un scrip mask1.gs
* .... USO DE MASKOUT ...
'reinit'
'clear'
rulab_grd='/home/jorge/Lab_grads/'
ctl1=rulab_grd'ctl/Peru_06z.ctl'
ctl2=rulab_grd'ctl/hgtperu_bin.ctl'
ctl3=rulab_grd'ctl/topo_bin.ctl'
archi=rulab_grd'gif/maskara.gif'
*.................................................................
'open 'ctl1
30

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

* **** SOMBREADO SUPERPUESTO - USO DE DRAW POLYF *****


'reinit'
'clear'
rulab_grd='/home/jorge/Lab_grads/'
ctl1=rulab_grd'ctl/Peru_06z.ctl'
archi=rulab_grd'gif/maskara2.gif'
corte=rulab_grd'gs/corte_lat.gs'
*.................................................................
'open 'ctl1
'set mpdset lowres.per'
'set lat -15'
'set lev 850 200'
'set gxout shaded'
'd tmp'
'set gxout contour'
'd tmp-273'
'set gxout vector'
'set arrlab off'
'set ccolor 6'
'set arrscl 1.2 45'
'd ugrd;vgrd'
* Inclusion de la cordillera de los Andes
'run 'corte
'set string 1 c 5';'set strsiz 0.15'
'draw title SOMBREADO DEL PERFIL - CORDILLERA'
'set string 4 c 5';'set strsiz 0.10'
'draw string 7.5 0.4 IMF-UNMSM, Nov 07 - JOtiniano'
'printim 'archi' white'
return
y el scrip corte_lat.gs (que se invoca con la variable corte)
* **** 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_bin.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'
'set rgb 75 196 164 242'
'set dfile 2'
'set lev 0';'set t 1'
'set yaxis 850 200'
32

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set rgb 75 196 164 242'


'set dfile 2'
'set lev 0';'set t 1'
'set yaxis 850 200'
ncol=151;delta=0.166666666667
ini=-90;fin=ini+ncol*delta;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+delta;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
y su controlador topo_peru.ctl invoca a la topografia cada 10 minutos
* Controlador ctl para datos topograficos Region Peru cada 10 minutos
dset /home/jorge/Lab_grads/Datos/ETOPO/etopo_peru.bin
options little_endian yrev
undef 9.999E20
title Data Topografia Region Peru
xdef 151 linear -90.000 0.166666666667
ydef 145 linear -22.000 0.166666666667
zdef 1 levels 0
tdef 1 linear 00z01MAR2014 12hrs
vars 1
z 1 100 Topografia Peru cada 10minutos
endvars
En el entorno GrADS ejecutamos
ga>run gs/mask2

34

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

Desarrollo de entorno grfico (Uso de botones)


Entorno interactivo con el display usando botones y haciendo click sobre ellos
8.

8.1 Uso de set button y draw button


set button <color del button_ON> <color del button_OFF> thickness
Donde <button_ON> y <button_OFF> contiene 4 numeros de colores c/u:
text color del texto
face color del fondo del button
bcol color claro de la linea del contorno del button para visualizarlo en 3-D
dcol color intenso dark de la linea del contorno del button para visualizarlo en 3-D
draw button number xpos ypos width height string
En donde draw button esta centrado en xpos, ypos con los siguientes atributos:
nro
numero de button, 1 - 512
xpos
x centro del button en el sistema coordenado de la pagina (pulgadas)
ypos
y centro del button en el sistema coordenado de la pagina (pulgadas)
width ancho (x) del button (pulgadas)
height altura (y) del button (pulgadas)
string texto de visualizacin centrado en el button
Ejm., deseamos contar con 3 botones que deriven a ejecutar grficos de temperatura,
viento y precipitacin
en un scrip button1.gs de simple visualizacin de botones sin ejecucin de tareas
'reinit'
'set rgb 90 100 100 100'
'set rgb 91 50 50 50'
'set rgb 92 200 200 200'
*while (1)
'set button 1 90 91 92 2 90 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'
'q pos'
say result
pull s
*endwhile
En el entorno GrADS ejecutamos y ensayamos con el mouse
ga>run gs/button1
en el button2.gs visualizacin de botones con ejecucin de tareas
* Uso de entorno grafico con botones
'reinit'
35

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'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

result: 3[x] 4[y] 5[mouse izq(1),cen(2),der(3)] 6[button(1),rband(2), dropmenu(3)]


7[nro button] 8[posicion lista]

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

quit: regresa al terminal


endwhile

En el entorno GrADS ejecutamos y ensayamos con el mouse


ga>run gs/button2
8.2 Uso de set dropmenu y draw dropmenu
set dropmenu fc bc oc1 oc2 tfc tbc toc1 toc2 bfc bbc boc1 boc2 soc1 soc2 thick
Donde:
fc
menu base text color
bc
menu base face color
oc1 dark color of shadow outline for menu base
oc2 bright color of shadow outline for menu base
tfc
menu base text color when selected with a mouse click
tbc menu base face color when selected with a mouse click
toc1 dark color of shadow outline for menu base when selected
toc2 bright color of shadow outline for menu base when selected
bfc
menu list text color
bbc menu list face color
boc1 dark color of shadow outline for menu list
boc2 bright color of shadow outline for menu list
soc1 dark color of shadow outline for highlighted menu item
soc2 bright color of shadow outline for highlighted menu item
thick thickness of the shadow outline
draw dropmenu number xpos ypos width height text_list
En donde draw dropmenu tiene los siguientes atributos:
nro
numero de menu, 0 - 64
xpos
x centro de la base del menu en las coordenadas de la pagina (pulgadas)
ypos
y centro de la base del menu en las coordenadas de la pagina (pulgadas)
width
ancho (x) de la base del menu (pulgadas)
height
alto (y) de la base del menu (pulgadas)
text_list el contenido del menu, separado por barras verticales (|)
Ejm, deseamos contar con 3 botones principales que deriven en ejecutar grficos
En el diseo preliminar scrip button3.gs
'reinit'
'clear'
'set rgb 90 100 100 100'
'set rgb 91 50 50 50'
'set rgb 92 200 200 200'
'set string 7 c 6';'set strsiz 0.24'
while (1)
'set strsiz 0.24';'draw string 5.5 7.9 MONITOREO DE VARIABLES METEOROLOGICAS'
'set line 1';'draw recf 1.3 7.45 9.7 7.50'
'set dropmenu 1 4 91 92 2 90 92 91 1 90 91 92 92 91 6'
37

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set strsiz 0.12'


'draw dropmenu 1 2.5 7 2.0 0.6 Graf 2D x-y | Temperatura | Viento | Precipitacion'
'draw dropmenu 2 5.5 7 2.0 0.6 Graf 1D x-t | SPRU | SPIM | SPSO | SPTN'
'draw dropmenu 3 8.5 7 2.0 0.6 Graf 2D x-z | 20 Sur | 16 Sur | 12 Sur | 08 Sur'
'q pos'
result:
3[x] 4[y] 5[mouse izq(1),cen(2),der(3)] 6[button(1),rband(2),dropmenu(3)]
7[nro button_menu] 8[posi lista menu]
9[nro 1er_submenu de posi_lista_menu] 10[posi lista 1er_submenu]
11[nro 2do_submenu de posi_lista_1er_submenu], 12[posi lista 2do_submenu]
say result
* pull s
endwhile
*
*
*
*
*

En el entorno GrADS ensayamos


ga>run gs/button3
Para el mismo ejm., con la informacin contenida en PERU_06z.bin, deseamos que los 3
botones principales deriven en ejecutar los siguientes grficos:
1er boton: para graficos 2D x-y
3 submenu: temperatura, viento y precipitacin
2 submenu: para temperatura y viento, c/u con 7 niveles
4 submenu: para los tiempos +6 +12 +18 +24
2do boton: para graficos 1D tmp-t, rh-t
2 submenu: temperatura y humedad
4 submenu: zonas (SPRU, SPIM, SPSO, SPTN)
7 submenu: 7 niveles (850,700,500,400,300,250,200 hPa)
3er boton: para graficos 2D x-z (seccin transversal latitudinal)
2 submenu: temperatura y humedad
4 submenu: secciones transversales latitudinales (20 16 12 y
08 Sur)
4 submenu: para los tiempos +6 +12 +18 +24
En el scrip button4.gs mejoramos el diseo
* Visualizacion de graficos selectivo mediante un menu pre-disenado
'reinit'
'clear'
'set rgb 90 100 100 100'
'set rgb 91 50 50 50'
'set rgb 92 200 200 200'
'set string 7 c 6';'set strsiz 0.24'
'open ctl/Peru_06z.ctl'
'set mpdset hires'
while (1)
'set strsiz 0.24';'draw string 5.5 8.2 MONITOREO DE VARIABLES METEOROLOGICAS'
'set line 1';'draw recf 1.3 7.75 9.7 7.80'
'set dropmenu 1 4 91 92 2 90 92 91 1 90 91 92 92 91 6'
38

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'set strsiz 0.12'


'draw dropmenu 1 2.5 7.3 2.0 0.6 Graf 2D x-y | Temperatura >11> | Viento >11> | Precipitacion >21>|'
'draw dropmenu 11 cascade Niveles| 850 >21>| 700 >21>| 500 >21>| 400 >21>| 300 >21>| 250 >21>| 200 >21>|'
'draw dropmenu 21 cascade Tiempos| + 06z| + 12z| + 18z| + 24z|'
'draw dropmenu 2 5.5 7.3 2.0 0.6 Graf 1D x-t | Temperatura >12> | Humedad >12>|'
'draw dropmenu 12 cascade Estaciones| SPRU >22>| SPIM >22>| SPSO >22>| SPTN >22>|'
'draw dropmenu 22 cascade Niveles| 850| 700| 500| 400| 300| 250| 200|'
'draw dropmenu 3 8.5 7.3 2.0 0.6 Graf 2D x-z | Temperatura >13> | Humedad >13>|'
'draw dropmenu 13 cascade Secciones | 20 Sur >23>| 16 Sur >23>| 12 Sur >23>| 08 Sur >23>|'
'draw dropmenu 23 cascade Tiempos| + 06z| + 12z| + 18z| + 24z|'

*
*
*
*
*
*
*
*

'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

*
*

click Graf 1D x-t > humedad > SPSO > 400


Position = 5.75767 6.95616 1 3 2 2 12 4 22 5 -1 -1

*
*

click Graf 2D x-z > temperatura > 16 Sur > + 12z


Position = 8.63651 7.09812 1 3 3 1 13 3 23 3 -1 -1
menu1=subwrd(result,7)
item1=subwrd(result,8)
menu2=subwrd(result,9)
item2=subwrd(result,10)
menu3=subwrd(result,11)
item3=subwrd(result,12)
if (item1=-1);item1=1;endif
if (item2=-1);item2=1;endif
if (item3=-1);item3=1;endif
'set vpage 1.0 9.5 0 7'
if (menu1=1);say ' Graf 2D x-y'; var_niv_tp=vnt_b1(item1,item2,item3);endif
if (menu1=2);say ' Graf 1D x-t'; var_est_niv=ven_b2(item1,item2,item3);endif
if (menu1=3);say ' Graf 2D x-z'; var_la_tp=vlt_b3(item1,item2,item3);endif

'set vpage off'


endwhile
return
function vnt_b1(it1,it2,it3)
'clear'
'set lat -22 6';'set lon -95 -55'
if (it2=1);niv=850;endif
if (it2=2);niv=850;endif
if (it2=3);niv=700;endif
if (it2=4);niv=500;endif
if (it2=5);niv=400;endif
if (it2=6);niv=300;endif
if (it2=7);niv=250;endif
39

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

'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

En el entorno GrADS ejecutamos y ensayamos con el mouse


ga>run gs/button4
9.

Lectura de imgenes de satlite (formato tiff)


Las imgenes en formato tiff, contienen valores de 0 a 255 que corresponden a los niveles
de grises (de negro a blanco) o niveles digitales que describen las diferentes intensidades
de luz (relacionados con la reflectancia o intensidad del flujo de radiacin
electromagntica)
Estas imgenes tienen un cabecero de 8 lineas (metadata que indica el nro de lineas, nro
de columnas, nro total de pixeles, tipo de dato almacenado), puede ser ledo con GrADS.
El proyecto de la NASA GOES Project Science en su web http://goes.gsfc.nasa.gov
difunde imgenes de satlite de sectores del mundo en formato TIFF (Tagged Image File
Format), comprimidas con el algoritmo LZW (Lempel-Ziv-Weich), para las bandas
espectrales IR2, IR3, IR4, IR5, IR6, VIS, ademas los archivos con las coordenadas
relativos a cada pixel.
Para el caso del sector Per http://goes.gsfc.nasa.gov/goeseast/peru/,
Como ejm extraemos una imagen IR4
En la linea de comando de un terminal extraemos y descompress la imagen IR4-Per
>wget -nd http://goes.gsfc.nasa.gov/goeseast/peru/ir4/1411191545G13I04.tif
>convert -compress none 1411191545G13I04.tif latest.tif
9.1. Lectura directa sobre un sistema cartesiano x-y
Construimos un controlador ctl para leer directamente los pixeles (saltando la
cabecera de 8 lineas) y montarlos en un sistema cartesiano x-y 1200x862
en el ctl ir4_header_xy.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 1 1
ydef 862 linear 1 1
zdef 1 levels 1
tdef 1 linear 15:45z18nov2014 30mn
vars 1
pix 0 -1,40,1 pixel
endvars
En el entorno GrADS ensayamos

42

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

>gunzip -vf peru_1006011745_G13I01_L_int.nav.gz


Leemos el archivo binario peru_1006011745_G13I01_L_int.nav para extraer hacia
un archivo (goesnav_peru.txt), las coordenadas Lat y Lon
En el programa fuente read_goesnav.f
C Programa para extraer las coordenadas Lat, Lon
program leergoesnav
integer*2 data(2)
dimension coordenadas(862,1200)
open(1,file="peru_1006011745_G13I01_L_int.nav",status="old",
& access="direct",recl=4)
open (2,file="goesnav_peru.txt")
do i=3,1200*862+2
read(1,rec=i) data
12

write(2,12) data
format (2(1x,i6))
enddo
end

En el terminal, dentro de la carpeta goes, compilamos el programa


>gfortran -o goesnav.exe read_goesnav.f

43

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

real dif_1, dif_2


real my_grid_lat(0:872),my_grid_lon(0:1270)
open(1,file="latest.tif",access="direct",
& recl=1034408,status="old")
read(1,rec=1) data !lee la imagen tif y lo guarda en data
close(1)
i1=1
j1=1
do i=1,1034400
j=i+8
data_fin(i)=data(j) !guarda la imagen pura sin cabecera
if (i1.GT.1200) then
j1=j1+1
i1=1
data2(i1,j1)=data(j)
i1=i1+1
else
data2(i1,j1)=data(j)
i1=i1+1
endif
enddo
C ====FIN EXTRACCION DE LA IMAGEN GRILLA IRREGULAR======
C

C
c

45

*** Pasa la lat y lon de la imagen a una matriz grilla_lat y grilla_lon


open(23,file="goesnav_peru.txt")
do l=1, 862
do k=1, 1200
read(23,*) nlat,nlon
grilla_lat(k,l)=nlat/100.
grilla_lon(k,l)=nlon/100.
enddo
enddo
close(23)
**** Coordenadas iniciales y delimitacion de la grilla regular
0.037653891*5 + 12.95
my_grid_lat(0)=13.138269455
do j=1,872
my_grid_lat(j)=my_grid_lat(j-1)-0.037653891
enddo
-0.038765638*35 - 98.29
my_grid_lon(0)=-99.64679733
do j=1,1270
my_grid_lon(j)=my_grid_lon(j-1)+0.038765638
enddo
**** Reproyectando las coordenadas
write(*,*)"Reproyectando en el eje Y"
do i=1, 1200
l=1
do j=1, 862
do k=l, 872
if (my_grid_lat(k).eq.grilla_lat(i,j)) then

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

**** Grabando en un file la data con grilla regular


open(22,file="latest.bin",access="direct",
& recl=1107440,status="unknown")
write(22,rec=1) dataf_lon
close(22)
write(*,*) "SE GENERO SATISFACTORIAMENTE LA IMAGEN"
end
C....................................................................................................................
46

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

LABORATORIO: VISUALIZACION DE RESULTADOS DE LOS MODELOS NUMERICOS


Y CONJUNTO DE DATO ESTRUCTURADO MATRICIALMENTE2D,3D Y 4D
____________________________________________________________________________________________________

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

Вам также может понравиться