go.F90 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. !
  2. !ProTeX: 1.14-AJS
  3. !
  4. !BOI
  5. !
  6. ! !TITLE: GO - General Objects library
  7. ! !AUTHORS: Arjo Segers
  8. ! !AFFILIATION: KNMI
  9. ! !DATE: \today
  10. !
  11. ! !INTRODUCTION: Introduction
  12. !
  13. ! The GO library provides general purpose entities for Fortran90 programs.
  14. !
  15. ! In summary, the GO library provides:
  16. !
  17. ! \begin{itemize}
  18. ! \item
  19. ! facilities to write (error) messages;
  20. ! \item
  21. ! system constants and interface to system functions;
  22. ! \item
  23. ! character functions;
  24. ! \item
  25. ! date and time manipulation;
  26. ! \item
  27. ! file handling without specification of unit numbers;
  28. ! \item
  29. ! reading from text file with comment lines;
  30. ! \item
  31. ! reading settings from a resource file;
  32. ! \end{itemize}
  33. !
  34. ! The library consists of a single module to provide access to routines,
  35. ! functions, and data types.
  36. ! In addition, a few shell scripts are provided for specialized tascs.
  37. !
  38. !
  39. ! !INTRODUCTION: About status argument
  40. !
  41. ! An integer status argument is present in most routines:
  42. ! \bv
  43. ! subroutine aaa( status )
  44. !
  45. ! integer, intent(out) :: status
  46. !
  47. ! ! wrong!
  48. ! if ( 1 /= 0 ) then
  49. ! write (*,'("ERROR - this is a serious error ...")')
  50. ! write (*,'("ERROR in aaa"); status=1; return
  51. ! end if
  52. !
  53. ! ! ok
  54. ! status = 0
  55. !
  56. ! end subroutine aaa
  57. ! \ev
  58. ! The value should be checked on return to test on succesful completion:
  59. ! \bv
  60. ! call aaa( status )
  61. ! if (status/=0) then; write (*,'("ERROR in prog")'); status=1; return; end if
  62. ! \ev
  63. ! To make the make the code more readible, define a preprossor macro
  64. ! for this check-and-trace line:
  65. ! \bv
  66. ! #define IF_ERROR_THEN(action) if (status/=0) then; write (*,'("ERROR in prog")'); action; return; end if
  67. !
  68. ! call aaa( status )
  69. ! IF_ERROR_RETURN( status=1 )
  70. ! \ev
  71. !
  72. !
  73. ! !INTRODUCTION: GO
  74. !
  75. ! The GO-library takes the form of a module:
  76. ! \bv
  77. ! use GO
  78. ! \ev
  79. !
  80. ! The GO module (source file \texttt{go.f90}) is in fact a shell around a bunch of
  81. ! sub modules.
  82. ! The sub modules should not be used directly, but accessed through
  83. ! the main module only.
  84. !
  85. !
  86. !
  87. ! !INTRODUCTION: GO\_FU
  88. !
  89. ! \subsection{Description}
  90. !
  91. ! Standard file units, might be compiler depended.
  92. !
  93. ! Since the standard file units might be used by other modules
  94. ! to write (error) messages, this is the most basic of all GO modules.
  95. !
  96. ! \subsection{Usage}
  97. !
  98. ! Access the entities of this module via the main module (prefered)
  99. ! or directly:
  100. ! \bv
  101. ! use GO, only : ...
  102. ! use GO_FU, only : ...
  103. ! \ev
  104. !
  105. !
  106. ! \subsection{Constants}
  107. !
  108. ! \begin{itemize}
  109. ! \item
  110. ! Standard input, output, and error file:
  111. ! \bv
  112. ! integer, parameter :: goStdIn = 0
  113. ! integer, parameter :: goStdOut = 5
  114. ! integer, parameter :: goStdErr = 6
  115. ! \ev
  116. ! \item
  117. ! Range of file units that may be used by this program:
  118. ! \bv
  119. ! integer, parameter :: goFuRange(2) = (/0,999/)
  120. ! \ev
  121. ! Free file units selected by 'goGetFu' in module 'GO\_File'
  122. ! are within this range; if all are in use, an error is issued.
  123. ! This range might become a variable in future, such that free
  124. ! file units are selected in a range that is not used by other
  125. ! parts of the code.
  126. ! \end{itemize}
  127. !
  128. ! \subsection{Hackers only}
  129. !
  130. ! The module is implemented in source file \texttt{go\_fu.F90} .
  131. !
  132. !
  133. !
  134. ! !INTRODUCTION: GO\_Print
  135. !
  136. ! \subsection{Description}
  137. !
  138. ! Tools for (error) messages.
  139. !
  140. ! Basic idea is to write messages to the character buffer 'gol'
  141. ! and let the the actual printing be managed by a special routine.
  142. ! This is especially usefull if the program runs on multiple processors:
  143. ! \bv
  144. ! write (gol,'("This is processor : ",i2)') myid; call goPr
  145. ! \ev
  146. ! With the appropriate settings, the output might be:
  147. ! \bv
  148. ! [00] This is processor : 0
  149. ! [03] This is processor : 3
  150. ! [02] This is processor : 2
  151. ! [01] This is processor : 1
  152. ! \ev
  153. !
  154. ! \subsection{Usage}
  155. !
  156. ! Access the entities of this module via the main module (prefered)
  157. ! or directly:
  158. ! \bv
  159. ! use GO, only : ...
  160. ! use GO_Print, only : ...
  161. ! \ev
  162. !
  163. ! \subsection{Variables}
  164. !
  165. ! \begin{itemize}
  166. ! \item
  167. ! Buffer for standard output:
  168. ! \bv
  169. ! character(len=256) :: gol
  170. ! \ev
  171. ! \end{itemize}
  172. !
  173. ! \subsection{Procedures}
  174. !
  175. ! \begin{itemize}
  176. ! \item
  177. ! Initialize printing of messages:
  178. ! \bv
  179. ! call GO_Print_Init( status, apply=.true., &
  180. ! prompt_pe=.true., pe=0, &
  181. ! trace=.false. )
  182. ! \ev
  183. ! Arguments:
  184. ! \begin{itemize}
  185. ! \item \texttt{integer, intent(inout) :: status}\\
  186. ! Should be zero on input, unequal to zero in case of errors.
  187. ! \item \texttt{logical, intent(in), optional :: apply}\\
  188. ! If set to true (on this processor), messages are printed.
  189. ! Use this flag to limit printing to root processor only for example.
  190. ! \item \texttt{logical, intent(in), optional :: prompt\_pe}\\
  191. ! If true, the processor number is printed at the begin of each line.
  192. ! \item \texttt{integer, intent(in), optional :: pe}\\
  193. ! Processor number used if \texttt{prompt\_pe} is true.
  194. ! \item \texttt{logical, intent(in), optional :: trace}\\
  195. ! Print all labels (see routine \texttt{goLabel}).
  196. ! \end{itemize}
  197. ! \item
  198. ! Donialize printing:
  199. ! \bv
  200. ! call GO_Print_Done( status )
  201. ! \ev
  202. ! Arguments:
  203. ! \begin{itemize}
  204. ! \item \texttt{integer, intent(inout) :: status}\\
  205. ! Should be zero on input, unequal to zero in case of errors.
  206. ! \end{itemize}
  207. ! \item
  208. ! Print the text written to '\texttt{gol}', including prompts etc:
  209. ! \bv
  210. ! write (gol,'("Hello!")'); call goPr
  211. ! \ev
  212. ! \item
  213. ! Write error messages:
  214. ! \bv
  215. ! write (gol,'("this is a serious error ...")'); call goErr
  216. ! write (gol,'("in program")'); call goErr; status=1; return
  217. ! \ev
  218. ! This will produce the following output:
  219. ! \bv
  220. ! [00] ERROR - this is a serious error ...
  221. ! [00] ERROR - in program
  222. ! \ev
  223. ! At the moment, error messages are treated the same as normal messages.
  224. ! \item
  225. ! Set and unset routine labels:
  226. ! \bv
  227. ! call goLabel( 'mymod/myroutine' )
  228. ! ...
  229. ! call goLabel()
  230. ! \ev
  231. ! The labels can be used to show in which routine info is printed
  232. ! or where exactelly an error occured.
  233. ! If option '\texttt{trace}' in the initialization is true,
  234. ! labels are always printed; nice for debugging.
  235. ! By the first command, a new label is pushed on a stack to let
  236. ! the program known that a new part of the code is reached;
  237. ! the second command (without arguments) indicates that the end
  238. ! of this part is reached and the label is popped from the stack.
  239. ! Messages printed in between the above commands will be indented;
  240. ! the height of the stack determines the indention.\\
  241. ! A program with three printing levels, and '\texttt{trace}' and
  242. ! '\texttt{prompe\_pe}' set to true, might produce the following output:
  243. ! \bv
  244. ! [00] <myprog>
  245. ! [00] This is the main program.
  246. ! [00] <mymod/aaa>
  247. ! [00] This is routine aaa.
  248. ! [00] <mymod/bbb>
  249. ! [00] This is routine bbb.
  250. ! [00] (mymod/bbb)
  251. ! [00] (mymod/aaa)
  252. ! [00] Normal end.
  253. ! [00] (myprog)
  254. ! \ev
  255. ! The current label is also unset by a second call to '\texttt{goErr}'
  256. ! if '\texttt{gol}' has not been filled in between:
  257. ! \bv
  258. ! subroutine aaa( status )
  259. !
  260. ! integer, intent(out) :: status
  261. !
  262. ! call goLabel( 'mymod/aaa' )
  263. !
  264. ! call bbb( status )
  265. ! if (status/=0) then; call goErr; status=1; return; end if
  266. !
  267. ! status=0; call goLabel()
  268. !
  269. ! end subroutine aaa
  270. !
  271. ! subroutine bbb( status )
  272. !
  273. ! integer, intent(out) :: status
  274. !
  275. ! call goLabel( 'mymod/bbb' )
  276. !
  277. ! write (gol,'("this is a serious error ...")'); call goErr
  278. ! call goErr; status=1; return
  279. !
  280. ! status=0; call goLabel()
  281. !
  282. ! end subroutine bbb
  283. ! \ev
  284. ! This will produce the following output (no trace):
  285. ! \bv
  286. ! [00] ERROR - this is a serious error ...
  287. ! [00] ERROR - in mymod/bbb
  288. ! [00] ERROR - in mymod/aaa
  289. ! [00] ERROR - in myprog
  290. ! \ev
  291. ! \end{itemize}
  292. !
  293. ! \subsection{To be done}
  294. !
  295. ! The following options should be implemented soon, since they have
  296. ! been implemented in older versions:
  297. ! \begin{itemize}
  298. ! \item option to write output (per processor?) to a file
  299. ! instead of standard output;
  300. ! \item error messages should be written to standar error or an error file;
  301. ! \item there should be a simple swith to turn on message printing
  302. ! for a while
  303. ! \item the time spent on a labelled code could be counted;
  304. ! a very simple but effective way to profile program performance.
  305. ! \end{itemize}
  306. !
  307. ! \subsection{Hackers only}
  308. !
  309. ! The module is implemented in source file \texttt{go\_print.f90} .
  310. !
  311. !
  312. !
  313. ! !INTRODUCTION: GO\_String
  314. !
  315. ! General objects for character strings.
  316. !
  317. ! \subsection{Usage}
  318. !
  319. ! Access the entities of this module via the main module (prefered)
  320. ! or directly:
  321. ! \bv
  322. ! use GO, only : ...
  323. ! use GO_String, only : ...
  324. ! \ev
  325. !
  326. ! \subsection{Procedures}
  327. !
  328. ! \begin{itemize}
  329. ! \item
  330. ! Split a string into two parts:
  331. ! \bv
  332. ! call goSplitLine( 'ab#cd', s1, '#', s2, status )
  333. ! \ev
  334. ! The input string is split at the first occurance of \texttt{'\#'};
  335. ! the leading part is returned in \texttt{s1}, and the remainder
  336. ! without \texttt{'\#'} in \texttt{s2}.
  337. ! One or both of \texttt{s1} and \texttt{s2} might be empty. \newline
  338. ! Interface:
  339. ! \bv
  340. ! subroutine goSplitLine( line, s1, c, s2 )
  341. ! character(len=*), intent(in) :: line
  342. ! character(len=*), intent(out) :: s1
  343. ! character(len=1), intent(in) :: c
  344. ! character(len=*), intent(out) :: s2
  345. ! integer, intent(inout) :: status
  346. ! end subroutine goSplitLine
  347. ! \ev
  348. ! \item
  349. ! Remove leading part of a string and store contents in a variable:
  350. ! \bv
  351. ! line = 'abc, 123'
  352. ! call goReadFromLine( line, x, status [,sep=','] )
  353. ! \ev
  354. ! The character string \texttt{line} is split at the first komma
  355. ! (or the character specified by the optional argument \texttt{sep}),
  356. ! the contents of the leading part is read into the
  357. ! variable \texttt{x} and the remainder is returned in \texttt{line}.
  358. ! Currently only variables of standard type could be read. \newline
  359. ! Interface:
  360. ! \bv
  361. ! subroutine goReadFromLine( line, x, status, sep )
  362. ! character(len=*), intent(inout) :: line
  363. ! <xtype>, intent(out) :: x
  364. ! integer, intent(inout) :: status
  365. ! character(len=*), intent(in), optional :: sep
  366. ! end subroutine goReadFromLine
  367. !
  368. ! <xtype> = integer | real | logical | character(len=*)
  369. ! \ev
  370. ! \item
  371. ! Reads the value assigned to a name from a character line:
  372. ! \bv
  373. ! bb = 'default'
  374. ! call goVarValue( 'aa=1;bb=xyz;cc=U123', ';', 'bb', '=', bb, status )
  375. ! \ev
  376. ! The character line is split at the specified seperations (here ';'),
  377. ! and examined on the occurance of the specified name (here 'bb')
  378. ! followed by an assignment character ('=') .
  379. ! The value is storred in the last variable before the status argument.
  380. ! If the name is not found, the value remains what it was.
  381. ! Interface:
  382. ! \bv
  383. ! subroutine goVarValue( line, sep, var, is, val, status )
  384. ! character(len=*), intent(in) :: line
  385. ! character(len=1), intent(in) :: sep
  386. ! character(len=*), intent(in) :: var
  387. ! character(len=1), intent(in) :: is
  388. ! <xtype>, intent(inout) :: x
  389. ! integer, intent(inout) :: status
  390. ! end subroutine goVarValue( line, sep, var, is, val, status )
  391. !
  392. ! <xtype> = integer | character(len=*)
  393. !
  394. ! Return status:
  395. ! <0 : variable not found, val remains the same
  396. ! 0 : variable found, val reset
  397. ! >0 : error
  398. ! \ev
  399. ! \item
  400. ! Convert integer value to a character string:
  401. ! \bv
  402. ! s = goNum2Str( i [,fmt='(i6)'] )
  403. ! \ev
  404. ! Returns a length 6-character string with the representation of the
  405. ! integer value \texttt{i} in the first characters.
  406. ! An optional format could be provided, for example to include
  407. ! leading zero's.
  408. ! Interface:
  409. ! \bv
  410. ! character(len=6) function goNum2Str( i, fmt )
  411. ! integer, intent(in) :: i
  412. ! character(len=*), intent(in), optional :: fmt
  413. ! end function goNum2Str
  414. ! \ev
  415. ! \item
  416. ! Convert to upper/lower case:
  417. ! \bv
  418. ! s2 = goUpCase( s1 )
  419. ! s2 = goLoCase( s1 )
  420. ! \ev
  421. ! Interfaces:
  422. ! \bv
  423. ! function goUpCase( s )
  424. ! character(len=*), intent(in) :: s
  425. ! character(len=len(s)) :: goUpCase
  426. ! end function goUpCase
  427. !
  428. ! function goLoCase( s )
  429. ! character(len=*), intent(in) :: s
  430. ! character(len=len(s)) :: goLoCase
  431. ! end function goLoCase
  432. ! \ev
  433. ! \item
  434. ! Write character keys formed by text and number:
  435. ! \bv
  436. ! call goWriteKeyNum( key, 'sh', 159 ) ! sh159
  437. ! \ev
  438. ! Interface:
  439. ! \bv
  440. ! subroutine WriteKeyNum( res, key, num )
  441. ! character(len=*), intent(out) :: res
  442. ! character(len=*), intent(in) :: key
  443. ! integer, intent(in) :: num
  444. ! end subroutine WriteKeyNum
  445. ! \ev
  446. ! \item
  447. ! Replace tab-characters by spaces:
  448. ! \bv
  449. ! call goTab2Space( s )
  450. ! \ev
  451. ! \end{itemize}
  452. !
  453. !
  454. ! \subsection{Hackers only}
  455. !
  456. ! The module is implemented in source file \texttt{go\_string.F90} .
  457. !
  458. !
  459. ! !INTRODUCTION: GO\_Date
  460. !
  461. ! General objects for date manipulation.
  462. !
  463. ! \subsection{Usage}
  464. !
  465. ! Access the entities of this module via the main module (prefered)
  466. ! or directly:
  467. ! \bv
  468. ! use GO, only : ...
  469. ! use GO_Date, only : ...
  470. ! \ev
  471. !
  472. !
  473. ! \subsection{Derived types}
  474. !
  475. ! A derived type is provided to store a date:
  476. ! \bv
  477. ! type(TDate) :: t
  478. ! \ev
  479. ! with fields:
  480. ! \bv
  481. ! character(len=4) :: calender ! see 'calenders'
  482. ! integer :: year, month, day, hour, min, sec, mili
  483. ! \ev
  484. !
  485. ! A second type is defined for time steps:
  486. ! \bv
  487. ! type(TIncrDate) :: dt
  488. ! \ev
  489. ! with fields for days, hours, minutes, seconds, and mili-seconds.
  490. ! The fields of an incremental data might have any value,
  491. ! even negative. Note that for this type a value day=1
  492. ! has the interpretation of 24 hours,
  493. ! while it has the interpretation of 'first day', thus 0 hours,
  494. ! for a regular date.
  495. !
  496. !
  497. ! \subsection{Calenders}
  498. !
  499. ! A number of different calender types is supported:
  500. ! \begin{itemize}
  501. ! \item 'greg'
  502. ! The Gregorian calender we are used to for a few ages now. \newline
  503. ! Some years have a Februari 29. \newline
  504. ! This is the default calender type; see also 'Defaults' below.
  505. ! \item '366'
  506. ! Every year has a Februari 29.
  507. ! \item '365'
  508. ! A year never has a Februari 29.
  509. ! \item '360'
  510. ! Every month has 30 days. \newline
  511. ! Use this calender if only operations on years and months are required.
  512. ! \item 'wall'
  513. ! Wall clock time, including time zone information.
  514. ! Most operations are not implemented for this calender yet.
  515. ! \end{itemize}
  516. !
  517. !
  518. !
  519. ! \subsection{Creating date structures}
  520. !
  521. ! To initialize a new date structure, a few routines are available.
  522. !
  523. ! Use routine \texttt{NewDate} to initialize some fields and to fill
  524. ! the rest with zero's. If no calender is specified,
  525. ! the default value \texttt{'greg'} is used (see section about defaults).
  526. ! \bv
  527. ! t = NewDate( year=2000, month=1, ..., calender='greg' )
  528. ! \ev
  529. ! Interface:
  530. ! \bv
  531. ! function NewDate( year, month, day, hour, min, sec, mili, zone, calender )
  532. ! type(TDate) :: NewDate
  533. ! integer, intent(in), optional :: year, month, day
  534. ! integer, intent(in), optional :: hour, min, sec, mili
  535. ! integer, intent(in), optional :: zone
  536. ! character(len=*), intent(in), optional :: calender
  537. ! end function NewDate
  538. ! \ev
  539. ! Use the specific order of the optional fields to quickly set the
  540. ! 'largest' values only, for example the date:
  541. ! \bv
  542. ! t = NewDate( 2000, 1, 2 )
  543. ! \ev
  544. ! A special funtion creates a date that represents 'any' time;
  545. ! useful to specify that some data is constant in time and thus
  546. ! valid for any time. A special inquiry function is available to
  547. ! test wether a date is any:
  548. ! \bv
  549. ! t = AnyDate()
  550. ! l = IsAnyDate(t)
  551. ! \ev
  552. !
  553. ! Use routine \texttt{IncrDate} to create an incremental date:
  554. ! \bv
  555. ! t = IncrDate( day=2, hour=12 )
  556. ! \ev
  557. ! Interface:
  558. ! \bv
  559. ! function IncrDate( day, hour, min, sec, mili )
  560. ! type(TIncrDate) :: IncrDate
  561. ! integer, intent(in), optional :: day, hour, min, sec, mili
  562. ! end function IncrDate
  563. ! \ev
  564. !
  565. ! Fill the time from the system clock in a date structure;
  566. ! the result is of calender type \texttt{'wall'}:
  567. ! \bv
  568. ! t = SystemDate()
  569. ! \ev
  570. !
  571. !
  572. ! \subsection{Changing date fields}
  573. !
  574. ! Use the \texttt{Set} routine to set some specific fields of
  575. ! a date structure:
  576. ! \bv
  577. ! call Set( t [,year=2000] [,month=1] [,day=2] &
  578. ! [,hour=0] [,min=0] [,sec=0] [,mili=0] &
  579. ! [,zone=0] [calender='greg'] )
  580. ! \ev
  581. ! Use the specific order of the optional fields to quickly set the
  582. ! 'largest' values only, for example the date:
  583. ! \bv
  584. ! call Set( t, 2000, 1, 2 )
  585. ! \ev
  586. !
  587. ! Normalize hours to 0,..,23, minutes to 0,..,59, etc:
  588. ! \bv
  589. ! call Normalize( t )
  590. ! \ev
  591. !
  592. ! To check if all fields are consistent with eachother, use:
  593. ! \bv
  594. ! call Check( t )
  595. ! \ev
  596. !
  597. ! Similar routines are implemented for date increments.
  598. !
  599. !
  600. ! \subsection{Extraction of date fields}
  601. !
  602. ! Use the \texttt{Get} routine to extract some specific fields of
  603. ! a date structure:
  604. ! \bv
  605. ! call Get( t [,year=year] [,month=month] [,day=day] &
  606. ! [,hour=hour] [,min=min] [,sec=sec] [,mili=mili] &
  607. ! [,zone=zone] [calender=calender] )
  608. ! \ev
  609. ! Use the specific order of the optional fields to quickly extract the
  610. ! 'largest' values only, for example the date:
  611. ! \bv
  612. ! call Get( t, year, month, day )
  613. ! \ev
  614. !
  615. ! A similar routine is implemented for date increments.
  616. !
  617. !
  618. ! \subsection{Inquiry functions}
  619. !
  620. ! A few inquiry functions are provided.
  621. !
  622. ! The logical function \texttt{LeapYear} tells you if the year
  623. ! has a Februari 29 :
  624. ! \bv
  625. ! l = LeapYear( t )
  626. ! \ev
  627. !
  628. ! Two integer functions are provided to count the total number
  629. ! of days in a month or a year:
  630. ! \bv
  631. ! i = Days_in_Month( t )
  632. ! i = Days_in_Year( t )
  633. ! \ev
  634. !
  635. ! An integer function is provided to return the day number,
  636. ! counting from 1 (Januari 1) to 360, 365, or 366 (last of December):
  637. ! \bv
  638. ! i = DayNumber( t )
  639. ! \ev
  640. !
  641. !
  642. ! \subsection{Operators}
  643. !
  644. ! Operator \texttt{+} is redefined to be able to add two
  645. ! dates to each other.
  646. ! Both should be of same calender type, unless one is an increment:
  647. ! \bv
  648. ! to = t1 + t2
  649. ! to = t + dt
  650. ! dto = dt1 + dt2
  651. ! \ev
  652. !
  653. ! Operator \texttt{-} is redefined to substract a date from another.
  654. ! Both should be of same calender type, unless the substracted date
  655. ! (\texttt{t2}) is an increment:
  656. ! \bv
  657. ! to = t1 - t2
  658. ! to = t - dt
  659. ! dto = dt1 - dt2
  660. ! \ev
  661. !
  662. ! Operator \texttt{*} has been redefined to multiply a date increment
  663. ! with a real or integer number.
  664. ! If necessary, a remaining fraction of miliseconds is rounded
  665. ! to the nearest integer.
  666. ! \bv
  667. ! dto = dt * 2
  668. ! dto = 2 * dt
  669. ! dto = dt * 1.5
  670. ! dto = 1.5 * dt
  671. ! \ev
  672. !
  673. ! Operator \texttt{/} is redefined to devide a date incrment by a real
  674. ! or an integer number.
  675. ! If necessary, a remaining fraction of miliseconds is rounded
  676. ! to the nearest integer.
  677. ! \bv
  678. ! dto = dt / 2
  679. ! dto = dt / 1.5
  680. ! \ev
  681. !
  682. ! Logical operators are defined to compare two dates with eachother;
  683. ! both should be of same calender type:
  684. ! \bv
  685. ! t1 == t2
  686. ! t1 >= t2
  687. ! t1 > t2
  688. ! t1 <= t2
  689. ! t1 < t2
  690. ! \ev
  691. !
  692. !
  693. ! \subsection{Summation routines}
  694. !
  695. ! The total number in a certain unit is returned by \texttt{rTotal}
  696. ! (real value) or \texttt{iTotal} (integer value, error if the sum could
  697. ! only be expressed as fraction).
  698. ! Currently supported units are \texttt{'year'}, \texttt{'month'}, \texttt{'day'},
  699. ! \texttt{'hour'}, \texttt{'min'}, \texttt{'sec'}, and \texttt{'mili'}.
  700. ! If the total number is not wel defined for a certain date
  701. ! (how to assign a fraction of years to the date of today?),
  702. ! an error message is produced.
  703. ! Date increments are supported too.
  704. ! \bv
  705. ! r = rTotal( t, 'year'|'month'|... )
  706. ! i = iTotal( t, 'year'|'month'|... )
  707. ! \ev
  708. !
  709. !
  710. ! \subsection{Temperal interpolation}
  711. !
  712. ! A linear interpolation in time is represented by:
  713. ! \bv
  714. ! f(t) = alfa1 * f(t1) + alfa2 * f(t2)
  715. ! \ev
  716. ! Given the dates t, t1, and t2, the fractions alfa1 and alfa2
  717. ! are set by the following routine:
  718. ! \bv
  719. ! InterpolFractions( t, t1, t2, alfa1, alfa2, status )
  720. ! type(TDate), intent(in) :: t
  721. ! type(TDate), intent(in) :: t1
  722. ! type(TDate), intent(in) :: t2
  723. ! real, intent(out) :: alfa1
  724. ! real, intent(out) :: alfa2
  725. ! integer, intent(out) :: status
  726. ! \ev
  727. !
  728. !
  729. ! \subsection{Output}
  730. !
  731. ! To obtain a pretty formatted print of the value of a date,
  732. ! the 'Pretty' routine is provided. Output differs based on
  733. ! the calender type. Also implemented for date increments.
  734. ! \bv
  735. ! character(len=36) function Pretty( t )
  736. ! type(TDate), intent(in) :: t
  737. !
  738. ! calender output
  739. ! ---------------------------- ----------------------------------------
  740. ! (date)
  741. ! 'wall' 1:23:45:678 03 feb 2001 (GMT+02:00)
  742. ! 'greg', '366', '365', '360' 2001/02/03 1:23:45:678
  743. ! (date increment)
  744. ! 2 days 1:23:45:678
  745. ! \ev
  746. !
  747. ! Two routines are provided to write messages including a date to
  748. ! the '\texttt{gol}' buffer from the '\texttt{go\_Print}' library.
  749. ! Add a call to '\texttt{goPr}' or '\texttt{goErr}' to actually
  750. ! display the message. Example:
  751. ! \bv
  752. ! call wrtgol( 'time : ', t ); call goPr
  753. ! call wrtgol( 'range : ', t1, ' - ', 't2' ); call goPr
  754. ! \ev
  755. ! provides:
  756. ! \bv
  757. ! [00] time : 2001/01/01 00:00:00:000
  758. ! [00] range : 2001/01/01 00:00:00:000 - 2001/01/01 03:00:00:000
  759. ! \ev
  760. !
  761. ! \subsection{Defaults}
  762. !
  763. ! For setting some default values, the subroutine 'go\_DateDefaults'
  764. ! is available. All arguments are optional.
  765. ! Yet, only the calender type might be set.
  766. ! \bv
  767. ! call goDateDefaults( [calender='greg'] )
  768. ! \ev
  769. !
  770. !
  771. ! \subsection{Hackers only}
  772. !
  773. ! The module is implemented in source file \texttt{go\_date.F90} .
  774. !
  775. !
  776. ! !INTRODUCTION: GO\_File
  777. !
  778. ! Selects free file units. \newline
  779. ! Read lines from a commented text file, skipping comments and empty lines.
  780. !
  781. ! \subsection{Usage}
  782. !
  783. ! Access the entities of this module via the main module (prefered)
  784. ! or directly:
  785. ! \bv
  786. ! use GO, only : ...
  787. ! use GO_File, only : ...
  788. ! \ev
  789. !
  790. ! \subsection{Free file unit}
  791. !
  792. ! Use the following routine to select a free (unopened) file unit:
  793. ! \bv
  794. ! call goGetFU( fu, status )
  795. ! integer, intent(inout) :: fu
  796. ! integer, intent(out) :: status
  797. ! \ev
  798. ! The routines searches for unopened file units with the range
  799. ! specified by '\texttt{goFuRange}' from module '\texttt{go\_FU}',
  800. ! excluding the standard units.
  801. ! If all units are already opened, an error message is returned.
  802. !
  803. ! \subsection{Commented text files}
  804. !
  805. ! A commented text file might look like:
  806. ! \bv
  807. ! !
  808. ! ! This is data file.
  809. ! !
  810. !
  811. ! ! number of data values:
  812. ! NDATA
  813. ! 3
  814. !
  815. ! ! data values:
  816. ! DATA
  817. ! 1.0 2.0 3.0
  818. ! \ev
  819. ! To be able to read from this file without bothering about comments
  820. ! and empty lines, a special file type is introduced:
  821. ! \bv
  822. ! type(TTextFile) :: file
  823. ! \ev
  824. !
  825. ! To open the file, use:
  826. ! \bv
  827. ! subroutine Init( file, 'data.txt', iostat, status, comment )
  828. ! type(TTextFile), intent(out) :: file
  829. ! character(len=*), intent(in) :: filename
  830. ! integer, intent(out) :: iostat
  831. ! character(len=*), intent(in), optional :: status
  832. ! character(len=1), intent(in), optional :: comment
  833. ! \ev
  834. ! The 'iostat' argument is the 'usuall' status argument, thus on return
  835. ! non-zero in case of errors.
  836. ! The 'status' argument is the same as used by Fortran's '\texttt{open}' command
  837. ! to specify wether a file should already exist (status='old'),
  838. ! should not exist yet and will be created ('new') or might exist or not ('unknown').
  839. !
  840. ! The optional comment is a single character; lines in the file that
  841. ! start with this character are skipped while reading.
  842. !
  843. ! To close the file, use:
  844. ! \bv
  845. ! subroutine file_Done( file, status )
  846. ! type(TTextFile), intent(inout) :: file
  847. ! integer, intent(out) :: status
  848. ! \ev
  849. !
  850. ! To read one line, skipping empty and comment lines, use:
  851. ! \bv
  852. ! subroutine ReadLine( file, s, status )
  853. ! type(TTextFile), intent(inout) :: file
  854. ! character(len=*), intent(out) :: s
  855. ! integer, intent(out) :: status
  856. ! \ev
  857. ! Return status<0 means that no values are read since end of file is reached;
  858. ! errors are indicated by status>0.
  859. !
  860. ! \subsection{Hackers only}
  861. !
  862. ! The module is implemented in source file \texttt{go\_file.F90} .
  863. !
  864. !
  865. !
  866. ! !INTRODUCTION: GO\_Rc
  867. !
  868. ! Read settings from a resource file. \newline
  869. !
  870. ! \subsection{Resource files}
  871. !
  872. ! In the GO library, an 'rcfile' or 'resource' file is a text file
  873. ! with settings for a program, with a format following the X-resource conventions:
  874. ! \bv
  875. ! ! This is an example resource file.
  876. ! ! Use line of the form:
  877. ! !
  878. ! ! <name> : <value>
  879. ! !
  880. ! ! Some conventions:
  881. ! ! * comment lines start with '!'
  882. ! ! * logical values are 'T' or 'F' (without quotes ...)
  883. ! ! * character strings do not contain quotes
  884. !
  885. ! prog.n : 20
  886. ! input.file : /data/test.dat
  887. ! prog.debug : T
  888. ! \ev
  889. !
  890. !
  891. ! \subsection{Derived types}
  892. !
  893. ! A type has been derived to get access to a rcfile:
  894. ! \bv
  895. ! type TrcFile
  896. ! \ev
  897. !
  898. !
  899. ! \subsection{Routines}
  900. !
  901. ! To open a rcfile, use:
  902. ! \bv
  903. ! subroutine Init( rcfile, fname, status )
  904. ! type(TrcFile), intent(out) :: rcfile
  905. ! character(len=*), intent(in) :: fname
  906. ! integer, intent(out) :: status
  907. ! \ev
  908. ! To close it again, use:
  909. ! \bv
  910. ! subroutine Done( rcfile, status )
  911. ! type(TrcFile), intent(inout) :: rcfile
  912. ! integer, intent(out) :: status
  913. ! \ev
  914. !
  915. ! To read the value asigned to a key, use:
  916. ! \bv
  917. ! subroutine ReadRc( rcfile, key, x, status, default )
  918. ! type(TrcFile), intent(in) :: rcfile
  919. ! character(len=*), intent(in) :: key
  920. ! <type>, intent(out) :: x
  921. ! integer, intent(out) :: status
  922. ! <type>, intent(in), optional :: default
  923. ! \ev
  924. ! Current implemented types:
  925. ! \bv
  926. ! <type> = integer|real|character(len=*)|logical
  927. ! \ev
  928. ! If a key has not been found, an error messages is returned
  929. ! unless a default is provided.
  930. !
  931. ! \subsection{See also}
  932. !
  933. ! The shell scripts '\texttt{go\_readrc}' and '\texttt{go\_pprc}' are available
  934. ! to read from a rcfile withing shell scripts and to preprocess the rcfile
  935. ! respectively.
  936. !
  937. ! \subsection{Hackers only}
  938. !
  939. ! The module is implemented in source file \texttt{go\_rc.F90} .
  940. !
  941. !
  942. !
  943. ! !INTRODUCTION: GO\_System
  944. !
  945. ! \subsection{Description}
  946. !
  947. ! Interface to routines of some common system routines.
  948. ! These routines are not part of the Fortran standard,
  949. ! but almost always supplied.
  950. ! There might be subtile compiler (vendor) specific differences however,
  951. ! and therefor this module was made.
  952. ! Preprocessor statements in select the compiler specific code.
  953. !
  954. ! Currently only implemented for:
  955. ! \begin{itemize}
  956. ! \item Intel Fortran Compiler (version 8)
  957. ! \end{itemize}
  958. !
  959. ! \subsection{Usage}
  960. !
  961. ! Access the entities of this module via the main module (prefered)
  962. ! or directly:
  963. ! \bv
  964. ! use GO, only : ...
  965. ! use GO_System, only : ...
  966. ! \ev
  967. !
  968. !
  969. ! \subsection{Procedures}
  970. !
  971. ! \begin{itemize}
  972. ! \item
  973. ! Perform a system command and return exit status:
  974. ! \bv
  975. ! subroutine goSystem( command, status )
  976. ! character(len=*), intent(in) :: command
  977. ! integer, intent(inout) :: status
  978. ! end subroutine goSystem
  979. ! \ev
  980. ! \item
  981. ! Stop execution and set the return status:
  982. ! \bv
  983. ! subroutine goExit( status )
  984. ! integer, intent(in) :: status
  985. ! end subroutine goExit
  986. ! \ev
  987. ! \item
  988. ! Return number of command line arguments:
  989. ! \bv
  990. ! integer function goArgC()
  991. ! end function goArgC
  992. ! \ev
  993. ! \item
  994. ! Return command line argument \texttt{nr} in character string \texttt{value}.
  995. ! \bv
  996. ! subroutine goGetArg( nr, value, status )
  997. ! integer, intent(in) :: nr
  998. ! character(len=*), intent(out) :: value
  999. ! integer, intent(out) :: status
  1000. ! end subroutine goGetArg
  1001. ! \ev
  1002. ! \end{itemize}
  1003. !
  1004. !
  1005. ! \subsection{Hackers only}
  1006. !
  1007. ! The module is implemented in source file \texttt{go\_system.F90} .
  1008. !
  1009. !
  1010. !EOI
  1011. !
  1012. module GO
  1013. use GO_FU
  1014. use GO_Print
  1015. use GO_System
  1016. use GO_String
  1017. use GO_Date
  1018. use GO_File
  1019. use GO_Rc
  1020. !use goRestart
  1021. !use goSave
  1022. !use goLabel
  1023. use go_Timer
  1024. ! --- in/out ---------------------------------------
  1025. public
  1026. end module GO