Posts

Fortran: "Hello world!"

FORTRAN: (Found in 1950s, latest version released: 2018) (.F90 is the extension mostly used in modern Fortran scripts) (Fortran is CASE INSENSITIVE ) ( SAVE the below script as " hello.f90" , then COMPILE using " gfortran hello.f90 -o hello ", then RUN the file "hello" as " ./hello ") The script: Program Hello     Print *, "Hello World!" End Program

Python: How to plot grouped bar graph?

The script: (SAVE this below script with ".py" or ".ipynb" extensions) import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np sns.set() departure=pd.read_csv('file.csv') departure df = pd.DataFrame(departure, columns = ['year', 'var1', 'var2', 'var3']) print(df) plt.figure(figsize=(9,6)) pos = list(range(len(df['var1']))) width = 0.25 N=35 ind = np.arange(N) fig, ax = plt.subplots(figsize=(40,15)) plt.bar(pos, df['var1'], width, alpha=0.5, color='#059C1E') plt.bar([p + width for p in pos], df['var2'], width, alpha=0.5, color='#1032E0') plt.bar([p + width*2 for p in pos], df['var3'], width, alpha=0.5, color='#000000') ax.set_ylabel('Y-AXIS',fontweight='bold') plt.xlabel('Year', fontweight='bold') ax.set_title('Title') plt.xlim(min(pos)-width, max(pos)+width*4) plt.ylim([-42, max(df['var1'...

GrADS: How to draw a Hovmoller (or Hovmuller) diagram?

Image
Output image The script: *********HOVMOLLER********** 'reinit' 'set display color white' 'c' 'set grads off' 'set grid off' 'run colors.gs' 'set xlint 6' 'set xlopts 1 6 0.13' 'set ylopts 1 6 0.13' 'sdfopen file9.nc' 'set t 1 68' 'define plon1=ave(uas,lon=70,lon=90)' 'set lat 0 37' 'set grads off' 'set clab off' 'set x 1' 'set ylabs 1989 | 1990 | 1991 | 1992 | 1993 | 1994 | 1995 | 1996 | 1997 | 1998 | 1999 | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 ' *'set parea 0.7 3.7 0.81 7.81' 'set display color white' 'set gxout shaded' 'color 0 10 1 -kind grainbow' 'd plon1' 'run cbar' *'xcbar 0.69 6.97 0.35 0.51 -fw 0.08 -fh 0.09 -fs 1 -line on -edge triangle -dir h' 'set string 1 l 6' 'set strsiz 0.11' 'draw title Hovmoller diagram' *'draw string 0.7 7.93 ERA' 'printim ou...

GrADS: Some useful prerequisite scripts - vec.gs

Save the below script as " vec.gs " in a text editor: The script: function vec (args) variable=subwrd(args,1) autopl  = 'on' scl = 0 strlast='' hdsz=0.15 * examine options are set or not n=2 while(n<10000) idx=subwrd(args,n) opt=subwrd(args,n+1) if(idx='');break;endif if(idx='-P')  cxleft =subwrd(args,n+1)  cylow  =subwrd(args,n+2)  autopl ='off'  n=n+3 endif if(idx='-SCL')  size=subwrd(args,n+1)  magni=subwrd(args,n+2)  scl=1  n=n+3 endif if(idx='-SL')  strlast=subwrd(args,n+1)  n=n+2 endif if(idx='-HDSZ')  hdsz=subwrd(args,n+1)  n=n+2 endif endwhile *** set default arrow labeling off 'set arrlab on' if(autopl='off');'set arrlab off';endif *** set arrow scale if(scl=1); 'set arrscl 'size ' 'magni;endif *** draw the vector 'display 'variable *** draw the vector arrow label if(autopl='off')  if(scl=0)   say '!! CANNOT PLOT Arrow Label: Set allow scale...

GrADS: How to plot a wind circulation pattern at a particular atmospheric pressure level with "u" and "v" wind vector components?

Image
The script: ********wind_at_870hPa****for_2007JJAS***** 'reinit' *'set display color white' *'c' 'set xlopts 4 8 .2' 'set ylopts 3 6 .2' 'set xlint 6' 'set ylint 5' *'set grads off' 'set grid off' 'run colors' ***************** 'open file8.nc.ctl' 'set z 18' *'set mpdset rupres' *'set cthick 3' *'set ccolor 1' *'set mpt 0 15 1 1' *'set csmooth on' *'set arrowhead 0.03' 'define uavg=ave(ua,t=101,t=104)' 'define vavg=ave(va,t=101,t=104)' *'color 1 19 3 -kind rainbow' *'set clevs  2 4 6 8 10 12 14 16' *'set ccols 0 48 47 46 45 44 43 42 41' 'define magw=mag(uavg,vavg)' *'set ccolor 1' 'set gxout shaded' 'd magw' 'run vec.gs skip(uavg,10);vavg -SCL 0.25 15 -P 7.7 9' 'run cbarn' 'draw title Wind at 870hPa for 2007 JJAS' *'printim output.eps' 'p...

GrADS: Plotting multiple variables and panelling of figures (Multiple plots on a single page)

Image
Output image The script: (For this script to be run, you have to have " rupres " file in your present working directory as a prerequisite ) 'reinit' *'set display color white' *'c' 'set grads off' 'set grid off' 'set xlint 7' 'set ylint 5' 'set xlopts 1 6 0.13' 'set ylopts 1 6 0.13' 'run colors.gs' 'run basemap.gs' 'set mpdset rupres' *************temperature**************** 'set parea 2 6 6 10' 'open file6.nc.ctl' 'set lon 60 104' 'set lat 5 37' 'set gxout shaded' 'set clevs -5 0 5 10 15 20 25 30 35' 'set ccols 45 46 51 52 53 54 55 56 57 58' 'd ts-273.15' 'run cbarn 0.85 8 6.5 8' 'basemap o 0 1' **************relative_humidity******************** 'set parea 2 6 1 5' 'open file7.nc.ctl' 'define hum=ave(rh,t=101,t=104)' 'set lon 60 104' 'set lat 5 37' 'set gxou...

GrADS: Some useful prerequisite scripts - basemap.gs

Save the below script as " basemap.gs " in a text editor: The script: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * basemap.gs * * This script overlays a land or ocean mask that exactly matches  * the coastal outlines.  *  * Usage:  *   basemap L(and)/O(cean) <fill_color> <outline_color> <L(owres)/M(res)/H(ires)>' * * Example: *   ga-> set mpdset mres *   ga-> display sst *   ga-> basemap L 7 2 M *  * Usage Notes:  * * The default values for the optional arguments are:  *   fill_color 15, outline_color 0, and lowres.  * * The land and ocean masks are composed of hundreds of  * polygons that are specified in accompanying ascii files.  * The ascii files must be downloaded from the GrADS script library: *   ftp://grads.iges.org/grads/scripts/lpoly_lowres.asc *   ftp://grads.iges.org/grads/scripts/lpoly_mres.a...