├── .gitignore ├── LICENSE ├── README.md ├── allclose.gs ├── allcolor.gs ├── arg.gsf ├── arrow.gs ├── atoi.gsf ├── chcase.gsf ├── clave.gs ├── cmonth.gsf ├── color.gs ├── color.gsf ├── comarg.gsf ├── cutdata.gs ├── dayofyear.gsf ├── days.gsf ├── dlev.gs ├── drawline.gs ├── drawmark.gs ├── drawpoly.gs ├── draws.gs ├── dshade.gs ├── dtopen.gsf ├── energybox.gs ├── find.gsf ├── getstr.gsf ├── gradsver.gsf ├── grid.gs ├── hatch.gs ├── ico.gs ├── itoa.gsf ├── last.gsf ├── lat2y.gsf ├── lev2z.gsf ├── libbase.gsf ├── line.gs ├── loglabel.gs ├── lon2x.gsf ├── lreg.gs ├── max.gs ├── min.gs ├── mul.gs ├── mul2.gs ├── mulval.gs ├── prex.gsf ├── printf.gsf ├── pwd.gsf ├── qattr.gsf ├── qctlinfo.gsf ├── qdims.gsf ├── qgr2w.gsf ├── qgr2xy.gsf ├── qgxinfo.gsf ├── qgxout.gsf ├── qv2rh.gs ├── qw2gr.gsf ├── qw2xy.gsf ├── qxy2gr.gsf ├── qxy2w.gsf ├── rgnwrd.gsf ├── save.gs ├── saveanim.gs ├── setfont.gs ├── setlabs.gs ├── setshift.gs ├── setstr.gsf ├── shade.gs ├── shift.gs ├── strmem.gsf ├── strrep.gsf ├── strtrim.gsf ├── sublw.gsf ├── t2time.gsf ├── tbox.gs ├── template.gs ├── tile.gs ├── time2t.gsf ├── time_avail.gsf ├── tsteps.gsf ├── v2s.gsf ├── x2lon.gsf ├── xcbar.gs ├── xmath_max.gsf ├── xmath_min.gsf ├── xmath_random.gsf ├── xopen.gs ├── y2lat.gsf ├── z2lev.gsf └── zero.gs /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gscript 2 | Script and script function libraries for GrADS 3 | -------------------------------------------------------------------------------- /allclose.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function allclose( args ) 5 | _version='0.01r1' 6 | 7 | * if( args = '' ) 8 | * help() 9 | * return 10 | * endif 11 | 12 | * serach for the largest file number 13 | 'q files' 14 | i = 1 15 | fmax = 0 16 | while( 1 ) 17 | line = sublin( result, i ) 18 | if( line = '' ) ; break ; endif 19 | num = subwrd( line, 2 ) 20 | if( num = fmax + 1 ) ; fmax = fmax + 1 ; endif 21 | i = i + 1 22 | endwhile 23 | 24 | * close 25 | say 'closing 'fmax' files' 26 | f = fmax 27 | while( f >= 1 ) 28 | 'close 'f 29 | f = f - 1 30 | endwhile 31 | 32 | return 33 | 34 | * 35 | * help 36 | * 37 | function help() 38 | say ' Name:' 39 | say ' allclose '_version' - close all the opened files' 40 | say ' ' 41 | say ' Usage:' 42 | say ' allclose' 43 | say '' 44 | say ' Copyright (C) 2010 Chihiro Kodama' 45 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 46 | say '' 47 | return 48 | -------------------------------------------------------------------------------- /allcolor.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function allcolor(args) 5 | _version='0.01r2' 6 | 7 | * if( args = '' ) 8 | * help() 9 | * endif 10 | 11 | imax = 20 12 | jmax = 10 13 | 14 | c = 0 15 | while( c <= 255 ) 16 | 'set line 'c 17 | i = math_fmod( c, imax ) 18 | j = ( c - i ) / imax 19 | 20 | x1 = 0.5 + 0.5 * i 21 | x2 = 0.5 + 0.5 * (i+1) 22 | xmed = ( x1 + x2 ) / 2.0 23 | 24 | y1 = 7.5 - 0.5 * j 25 | y2 = 7.5 - 0.5 * (j-1) 26 | ymed = ( y1 + y2 ) / 2.0 27 | 28 | 'draw recf 'x1' 'y1' 'x2' 'y2 29 | 30 | 'set strsiz 0.1 0.15' 31 | 'set string 0 c 0.15' 32 | 'draw string 'xmed' 'ymed' 'c 33 | 34 | c = c + 1 35 | endwhile 36 | 37 | return 38 | 39 | 40 | * 41 | * help 42 | * 43 | function help() 44 | say ' Name:' 45 | say ' allcolor '_version' - display all the colors' 46 | say ' ' 47 | say ' Usage:' 48 | say ' allcolor' 49 | say '' 50 | say ' Copyright (C) 2009-2015 Chihiro Kodama' 51 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 52 | say '' 53 | return 54 | -------------------------------------------------------------------------------- /arg.gsf: -------------------------------------------------------------------------------- 1 | * get argument of z=x+iy in radian. 2 | function arg( x, y ) 3 | pi = 4 * math_atan( 1.0 ) 4 | if( x > 0 & y > 0 ) ; ret = math_atan( y / x ) ; endif 5 | if( x < 0 & y > 0 ) ; ret = pi - math_atan( y / (-x) ) ; endif 6 | if( x < 0 & y < 0 ) ; ret = pi + math_atan( y / x ) ; endif 7 | if( x > 0 & y < 0 ) ; ret = 2*pi - math_atan( (-y) / x ) ; endif 8 | 9 | if( x = 0 & y > 0 ) ; ret = 0.5*pi ; endif 10 | if( x = 0 & y < 0 ) ; ret = 1.5*pi ; endif 11 | if( x > 0 & y = 0 ) ; ret = 0.0*pi ; endif 12 | if( x < 0 & y = 0 ) ; ret = 1.0*pi ; endif 13 | if( x = 0 & y = 0 ) ; ret = 9999 ; endif 14 | return ret 15 | -------------------------------------------------------------------------------- /arrow.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function clave( args ) 5 | _version='0.01r2' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | ***** Default value ***** 13 | x1 = -1 14 | y1 = -1 15 | x2 = -1 16 | y2 = -1 17 | angle = 30 18 | head = '20%' 19 | 20 | ***** Arguement ***** 21 | i = 1 22 | while( 1 ) 23 | arg = subwrd( args, i ) 24 | i = i + 1; 25 | if( arg = '' ); break; endif 26 | 27 | while(1) 28 | *** option 29 | if( arg = '-angle'); angle=subwrd(args,i); i=i+1; break; endif 30 | if( arg = '-head'); head=subwrd(args,i); i=i+1; break; endif 31 | 32 | *** x1, y1, x2, y2 33 | if( x1 = -1 ); x1 = arg; break; endif 34 | if( y1 = -1 ); y1 = arg; break; endif 35 | if( x2 = -1 ); x2 = arg; break; endif 36 | if( y2 = -1 ); y2 = arg; break; endif 37 | 38 | say 'syntax error : 'arg 39 | return 40 | 41 | endwhile 42 | endwhile 43 | 44 | if( substr( head, math_strlen(head), 1 ) = '%' ) 45 | head = substr( head, 1, math_strlen(head)-1 ) 46 | head = math_sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) * head / 100.0 47 | endif 48 | 49 | ***** Draw ***** 50 | pi = 3.14159 51 | alpha = math_atan2( y2-y1, x2-x1 ) 52 | 53 | 'draw line 'x1' 'y1' 'x2' 'y2 54 | 55 | x = x2 + head * math_cos( (180+angle)*pi/180 + alpha ) 56 | y = y2 + head * math_sin( (180+angle)*pi/180 + alpha ) 57 | 'draw line 'x2' 'y2' 'x' 'y 58 | 59 | x = x2 + head * math_cos( (180-angle)*pi/180 + alpha ) 60 | y = y2 + head * math_sin( (180-angle)*pi/180 + alpha ) 61 | 'draw line 'x2' 'y2' 'x' 'y 62 | 63 | return 64 | 65 | 66 | * 67 | * help 68 | * 69 | function help() 70 | say ' Name:' 71 | say ' arrow '_version' - draw arrow ' 72 | say ' ' 73 | say ' Usage:' 74 | say ' arrow x1 y1 x2 y2 [-angle angle] [-head head[%]]' 75 | say '' 76 | say ' x1 y1 : start point' 77 | say ' x2 y2 ; end point' 78 | say ' angle : arrow head angle. default=30.' 79 | say ' head[%] : arrow head length. default=20%' 80 | say ' If you specify %, ' 81 | say ' then the length will be set relative to the arrow length.' 82 | say '' 83 | say ' Note:' 84 | say ' [arg-name] : specify if needed' 85 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 86 | say '' 87 | say ' Copyright (C) 2009 Chihiro Kodama' 88 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 89 | say '' 90 | return 91 | -------------------------------------------------------------------------------- /atoi.gsf: -------------------------------------------------------------------------------- 1 | ***** char -> integer ***** 2 | function atoi( char ) 3 | rc = gsfallow( 'on' ) 4 | 5 | * avoid bug in GrADS 1.9 or less ('e' and '+' are assumed to be same) 6 | a='1'char'5' 7 | if( a = 1e+5 ) ; return 101 ; endif 8 | if( a = '1+5' ) ; return 43 ; endif 9 | 10 | if( char = a ) ; return 43 ; endif 11 | if( char = 'e' ) ; return 101 ; endif 12 | i = 32 13 | while( i <= 126 ) 14 | if( itoa(i) = char ) ; return i ; endif 15 | i = i + 1 16 | endwhile 17 | return -1 18 | -------------------------------------------------------------------------------- /chcase.gsf: -------------------------------------------------------------------------------- 1 | * type = 'upper' or 'lower' or 'upper-first' 2 | function chcase( str, type ) 3 | ret = '' 4 | i = 1 5 | length = math_strlen( str ) 6 | while( i <= length ) 7 | c = substr( str, i, 1 ) 8 | c = atoi( c ) 9 | if( type = 'upper' & c >= 97 & c <= 122 ) 10 | c = c - 32 11 | endif 12 | if( type = 'upper_first' & c >= 97 & c <= 122 & i = 1 ) 13 | c = c - 32 14 | endif 15 | if( type = 'lower' & c >= 65 & c <= 90 ) 16 | c = c + 32 17 | endif 18 | if( type = 'upper_first' & c >= 65 & c <= 90 & i != 1 ) 19 | c = c + 32 20 | endif 21 | c = itoa( c ) 22 | ret = ret % c 23 | i = i + 1 24 | endwhile 25 | return ret 26 | -------------------------------------------------------------------------------- /clave.gs: -------------------------------------------------------------------------------- 1 | * 2 | * help is in the end of this script 3 | * 4 | function clave(args) 5 | _version = '0.05r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | varin = '' 15 | time1 = '' 16 | time2 = '' 17 | ystart = '' 18 | yend = '' 19 | ylist = '' 20 | varout = '' 21 | within = 0 22 | 23 | i = 1 24 | while( 1 ) 25 | arg = subwrd( args, i ) 26 | i = i + 1; 27 | if( arg = '' ); break; endif 28 | 29 | while( 1 ) 30 | *** option 31 | if( arg = '-ylist' ) ; ylist = subwrd(args,i) ; i=i+1 ; break ; endif 32 | if( arg = '-within' ) ; within = 1 ; break ; endif 33 | 34 | *** varin, time1, time2, ... 35 | if( varin = '' ) ; varin = arg ; break ; endif 36 | if( time1 = '' ) ; time1 = arg ; break ; endif 37 | if( time2 = '' ) ; time2 = arg ; break ; endif 38 | if( ystart = '' & ylist = '' ) ; ystart = arg ; break ; endif 39 | if( yend = '' & ylist = '' ) ; yend = arg ; break ; endif 40 | if( varout = '' ) ; varout = arg ; break ; endif 41 | 42 | say 'syntax error: 'arg 43 | return 44 | endwhile 45 | endwhile 46 | 47 | * varin = subwrd( args, 1 ) 48 | * time1 = subwrd( args, 2 ) 49 | * time2 = subwrd( args, 3 ) 50 | * ystart = subwrd( args, 4 ) 51 | * if( ystart = '-ylist' ) 52 | * ystart = '' 53 | * yend = '' 54 | * ylist = subwrd( args, 5 ) 55 | * else 56 | * yend = subwrd( args, 5 ) 57 | * ylist = '' 58 | * endif 59 | * varout = subwrd( args, 6 ) 60 | 61 | if( varin = '' ) ; say 'error: no varin is specified!' ; return ; endif 62 | if( time1 = '' ) ; say 'error: no time1 is specified!' ; return ; endif 63 | if( time2 = '' ) ; say 'error: no time2 is specified!' ; return ; endif 64 | if( ystart = '' & yend = '' & ylist = '' ) 65 | say 'error: no year range is specified!' ; return ; endif 66 | if( ystart != '' & yend != '' & ystart > yend ) 67 | say 'error: no ystart > yend' ; return ; endif 68 | 69 | * set yeay list (year.pn) 70 | * if( ystart != '' & y_end != '' ) 71 | if( ystart != '' & yend != '' ) 72 | pn = 0 73 | y = ystart 74 | while( y <= yend ) 75 | pn = pn + 1 76 | year.pn = y 77 | y = y + 1 78 | endwhile 79 | endif 80 | if( ylist != '' ) 81 | pn = 1 82 | year.pn = '' 83 | len = math_strlen( ylist ) 84 | i = 1 85 | while( i <= len ) 86 | c = substr( ylist, i, 1 ) 87 | if( c = ',' ) ; pn = pn + 1 ; year.pn = '' 88 | else ; year.pn = year.pn % c ; endif 89 | i = i + 1 90 | endwhile 91 | endif 92 | 93 | 94 | ***** Calculate ***** 95 | p = 1 96 | while( p <= pn ) 97 | y = year.p 98 | timey1 = gettime( time1, y ) 99 | timey2 = gettime( time2, y ) 100 | if( time2t(timey1) > time2t(timey2) ) 101 | say 'error: time range is ' % timey1 % ' and ' % timey2 102 | exit 103 | endif 104 | 105 | calc = 0 106 | 107 | * only support ystart/yend for within=1 108 | * timey2 >= 00z01jan{ypp} -> 109 | if( within = 1 ) 110 | if( time2t(timey2) >= time2t('00z01jan' % (yend+1)) ) 111 | calc = 1 112 | say 'Keep time within year range' 113 | timey2a = gettime( time2, ystart-1 ) 114 | timey1a = t2time( time2t( '00z01jan'ystart ) ) 115 | say ' ave( 'varin', time='timey1a', time='timey2a ')' 116 | 'claveav = ave( 'varin', time='timey1a', time='timey2a ')' 117 | 'clavean = sum( const('varin'*0+1,0,-u), time='timey1a', time='timey2a ')' 118 | timey2b = t2time( time2t( '00z01jan' % (yend+1) ) - 1 ) 119 | say ' ave( 'varin', time='timey1', time='timey2b ')' 120 | 'clavebv = ave( 'varin', time='timey1', time='timey2b ')' 121 | 'clavebn = sum( const('varin'*0+1,0,-u), time='timey1', time='timey2b ')' 122 | 'claveav = const( claveav, 0, -u )' 123 | 'clavebv = const( clavebv, 0, -u )' 124 | 'clavetemp = ( claveav * clavean + clavebv * clavebn ) / ( clavean + clavebn )' 125 | endif 126 | if( time2t(timey1) < time2t('00z01jan' % (ystart)) ) 127 | calc = 1 128 | say 'Keep time within year range' 129 | timey2a = gettime( time2, ystart ) 130 | timey1a = t2time( time2t( '00z01jan'ystart ) ) 131 | say ' ave( 'varin', time='timey1a', time='timey2a ')' 132 | 'claveav = ave( 'varin', time='timey1a', time='timey2a ')' 133 | 'clavean = sum( const('varin'*0+1,0,-u), time='timey1a', time='timey2a ')' 134 | timey1b = gettime( time1, yend+1 ) 135 | timey2b = t2time( time2t( '00z01jan' % (yend+1) ) - 1 ) 136 | say ' ave( 'varin', time='timey1b', time='timey2b ')' 137 | 'clavebv = ave( 'varin', time='timey1', time='timey2b ')' 138 | 'clavebn = sum( const('varin'*0+1,0,-u), time='timey1', time='timey2b ')' 139 | 'claveav = const( claveav, 0, -u )' 140 | 'clavebv = const( clavebv, 0, -u )' 141 | 'clavetemp = ( claveav * clavean + clavebv * clavebn ) / ( clavean + clavebn )' 142 | endif 143 | endif 144 | 145 | if( calc = 0 ) 146 | say 'ave( 'varin', time='timey1', time='timey2 ')' 147 | 'clavetemp = ave( 'varin', time='timey1', time='timey2' )' 148 | endif 149 | 150 | if( p = 1 ) 151 | 'clavenum = const( clavetemp*0+1, 0, -u )' 152 | 'clave = clavetemp' 153 | else 154 | 'clavenum = clavenum + const( clavetemp*0+1, 0, -u )' 155 | 'clavemask = const( clave*0+1, 0, -u ) + const( clavetemp*0+1, 0, -u ) - 0.5' 156 | 'clave = maskout( const( clave, 0, -u ) + const( clavetemp, 0, -u ), clavemask )' 157 | endif 158 | 159 | p = p + 1 160 | endwhile 161 | 162 | 'clave = clave / clavenum' 163 | 164 | 165 | ***** Output ***** 166 | if( varout = '' ) 167 | 'd clave' 168 | else 169 | varout'=clave' 170 | endif 171 | 172 | 'undefine clave' 173 | return 174 | 175 | 176 | 177 | * 178 | * Convert time for GrADS 179 | * 180 | * str: virtual time including %y, %ypp, %end. 181 | * y : year 182 | * ret: time for GrADS 183 | * 184 | * e.g. %y, %ypp -> 1980, 1981 185 | * %end -> 18z31 (if Jan, 6 hourly ) 186 | * 187 | function gettime( str, y ) 188 | ret = str 189 | yret = -999 190 | ypp = y + 1 191 | ymm = y - 1 192 | 193 | tmp = strrep( ret, '%ypp', ypp ) 194 | if( ret != tmp ) ; yret = ypp ; endif 195 | ret = tmp 196 | 197 | tmp = strrep( ret, '%ymm', ymm ) 198 | if( ret != tmp ) ; yret = ymm ; endif 199 | ret = tmp 200 | 201 | tmp = strrep( ret, '%y', y ) 202 | if( ret != tmp ) ; yret = y ; endif 203 | ret = tmp 204 | 205 | pos = find( ret, '%end' ) 206 | if( pos > 0 ) 207 | len = math_strlen( ret ) 208 | cm = substr( ret, pos+4, 3 ) 209 | year = substr( ret, pos+7, len-(pos+7)+1 ) 210 | t1 = time2t( '00z01'cm''year ) 211 | t2 = t1 + tsteps( year, cmonth(cm) ) - 1 212 | ret = t2time( t2 ) 213 | endif 214 | 215 | return ( ret ) 216 | 217 | 218 | * 219 | * help 220 | * 221 | function help() 222 | say ' Name:' 223 | say ' clave '_version' - make climatological mean ' 224 | say '' 225 | say ' Usage:' 226 | say ' clave' 227 | say ' var_in time1 time2' 228 | say ' (ystart yend | -ylist y1,y2,...) [var_out]' 229 | say ' [-within]' 230 | say '' 231 | say ' var_in : variable' 232 | say ' time1 time2 : Seasonal time range' 233 | say ' %y, %ypp, or %ymm should be included. ' 234 | say ' They will be replaced by a particular year,' 235 | say ' the next year or the previous year.' 236 | say ' %end, which will be replaced by the end of month, may be included.' 237 | say ' e.g. time1 time2' 238 | say ' 01jan%y 01feb%y : January-mean (including 01feb)' 239 | say ' 01jan%y %endjan%y : January-mean (averaged only within January)' 240 | say ' 01jun%y %endaug%y : JJA-mean' 241 | say ' 01dec%y %endfeb%ypp: DJF-mean' 242 | say ' ystart yend : year range (ystart <= yend)' 243 | say ' -ylist list : year used' 244 | say ' var_out : variable in which climatological mean will be stored.' 245 | say ' -within : do not use data outside year range with %ypp and/or %ymm.' 246 | say '' 247 | say ' Note:' 248 | say ' [arg-name] : specify if needed' 249 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 250 | say ' If var_out is not specified, climatological mean will be drawn.' 251 | say '' 252 | say ' Copyright (C) 2009-2017 Chihiro Kodama' 253 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 254 | say '' 255 | return 256 | -------------------------------------------------------------------------------- /cmonth.gsf: -------------------------------------------------------------------------------- 1 | function cmonth( month, size ) 2 | cmonth.1 = 'January' 3 | cmonth.2 = 'February' 4 | cmonth.3 = 'March' 5 | cmonth.4 = 'April' 6 | cmonth.5 = 'May' 7 | cmonth.6 = 'June' 8 | cmonth.7 = 'July' 9 | cmonth.8 = 'August' 10 | cmonth.9 = 'September' 11 | cmonth.10 = 'October' 12 | cmonth.11 = 'November' 13 | cmonth.12 = 'December' 14 | 15 | c = substr( month, 1, 1 ) 16 | 17 | **************************************** 18 | * integer(s) -> string 19 | **************************************** 20 | 21 | if( valnum(c) = 1 ) 22 | 23 | * month = '123', '234', ..., '212' are accepted (must be a string!). 24 | flag = 0 25 | if( math_strlen(month) = 3 ) 26 | if( month = '123' ) ; c.1 = 1 ; c.2 = 2 ; c.3 = 3 ; flag = 1 ; endif 27 | if( month = '234' ) ; c.1 = 2 ; c.2 = 3 ; c.3 = 4 ; flag = 1 ; endif 28 | if( month = '345' ) ; c.1 = 3 ; c.2 = 4 ; c.3 = 5 ; flag = 1 ; endif 29 | if( month = '456' ) ; c.1 = 4 ; c.2 = 5 ; c.3 = 6 ; flag = 1 ; endif 30 | if( month = '567' ) ; c.1 = 5 ; c.2 = 6 ; c.3 = 7 ; flag = 1 ; endif 31 | if( month = '678' ) ; c.1 = 6 ; c.2 = 7 ; c.3 = 8 ; flag = 1 ; endif 32 | if( month = '789' ) ; c.1 = 7 ; c.2 = 8 ; c.3 = 9 ; flag = 1 ; endif 33 | if( month = '890' ) ; c.1 = 8 ; c.2 = 9 ; c.3 = 10 ; flag = 1 ; endif 34 | if( month = '901' ) ; c.1 = 9 ; c.2 = 10 ; c.3 = 11 ; flag = 1 ; endif 35 | if( month = '012' ) ; c.1 = 10 ; c.2 = 11 ; c.3 = 12 ; flag = 1 ; endif 36 | if( month = '121' ) ; c.1 = 11 ; c.2 = 12 ; c.3 = 1 ; flag = 1 ; endif 37 | if( month = '212' ) ; c.1 = 12 ; c.2 = 1 ; c.3 = 2 ; flag = 1 ; endif 38 | endif 39 | 40 | if( flag = 1 ) 41 | i = 1 42 | ret = '' ; h = '' 43 | while( i <= 3 ) 44 | c = c.i 45 | if( size != 'size' ) 46 | ret = ret % h % substr( cmonth.c, 1, size ) 47 | else 48 | ret = ret % h % cmonth.c 49 | endif 50 | if( size != 1 ) ; h = '-' ; endif 51 | i = i + 1 52 | endwhile 53 | return ret 54 | endif 55 | 56 | * month = 1, 2, 3, ..., or 12 57 | * month < 1 or month > 12 is also accepted 58 | if( valnum(month) = 1 ) 59 | month = month + 0 60 | month = math_fmod( month-1, 12 ) + 1 61 | ret = cmonth.month 62 | if( size != 'size' & size != -1 ) 63 | ret = substr( ret, 1, size ) 64 | endif 65 | 66 | * month = '12,1,2' = DJF, '6,7' = 'JJ' etc 67 | * size: length per one month 68 | else 69 | m = 1 70 | month.m = '' 71 | length = math_strlen( month ) 72 | i = 1 73 | while( i <= length ) 74 | c = substr( month, i, 1 ) 75 | if( c = ',' ) 76 | m = m + 1 77 | month.m = '' 78 | else 79 | month.m = month.m % c 80 | endif 81 | i = i + 1 82 | endwhile 83 | mmax = m 84 | 85 | m = 1 86 | h = '' 87 | ret = '' 88 | while( m <= mmax ) 89 | * say m % ': ' % month.m 90 | mm = month.m 91 | if( size != 'size' ) 92 | ret = ret % h % substr( cmonth.mm, 1, size ) 93 | else 94 | ret = ret % h % cmonth.mm 95 | endif 96 | if( size != 1 ) ; h = '-' ; endif 97 | m = m + 1 98 | endwhile 99 | endif 100 | 101 | **************************************** 102 | * string -> integer(s) 103 | **************************************** 104 | else 105 | month = chcase( month, 'upper_first' ) 106 | ret = -1 107 | len_month = math_strlen( month ) 108 | 109 | ***** simgle month ***** 110 | m = 1 111 | while( m <= 12 ) 112 | cmonth_tmp = substr( cmonth.m, 1, len_month ) 113 | if( cmonth_tmp = month ) 114 | if( ret != -1 ) ; ret = ret % '|' % m ; 115 | else ; ret = m ; endif 116 | endif 117 | m = m + 1 118 | endwhile 119 | if( ret != -1 ) ; return ret ; endif 120 | 121 | ***** multi-month (e.g. DJF, Dec-Jan-Feb) ***** 122 | * add '-' if necessary 123 | length = math_strlen( month ) 124 | i = 1 125 | tmp = '' 126 | while( i <= length ) 127 | c = substr( month, i, 1 ) 128 | if( c = '-' ) ; break ; endif 129 | if( i = length ) ; month = tmp % c ; endif 130 | tmp = tmp % c % '-' 131 | i = i + 1 132 | endwhile 133 | 134 | * convert 135 | m = 1 136 | 137 | * month.m = '' 138 | * length = math_strlen( month ) 139 | * i = 1 140 | * while( i <= length ) 141 | * c = substr( month, i, 1 ) 142 | * if( c = '-' ) 143 | * m = m + 1 144 | * month.m = '' 145 | * else 146 | * month.m = month.m % c 147 | * endif 148 | * i = i + 1 149 | * endwhile 150 | * mmax = m 151 | 152 | while( 1 = 1 ) 153 | month.m = rgnwrd( month, m, m, '-' ) 154 | if( month.m = '' ) ; break ; endif 155 | m = m + 1 156 | endwhile 157 | mmax = m - 1 158 | 159 | 160 | m = 1 161 | while( m <= mmax ) 162 | month.m = chcase( month.m, 'upper_first' ) 163 | month.m = cmonth( month.m ) 164 | 165 | * m2: for multiple-candidate 166 | * length = math_strlen( month.m ) 167 | * i = 1 168 | * m2 = 1 169 | * month.m.m2 = '' 170 | * while( i <= length ) 171 | * c = substr( month.m, i, 1 ) 172 | * if( c = '|' ) 173 | * m2 = m2 + 1 174 | * month.m.m2 = '' 175 | * else 176 | * month.m.m2 = month.m.m2 % c 177 | * endif 178 | * i = i + 1 179 | * endwhile 180 | i = 1 181 | * month.m.i = '' 182 | while( 1 = 1 ) 183 | month.m.i = rgnwrd( month.m, i, i, '|' ) 184 | if( month.m.i = '' ) ; break ; endif 185 | i = i + 1 186 | endwhile 187 | * m2 = m2 + 1 188 | * month.m.m2 = '' 189 | m = m + 1 190 | endwhile 191 | 192 | * check for continuity 193 | sm = 1 194 | while( month.1.sm != '' & ret = -1 ) 195 | now = month.1.sm 196 | 197 | cont = 1 198 | if( size = 1 ) 199 | ret = math_fmod( month.1.sm, 10 ) 200 | else 201 | ret = month.1.sm 202 | endif 203 | 204 | m = 2 205 | while( m <= mmax ) 206 | * now = math_fmod( now + 1 + 1, 12 ) - 1 207 | now = math_fmod( now, 12 ) + 1 208 | m2 = 1 209 | while( month.m.m2 != '' ) 210 | 211 | if( month.m.m2 = now ) 212 | if( size = 1 ) 213 | ret = ret % math_fmod( month.m.m2, 10 ) 214 | else 215 | ret = ret % ',' % month.m.m2 216 | endif 217 | break 218 | endif 219 | m2 = m2 + 1 220 | if( month.m.m2 = '' ) ; cont = 0 ; endif 221 | endwhile 222 | 223 | m = m + 1 224 | endwhile 225 | 226 | *say cont 227 | if( cont != 1 ) ; ret = -1 ; endif 228 | sm = sm + 1 229 | endwhile 230 | 231 | if( ret != -1 ) ; return ret ; endif 232 | 233 | endif 234 | return ret 235 | -------------------------------------------------------------------------------- /comarg.gsf: -------------------------------------------------------------------------------- 1 | * get value from standard command arguements 2 | * target: string or number 3 | function comarg( args, target ) 4 | ret = '' 5 | 6 | cnt = 0 7 | i = 1 8 | while( 1 ) 9 | arg = subwrd( args, i ) 10 | if( arg = '' ) ; break ; endif 11 | 12 | if( substr( arg, 1, 1 ) = '-' ) 13 | key = substr( arg, 2, math_strlen(arg)-1 ) 14 | i = i + 1 15 | val = subwrd( args, i ) 16 | if( key = target ) ; ret = val ; endif 17 | 18 | * say 'ok: ' % key % ' : ' % val 19 | else 20 | cnt = cnt + 1 21 | val = arg 22 | if( cnt = target ) ; ret = val ; endif 23 | endif 24 | 25 | i = i + 1 26 | endwhile 27 | return ret 28 | -------------------------------------------------------------------------------- /cutdata.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function cutdata( args ) 5 | _version = '0.01r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | xmin = -9999 15 | xmax = -9999 16 | ymin = -9999 17 | ymax = -9999 18 | zmin = -9999 19 | zmax = -9999 20 | tmin = -9999 21 | tmax = -9999 22 | timemin = '' 23 | timemax = '' 24 | ctl_in = '' 25 | grd_out = '' 26 | vnames = '' 27 | undef = '' 28 | 29 | ***** Arguement ***** 30 | i = 1 31 | while( 1 ) 32 | arg = subwrd( args, i ) 33 | i = i + 1; 34 | if( arg = '' ); break; endif 35 | 36 | while( 1 ) 37 | *** option 38 | if( arg = '-t' ) 39 | timemin = '' 40 | timemax = '' 41 | tmp = subwrd( args, i ); i = i + 1 42 | * -t t1 t2 43 | if( find( tmp, '-' ) <= 0 ) 44 | tmin = tmp 45 | tmax = subwrd( args, i ); i = i + 1 46 | if( valnum(tmax) != 1 ) 47 | say 'error: invalid time range (-t ' % tmin % ' ' % tmax % ')' 48 | exit 49 | endif 50 | * -t [t1-t2] 51 | else 52 | tmin = rgnwrd( tmp, 1, 1, '-' ) 53 | tmin = substr( tmin, 2, math_strlen(tmin)-1 ) 54 | tmax = rgnwrd( tmp, 2, 2, '-' ) 55 | tmax = substr( tmax, 1, math_strlen(tmax)-1 ) 56 | flag_tmin = substr( tmp, 1, 1 ) 57 | if( flag_tmin = '(' ) ; tmin = tmin + 1 ; endif 58 | flag_tmax = substr( tmp, math_strlen(tmp), 1 ) 59 | if( flag_tmax = ')' ) ; tmax = tmax - 1 ; endif 60 | endif 61 | break 62 | endif 63 | if( arg = '-time' ) 64 | tmin = -9999 65 | tmax = -9999 66 | tmp = subwrd( args, i ); i = i + 1 67 | * -time time1 time2 68 | if( find( tmp, '-' ) <= 0 ) 69 | timemin = tmp 70 | timemax = subwrd( args, i ); i = i + 1 71 | * -time [time1-time2] 72 | else 73 | timemin = rgnwrd( tmp, 1, 1, '-' ) 74 | timemin = substr( timemin, 2, math_strlen(timemin)-1 ) 75 | timemax = rgnwrd( tmp, 2, 2, '-' ) 76 | timemax = substr( timemax, 1, math_strlen(timemax)-1 ) 77 | flag_timemin = substr( tmp, 1, 1 ) 78 | flag_timemax = substr( tmp, math_strlen(tmp), 1 ) 79 | endif 80 | break 81 | endif 82 | 83 | if( arg = '-x' ) 84 | xmin = subwrd( args, i ); i = i + 1 85 | xmax = subwrd( args, i ); i = i + 1 86 | break 87 | endif 88 | if( arg = '-y' ) 89 | ymin = subwrd( args, i ); i = i + 1 90 | ymax = subwrd( args, i ); i = i + 1 91 | break 92 | endif 93 | if( arg = '-z' ) 94 | zmin = subwrd( args, i ); i = i + 1 95 | zmax = subwrd( args, i ); i = i + 1 96 | break 97 | endif 98 | 99 | if( arg = '-undef' ) ; undef = subwrd( args, i ); i = i + 1; break; endif 100 | 101 | if( arg = '-var' ) ; vnames = subwrd( args, i ); i = i + 1; break; endif 102 | 103 | *** ctl_in, grd_out 104 | if( ctl_in = '' ); ctl_in = arg; break; endif 105 | if( grd_out = '' ); grd_out = arg; break; endif 106 | say 'syntax error : 'arg 107 | return 108 | endwhile 109 | endwhile 110 | 111 | ***** check arguments ***** 112 | if( ctl_in = '' ) 113 | say 'error: input control file name is not specified.' 114 | exit 115 | endif 116 | if( grd_out = '' ) 117 | say 'error: output file name is not specified.' 118 | exit 119 | endif 120 | 121 | ret = read( grd_out ) 122 | line = sublin( ret, 1 ) 123 | stat = subwrd( line, 1 ) 124 | if( stat = 0 ) 125 | say 'output file (' % grd_out % ') exists.' 126 | exit 127 | endif 128 | 129 | ***** open control file ***** 130 | 'xopen 'ctl_in 131 | f = last() 132 | 'set dfile 'f 133 | 134 | if( vnames = '' ) 135 | vnames = qctlinfo( f, 'vlist', 0 ) 136 | vnames = strrep( vnames, ' ', ',' ) 137 | say vnames 138 | endif 139 | 140 | v = 1 141 | while( 1 = 1 ) 142 | vname.v = rgnwrd( vnames, v, v, ',' ) 143 | if( vname.v = '' | vname.v = vnames ) ; break ; endif 144 | v = v + 1 145 | endwhile 146 | if( vnames = vname.1 ) ; vmax = 1 147 | else ; vmax = v - 1 ; endif 148 | 149 | 'set gxout fwrite' 150 | 'set fwrite -be 'grd_out 151 | if( undef = '' ) 152 | 'set undef dfile' 153 | else 154 | 'set undef 'undef 155 | endif 156 | 157 | if( timemin != '' ) 158 | tmin = time2t( timemin ) 159 | tmax = time2t( timemax ) 160 | if( flag_timemin = '(' ) ; tmin = tmin + 1 ; endif 161 | if( flag_timemax = ')' ) ; tmax = tmax - 1 ; endif 162 | endif 163 | 164 | xdef = qctlinfo( f, 'xdef', 1 ) 165 | ydef = qctlinfo( f, 'ydef', 1 ) 166 | zdef = qctlinfo( f, 'zdef', 1 ) 167 | tdef = qctlinfo( f, 'tdef', 1 ) 168 | 169 | if( xmin = -9999 ) ; xmin = 1 ; endif 170 | if( xmax = -9999 ) ; xmax = xdef ; endif 171 | if( ymin = -9999 ) ; ymin = 1 ; endif 172 | if( ymax = -9999 ) ; ymax = ydef ; endif 173 | if( zmin = -9999 ) ; zmin = 1 ; endif 174 | if( zmax = -9999 ) ; zmax = zdef ; endif 175 | if( tmin = -9999 ) ; tmin = 1 ; endif 176 | if( tmax = -9999 ) ; tmax = tdef ; endif 177 | 178 | ***** cut data ***** 179 | prex( 'set x 'xmin' 'xmax ) 180 | prex( 'set y 'ymin' 'ymax ) 181 | say 'zmin=' % zmin % ', zmax=' % zmax 182 | t = tmin 183 | 184 | while( t <= tmax ) 185 | prompt ' t=' % t % ': ' 186 | 'set t 't 187 | v = 1 188 | while( v <= vmax ) 189 | if( v >= 2 ) ; prompt ', ' ; endif 190 | prompt vname.v 191 | z = zmin 192 | while( z <= zmax ) 193 | 'set z 'z 194 | 'd 'vname.v 195 | z = z + 1 196 | endwhile 197 | v = v + 1 198 | endwhile 199 | say '' 200 | t = t + 1 201 | endwhile 202 | 203 | 'disable fwrite' 204 | 'close 'f 205 | 'set gxout contour' 206 | return 207 | 208 | * 209 | * help 210 | * 211 | function help() 212 | say ' Name:' 213 | say ' cutdata '_version' - cut data' 214 | say ' ' 215 | say ' Usage:' 216 | say ' cutdata input-ctl output-grd ' 217 | say ' [-x xmin xmax]' 218 | say ' [-y ymin ymax]' 219 | say ' [-z zmin zmax]' 220 | say ' [-t tmin tmax]' 221 | say ' [-t timestep-range | -time timemin tmimeax | -time time-range]' 222 | say ' [-var vname1,vname2,...]' 223 | say ' [-undef undefined-value]' 224 | say '' 225 | say ' input-ctl : Control file name for input.' 226 | say ' output-grd : Output flat-binary file name' 227 | say ' cutdata.gs stops if the file already exists.' 228 | say ' -x xmin xmax : X range to cut.' 229 | say ' -y ymin ymax : Y range to cut.' 230 | say ' -z zmin zmax : Z range to cut.' 231 | say ' -t tmin tmax : Time step range to cut.' 232 | say ' -t timestep-range: Time step range to cut.' 233 | say ' e.g. [1-3]: 1<=t<=3 is stored' 234 | say ' e.g. [1-3): 1<=t<3 is stored' 235 | say ' -time timemin timemax ' 236 | say ' : Time range to cut.' 237 | say ' -time time-range: Time range to cut.' 238 | say ' e.g. [01jan2000-02jan2000]: 01jan2000<=time<=02jan2000 is stored' 239 | say ' e.g. [01jan2000-02jan2000): 01jan2000<=t<02jan2000 is stored' 240 | say ' -var vname1,vname2,...' 241 | say ' : List of variable names to cut' 242 | say ' -undef undefined-value' 243 | say ' : Undefined value for output data.' 244 | say '' 245 | say ' Note:' 246 | say ' [arg-name] : specify if needed' 247 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 248 | say ' cutdata.gs depends on xopen.gs, last.gsf, qctlinfo.gsf, and rgnwrd.gsf.' 249 | say '' 250 | say ' Copyright (C) 2014-2014 Chihiro Kodama' 251 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 252 | say '' 253 | return 254 | -------------------------------------------------------------------------------- /dayofyear.gsf: -------------------------------------------------------------------------------- 1 | function dayofyear( time ) 2 | length = math_strlen( time ) 3 | year = substr( time, length-3, 4 ) 4 | cmonth = substr( time, length-6, 3 ) 5 | cmonth = chcase( cmonth, 'upper' ) 6 | day = substr( time, length-8, 2 ) 7 | 8 | if( cmonth = 'JAN' ) ; month = 1 ; endif 9 | if( cmonth = 'FEB' ) ; month = 2 ; endif 10 | if( cmonth = 'MAR' ) ; month = 3 ; endif 11 | if( cmonth = 'APR' ) ; month = 4 ; endif 12 | if( cmonth = 'MAY' ) ; month = 5 ; endif 13 | if( cmonth = 'JUN' ) ; month = 6 ; endif 14 | if( cmonth = 'JUL' ) ; month = 7 ; endif 15 | if( cmonth = 'AUG' ) ; month = 8 ; endif 16 | if( cmonth = 'SEP' ) ; month = 9 ; endif 17 | if( cmonth = 'OCT' ) ; month = 10 ; endif 18 | if( cmonth = 'NOV' ) ; month = 11 ; endif 19 | if( cmonth = 'DEC' ) ; month = 12 ; endif 20 | 21 | doy = 0 22 | m = 1 23 | while( m < month ) 24 | doy = doy + days( year, m ) 25 | m = m + 1 26 | endwhile 27 | doy = doy + day 28 | return doy 29 | -------------------------------------------------------------------------------- /days.gsf: -------------------------------------------------------------------------------- 1 | function days( year, month ) 2 | 3 | d.1 = 31 4 | d.2 = 0 5 | if( d.2 = 0 & math_fmod(year,400) = 0 ) ; d.2 = 29 ; endif 6 | if( d.2 = 0 & math_fmod(year,100) = 0 ) ; d.2 = 28 ; endif 7 | if( d.2 = 0 & math_fmod(year,4) = 0 ) ; d.2 = 29 ; endif 8 | if( d.2 = 0 ) ; d.2 = 28 ; endif 9 | d.3 = 31 10 | d.4 = 30 11 | d.5 = 31 12 | d.6 = 30 13 | d.7 = 31 14 | d.8 = 31 15 | d.9 = 30 16 | d.10 = 31 17 | d.11 = 30 18 | d.12 = 31 19 | 20 | if( month != 'month' ) 21 | ret = d.month 22 | else 23 | ret = 0 24 | m = 1 25 | while( m <= 12 ) 26 | ret = ret + d.m 27 | m = m + 1 28 | endwhile 29 | endif 30 | 31 | return ret 32 | -------------------------------------------------------------------------------- /dlev.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function dlev( args ) 5 | _version='0.01r2' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | ***** Default value ***** 13 | var = '' 14 | dvdlev = '' 15 | loglev = 0 16 | 17 | 18 | ***** Arguement ***** 19 | i = 1 20 | while(1) 21 | arg = subwrd( args, i ) 22 | i = i + 1; 23 | if( arg = '' ); break; endif 24 | 25 | while(1) 26 | *** option 27 | if( arg = '-loglev' ); loglev=1; break; endif 28 | 29 | *** int, max, min 30 | if( var = '' ); var=arg; break; endif 31 | if( var != '' & dvdlev = '' ); dvdlev=arg; break; endif 32 | 33 | say 'syntax error : 'arg 34 | return 35 | 36 | endwhile 37 | endwhile 38 | 39 | 'q dims' 40 | line = sublin( result, 4 ) 41 | flag = subwrd( line, 3 ) 42 | if( flag != 'varying' ); return; endif 43 | 44 | zmin = subwrd( line, 11 ) 45 | zmax = subwrd( line, 13 ) 46 | 47 | zminpp = zmin + 1 48 | zmaxmm = zmax - 1 49 | 50 | 51 | * Half level 52 | 'set z 'zmin' 'zmaxmm 53 | if( loglev = 0 ) 54 | 'dvp = ( 'var'(z+1) - 'var' ) / ( lev(z+1) - lev )' 55 | 'levp = 0.5 * ( lev + lev(z+1) )' 56 | else 57 | 'dvp = ( 'var'(z+1) - 'var' ) / ( log(lev(z+1)) - log(lev) )' 58 | 'levp = 0.5 * ( log(lev) + log(lev(z+1)) )' 59 | endif 60 | 61 | * 'dv = 0 * 'var 62 | * z = zmin 63 | * while( z <= zmaxmm ) 64 | * 'set z 'z+1 65 | * 'varpp = 'var 66 | * 'set z 'zmin' 'zmaxmm 67 | ** 'dv = dv + maskout(varpp,z)' 68 | * z = z + 1 69 | * endwhile 70 | 71 | 72 | 73 | *exit 74 | 75 | 'set z 'zminpp' 'zmax 76 | if( loglev = 0 ) 77 | 'dvm = ( 'var' - 'var'(z-1) ) / ( lev - lev(z-1) )' 78 | 'levm = 0.5 * ( lev(z-1) + lev )' 79 | else 80 | 'dvm = ( 'var' - 'var'(z-1) ) / ( log(lev) - log(lev(z-1)) )' 81 | 'levm = 0.5 * ( log(lev(z-1)) + log(lev) )' 82 | endif 83 | 84 | * Full level 85 | 'set z 'zminpp' 'zmaxmm 86 | if( loglev = 0 ) 87 | 'w = ( lev - levm ) / ( levp - levm )' 88 | 'out = w * dvp + (1-w) * dvm' 89 | else 90 | 'w = ( log(lev) - levm ) / ( levp - levm )' 91 | 'out = w * dvp + (1-w) * dvm' 92 | 'out = 'out' / lev' 93 | endif 94 | 95 | 96 | * Output 97 | 'set z 'zmin' 'zmax 98 | 99 | if( dvdlev = '' ) 100 | 'd out' 101 | else 102 | dvdlev' = out' 103 | endif 104 | 105 | return 106 | 107 | 108 | * 109 | * help 110 | * 111 | function help() 112 | say ' Name:' 113 | say ' dlev '_version' - differentiate variable with respect to lev' 114 | say ' ' 115 | say ' Usage:' 116 | say ' dlev var [var_out] [-loglev]' 117 | say '' 118 | say ' var : variable to be differentiated' 119 | say ' var_out : result variable' 120 | say ' if var_out is not specified,' 121 | say ' result is displayed on the screen instead' 122 | say ' -loglev : use log(lev) instead of lev' 123 | say '' 124 | say ' Note:' 125 | say ' [arg-name] : specify if needed' 126 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 127 | say ' Without -loglev, var_out = d(var)/d(lev)' 128 | say ' With -loglev, var_out = d(var)/dlog(lev) / lev' 129 | say ' Half-level value is calculated for accuracy (2nd-order)' 130 | say '' 131 | say ' Copyright (C) 2009 Chihiro Kodama' 132 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 133 | say '' 134 | return 135 | -------------------------------------------------------------------------------- /drawline.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function drawline( args ) 5 | _version = '0.01r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | 'drawpoly opened 'args 14 | 15 | return 16 | 17 | 18 | * 19 | * help 20 | * 21 | function help() 22 | say ' Name:' 23 | say ' drawline '_version' - draw polygon' 24 | say ' ' 25 | say ' Usage:' 26 | say ' drawpoly [ -by ( world | grid | xy ) ] x1 y1 x2 y2 ...' 27 | say ' ' 28 | say '' 29 | say ' -by : unit of p1, q1, p2, q2' 30 | say ' world : world coordinate (e.g. lat)' 31 | say ' grid : grid coordinate (grid number)' 32 | say ' xy : same as "draw line"' 33 | say '' 34 | say ' x1, y1, ... : positions' 35 | say '' 36 | say ' Note:' 37 | say ' [arg-name] : specify if needed' 38 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 39 | say '' 40 | say ' Copyright (C) 2016 Chihiro Kodama' 41 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 42 | say '' 43 | return 44 | -------------------------------------------------------------------------------- /drawmark.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function drawmark( args ) 5 | _version='0.03r1' 6 | rc = gsfallow( 'on' ) 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | ***** Default value 13 | name = 'none' 14 | xpos = 'none' 15 | ypos = 'none' 16 | size = 'none' 17 | angle = 0 18 | by = 'xy' 19 | fill = 0 20 | r = -1 21 | g = -1 22 | b = -1 23 | a = -1 24 | setline = '' 25 | 26 | ***** Arguement ***** 27 | i = 1 28 | while( 1 ) 29 | arg = subwrd( args, i ) 30 | i = i + 1; 31 | if( arg = '' ); break; endif 32 | 33 | while( 1 ) 34 | *** option 35 | if( arg = '-angle' ) ; angle=subwrd(args,i) ; i=i+1 ; break ; endif 36 | if( arg = '-by' ) ; by=subwrd(args,i) ; i=i+1 ; break ; endif 37 | if( arg = '-f' ) ; fill = 1 ; break ; endif 38 | if( arg = '-rgb' ) 39 | r = subwrd(args,i) 40 | g = subwrd(args,i+1) 41 | b = subwrd(args,i+2) 42 | i=i+3 ; break 43 | endif 44 | if( arg = '-rgba' ) 45 | r = subwrd(args,i) 46 | g = subwrd(args,i+1) 47 | b = subwrd(args,i+2) 48 | a = subwrd(args,i+3) 49 | i=i+4 ; break 50 | endif 51 | if( arg = '-setline' ) 52 | setline = subwrd(args,i) ; i=i+1 53 | tmp = subwrd(args,i) 54 | if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif 55 | tmp = subwrd(args,i) 56 | if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif 57 | break 58 | endif 59 | if( arg = '-a' ) ; a=subwrd(args,i) ; i=i+1 ; break ; endif 60 | 61 | *** name, xpos, ypos, size 62 | if( name = 'none' ) 63 | name = arg 64 | break 65 | endif 66 | if( valnum(arg) != 0 & xpos = 'none' ) 67 | xpos = arg 68 | break 69 | endif 70 | if( valnum(arg) != 0 & ypos = 'none' ) 71 | ypos = arg 72 | break 73 | endif 74 | if( valnum(arg) != 0 & size = 'none' ) 75 | size = arg 76 | break 77 | endif 78 | 79 | say 'syntax error: 'arg 80 | return 81 | endwhile 82 | endwhile 83 | 84 | if( size = 'none' ) ; size = 1 ; endif 85 | 86 | if( by = 'world' ) ; xypos = qw2xy( xpos, ypos ) ; endif 87 | if( by = 'grid' ) ; xypos = qgr2xy( xpos, ypos ) ; endif 88 | if( by = 'xy' ) ; xypos = xpos % ' ' % ypos ; endif 89 | xpos = subwrd( xypos, 1 ) 90 | ypos = subwrd( xypos, 2 ) 91 | 92 | * virtual coordinate: [-0.5,-0,5]-[0.5:0.5] 93 | if( name = 'triangle' ) 94 | tmpred = math_sqrt(3.0)/3.0*2 95 | x.1 = -0.5/tmpred ; y.1 = -math_sqrt(3.0)/6.0/tmpred 96 | x.2 = 0.5/tmpred ; y.2 = -math_sqrt(3.0)/6.0/tmpred 97 | x.3 = 0.0/tmpred ; y.3 = math_sqrt(3.0)/3.0/tmpred 98 | pmax = 3 99 | cmd = 'drawpoly' 100 | endif 101 | if( name = 'rectangle' ) 102 | x.1 = -0.4 ; y.1 = -0.4 103 | x.2 = 0.4 ; y.2 = -0.4 104 | x.3 = 0.4 ; y.3 = 0.4 105 | x.4 = -0.4 ; y.4 = 0.4 106 | pmax = 4 107 | cmd = 'drawpoly' 108 | endif 109 | if( name = 'plus' ) 110 | x.1 = -0.4 ; y.1 = 0.0 111 | x.2 = 0.4 ; y.2 = 0.0 112 | x.3 = 111 ; y.3 = 111 113 | x.4 = 0.0 ; y.4 = -0.4 114 | x.5 = 0.0 ; y.5 = 0.4 115 | pmax = 5 116 | cmd = 'drawline' 117 | endif 118 | if( name = 'circle' ) 119 | dint = 15 120 | if( size > 1 ) 121 | dint = dint / size 122 | endif 123 | d = 0 ; i = 1 124 | while( d < 360 ) 125 | x.i = 0.4 * math_sin(d*3.14159/180) 126 | y.i = 0.4 * math_cos(d*3.14159/180) 127 | i = i + 1 ; d = d + dint 128 | endwhile 129 | pmax = i - 1 130 | cmd = 'drawpoly' 131 | endif 132 | 133 | * rotate 134 | if( angle != 0 ) 135 | d2r = 4.0 * math_atan(1.0) / 180.0 136 | i = 1 137 | while( i <= pmax ) 138 | if( x.i < 100 & y.i < 100 ) 139 | xtmp = x.i * math_cos(angle*d2r) - y.i * math_sin(angle*d2r) 140 | ytmp = x.i * math_sin(angle*d2r) + y.i * math_cos(angle*d2r) 141 | x.i = xtmp 142 | y.i = ytmp 143 | endif 144 | i = i + 1 145 | endwhile 146 | endif 147 | 148 | * size 149 | if( size != 0 ) 150 | i = 1 151 | while( i <= pmax ) 152 | if( x.i < 100 & y.i < 100 ) 153 | x.i = x.i * size 154 | y.i = y.i * size 155 | endif 156 | i = i + 1 157 | endwhile 158 | endif 159 | 160 | 161 | * draw 162 | strtail = '' 163 | if( fill = 1 ) ; strtail = strtail % ' -f' ; endif 164 | strtail = strtail % ' -rgba 'r' 'g' 'b' 'a 165 | if( setline != '' ) ; strtail = strtail % ' -setline ' % setline ; endif 166 | 167 | str = '' 168 | i = 1 169 | while( i <= pmax ) 170 | * while( x.i != 999 & y.i != 999 ) 171 | 172 | if( x.i = 111 & y.i = 111 ) 173 | 'drawline 'str' 'strtail 174 | str = '' 175 | else 176 | str = str % x.i+xpos % ' ' % y.i+ypos % ' ' 177 | endif 178 | i = i + 1 179 | endwhile 180 | 181 | cmd' 'str' 'strtail 182 | 183 | return 184 | 185 | * 186 | * help 187 | * 188 | function help() 189 | say ' Name:' 190 | say ' drawmark '_version' - draw mark' 191 | say ' ' 192 | say ' Usage:' 193 | say ' drawmark mark-name p q [size] [-angle angle]' 194 | say ' [ -f ]' 195 | say ' [ ( -rgb r g b | -rgba r g b a ) ]' 196 | say ' [ -setline setline-options ]' 197 | say ' [ -by ( world | grid | xy ) ]' 198 | say '' 199 | say ' mark-name : rectangle, triangle, plus, or circle' 200 | say '' 201 | say ' p, q : positions' 202 | say '' 203 | say ' -f : filled mark' 204 | say '' 205 | say ' -rgb | -rgba : rgb or rgba values in [0-255]' 206 | say '' 207 | say ' -setline : options same as "set line"' 208 | say '' 209 | say ' -by : unit of (p, q)' 210 | say ' world : world coordinate (e.g. lat)' 211 | say ' grid : grid coordinate (grid number)' 212 | say ' xy : display coordinate (e.g. 11x8.5)' 213 | say '' 214 | say ' Note:' 215 | say ' [arg-name] : specify if needed' 216 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 217 | say '' 218 | say ' Copyright (C) 2016-2020 Chihiro Kodama' 219 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 220 | say '' 221 | return 222 | -------------------------------------------------------------------------------- /drawpoly.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function drawpoly( args ) 5 | _version = '0.02r2' 6 | rc = gsfallow( 'on' ) 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | * pos = 1 13 | 14 | ***** Default value 15 | * closed: for drawline.gs 16 | closed = 1 17 | by = 'xy' 18 | fill = 0 19 | r = -1 20 | g = -1 21 | b = -1 22 | a = -1 23 | setline = '' 24 | 25 | ***** Arguement ***** 26 | i = 1 27 | p = 0 28 | while( 1 ) 29 | arg = subwrd( args, i ) 30 | i = i + 1; 31 | if( arg = '' ); break; endif 32 | 33 | while( 1 ) 34 | *** option 35 | if( arg = '-o' | arg = 'opened' ) ; closed = 0 ; break ; endif 36 | if( arg = '-f' ) ; fill = 1 ; break ; endif 37 | if( arg = '-by' ) ; by=subwrd(args,i) ; i=i+1 ; break ; endif 38 | if( arg = '-rgb' ) 39 | r = subwrd(args,i) 40 | g = subwrd(args,i+1) 41 | b = subwrd(args,i+2) 42 | i=i+3 ; break 43 | endif 44 | if( arg = '-rgba' ) 45 | r = subwrd(args,i) 46 | g = subwrd(args,i+1) 47 | b = subwrd(args,i+2) 48 | a = subwrd(args,i+3) 49 | i=i+4 ; break 50 | endif 51 | if( arg = '-setline' ) 52 | setline = subwrd(args,i) ; i=i+1 53 | tmp = subwrd(args,i) 54 | if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif 55 | tmp = subwrd(args,i) 56 | if( valnum(tmp) != 0 ) ; setline = setline % ' ' % tmp ; i=i+1 ; endif 57 | break 58 | endif 59 | if( arg = '-a' ) ; a=subwrd(args,i) ; i=i+1 ; break ; endif 60 | if( valnum(arg) != 0 ) 61 | x.p = arg 62 | y.p = subwrd(args,i) 63 | i = i + 1 64 | p = p + 1 65 | break 66 | endif 67 | 68 | say 'syntax error: 'arg 69 | return 70 | 71 | endwhile 72 | endwhile 73 | pmax = p - 1 74 | 75 | * color table from http://cola.gmu.edu/grads/gadoc/colorcontrol.html 76 | r.0 = 0 ; g.0 = 0 ; b.0 = 0 77 | r.1 = 255 ; g.1 = 255 ; b.1 = 255 78 | r.2 = 250 ; g.2 = 60 ; b.2 = 60 79 | r.3 = 0 ; g.3 = 220 ; b.3 = 0 80 | r.4 = 30 ; g.4 = 60 ; b.4 = 255 81 | r.5 = 0 ; g.5 = 200 ; b.5 = 200 82 | r.6 = 240 ; g.6 = 0 ; b.6 = 130 83 | r.7 = 230 ; g.7 = 220 ; b.7 = 50 84 | r.8 = 240 ; g.8 = 130 ; b.8 = 40 85 | r.9 = 160 ; g.9 = 0 ; b.9 = 200 86 | r.10 = 160 ; g.10 = 230 ; b.10 = 50 87 | r.11 = 0 ; g.11 = 160 ; b.11 = 255 88 | r.12 = 230 ; g.12 = 175 ; b.12 = 45 89 | r.13 = 0 ; g.13 = 210 ; b.13 = 140 90 | r.14 = 130 ; g.14 = 0 ; b.14 = 220 91 | r.15 = 170 ; g.15 = 170 ; b.15 = 170 92 | 93 | if( setline != '' ) 94 | 'set line 'setline 95 | if( a != -1 ) 96 | c = subwrd( setline, 1 ) 97 | 'set rgb 99 'r.c' 'g.c' 'b.c' 'a 98 | 'set line 99' 99 | endif 100 | endif 101 | 102 | if( r != -1 & g != -1 & g != -1 ) 103 | if( a != -1 ) ; 'set rgb 99 'r' 'g' 'b' 'a 104 | else ; 'set rgb 99 'r' 'g' 'b 105 | endif 106 | 'set line 99' 107 | endif 108 | 109 | p = 0 110 | pmm = -1 111 | str_fill = '' 112 | while( p <= pmax ) 113 | if( by = 'world' ) ; xy.p = qw2xy( x.p, y.p ) ; endif 114 | if( by = 'grid' ) ; xy.p = qgr2xy( x.p, y.p ) ; endif 115 | if( by = 'xy' ) ; xy.p = x.p % ' ' % y.p ; endif 116 | 117 | if( pmm >= 0 & fill = 0 ) 118 | 'draw line 'xy.pmm' 'xy.p 119 | endif 120 | if( fill = 1 ) 121 | str_fill = str_fill % xy.p % ' ' 122 | endif 123 | 124 | p = p + 1 125 | pmm = pmm + 1 126 | endwhile 127 | 128 | if( fill = 0 & closed = 1 ) 129 | 'draw line 'xy.pmax' 'xy.0 130 | endif 131 | if( fill = 1 ) 132 | 'draw polyf 'str_fill 133 | endif 134 | 135 | return 136 | 137 | * 138 | * help 139 | * 140 | function help() 141 | say ' Name:' 142 | say ' drawpoly '_version' - draw polygon' 143 | say ' ' 144 | say ' Usage:' 145 | say ' drawpoly [ -o | open ]' 146 | say ' [ -f ]' 147 | say ' [ -rgb r g b ]' 148 | say ' [ -rgba r g b a ]' 149 | say ' [ -setline setline-options ]' 150 | say ' [ -by ( world | grid | xy ) ] x1 y1 x2 y2 ...' 151 | say ' ' 152 | say '' 153 | say ' -o | open : open polygon (for drawline.gs)' 154 | say '' 155 | say ' -f : filled' 156 | say '' 157 | say ' -rgb | -rgba : rgb or rgba values in [0-255]' 158 | say '' 159 | say ' -setline : options same as "set line"' 160 | say '' 161 | say ' -by : unit of p1, q1, p2, q2' 162 | say ' world : world coordinate (e.g. lat)' 163 | say ' grid : grid coordinate (grid number)' 164 | say ' xy : same as "draw line"' 165 | say '' 166 | say ' x1, y1, ... : positions' 167 | say '' 168 | say ' Note:' 169 | say ' [arg-name] : specify if needed' 170 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 171 | say '' 172 | say ' Copyright (C) 2013-2019 Chihiro Kodama' 173 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 174 | say '' 175 | return 176 | -------------------------------------------------------------------------------- /draws.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function draws(args) 5 | _version='0.05r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | pos = 'tc' 15 | base = 'none' 16 | xoffset = 0 17 | yoffset = 0 18 | color = 1 19 | setfont = '' 20 | angle = '' 21 | by = 'figure' 22 | x = -1 23 | y = -1 24 | 25 | ***** Arguement ***** 26 | i=1 27 | flag=0 28 | while(1) 29 | arg = subwrd(args,i) 30 | i = i + 1 31 | if( arg = '' ); break; endif 32 | 33 | while(1) 34 | *** option 35 | if( arg = '-angle' ) ; angle = subwrd(args,i); i=i+1; break; endif 36 | if( arg = '-base' ) ; base = subwrd(args,i); i=i+1; break; endif 37 | if( arg = '-color' ) ; color = subwrd(args,i); i=i+1; break; endif 38 | if( arg = '-pos' ) ; pos = subwrd(args,i); i=i+1; break; endif 39 | if( arg = '-setfont' ) ; setfont = subwrd(args,i); i=i+1; break; endif 40 | if( arg = '-xoffset' | arg = '-xo' ) ; xoffset = subwrd(args,i); i=i+1; break; endif 41 | if( arg = '-yoffset' | arg = '-yo' ) ; yoffset = subwrd(args,i); i=i+1; break; endif 42 | if( arg = '-by' ) 43 | by = subwrd(args,i) 44 | i=i+1 45 | if( by = 'xy' | by = 'grid' | by = 'world' ) 46 | x = subwrd(args,i) ; i=i+1 47 | y = subwrd(args,i) ; i=i+1 48 | endif 49 | break 50 | endif 51 | 52 | flag = 1 53 | i = i - 1 54 | break; 55 | endwhile 56 | 57 | if( flag = 1 ); break; endif 58 | 59 | endwhile 60 | 61 | *** string 62 | start=0 63 | end=math_strlen(args) 64 | * order of the word 65 | word=0 66 | * previous character (0:space 1:word) 67 | pre=0 68 | 69 | while( start < end ) 70 | start = start + 1 71 | 72 | c = substr(args, start, 1) 73 | if( c != ' ' & pre = 0 ) 74 | word = word + 1 75 | pre = 1 76 | else 77 | if( c = ' ' & pre = 1 ) 78 | pre = 0 79 | endif 80 | endif 81 | 82 | if( word = i ) ; break; endif 83 | 84 | endwhile 85 | 86 | str = substr(args, start, end-start+1) 87 | 88 | **************************************** 89 | * case 1: relative to figure 90 | **************************************** 91 | if( by = 'figure' ) 92 | 93 | ***** Parameter adjust ***** 94 | if( base = 'none' ) 95 | if( pos = 'tc' ); base = 'bc'; endif 96 | if( pos = 'bc' ); base = 'tc'; endif 97 | if( pos = 'tl' ); base = 'bl'; endif 98 | if( pos = 'bl' ); base = 'tl'; endif 99 | if( pos = 'tr' ); base = 'br'; endif 100 | if( pos = 'br' ); base = 'tr'; endif 101 | if( pos = 'l' ); base = 'r'; endif 102 | if( pos = 'r' ); base = 'l'; endif 103 | endif 104 | ***** TODO: Parameter check ***** 105 | 106 | ***** Get gxinfo ***** 107 | * 'q gxinfo' 108 | * temp = sublin(result, 3) 109 | * xmin = subwrd(temp, 4) 110 | * xmax = subwrd(temp, 6) 111 | * temp = sublin(result, 4) 112 | * ymin = subwrd(temp, 4) 113 | * ymax = subwrd(temp, 6) 114 | xmin = qgxinfo( 'xmin' ) 115 | xmax = qgxinfo( 'xmax' ) 116 | ymin = qgxinfo( 'ymin' ) 117 | ymax = qgxinfo( 'ymax' ) 118 | 119 | if( pos = 'tc' ) 120 | x = xmin + 0.5 * (xmax - xmin) + xoffset 121 | y = ymax + 0.1 + yoffset 122 | endif 123 | if( pos = 'bc' ) 124 | x = xmin + 0.5 * (xmax - xmin) + xoffset 125 | y = ymin - 0.1 + yoffset 126 | endif 127 | if( pos = 'tl' ) 128 | x = xmin + xoffset 129 | y = ymax + 0.1 + yoffset 130 | endif 131 | if( pos = 'bl' ) 132 | x = xmin + xoffset 133 | y = ymin - 0.1 + yoffset 134 | endif 135 | if( pos = 'tr' ) 136 | x = xmax + xoffset 137 | y = ymax + 0.1 + yoffset 138 | endif 139 | if( pos = 'br' ) 140 | x = xmax + xoffset 141 | y = ymin - 0.1 + yoffset 142 | endif 143 | if( pos = 'l' ) 144 | x = xmin - 0.1 + xoffset 145 | y = ymin + 0.5 * ( ymax - ymin ) + yoffset 146 | endif 147 | if( pos = 'r' ) 148 | x = xmax + 0.1 + xoffset 149 | y = ymin + 0.5 * ( ymax - ymin ) + yoffset 150 | endif 151 | endif 152 | 153 | **************************************** 154 | if( by != 'figure' ) 155 | if( base = 'none' ) ; base = '' ; endif 156 | endif 157 | 158 | **************************************** 159 | * case 2: xy 160 | **************************************** 161 | if( by = 'xy' ) 162 | x = x + xoffset 163 | y = y + yoffset 164 | endif 165 | 166 | **************************************** 167 | * case 3: world 168 | **************************************** 169 | if( by = 'world' ) 170 | xy = qw2xy( x, y ) 171 | x = subwrd( xy, 1 ) + xoffset 172 | y = subwrd( xy, 2 ) + yoffset 173 | endif 174 | 175 | **************************************** 176 | * case 4: grid 177 | **************************************** 178 | if( by = 'grid' ) 179 | xy = qgr2xy( x, y ) 180 | x = subwrd( xy, 1 ) + xoffset 181 | y = subwrd( xy, 2 ) + yoffset 182 | endif 183 | 184 | ***** draw ***** 185 | if( angle = '' ) 186 | 'set string 'color' 'base 187 | else 188 | 'set string 'color' 'base' 3 'angle 189 | endif 190 | if( setfont != "" ) 191 | if( angle = '' ) 192 | 'setfont 'setfont' -base 'base 193 | else 194 | 'setfont 'setfont' -base 'base' -angle 'angle 195 | endif 196 | endif 197 | 'draw string 'x' 'y' 'str 198 | 199 | return 200 | 201 | * 202 | * help 203 | * 204 | function help() 205 | say ' Name:' 206 | say ' draws '_version' - draw string at the position specified relative to the figure' 207 | say ' ' 208 | say ' Usage:' 209 | say ' draws' 210 | say ' ([-by figure] [-pos position] [-base base]' 211 | say ' | -by (world | grid | xy) xpos ypos)' 212 | say ' [(-xoffset | -xo) xoffset] [(-yoffset | -yo) yoffset]' 213 | say ' [-color color] [-setfont size] [-angle angle]' 214 | say ' string' 215 | say ' ' 216 | say ' -by : Coordinate type' 217 | say ' figure : relative to figure (default)' 218 | say ' world : world coordinate (e.g. lat)' 219 | say ' grid : grid coordinate (grid number)' 220 | say ' xy : same as "draw line"' 221 | say ' position : Position to draw string. Default value is "tc".' 222 | say ' tc: top center, bc: buttom center,' 223 | say ' tl: top left, bl: buttom left,' 224 | say ' tr: top right, br: buttom right,' 225 | say ' l:left, r: right' 226 | say ' base : Base position of the string.' 227 | say ' How to specify is same as position.' 228 | say ' xpos, ypos : positions' 229 | say ' xoffset : Horizontal offset. Default value is 0.' 230 | say ' yoffset : Vertical offset. Default value is 0.' 231 | say ' color : Font color. Default value is 1.' 232 | say ' size : Size for setfont.gs.' 233 | say ' angle : Rotation angle of string in degree. Default value is 0.' 234 | say ' string : String to draw. Specify it as the last option.' 235 | say '' 236 | say ' Note:' 237 | say ' [arg-name] : specify if needed' 238 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 239 | say '' 240 | say ' Copyright (C) 2009-2019 Chihiro Kodama' 241 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 242 | say '' 243 | return 244 | -------------------------------------------------------------------------------- /dshade.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function dshade( args ) 5 | _version = '0.01b2' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | sw = subwrd( args, 1 ) 14 | 15 | **************************************** 16 | * set color levels 17 | **************************************** 18 | if( sw = 'set' ) 19 | 20 | ***** arguements ***** 21 | * default 22 | alpha = '0 255' 23 | 24 | * user-specified arguemtnts 25 | sw2 = subwrd( args, 2 ) 26 | colorarg = '-ret' 27 | i = 3 28 | while( i <= 1000 ) 29 | word = subwrd( args, i ) 30 | if( word = '' ) ; break ; endif 31 | if( word = '-alpha' ) 32 | i = i + 1 33 | alpha = subwrd( args, i ) 34 | i = i + 1 35 | alpha = alpha % ' ' % subwrd( args, i ) 36 | else 37 | colorarg = colorarg % ' ' % word 38 | endif 39 | i = i + 1 40 | endwhile 41 | 42 | * check arguements 43 | if( sw2 != 'back' & sw2 != 'over' ) 44 | say 'error: second arguement must be "back" or "over" when the first arguement is "set".' 45 | exit 46 | endif 47 | 48 | * get and save color information 49 | colorret = color( colorarg ) 50 | 51 | if( sw2 = 'back' ) 52 | setstr( colback, colorret ) 53 | else 54 | setstr( colover, colorret ) 55 | setstr( alphaover, alpha ) 56 | endif 57 | 58 | return 59 | endif 60 | 61 | **************************************** 62 | * draw double-shaded figure 63 | **************************************** 64 | if( sw = 'draw' ) 65 | ***** arguements ***** 66 | * default 67 | 68 | * user-specified arguemtnts 69 | vback = subwrd( args, 2 ) 70 | 'tmpvback = 'vback 71 | vover = subwrd( args, 3 ) 72 | 'tmpvover = 'vover 73 | 74 | colback = getstr( colback ) 75 | colover = getstr( colover ) 76 | alphaover = getstr( alphaover ) 77 | 78 | key.1 = colback 79 | key.2 = colover 80 | f = 1 81 | while( f <= 2 ) 82 | n = 1 83 | while( n <= 1000 ) 84 | lev.f.n = sep( key.f, 'clevs', n ) 85 | r.f.n = sep( key.f, 'rgb', 4*n-2 ) 86 | g.f.n = sep( key.f, 'rgb', 4*n-1 ) 87 | b.f.n = sep( key.f, 'rgb', 4*n-0 ) 88 | say f % ',' % n % ' : ' % lev.f.n % ' ' % r.f.n % ' ' % g.f.n % ' ' % b.f.n 89 | if( lev.f.n = '' ) ; break ; endif 90 | n = n + 1 91 | endwhile 92 | 93 | * say f % ',' % n % ' : ' % 'NON ' % r.f.n % ' ' % g.f.n % ' ' % b.f.n 94 | cnum.f = n 95 | * say n 96 | f = f + 1 97 | endwhile 98 | 99 | a.2.1 = subwrd( alphaover, 1 ) 100 | n = cnum.2 101 | a.2.n = subwrd( alphaover, 2 ) 102 | c = 2 103 | while( c <= n - 1 ) 104 | a.2.c = a.2.1 + ( a.2.n - a.2.1 ) / ( n - 1 ) * ( c - 1 ) 105 | c = c + 1 106 | endwhile 107 | 108 | 109 | c = 1 110 | while( c <= cnum.1 ) 111 | cmm = c - 1 112 | 113 | 'set gxout shaded' 114 | 115 | d = 1 116 | ccols = '' 117 | clevs = '' 118 | while( d <= cnum.2 ) 119 | w = a.2.d / 255.0 120 | r = ( 1 - w ) * r.1.c + w * r.2.d 121 | g = ( 1 - w ) * g.1.c + w * g.2.d 122 | b = ( 1 - w ) * b.1.c + w * b.2.d 123 | temp = d + 15 124 | 'set rgb 'temp' 'r' 'g' 'b 125 | ccols = ccols % ' ' % (d+15) 126 | if( d < cnum.2 ) ; clevs = clevs % ' ' % lev.2.d ; endif 127 | d = d + 1 128 | endwhile 129 | 'set ccols 'ccols 130 | 'set clevs 'clevs 131 | 132 | if( c = 1 ) 133 | 'd maskout( tmpvover, 'lev.1.c'-tmpvback )' 134 | endif 135 | if( c = cnum.1 ) 136 | 'd maskout( tmpvover, tmpvback-'lev.1.cmm' )' 137 | endif 138 | if( c != 1 & c != cnum.1 ) 139 | 'd maskout( tmpvover, -(tmpvback-'lev.1.cmm')*(tmpvback-'lev.1.c') )' 140 | endif 141 | 142 | c = c + 1 143 | endwhile 144 | 145 | 146 | 147 | * fill boundary 148 | * another better way exist??? 149 | 150 | c = 1 151 | while( c <= cnum.1 - 1 ) 152 | 153 | 'c = maskout( tmpvover, tmpvback-'lev.1.c' )' 154 | 'int1 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 155 | 'int1 = const( int1, 1 )' 156 | 'int1 = const( int1, -1, -u )' 157 | 158 | 'c = maskout( tmpvover, 'lev.1.c'-tmpvback )' 159 | 'int2 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 160 | 'int2 = const( int2, 1 )' 161 | 'int2 = const( int2, -1, -u )' 162 | 163 | 'bound1 = maskout( maskout( tmpvback, -int1 ), -int2 )' 164 | 'bound1 = const( const( bound1, 1 ), -1, -u )' 165 | if( c = 1 ) 166 | 'bound = bound1 + 1' 167 | else 168 | 'bound = bound + ( bound1 + 1 )' 169 | endif 170 | c = c + 1 171 | endwhile 172 | 173 | 174 | 175 | *'bound = maskout( 'tmpvback', (bound1+1) + (bound2+1) - 1 )' 176 | 177 | 'bound = maskout( 'tmpvback', bound - 1 )' 178 | 'bound = const( const( bound, 1 ), -1, -u )' 179 | 180 | 181 | 'set gxout grfill' 182 | 183 | *'d maskout( b, bound )' 184 | 185 | 186 | 'tmpvover = maskout( tmpvover, bound )' 187 | 188 | 189 | c = 1 190 | while( c <= cnum.1 ) 191 | cmm = c - 1 192 | 193 | * kind = '(0,127,0)->(255,255,255)' 194 | * kind = '('r.1.c','g.1.c','b.1.c')->('r.2.12','r.2.12','r.2.12')' 195 | * 'color 0.1 20.1 2 -kind 'kind 196 | 'set gxout grfill' 197 | 198 | d = 1 199 | ccols = '' 200 | clevs = '' 201 | while( d <= cnum.2 ) 202 | w = a.2.d / 255.0 203 | r = ( 1 - w ) * r.1.c + w * r.2.d 204 | g = ( 1 - w ) * g.1.c + w * g.2.d 205 | b = ( 1 - w ) * b.1.c + w * b.2.d 206 | temp = d + 15 207 | 'set rgb 'temp' 'r' 'g' 'b 208 | ccols = ccols % ' ' % (d+15) 209 | if( d < cnum.2 ) ; clevs = clevs % ' ' % lev.2.d ; endif 210 | d = d + 1 211 | endwhile 212 | 'set ccols 'ccols 213 | 'set clevs 'clevs 214 | 215 | if( c = 1 ) 216 | 'd maskout( tmpvover, 'lev.1.c'-tmpvback )' 217 | endif 218 | if( c = cnum.1 ) 219 | 'd maskout( tmpvover, tmpvback-'lev.1.cmm' )' 220 | endif 221 | if( c != 1 & c != cnum.1 ) 222 | 'd maskout( tmpvover, -(tmpvback-'lev.1.cmm')*(tmpvback-'lev.1.c') )' 223 | endif 224 | 225 | c = c + 1 226 | endwhile 227 | ******************************************************************* 228 | 229 | 230 | exit 231 | 232 | '!sleep 3s' 233 | **************************************** 234 | * reverse background & over-paint to smooth boundary 235 | 236 | c = 1 237 | while( c <= cnum.2 ) 238 | cmm = c - 1 239 | 240 | * kind = '(0,127,0)->(255,255,255)' 241 | * kind = '('r.1.c','g.1.c','b.1.c')->('r.2.12','r.2.12','r.2.12')' 242 | * 'color 0.1 20.1 2 -kind 'kind 243 | 'set gxout shaded' 244 | 245 | d = 1 246 | ccols = '' 247 | clevs = '' 248 | while( d <= cnum.1 ) 249 | w = a.2.c / 255.0 250 | r = ( 1 - w ) * r.1.d + w * r.2.d 251 | g = ( 1 - w ) * g.1.d + w * g.2.d 252 | b = ( 1 - w ) * b.1.d + w * b.2.d 253 | temp = d + 15 254 | 'set rgb 'temp' 'r' 'g' 'b 255 | ccols = ccols % ' ' % (d+15) 256 | if( d < cnum.1 ) ; clevs = clevs % ' ' % lev.1.d ; endif 257 | d = d + 1 258 | endwhile 259 | * say ccols 260 | * say clevs 261 | 'set ccols 'ccols 262 | 'set clevs 'clevs 263 | 264 | if( c = 1 ) 265 | 'd maskout( maskout( vback, 'lev.2.c'-vover ), bound )' 266 | endif 267 | if( c = cnum.2 ) 268 | 'd maskout( maskout( vback, vover-'lev.2.cmm' ), bound )' 269 | endif 270 | if( c != 1 & c != cnum.2 ) 271 | 'd maskout( maskout( vback, -(vover-'lev.2.cmm')*(vover-'lev.2.c') ), bound )' 272 | endif 273 | 274 | c = c + 1 275 | endwhile 276 | **************************************** 277 | 278 | 279 | 280 | exit 281 | 282 | 283 | * lon=126 (x=127), lat=11 (y=102) 284 | 'temp = maskout( b, const( b, -1, -a ) )' 285 | 'set defval temp 127 102 1' 286 | 'set defval temp 128 102 2' 287 | *'set defval temp 129 102 3' 288 | 'set defval temp 127 103 3' 289 | 'set defval temp 128 103 4' 290 | *'set defval temp 129 103 5' 291 | *'set defval temp 127 104 3' 292 | *'set defval temp 128 104 4' 293 | *'set defval temp 129 104 5' 294 | 295 | 296 | 297 | exit 298 | **************************************** 299 | 300 | 301 | c = 1 302 | while( c <= cnum.1 ) 303 | cmm = c - 1 304 | 305 | * kind = '(0,127,0)->(255,255,255)' 306 | kind = '('r.1.c','g.1.c','b.1.c')->('r.2.12','r.2.12','r.2.12')' 307 | 'color 0.1 20.1 2 -kind 'kind 308 | 'set gxout grfill' 309 | 310 | if( c = 1 ) 311 | 'd maskout( vover, 'lev.1.c'-vback )' 312 | endif 313 | if( c = cnum.1 ) 314 | 'd maskout( vover, vback-'lev.1.cmm' )' 315 | endif 316 | if( c != 1 & c != cnum.1 ) 317 | 'd maskout( vover, -(vback-'lev.1.cmm')*(vback-'lev.1.c') )' 318 | endif 319 | 320 | c = c + 1 321 | endwhile 322 | 323 | 324 | exit 325 | 326 | *min.1 = 'infty' ; max.1 = 100 327 | *min.2 = 100 ; max.2 = '1000' 328 | *min.3 = 1000 ; max.3 = 'infty' 329 | 330 | c = 1 331 | while( c <= cnum.1 ) 332 | cpp = c + 1 333 | 334 | * kind = '(0,127,0)->(255,255,255)' 335 | kind = '('r.1.c','g.1.c','b.1.c')->('r.2.6','r.2.6','r.2.6')' 336 | 'color 0.1 20.1 2 -kind 'kind 337 | 'set gxout grfill' 338 | 339 | * if( min.c = 'infty' ) 340 | if( c = 1 ) 341 | 'd maskout( 'vover', 'max.c'-'vback' )' 342 | endif 343 | * if( max.c = 'infty' ) 344 | if( c = cnum.1 ) 345 | 'd maskout( 'vover', 'vback'-'min.c' )' 346 | endif 347 | * if( max.c != 'infty' & min.c != 'infty' ) 348 | if( c != 1 & c != cnum.1 ) 349 | 'd maskout( 'vover', -('vback'-'min.c')*('vback'-'max.c') )' 350 | endif 351 | 352 | c = c + 1 353 | endwhile 354 | 355 | 356 | exit 357 | 358 | clev = 1 359 | while( clev <= 3 ) 360 | * kind = '(0,127,0)->(255,255,255)' 361 | kind = '('r.1.clev','g.1.clev','b.1.clev')->('r.2.6','r.2.6','r.2.6')' 362 | 'color 0.1 20.1 2 -kind 'kind 363 | 'set gxout grfill' 364 | 365 | if( max.clev = 'infty' ) 366 | 'd maskout( 'vover', 'vback'-'min.clev' )' 367 | endif 368 | if( min.clev = 'infty' ) 369 | 'd maskout( 'vover', 'max.clev'-'vback' )' 370 | endif 371 | if( max.clev != 'infty' & min.clev != 'infty' ) 372 | 'd maskout( 'vover', -('vback'-'min.clev')*('vback'-'max.clev') )' 373 | endif 374 | 375 | clev = clev + 1 376 | endwhile 377 | 378 | 379 | exit 380 | 381 | 382 | 383 | 384 | exit 385 | 386 | * land 387 | *'color 1 1 1 -kind (165,42,42)->(0,0,255)' 388 | *'color 1 1 1 -kind (0,255,0)->(255,255,255)' 389 | *'set rgb 16 0 127 0' 390 | *'set rgb 17 255 255 255' 391 | 'color 0.1 20.1 2 -kind (0,127,0)->(255,255,255)' 392 | *'set ccols 16 17' 393 | *'set clevs 1' 394 | *'d maskout( lterp(prate.2*24*3600,hgs.1(t=1)), hgs.1(t=1)-100 )' 395 | *'d maskout( lterp(prate.2*24*3600,dummy), lterp(hgs.1(t=1)-100,dummy) )' 396 | 397 | *'set gxout grfill' 398 | 'd maskout( b, a-100 )' 399 | 400 | * ocean 401 | *'color 1 1 1 -kind (255,255,255)->(0,0,255)' 402 | *'set rgb 16 0 0 0' 403 | *'set rgb 17 255 255 255' 404 | *'set ccols 16 17' 405 | *'set clevs 1' 406 | 'color 0.1 20.1 2 -kind (0,0,255)->(255,255,255)' 407 | *'d maskout( lterp(prate.2*24*3600,hgs.1(t=1)), 100-hgs.1(t=1) )' 408 | *'d maskout( lterp(prate.2*24*3600,dummy), lterp(200-hgs.1(t=1),dummy) )' 409 | *'set gxout grfill' 410 | 'd maskout( b, 100-a )' 411 | 412 | 413 | 414 | 415 | exit 416 | 417 | 418 | 419 | *'c = maskout( 'vover', 'vback'-1000 )' 420 | *'int1 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 421 | *'int1 = const( int1, 1 )' 422 | *'int1 = const( int1, -1, -u )' 423 | 424 | *'c = maskout( 'vover', 1000-'vback' )' 425 | *'int2 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 426 | *'int2 = const( int2, 1 )' 427 | *'int2 = const( int2, -1, -u )' 428 | 429 | *'bound1 = maskout( maskout( 'vback', -int1 ), -int2 )' 430 | *'bound1 = const( const( bound1, 1 ), -1, -u )' 431 | 432 | 433 | *'c = maskout( 'vover', 'vback'-100 )' 434 | *'int1 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 435 | *'int1 = const( int1, 1 )' 436 | *'int1 = const( int1, -1, -u )' 437 | 438 | *'c = maskout( 'vover', 100-'vback' )' 439 | *'int2 = cdiff( c, x ) + cdiff( c, y ) + cdiff( cdiff( c, x ), y ) + c' 440 | *'int2 = const( int2, 1 )' 441 | *'int2 = const( int2, -1, -u )' 442 | 443 | *'bound2 = maskout( maskout( 'vback', -int1 ), -int2 )' 444 | *'bound2 = const( const( bound2, 1 ), -1, -u )' 445 | 446 | 447 | 448 | 449 | 450 | 451 | return 452 | endif 453 | 454 | say 'error: dshade.gs did nothing' 455 | return 456 | 457 | 458 | 459 | function sep( colorret, id, num ) 460 | * say 'sep: ' % colorret 461 | * say id % ' ' % num 462 | i = 1 463 | n = 1 464 | flag = 0 465 | while( i <= 1000 ) 466 | word = subwrd( colorret, i ) 467 | if( flag = 1 & valnum(word) != 0 ) 468 | if( n = num ) ; return word ; endif 469 | n = n + 1 470 | else 471 | flag = 0 472 | endif 473 | if( word = id ) 474 | flag = 1 475 | endif 476 | i = i + 1 477 | endwhile 478 | 479 | return '' 480 | 481 | 482 | * 483 | * help 484 | * 485 | function help() 486 | say ' Name:' 487 | say ' dshade '_version' - draw transparent shadings' 488 | say ' ' 489 | say ' Usage(1): set background color' 490 | say ' dshade set back color-args...' 491 | say '' 492 | say ' Usage(2): set overlay color' 493 | say ' dshade set over [-alpha min max] color-args...' 494 | say '' 495 | say ' Usage(3): draw' 496 | say ' dshade draw var-back var-over' 497 | say '' 498 | say ' color-args : same as color.gs' 499 | say ' -alpha min max : min. and max. transparency' 500 | say ' var-back : background variable' 501 | say ' var-over : variable to overlay' 502 | say '' 503 | say ' Note:' 504 | say ' [arg-name] : specify if needed' 505 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 506 | say '' 507 | say ' dshades.gs needs setstr.gsf, getstr.gsf, strmem.gsf' 508 | say ' dshades.gs needs color.gs whose version is more than 0.06r3' 509 | say '' 510 | say ' Copyright (C) 2010-2010 Chihiro Kodama' 511 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 512 | say '' 513 | return 514 | -------------------------------------------------------------------------------- /dtopen.gsf: -------------------------------------------------------------------------------- 1 | * cmd: open command (if necessary) 2 | function dtopen( dir, tail, cmd, error ) 3 | ret = read( dir'/'tail ) 4 | stat = sublin( ret, 1 ) 5 | if( stat = 0 ) 6 | fv_pre = last() 7 | 8 | if( cmd = 'cmd' | cmd = '' ) 9 | 'xopen 'dir'/'tail 10 | else 11 | cmd' 'dir'/'tail 12 | endif 13 | fv = last() 14 | if( fv = fv_pre ) 15 | fv = -1 16 | else 17 | say 'open #' % fv % ': ' % dir % '/' % tail 18 | endif 19 | else 20 | fv = -1 21 | endif 22 | 23 | if( error != 0 & fv < 0 ) 24 | say 'error: fail to open ' % dir % '/' % tail 25 | exit 26 | endif 27 | if( fv < 0 ) 28 | say 'info: fail to open ' % dir % '/' % tail 29 | endif 30 | return fv 31 | -------------------------------------------------------------------------------- /energybox.gs: -------------------------------------------------------------------------------- 1 | function energybox(args) 2 | 3 | *** arguement *** 4 | type = subwrd( args, 1 ) 5 | 6 | 7 | xbase = 0.0 8 | ybase = 0.0 9 | az = '' 10 | kz = '' 11 | ae = '' 12 | ke = '' 13 | w = '' 14 | c_az_kz = '' 15 | c_kz_ae = '' 16 | c_ae_ke = '' 17 | c_ke_kz = '' 18 | c_kz_w = '' 19 | qz = '' 20 | qz_res = '' 21 | qe = '' 22 | qe_res = '' 23 | dz_res = '' 24 | de_res = '' 25 | 26 | i = 2 27 | arg = "dummy" 28 | while( arg != "" ) 29 | arg = subwrd( args, i ) 30 | i = i + 1 31 | 32 | if( arg = "-xbase" ) ; xbase = subwrd( args, i ) ; i = i + 1 ; endif 33 | if( arg = "-ybase" ) ; ybase = subwrd( args, i ) ; i = i + 1 ; endif 34 | 35 | if( arg = "-az" ) ; az = subwrd( args, i ) ; i = i + 1 ; endif 36 | if( arg = "-kz" ) ; kz = subwrd( args, i ) ; i = i + 1 ; endif 37 | if( arg = "-ae" ) ; ae = subwrd( args, i ) ; i = i + 1 ; endif 38 | if( arg = "-ke" ) ; ke = subwrd( args, i ) ; i = i + 1 ; endif 39 | if( arg = "-w" ) ; w = subwrd( args, i ) ; i = i + 1 ; endif 40 | if( arg = "-c_az_kz" ) ; c_az_kz = subwrd( args, i ) ; i = i + 1 ; endif 41 | if( arg = "-c_kz_ae" ) ; c_kz_ae = subwrd( args, i ) ; i = i + 1 ; endif 42 | if( arg = "-c_ae_ke" ) ; c_ae_ke = subwrd( args, i ) ; i = i + 1 ; endif 43 | if( arg = "-c_ke_kz" ) ; c_ke_kz = subwrd( args, i ) ; i = i + 1 ; endif 44 | if( arg = "-c_kz_w" ) ; c_kz_w = subwrd( args, i ) ; i = i + 1 ; endif 45 | if( arg = "-qz" ) ; qz = subwrd( args, i ) ; i = i + 1 ; endif 46 | if( arg = "-qz_res" ) ; qz_res = subwrd( args, i ) ; i = i + 1 ; endif 47 | if( arg = "-qe" ) ; qe = subwrd( args, i ) ; i = i + 1 ; endif 48 | if( arg = "-qe_res" ) ; qe_res = subwrd( args, i ) ; i = i + 1 ; endif 49 | if( arg = "-dz_res" ) ; dz_res = subwrd( args, i ) ; i = i + 1 ; endif 50 | if( arg = "-de_res" ) ; de_res = subwrd( args, i ) ; i = i + 1 ; endif 51 | 52 | endwhile 53 | 54 | 55 | 56 | if( type = 'iwasaki4' ) 57 | 58 | box( xbase+1.4, xbase+2.0, ybase+5.4, ybase+6.0, 'A`bZ', az ) 59 | box( xbase+1.4, xbase+2.0, ybase+4.2, ybase+4.8, 'K`bZ', kz ) 60 | box( xbase+2.6, xbase+3.2, ybase+5.4, ybase+6.0, 'A`bE', ae ) 61 | box( xbase+2.6, xbase+3.2, ybase+4.2, ybase+4.8, 'K`bE', ke ) 62 | 63 | 'setfont small -angle 0' 64 | head = 0.15 65 | 66 | 'arrow 'xbase+1.7' 'ybase+5.4' 'xbase+1.7' 'ybase+4.8' -head 'head 67 | string( xbase+1.4, ybase+5.1, c_az_kz ) 68 | 69 | 'arrow 'xbase+2.0' 'ybase+4.8' 'xbase+2.6' 'ybase+5.4' -head 'head 70 | 'setfont small -angle 45' 71 | string( xbase+2.1, ybase+5.1, c_kz_ae ) 72 | 'setfont small -angle 0' 73 | 74 | 'arrow 'xbase+2.9' 'ybase+5.4' 'xbase+2.9' 'ybase+4.8' -head 'head 75 | string( xbase+3.2, ybase+5.1, c_ae_ke ) 76 | 77 | 'arrow 'xbase+2.6' 'ybase+4.5' 'xbase+2.0' 'ybase+4.5' -head 'head 78 | string( xbase+2.3, ybase+4.3, c_ke_kz ) 79 | 80 | 'arrow 'xbase+1.1' 'ybase+6.3' 'xbase+1.4' 'ybase+6.0' -head 'head 81 | if( qz_res = '' ) ; string( xbase+1.1, ybase+6.5, qz ) 82 | else ; string( xbase+1.1, ybase+6.7, qz ) ; endif 83 | string_bracket( xbase+1.1, ybase+6.5, qz_res ) 84 | 85 | 'arrow 'xbase+3.5' 'ybase+6.3' 'xbase+3.2' 'ybase+6.0' -head 'head 86 | if( qe_res = '' ) ; string( xbase+3.5, ybase+6.5, qe ) 87 | else ; string( xbase+3.5, ybase+6.7, qe ) ; endif 88 | string_bracket( xbase+3.5, ybase+6.5, qe_res ) 89 | 90 | 91 | 'arrow 'xbase+1.7' 'ybase+4.2' 'xbase+1.7' 'ybase+3.9' -head 'head 92 | string_bracket( xbase+1.7, ybase+3.7, dz_res ) 93 | 94 | 'arrow 'xbase+2.9' 'ybase+4.2' 'xbase+2.9' 'ybase+3.9' -head 'head 95 | string_bracket( xbase+2.9, ybase+3.7, de_res ) 96 | 97 | endif 98 | 99 | 100 | 101 | 102 | if( type = 'iwasaki3' ) 103 | 104 | box( xbase+1.0, xbase+1.6, ybase+5.4, ybase+6.0, 'A`bZ', az ) 105 | box( xbase+2.2, xbase+2.8, ybase+5.4, ybase+6.0, 'K`bZ', kz ) 106 | box( xbase+3.4, xbase+4.0, ybase+5.4, ybase+6.0, 'W', w ) 107 | 108 | 'setfont small -angle 0 -base c' 109 | head = 0.15 110 | 111 | 'arrow 'xbase+1.6' 'ybase+5.7' 'xbase+2.2' 'ybase+5.7' -head 'head 112 | string( xbase+1.9, ybase+5.4, c_az_kz ) 113 | 114 | 'arrow 'xbase+2.8' 'ybase+5.7' 'xbase+3.4' 'ybase+5.7' -head 'head 115 | string( xbase+3.1, ybase+5.4, c_kz_w ) 116 | 117 | 'arrow 'xbase+1.3' 'ybase+6.3' 'xbase+1.3' 'ybase+6.0' -head 'head 118 | if( qz_res = '' ) ; string( xbase+1.3, ybase+6.5, qz ) 119 | else ; string( xbase+1.3, ybase+6.7, qz ) ; endif 120 | string_bracket( xbase+1.3, ybase+6.5, qz_res ) 121 | 122 | 'arrow 'xbase+3.7' 'ybase+6.3' 'xbase+3.7' 'ybase+6.0' -head 'head 123 | if( qe_res = '' ) ; string( xbase+3.7, ybase+6.5, qe ) 124 | else ; string( xbase+3.7, ybase+6.7, qe ) ; endif 125 | string_bracket( xbase+3.7, ybase+6.5, qe_res ) 126 | 127 | 'arrow 'xbase+2.5' 'ybase+5.4' 'xbase+2.5' 'ybase+5.1' -head 'head 128 | string_bracket( xbase+2.5, ybase+4.9, dz_res ) 129 | 130 | 'arrow 'xbase+3.7' 'ybase+5.4' 'xbase+3.7' 'ybase+5.1' -head 'head 131 | string_bracket( xbase+3.7, ybase+4.9, de_res ) 132 | 133 | 134 | endif 135 | 136 | 137 | 138 | 139 | 140 | 141 | return 142 | 143 | 144 | 145 | 146 | 147 | function box( xmin, xmax, ymin, ymax, name, value ) 148 | 'set line 1 1 6' 149 | 'draw rec 'xmin' 'ymin' 'xmax' 'ymax 150 | 151 | 'setfont normal' 152 | x = xmin + (xmax - xmin) / 2.0 153 | y = ymin + (ymax - ymin) / 4.0 * 3.0 154 | 'draw string 'x' 'y' 'name 155 | 156 | 157 | if( value != '' ) 158 | 159 | 'setfont small' 160 | * 'set strsiz 0.25 0.25' 161 | * 'set string 1 c 8' 162 | x = xmin + (xmax - xmin) / 2.0 163 | y = ymin + (ymax - ymin) / 4.0 164 | 'draw string 'x' 'y' 'math_format("%.2f",value) 165 | endif 166 | 167 | return 168 | 169 | 170 | 171 | function string( x, y, value ) 172 | if( value != '' ) 173 | 'draw string 'x' 'y' 'math_format("%.2f", value) 174 | endif 175 | return 176 | 177 | function string_bracket( x, y, value ) 178 | if( value != '' ) 179 | 'draw string 'x' 'y' ('math_format("%.2f",value)')' 180 | endif 181 | return 182 | -------------------------------------------------------------------------------- /find.gsf: -------------------------------------------------------------------------------- 1 | * return position of the target string in the string. 2 | * return -1 if target string does not exist. 3 | function find( str, tar ) 4 | l_str = math_strlen( str ) 5 | l_tar = math_strlen( tar ) 6 | i = 1 7 | while( i <= l_str - l_tar + 1 ) 8 | tmp = substr( str, i, l_tar ) 9 | if( tmp = tar ) ; return i ; endif 10 | i = i + 1 11 | endwhile 12 | return -1 13 | -------------------------------------------------------------------------------- /getstr.gsf: -------------------------------------------------------------------------------- 1 | function getstr( name ) 2 | rc = gsfallow( 'on' ) 3 | ret = strmem( get, name ) 4 | return ret 5 | -------------------------------------------------------------------------------- /gradsver.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * cmpver: e.g., "v2.1.a1" 3 | * 4 | * no specifiation of cmpver -> return GrADS version 5 | * 6 | * ver is newer than cmpver -> return 1 7 | * ver is same as cmpver -> return 0 8 | * ver is older than cmpver -> return -1 9 | * 10 | function gradsver( cmpver ) 11 | ret = '' 12 | rc = gsfallow( 'on' ) 13 | 14 | 'q config' 15 | line = sublin( result, 1 ) 16 | ver = subwrd( line, 2 ) 17 | 18 | if( cmpver = '' | cmpver = 'cmpver' ) 19 | return ver 20 | else 21 | if( ver = cmpver ) ; return 0 ; endif 22 | 23 | i = 1 24 | while( i <= 4 ) 25 | ver.i = rgnwrd( ver, i, i, '.' ) 26 | cmpver.i = rgnwrd( cmpver, i, i, '.' ) 27 | ver.i = subver2num( ver.i ) 28 | cmpver.i = subver2num( cmpver.i ) 29 | * say ver.i % ' ' % cmpver.i 30 | if( ver.i > cmpver.i ) ; return 1 ; endif 31 | if( ver.i < cmpver.i ) ; return -1 ; endif 32 | 33 | if( i = 1 & ver.i <= 91 ) 34 | say 'main version = 1 or less is not fully supported.' 35 | return -9999 36 | endif 37 | i = i + 1 38 | endwhile 39 | 40 | endif 41 | 42 | return -9999 43 | 44 | 45 | 46 | function subver2num( subver ) 47 | pref = 'none' 48 | if( valnum(subver) = 1 ) 49 | pref = 9 50 | else 51 | pref = substr( subver, 1, 1 ) 52 | subver = substr( subver, 2, 1024 ) 53 | if( pref = 'v' ) ; pref = 9 ; endif 54 | if( pref = 's' ) ; pref = 9 ; endif 55 | if( pref = 'a' ) ; pref = 5 ; endif 56 | if( pref = 'b' ) ; pref = 2 ; endif 57 | endif 58 | ret = pref % subver 59 | return ret 60 | -------------------------------------------------------------------------------- /grid.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function grid(args) 5 | _version='0.04r1' 6 | 7 | if( args = '' ) 8 | help() 9 | endif 10 | 11 | ***** Default value ***** 12 | xstep = 'none' 13 | ystep = 'none' 14 | lflag = 1 15 | aflag = 0 16 | xastep = 'none' 17 | yastep = 'none' 18 | 19 | ***** Arguement ***** 20 | i = 1 21 | flag = 0 22 | while(1) 23 | arg = subwrd(args,i) 24 | i = i + 1 25 | if( arg = '' ); break; endif 26 | while(1) 27 | *** option 28 | if( arg = '-nl' ) ; lflag = 0; break; endif 29 | if( arg = '-a' ) 30 | aflag = 1 31 | arg = subwrd(args,i) 32 | if( valnum(arg) != 0 & xastep = 'none' ) ; xastep = arg ; i = i + 1 ; endif 33 | arg = subwrd(args,i) 34 | if( valnum(arg) != 0 & yastep = 'none' ) ; yastep = arg ; i = i + 1 ; endif 35 | break 36 | endif 37 | 38 | if( valnum(arg) != 0 & xstep = 'none' ) ; xstep = arg ; break ; endif 39 | if( valnum(arg) != 0 & ystep = 'none' ) ; ystep = arg ; break ; endif 40 | 41 | 42 | say 'syntax error: 'arg 43 | return 44 | break; 45 | endwhile 46 | 47 | if( flag = 1 ); break; endif 48 | 49 | endwhile 50 | 51 | *** default value *** 52 | if( xstep = 'none' ) ; xstep = 1.0 ; endif 53 | if( ystep = 'none' ) ; ystep = xstep ; endif 54 | if( xastep = 'none' ) ; xastep = xstep / 2 ; endif 55 | if( yastep = 'none' ) ; yastep = xastep ; endif 56 | 57 | *** checking value *** 58 | if( xstep <= 0 | ystep <= 0 | xastep <= 0 | yastep <= 0 ) 59 | say "error! ---step value is negative---" 60 | return 61 | endif 62 | 63 | *** get gxinfo *** 64 | 'q gxinfo' 65 | line = sublin( result, 2 ) 66 | psx = subwrd( line, 4 ) 67 | psy = subwrd( line, 6 ) 68 | 69 | *** draw line (x) *** 70 | if( aflag = 1 ) 71 | 'set line 1 1 6' 72 | else 73 | 'set line 1 1 3' 74 | endif 75 | i = xstep + 0 76 | while( i < psx ) 77 | if( lflag = 1 ) 78 | 'set strsiz 'xstep/3' 'xstep/3 79 | 'set string 1 bc' 80 | 'draw string 'i' 0.05 'i 81 | 'draw line 'i' 'xstep/3+0.1' 'i' 'psy 82 | else 83 | 'draw line 'i' 0 'i' 'psy 84 | endif 85 | i = i + xstep 86 | endwhile 87 | 88 | if( aflag = 1 ) 89 | i = xastep + 0 90 | 'set line 1 1 1' 91 | while( i < psx ) 92 | if( math_abs( math_int(i/xstep)-(i/xstep)) > 0.001 ) 93 | 'draw line 'i' 0 'i' 'psy 94 | endif 95 | i = i + xastep 96 | endwhile 97 | endif 98 | 99 | 100 | *** draw line (y) *** 101 | if( aflag = 1 ) 102 | 'set line 1 1 6' 103 | else 104 | 'set line 1 1 3' 105 | endif 106 | i = ystep + 0 107 | while( i < psy ) 108 | if( lflag = 1 ) 109 | 'set strsiz 'ystep/3' 'ystep/3 110 | 'set string 1 l' 111 | 'draw string 0.05 'i' 'i 112 | 'draw line '0.1+ystep/3*math_strlen(i)' 'i' 'psx' 'i 113 | else 114 | 'draw line 0 'i' 'psx' 'i 115 | endif 116 | i = i + ystep 117 | endwhile 118 | 119 | if( aflag = 1 ) 120 | i = yastep + 0 121 | 'set line 1 1 1' 122 | while( i < psy ) 123 | if( math_abs( math_int(i/ystep)-(i/ystep)) > 0.001 ) 124 | 'draw line 0 'i' 'psx' 'i 125 | endif 126 | i = i + yastep 127 | endwhile 128 | endif 129 | 130 | return 131 | 132 | 133 | * 134 | * help 135 | * 136 | function help() 137 | say ' Name:' 138 | say ' grid '_version' - display grid' 139 | say '' 140 | say ' Usage:' 141 | say ' grid [xstep [ystep]] [-nl] [-a [xastep [yastep]]]' 142 | say '' 143 | say ' xstep : Interval in x-direction. Default value is 1.0.' 144 | say ' ystep : Interval in y-direction. Default value is xstep.' 145 | say ' -nl : No label.' 146 | say ' -a : Extension line is on.' 147 | say ' xastep : Interval of extension line for x-direction. Default value is xstep/2.' 148 | say ' yastep : Interval of extension line for x-direction. Default value is ystep/2.' 149 | say '' 150 | say ' Note:' 151 | say ' [arg-name] : specify if needed' 152 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 153 | say '' 154 | say ' Copyright (C) 2009-2015 Chihiro Kodama' 155 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 156 | say '' 157 | return 158 | -------------------------------------------------------------------------------- /hatch.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function hatch( args ) 5 | _version='0.04r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | ***** Default value ***** 13 | var = 'none' 14 | vmin = 'none' 15 | vmax = 'none' 16 | density = 0.01 17 | int = 0.1 18 | angle = 45 19 | color = 1 20 | type = 1 21 | thickness = 1 22 | 23 | varmin = 'none' 24 | varmax = 'none' 25 | 26 | ***** Arguement ***** 27 | i = 1 28 | while( 1 ) 29 | arg = subwrd( args, i ) 30 | i = i + 1; 31 | if( arg = '' ); break; endif 32 | 33 | while( 1 ) 34 | *** option 35 | if( arg = '-min' ); vmin = subwrd(args,i); i=i+1; break; endif 36 | if( arg = '-max' ); vmax = subwrd(args,i); i=i+1; break; endif 37 | if( arg = '-density' ); density = subwrd(args,i); i=i+1; break; endif 38 | if( arg = '-int' ); int = subwrd(args,i); i=i+1; break; endif 39 | if( arg = '-angle' ); angle = subwrd(args,i); i=i+1; break; endif 40 | if( arg = '-color' ); color = subwrd(args,i); i=i+1; break; endif 41 | if( arg = '-type' ); type = subwrd(args,i); i=i+1; break; endif 42 | if( arg = '-thickness' ); thickness = subwrd(args,i); i=i+1; break; endif 43 | 44 | *** var, min, max 45 | if( var != 'none' & vmin != 'none' & vmax = 'none' & valnum(arg) != 0 ) 46 | vmax = arg 47 | break 48 | endif 49 | if( var != 'none' & vmin = 'none' & valnum(arg) != 0 ) 50 | vmin = arg 51 | break 52 | endif 53 | if( var = 'none' & valnum(arg) = 0 ) 54 | var = arg 55 | varmin = arg 56 | break 57 | endif 58 | if( varmax = 'none' & valnum(arg) = 0 ) 59 | varmax = arg 60 | break 61 | endif 62 | 63 | say 'syntax error : 'arg 64 | say 'type "hatch" for help' 65 | return 66 | 67 | endwhile 68 | endwhile 69 | 70 | 71 | * draw hatch for each angle 72 | length = math_strlen( angle ) 73 | i = 1 74 | angletmp = '' 75 | while( i <= length ) 76 | c = substr( angle, i, 1 ) 77 | if( c = ',' ) 78 | hatchcore( var, vmin, vmax, density, int, angletmp, color, type, thickness, varmin, varmax ) 79 | angletmp = '' 80 | else 81 | angletmp = angletmp % c 82 | endif 83 | i = i + 1 84 | endwhile 85 | hatchcore( var, vmin, vmax, density, int, angletmp, color, type, thickness, varmin, varmax ) 86 | 87 | return 88 | 89 | 90 | 91 | function hatchcore( var, vmin, vmax, density, int, angle, color, type, thickness, varmin, varmax ) 92 | 93 | 94 | *** adjust angle 95 | * 0 <= angle < 180 96 | * +X axis <-> angle=0 97 | * anti-clockwise 98 | while( angle < 0 ) 99 | angle = angle + 180 100 | endwhile 101 | angle = math_fmod( angle, 180 ) 102 | 103 | if( vmin = 'none' ); vmin = -1e+30; endif 104 | if( vmax = 'none' ); vmax = 1e+30; endif 105 | 106 | 107 | * Note: 108 | * x,y : coordinate on the display (0 <= x,y <= 8.5 or 11) 109 | * wx,wy : coordinate on the map (e.g. lat, lon) 110 | * gx,gy : coordinate on the map (number) 111 | * gxset, gyset : string like 'set x ' 112 | * 113 | 114 | ***** Get range ***** 115 | gxmin = -1 116 | gxmax = -1 117 | gxset = '' 118 | gymin = -1 119 | gymax = -1 120 | gyset = '' 121 | 'q dims' 122 | i = 1 123 | while( i <= 4 ) 124 | temp = sublin( result, i+1 ) 125 | coname = subwrd( temp, 1 ) 126 | flag = subwrd( temp, 3 ) 127 | if( flag = "varying" ) 128 | comin.i = subwrd( temp, 11 ) 129 | comax.i = subwrd( temp, 13 ) 130 | if( gxmin = -1 ) 131 | gxmin = comin.i 132 | gxmax = comax.i 133 | gxset = 'set ' % coname 134 | else 135 | gymin = comin.i 136 | gymax = comax.i 137 | gyset = 'set ' % coname 138 | endif 139 | else 140 | comin.i = subwrd( temp, 9 ) 141 | comax.i = comin.i 142 | endif 143 | 144 | i = i + 1 145 | endwhile 146 | 147 | 'set x 'comin.1' 'comax.1 148 | 'set y 'comin.2' 'comax.2 149 | 'set z 'comin.3' 'comax.3 150 | 'set t 'comin.4' 'comax.4 151 | 152 | 'q gxinfo' 153 | temp = sublin( result, 3 ) 154 | xmin = subwrd( temp, 4 ) 155 | xmax = subwrd( temp, 6 ) 156 | temp = sublin( result, 4 ) 157 | ymin = subwrd( temp, 4 ) 158 | ymax = subwrd( temp, 6 ) 159 | * say xmin % ' ' % xmax % ' ' % ymin % ' ' % ymax 160 | 161 | *** degree -> radian 162 | rangle = angle * 4 * math_atan(1) / 180 163 | 164 | if( 0 <= angle & angle < 45 ) 165 | xint = 0 166 | yint = int / math_cos(rangle) 167 | xstart = xmin 168 | ystart = ymin - (xmax-xmin) * math_tan(rangle) 169 | xend = 0 170 | yend = ymax 171 | xdensity = density * math_cos(rangle) 172 | ydensity = density * math_sin(rangle) 173 | endif 174 | if( 45 <= angle & angle < 90 ) 175 | xint = int / math_sin(rangle) 176 | yint = 0 177 | xstart = xmin - (ymax-ymin) / math_tan(rangle) 178 | ystart = ymin 179 | xend = xmax 180 | xdensity = density * math_cos(rangle) 181 | ydensity = density * math_sin(rangle) 182 | endif 183 | if( 90 <= angle & angle < 135 ) 184 | xint = int / math_sin(rangle) 185 | yint = 0 186 | xstart = xmin 187 | ystart = ymin 188 | xend = xmax - (ymax-ymin) / math_tan(rangle) 189 | yend = 0 190 | xdensity = density * math_cos(rangle) 191 | ydensity = density * math_sin(rangle) 192 | endif 193 | if( 135 <= angle & angle < 180 ) 194 | xint = 0 195 | yint = -int / math_cos(rangle) 196 | xstart = xmin 197 | ystart = ymin 198 | xend = 0 199 | yend = ymax - (xmax-xmin) * math_tan(rangle) 200 | xdensity = -density * math_cos(rangle) 201 | ydensity = -density * math_sin(rangle) 202 | endif 203 | 204 | * say xstart % ' ' % ystart 205 | * say xint % ' ' % yint 206 | * say xdensity % ' ' % ydensity 207 | 208 | line = '' 209 | 210 | while( ( xint > 0 & xstart <= xend ) | ( yint > 0 & ystart <= yend ) ) 211 | 212 | * set start point of the line 213 | x = xstart 214 | y = ystart 215 | if( xint > 0 & x < xmin ) 216 | x = xmin 217 | y = ymin + (xmin-xstart) * math_tan(rangle) 218 | endif 219 | if( yint > 0 & y < ymin ) 220 | x = xmin + (ymin-ystart) / math_tan(rangle) 221 | y = ymin 222 | endif 223 | * say x % ' ' % y 224 | 225 | * loop for line starting from (x,y) as determined above 226 | while( 1 ) 227 | if( xdensity > 0 & x > xmax ); break; endif 228 | if( xdensity < 0 & x < xmin ); break; endif 229 | if( ydensity > 0 & y > ymax ); break; endif 230 | if( ydensity < 0 & y < ymin ); break; endif 231 | 232 | if( x < xmin | x > xmax | y < ymin | y > ymax ) 233 | x = x + xdensity 234 | y = y + ydensity 235 | continue 236 | endif 237 | 238 | 'set x 'comin.1' 'comax.1 239 | 'set y 'comin.2' 'comax.2 240 | 'set z 'comin.3' 'comax.3 241 | 'set t 'comin.4' 'comax.4 242 | 243 | 244 | * get target coordinates (gx,gy), (wx,wy) at (x,y) 245 | 'q xy2gr 'x' 'y 246 | gx = subwrd( result, 3 ) 247 | gy = subwrd( result, 6 ) 248 | 'q xy2w 'x' 'y 249 | wx = subwrd( result, 3 ) 250 | wy = subwrd( result, 6 ) 251 | * say 'xy(' % x % ',' % y % ') : gr(' % gx % ',' % gy % ') : w(' % wx % ',' % wy % ')' 252 | 253 | 254 | * get the surrounding 4 point coordinates 255 | 'q xy2gr 'x' 'y 256 | gx.1 = subwrd( result, 3 ) 257 | gx.1 = math_int(gx.1) 258 | gy.1 = subwrd( result, 6 ) 259 | gy.1 = math_int(gy.1) 260 | 261 | if( gx.1 < gxmin ) 262 | gx.1 = gx.1 + 1 263 | endif 264 | if( gx.1+1 > gxmax ) 265 | gx.1 = gx.1 - 1 266 | endif 267 | if( gy.1 < gymin ) 268 | gy.1 = gy.1 + 1 269 | endif 270 | if( gy.1+1 > gymax ) 271 | gy.1 = gy.1 - 1 272 | endif 273 | 274 | gx.2 = gx.1 + 1 275 | gy.2 = gy.1 276 | 277 | gx.3 = gx.1 278 | gy.3 = gy.1 + 1 279 | 280 | gx.4 = gx.1 + 1 281 | gy.4 = gy.1 + 1 282 | 283 | i = 1 284 | while( i <= 4 ) 285 | 'q gr2w 'gx.i' 'gy.i 286 | wx.i = subwrd( result, 3 ) 287 | wy.i = subwrd( result, 6 ) 288 | 289 | 'q gr2xy 'gx.i' 'gy.i 290 | x.i = subwrd( result, 3 ) 291 | y.i = subwrd( result, 6 ) 292 | 293 | * get the surrounding 4 point values (set ccolor: dummy) 294 | gxset' 'gx.i 295 | 296 | valmin.i = 0 297 | valmax.i = 0 298 | 299 | * 2D 300 | if( gyset != '' ) 301 | gyset' 'gy.i 302 | 'set ccolor 1' 303 | 'd 'var 304 | val.i = subwrd( result, 4 ) 305 | 306 | if( val.i = 'Interpolation' ) 307 | temp = sublin( result, 2 ) 308 | val.i = subwrd( temp, 4 ) 309 | endif 310 | 311 | * 1D 312 | else 313 | 'set ccolor 1' 314 | 'd 'var 315 | val.i = subwrd( result, 4 ) 316 | 317 | if( val.i = 'Interpolation' ) 318 | temp = sublin( result, 2 ) 319 | val.i = subwrd( temp, 4 ) 320 | endif 321 | 322 | if( varmin != 'none' & varmax != 'none' ) 323 | 'set ccolor 1' 324 | 'd 'varmin 325 | valmin.i = subwrd( result, 4 ) 326 | 'set ccolor 1' 327 | 'd 'varmax 328 | valmax.i = subwrd( result, 4 ) 329 | * say val.i % ' ' % valmin.i % ' ' % valmax.i 330 | endif 331 | 332 | endif 333 | 334 | 335 | * get the distance from the target point to the surrounding 4 points 336 | r.i = math_sqrt( (x.i-x)*(x.i-x)+(y.i-y)*(y.i-y) ) 337 | 338 | i = i + 1 339 | endwhile 340 | 341 | * say 'xy(' % x.1 % ',' % y.1 % ') - (' % x.4 % ',' % y.4 % ')' 342 | * say 'gr(' % gx.1 % ',' % gy.1 % ') - (' % gx.4 % ',' % gy.4 % ')' 343 | * say 'w(' % wx.1 % ',' % wy.1 % ') - (' % wx.4 % ',' % wy.4 % ')' 344 | 345 | 346 | *** Interpolation ( 1/r^2 weighted ) 347 | * for sps, nsp (which is the best way...) 348 | * say r.1 % ' ' % r.2 % ' ' % r.3 % ' ' % r.4 349 | r123=math_pow(r.1 * r.2 * r.3, 2) 350 | r124=math_pow(r.1 * r.2 * r.4, 2) 351 | r134=math_pow(r.1 * r.3 * r.4, 2) 352 | r234=math_pow(r.2 * r.3 * r.4, 2) 353 | rsumrev = 1.0 / ( r123 + r124 + r134 + r234 ) 354 | val = ( r123*val.4 + r124*val.3 + r134*val.2 + r234*val.1 ) * rsumrev 355 | * For 1D with linefill 356 | if( varmin != 'none' & varmax != 'none' ) 357 | vmintmp = ( r123*valmin.4 + r124*valmin.3 + r134*valmin.2 + r234*valmin.1 ) * rsumrev 358 | vmaxtmp = ( r123*valmax.4 + r124*valmax.3 + r134*valmax.2 + r234*valmax.1 ) * rsumrev 359 | endif 360 | * say val.1 % ' ' % val.2 % ' ' % val.3 % ' ' % val.4 % ' ' % val 361 | 362 | **** Interpolation ( 3 times linear ) *** 363 | ** 1(x.1,y.1), 2(x.2,y.2=y.1) -> v12(x,y.1) 364 | ** if( x.2-x.1 = 0 ) ; w = 0 365 | * if( math_abs(x.2-x.1) <= 1e-3 ) ; w = 0 366 | * else ; w = (x-x.1) / (x.2-x.1) ; endif 367 | * v12 = w * val.2 + (1-w) * val.1 368 | * vmin12 = w * valmin.2 + (1-w) * valmin.1 369 | * vmax12 = w * valmax.2 + (1-w) * valmax.1 370 | * 371 | ** 3(x.3,y.3), 4(x.4,y.4=y.3) -> v34(x,y.3) 372 | ** if ( x.2-x.1 = 0 ) ; w = 0 373 | * if ( math_abs(x.2-x.1) <= 1e-3 ) ; w = 0 374 | * else ; w = (x-x.1) / (x.2-x.1) ; endif 375 | * v34 = w * val.4 + (1-w) * val.3 376 | * vmin34 = w * valmin.4 + (1-w) * valmin.3 377 | * vmax34 = w * valmax.4 + (1-w) * valmax.3 378 | * 379 | ** v12(x,y.1), v34(x,y.3) -> val(x,y) 380 | ** if ( y.3-y.1 = 0 ) ; w = 0 381 | * if ( math_abs(y.3-y.1) <= 1e-3 ) ; w = 0 382 | * else ; w = (y-y.1) / (y.3-y.1) ; endif 383 | * val = w * v34 + (1-w) * v12 384 | * vmintmp = w * vmin34 + (1-w) * vmin12 385 | * vmaxtmp = w * vmax34 + (1-w) * vmax12 386 | 387 | ***** judge & draw ***** 388 | 389 | *** For 2D and 1D without linefill 390 | if( varmin = 'none' | varmax = 'none' ) 391 | 392 | * find point which should be drawn 393 | if( vmin <= val & val <= vmax & line = '' ) 394 | * if( vmin <= val & val <= vmax & line = '' & wy < 0 ) 395 | line = x % ' ' % y % ' ' 396 | endif 397 | 398 | * accelerator (if needed) 399 | if( vmin <= val & val <= vmax ) 400 | * if( vmin <= val & val <= vmax & wy < 0 ) 401 | if( vmin <= val.1 & val.1 <= vmax & vmin <= val.2 & val.2 <= vmax & vmin <= val.3 & val.3 <= vmax & vmin <= val.4 & val.4 <= vmax ) 402 | while( x > x.1 & y > y.1 & x < x.4 & y < y.4 ) 403 | x = x + xdensity 404 | y = y + ydensity 405 | endwhile 406 | endif 407 | endif 408 | 409 | * draw line 410 | if( ( val < vmin | vmax < val ) & line != '' ) 411 | * if( ( val < vmin | vmax < val | wy > 0 ) & line != '' ) 412 | 413 | line = line % x-xdensity % ' ' % y-ydensity 414 | 'set line 'color' 'type' 'thickness 415 | 'draw line 'line 416 | line='' 417 | endif 418 | 419 | * accelerator (if needed) 420 | if( val < vmin | vmax < val ) 421 | * if( val < vmin | vmax < val | wy > 0 ) 422 | if( ( val.1 < vmin & val.2 < vmin & val.3 < vmin & val.4 < vmin ) | ( vmax < val.1 & vmax < val.2 & vmax < val.3 & vmax < val.4 ) ) 423 | while( x > x.1 & y > y.1 & x < x.4 & y < y.4 ) 424 | x = x + xdensity 425 | y = y + ydensity 426 | endwhile 427 | endif 428 | endif 429 | 430 | * draw line before loop end 431 | if( ( x+xdensity < xmin | x+xdensity > xmax | y+ydensity < ymin | y+ydensity > ymax ) & line != '' ) 432 | line = line % x % ' ' % y 433 | 'set line 'color' 'type' 'thickness 434 | 'draw line 'line 435 | line='' 436 | endif 437 | 438 | *** For 1D linefill 439 | * vmin -> vmintmp 440 | * vmax -> vmaxtmp 441 | * val -> wy 442 | else 443 | 444 | * find point which should be drawn 445 | if( vmintmp <= wy & wy <= vmaxtmp & line = '' ) 446 | line = x % ' ' % y % ' ' 447 | endif 448 | 449 | * accelerator (if needed) 450 | if( vmintmp <= wy & wy <= vmaxtmp ) 451 | if( vmintmp <= wy.1 & wy.1 <= vmaxtmp & vmintmp <= wy.2 & wy.2 <= vmaxtmp & vmintmp <= wy.3 & wy.3 <= vmaxtmp & vmintmp <= wy.4 & wy.4 <= vmaxtmp ) 452 | while( x > x.1 & y > y.1 & x < x.4 & y < y.4 ) 453 | x = x + xdensity 454 | y = y + ydensity 455 | endwhile 456 | endif 457 | endif 458 | 459 | * draw line 460 | if( ( wy < vmintmp | vmaxtmp < wy ) & line != '' ) 461 | line = line % x-xdensity % ' ' % y-ydensity 462 | 'set line 'color' 'type' 'thickness 463 | 'draw line 'line 464 | line='' 465 | endif 466 | 467 | * accelerator (if needed) 468 | if( wy < vmintmp | vmaxtmp < wy ) 469 | if( ( wy.1 < vmintmp & wy.2 < vmintmp & wy.3 < vmintmp & wy.4 < vmintmp ) | ( vmaxtmp < wy.1 & vmaxtmp < wy.2 & vmaxtmp < wy.3 & vmaxtmp < wy.4 ) ) 470 | while( x > x.1 & y > y.1 & x < x.4 & y < y.4 ) 471 | x = x + xdensity 472 | y = y + ydensity 473 | endwhile 474 | endif 475 | endif 476 | 477 | * draw line before loop end 478 | if( ( x+xdensity < xmin | x+xdensity > xmax | y+ydensity < ymin | y+ydensity > ymax ) & line != '' ) 479 | line = line % x % ' ' % y 480 | 'set line 'color' 'type' 'thickness 481 | 'draw line 'line 482 | line='' 483 | endif 484 | 485 | endif 486 | 487 | 488 | x = x + xdensity 489 | y = y + ydensity 490 | endwhile 491 | 492 | xstart = xstart + xint 493 | ystart = ystart + yint 494 | endwhile 495 | 496 | 'set x 'comin.1' 'comax.1 497 | 'set y 'comin.2' 'comax.2 498 | 'set z 'comin.3' 'comax.3 499 | 'set t 'comin.4' 'comax.4 500 | 501 | return 502 | 503 | 504 | * 505 | * help 506 | * 507 | function help() 508 | say ' Name:' 509 | say ' hatch '_version' - draw hatch ' 510 | say ' ' 511 | say ' Usage:' 512 | say ' hatch ( var ( min max | -min min | -max max ) | varmin varmax ) ' 513 | say ' [-angle angle] [-density density] [-int int]' 514 | say ' [-color color] [-type type] [-thickness thickness]' 515 | say ' ' 516 | say ' var : variable' 517 | say ' varmin,varmax : variable range (only for 1D chart)' 518 | say ' min,max : value range to be drawn (default: [-1e+30:1e+30])' 519 | say ' varmin,varmax : range of variable to be drawn (only for 1D chart)' 520 | say ' angle : angle of the hatch (default: 45). ' 521 | say ' hatch is parallel to +X axis when angle=0.' 522 | say ' anti-clockwise.' 523 | say ' you can specify two or more angles by' 524 | say ' comma-separated values, e.g., -angle 45,90.' 525 | say ' density : density (or accuracy) of the hatch (default: 0.01)' 526 | say ' int : hatch interval (default: 0.1)' 527 | say ' color : hatch color (default: 1)' 528 | say ' type : hatch line type (default: 1)' 529 | say ' thickness : hatch line thickness (default: 1)' 530 | say '' 531 | say ' Note:' 532 | say ' [arg-name] : specify if needed' 533 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 534 | say '' 535 | say ' Method of drawing hatch is not equivalent to that in grads' 536 | say ' so please check whether hatch is correctly drawn' 537 | say '' 538 | say ' Copyright (C) 2008-2012 Chihiro Kodama' 539 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 540 | say '' 541 | return 542 | -------------------------------------------------------------------------------- /itoa.gsf: -------------------------------------------------------------------------------- 1 | ***** integer -> char ***** 2 | function itoa( int ) 3 | * ascii character table 4 | table = ' !"#$%&' 5 | table = table % "'" 6 | table = table % '()*+,-./0123456789:;<=>?@' 7 | table = table % 'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`' 8 | table = table % 'abcdefghijklmnopqrstuvwxyz{|}~' 9 | 10 | if( int >= 32 & int <= 126 ) 11 | return substr( table, int-31, 1 ) 12 | endif 13 | return -1 14 | -------------------------------------------------------------------------------- /last.gsf: -------------------------------------------------------------------------------- 1 | function last() 2 | 'q files' 3 | i = 1 4 | fmax = 0 5 | while( 1 ) 6 | line = sublin( result, i ) 7 | if( line = '' ) ; break ; endif 8 | num = subwrd( line, 2 ) 9 | if( num = fmax + 1 ) ; fmax = fmax + 1 ; endif 10 | i = i + 1 11 | endwhile 12 | return fmax 13 | -------------------------------------------------------------------------------- /lat2y.gsf: -------------------------------------------------------------------------------- 1 | function lat2y( lat ) 2 | 'q dims' 3 | line = sublin( result, 3 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | y1 = subwrd( line, 11 ) 7 | y2 = subwrd( line, 13 ) 8 | else 9 | y1 = subwrd( line, 9 ) 10 | y2 = subwrd( line, 9 ) 11 | endif 12 | 'set lat 'lat 13 | 'q dims' 14 | line = sublin( result, 3 ) 15 | y = subwrd( line, 9 ) 16 | 'set y 'y1' 'y2 17 | return y 18 | -------------------------------------------------------------------------------- /lev2z.gsf: -------------------------------------------------------------------------------- 1 | function lev2z( lev ) 2 | 'q dims' 3 | line = sublin( result, 4 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | z1 = subwrd( line, 11 ) 7 | z2 = subwrd( line, 13 ) 8 | else 9 | z1 = subwrd( line, 9 ) 10 | z2 = subwrd( line, 9 ) 11 | endif 12 | 'set lev 'lev 13 | 'q dims' 14 | line = sublin( result, 4 ) 15 | z = subwrd( line, 9 ) 16 | 'set z 'z1' 'z2 17 | return z 18 | -------------------------------------------------------------------------------- /libbase.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * basic library for grads script 3 | * 4 | * libbase( 'args...' ) 5 | * 6 | function libbase( args ) 7 | 8 | ********** BELOW PLEASE SET PATH FOR TEMPORARY BUFFER ************ 9 | * for act = 'pwd' 10 | * 11 | _buff_path = '/var/tmp' 12 | * _buff_path = '.' 13 | ********** ABOVE PLEASE SET PATH FOR TEMPORARY BUFFER ************ 14 | 15 | act = subwrd( args, 1 ) 16 | act_length = math_strlen( act ) 17 | args_length = math_strlen( args ) 18 | 19 | p = act_length + 1 20 | while( p <= args_length ) 21 | str = substr( args, p, 1 ) 22 | if( str != ' ' ) ; break ; endif 23 | p = p + 1 24 | endwhile 25 | 26 | if( p <= args_length ) 27 | next_args = substr( args, p, args_length-p+1 ) 28 | else 29 | next_args = '' 30 | endif 31 | 32 | if( act = 'pwd' ) 33 | ret = libbase_pwd( next_args ) 34 | return ret 35 | endif 36 | 37 | 38 | say 'error: act = ' % act % ' is not supported' 39 | return 40 | 41 | * 42 | * libbase_pwd() : obtain current path 43 | * 44 | function libbase_pwd( args ) 45 | buff = _buff_path % '/grads_libbase_pwd.txt' 46 | 47 | i = 1 48 | imax = 10 49 | while( i <= imax ) 50 | temp = read( buff ) 51 | status = sublin( temp, 1 ) 52 | if( status = 1 ) ; break ; endif 53 | temp = close( buff ) 54 | if( status != 1 & i = imax ) 55 | say 'error: temporary file = ' % buff % ' already exists' 56 | return '' 57 | endif 58 | '!sleep 1s' 59 | i = i + 1 60 | endwhile 61 | 62 | '!pwd > 'buff 63 | temp = read( buff ) 64 | ret = sublin( temp, 2 ) 65 | '!rm -f 'buff 66 | return ret 67 | -------------------------------------------------------------------------------- /line.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function line(args) 5 | _version='0.01r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | ***** Default value ***** 13 | p1 = 'none' 14 | q1 = 'none' 15 | p2 = 'none' 16 | q2 = 'none' 17 | by = 'world' 18 | 19 | ***** Arguement ***** 20 | i = 1 21 | while( 1 ) 22 | arg = subwrd( args, i ) 23 | i = i + 1; 24 | if( arg = '' ); break; endif 25 | 26 | while( 1 ) 27 | *** option 28 | if( arg = '-by' ); by = subwrd(args,i); i = i + 1; break; endif 29 | 30 | *** x1, y1, x2, y2 31 | if( p1 = 'none' ); p1 = arg; break; endif 32 | if( q1 = 'none' ); q1 = arg; break; endif 33 | if( p2 = 'none' ); p2 = arg; break; endif 34 | if( q2 = 'none' ); q2 = arg; break; endif 35 | 36 | say 'syntax error : 'arg 37 | return 38 | endwhile 39 | 40 | endwhile 41 | 42 | if( p1 = 'none' | q1 = 'none' | p2 = 'none' | q2 = 'none' ) 43 | say 'syntax error : too few arguement' 44 | return 45 | endif 46 | if( by != 'world' & by != 'grid' & by != 'xy' ) 47 | say 'syntax error : "-by 'by'" is invalid' 48 | endif 49 | 50 | if( by = 'world' ) 51 | 'q w2xy 'p1' 'q1 52 | x1 = subwrd( result, 3 ) 53 | y1 = subwrd( result, 6 ) 54 | 'q w2xy 'p2' 'q2 55 | x2 = subwrd( result, 3 ) 56 | y2 = subwrd( result, 6 ) 57 | endif 58 | 59 | if( by = 'grid' ) 60 | 'q gr2xy 'p1' 'q1 61 | x1 = subwrd( result, 3 ) 62 | y1 = subwrd( result, 6 ) 63 | 'q gr2xy 'p2' 'q2 64 | x2 = subwrd( result, 3 ) 65 | y2 = subwrd( result, 6 ) 66 | endif 67 | 68 | if( by = 'xy' ) 69 | x1 = p1 70 | y1 = q1 71 | x2 = p2 72 | y2 = q2 73 | endif 74 | 75 | 'draw line 'x1' 'y1' 'x2' 'y2 76 | 77 | return 78 | 79 | 80 | * 81 | * help 82 | * 83 | function help() 84 | say ' Name:' 85 | say ' line '_version' - draw line in various coordinates' 86 | say ' ' 87 | say ' Usage:' 88 | say ' line [-by ( world | grid | xy ) ] p1 q1 p2 q2' 89 | say '' 90 | say ' -by : unit of p1, q1, p2, q2' 91 | say ' world : world coordinate (e.g. lat)' 92 | say ' grid : grid coordinate (grid number)' 93 | say ' xy : same as "draw line"' 94 | say '' 95 | say ' Note:' 96 | say ' [arg-name] : specify if needed' 97 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 98 | say '' 99 | say ' Copyright (C) 2010 Chihiro Kodama' 100 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 101 | say '' 102 | return 103 | -------------------------------------------------------------------------------- /loglabel.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function loglabel( args ) 5 | _version='0.04r3' 6 | 7 | if( args = '-help' ) 8 | help() 9 | return 10 | endif 11 | 12 | 'q dims' 13 | res = sublin(result,4) 14 | levmin = subwrd(res,6) 15 | levmax = subwrd(res,8) 16 | 17 | fix = subwrd(res,3) 18 | if( fix = 'fixed' ) 19 | return 20 | endif 21 | 22 | lnlevmin = math_log10(levmin) 23 | lnlevmax = math_log10(levmax) 24 | diff = lnlevmin-lnlevmax 25 | 26 | ***** set parameters ***** 27 | * rule: (diff * n) should be close to 10 28 | 29 | * ex. 1000hPa - 100hPa 30 | if( diff >= 0.5 & diff < 1.5 ) 31 | base.1 = 8.5 32 | base.2 = 7.0 33 | base.3 = 6.0 34 | base.4 = 5.0 35 | base.5 = 4.0 36 | base.6 = 3.0 37 | base.7 = 2.5 38 | base.8 = 2.0 39 | base.9 = 1.5 40 | base.10= 1.0 41 | n = 10 42 | * loop = 2 43 | endif 44 | 45 | * ex. 100hPa - 1hPa 46 | if( diff >= 1.5 & diff < 2.5 ) 47 | base.1 = 7.0 48 | base.2 = 5.0 49 | base.3 = 3.0 50 | base.4 = 2.0 51 | base.5 = 1.0 52 | n = 5 53 | * loop = 3 54 | endif 55 | 56 | * ex. 1000hPa - 1hPa 57 | if( diff >= 2.5 & diff < 3.5 ) 58 | base.1 = 5.0 59 | base.2 = 3.0 60 | base.3 = 2.0 61 | base.4 = 1.0 62 | n = 4 63 | * loop = 4 64 | endif 65 | 66 | ** ex. 1000hPa - 0.1hPa 67 | * if( diff >= 3.5 & diff < 4.5 ) 68 | * base.1 = 5.0 69 | * base.2 = 2.0 70 | * base.3 = 1.0 71 | * n = 3 72 | ** loop = 5 73 | * endif 74 | * 75 | ** ex. 1000hPa - 0.01hPa 76 | * if( diff >= 4.5 & diff < 5.5 ) 77 | * base.1 = 5.0 78 | * base.2 = 2.0 79 | * base.3 = 1.0 80 | * n = 3 81 | ** loop = 6 82 | * endif 83 | 84 | * ex. 1000hPa - 0.1hPa 85 | if( diff >= 3.5 & diff < 4.5 ) 86 | base.1 = 5.0 87 | base.2 = 2.0 88 | base.3 = 1.0 89 | n = 3 90 | endif 91 | 92 | * ex. 1000hPa - 0.01hPa, 1000hPa - 0.001hPa, 1000hPa - 0.0001hPa, 93 | if( diff >= 4.5 & diff < 7.5 ) 94 | base.1 = 3.0 95 | base.2 = 1.0 96 | n = 2 97 | endif 98 | 99 | * ex. 1000hPa - 0.01hPa, 1000hPa - 0.001hPa, 1000hPa - 0.0001hPa, 100 | if( diff >= 7.5 ) 101 | base.1 = 1.0 102 | n = 1 103 | endif 104 | 105 | * if( diff < 0.5 | diff >= 5.5 ) 106 | * if( diff < 0.5 | diff >= 6.5 ) 107 | * say 'loglabel : out of range' 108 | * return 109 | * endif 110 | 111 | ***** set ylevs ***** 112 | loop = math_int( diff + 1.5 ) 113 | fact = math_pow(10,math_int(math_log10(levmin))) 114 | string = base.n * fact * 10 % ' ' 115 | j = 1 116 | while( j <= loop ) 117 | div = math_pow(10,j-1) 118 | 119 | i = 1 120 | while ( i <= n ) 121 | string = string % fact*base.i/div % ' ' 122 | i = i + 1 123 | endwhile 124 | 125 | j = j + 1 126 | endwhile 127 | 128 | 'set ylevs 'string 129 | *say 'ylevs (loglabels) = ' % string 130 | 131 | return 132 | 133 | * 134 | * help 135 | * 136 | function help() 137 | say ' Name:' 138 | say ' loglabel '_version' - set log-p label' 139 | say ' ' 140 | say ' Usage:' 141 | say ' loglabel [-help]' 142 | say '' 143 | say ' Note:' 144 | say ' [arg-name] : specify if needed' 145 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 146 | say '' 147 | say ' "set imprun loglabel" is useful' 148 | say ' set level before running loglabel' 149 | say '' 150 | say ' Copyright (C) 2004-2011 Chihiro Kodama' 151 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 152 | say '' 153 | return 154 | -------------------------------------------------------------------------------- /lon2x.gsf: -------------------------------------------------------------------------------- 1 | function lon2x( lon ) 2 | 'q dims' 3 | line = sublin( result, 2 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | x1 = subwrd( line, 11 ) 7 | x2 = subwrd( line, 13 ) 8 | else 9 | x1 = subwrd( line, 9 ) 10 | x2 = subwrd( line, 9 ) 11 | endif 12 | 'set lon 'lon 13 | 'q dims' 14 | line = sublin( result, 2 ) 15 | x = subwrd( line, 9 ) 16 | 'set x 'x1' 'x2 17 | return x 18 | -------------------------------------------------------------------------------- /lreg.gs: -------------------------------------------------------------------------------- 1 | function lreg( args ) 2 | _version = '0.01b1' 3 | rc = gsfallow("on") 4 | 5 | if( args = '' ) 6 | help() 7 | return 8 | endif 9 | 10 | ***** Arguement ***** 11 | 'vx = 'subwrd( args, 1 ) 12 | 'vy = 'subwrd( args, 2 ) 13 | 14 | * optional 15 | slope_in = subwrd( args, 3 ) 16 | icept_in = subwrd( args, 4 ) 17 | cor_in = subwrd( args, 5 ) 18 | 19 | xmin = qdims( xmin ) ; xmax = qdims( xmax ) 20 | ymin = qdims( ymin ) ; ymax = qdims( ymax ) 21 | zmin = qdims( zmin ) ; zmax = qdims( zmax ) 22 | tmin = qdims( tmin ) ; tmax = qdims( tmax ) 23 | emin = qdims( emin ) ; emax = qdims( emax ) 24 | 25 | str_head = '' 26 | str_tail = '' 27 | 28 | if( xmin != xmax ) 29 | str_head = 'ave(' % str_head 30 | str_tail = str_tail % ',x='xmin',x='xmax')' 31 | endif 32 | if( ymin != ymax ) 33 | str_head = 'ave(' % str_head 34 | str_tail = str_tail % ',y='ymin',y='ymax')' 35 | endif 36 | if( zmin != zmax ) 37 | str_head = 'ave(' % str_head 38 | str_tail = str_tail % ',z='zmin',z='zmax')' 39 | endif 40 | if( tmin != tmax ) 41 | str_head = 'ave(' % str_head 42 | str_tail = str_tail % ',t='tmin',t='tmax')' 43 | endif 44 | if( emin != emax ) 45 | str_head = 'ave(' % str_head 46 | str_tail = str_tail % ',e='emin',e='emax')' 47 | endif 48 | 49 | 'set x 1' 50 | 'set y 1' 51 | 'set z 1' 52 | 'set t 1' 53 | 'set e 1' 54 | 55 | * avx, avy: ave(vx), ave(vy) 56 | 'tmp = ' % str_head % 'vx' % str_tail 57 | 'd tmp' 58 | avx = subwrd( result, 4 ) 59 | say 'avx = ' % str_head % 'vx' % str_tail % ' = ' % avx 60 | 61 | 'tmp = ' % str_head % 'vy' % str_tail 62 | 'd tmp' 63 | avy = subwrd( result, 4 ) 64 | say 'avy = ' % str_head % 'vy' % str_tail % ' = ' % avy 65 | 66 | * avxy: ave(vx*vy) 67 | 'tmp = ' % str_head % 'vx*vy' % str_tail 68 | 'd tmp' 69 | avxy = subwrd( result, 4 ) 70 | say 'avxy = ' % str_head % 'vx*vy' % str_tail % ' = ' % avxy 71 | 72 | * avxx: ave(vx*vx) 73 | 'tmp = ' % str_head % 'vx*vx' % str_tail 74 | 'd tmp' 75 | avxx = subwrd( result, 4 ) 76 | say 'avxx = ' % str_head % 'vx*vx' % str_tail % ' = ' % avxx 77 | 78 | * sgx, sgy: sigma(vx), sigma(vy) 79 | 'tmp = sqrt(' % str_head % '(vx-'avx')*(vx-'avx')' % str_tail % ')' 80 | 'd tmp' 81 | sgx = subwrd( result, 4 ) 82 | say 'sgx = sqrt(' % str_head % '(vx-avx)*(vx-avx)' % str_tail % ' = ' % sgx 83 | 84 | 'tmp = sqrt(' % str_head % '(vy-'avy')*(vy-'avy')' % str_tail % ')' 85 | 'd tmp' 86 | sgy = subwrd( result, 4 ) 87 | say 'sgy = sqrt(' % str_head % '(vy-avy)*(vy-avy)' % str_tail % ' = ' % sgy 88 | 89 | 90 | * linear regression coefficient 91 | slope = ( avxy - avx * avy ) / ( avxx - avx * avx ) 92 | icept = avy - slope * avx 93 | say 'y = ' % slope % ' x + ' % icept 94 | 95 | * correlation coefficient 96 | 'tmp = ' % str_head % '(vx-'avx')*(vy-'avy')' % str_tail % ' / ('sgx'*'sgy')' 97 | 'd tmp' 98 | cor = subwrd( result, 4 ) 99 | say 'correlation: ' % cor 100 | 101 | if( slope_in != '' ) 102 | slope_in' = 'slope 103 | endif 104 | if( icept_in != '' ) 105 | icept_in' = 'icept 106 | endif 107 | if( cor_in != '' ) 108 | cor_in' = 'cor 109 | endif 110 | 111 | ret = slope % ' ' % icept % ' ' % cor 112 | 113 | 'set x 'xmin' 'xmax 114 | 'set y 'ymin' 'ymax 115 | 'set z 'zmin' 'zmax 116 | 'set t 'tmin' 'tmax 117 | 'set e 'emin' 'emax 118 | return ret 119 | 120 | 121 | 122 | * 123 | * help 124 | * 125 | function help() 126 | say ' Name:' 127 | say ' lreg '_version' - linear regression and correlation for any varying dimensions' 128 | say ' ' 129 | say ' Usage:' 130 | say ' lreg vx vy [slope [icept [cor]]]' 131 | say '' 132 | say ' vx,vy : input field variables' 133 | say ' slope : output field variable name for slope parameter' 134 | say ' icept : output field variable name for intercept parameter' 135 | say ' cor : output field variable name for correlation coefficient' 136 | say ' Output as "result"' 137 | say '1. slope parameter in linear regression' 138 | say '2. intercept parameter in linear regression' 139 | say '3. correlation coefficient' 140 | say '' 141 | say ' Note:' 142 | say ' This script is under construction and its syntax will perhaps be changed in near future.' 143 | say ' lon/lat is weighted...' 144 | say '' 145 | say ' [arg-name] : specify if needed' 146 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 147 | say '' 148 | say ' Copyright (C) 2012-2012 Chihiro Kodama' 149 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 150 | say '' 151 | return 152 | -------------------------------------------------------------------------------- /max.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function max( args ) 5 | _version='0.01r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | org = subwrd( args, 1 ) 13 | cmp = subwrd( args, 2 ) 14 | new = subwrd( args, 3 ) 15 | if( new = '' ) ; new = org ; endif 16 | 17 | 'tempmax1 = maskout( 'org', 'org'-'cmp' )' 18 | 'tempmax2 = maskout( 'cmp', const(const(tempmax1,-1),1,-u) )' 19 | 20 | new' = const( tempmax1, 0, -u ) + const( tempmax2, 0, -u )' 21 | 22 | return 23 | 24 | 25 | 26 | * 27 | * help 28 | * 29 | function help() 30 | say ' Name:' 31 | say ' max '_version' - get maximum value from two field variables' 32 | say ' ' 33 | say ' Usage:' 34 | say ' max org cmp [new]' 35 | say '' 36 | say ' org : 1st variable name' 37 | say ' without specifying [new], it will be overridden.' 38 | say ' cmp : 2nd variable name' 39 | say ' new : result variable name. Without specified it, new=org.' 40 | say '' 41 | say ' Note:' 42 | say ' [arg-name] : specify if needed' 43 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 44 | say '' 45 | say ' Copyright (C) 2009 Chihiro Kodama' 46 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 47 | say '' 48 | return 49 | -------------------------------------------------------------------------------- /min.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function min( args ) 5 | _version='0.01r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | org = subwrd( args, 1 ) 13 | cmp = subwrd( args, 2 ) 14 | new = subwrd( args, 3 ) 15 | if( new = '' ) ; new = org ; endif 16 | 17 | 'tempmin1 = maskout( 'org', 'cmp'-'org' )' 18 | 'tempmin2 = maskout( 'cmp', const(const(tempmin1,-1),1,-u) )' 19 | 20 | new' = const( tempmin1, 0, -u ) + const( tempmin2, 0, -u )' 21 | 22 | return 23 | 24 | 25 | 26 | * 27 | * help 28 | * 29 | function help() 30 | say ' Name:' 31 | say ' min '_version' - get minimum value from two field variables' 32 | say ' ' 33 | say ' Usage:' 34 | say ' min org cmp [new]' 35 | say '' 36 | say ' org : 1st variable name' 37 | say ' without specifying [new], it will be overridden.' 38 | say ' cmp : 2nd variable name' 39 | say ' new : result variable name. Without specified it, new=org.' 40 | say '' 41 | say ' Note:' 42 | say ' [arg-name] : specify if needed' 43 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 44 | say '' 45 | say ' Copyright (C) 2009 Chihiro Kodama' 46 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 47 | say '' 48 | return 49 | -------------------------------------------------------------------------------- /mul.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function mul( args ) 5 | _version='0.06r2' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | imax = 'none' 15 | jmax = 'none' 16 | ipos = 'none' 17 | jpos = 'none' 18 | npos = 'none' 19 | xoffset = 0 20 | yoffset = 0 21 | novpage = 0 22 | xini = 'none' 23 | xwid = 'none' 24 | xint = 'none' 25 | yini = 'none' 26 | ywid = 'none' 27 | yint = 'none' 28 | grads = 'on' 29 | 30 | *** arguement *** 31 | * imax = subwrd( args, 1 ) 32 | * jmax = subwrd( args, 2 ) 33 | * ipos = subwrd( args, 3 ) 34 | * jpos = subwrd( args, 4 ) 35 | 36 | i = 1 37 | * i = 5 38 | arg = "dummy" 39 | while( 1 ) 40 | arg = subwrd( args, i ) 41 | i = i + 1 42 | if( arg = '' ); break; endif 43 | 44 | while( 1 ) 45 | if( arg = '-xoffset' ) ; xoffset=subwrd(args,i) ; i=i+1 ; break ; endif 46 | if( arg = '-yoffset' ) ; yoffset=subwrd(args,i) ; i=i+1 ; break ; endif 47 | if( arg = '-xini' ) ; xini =subwrd(args,i) ; i=i+1 ; break ; endif 48 | if( arg = '-xwid' ) ; xwid =subwrd(args,i) ; i=i+1 ; break ; endif 49 | if( arg = '-xint' ) ; xint =subwrd(args,i) ; i=i+1 ; break ; endif 50 | if( arg = '-yini' ) ; yini =subwrd(args,i) ; i=i+1 ; break ; endif 51 | if( arg = '-ywid' ) ; ywid =subwrd(args,i) ; i=i+1 ; break ; endif 52 | if( arg = '-yint' ) ; yint =subwrd(args,i) ; i=i+1 ; break ; endif 53 | if( arg = '-n' ) ; npos =subwrd(args,i) ; i=i+1 ; break ; endif 54 | if( arg = '-grads' ) ; grads =subwrd(args,i) ; i=i+1 ; break ; endif 55 | 56 | * values 57 | if( valnum(arg) != 0 & imax = 'none' ) ; imax=arg ; break ; endif 58 | if( valnum(arg) != 0 & jmax = 'none' ) ; jmax=arg ; break ; endif 59 | if( valnum(arg) != 0 & ipos = 'none' ) ; ipos=arg ; break ; endif 60 | if( valnum(arg) != 0 & jpos = 'none' ) ; jpos=arg ; break ; endif 61 | 62 | say 'syntax error: 'arg 63 | return 64 | endwhile 65 | endwhile 66 | 67 | if( valnum(npos) != 0 & ipos = 'none' & jpos = 'none' ) 68 | ipos = math_mod( npos - 1, imax ) + 1 69 | jpos = jmax - math_int( ( npos - 1 ) / imax ) 70 | endif 71 | 72 | 73 | ***** get real page ***** 74 | 'q gxinfo' 75 | temp = sublin( result, 2 ) 76 | vpagex = subwrd( temp, 4 ) 77 | vpagey = subwrd( temp, 6 ) 78 | 79 | 80 | ***** set default value (landscape) ***** 81 | 82 | ***** imax ***** 83 | *** 1 *** 84 | xini.1 = 1.0 85 | xwid.1 = 9.5 86 | xint.1 = 0.0 87 | 88 | *** 2 *** 89 | xini.2 = 1.0 90 | xwid.2 = 4.5 91 | xint.2 = 0.5 92 | 93 | *** 3 *** 94 | xini.3 = 1.0 95 | xwid.3 = 3.0 96 | xint.3 = 0.4 97 | 98 | *** 4 *** 99 | xini.4 = 0.4 100 | xwid.4 = 2.3 101 | xint.4 = 0.4 102 | 103 | *** 5 *** 104 | xini.5 = 0.9 105 | xwid.5 = 1.9 106 | xint.5 = 0.1 107 | 108 | 109 | ***** jmax ***** 110 | *** 1 *** 111 | yini.1 = 1.0 112 | ywid.1 = 7.0 113 | yint.1 = 0.0 114 | 115 | *** 2 *** 116 | yini.2 = 1.0 117 | ywid.2 = 3.0 118 | yint.2 = 1.0 119 | 120 | *** 3 *** 121 | yini.3 = 0.8 122 | ywid.3 = 2.0 123 | yint.3 = 0.5 124 | 125 | *** 4 *** 126 | yini.4 = 0.6 127 | ywid.4 = 1.5 128 | yint.4 = 0.4 129 | 130 | *** 5 *** 131 | yini.5 = 0.6 132 | ywid.5 = 1.4 133 | yint.5 = 0.1 134 | 135 | 136 | 137 | ***** set default value (portrait) ***** 138 | if( vpagex = 8.5 & vpagey = 11 ) 139 | k = 1 140 | while( k <= 5 ) 141 | ini = xini.k 142 | wid = xwid.k 143 | int = xint.k 144 | xini.k = yini.k 145 | xwid.k = ywid.k 146 | xint.k = yint.k 147 | yini.k = ini 148 | ywid.k = wid 149 | wint.k = int 150 | k = k + 1 151 | endwhile 152 | 153 | endif 154 | 155 | 156 | ***** set xini, xwid, etc ***** 157 | if( xini = "none" ) ; xini = xini.imax ; endif 158 | if( xwid = "none" ) ; xwid = xwid.imax ; endif 159 | if( xint = "none" ) ; xint = xint.imax ; endif 160 | 161 | if( yini = "none" ) ; yini = yini.jmax ; endif 162 | if( ywid = "none" ) ; ywid = ywid.jmax ; endif 163 | if( yint = "none" ) ; yint = yint.jmax ; endif 164 | 165 | 166 | ***** set parea ***** 167 | xmin = xini + (xwid + xint) * (ipos-1) + xoffset 168 | xmax = xini + (xwid + xint) * (ipos-1) + xwid + xoffset 169 | ymin = yini + (ywid + yint) * (jpos-1) + yoffset 170 | ymax = yini + (ywid + yint) * (jpos-1) + ywid + yoffset 171 | 172 | say 'set parea (by mul) -> xmin='xmin' xmax='xmax' ymin='ymin' ymax='ymax 173 | if( novpage = 0 ) 174 | 'set vpage 0 'vpagex' 0 'vpagey 175 | endif 176 | 'set parea 'xmin' 'xmax' 'ymin' 'ymax 177 | if( grads = 'off' ) 178 | 'set grads off' 179 | endif 180 | 181 | return 182 | 183 | 184 | * 185 | * help 186 | * 187 | function help() 188 | say ' Name:' 189 | say ' mul '_version' - set multi-window' 190 | say ' ' 191 | say ' Usage:' 192 | say ' mul imax jmax ( ipos jpos | -n npos )' 193 | say ' [-xoffset value/0] [-yoffset value/0] [-novpage]' 194 | say ' [-xini value] [-xwid value] [-xint value]' 195 | say ' [-yini value] [-ywid value] [-yint value]' 196 | say ' [-grads on|off]' 197 | say '' 198 | say ' imax : number of window horizontally ( 1<= imax <= 5 )' 199 | say ' jmax : number of window vertically ( 1<= jmax <= 5 )' 200 | say ' ipos : horizontal position (count from left window)' 201 | say ' jpos : vertical position (count from bottom window)' 202 | say ' npos : position (count from top-left window)' 203 | say ' xoffset : offset of horizontal position' 204 | say ' yoffset : offset of vertical position' 205 | say ' novpage : avoid "set vpage"' 206 | say ' xini,yini : lower-left position when "mul ? ? 1 1"' 207 | say ' xwid,ywid : width of figure' 208 | say ' xint,yint : interval of figures' 209 | say ' -grads : "set grads" after setting display' 210 | say '' 211 | say ' Note:' 212 | say ' [arg-name] : specify if needed' 213 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 214 | say '' 215 | say ' Copyright (C) 2009-2022 Chihiro Kodama' 216 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 217 | say '' 218 | return 219 | -------------------------------------------------------------------------------- /mul2.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function mul2( args ) 5 | _version = '0.01b1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | *** arguement *** 13 | imax = subwrd( args, 1 ) 14 | jmax = subwrd( args, 2 ) 15 | ipos = subwrd( args, 3 ) 16 | jpos = subwrd( args, 4 ) 17 | 18 | ***** get real page ***** 19 | 'set vpage off' 20 | if( imax = 1 & jmax = 1 ) ; return ; endif 21 | 'q gxinfo' 22 | temp = sublin( result, 2 ) 23 | vpagex = subwrd( temp, 4 ) 24 | vpagey = subwrd( temp, 6 ) 25 | 26 | xmin = ( vpagex / imax ) * ( ipos - 1 ) 27 | xmax = ( vpagex / imax ) * ( ipos ) 28 | ymin = ( vpagey / jmax ) * ( jpos - 1 ) 29 | ymax = ( vpagey / jmax ) * ( jpos ) 30 | 'set vpage 'xmin' 'xmax' 'ymin' 'ymax 31 | 32 | 'set grads off' 33 | return 34 | 35 | 36 | * 37 | * help 38 | * 39 | function help() 40 | say ' Name:' 41 | say ' mul2 '_version' - set multi-virtual window' 42 | say ' ' 43 | say ' Usage:' 44 | say ' mul2 imax jmax ipos jpos' 45 | say '' 46 | say ' imax : Number of horizontal windows.' 47 | say ' jmax : Number of vertical windows' 48 | say ' ipos : Horizontal position (count from left window)' 49 | say ' jpos : Vertical position (count from bottom window)' 50 | say '' 51 | say ' Note:' 52 | say ' [arg-name] : specify if needed' 53 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 54 | say '' 55 | say ' Copyright (C) 2015-2015 Chihiro Kodama' 56 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 57 | say '' 58 | return 59 | -------------------------------------------------------------------------------- /mulval.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function mulval(args) 5 | _version='0.01r2' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | *** arguement *** 13 | imax = subwrd(args,1) 14 | jmax = subwrd(args,2) 15 | ipos = subwrd(args,3) 16 | jpos = subwrd(args,4) 17 | var = subwrd(args,5) 18 | 19 | xoffset = 0 20 | yoffset = 0 21 | 22 | i = 6 23 | arg = "dummy" 24 | while( arg != "" ) 25 | arg = subwrd( args, i ) 26 | i = i + 1 27 | 28 | if( arg = "-xoffset" ) 29 | xoffset = subwrd( args, i ) 30 | i = i + 1 31 | endif 32 | 33 | if( arg = "-yoffset" ) 34 | yoffset = subwrd( args, i ) 35 | i = i + 1 36 | endif 37 | 38 | endwhile 39 | 40 | 41 | ***** set value ***** 42 | 43 | ***** imax ***** 44 | *** 1 *** 45 | xini.1 = 1.0 46 | xwid.1 = 9.5 47 | xint.1 = 0.0 48 | 49 | *** 2 *** 50 | xini.2 = 1.0 51 | xwid.2 = 4.5 52 | xint.2 = 0.5 53 | 54 | *** 3 *** 55 | xini.3 = 1.0 56 | xwid.3 = 3.0 57 | xint.3 = 0.4 58 | 59 | *** 4 *** 60 | xini.4 = 0.4 61 | xwid.4 = 2.3 62 | xint.4 = 0.4 63 | 64 | *** 5 *** 65 | xini.5 = 0.9 66 | xwid.5 = 1.9 67 | xint.5 = 0.1 68 | 69 | 70 | ***** jmax ***** 71 | *** 1 *** 72 | yini.1 = 1.0 73 | ywid.1 = 7.0 74 | yint.1 = 0.0 75 | 76 | *** 2 *** 77 | yini.2 = 1.0 78 | ywid.2 = 3.0 79 | yint.2 = 1.0 80 | 81 | *** 3 *** 82 | yini.3 = 0.8 83 | ywid.3 = 2.0 84 | yint.3 = 0.5 85 | 86 | *** 4 *** 87 | yini.4 = 0.6 88 | ywid.4 = 1.5 89 | yint.4 = 0.4 90 | 91 | *** 5 *** 92 | yini.5 = 0.6 93 | ywid.5 = 1.4 94 | yint.5 = 0.1 95 | 96 | 97 | ***** set parea ***** 98 | xmin = xini.imax + (xwid.imax + xint.imax) * (ipos-1) + xoffset 99 | xmax = xini.imax + (xwid.imax + xint.imax) * (ipos-1) + xwid.imax + xoffset 100 | ymin = yini.jmax + (ywid.jmax + yint.jmax) * (jpos-1) + yoffset 101 | ymax = yini.jmax + (ywid.jmax + yint.jmax) * (jpos-1) + ywid.jmax + yoffset 102 | 103 | 'set string 1 br 4 0' 104 | 'set strsiz 0.08 0.1' 105 | 'draw string 'xmax' 'ymax+0.30' max='max2d(var) 106 | 'draw string 'xmax' 'ymax+0.12' min='min2d(var) 107 | 108 | return 109 | 110 | 111 | 112 | 113 | function max2d(var) 114 | com = var 115 | 'q dims' 116 | 117 | * lon 118 | temp = sublin( result, 2 ) 119 | if( subwrd(temp,3) = 'varying' ) 120 | min = subwrd( temp, 6 ) 121 | max = subwrd( temp, 8 ) 122 | com = 'max('%com',lon='min',lon='max')' 123 | endif 124 | 125 | * lat 126 | temp = sublin( result, 3 ) 127 | if( subwrd(temp,3) = 'varying' ) 128 | min = subwrd( temp, 6 ) 129 | max = subwrd( temp, 8 ) 130 | com = 'max('%com',lat='min',lat='max')' 131 | endif 132 | 133 | * lev 134 | temp = sublin( result, 4 ) 135 | if( subwrd(temp,3) = 'varying' ) 136 | min = subwrd( temp, 6 ) 137 | max = subwrd( temp, 8 ) 138 | com = 'max('%com',lev='min',lev='max')' 139 | endif 140 | 141 | say com 142 | 'd 'com 143 | 144 | i = 1 145 | while(1) 146 | res = sublin( result, i ) 147 | if( res = '' ); break; endif 148 | if( subwrd(res,1) = 'Result' ); max=subwrd(res,4); break; endif 149 | i = i + 1 150 | endwhile 151 | 152 | return max 153 | 154 | 155 | 156 | function min2d(var) 157 | com = var 158 | 'q dims' 159 | 160 | * lon 161 | temp = sublin( result, 2 ) 162 | if( subwrd(temp,3) = 'varying' ) 163 | min = subwrd( temp, 6 ) 164 | max = subwrd( temp, 8 ) 165 | com = 'min('%com',lon='min',lon='max')' 166 | endif 167 | 168 | * lat 169 | temp = sublin( result, 3 ) 170 | if( subwrd(temp,3) = 'varying' ) 171 | min = subwrd( temp, 6 ) 172 | max = subwrd( temp, 8 ) 173 | com = 'min('%com',lat='min',lat='max')' 174 | endif 175 | 176 | * lev 177 | temp = sublin( result, 4 ) 178 | if( subwrd(temp,3) = 'varying' ) 179 | min = subwrd( temp, 6 ) 180 | max = subwrd( temp, 8 ) 181 | com = 'min('%com',lev='min',lev='max')' 182 | endif 183 | 184 | say com 185 | 'd 'com 186 | 187 | i = 1 188 | while(1) 189 | res = sublin( result, i ) 190 | if( res = '' ); break; endif 191 | if( subwrd(res,1) = 'Result' ); max=subwrd(res,4); break; endif 192 | i = i + 1 193 | endwhile 194 | 195 | return max 196 | 197 | 198 | * 199 | * help 200 | * 201 | function help() 202 | say ' Name:' 203 | say ' mulval '_version' - draw min/max values using multi-window' 204 | say ' ' 205 | say ' Usage:' 206 | say ' mulval imax jmax ipos jpos var ' 207 | say ' [-xoffset value/0] [-yoffset value/0]' 208 | say ' imax : number of window horizontally ( 1<= imax <= 5 )' 209 | say ' jmax : number of window vertically ( 1<= jmax <= 5 )' 210 | say ' ipos : horizontal position (count from left window)' 211 | say ' jpos : vertical position (count from bottom window)' 212 | say ' var : variables' 213 | say ' xoffset : offset of horizontal position' 214 | say ' yoffset : offset of vertical position' 215 | say '' 216 | say ' Note:' 217 | say ' [arg-name] : specify if needed' 218 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 219 | say '' 220 | say ' Copyright (C) 2009 Chihiro Kodama' 221 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 222 | say '' 223 | return 224 | -------------------------------------------------------------------------------- /prex.gsf: -------------------------------------------------------------------------------- 1 | function prex( cmd ) 2 | say cmd 3 | cmd 4 | return 5 | -------------------------------------------------------------------------------- /printf.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * currently, only support %0*[0-9]d 3 | * 4 | function printf( format, arg.1, arg.2, arg.3, arg.4, arg.5, arg.6, arg.7, arg.8, arg.9, arg.10 ) 5 | ret = '' 6 | buf.1 = '' 7 | 8 | length = math_strlen( format ) 9 | 10 | i = 1 11 | a = 1 12 | stat = 0 13 | buf.1 = '' 14 | buf.2 = '' 15 | buf.3 = '' 16 | while( i <= length ) 17 | *say 'stat = ' % stat 18 | tmp = substr( format, i, 1 ) 19 | *say tmp 20 | 21 | 22 | ***** stat=0: normal string ***** 23 | 24 | * 0 -> 1 25 | if( stat = 0 & tmp = '%' ) 26 | buf.1 = tmp 27 | stat = 1 28 | i = i + 1 ; continue 29 | endif 30 | 31 | * 0 -> 0 32 | if( stat = 0 ) 33 | ret = ret % tmp 34 | i = i + 1 ; continue 35 | endif 36 | 37 | ***** 1: buf.1='%' ***** 38 | 39 | * 1 -> 2 40 | if( stat = 1 & tmp = '0' ) 41 | buf.2 = tmp 42 | stat = 2 43 | i = i + 1 ; continue 44 | endif 45 | 46 | * 1 -> 3 47 | if( stat = 1 & valnum(tmp) = 1 ) 48 | buf.2 = ' ' 49 | buf.3 = tmp 50 | stat = 3 51 | i = i + 1 ; continue 52 | endif 53 | 54 | * 1 -> 0 55 | if( stat = 1 & tmp = 'd' ) 56 | ret = ret % math_int(arg.a) 57 | buf.1 = '' 58 | stat = 0 59 | a = a + 1 60 | i = i + 1 ; continue 61 | endif 62 | 63 | * 1 -> 0 64 | if( stat = 1 ) 65 | ret = ret % buf.1 % tmp 66 | buf.1 = '' 67 | stat = 0 68 | i = i + 1 ; continue 69 | endif 70 | 71 | ***** 2: buf.1='%', buf.2='0' ***** 72 | 73 | * 2 -> 3 74 | if( stat = 2 & valnum(tmp) = 1 ) 75 | buf.3 = tmp 76 | stat = 3 77 | i = i + 1 ; continue 78 | endif 79 | 80 | * 2 -> 0 81 | if( stat = 2 ) 82 | ret = ret % buf.1 % buf.2 % tmp 83 | buf.1 = '' 84 | buf.2 = '' 85 | stat = 0 86 | i = i + 1 ; continue 87 | endif 88 | 89 | ***** 3: buf.1='%', buf.2='0' or ' ', buf.3=[0-9] ***** 90 | 91 | * 3 -> 0 92 | if( stat = 3 & tmp = 'd' ) 93 | argc = math_int( arg.a ) 94 | j = math_strlen( argc ) + 1 95 | while( j <= buf.3 ) 96 | ret = ret % buf.2 97 | j = j + 1 98 | endwhile 99 | ret = ret % argc 100 | buf.3 = '' 101 | buf.2 = '' 102 | buf.1 = '' 103 | stat = 0 104 | a = a + 1 105 | i = i + 1 ; continue 106 | endif 107 | 108 | * 3 -> 0 109 | if( stat = 3 ) 110 | ret = ret % buf.1 % buf.2 % buf.3 % tmp 111 | buf.3 = '' 112 | buf.2 = '' 113 | buf.1 = '' 114 | stat = 0 115 | i = i + 1 ; continue 116 | endif 117 | 118 | * say tmp 119 | i = i + 1 120 | endwhile 121 | 122 | * flush buffer 123 | ret = ret % buf.1 % buf.2 % buf.3 124 | 125 | return ret 126 | end function 127 | -------------------------------------------------------------------------------- /pwd.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * need libbase.gsf 3 | * 4 | function pwd() 5 | rc = gsfallow( 'on' ) 6 | ret = libbase( 'pwd' ) 7 | return ret 8 | -------------------------------------------------------------------------------- /qattr.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * qattr( fn, key, name ) 3 | * 4 | * key = 'global', dimension name (e.g. 'lon'), or variable name 5 | * 6 | function qattr( fn, key_in, name_in ) 7 | _version = '0.01r1' 8 | 9 | * check arguement 10 | if( valnum(fn) != 1 ) 11 | say 'error: fn = ' % fn % ' is illegal.' 12 | exit 13 | endif 14 | if( valnum(key_in) != 0 ) 15 | say 'error: key = ' % key_in % ' is illegal.' 16 | exit 17 | endif 18 | if( valnum(name_in) != 0 ) 19 | say 'error: name = ' % name_in % ' is illegal.' 20 | exit 21 | endif 22 | 23 | ret = '' 24 | 25 | * obtain control file information 26 | 'q attr 'fn 27 | i = 2 28 | stat = '' 29 | while( i <= 10000 ) 30 | line = sublin( result, i ) 31 | if( line = '' ) ; break ; endif 32 | 33 | key = subwrd( line, 1 ) 34 | if( key = key_in ) 35 | name = subwrd( line, 3 ) 36 | if( name = name_in ) 37 | ret = rgnwrd( line, 4, 10000 ) 38 | break 39 | endif 40 | endif 41 | i = i + 1 42 | endwhile 43 | 44 | return ret 45 | -------------------------------------------------------------------------------- /qctlinfo.gsf: -------------------------------------------------------------------------------- 1 | * id = dset 2 | * title 3 | * undef 4 | * xdef 5 | * ydef 6 | * zdef 7 | * edef 8 | * tdef 9 | * vars 10 | * 'var-name' 11 | * vlist 12 | * elist 13 | * 14 | * num = 0: id itself 15 | * num >= 1 16 | * 17 | * for id = 'vlist', num is line number. 18 | * for id = 'elist', num is line number and num2 is its element. 19 | * 20 | function qctlinfo( fn, id, num, num2 ) 21 | _version = '0.03r3' 22 | 23 | * check arguement 24 | if( valnum(fn) != 1 ) 25 | say 'error: fn = ' % fn % ' is illegal.' 26 | exit 27 | endif 28 | if( valnum(id) != 0 ) 29 | say 'error: id = ' % id % ' is illegal.' 30 | exit 31 | endif 32 | if( num = 'num' ) ; num = '' ; endif 33 | if( valnum(num) != 1 & num != '' ) 34 | say 'error: num = ' % num % ' is illegal.' 35 | exit 36 | endif 37 | if( num2 = 'num2' ) ; num2 = '' ; endif 38 | if( valnum(num2) != 1 & num2 != '' ) 39 | say 'error: num2 = ' % num2 % ' is illegal.' 40 | exit 41 | endif 42 | 43 | * save current file number 44 | 'q file' 45 | line = sublin( result, 1 ) 46 | fnc = subwrd( line, 2 ) 47 | ret = '' 48 | 49 | * obtain control file information 50 | 'set dfile 'fn 51 | 'q ctlinfo' 52 | i = 1 53 | stat = '' 54 | statn = 1 55 | while( i - i = 0 ) 56 | line = sublin( result, i ) 57 | if( line = '' ) ; break ; endif 58 | 59 | * key = subwrd( line, 1 ) 60 | v.1 = subwrd( line, 1 ) 61 | v.2 = subwrd( line, 2 ) 62 | v.3 = subwrd( line, 3 ) 63 | 64 | if( v.1 = id ) 65 | if( num = '' ) 66 | ret = line 67 | else 68 | ret = subwrd( line, num+1 ) 69 | endif 70 | break 71 | endif 72 | 73 | if( v.1 = 'endedef' ) 74 | stat = '' ; statn = 0 75 | if( id = 'elist' ) ; break ; endif 76 | endif 77 | if( v.1 = 'endvars' ) 78 | stat = '' ; statn = 0 79 | if( id = 'vlist' ) ; break ; endif 80 | endif 81 | 82 | if( id = 'vlist' & stat = 'vars' ) 83 | if( statn = num ) 84 | ret = v.1 85 | break 86 | else 87 | ret = ret % v.1 % ' ' 88 | endif 89 | endif 90 | 91 | if( id = 'elist' & stat = 'edef' ) 92 | if( statn = num ) 93 | if( num2 = '' | num2 = 0 ) 94 | ret = line 95 | else 96 | ret = v.num2 97 | endif 98 | break 99 | else 100 | if( num2 = '' | num2 = 0 ) 101 | ret = ret % line % ' ' 102 | else 103 | ret = ret % v.num2 % ' ' 104 | endif 105 | endif 106 | endif 107 | 108 | if( v.1 = 'vars' & stat = '' ) 109 | stat = 'vars' ; statn = 0 110 | endif 111 | if( v.1 = 'edef' & stat = '' ) 112 | stat = 'edef' ; statn = 0 113 | endif 114 | 115 | statn = statn + 1 116 | i = i + 1 117 | endwhile 118 | 'set dfile 'fnc 119 | 120 | return ret 121 | -------------------------------------------------------------------------------- /qdims.gsf: -------------------------------------------------------------------------------- 1 | * id = fnum 2 | * varying/fixed : number of varying/fixed dimensions 3 | * 4 | * xtype 5 | * lonmin, lonmax 6 | * xmin, xmax 7 | * ytype 8 | * ... 9 | * z 10 | * t 11 | * e 12 | function qdims( id ) 13 | ret = '' 14 | 15 | 'q dims' 16 | 17 | if( id = 'fnum' ) 18 | line = sublin( result, 1 ) 19 | ret = subwrd( line, 5 ) 20 | return ret 21 | endif 22 | 23 | if( id = 'varying' | id = 'fixed' ) 24 | ret = 0 25 | i = 2 26 | while( i <= 6 ) 27 | line = sublin( result, i ) 28 | stat = subwrd( line, 3 ) 29 | if( stat = id ) ; ret = ret + 1 ; endif 30 | i = i + 1 31 | endwhile 32 | return ret 33 | endif 34 | 35 | if( id = 'xtype' | id = 'lonmin' | id = 'lonmax' | id = 'xmin' | id = 'xmax' ) 36 | line = sublin( result, 2 ) 37 | endif 38 | if( id = 'ytype' | id = 'latmin' | id = 'latmax' | id = 'ymin' | id = 'ymax' ) 39 | line = sublin( result, 3 ) 40 | endif 41 | if( id = 'ztype' | id = 'levmin' | id = 'levmax' | id = 'zmin' | id = 'zmax' ) 42 | line = sublin( result, 4 ) 43 | endif 44 | if( id = 'ttype' | id = 'timemin' | id = 'timemax' | id = 'tmin' | id = 'tmax' ) 45 | line = sublin( result, 5 ) 46 | endif 47 | if( id = 'etype' | id = 'ensmin' | id = 'ensmax' | id = 'emin' | id = 'emax' ) 48 | line = sublin( result, 6 ) 49 | endif 50 | 51 | type = subwrd( line, 3 ) 52 | if( id = 'xtype' | id = 'ytype' | id = 'ztype' | id = 'ttype' | id = 'etype' ) 53 | ret = type 54 | endif 55 | 56 | if( id = 'lonmin' | id = 'latmin' | id = 'levmin' | id = 'timemin' | id = 'ensmin' ) 57 | ret = subwrd( line, 6 ) 58 | return ret 59 | endif 60 | 61 | if( id = 'lonmax' | id = 'latmax' | id = 'levmax' | id = 'timemax' | id = 'ensmax' ) 62 | if( type = 'fixed' ) ; ret = subwrd( line, 6 ) 63 | else ; ret = subwrd( line, 8 ) ; endif 64 | return ret 65 | endif 66 | 67 | if( id = 'xmin' | id = 'ymin' | id = 'zmin' | id = 'tmin' | id = 'emin' ) 68 | if( type = 'fixed' ) ; ret = subwrd( line, 9 ) 69 | else ; ret = subwrd( line, 11 ) ; endif 70 | return ret 71 | endif 72 | 73 | if( id = 'xmax' | id = 'ymax' | id = 'zmax' | id = 'tmax' | id = 'emax' ) 74 | if( type = 'fixed' ) ; ret = subwrd( line, 9 ) 75 | else ; ret = subwrd( line, 13 ) ; endif 76 | return ret 77 | endif 78 | 79 | return ret 80 | -------------------------------------------------------------------------------- /qgr2w.gsf: -------------------------------------------------------------------------------- 1 | function qgr2w( gx, gy ) 2 | rc = gsfallow( 'on' ) 3 | 'q gr2w 'gx' 'gy 4 | wx = subwrd( result, 3 ) 5 | wy = subwrd( result, 6 ) 6 | if( valnum(wx) = 0 | valnum(wy) = 0 ) 7 | say 'error in qgr2w.gsf: fail to get (wx,wy) from (gx,gy)' 8 | return '' 9 | endif 10 | ret = wx % ' ' % wy 11 | return ret 12 | end function 13 | -------------------------------------------------------------------------------- /qgr2xy.gsf: -------------------------------------------------------------------------------- 1 | function qgr2xy( gx, gy ) 2 | rc = gsfallow( 'on' ) 3 | 'q gr2xy 'gx' 'gy 4 | x = subwrd( result, 3 ) 5 | y = subwrd( result, 6 ) 6 | if( valnum(x) = 0 | valnum(y) = 0 ) 7 | say 'error in qgr2xy.gsf: fail to get (x,y) from (gx,gy)' 8 | return '' 9 | endif 10 | ret = x % ' ' % y 11 | return ret 12 | end function 13 | -------------------------------------------------------------------------------- /qgxinfo.gsf: -------------------------------------------------------------------------------- 1 | * id = last 2 | * pagex, pagey 3 | * xmin, xmax 4 | * ymin, ymax 5 | * xaxis, yaxis 6 | * mproj 7 | function qgxinfo( id ) 8 | ret = '' 9 | 'q gxinfo' 10 | 11 | if( id = 'last' ) 12 | line = sublin( result, 1 ) 13 | ret = subwrd( line, 4 ) 14 | endif 15 | 16 | if( id = 'pagex' ) 17 | line = sublin( result, 2 ) 18 | ret = subwrd( line, 4 ) 19 | endif 20 | if( id = 'pagey' ) 21 | line = sublin( result, 2 ) 22 | ret = subwrd( line, 6 ) 23 | endif 24 | 25 | if( id = 'xmin' ) 26 | line = sublin( result, 3 ) 27 | ret = subwrd( line, 4 ) 28 | endif 29 | if( id = 'xmax' ) 30 | line = sublin( result, 3 ) 31 | ret = subwrd( line, 6 ) 32 | endif 33 | 34 | if( id = 'ymin' ) 35 | line = sublin( result, 4 ) 36 | ret = subwrd( line, 4 ) 37 | endif 38 | if( id = 'ymax' ) 39 | line = sublin( result, 4 ) 40 | ret = subwrd( line, 6 ) 41 | endif 42 | 43 | if( id = 'xaxis' ) 44 | line = sublin( result, 5 ) 45 | ret = subwrd( line, 3 ) 46 | endif 47 | if( id = 'yaxis' ) 48 | line = sublin( result, 5 ) 49 | ret = subwrd( line, 6 ) 50 | endif 51 | 52 | if( id = 'mproj' ) 53 | line = sublin( result, 6 ) 54 | ret = subwrd( line, 3 ) 55 | endif 56 | return ret 57 | -------------------------------------------------------------------------------- /qgxout.gsf: -------------------------------------------------------------------------------- 1 | * id = general 2 | * 1d-1expr, 1d-2expr, 3 | * 2d-1expr, 2d-2expr, 4 | * station 5 | function qgxout( id ) 6 | ret = '' 7 | 'q gxout' 8 | 9 | if( id = 'general' ) 10 | line = sublin( result, 1 ) 11 | ret = subwrd( line, 3 ) 12 | endif 13 | 14 | if( id = '1d-1expr' ) 15 | line = sublin( result, 2 ) 16 | ret = subwrd( line, 6 ) 17 | endif 18 | if( id = '1d-2expr' ) 19 | line = sublin( result, 3 ) 20 | ret = subwrd( line, 6 ) 21 | endif 22 | if( id = '2d-1expr' ) 23 | line = sublin( result, 4 ) 24 | ret = subwrd( line, 6 ) 25 | endif 26 | if( id = '2d-2expr' ) 27 | line = sublin( result, 5 ) 28 | ret = subwrd( line, 6 ) 29 | endif 30 | if( id = 'station' ) 31 | line = sublin( result, 6 ) 32 | ret = subwrd( line, 4 ) 33 | endif 34 | return ret 35 | -------------------------------------------------------------------------------- /qv2rh.gs: -------------------------------------------------------------------------------- 1 | * qv2rh qv prs rh 2 | function qv2rh( args ) 3 | qv = subwrd( args, 1 ) 4 | tem = subwrd( args, 2 ) 5 | * prs in [Pa] 6 | prs = subwrd( args, 3 ) 7 | rh = subwrd( args, 4 ) 8 | 9 | 10 | *** get saturation vapor mixing ratio [kg/kg] 11 | * following conv_prs.f90 in NICAM (original: Enanuel 1994, eq.4.1.2) 12 | 'tem0 = 273.15' 13 | 'tc = 'tem' - tem0' 14 | 'tc = const( maskout( tc, tc+80.0 ), -80.0, -u ) + 0 * 'tem 15 | 16 | * for liquid 17 | 'c0 = 0.6105851e+03' 18 | 'c1 = 0.4440316e+02' 19 | 'c2 = 0.1430341e+01' 20 | 'c3 = 0.2641412e-01' 21 | 'c4 = 0.2995057e-03' 22 | 'c5 = 0.2031998e-05' 23 | 'c6 = 0.6936113e-08' 24 | 'c7 = 0.2564861e-11' 25 | 'c8 = -0.3704404e-13' 26 | 'psatl = c0 + tc * ( c1 + tc * ( c2 + tc * ( c3 + tc * ( c4 + tc * ( c5 + tc * ( c6 + tc * ( c7 + tc * c8 )))))))' 27 | 28 | 'c0i = 0.609868993e+03' 29 | 'c1i = 0.499320233e+02' 30 | 'c2i = 0.184672631e+01' 31 | 'c3i = 0.402737184e-01' 32 | 'c4i = 0.565392987e-03' 33 | 'c5i = 0.521693933e-05' 34 | 'c6i = 0.307839583e-07' 35 | 'c7i = 0.105785160e-09' 36 | 'c8i = 0.161444444e-12' 37 | 'psati = c0i + tc * ( c1i + tc * ( c2i + tc * ( c3i + tc * ( c4i + tc * ( c5i + tc * ( c6i + tc * ( c7i + tc * c8i )))))))' 38 | 39 | 40 | * lmask = 1 & imask = 0: tc >= 0 41 | * lmask = 0 & imask = 1: tc < 0 42 | 'lmask = const( const( maskout(tc, tc), 1 ), 0, -u )' 43 | 'imask = -lmask + 1 + 0 * tc' 44 | 45 | 'qvsat = lmask * 287.04 / 461.50 * psatl / ( 'prs' - psatl ) + imask * 287.04 / 461.50 * psati / ( 'prs' - psati )' 46 | 47 | * 'qvsat = 287.04 / 461.50 * psatl / ( 'prs' - psatl )' 48 | * 'qvsat = 287.04 / 461.50 * psati / ( 'prs' - psati )' 49 | 50 | 51 | rh' = const( maskout( 'qv', 'qv' ), 0, -u) / qvsat * 100' 52 | 53 | return 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /qw2gr.gsf: -------------------------------------------------------------------------------- 1 | function qw2gr( wx, wy ) 2 | rc = gsfallow( 'on' ) 3 | 'q w2gr 'wx' 'wy 4 | gx = subwrd( result, 3 ) 5 | gy = subwrd( result, 6 ) 6 | if( valnum(gx) = 0 | valnum(gy) = 0 ) 7 | say 'error in qw2gr.gsf: fail to get (gx,gy) from (wx,wy)' 8 | return '' 9 | endif 10 | ret = gx % ' ' % gy 11 | return ret 12 | end function 13 | -------------------------------------------------------------------------------- /qw2xy.gsf: -------------------------------------------------------------------------------- 1 | function qw2xy( wx, wy ) 2 | rc = gsfallow( 'on' ) 3 | 'q w2xy 'wx' 'wy 4 | x = subwrd( result, 3 ) 5 | y = subwrd( result, 6 ) 6 | if( valnum(x) = 0 | valnum(y) = 0 ) 7 | say 'error in qw2xy.gsf: fail to get (x,y) from (wx,wy)' 8 | return '' 9 | endif 10 | ret = x % ' ' % y 11 | return ret 12 | end function 13 | -------------------------------------------------------------------------------- /qxy2gr.gsf: -------------------------------------------------------------------------------- 1 | function qxy2gr( x, y ) 2 | rc = gsfallow( 'on' ) 3 | 'q xy2gr 'x' 'y 4 | gx = subwrd( result, 3 ) 5 | gy = subwrd( result, 6 ) 6 | if( valnum(gx) = 0 | valnum(gy) = 0 ) 7 | say 'error in qxy2gr.gsf: fail to get (gx,gy) from (x,y)' 8 | return '' 9 | endif 10 | ret = gx % ' ' % gy 11 | return ret 12 | end function 13 | -------------------------------------------------------------------------------- /qxy2w.gsf: -------------------------------------------------------------------------------- 1 | function qxy2w( x, y ) 2 | rc = gsfallow( 'on' ) 3 | check = qgxinfo( 'last' ) 4 | 'q xy2w 'x' 'y 5 | wx = subwrd( result, 3 ) 6 | wy = subwrd( result, 6 ) 7 | if( valnum(wx) = 0 | valnum(wy) = 0 ) 8 | say 'error in qxy2w.gsf: fail to get (wx,wy) from (x,y)' 9 | return '' 10 | endif 11 | ret = wx % ' ' % wy 12 | return ret 13 | end function 14 | -------------------------------------------------------------------------------- /rgnwrd.gsf: -------------------------------------------------------------------------------- 1 | function rgnwrd( str, n_start, n_end, sep ) 2 | 3 | * If separator is space, just use subwrd() for output. 4 | * if( sep = 'sep' | sep = '' | sep = ' ' ) 5 | if( sep = 'sep' | sep = '' ) 6 | n = n_start 7 | ret = '' 8 | while( n <= n_end ) 9 | tmp = subwrd( str, n ) 10 | if( tmp = '' ) ; break ; endif 11 | ret = ret % tmp % ' ' 12 | n = n + 1 13 | endwhile 14 | 15 | else 16 | ret = '' 17 | len_sep = math_strlen( sep ) 18 | len = math_strlen( str ) 19 | p = 1 20 | i = 1 21 | imin = -1 22 | if( n_start = 1 ) ; imin = 1 ; endif 23 | imax = len 24 | while( i <= len ) 25 | c = substr( str, i, len_sep ) 26 | if( c = sep ) 27 | p = p + 1 28 | if( p = n_start ) ; imin = i + len_sep ; endif 29 | if( p > n_end ) ; imax = i - len_sep ; break ; endif 30 | i = i + len_sep 31 | else 32 | i = i + 1 33 | endif 34 | endwhile 35 | if( imin = -1 | imin > imax ) ; ret = '' 36 | else ; ret = substr( str, imin, imax-imin+1 ) ; endif 37 | 38 | endif 39 | return ret 40 | -------------------------------------------------------------------------------- /save.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function save( args ) 5 | _version = '0.04r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | fhead = '' 15 | background = 'white' 16 | density = 'low' 17 | size = 'normal' 18 | 19 | ***** Arguements ***** 20 | i = 1 21 | while( 1 ) 22 | arg = subwrd( args, i ) 23 | i = i + 1; 24 | if( arg = '' ); break; endif 25 | while( 1 ) 26 | *** option 27 | if( arg = '-background' ) ; background = subwrd(args,i) ; i=i+1 ; break ; endif 28 | if( arg = '-density' ) ; density = subwrd(args,i) ; i=i+1 ; break ; endif 29 | if( arg = '-size' ) ; size = subwrd(args,i) ; i=i+1 ; break ; endif 30 | 31 | if( arg = '-hh' ) ; size = 'huge' ; density = 'high' ; break ; endif 32 | if( arg = '-lh' | arg = '-hl' ) ; size = 'large' ; density = 'high' ; break ; endif 33 | if( arg = '-nh' | arg = '-hn' ) ; size = 'normal' ; density = 'high' ; break ; endif 34 | if( arg = '-sh' | arg = '-hs' ) ; size = 'small' ; density = 'high' ; break ; endif 35 | 36 | *** fhead 37 | if( fhead = '' ) ; fhead = arg ; break ; endif 38 | say 'syntax error: 'arg 39 | return 40 | endwhile 41 | endwhile 42 | 43 | if( background != 'white' & background != 'black' ) 44 | say 'error: background = ' % background % ' is not supported' 45 | exit 46 | endif 47 | 48 | * quality of rendering 49 | if( density = 'low' ) ; density = 150 ; endif 50 | if( density = 'normal' ) ; density = 300 ; endif 51 | if( density = 'high' ) ; density = 600 ; endif 52 | if( density = 'print' ) ; density = 1200 ; endif 53 | 54 | if( size = 'small' ) ; size = '400x400' ; endif 55 | if( size = 'normal' ) ; size = '800x800' ; endif 56 | if( size = 'large' ) ; size = '1600x1600' ; endif 57 | if( size = 'huge' ) ; size = '3200x3200' ; endif 58 | 59 | ***** ***** 60 | len = math_strlen( fhead ) 61 | ext = substr( fhead, len-3, 4 ) 62 | 63 | fname = '' 64 | if( ext = '.png' ) 65 | fname = fhead 66 | fhead = substr( fhead, 1, len-4 ) 67 | endif 68 | if( ext = '.eps' ) 69 | fhead = substr( fhead, 1, len-4 ) 70 | fname = fhead % '.eps' 71 | endif 72 | if( fname = '' ) 73 | ext = '.eps' 74 | fname = fhead % '.eps' 75 | endif 76 | 77 | 78 | ***** png ***** 79 | if( ext = '.png' ) 80 | 81 | * This version (v2.1.0) seems to have a bug in printim. 82 | * if( gradsver( 'v2.1.0' ) = 0 ) 83 | eps = fhead % '_tmp.eps' 84 | temp1 = fhead % '_tmp1.png' 85 | temp2 = fhead % '_tmp2.png' 86 | 'save 'fhead'_tmp -background 'background 87 | '!convert -rotate 90 +antialias -depth 8 -define png:bit-depth=8 -density 'density' -resize 'size' 'eps' 'temp1 88 | '!convert -fill 'background' -draw "rectangle 0,0,10000,10000" 'temp1' 'temp2 89 | '!composite 'temp1' 'temp2' 'fname 90 | '!rm 'eps' 'temp1' 'temp2 91 | 92 | * else 93 | 94 | * 'printim 'fname' 'background 95 | 96 | * endif 97 | endif 98 | 99 | ***** eps ***** 100 | if( ext = '.eps' ) 101 | 102 | if( gradsver( 'v2.1.a1' ) = 1 ) 103 | 'gxprint 'fhead'.eps 'background 104 | 105 | else 106 | 'enable print 'fhead'.gmf' 107 | 'print' 108 | 'disable' 109 | opt = '' 110 | if( background = 'black' ) 111 | opt = '-r' 112 | endif 113 | '!gxeps -c 'opt' -i 'fhead'.gmf -o 'fhead'.eps' 114 | '!rm -f 'fhead'.gmf' 115 | endif 116 | endif 117 | 118 | return 119 | 120 | * 121 | * help 122 | * 123 | function help() 124 | say ' Name:' 125 | say ' save '_version' - Save image as eps/png format.' 126 | say ' ' 127 | say ' Usage(1):' 128 | say ' save file-head' 129 | say '' 130 | say ' file-head : filename before .eps' 131 | say ' (ex. file-head=test -> save as test.eps)' 132 | say '' 133 | say ' Usage(2):' 134 | say ' save filename [-background ("white"|"black")]' 135 | say ' [-density ("low"|"normal"|"high"|"print"|density)]' 136 | say ' [-size ("small"|"normal"|"large"|"huge"|size)]' 137 | say ' [-hh|-lh|-hl|-nh|-nl|-sh|-hs]' 138 | say '' 139 | say ' filename : Filename ending with .eps or .png' 140 | say ' background : Background color. Default="white"' 141 | say ' density : Quality of rendering from eps to png. Default="low"' 142 | say ' size : Size of png. Default="normal"' 143 | say ' -hh : same as "-size huge -density high"' 144 | say ' -lh | -hl : same as "-size large -density high"' 145 | say ' -nh | -hn : same as "-size normal -density high"' 146 | say ' -sh | -hs : same as "-size small -density high"' 147 | say '' 148 | say ' Note:' 149 | say ' [arg-name] : specify if needed' 150 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 151 | say ' This function uses ImageMagick and gxeps commands.' 152 | say '' 153 | say ' Copyright (C) 2009-2019 Chihiro Kodama' 154 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 155 | say '' 156 | return 157 | -------------------------------------------------------------------------------- /saveanim.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function saveanim( args ) 5 | _version = '0.01r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | var = '' 15 | head = '' 16 | type = 'gifanim' 17 | fps = 5 18 | density = 'low' 19 | size = 'medium' 20 | 21 | ***** Arguement ***** 22 | i = 1 23 | while( 1 ) 24 | arg = subwrd( args, i ) 25 | i = i + 1; 26 | if( arg = '' ); break; endif 27 | 28 | while( 1 ) 29 | *** option 30 | if( arg = '-density' ) ; density = subwrd(args,i) ; i=i+1 ; break ; endif 31 | if( arg = '-fps' ) ; fps = subwrd(args,i) ; i=i+1 ; break ; endif 32 | if( arg = '-size' ) ; size = subwrd(args,i) ; i=i+1 ; break ; endif 33 | if( arg = '-type' ) ; type = subwrd(args,i) ; i=i+1 ; break ; endif 34 | 35 | if( arg = '-hh' ) ; size = 'huge' ; density = 'high' ; break ; endif 36 | if( arg = '-hl' | arg = '-lh' ) ; size = 'large' ; density = 'high' ; break ; endif 37 | if( arg = '-hn' | arg = '-nh' ) ; size = 'normal' ; density = 'high' ; break ; endif 38 | if( arg = '-hs' | arg = '-sh' ) ; size = 'small' ; density = 'high' ; break ; endif 39 | 40 | *** 41 | if( var = '' ) 42 | var = arg 43 | break 44 | endif 45 | 46 | if( var != '' & head = '' ) 47 | head = arg 48 | break 49 | endif 50 | 51 | say 'syntax error: 'arg 52 | return 53 | endwhile 54 | 55 | endwhile 56 | 57 | * var = subwrd( args, 1 ) 58 | * head = subwrd( args, 2 ) 59 | if( head = '' ) ; head = 'anim_' % var ; endif 60 | 61 | *** 62 | tmin = qdims( 'tmin' ) 63 | tmax = qdims( 'tmax' ) 64 | 65 | * save color table 66 | gxinfo = qgxinfo('last') 67 | if( gxinfo = 'Shaded2' | gxinfo = 'GrFill' ) 68 | 'q shades' 69 | shdinfo = result 70 | cnum = subwrd( shdinfo, 5 ) 71 | ccols = '' 72 | clevs = '' 73 | i = 1 74 | while( i <= cnum ) 75 | rec = sublin( shdinfo, i+1 ) 76 | ccols = ccols % ' ' % subwrd( rec, 1 ) 77 | if( i = cnum ) ; break ; endif 78 | clevs = clevs % ' ' % subwrd( rec, 3 ) 79 | i = i + 1 80 | endwhile 81 | endif 82 | 83 | file_list = '' 84 | 85 | t = tmin 86 | while( t <= tmax ) 87 | 'set t 't 88 | file = head % '_' % printf( '%05d', t ) % '.png' 89 | say file 90 | 91 | 'c' 92 | 'set grads off' 93 | if( gxinfo = 'Shaded2' | gxinfo = 'GrFill' ) 94 | 'set clevs 'clevs 95 | 'set ccols 'ccols 96 | endif 97 | 'd 'var 98 | 'draw title 't2time(t) 99 | gxinfo = qgxinfo('last') 100 | if( gxinfo = 'Shaded2' | gxinfo = 'GrFill' ) 101 | 'xcbar -line on -edge triangle' 102 | endif 103 | 'save -density 'density' -size 'size' 'file 104 | file_list = file_list % ' ' % file 105 | t = t + 1 106 | endwhile 107 | 108 | if( type = 'gifanim' ) 109 | delay = 100 / fps 110 | prex( '!convert -delay 'delay' 'file_list' 'head'.gif' ) 111 | endif 112 | 113 | 'set t 'tmin' 'tmax 114 | return 115 | 116 | * 117 | * help 118 | * 119 | function help() 120 | say ' Name:' 121 | say ' saveanim '_version' - Save animation as gif format or separate png files.' 122 | say ' ' 123 | say ' Usage:' 124 | say ' saveanim var-exp [fhead]' 125 | say ' [-type type]' 126 | say ' [-fps fps]' 127 | say ' [-density ] [-size size]' 128 | say ' [-hh|-lh|-hl|-nh|-hn|-sh|-hs]' 129 | say '' 130 | say ' var-exp : Expression' 131 | say ' fhead : Header of filename (before extension)' 132 | say ' type : Output file type. "gifanim" or "png". Default="gifanim".' 133 | say ' fps : Flame per second for animation. Default=5' 134 | say ' density : Quality of rendering from eps to png. Default="low"' 135 | say ' size : Size of png. Default="normal"' 136 | say ' -hh : Same as "-size huge -density high"' 137 | say ' -lh | -hl : Same as "-size large -density high"' 138 | say ' -nh | -hn : Same as "-size normal -density high"' 139 | say ' -sh | -hs : Same as "-size small -density high"' 140 | say '' 141 | say ' Note:' 142 | say ' [arg-name] : specify if needed' 143 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 144 | say ' This function uses save.gs and ImageMagic.' 145 | say '' 146 | say ' Copyright (C) 2019-2022 Chihiro Kodama' 147 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 148 | say '' 149 | return 150 | 151 | fps = 5 152 | density = 'low' 153 | size = 'medium' 154 | -------------------------------------------------------------------------------- /setfont.gs: -------------------------------------------------------------------------------- 1 | * 2 | * help is in the end of this script 3 | * 4 | function setfont( args ) 5 | _version = '0.02r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | angle = 0 15 | base = 'c' 16 | color = 1 17 | 18 | ***** Arguement ***** 19 | type = subwrd(args,1) 20 | i = 2 21 | arg = "dummy" 22 | while( arg != "" ) 23 | arg = subwrd( args, i ) 24 | i = i + 1 25 | 26 | if( arg = "-angle" ) ; angle = subwrd( args, i ) ; i = i + 1 ; endif 27 | if( arg = "-base" ) ; base = subwrd( args, i ) ; i = i + 1 ; endif 28 | if( arg = "-color" ) ; color = subwrd( args, i ) ; i = i + 1 ; endif 29 | endwhile 30 | 31 | 32 | if( type = "tiny" ) 33 | width = 0.09 34 | height = 0.09 35 | thickness = 2.7 36 | endif 37 | 38 | if( type = "small" ) 39 | width = 0.12 40 | height = 0.12 41 | thickness = 3.6 42 | endif 43 | 44 | if( type = "normal" ) 45 | width = 0.15 46 | height = 0.15 47 | thickness = 4.5 48 | endif 49 | 50 | if( type = "large" ) 51 | width = 0.20 52 | height = 0.20 53 | thickness = 6.0 54 | endif 55 | 56 | if( type = "huge" ) 57 | width = 0.30 58 | height = 0.30 59 | thickness = 9.0 60 | endif 61 | 62 | pt = strrep( type, 'pt', '' ) 63 | if( type != pt ) 64 | width = pt / 72.0 65 | height = width 66 | thickness = math_int( width * 30 ) 67 | if( thickness > 12 ) ; thickness = 12 ; endif 68 | endif 69 | 70 | 'set strsiz 'width' 'height 71 | 'set string 'color' 'base' 'thickness' 'angle 72 | 73 | return 74 | 75 | 76 | * 77 | * help 78 | * 79 | function help() 80 | say ' Name:' 81 | say ' setfont '_version' - Set font property' 82 | say ' ' 83 | say ' Usage:' 84 | say ' setfont size [-angle angle] [-base string-base]' 85 | say '' 86 | say ' size : tiny, small, normal, large, huge, or e.g., 10pt ' 87 | say ' -angle angle : string angle (0<=angle<360)' 88 | say ' -base string-base : string base (c, tl, bc, etc...), default=c' 89 | say ' -color color-num : color number' 90 | say '' 91 | say ' Note:' 92 | say ' [arg-name] : specify if needed' 93 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 94 | say '' 95 | say ' Copyright (C) 2009-2015 Chihiro Kodama' 96 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 97 | say '' 98 | return 99 | -------------------------------------------------------------------------------- /setlabs.gs: -------------------------------------------------------------------------------- 1 | function setlabs( args ) 2 | _version = '0.01b2' 3 | rc = gsfallow("on") 4 | 5 | if( args = '' ) 6 | help() 7 | return 8 | endif 9 | 10 | ***** Default value ***** 11 | axis = '' 12 | int = 0 13 | mul = '1' 14 | add = '0' 15 | opmax = 0 16 | 17 | ***** Arguement ***** 18 | i = 1 19 | while( 1 ) 20 | arg = subwrd( args, i ) 21 | i = i + 1; 22 | if( arg = '' ); break; endif 23 | 24 | while( 1 ) 25 | *** option 26 | if( arg = '-int' ) ; int=subwrd(args,i) ; i=i+1 ; break ; endif 27 | 28 | if( arg = '-mul' | arg = '-add' ) 29 | opmax = opmax + 1 30 | op.opmax = arg 31 | opval.opmax = subwrd(args,i) 32 | i=i+1 33 | break 34 | endif 35 | 36 | *** dim 37 | if( axis = '' ) 38 | axis = arg 39 | break 40 | endif 41 | 42 | say 'syntax error: 'arg 43 | 44 | return 45 | 46 | endwhile 47 | endwhile 48 | 49 | type.1 = 'xtype' ; dim.1 = 'lon' 50 | type.2 = 'ytype' ; dim.2 = 'lat' 51 | type.3 = 'ztype' ; dim.3 = 'lev' 52 | 53 | cnt = 0 54 | i = 1 55 | while( i <= 3 ) 56 | tmp = qdims( type.i ) 57 | if( tmp = 'varying' ) 58 | cnt = cnt + 1 59 | if( ( cnt = 1 & axis = 'xl' ) | ( cnt = 2 & axis = 'yl' ) ) 60 | dim = dim.i 61 | break 62 | endif 63 | endif 64 | i = i + 1 65 | endwhile 66 | 67 | min = qdims( dim'min' ) 68 | max = qdims( dim'max' ) 69 | o = 1 70 | while( o <= opmax ) 71 | if( op.o = '-mul' ) 72 | min = min * (opval.o) 73 | max = max * (opval.o) 74 | endif 75 | if( op.o = '-add' ) 76 | min = min + (opval.o) 77 | max = max + (opval.o) 78 | endif 79 | o = o + 1 80 | endwhile 81 | 82 | if( int > 0 ) 83 | num = ( max - min ) / int 84 | if( valnum(num) != 1 ) 85 | say 'error in setlabs.gs: number of labels must be an integer.' 86 | say 'min=' % min % ', max=' % max % ', int=' % int % ', num=' % num 87 | return 88 | endif 89 | else 90 | num = 10 91 | int = ( max - min ) / num 92 | endif 93 | 94 | if( max < min ) 95 | num = -num 96 | if( int > 0 ) ; int = -int ; endif 97 | endif 98 | 99 | n = 0 100 | val = min 101 | while( n <= num ) 102 | val_disp = val 103 | 104 | if( n = 0 ) 105 | labs = val_disp 106 | else 107 | labs = labs % '|' % val_disp 108 | endif 109 | 110 | n = n + 1 111 | val = val + int 112 | endwhile 113 | 114 | prex( 'set 'axis'abs 'labs ) 115 | return 116 | 117 | 118 | * 119 | * help 120 | * 121 | function help() 122 | say ' Name:' 123 | say ' setlabs '_version' - Set x/y labels.' 124 | say ' ' 125 | say ' Usage:' 126 | say ' setlabs ( xl | yl )' 127 | say ' [ (-mul | -add) value1 [ (-mul | -add) value2 ... ]]' 128 | say ' [-int interval]' 129 | say '' 130 | say ' ( xl | yl ) : Horizontal label or vertical label.' 131 | say ' (-mul value1) : Label values are multiplied by value1.' 132 | say ' (-add value1) : label values are added by value1.' 133 | say ' Operations are performed by the order appeared in the -mul/-add options.' 134 | say ' -int interval : interval of label values (after operator is applied).' 135 | say '' 136 | say ' Note:' 137 | say ' [arg-name] : specify if needed' 138 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 139 | say '' 140 | say ' Copyright (C) 2012-2015 Chihiro Kodama' 141 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 142 | say '' 143 | return 144 | -------------------------------------------------------------------------------- /setshift.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function setshift( args ) 5 | _version = '0.01r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | dim = subwrd( args, 1 ) 14 | shift = subwrd( args, 2 ) 15 | 16 | min = qdims( dim'min' ) 17 | max = qdims( dim'max' ) 18 | 19 | min = min + shift 20 | max = max + shift 21 | 22 | * prex( 'set 'dim' 'min' 'max ) 23 | 'set 'dim' 'min' 'max 24 | 25 | return 26 | 27 | * 28 | * help 29 | * 30 | function help() 31 | say ' Name:' 32 | say ' setshift '_version' - set dimension relative to the current one' 33 | say ' ' 34 | say ' Usage:' 35 | say ' setshift dim-name shift' 36 | say '' 37 | say ' dim : Dimension name. "x", "y", "z", or "t"' 38 | say ' shift : Amount of shift relative to the current dimension.' 39 | say '' 40 | say ' Note:' 41 | say ' [arg-name] : specify if needed' 42 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 43 | say '' 44 | say ' Copyright (C) 2015-2015 Chihiro Kodama' 45 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 46 | say '' 47 | return 48 | -------------------------------------------------------------------------------- /setstr.gsf: -------------------------------------------------------------------------------- 1 | function setstr( name, str ) 2 | rc = gsfallow( 'on' ) 3 | ret = strmem( set, name, str ) 4 | return ret 5 | -------------------------------------------------------------------------------- /shade.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function shade( args ) 5 | _version = '0.02r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | var = subwrd( args, 1 ) 13 | 14 | min = subwrd( args, 2 ) 15 | max = subwrd( args, 3 ) 16 | if( min = '-min' ) 17 | min = max 18 | max = 1e+30 19 | endif 20 | if( min = '-max' ) 21 | min = -1e+30 22 | endif 23 | 24 | r = subwrd( args, 4 ) 25 | g = subwrd( args, 5 ) 26 | b = subwrd( args, 6 ) 27 | 28 | *** gray (default) *** 29 | if( r = "" | g = "" | b = "" ) 30 | r = 211 31 | g = 211 32 | b = 211 33 | endif 34 | 35 | 'set rgb 90 'r' 'g' 'b' 255' 36 | 'set rgb 91 255 255 255 0' 37 | 38 | 'set gxout shaded' 39 | 'set clevs 'min' 'max 40 | * 'set ccols 0 90 0' 41 | 'set ccols 91 90 91' 42 | 'd 'var 43 | 44 | return 45 | 46 | 47 | * 48 | * help 49 | * 50 | function help() 51 | say ' Name:' 52 | say ' shade '_version' - draw shade' 53 | say ' ' 54 | say ' Usage:' 55 | say ' shade ' 56 | say ' var (min max | -min min | -max max)' 57 | say ' [r g b]' 58 | say '' 59 | say ' var : Variable name.' 60 | say ' min : Minimum value of the region to shade.' 61 | say ' max : Mamimum value of the region to shade.' 62 | say ' r : RGB value (red) of the color for shading. Default value is 211.' 63 | say ' g : RGB value (green) of the color for shading. Default value is 211.' 64 | say ' b : RGB value (blue) of the color for shading. Default value is 211.' 65 | say '' 66 | say ' Note:' 67 | say ' [arg-name] : specify if needed' 68 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 69 | say ' If (r,g,b) is not specified, the color of shade is set to gray' 70 | say '' 71 | say ' Copyright (C) 2009-2015 Chihiro Kodama' 72 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 73 | say '' 74 | return 75 | -------------------------------------------------------------------------------- /shift.gs: -------------------------------------------------------------------------------- 1 | function shift( args ) 2 | _version = '0.01b1' 3 | rc = gsfallow("on") 4 | 5 | if( args = '' ) 6 | help() 7 | return 8 | endif 9 | 10 | ***** Default value ***** 11 | xshift = 0 12 | yshift = 0 13 | xcyc = 0 14 | ycyc = 0 15 | xrev = 0 16 | yrev = 0 17 | 18 | vorg = '' 19 | vnew = '' 20 | 21 | ***** Arguement ***** 22 | i = 1 23 | while( 1 ) 24 | arg = subwrd( args, i ) 25 | i = i + 1; 26 | if( arg = '' ); break; endif 27 | 28 | while( 1 ) 29 | *** option 30 | if( arg = '-xcyc' ) ; xcyc = 1 ; break ; endif 31 | if( arg = '-ycyc' ) ; ycyc = 1 ; break ; endif 32 | if( arg = '-xrev' ) ; xrev = 1 ; break ; endif 33 | if( arg = '-yrev' ) ; yrev = 1 ; break ; endif 34 | if( arg = '-xshift' ) ; xshift=subwrd(args,i) ; i=i+1 ; break ; endif 35 | if( arg = '-yshift' ) ; yshift=subwrd(args,i) ; i=i+1 ; break ; endif 36 | if( arg = '-xyshift' ) 37 | xshift = subwrd(args,i) 38 | i = i + 1 39 | yshift = subwrd(args,i) 40 | i = i + 1 41 | break 42 | endif 43 | 44 | *** vorg, vnew 45 | if( vorg = '' ) 46 | vorg = arg 47 | break 48 | endif 49 | if( vnew = '' ) 50 | vnew = arg 51 | break 52 | endif 53 | 54 | say 'syntax error: 'arg 55 | return 56 | 57 | endwhile 58 | endwhile 59 | 60 | xmin = qdims( xmin ) 61 | xmax = qdims( xmax ) 62 | xdef = xmax - xmin + 1 63 | ymin = qdims( ymin ) 64 | ymax = qdims( ymax ) 65 | ydef = ymax - ymin + 1 66 | 67 | 'q undef' 68 | undef = subwrd( result, 7 ) 69 | 70 | vnew' = maskout('vorg',-1)' 71 | 72 | y = ymin 73 | while( y <= ymax ) 74 | x = xmin 75 | while( x <= xmax ) 76 | 77 | xnew = x + xshift 78 | ynew = y + yshift 79 | if( xrev = 1 ) ; xnew = xmax - ( xnew - xmin ) ; endif 80 | if( yrev = 1 ) ; ynew = ymax - ( ynew - ymin ) ; endif 81 | 82 | if( xcyc = 1 & xnew < xmin ) ; xnew = xnew + xdef ; endif 83 | if( xcyc = 1 & xnew > xmax ) ; xnew = xnew - xdef ; endif 84 | if( ycyc = 1 & ynew < ymin ) ; ynew = ynew + ydef ; endif 85 | if( ycyc = 1 & ynew > ymax ) ; ynew = ynew - ydef ; endif 86 | 87 | if( xnew >= xmin & xnew <= xmax & ynew >= ymin & ynew <= ymax ) 88 | 'set x 'x 89 | 'set y 'y 90 | 'd 'vorg 91 | tmpvorg = subwrd( result, 4 ) 92 | if( tmpvorg != undef ) 93 | 'set defval 'vnew' 'xnew' 'ynew' 'tmpvorg 94 | endif 95 | endif 96 | 97 | x = x + 1 98 | endwhile 99 | y = y + 1 100 | endwhile 101 | 102 | 'set x 'xmin' 'xmax 103 | 'set y 'ymin' 'ymax 104 | return 105 | 106 | 107 | * 108 | * help 109 | * 110 | function help() 111 | say ' Name:' 112 | say ' shift '_version' - horizontally shift values of variable' 113 | say ' ' 114 | say ' Usage:' 115 | say ' shift vorg vnew' 116 | say ' [-xshift xshift]' 117 | say ' [-yshift yshift]' 118 | say ' [-xyshift xshift yshift]' 119 | say ' [-xcyc]' 120 | say ' [-ycyc]' 121 | say '' 122 | say ' vorg : original variable name' 123 | say ' vnew : converted variable name' 124 | say ' xshift/yshift : shift in x/y direction' 125 | say ' -xcyc, -ycyc : specify if x/y is cyclic' 126 | say ' -xrev, -yrev : reverse x/y AFTER shifting' 127 | say '' 128 | say ' Note:' 129 | say ' [arg-name] : specify if needed' 130 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 131 | say '' 132 | say ' Copyright (C) 2012-2012 Chihiro Kodama' 133 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 134 | say '' 135 | return 136 | -------------------------------------------------------------------------------- /strmem.gsf: -------------------------------------------------------------------------------- 1 | * 2 | * act = 'set' : set variable 3 | * 4 | * act = 'get' : get variable 5 | * 6 | * ' Copyright (C) 2010-2015 Chihiro Kodama' 7 | * ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 8 | * 9 | function strmem( act, name, str ) 10 | _version = '0.01r1' 11 | rc = gsfallow( 'on' ) 12 | 13 | ********** BELOW PLEASE SET PATH FOR TEMPORARY BUFFER ************ 14 | path = '/var/tmp' 15 | ********** ABOVE PLEASE SET PATH FOR TEMPORARY BUFFER ************ 16 | 17 | if( act != 'set' & act != get ) 18 | say 'error in strmem.gsf : no action specified' 19 | return -1 20 | endif 21 | if( name = '' ) 22 | say 'error in strmem.gsf : no variable name' 23 | return -1 24 | endif 25 | 26 | ********** create dummy control file if necessary ********** 27 | * whether at least one control file is opened or not 28 | 'q files' 29 | 30 | flag = sublin( result, 1 ) 31 | if( flag = 'No files open' ) ; flag = 'dummy' ; endif 32 | if( flag = 'dummy' ) 33 | gs = path % '/grads_strmem_dummy.ctl' 34 | i = 1 35 | maxi = 10 36 | while( i <= maxi ) 37 | ret = read( gs ) 38 | stat = sublin( ret, 1 ) 39 | if( stat = 1 ) ; ret = write( gs, '*' ) ; break ; endif 40 | if( stat = 0 ) ; ret = close( gs ) ; endif 41 | if( i = maxi ) 42 | say 'error : ' % gs % ' is locked by other process' 43 | exit 44 | endif 45 | '!sleep 1s' 46 | i = i + 1 47 | endwhile 48 | 49 | * dummy control file is created, opened, and removed 50 | ret = write( gs, 'DSET ^dummy%y4.grd' ) 51 | ret = write( gs, 'OPTIONS TEMPLATE' ) 52 | ret = write( gs, 'UNDEF 0' ) 53 | ret = write( gs, 'XDEF 1 LEVELS 0' ) 54 | ret = write( gs, 'YDEF 1 LEVELS 0' ) 55 | ret = write( gs, 'ZDEF 1 LEVELS 0' ) 56 | ret = write( gs, 'TDEF 1 LINEAR 01jan2000 1mo' ) 57 | ret = write( gs, 'VARS 1' ) 58 | ret = write( gs, 'dummy 0 99 dummy' ) 59 | ret = write( gs, 'ENDVARS' ) 60 | ret = close( gs ) 61 | 'open 'gs 62 | '!rm -f 'gs 63 | endif 64 | 65 | ********** set string ********** 66 | if( act = 'set' ) 67 | length = math_strlen(str) 68 | i = 1 69 | while( i <= length ) 70 | char = substr( str, i, 1 ) 71 | int = atoi( char ) 72 | 73 | * say char ' ' int 74 | 75 | ''name''i' = 'int 76 | 77 | i = i + 1 78 | endwhile 79 | ''name'0 = 'i-1 80 | if( flag = 'dummy' ) ; 'close 1' ; endif 81 | return 82 | endif 83 | 84 | ********** get string ********** 85 | if( act = 'get' ) 86 | str = '' 87 | * 'd 'name'0' 88 | 'q defval 'name'0 1 1' 89 | * length = subwrd( result, 4 ) 90 | length = subwrd( result, 3 ) 91 | if( valnum(length) = 0 ) ; exit ; endif 92 | i = 1 93 | while( i <= length ) 94 | * 'd 'name''i 95 | 'q defval 'name''i' 1 1' 96 | * int = subwrd( result, 4 ) 97 | int = subwrd( result, 3 ) 98 | if( valnum(int) = 0 ) ; say 'error at 'i ; exit ; endif 99 | str = str % itoa( int ) 100 | i = i + 1 101 | endwhile 102 | 103 | if( flag = 'dummy' ) ; 'close 1' ; endif 104 | return str 105 | endif 106 | 107 | ********** nothing to do ********** 108 | if( flag = 'dummy' ) ; 'close 1' ; endif 109 | say 'nothing to do in strmem.gs' 110 | return -1 111 | 112 | 113 | 114 | ***** char -> integer ***** 115 | *function atoi( char ) 116 | * 117 | ** avoid bug in GrADS 1.9 or less ('e' and '+' are assumed to be same) 118 | * a='1'char'5' 119 | * if( a = 1e+5 ) ; return 101 ; endif 120 | * if( a = '1+5' ) ; return 43 ; endif 121 | * 122 | *if( char = a ) ; return 43 ; endif 123 | * if( char = 'e' ) ; return 101 ; endif 124 | * i = 32 125 | * while( i <= 126 ) 126 | * if( itoa(i) = char ) ; return i ; endif 127 | * i = i + 1 128 | * endwhile 129 | *return -1 130 | 131 | 132 | ***** integer -> char ***** 133 | *function itoa( int ) 134 | ** ascii character table 135 | * table = ' !"#$%&' 136 | * table = table % "'" 137 | * table = table % '()*+,-./0123456789:;<=>?@' 138 | * table = table % 'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`' 139 | * table = table % 'abcdefghijklmnopqrstuvwxyz{|}~' 140 | * 141 | * if( int >= 32 & int <= 126 ) 142 | * return substr( table, int-31, 1 ) 143 | * endif 144 | *return -1 145 | -------------------------------------------------------------------------------- /strrep.gsf: -------------------------------------------------------------------------------- 1 | function strrep( str, org, rep ) 2 | ret = '' 3 | l_str = math_strlen( str ) 4 | l_org = math_strlen( org ) 5 | 6 | i = 1 7 | while( i <= l_str ) 8 | tmp = substr( str, i, l_org ) 9 | if( tmp = org ) 10 | ret = ret % rep 11 | i = i + l_org 12 | continue 13 | endif 14 | c = substr( str, i, 1 ) 15 | ret = ret % c 16 | i = i + 1 17 | endwhile 18 | 19 | return ret 20 | -------------------------------------------------------------------------------- /strtrim.gsf: -------------------------------------------------------------------------------- 1 | function strtrim( str, opt ) 2 | if( opt != 'l' & opt != 'r' ) ; opt = '' ; endif 3 | ret = str 4 | 5 | * trim right 6 | if( opt = 'r' | opt = '' ) 7 | len = math_strlen( ret ) 8 | while( len > 0 ) 9 | c = substr( ret, len, 1 ) 10 | if( c != ' ' ) ; break ; endif 11 | ret = substr( ret, 1, len-1 ) 12 | len = len - 1 13 | endwhile 14 | endif 15 | 16 | * trim left 17 | if( opt = 'l' | opt = '' ) 18 | len = math_strlen( ret ) 19 | while( len > 0 ) 20 | c = substr( ret, 1, 1 ) 21 | if( c != ' ' ) ; break ; endif 22 | ret = substr( ret, 2, len-1 ) 23 | len = len - 1 24 | endwhile 25 | endif 26 | 27 | return ret 28 | -------------------------------------------------------------------------------- /sublw.gsf: -------------------------------------------------------------------------------- 1 | function sublw( str, lnum, wnum ) 2 | line = sublin( str, lnum ) 3 | ret = subwrd( line, wnum ) 4 | return ret 5 | -------------------------------------------------------------------------------- /t2time.gsf: -------------------------------------------------------------------------------- 1 | function t2time( t ) 2 | 'q dims' 3 | line = sublin( result, 5 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | t1 = subwrd( line, 11 ) 7 | t2 = subwrd( line, 13 ) 8 | else 9 | t1 = subwrd( line, 9 ) 10 | t2 = subwrd( line, 9 ) 11 | endif 12 | 'set t 't 13 | 'q dims' 14 | line = sublin( result, 5 ) 15 | time = subwrd( line, 6 ) 16 | 'set t 't1' 't2 17 | return time 18 | -------------------------------------------------------------------------------- /tbox.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function tbox( args ) 5 | _version = '0.01b2' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | sw = subwrd( args, 1 ) 14 | 15 | ********** start ********** 16 | if( sw = 'start' ) 17 | xstart = subwrd( args, 2 ) 18 | ystart = subwrd( args, 3 ) 19 | 20 | * start position 21 | rc = setstr( gstboxxstart, xstart ) 22 | rc = setstr( gstboxystart, ystart ) 23 | 24 | * current position 25 | x = xstart 26 | y = ystart 27 | rc = setstr( gstboxx, x ) 28 | rc = setstr( gstboxy, y ) 29 | endif 30 | 31 | ********** draw ********** 32 | if( sw = 'draw' ) 33 | * str = subwrd( args, 2 ) 34 | len = math_strlen( args ) 35 | str = substr( args, 6, len-5 ) 36 | * say '"' % args % '"' 37 | * say '"' % str % '"' 38 | 39 | x = getstr( gstboxx ) 40 | y = getstr( gstboxy ) 41 | 42 | 'draw string 'x' 'y' 'str 43 | 44 | 'q string 'str 45 | width = subwrd( result, 4 ) 46 | x = x + width 47 | rc = setstr( gstboxx, x ) 48 | endif 49 | 50 | ********** enter ********** 51 | if( sw = 'enter' ) 52 | yint = subwrd( args, 2 ) 53 | 54 | xstart = getstr( gstboxxstart ) 55 | y = getstr( gstboxy ) 56 | 57 | x = xstart 58 | y = y - yint 59 | rc = setstr( gstboxx, x ) 60 | rc = setstr( gstboxy, y ) 61 | endif 62 | 63 | return 64 | 65 | 66 | * 67 | * help 68 | * 69 | function help() 70 | say ' Name:' 71 | say ' tbox '_version' - draw string using text-box' 72 | say ' ' 73 | say ' Usage 1 (create text-box):' 74 | say ' tbox start xpos ypos ' 75 | say ' ' 76 | say ' Usage 2: (draw string)' 77 | say ' tbox draw string' 78 | say ' ' 79 | say ' Usage 3: (return)' 80 | say ' tbox enter yint' 81 | say '' 82 | say ' xpos, ypos : starting position' 83 | say ' string : string to draw' 84 | say ' yint : vertical interval' 85 | say '' 86 | say ' Copyright (C) 2010 Chihiro Kodama' 87 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 88 | say '' 89 | return 90 | -------------------------------------------------------------------------------- /template.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function template( args ) 5 | _version = '0.01r1' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | * 13 | * 14 | * scripts 15 | * 16 | * 17 | 18 | return 19 | 20 | 21 | 22 | * 23 | * help 24 | * 25 | function help() 26 | say ' Name:' 27 | say ' template '_version' - brief document' 28 | say ' ' 29 | say ' Usage:' 30 | say ' template size [-angle angle] [-base string-base]' 31 | say '' 32 | say ' size : tiny, small, normal, large or huge ' 33 | say ' -angle angle : string angle (0<=angle<360)' 34 | say ' -base string-base : string base (c, tl, bc, etc...), default=c' 35 | say '' 36 | say ' Necessary script(s):' 37 | say ' aaa.gs' 38 | say ' bbb.gs (if necessary)' 39 | say '' 40 | say ' Note:' 41 | say ' [arg-name] : specify if needed' 42 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 43 | say '' 44 | say ' Copyright (C) 2009-2011 Chihiro Kodama' 45 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 46 | say '' 47 | return 48 | -------------------------------------------------------------------------------- /tile.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script 3 | * 4 | function tile( args ) 5 | _version = '0.01b1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | ***** Default value ***** 14 | var = 'none' 15 | vmin = 'none' 16 | vmax = 'none' 17 | int = 9 18 | color = 1 19 | type = 5 20 | thickness = 3 21 | varmin = 'none' 22 | varmax = 'none' 23 | 24 | ***** Arguement ***** 25 | i = 1 26 | while( 1 ) 27 | arg = subwrd( args, i ) 28 | i = i + 1; 29 | if( arg = '' ); break; endif 30 | 31 | while( 1 ) 32 | *** option 33 | if( arg = '-min' ); vmin = subwrd(args,i); i=i+1; break; endif 34 | if( arg = '-max' ); vmax = subwrd(args,i); i=i+1; break; endif 35 | if( arg = '-int' ); int = subwrd(args,i); i=i+1; break; endif 36 | if( arg = '-color' ); color = subwrd(args,i); i=i+1; break; endif 37 | if( arg = '-type' ); type = subwrd(args,i); i=i+1; break; endif 38 | if( arg = '-thickness' ); thickness = subwrd(args,i); i=i+1; break; endif 39 | 40 | *** var, min, max 41 | if( var != 'none' & vmin != 'none' & vmax = 'none' & valnum(arg) != 0 ) 42 | vmax = arg 43 | break 44 | endif 45 | if( var != 'none' & vmin = 'none' & valnum(arg) != 0 ) 46 | vmin = arg 47 | break 48 | endif 49 | if( var = 'none' & valnum(arg) = 0 ) 50 | var = arg 51 | varmin = arg 52 | break 53 | endif 54 | if( varmax = 'none' & valnum(arg) = 0 ) 55 | varmax = arg 56 | break 57 | endif 58 | 59 | say 'syntax error : 'arg 60 | say 'type "tile" for help' 61 | return 62 | 63 | endwhile 64 | endwhile 65 | 66 | if( vmin = 'none' ); vmin = -1e+30; endif 67 | if( vmax = 'none' ); vmax = 1e+30; endif 68 | 69 | 'set tile 1 'type' 'int' 'int' 'thickness' 'color 70 | 'set rgb 16 tile 1' 71 | 72 | * for 1-D 73 | if( qdims( 'varying' ) = 1 ) 74 | 'set gxout linefill' 75 | 'set lfcols -1 16' 76 | 'd 'varmin';'varmax 77 | 78 | * for 2-D 79 | else 80 | 'set gxout shaded' 81 | 'set clevs 'vmin' 'vmax 82 | 'set ccols -1 16 -1' 83 | 'd 'var 84 | endif 85 | 86 | return 87 | 88 | 89 | * 90 | * help 91 | * 92 | function help() 93 | say ' Name:' 94 | say ' tile '_version' - Draw tile (hatch).' 95 | say '' 96 | say ' Usage:' 97 | say ' tile ( var ( min max | -min min | -max max ) | varmin varmax ) ' 98 | say ' [-type type] [-int int]' 99 | say ' [-color color] [-thickness thickness]' 100 | say '' 101 | say ' var : Variable.' 102 | say ' varmin,varmax : variable range (only for 1D chart)' 103 | say ' min,max : value range to be drawn (default: [-1e+30:1e+30])' 104 | say ' varmin,varmax : range of variable to be drawn (only for 1D chart)' 105 | say ' int : integer tile interval (default: 9)' 106 | say ' color : hatch color (default: 1)' 107 | say ' type : hatch line type (default: 5)' 108 | say ' thickness : hatch line thickness between 1-12 (default: 3)' 109 | say '' 110 | say ' Note:' 111 | say ' [arg-name] : specify if needed' 112 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 113 | say '' 114 | say ' Only for GrADS 2.1 or later.' 115 | say '' 116 | say ' Copyright (C) 2015-2015 Chihiro Kodama' 117 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 118 | say '' 119 | return 120 | -------------------------------------------------------------------------------- /time2t.gsf: -------------------------------------------------------------------------------- 1 | function time2t( time ) 2 | 'q dims' 3 | line = sublin( result, 5 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | t1 = subwrd( line, 11 ) 7 | t2 = subwrd( line, 13 ) 8 | else 9 | t1 = subwrd( line, 9 ) 10 | t2 = subwrd( line, 9 ) 11 | endif 12 | 'set time 'time 13 | 'q dims' 14 | line = sublin( result, 5 ) 15 | t = subwrd( line, 9 ) 16 | 'set t 't1' 't2 17 | return t 18 | -------------------------------------------------------------------------------- /time_avail.gsf: -------------------------------------------------------------------------------- 1 | * return ratio of availability 2 | * ret=0: totally not available 3 | * ret=1: totally available 4 | function time_avail( time_start, time_end ) 5 | ret = 0 6 | t_start = time2t( time_start ) 7 | t_end = time2t( time_end ) 8 | 9 | f = qdims( 'fnum' ) 10 | tdef = qctlinfo( f, 'tdef', 1 ) 11 | 12 | if( 1 <= t_start ) 13 | tmin = t_start 14 | else 15 | tmin = 1 16 | endif 17 | 18 | if( tdef >= t_end ) 19 | tmax = t_end 20 | else 21 | tmax = tdef 22 | endif 23 | 24 | ret = ( tmax - tmin + 1 ) / ( t_end - t_start + 1 ) 25 | return ret 26 | -------------------------------------------------------------------------------- /tsteps.gsf: -------------------------------------------------------------------------------- 1 | *return number of time steps within year/month. 2 | function tsteps( year, month ) 3 | rc = gsfallow( 'on' ) 4 | ypp = year + 1 5 | 6 | if( month = 'month' ) 7 | time1 = '00z01jan'year 8 | time2 = '00z01jan'ypp 9 | 10 | else 11 | cm = cmonth( month, 3 ) 12 | cmpp = cmonth( month+1, 3 ) 13 | time1 = '00z01'cm''year 14 | if( month = 12 ) 15 | time2 = '00z01'cmpp''ypp 16 | else 17 | time2 = '00z01'cmpp''year 18 | endif 19 | endif 20 | 21 | ret = time2t(time2) - time2t(time1) 22 | return ret 23 | -------------------------------------------------------------------------------- /v2s.gsf: -------------------------------------------------------------------------------- 1 | function v2s( var ) 2 | rc = gsfallow( 'on' ) 3 | pre = qgxout( '2d-1expr' ) 4 | if( pre = 'Fwrite' ) 5 | 'set gxout contour' 6 | endif 7 | 'd 'var 8 | check.1 = subwrd( result, 1 ) 9 | check.2 = subwrd( result, 2 ) 10 | if( check.1 = 'Result' & check.2 = 'value' ) 11 | value = subwrd( result, 4 ) 12 | else 13 | value = 'error: var does not seem to be a single value.' 14 | endif 15 | if( pre = 'Fwrite' ) 16 | 'set gxout 'pre 17 | endif 18 | return value 19 | end function 20 | -------------------------------------------------------------------------------- /x2lon.gsf: -------------------------------------------------------------------------------- 1 | function x2lon( x ) 2 | 'q dims' 3 | line = sublin( result, 2 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | x1 = subwrd( line, 11 ) 7 | x2 = subwrd( line, 13 ) 8 | else 9 | x1 = subwrd( line, 9 ) 10 | x2 = subwrd( line, 9 ) 11 | endif 12 | 'set x 'x 13 | 'q dims' 14 | line = sublin( result, 2 ) 15 | lon = subwrd( line, 6 ) 16 | 'set x 'x1' 'x2 17 | return lon 18 | -------------------------------------------------------------------------------- /xcbar.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function xcbar( args ) 5 | _version = '0.09r1' 6 | rc = gsfallow( 'on' ) 7 | 8 | if( args = '' ) 9 | help() 10 | * return 11 | endif 12 | 13 | ***** Default value ***** 14 | xmin = 'none' 15 | xmax = 'none' 16 | ymin = 'none' 17 | ymax = 'none' 18 | direction = 'none' 19 | line = 'on' 20 | caption = '' 21 | 22 | cnum = -1 23 | fxoffset = 0 24 | fyoffset = 0 25 | xoffset = 0 26 | yoffset = 0 27 | fformat = '' 28 | 29 | ***** Arguement ***** 30 | i = 1 31 | arg = 'dummy' 32 | while( 1 ) 33 | arg = subwrd( args, i ) 34 | i = i + 1 35 | if( arg = '' ); break; endif 36 | 37 | while( 1 ) 38 | if( arg = '-caption' | arg = '-c' ) 39 | caption = subwrd( args, i ) 40 | i = i + 1 41 | while ( 1 ) 42 | tmp = subwrd( args, i ) 43 | if( tmp = '' ) ; break ; endif 44 | caption = caption % ' ' % tmp 45 | i = i + 1 46 | endwhile 47 | break 48 | endif 49 | if( arg = '-direction' | arg = '-dir' | arg = '-d' ) 50 | direction = subwrd( args, i ) 51 | if( direction = 'h' ); direction = 'horizontal'; endif 52 | if( direction = 'v' ); direction = 'vertical'; endif 53 | i = i + 1 54 | break 55 | endif 56 | if( arg = '-edge' ) 57 | edge = subwrd( args, i ) 58 | i = i + 1 59 | break 60 | endif 61 | if( arg = '-fwidth' | arg = '-fw' ) 62 | fwidth = subwrd( args, i ) 63 | i = i + 1 64 | break 65 | endif 66 | if( arg = '-fheight' | arg = '-fh' ) 67 | fheight = subwrd( args, i ) 68 | i = i + 1 69 | break 70 | endif 71 | if( arg = '-fthickness' | arg = '-ft' ) 72 | fthickness = subwrd( args, i ) 73 | i = i + 1 74 | break 75 | endif 76 | if( arg = '-fskip' | arg = '-fstep' | arg = '-fs' ) 77 | fstep = subwrd( args, i ) 78 | i = i + 1 79 | break 80 | endif 81 | if( arg = '-foffset' | arg = '-fo' ) 82 | foffset = subwrd( args, i ) 83 | i = i + 1 84 | break 85 | endif 86 | if( arg = '-fcolor' | arg = '-fc' ) 87 | fcolor = subwrd( args, i ) 88 | i = i + 1 89 | break 90 | endif 91 | if( arg = '-fxoffset' | arg = '-fx' ) 92 | fxoffset = subwrd( args, i ) 93 | i = i + 1 94 | break 95 | endif 96 | if( arg = '-fyoffset' | arg = '-fy' ) 97 | fyoffset = subwrd( args, i ) 98 | i = i + 1 99 | break 100 | endif 101 | if( arg = '-fformat' | arg = '-ffmt' ) 102 | fformat = subwrd( args, i ) 103 | i = i + 1 104 | break 105 | endif 106 | if( arg = '-line' ) 107 | tmp = subwrd( args, i ) 108 | if( tmp = 'on' | tmp = 'off' ) 109 | line = tmp 110 | i = i + 1 111 | else 112 | line = 'on' 113 | endif 114 | break 115 | endif 116 | if( arg = '-linecolor' | arg = '-lc' ) 117 | linecolor = subwrd( args, i ) 118 | i = i + 1 119 | break 120 | endif 121 | if( arg = '-levcol' ) 122 | * color(1) level(1) color(2) level(2) ... level(cnum-1) color(cnum) 123 | cnum = 1 124 | while( 1 ) 125 | col.cnum = subwrd( args, i ) 126 | if( valnum(col.cnum) = 0 ) 127 | say 'Error in xcbar.gs: Syntax error in -levcol' 128 | return 129 | endif 130 | i = i + 1 131 | hi.cnum = subwrd( args, i ) 132 | if( valnum(hi.cnum) = 0 ); break; endif 133 | cnum = cnum + 1 134 | i = i + 1 135 | endwhile 136 | break 137 | endif 138 | if( arg = '-xoffset' | arg = '-xo' ) 139 | xoffset = subwrd( args, i ) 140 | i = i + 1 141 | break 142 | endif 143 | if( arg = '-yoffset' | arg = '-yo' ) 144 | yoffset = subwrd( args, i ) 145 | i = i + 1 146 | break 147 | endif 148 | if( valnum(arg) != 0 & xmin = 'none' ) 149 | xmin = arg 150 | break 151 | endif 152 | if( valnum(arg) != 0 & xmax = 'none' ) 153 | xmax = arg 154 | break 155 | endif 156 | if( valnum(arg) != 0 & ymin = 'none' ) 157 | ymin = arg 158 | break 159 | endif 160 | if( valnum(arg) != 0 & ymax = 'none' ) 161 | ymax = arg 162 | break 163 | endif 164 | say 'syntax error: 'arg 165 | return 166 | endwhile 167 | endwhile 168 | 169 | 170 | *** get shade information *** 171 | if( cnum = -1 ) 172 | 'q shades' 173 | shdinfo = result 174 | if ( subwrd( shdinfo, 1 ) = 'None' ) 175 | say 'Error in xcbar.gs: No shading information' 176 | return 177 | endif 178 | 179 | * number of colors 180 | cnum = subwrd( shdinfo, 5 ) 181 | if( cnum <= 0 ) 182 | say 'Error in xcbar.gs: Number of color is zero' 183 | return 184 | endif 185 | 186 | * color and (higher) levels 187 | i = 1 188 | while( i <= cnum ) 189 | rec = sublin( shdinfo, i+1 ) 190 | col.i = subwrd( rec, 1 ) 191 | hi.i = subwrd( rec, 3 ) 192 | i = i + 1 193 | endwhile 194 | 195 | endif 196 | 197 | 198 | *** determine xmin, xmax, ymin, ymax if necessary *** 199 | ** ( following cbar.gs ) 200 | if( xmin = 'none' | xmax = 'none' | ymin = 'none' | ymax = 'none' ) 201 | * 'q gxinfo' 202 | * sline = sublin( result, 2 ) 203 | * xsize = subwrd( sline, 4 ) 204 | * ysize = subwrd( sline, 6 ) 205 | * xline = sublin( result, 3 ) 206 | * yline = sublin( result, 4 ) 207 | * xlmin = subwrd( xline, 4 ) 208 | * xlmax = subwrd( xline, 6 ) 209 | * xlwid = xlmax - xlmin 210 | * ylmin = subwrd( yline, 4 ) 211 | * ylmax = subwrd( yline, 6 ) 212 | * ylwid = ylmax - ylmin 213 | * 214 | ** vertical 215 | * if( ylmin < 0.6 | xsize-xlmax > 1.5 ) 216 | * direction = 'vertical' 217 | * xmin = xlmax + ( xsize - xlmax ) / 2 - 0.4 218 | * xmax = xmin + 0.2 219 | * 220 | * y1wid = 0.5 221 | * if ( y1wid * cnum > ysize * 0.8 ) 222 | * y1wid = ysize * 0.8 / cnum 223 | * endif 224 | * ymin = ysize / 2 - y1wid * cnum / 2 225 | * ymax = ysize / 2 + y1wid * cnum / 2 226 | * 227 | ** horizontal 228 | * else 229 | * direction = 'horizontal' 230 | * ymin = ylmin / 2 231 | * ymax = ymin + 0.2 232 | * 233 | * x1wid = 0.8 234 | * if ( x1wid * cnum > xsize * 0.8 ) 235 | * x1wid = xsize * 0.8 / cnum 236 | * endif 237 | * xmin = xsize / 2 - x1wid * cnum / 2 238 | * xmax = xsize / 2 + x1wid * cnum / 2 239 | * 240 | * endif 241 | 242 | 'q gxinfo' 243 | sline = sublin( result, 2 ) 244 | xsize = subwrd( sline, 4 ) 245 | ysize = subwrd( sline, 6 ) 246 | 247 | xline = sublin( result, 3 ) 248 | yline = sublin( result, 4 ) 249 | xlmin = subwrd( xline, 4 ) 250 | xlmax = subwrd( xline, 6 ) 251 | xlwid = xlmax - xlmin 252 | ylmin = subwrd( yline, 4 ) 253 | ylmax = subwrd( yline, 6 ) 254 | ylwid = ylmax - ylmin 255 | 256 | * vertical 257 | if( ( ylmin < 0.6 | xsize-xlmax > 1.5 ) & direction != 'horizontal' ) 258 | direction = 'vertical' 259 | dx = xlwid / 30 260 | 261 | xmin = xlmax + 0.2 262 | xmax = xmin + dx 263 | 264 | ymin = ylmin 265 | ymax = ylmax 266 | 267 | * horizontal 268 | else 269 | direction = 'horizontal' 270 | 271 | dy = ylwid / 20 272 | ymax = ylmin - 0.3 273 | ymin = ymax - dy 274 | 275 | xmin = xlmin 276 | xmax = xlmax 277 | 278 | endif 279 | endif 280 | 281 | xmin = xmin + xoffset 282 | xmax = xmax + xoffset 283 | xmid = ( xmax + xmin ) / 2 284 | ymin = ymin + yoffset 285 | ymax = ymax + yoffset 286 | ymid = ( ymax + ymin ) / 2 287 | 288 | *** determine direction if necessary *** 289 | if( direction != 'horizontal' & direction != 'vertical' ) 290 | if( xmax - xmin >= ymax - ymin ) 291 | direction = 'horizontal' 292 | else 293 | direction = 'vertical' 294 | endif 295 | endif 296 | if( direction = 'horizontal' ) 297 | xdir = 1 298 | ydir = 0 299 | else 300 | xdir = 0 301 | ydir = 1 302 | endif 303 | 304 | *** other default value ***** 305 | if( edge != 'box' & edge != 'triangle' & edge != 'circle' ) 306 | edge = 'box' 307 | endif 308 | 309 | if( valnum(fwidth) = 0 ) 310 | fwidth = 0.12 311 | endif 312 | 313 | if( valnum(fheight) = 0 ) 314 | fheight = 0.13 315 | endif 316 | 317 | if( valnum(fthickness) = 0 ) 318 | fthickness = fheight * 40 319 | endif 320 | 321 | if( valnum(fstep) = 0 ) 322 | fstep = 1 323 | endif 324 | 325 | if( foffset = 'center' ) 326 | if( math_fmod(cnum,2) = 0 ) 327 | foffset = math_fmod( cnum / 2 - 1, fstep ) 328 | else 329 | foffset = math_fmod( (cnum+1) / 2 - 1, fstep ) 330 | endif 331 | * say foffset 332 | endif 333 | if( valnum(foffset) = 0 ) 334 | foffset = 0 335 | * foffset = fstep - 1 336 | endif 337 | 338 | if( valnum(fcolor) = 0 ) 339 | fcolor = 1 340 | endif 341 | 342 | if( line != 'on' & line != 'off' ) 343 | line = 'off' 344 | endif 345 | 346 | if( valnum(linecolor) = 0 ) 347 | linecolor = 1 348 | endif 349 | 350 | 351 | *** get other constant *** 352 | 353 | * width of color bar 354 | xdif = xdir * (xmax-xmin) / cnum 355 | ydif = ydir * (ymax-ymin) / cnum 356 | 357 | 358 | *** draw *** 359 | i = 1 360 | x1 = xmin - xdif 361 | x2 = xmin * xdir + xmax * ydir 362 | y1 = ymin - ydif 363 | y2 = ymin * ydir + ymax * xdir 364 | 365 | maxstr = 0 366 | while( i <= cnum ) 367 | x1 = x1 + xdif 368 | x2 = x2 + xdif 369 | y1 = y1 + ydif 370 | y2 = y2 + ydif 371 | xmoji = x2 + ( 0.5 * fwidth ) * ydir + fxoffset 372 | ymoji = ( y1 - 0.5 * fheight ) * xdir + y2 * ydir + fyoffset 373 | 374 | 'set line 'col.i 375 | 'set strsiz 'fwidth' 'fheight 376 | 377 | *** draw color bar *** 378 | if( edge = 'box' ) 379 | 'draw recf 'x1' 'y1' 'x2' 'y2 380 | if( line = 'on' ) ; drawrec( linecolor, x1, y1, x2, y2 ) ; endif 381 | endif 382 | 383 | if( edge = 'triangle' ) 384 | if( i != 1 & i != cnum ) 385 | 'draw recf 'x1' 'y1' 'x2' 'y2 386 | if( line = 'on' ) ; drawrec( linecolor, x1, y1, x2, y2 ) ; endif 387 | endif 388 | 389 | if( direction = 'horizontal' ) 390 | if( i = 1 ) 391 | ymed = 0.5 * ( y1 + y2 ) 392 | poly = x1' 'ymed' 'x2' 'y1' 'x2' 'y2 393 | 'draw polyf 'poly 394 | if( line = 'on' ) ; drawpoly( linecolor' 'poly ) ; endif 395 | endif 396 | if( i = cnum ) 397 | ymed = 0.5 * ( y1 + y2 ) 398 | poly = x1' 'y1' 'x1' 'y2' 'x2' 'ymed 399 | 'draw polyf 'poly 400 | if( line = 'on' ) ; drawpoly( linecolor' 'poly ) ; endif 401 | endif 402 | endif 403 | if( direction = 'vertical' ) 404 | if( i = 1 ) 405 | xmed = 0.5 * ( x1 + x2 ) 406 | poly = xmed' 'y1' 'x1' 'y2' 'x2' 'y2 407 | 'draw polyf 'poly 408 | if( line = 'on' ) ; drawpoly( linecolor' 'poly ) ; endif 409 | endif 410 | if( i = cnum ) 411 | xmed = 0.5 * ( x1 + x2 ) 412 | poly = x1' 'y1' 'x2' 'y1' 'xmed' 'y2 413 | 'draw polyf 'poly 414 | if( line = 'on' ) ; drawpoly( linecolor' 'poly ) ; endif 415 | endif 416 | endif 417 | endif 418 | * end of triangle 419 | 420 | 421 | if( edge = 'circle' ) 422 | if( i != 1 & i != cnum ) 423 | 'draw recf 'x1' 'y1' 'x2' 'y2 424 | if( line = 'on' ) ; drawrec( linecolor, x1, y1, x2, y2 ) ; endif 425 | endif 426 | 427 | if( direction = 'horizontal' ) 428 | if( i = 1 ) 429 | xc = x1 + ( y2 - y1 ) 430 | yc = y1 + 0.5 * ( y2 - y1 ) 431 | radius = 0.5 * ( y2 - y1 ) 432 | if( xc < x2 ) 433 | 'draw recf 'xc' 'y1' 'x2' 'y2 434 | else 435 | xc = x2 436 | endif 437 | circle = circle( xc, yc, radius, 90, 270, 6 ) 438 | 'draw polyf 'circle 439 | if( line = 'on' ) ; drawpoly( linecolor' 'x2' 'y2' 'circle' 'x2' 'y1 ) ; endif 440 | endif 441 | if( i = cnum ) 442 | xc = x2 - ( y2 - y1 ) 443 | yc = y1 + 0.5 * ( y2 - y1 ) 444 | radius = 0.5 * ( y2 - y1 ) 445 | if( x1 < xc ) 446 | 'draw recf 'x1' 'y1' 'xc' 'y2 447 | else 448 | xc = x1 449 | endif 450 | circle = circle( xc, yc, radius, 270, 450, 6 ) 451 | 'draw polyf 'circle 452 | if( line = 'on' ) ; drawpoly( linecolor' 'x1' 'y1' 'circle' 'x1' 'y2) ; endif 453 | endif 454 | endif 455 | 456 | if( direction = 'vertical' ) 457 | if( i = 1 ) 458 | xc = x1 + 0.5 * ( x2 - x1 ) 459 | yc = y1 + 0.5 * ( x2 - x1 ) 460 | radius = 0.5 * ( x2 - x1 ) 461 | if( yc < y2 ) 462 | 'draw recf 'x1' 'yc' 'x2' 'y2 463 | else 464 | yc = y2 465 | endif 466 | circle = circle( xc, yc, radius, 180, 360, 6 ) 467 | 'draw polyf 'circle 468 | if( line = 'on' ) ; drawpoly( linecolor' 'x1' 'y2' 'circle' 'x2' 'y2 ) ; endif 469 | endif 470 | if( i = cnum ) 471 | xc = x1 + 0.5 * ( x2 - x1 ) 472 | yc = y2 - 0.5 * ( x2 - x1 ) 473 | radius = 0.5 * ( x2 - x1 ) 474 | if( y1 < yc ) 475 | 'draw recf 'x1' 'y1' 'x2' 'yc 476 | else 477 | yc = y1 478 | endif 479 | circle = circle( xc, yc, radius, 0, 180, 6 ) 480 | 'draw polyf 'circle 481 | if( line = 'on' ) ; drawpoly( linecolor' 'x2' 'y1' 'circle' 'x1' 'y1 ) ; endif 482 | endif 483 | endif 484 | endif 485 | * end of circle 486 | 487 | 488 | * draw labels 489 | if( i != cnum & i-foffset > 0 & math_int((i-1-foffset)/fstep)*fstep = i-1-foffset ) 490 | if( direction = 'horizontal' ) 491 | 'set string 'fcolor' tc 'fthickness' 0' 492 | else 493 | 'set string 'fcolor' l 'fthickness' 0' 494 | endif 495 | str = hi.i 496 | if( fformat != '' ) 497 | str = math_format( fformat, hi.i ) 498 | endif 499 | 'draw string 'xmoji' 'ymoji' 'str 500 | endif 501 | 502 | if( math_strlen(str) > maxstr ) 503 | maxstr = math_strlen(str) 504 | endif 505 | 506 | i = i + 1 507 | endwhile 508 | 509 | * caption = 'Temperature [K]' 510 | if( caption != '' ) 511 | 512 | 'set strsiz 'fwidth*1.2' 'fheight*1.2 513 | if( direction = 'horizontal' ) 514 | 'set string 'fcolor' tc 'fthickness' 0' 515 | * 'draw string 'xmid' 'ymin-fheight-0.2' 'str2 516 | 'draw string 'xmid' 'ymin-fheight*2' 'caption 517 | else 518 | 'set string 'fcolor' tc 'fthickness' 90' 519 | 'draw string 'xmax+fwidth*(2+maxstr)' 'ymid' 'caption 520 | endif 521 | endif 522 | 523 | return 524 | 525 | 526 | 527 | * 528 | * angle = 0 : x(+) direction 529 | * angle = 90 : y(+) direction 530 | * 531 | function circle( xc, yc, radius, amin, amax, astep ) 532 | circle = '' 533 | 534 | angle = amin 535 | while( angle <= amax ) 536 | x = xc + radius * math_cos( angle * 3.14 / 180.0 ) 537 | y = yc + radius * math_sin( angle * 3.14 / 180.0 ) 538 | circle = circle % x % ' ' % y % ' ' 539 | angle = angle + astep 540 | endwhile 541 | 542 | return ( circle ) 543 | 544 | 545 | 546 | function drawrec( linecolor, xmin, ymin, xmax, ymax ) 547 | drawpoly( linecolor' 'xmin' 'ymin' 'xmin' 'ymax' 'xmax' 'ymax' 'xmax' 'ymin ) 548 | return 549 | 550 | 551 | 552 | function drawpoly( args ) 553 | linecolor = subwrd( args, 1 ) 554 | xstart = subwrd( args, 2 ) 555 | ystart = subwrd( args, 3 ) 556 | 557 | xmin = xstart 558 | ymin = ystart 559 | 560 | i = 4 561 | while( 1 = 1 ) 562 | xmax = subwrd( args, i ) 563 | ymax = subwrd( args, i+1 ) 564 | if( xmax = '' | ymax = '' ) ; break ; endif 565 | 566 | 'set cthick 1' 567 | 'set line 'linecolor 568 | 'draw line 'xmin' 'ymin' 'xmax' 'ymax 569 | 570 | xmin = xmax 571 | ymin = ymax 572 | i = i + 2 573 | endwhile 574 | 575 | 'set cthick 1' 576 | 'set line 'linecolor 577 | 'draw line 'xmin' 'ymin' 'xstart' 'ystart 578 | return 579 | 580 | * 581 | * help 582 | * 583 | function help() 584 | say ' Name:' 585 | say ' xcbar '_version' - Draw color bar at any position and size.' 586 | say ' ' 587 | say ' Usage:' 588 | say ' xcbar [ xmin xmax ymin ymax ]' 589 | say ' [ ( -xoffset | -xo ) xoffset ] [ ( -yoffset | -yo ) yoffset ]' 590 | say ' [ ( -fwidth | -fw ) fwidth ]' 591 | say ' [ ( -fheight | -fh ) hfeight ]' 592 | say ' [ ( -fthickness | -ft ) fthickness ]' 593 | say ' [ ( -fskip | -fstep | -fs ) fskip ]' 594 | say ' [ ( -foffset | -fo ) ( foffset | center ) ]' 595 | say ' [ ( -fcolor | -fc ) fcolor ]' 596 | say ' [ ( -fxoffset | -fx ) fxoffset ] [ ( -fyoffset | -fy ) fyoffset ]' 597 | say ' [ ( -fformat | -ffmt ) fformat ]' 598 | say ' [ ( -direction | -dir ) ( horizontal | h | vertical | v ) ]' 599 | say ' [ -edge ( box | triangle | circle ) ]' 600 | say ' [ -line [ on | off ] ]' 601 | say ' [ -levcol c(1) l(1) c(2) level(2) ... l(cnum-1) c(cnum) ]' 602 | say ' [ ( -caption | -c ) caption... ]' 603 | say '' 604 | say ' xmin : color bar position (left side)' 605 | say ' xmax : color bar position (right side)' 606 | say ' ymin : color bar position (bottom side)' 607 | say ' ymax : color bar position (top side)' 608 | say ' without xmin, xmax, ymin or ymax, ' 609 | say ' position will be determined automatically' 610 | say ' following cbar.gs manner.' 611 | say ' xoffset : x-position offset (default=0)' 612 | say ' yoffset : y-position offset (default=0)' 613 | say ' fwidth : font width (default=0.12)' 614 | say ' fheight : font height (default=0.13)' 615 | say ' fthickness : font thickness (default=fheight*40)' 616 | say ' fskip : label interval (default=1)' 617 | say ' foffset : label offset for fstep (default=0)' 618 | say ' to put labels at the center, specify "center".' 619 | say ' fcolor : label color number (default=1)' 620 | say ' fxoffset : x-direction offset for a label (default=0)' 621 | say ' fyoffset : y-direction offset for a label (default=0)' 622 | say ' fformat : font format (e.g. %5.2e, %.2f' 623 | say ' -direction : horizontal ("h" in short) or vertical ("v" in short)' 624 | say ' color bar (default=auto)' 625 | say ' -edge : shape of edge (default=box)' 626 | say ' -line : lines between each color box. (default="on")' 627 | say ' -levcol : color of lines between each color box (default=1)' 628 | say ' c(1) l(1) c(2) level(2) ... l(cnum-1) c(cnum)' 629 | say ' : color numbers and levels. By using this option,' 630 | say ' you can draw color bar without drawing figure' 631 | say '' 632 | say ' Note:' 633 | say ' [arg-name] : specify if needed' 634 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 635 | say '' 636 | say ' xcbar is based on cbar.gs' 637 | say '' 638 | say ' Copyright (C) 2011-2021 Chihiro Kodama' 639 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 640 | say '' 641 | return 642 | -------------------------------------------------------------------------------- /xmath_max.gsf: -------------------------------------------------------------------------------- 1 | function xmath_max( v1, v2 ) 2 | if( v1 > v2 ) ; return v1 ; endif 3 | return v2 4 | -------------------------------------------------------------------------------- /xmath_min.gsf: -------------------------------------------------------------------------------- 1 | function xmath_min( v1, v2 ) 2 | if( v1 > v2 ) ; return v2 ; endif 3 | return v1 4 | -------------------------------------------------------------------------------- /xmath_random.gsf: -------------------------------------------------------------------------------- 1 | * num: number of random number 2 | * (optional) seed: seed of random number (seed>0) 3 | * ret: list of random number from 0 to 32767 4 | * 5 | * temporary file (.tmp_xmath_random.txt) is created 6 | * only for bash environment 7 | * 8 | function xmath_random( num, seed ) 9 | ret = '' 10 | tmp_file = '.tmp_xmath_random.txt' 11 | 12 | buff = read( tmp_file ) 13 | status = sublin( buff, 1 ) 14 | if( status = 0 ) 15 | say 'error in xmath_random.gsf: ' % tmp_file % ' exists.' 16 | exit 17 | endif 18 | 19 | str = '!' 20 | if( valnum(seed) = 1 ) 21 | str = str % 'export RANDOM=' % seed % ' ; ' 22 | endif 23 | 24 | i = 1 25 | while( i <= num ) 26 | str = str % 'echo ${RANDOM} >> ' % tmp_file % ' ; ' 27 | i = i + 1 28 | endwhile 29 | str 30 | 31 | i = 1 32 | while( i <= num ) 33 | buff = read( tmp_file ) 34 | ret = ret % sublin( buff, 2 ) % ' ' 35 | i = i + 1 36 | endwhile 37 | 38 | '!rm ' % tmp_file 39 | return ret 40 | -------------------------------------------------------------------------------- /xopen.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function xopen( args ) 5 | rc = gsfallow( 'on' ) 6 | _version = '0.01r1' 7 | 8 | if( args = '' ) 9 | help() 10 | return 11 | endif 12 | 13 | *** arguements *** 14 | show_type = 0 15 | arg.1 = subwrd( args, 1 ) 16 | arg.2 = subwrd( args, 2 ) 17 | if( arg.1 = '-t' | arg.2 = '-t' ) 18 | show_type = 1 19 | if( arg.1 = '-t' ) ; fname = arg.2 ; endif 20 | if( arg.2 = '-t' ) ; fname = arg.1 ; endif 21 | else 22 | fname = arg.1 23 | endif 24 | 25 | *** get extension *** 26 | length = strlen( fname ) 27 | ext2 = substr( fname, length-2, 3 ) 28 | ext3 = substr( fname, length-3, 4 ) 29 | 30 | cmd = '' 31 | 32 | *** open with sdfopen if appropriate *** 33 | if( ext2 = '.nc' | ext3 = '.nc4' ) 34 | cmd = 'sdfopen' 35 | endif 36 | 37 | *** open with open/xdfopen *** 38 | if( cmd = '' ) 39 | if( ext3 != '.ctl' ) 40 | fname = fname % '.ctl' 41 | ext3 = '.ctl' 42 | endif 43 | 44 | file_type = 'grd' 45 | while( 1 = 1 ) 46 | ret = read( fname ) 47 | line1 = sublin( ret, 1 ) 48 | line2 = sublin( ret, 2 ) 49 | if( line1 != 0 ) ; break ; endif 50 | 51 | wrd1 = subwrd( line2, 1 ) 52 | wrd1 = chcase( wrd1, 'upper' ) 53 | wrd2 = subwrd( line2, 2 ) 54 | if( wrd1 = 'DSET' ) 55 | length_tmp = strlen( wrd2 ) 56 | ext2_tmp = substr( wrd2, length_tmp-2, 3 ) 57 | ext3_tmp = substr( wrd2, length_tmp-3, 4 ) 58 | if( ext2_tmp = '.nc' | ext3_tmp = '.nc4' ) 59 | file_type = 'nc' 60 | break 61 | endif 62 | endif 63 | endwhile 64 | 65 | if( file_type = 'grd' ) 66 | cmd = 'open' 67 | else 68 | cmd = 'xdfopen' 69 | endif 70 | endif 71 | 72 | if( show_type = 1 ) ; say 'using 'cmd; endif 73 | cmd' 'fname 74 | prompt result 75 | 76 | return 77 | 78 | 79 | * 80 | * help 81 | * 82 | function help() 83 | say ' Name:' 84 | say ' xopen '_version' - Automatically choose appropriate open command (open/sdfopen/xdfopen)' 85 | say ' ' 86 | say ' Usage:' 87 | say ' open [-t] file-name' 88 | say '' 89 | say ' file-name : filename' 90 | say ' (ex. test.ctl, test.nc, test)' 91 | say ' -t : show command to open.' 92 | say '' 93 | say ' Note:' 94 | say ' [arg-name] : specify if needed' 95 | say ' (arg1 | arg2) : arg1 or arg2 must be specified' 96 | say ' This function depends on chcase.gsf.' 97 | say '' 98 | say ' Copyright (C) 2012-2015 Chihiro Kodama' 99 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 100 | say '' 101 | return 102 | -------------------------------------------------------------------------------- /y2lat.gsf: -------------------------------------------------------------------------------- 1 | function y2lat( y ) 2 | 'q dims' 3 | line = sublin( result, 3 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | y1 = subwrd( line, 11 ) 7 | y2 = subwrd( line, 13 ) 8 | else 9 | y1 = subwrd( line, 9 ) 10 | y2 = subwrd( line, 9 ) 11 | endif 12 | 'set y 'y 13 | 'q dims' 14 | line = sublin( result, 3 ) 15 | lat = subwrd( line, 6 ) 16 | 'set y 'y1' 'y2 17 | return lat 18 | -------------------------------------------------------------------------------- /z2lev.gsf: -------------------------------------------------------------------------------- 1 | function z2lev( z ) 2 | 'q dims' 3 | line = sublin( result, 4 ) 4 | type = subwrd( line, 3 ) 5 | if( type = 'varying' ) 6 | z1 = subwrd( line, 11 ) 7 | z2 = subwrd( line, 13 ) 8 | else 9 | z1 = subwrd( line, 9 ) 10 | z2 = subwrd( line, 9 ) 11 | endif 12 | 'set z 'z 13 | 'q dims' 14 | line = sublin( result, 4 ) 15 | lev = subwrd( line, 6 ) 16 | 'set z 'z1' 'z2 17 | return lev 18 | -------------------------------------------------------------------------------- /zero.gs: -------------------------------------------------------------------------------- 1 | * 2 | * Help is in the end of this script. 3 | * 4 | function zero( args ) 5 | _version='0.01r2' 6 | 7 | if( args = '' ) 8 | help() 9 | return 10 | endif 11 | 12 | var = subwrd( args, 1 ) 13 | 14 | 'set gxout contour' 15 | 'set clevs 0' 16 | 'd 'var 17 | 18 | return 19 | 20 | * 21 | * help 22 | * 23 | function help() 24 | say ' Name:' 25 | say ' zero '_version' - draw zero-line' 26 | say ' ' 27 | say ' Usage:' 28 | say ' zero var' 29 | say ' var : variable' 30 | say '' 31 | say ' Copyright (C) 2009 Chihiro Kodama' 32 | say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)' 33 | say '' 34 | return 35 | --------------------------------------------------------------------------------