special_symbol.F 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. SUBROUTINE SPECIAL_SYMBOL( isym, name, value, slen )
  2. * This software was developed by the Thermal Modeling and Analysis
  3. * Project(TMAP) of the National Oceanographic and Atmospheric
  4. * Administration's (NOAA) Pacific Marine Environmental Lab(PMEL),
  5. * hereafter referred to as NOAA/PMEL/TMAP.
  6. *
  7. * Access and use of this software shall impose the following
  8. * obligations and understandings on the user. The user is granted the
  9. * right, without any fee or cost, to use, copy, modify, alter, enhance
  10. * and distribute this software, and any derivative works thereof, and
  11. * its supporting documentation for any purpose whatsoever, provided
  12. * that this entire notice appears in all copies of the software,
  13. * derivative works and supporting documentation. Further, the user
  14. * agrees to credit NOAA/PMEL/TMAP in any publications that result from
  15. * the use of this software or in any product that includes this
  16. * software. The names TMAP, NOAA and/or PMEL, however, may not be used
  17. * in any advertising or publicity to endorse or promote any products
  18. * or commercial entity unless specific written permission is obtained
  19. * from NOAA/PMEL/TMAP. The user also understands that NOAA/PMEL/TMAP
  20. * is not obligated to provide the user with any support, consulting,
  21. * training or assistance of any kind with regard to the use, operation
  22. * and performance of this software nor to provide the user with any
  23. * updates, revisions, new versions or "bug fixes".
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY NOAA/PMEL/TMAP "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  27. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL NOAA/PMEL/TMAP BE LIABLE FOR ANY SPECIAL,
  29. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  30. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  31. * CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN
  32. * CONNECTION WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
  33. *
  34. * this routine is 2-in-1 to handle "special" (internally defined) symbols
  35. * it acts like an encapsulated special symbol "object" (FORTRAN ...)
  36. * if isym=0 on input then this is a request to translate the passed "name"
  37. * if the given name is the name of a special symbol return its definition
  38. * in value and its length in slen. Else return slen=0
  39. * if slen is a positive integer then return the name of that symbol
  40. * or a blank name if the integer is larger than the number of symbols
  41. * programmer - steve hankin
  42. * NOAA/PMEL, Seattle, WA - Tropical Modeling and Analysis Program
  43. * V522 7/00 *sh* - extracted from symbol_command.F
  44. * V530 8/00 *sh* - bug (feature) fix so that SHOW SYM doesn't eveluate
  45. * PPL$XPIXEL
  46. * 12/00 *sh* - added symbols SESSION_DATE and SESSION_TIME
  47. * 10/01 *kob*- add symbol FERRET_PLATFORM to display the platform
  48. * the executable was built on.
  49. * 8/05 *acm*- Allow more digits in xrevision number
  50. * V62 4/09 *acm*- Add new symbol DELTA_CPU. When it is evaluated,
  51. * calls the intrinsic fcn Dtime and sets the value to that new
  52. * delta-time since the last call. Initialized in initizlize.F
  53. * V62 4/09 *acm*- Add new symbol CLOCK_SECS. When it is evaluated, calls the
  54. * intrinsic SYSTEM_CLOCK and sets the value to the delta-time
  55. * in seconds since Ferret was initialized.
  56. * V62 4/09 *acm*- Add new symbols CURRENT_DATE, CURRENT_TIME. These get formatted
  57. * date and time, unlike SESSION_DATE, SESSION_TIME which remain
  58. * fixed at the start time of the Ferret session.
  59. * V62 5/09 *acm*- make FERRET_MEMORY a special symbol.
  60. * V65 1/10 *acm*- New special symbol N_OPEN_DSETS, counts the number of open datasets
  61. * V65 2/10 *acm*- Call CPU_TIME rather than DTIME for clock symbols. Works
  62. * with gfortran as well as g77.
  63. * V68 *acm* 1/12 ifdef double_p for double-precision ferret.
  64. * V68 1/12 *acm*- Symbol FERRET_PRECISION is single or double.
  65. * V68 3/12 *acm*- Symbol SESSION_PID for the process ID
  66. * V68 2/13 *kms*- Symbol PROGRAM_NAME = Ferret or PyFerret
  67. * V702 3/17 *sh* - Dynamic memory calculation change for FERRET_MEMORY symbol
  68. * - added PEAK_MEMORY and SPAWN_STATUS
  69. * v720 7/17 *acm* ticket 2552 Make SPAWN_STATUS return the return status, so 0=succcess
  70. * SPAWN_OK -> SPAWN_OK, so 1=succcess, 0=failure
  71. * SPAWN_STATUS returns the status value
  72. IMPLICIT NONE
  73. * calling argument declarations:
  74. INTEGER isym, slen
  75. CHARACTER name*(*), value*(*)
  76. * internal parameter declaration
  77. INTEGER nspecial
  78. PARAMETER (nspecial = 20)
  79. * internal variable declarations:
  80. LOGICAL IS_SECURE
  81. INTEGER STR_UPCASE, TM_LENSTR, i, i1, ierr, wsid,
  82. . nxpix, nypix, llen, icount, irate, imax, iset
  83. c REAL DTIME
  84. REAL TArray(2), dtime_res, clock_secs, count, cputime_now, rstatus
  85. CHARACTER special(nspecial)*16, upname*16
  86. CHARACTER LEFINT*16, TM_FMT*12, NF_INQ_LIBVERS*80, NF_INQ_LIBVERS_*80,
  87. . LEFINT8*16
  88. CHARACTER*10 current_date, current_time, zone
  89. INTEGER itimes(8)
  90. * names of special symbols (must be upper case)
  91. DATA special(1)/ 'PPL$XPIXEL' /,
  92. . special(2)/ 'PPL$YPIXEL' /,
  93. . special(3)/ 'BYTEORDER' /,
  94. . special(4)/ 'FERRET_VERSION' /,
  95. . special(5)/ 'FERRET_PLATFORM' /,
  96. . special(6)/ 'FERRET_PRECISION' /,
  97. . special(7)/ 'NETCDF_VERSION' /,
  98. . special(8)/ 'FERRET_MEMORY' /,
  99. . special(9)/ 'SESSION_DATE' /,
  100. . special(10)/ 'SESSION_TIME' /,
  101. . special(11)/ 'SESSION_PID' /,
  102. . special(12)/ 'DELTA_CPU' /,
  103. . special(13)/ 'CLOCK_SECS' /,
  104. . special(14)/ 'CURRENT_DATE' /,
  105. . special(15)/ 'CURRENT_TIME' /,
  106. . special(16)/ 'N_OPEN_DSETS' /,
  107. . special(17)/ 'PROGRAM_NAME' /,
  108. . special(18)/ 'PEAK_MEMORY' /,
  109. . special(19)/ 'SPAWN_OK' /,
  110. . special(20)/ 'SPAWN_STATUS' /
  111. include 'tmap_dims.parm'
  112. include 'ferret.parm'
  113. include 'xplot_state.cmn' ! for PPL$XPIXEL
  114. include 'xrevision.cmn'
  115. include 'xtoday.cmn'
  116. include 'xplatform_type.cmn'
  117. include 'xvariables.cmn'
  118. # include "tmap_dset.parm"
  119. include 'xdset_info.cmn_text'
  120. include 'xprog_state.cmn' ! for spawn_status
  121. * #ifdef for endianness info.
  122. #ifdef sun
  123. include 'xmachine_byte.cmn'
  124. #else
  125. include 'xmachine_int1.cmn'
  126. #endif
  127. * is this a query by integer or by name?
  128. IF (isym .GE. 1) THEN
  129. * ***** QUERY BY INTEGER ******
  130. IF (isym.GT.nspecial) THEN
  131. name = ' '
  132. RETURN
  133. ENDIF
  134. name = special(isym)
  135. RETURN
  136. ENDIF
  137. * ***** QUERY BY NAME *****
  138. * identify the given name
  139. ierr = STR_UPCASE( upname, name )
  140. DO 100 i = 1, nspecial
  141. IF (upname .EQ. special(i)) GOTO 200
  142. 100 CONTINUE
  143. * not a recognized special symbol
  144. slen = 0
  145. RETURN
  146. 200 GOTO (1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800,
  147. . 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600,
  148. . 2700, 2800, 2900, 3000 ) i
  149. * PPL$XPIXEL, PPL$YPIXEL
  150. 1100 CONTINUE
  151. * ... determine the current output window (GKS wkstn ID, that is)
  152. 1200 DO 1230 wsid = 1, max_windows
  153. IF ( wn_active(wsid) ) GOTO 1240
  154. 1230 CONTINUE
  155. * ... no currently active window
  156. value = '0'
  157. slen = 1
  158. RETURN
  159. 1240 CALL GET_WINDOW_PIXELS(wsid, nxpix, nypix)
  160. IF ( i.EQ.1 ) THEN
  161. value = LEFINT(nxpix,slen)
  162. ELSE
  163. value = LEFINT(nypix,slen)
  164. ENDIF
  165. RETURN
  166. * BYTEORDER - get byteorder of this architecture
  167. 1300 IF (active_cpu .EQ. cptype_sun) THEN
  168. value = 'BIG'
  169. slen = 3
  170. ELSE
  171. value = 'LITTLE'
  172. slen = 6
  173. ENDIF
  174. RETURN
  175. * FERRET_VERSION
  176. 1400 value = ' '
  177. value = TM_FMT(revision_level, 5, 12, llen)
  178. slen = llen
  179. RETURN
  180. * PLATFORM_TYPE *kob* 10/01
  181. 1500 value = platform_type
  182. slen = TM_LENSTR(platform_type)
  183. RETURN
  184. * FERRET_PRECISION
  185. 1600 CONTINUE
  186. #ifdef double_p
  187. value = 'double'
  188. #else
  189. value = 'single'
  190. #endif
  191. slen = TM_LENSTR(value)
  192. RETURN
  193. * NETCDF_VERSION
  194. 1700 CONTINUE
  195. value = NF_INQ_LIBVERS()
  196. slen = TM_LENSTR(value)
  197. RETURN
  198. * FERRET_MEMORY
  199. 1800 value = TM_FMT(max_mem_allowed/1.E6,3,12,llen)
  200. slen = llen
  201. RETURN
  202. * SESSION_DATE
  203. 1900 value = today_date
  204. slen = 9
  205. RETURN
  206. * SESSION_TIME
  207. 2000 value = today_time
  208. slen = 5
  209. RETURN
  210. * SESSION_PID
  211. 2100 CONTINUE
  212. i1 = GETPID()
  213. count = i1
  214. value = TM_FMT(count, 10, 10, slen)
  215. RETURN
  216. * DELTA_CPU
  217. 2200 CONTINUE
  218. c CALL DTIME(TArray)
  219. CALL CPU_TIME(cputime_now)
  220. dtime_res = cputime_now - cpu_last
  221. cpu_last = cputime_now
  222. value = ' '
  223. value = TM_FMT(dtime_res, 6, 8, slen)
  224. RETURN
  225. * CLOCK_SECS
  226. 2300 CALL SYSTEM_CLOCK(icount, irate, imax)
  227. clock_secs = FLOAT(icount-clock_start_count)/FLOAT(irate)
  228. IF (clock_secs .LT. 0) THEN
  229. CALL WARN('Evaluating CLOCK_SECS, call to '//
  230. . 'SYSTEM_CLOCK. Count has exceeded its max and reset.')
  231. CALL WARN( 'This value of CLOCK_SECS is invalid. '//
  232. . 'Resetting to new initial value.')
  233. clock_secs = 0.
  234. clock_start_count = FLOAT(icount)/FLOAT(irate)
  235. ENDIF
  236. value = ' '
  237. value = TM_FMT(clock_secs, 6, 8, slen)
  238. RETURN
  239. * CURRENT_DATE
  240. 2400 CONTINUE
  241. #ifdef AIX_XLF
  242. CALL AIX_DATE( current_date )
  243. #elif F90_DATE_TIME
  244. CALL FDATE(current_date)
  245. #else
  246. CALL GET_DATE_AND_TIME (current_date, current_time)
  247. #endif
  248. value = current_date
  249. slen = 9
  250. RETURN
  251. * CURRENT_TIME
  252. 2500 CONTINUE
  253. #ifdef AIX_XLF
  254. CALL AIX_TIME( current_time )
  255. #elif F90_DATE_TIME
  256. CALL FTIME(current_time)
  257. #else
  258. CALL GET_DATE_AND_TIME (current_date, current_time) ! doesnt get seconds
  259. CALL Date_and_Time(current_date, current_time, Zone, itimes)
  260. WRITE (current_time,1000) itimes(5), itimes(6), itimes(7)
  261. 1000 FORMAT (2(I2.2,":"), I2.2)
  262. #endif
  263. value = current_time
  264. slen = 8
  265. RETURN
  266. * N_OPEN_DSETS
  267. 2600 CONTINUE
  268. count = 0.
  269. DO 2690 iset = 1, maxdsets
  270. IF ( ds_name(iset) .NE. char_init2048) count = count + 1.
  271. 2690 CONTINUE
  272. value = TM_FMT(count, 10, 10, slen)
  273. RETURN
  274. * PROGRAM_NAME
  275. 2700 CONTINUE
  276. value = 'Ferret'
  277. slen = 6
  278. RETURN
  279. * PEAK_MEMORY
  280. 2800 value = LEFINT8(peak_mem,slen)
  281. RETURN
  282. * SPAWN_OK
  283. 2900 IF (IS_SECURE()) THEN
  284. rstatus = 0.
  285. ELSEIF (spawn_status .EQ. 0.) THEN
  286. rstatus = 1.
  287. ELSE
  288. rstatus = 0.
  289. ENDIF
  290. value = TM_FMT(rstatus, 10, 10, slen)
  291. RETURN
  292. * SPAWN_STATUS
  293. 3000 IF (IS_SECURE()) THEN
  294. value = 'secure: spawn not allowed'
  295. slen = 25
  296. ELSE
  297. rstatus = spawn_status
  298. value = TM_FMT(rstatus, 10, 10, slen)
  299. ENDIf
  300. RETURN
  301. END