FV3 Bundle
Zeeman_Input_Define.f90
Go to the documentation of this file.
1 !
2 ! Zeeman_Input_Define
3 !
4 ! Module containing the structure definition and associated routines
5 ! for CRTM inputs specific to Zeeman
6 !
7 !
8 ! CREATION HISTORY:
9 ! Written by: Paul van Delst, 26-Oct-2009
10 ! paul.vandelst@noaa.gov
11 !
12 
14 
15  ! -----------------
16  ! Environment setup
17  ! -----------------
18  ! Module use
19  USE type_kinds , ONLY: fp, long, double
21  USE compare_float_numbers, ONLY: OPERATOR(.equalto.)
26  ! ------------
27  ! Visibilities
28  ! ------------
29  PRIVATE
30  ! Datatypes
31  PUBLIC :: zeeman_input_type
32  ! Operators
33  PUBLIC :: OPERATOR(==)
34  ! Procedures
35  PUBLIC :: zeeman_input_getvalue
36  PUBLIC :: zeeman_input_setvalue
37  PUBLIC :: zeeman_input_isvalid
38  PUBLIC :: zeeman_input_inspect
41  PUBLIC :: zeeman_input_readfile
42  PUBLIC :: zeeman_input_writefile
43 
44 
45  ! -------------------
46  ! Procedure overloads
47  ! -------------------
48  INTERFACE OPERATOR(==)
49  MODULE PROCEDURE zeeman_input_equal
50  END INTERFACE OPERATOR(==)
51 
52 
53  ! -----------------
54  ! Module parameters
55  ! -----------------
56  CHARACTER(*), PRIVATE, PARAMETER :: module_version_id = &
57  '$Id: Zeeman_Input_Define.f90 60152 2015-08-13 19:19:13Z paul.vandelst@noaa.gov $'
58  ! Release and version
59  INTEGER, PARAMETER :: zeeman_input_release = 1 ! This determines structure and file formats.
60  INTEGER, PARAMETER :: zeeman_input_version = 1 ! This is just the default data version.
61  ! Close status for write errors
62  CHARACTER(*), PARAMETER :: write_error_status = 'DELETE'
63  ! Message string length
64  INTEGER, PARAMETER :: ml = 256
65  ! Literal constants
66  REAL(Double), PARAMETER :: zero = 0.0_double
67  ! Zeeman specific data
68  REAL(Double), PARAMETER :: default_magentic_field = 0.3_double
69 
70 
71  !--------------------
72  ! Structure defintion
73  !--------------------
74  !:tdoc+:
76  PRIVATE
77  ! Release and version information
78  INTEGER(Long) :: release = zeeman_input_release
79  INTEGER(Long) :: version = zeeman_input_version
80  ! Earth magnetic field strength in Gauss
81  REAL(Double) :: be = default_magentic_field
82  ! Cosine of the angle between the Earth
83  ! magnetic field and wave propagation direction
84  REAL(Double) :: cos_thetab = zero
85  ! Cosine of the azimuth angle of the Be vector.
86  REAL(Double) :: cos_phib = zero
87  ! Doppler frequency shift caused by Earth-rotation.
88  REAL(Double) :: doppler_shift = zero
89  END TYPE zeeman_input_type
90  !:tdoc-:
91 
92 
93 CONTAINS
94 
95 
96 !################################################################################
97 !################################################################################
98 !## ##
99 !## ## PUBLIC MODULE ROUTINES ## ##
100 !## ##
101 !################################################################################
102 !################################################################################
103 
104 !--------------------------------------------------------------------------------
105 !:sdoc+:
106 !
107 ! NAME:
108 ! Zeeman_Input_SetValue
109 !
110 ! PURPOSE:
111 ! Elemental subroutine to set the values of Zeeman_Input
112 ! object components.
113 !
114 ! CALLING SEQUENCE:
115 ! CALL Zeeman_Input_SetValue( Zeeman_Input , &
116 ! Field_Strength = Field_Strength, &
117 ! Cos_ThetaB = Cos_ThetaB , &
118 ! Cos_PhiB = Cos_PhiB , &
119 ! Doppler_Shift = Doppler_Shift )
120 !
121 ! OBJECTS:
122 ! Zeeman_Input: Zeeman_Input object for which component values
123 ! are to be set.
124 ! UNITS: N/A
125 ! TYPE: Zeeman_Input_type
126 ! DIMENSION: Scalar or any rank
127 ! ATTRIBUTES: INTENT(IN OUT)
128 !
129 ! OPTIONAL INPUTS:
130 ! Field_Strength: Earth's magnetic filed strength
131 ! UNITS: Gauss
132 ! TYPE: REAL(fp)
133 ! DIMENSION: Scalar or same as Zeeman_Input
134 ! ATTRIBUTES: INTENT(IN), OPTIONAL
135 !
136 ! Cos_ThetaB: Cosine of the angle between the Earth magnetic
137 ! field and wave propagation vectors.
138 ! UNITS: N/A
139 ! TYPE: REAL(fp)
140 ! DIMENSION: Scalar or same as Zeeman_Input
141 ! ATTRIBUTES: INTENT(IN), OPTIONAL
142 !
143 ! Cos_PhiB: Cosine of the azimuth angle of the Earth magnetic
144 ! field vector.
145 ! UNITS: N/A
146 ! TYPE: REAL(fp)
147 ! DIMENSION: Scalar or same as Zeeman_Input
148 ! ATTRIBUTES: INTENT(IN), OPTIONAL
149 !
150 ! Doppler_Shift: Doppler frequency shift caused by Earth-rotation.
151 ! Positive towards sensor.
152 ! UNITS: KHz
153 ! TYPE: REAL(fp)
154 ! DIMENSION: Scalar or same as Zeeman_Input
155 ! ATTRIBUTES: INTENT(IN), OPTIONAL
156 !
157 !:sdoc-:
158 !--------------------------------------------------------------------------------
159 
160  ELEMENTAL SUBROUTINE zeeman_input_setvalue( &
161  Zeeman_Input , &
162  Field_Strength, &
163  Cos_ThetaB , &
164  Cos_PhiB , &
165  Doppler_Shift )
166  ! Arguments
167  TYPE(zeeman_input_type), INTENT(IN OUT) :: zeeman_input
168  REAL(fp), OPTIONAL, INTENT(IN) :: field_strength
169  REAL(fp), OPTIONAL, INTENT(IN) :: cos_thetab
170  REAL(fp), OPTIONAL, INTENT(IN) :: cos_phib
171  REAL(fp), OPTIONAL, INTENT(IN) :: doppler_shift
172  ! Set components
173  IF ( PRESENT(field_strength) ) zeeman_input%Be = field_strength
174  IF ( PRESENT(cos_thetab ) ) zeeman_input%Cos_ThetaB = cos_thetab
175  IF ( PRESENT(cos_phib ) ) zeeman_input%Cos_PhiB = cos_phib
176  IF ( PRESENT(doppler_shift ) ) zeeman_input%Doppler_Shift = doppler_shift
177  END SUBROUTINE zeeman_input_setvalue
178 
179 
180 !--------------------------------------------------------------------------------
181 !:sdoc+:
182 !
183 ! NAME:
184 ! Zeeman_Input_GetValue
185 !
186 ! PURPOSE:
187 ! Elemental subroutine to get the values of Zeeman_Input
188 ! object components.
189 !
190 ! CALLING SEQUENCE:
191 ! CALL Zeeman_Input_GetValue( Zeeman_Input , &
192 ! Field_Strength = Field_Strength, &
193 ! Cos_ThetaB = Cos_ThetaB , &
194 ! Cos_PhiB = Cos_PhiB , &
195 ! Doppler_Shift = Doppler_Shift )
196 !
197 ! OBJECTS:
198 ! Zeeman_Input: Zeeman_Input object for which component values
199 ! are to be set.
200 ! UNITS: N/A
201 ! TYPE: Zeeman_Input_type
202 ! DIMENSION: Scalar or any rank
203 ! ATTRIBUTES: INTENT(IN OUT)
204 !
205 ! OPTIONAL OUTPUTS:
206 ! Field_Strength: Earth's magnetic filed strength
207 ! UNITS: Gauss
208 ! TYPE: REAL(fp)
209 ! DIMENSION: Scalar or same as Zeeman_Input
210 ! ATTRIBUTES: INTENT(OUT), OPTIONAL
211 !
212 ! Cos_ThetaB: Cosine of the angle between the Earth magnetic
213 ! field and wave propagation vectors.
214 ! UNITS: N/A
215 ! TYPE: REAL(fp)
216 ! DIMENSION: Scalar or same as Zeeman_Input
217 ! ATTRIBUTES: INTENT(OUT), OPTIONAL
218 !
219 ! Cos_PhiB: Cosine of the azimuth angle of the Earth magnetic
220 ! field vector.
221 ! UNITS: N/A
222 ! TYPE: REAL(fp)
223 ! DIMENSION: Scalar or same as Zeeman_Input
224 ! ATTRIBUTES: INTENT(OUT), OPTIONAL
225 !
226 ! Doppler_Shift: Doppler frequency shift caused by Earth-rotation.
227 ! Positive towards sensor.
228 ! UNITS: KHz
229 ! TYPE: REAL(fp)
230 ! DIMENSION: Scalar or same as Zeeman_Input
231 ! ATTRIBUTES: INTENT(OUT), OPTIONAL
232 !
233 !:sdoc-:
234 !--------------------------------------------------------------------------------
235 
236  ELEMENTAL SUBROUTINE zeeman_input_getvalue( &
237  Zeeman_Input , &
238  Field_Strength, &
239  Cos_ThetaB , &
240  Cos_PhiB , &
241  Doppler_Shift )
242  ! Arguments
243  TYPE(zeeman_input_type),INTENT(IN) :: zeeman_input
244  REAL(fp), OPTIONAL, INTENT(OUT) :: field_strength
245  REAL(fp), OPTIONAL, INTENT(OUT) :: cos_thetab
246  REAL(fp), OPTIONAL, INTENT(OUT) :: cos_phib
247  REAL(fp), OPTIONAL, INTENT(OUT) :: doppler_shift
248  ! Get components
249  IF ( PRESENT(field_strength) ) field_strength = zeeman_input%Be
250  IF ( PRESENT(cos_thetab ) ) cos_thetab = zeeman_input%Cos_ThetaB
251  IF ( PRESENT(cos_phib ) ) cos_phib = zeeman_input%Cos_PhiB
252  IF ( PRESENT(doppler_shift ) ) doppler_shift = zeeman_input%Doppler_Shift
253  END SUBROUTINE zeeman_input_getvalue
254 
255 
256 !--------------------------------------------------------------------------------
257 !:sdoc+:
258 !
259 ! NAME:
260 ! Zeeman_Input_IsValid
261 !
262 ! PURPOSE:
263 ! Non-pure function to perform some simple validity checks on a
264 ! Zeeman_Input object.
265 !
266 ! If invalid data is found, a message is printed to stdout.
267 !
268 ! CALLING SEQUENCE:
269 ! result = Zeeman_Input_IsValid( z )
270 !
271 ! or
272 !
273 ! IF ( Zeeman_Input_IsValid( z ) ) THEN....
274 !
275 ! OBJECTS:
276 ! z: Zeeman_Input object which is to have its
277 ! contents checked.
278 ! UNITS: N/A
279 ! TYPE: Zeeman_Input_type
280 ! DIMENSION: Scalar
281 ! ATTRIBUTES: INTENT(IN)
282 !
283 ! FUNCTION RESULT:
284 ! result: Logical variable indicating whether or not the input
285 ! passed the check.
286 ! If == .FALSE., object is unused or contains
287 ! invalid data.
288 ! == .TRUE., object can be used.
289 ! UNITS: N/A
290 ! TYPE: LOGICAL
291 ! DIMENSION: Scalar
292 !
293 !:sdoc-:
294 !--------------------------------------------------------------------------------
295 
296  FUNCTION zeeman_input_isvalid( z ) RESULT( IsValid )
297  TYPE(zeeman_input_type), INTENT(IN) :: z
298  LOGICAL :: isvalid
299  CHARACTER(*), PARAMETER :: routine_name = 'Zeeman_Input_IsValid'
300 !!!
301 real(fp), parameter :: big_number = 1.0e+09_fp
302 !!!
303  CHARACTER(ML) :: msg
304 
305  ! Setup
306  isvalid = .true.
307 
308  ! Check components
309  IF ( z%Be < zero ) THEN
310  msg = 'Invalid field strength'
311  CALL display_message( routine_name, trim(msg), information )
312  isvalid = .false.
313  END IF
314  IF ( z%Cos_ThetaB > big_number ) THEN
315  msg = 'Invalid COS(ThetaB)'
316  CALL display_message( routine_name, trim(msg), information )
317  isvalid = .false.
318  END IF
319  IF ( z%Cos_PhiB > big_number ) THEN
320  msg = 'Invalid COS(PhiB)'
321  CALL display_message( routine_name, trim(msg), information )
322  isvalid = .false.
323  END IF
324  IF ( abs(z%Doppler_Shift) > big_number ) THEN
325  msg = 'Invalid Doppler shift'
326  CALL display_message( routine_name, trim(msg), information )
327  isvalid = .false.
328  END IF
329 
330  END FUNCTION zeeman_input_isvalid
331 
332 
333 !--------------------------------------------------------------------------------
334 !:sdoc+:
335 !
336 ! NAME:
337 ! Zeeman_Input_Inspect
338 !
339 ! PURPOSE:
340 ! Subroutine to print the contents of an Zeeman_Input object to stdout.
341 !
342 ! CALLING SEQUENCE:
343 ! CALL Zeeman_Input_Inspect( z )
344 !
345 ! INPUTS:
346 ! z: Zeeman_Input object to display.
347 ! UNITS: N/A
348 ! TYPE: Zeeman_Input_type
349 ! DIMENSION: Scalar
350 ! ATTRIBUTES: INTENT(IN)
351 !
352 !:sdoc-:
353 !--------------------------------------------------------------------------------
354 
355  SUBROUTINE zeeman_input_inspect(z)
356  TYPE(zeeman_input_type), INTENT(IN) :: z
357  WRITE(*,'(3x,"Zeeman_Input OBJECT")')
358  WRITE(*,'(5x,"Field strength (gauss):",1x,es22.15)') z%Be
359  WRITE(*,'(5x,"COS(ThetaB) :",1x,es22.15)') z%Cos_ThetaB
360  WRITE(*,'(5x,"COS(PhiB) :",1x,es22.15)') z%Cos_PhiB
361  WRITE(*,'(5x,"Doppler shift (KHz) :",1x,es22.15)') z%Doppler_Shift
362  END SUBROUTINE zeeman_input_inspect
363 
364 
365 !--------------------------------------------------------------------------------
366 !:sdoc+:
367 !
368 ! NAME:
369 ! Zeeman_Input_DefineVersion
370 !
371 ! PURPOSE:
372 ! Subroutine to return the module version information.
373 !
374 ! CALLING SEQUENCE:
375 ! CALL Zeeman_Input_DefineVersion( Id )
376 !
377 ! OUTPUTS:
378 ! Id: Character string containing the version Id information
379 ! for the module.
380 ! UNITS: N/A
381 ! TYPE: CHARACTER(*)
382 ! DIMENSION: Scalar
383 ! ATTRIBUTES: INTENT(OUT)
384 !
385 !:sdoc-:
386 !--------------------------------------------------------------------------------
387 
388  SUBROUTINE zeeman_input_defineversion( Id )
389  CHARACTER(*), INTENT(OUT) :: id
390  id = module_version_id
391  END SUBROUTINE zeeman_input_defineversion
392 
393 
394 !----------------------------------------------------------------------------------
395 !:sdoc+:
396 !
397 ! NAME:
398 ! Zeeman_Input_ValidRelease
399 !
400 ! PURPOSE:
401 ! Function to check the Zeeman_Input Release value.
402 !
403 ! CALLING SEQUENCE:
404 ! IsValid = Zeeman_Input_ValidRelease( Zeeman_Input )
405 !
406 ! INPUTS:
407 ! Zeeman_Input: Zeeman_Input object for which the Release component
408 ! is to be checked.
409 ! UNITS: N/A
410 ! TYPE: Zeeman_Input_type
411 ! DIMENSION: Scalar
412 ! ATTRIBUTES: INTENT(IN)
413 !
414 ! FUNCTION RESULT:
415 ! IsValid: Logical value defining the release validity.
416 ! UNITS: N/A
417 ! TYPE: LOGICAL
418 ! DIMENSION: Scalar
419 !
420 !:sdoc-:
421 !----------------------------------------------------------------------------------
422 
423  FUNCTION zeeman_input_validrelease( self ) RESULT( IsValid )
424  ! Arguments
425  TYPE(zeeman_input_type), INTENT(IN) :: self
426  ! Function result
427  LOGICAL :: isvalid
428  ! Local parameters
429  CHARACTER(*), PARAMETER :: routine_name = 'Zeeman_Input_ValidRelease'
430  ! Local variables
431  CHARACTER(ML) :: msg
432 
433  ! Set up
434  isvalid = .true.
435 
436 
437  ! Check release is not too old
438  IF ( self%Release < zeeman_input_release ) THEN
439  isvalid = .false.
440  WRITE( msg,'("An Zeeman_Input data update is needed. ", &
441  &"Zeeman_Input release is ",i0,". Valid release is ",i0,"." )' ) &
442  self%Release, zeeman_input_release
443  CALL display_message( routine_name, msg, information ); RETURN
444  END IF
445 
446 
447  ! Check release is not too new
448  IF ( self%Release > zeeman_input_release ) THEN
449  isvalid = .false.
450  WRITE( msg,'("An Zeeman_Input software update is needed. ", &
451  &"Zeeman_Input release is ",i0,". Valid release is ",i0,"." )' ) &
452  self%Release, zeeman_input_release
453  CALL display_message( routine_name, msg, information ); RETURN
454  END IF
455 
456  END FUNCTION zeeman_input_validrelease
457 
458 
459 
460 !--------------------------------------------------------------------------------
461 !:sdoc+:
462 !
463 ! NAME:
464 ! Zeeman_Input_ReadFile
465 !
466 ! PURPOSE:
467 ! Function to read Zeeman_Input object files.
468 !
469 ! CALLING SEQUENCE:
470 ! Error_Status = Zeeman_Input_ReadFile( &
471 ! Zeeman_Input , &
472 ! Filename , &
473 ! No_Close = No_Close, &
474 ! Quiet = Quiet )
475 !
476 ! OBJECTS:
477 ! Zeeman_Input: Zeeman_Input object containing the data read from file.
478 ! UNITS: N/A
479 ! TYPE: Zeeman_Input_type
480 ! DIMENSION: Scalar
481 ! ATTRIBUTES: INTENT(OUT)
482 !
483 ! INPUTS:
484 ! Filename: Character string specifying the name of a
485 ! Zeeman_Input data file to read.
486 ! UNITS: N/A
487 ! TYPE: CHARACTER(*)
488 ! DIMENSION: Scalar
489 ! ATTRIBUTES: INTENT(IN)
490 !
491 ! OPTIONAL INPUTS:
492 ! No_Close: Set this logical argument to *NOT* close the datafile
493 ! upon exiting this routine. This option is required if
494 ! the Zeeman_Input data is embedded within another file.
495 ! If == .FALSE., File is closed upon function exit [DEFAULT].
496 ! == .TRUE., File is NOT closed upon function exit
497 ! If not specified, default is .FALSE.
498 ! UNITS: N/A
499 ! TYPE: LOGICAL
500 ! DIMENSION: Scalar
501 ! ATTRIBUTES: INTENT(IN), OPTIONAL
502 !
503 ! Quiet: Set this logical argument to suppress INFORMATION
504 ! messages being printed to stdout
505 ! If == .FALSE., INFORMATION messages are OUTPUT [DEFAULT].
506 ! == .TRUE., INFORMATION messages are SUPPRESSED.
507 ! If not specified, default is .FALSE.
508 ! UNITS: N/A
509 ! TYPE: LOGICAL
510 ! DIMENSION: Scalar
511 ! ATTRIBUTES: INTENT(IN), OPTIONAL
512 !
513 ! FUNCTION RESULT:
514 ! Error_Status: The return value is an integer defining the error status.
515 ! The error codes are defined in the Message_Handler module.
516 ! If == SUCCESS, the file read was successful
517 ! == FAILURE, an unrecoverable error occurred.
518 ! UNITS: N/A
519 ! TYPE: INTEGER
520 ! DIMENSION: Scalar
521 !
522 !:sdoc-:
523 !------------------------------------------------------------------------------
524 
525  FUNCTION zeeman_input_readfile( &
526  Zeeman_Input, & ! Output
527  Filename , & ! Input
528  No_Close , & ! Optional input
529  Quiet , & ! Optional input
530  Title , & ! Optional output
531  History , & ! Optional output
532  Comment , & ! Optional output
533  Debug ) & ! Optional input (Debug output control)
534  result( err_stat )
535  ! Arguments
536  TYPE(zeeman_input_type), INTENT(OUT) :: zeeman_input
537  CHARACTER(*), INTENT(IN) :: filename
538  LOGICAL, OPTIONAL, INTENT(IN) :: no_close
539  LOGICAL, OPTIONAL, INTENT(IN) :: quiet
540  CHARACTER(*), OPTIONAL, INTENT(OUT) :: title
541  CHARACTER(*), OPTIONAL, INTENT(OUT) :: history
542  CHARACTER(*), OPTIONAL, INTENT(OUT) :: comment
543  LOGICAL, OPTIONAL, INTENT(IN) :: debug
544  ! Function result
545  INTEGER :: err_stat
546  ! Function parameters
547  CHARACTER(*), PARAMETER :: routine_name = 'Zeeman_Input_ReadFile'
548  ! Function variables
549  CHARACTER(ML) :: msg
550  CHARACTER(ML) :: io_msg
551  LOGICAL :: close_file
552  LOGICAL :: noisy
553  INTEGER :: io_stat
554  INTEGER :: fid
555  TYPE(zeeman_input_type) :: dummy
556 
557  ! Setup
558  err_stat = success
559  ! ...Check No_Close argument
560  close_file = .true.
561  IF ( PRESENT(no_close) ) close_file = .NOT. no_close
562  ! ...Check Quiet argument
563  noisy = .true.
564  IF ( PRESENT(quiet) ) noisy = .NOT. quiet
565  ! ...Override Quiet settings if debug set.
566  IF ( PRESENT(debug) ) THEN
567  IF ( debug ) noisy = .true.
568  END IF
569 
570 
571  ! Check if the file is open.
572  IF ( file_open( filename ) ) THEN
573  ! ...Inquire for the logical unit number
574  INQUIRE( file=filename, number=fid )
575  ! ...Ensure it's valid
576  IF ( fid < 0 ) THEN
577  msg = 'Error inquiring '//trim(filename)//' for its FileID'
578  CALL read_cleanup(); RETURN
579  END IF
580  ELSE
581  ! ...Open the file if it exists
582  IF ( file_exists( filename ) ) THEN
583  err_stat = open_binary_file( filename, fid )
584  IF ( err_stat /= success ) THEN
585  msg = 'Error opening '//trim(filename)
586  CALL read_cleanup(); RETURN
587  END IF
588  ELSE
589  msg = 'File '//trim(filename)//' not found.'
590  CALL read_cleanup(); RETURN
591  END IF
592  END IF
593 
594 
595  ! Read and check the release and version
596  READ( fid, iostat=io_stat, iomsg=io_msg ) &
597  dummy%Release, &
598  dummy%Version
599  IF ( io_stat /= 0 ) THEN
600  msg = 'Error reading Release/Version - '//trim(io_msg)
601  CALL read_cleanup(); RETURN
602  END IF
603  IF ( .NOT. zeeman_input_validrelease( dummy ) ) THEN
604  msg = 'Zeeman_Input Release check failed.'
605  CALL read_cleanup(); RETURN
606  END IF
607  ! ...Explicitly assign the version number
608  zeeman_input%Version = dummy%Version
609 
610 
611  ! Read the global attributes
612  err_stat = readgatts_binary_file( &
613  fid, &
614  title = title , &
615  history = history, &
616  comment = comment )
617  IF ( err_stat /= success ) THEN
618  msg = 'Error reading global attributes'
619  CALL read_cleanup(); RETURN
620  END IF
621 
622 
623  ! Read the scalars
624  READ( fid, iostat=io_stat, iomsg=io_msg ) &
625  zeeman_input%Be , &
626  zeeman_input%Cos_ThetaB , &
627  zeeman_input%Cos_PhiB , &
628  zeeman_input%Doppler_Shift
629  IF ( io_stat /= 0 ) THEN
630  msg = 'Error reading data - '//trim(io_msg)
631  CALL read_cleanup(); RETURN
632  END IF
633 
634 
635  ! Close the file
636  IF ( close_file ) THEN
637  CLOSE( fid, iostat=io_stat, iomsg=io_msg )
638  IF ( io_stat /= 0 ) THEN
639  msg = 'Error closing '//trim(filename)//' - '//trim(io_msg)
640  CALL read_cleanup(); RETURN
641  END IF
642  END IF
643 
644  CONTAINS
645 
646  SUBROUTINE read_cleanup()
647  IF ( file_open(filename) ) THEN
648  CLOSE( fid, iostat=io_stat, iomsg=io_msg )
649  IF ( io_stat /= 0 ) &
650  msg = trim(msg)//'; Error closing input file during error cleanup - '//trim(io_msg)
651  END IF
652  err_stat = failure
653  CALL display_message( routine_name, msg, err_stat )
654  END SUBROUTINE read_cleanup
655 
656  END FUNCTION zeeman_input_readfile
657 
658 
659 !--------------------------------------------------------------------------------
660 !:sdoc+:
661 !
662 ! NAME:
663 ! Zeeman_Input_WriteFile
664 !
665 ! PURPOSE:
666 ! Function to write Zeeman_Input object files.
667 !
668 ! CALLING SEQUENCE:
669 ! Error_Status = Zeeman_Input_WriteFile( &
670 ! Zeeman_Input , &
671 ! Filename , &
672 ! No_Close = No_Close, &
673 ! Quiet = Quiet )
674 !
675 ! OBJECTS:
676 ! Zeeman_Input: Zeeman_Input object containing the data to write to file.
677 ! UNITS: N/A
678 ! TYPE: Zeeman_Input_type
679 ! DIMENSION: Scalar
680 ! ATTRIBUTES: INTENT(IN)
681 !
682 ! INPUTS:
683 ! Filename: Character string specifying the name of a
684 ! Zeeman_Input format data file to write.
685 ! UNITS: N/A
686 ! TYPE: CHARACTER(*)
687 ! DIMENSION: Scalar
688 ! ATTRIBUTES: INTENT(IN)
689 !
690 ! OPTIONAL INPUTS:
691 ! No_Close: Set this logical argument to *NOT* close the datafile
692 ! upon exiting this routine. This option is required if
693 ! the Zeeman_Input data is to be embedded within another file.
694 ! If == .FALSE., File is closed upon function exit [DEFAULT].
695 ! == .TRUE., File is NOT closed upon function exit
696 ! If not specified, default is .FALSE.
697 ! UNITS: N/A
698 ! TYPE: LOGICAL
699 ! DIMENSION: Scalar
700 ! ATTRIBUTES: INTENT(IN), OPTIONAL
701 !
702 ! Quiet: Set this logical argument to suppress INFORMATION
703 ! messages being printed to stdout
704 ! If == .FALSE., INFORMATION messages are OUTPUT [DEFAULT].
705 ! == .TRUE., INFORMATION messages are SUPPRESSED.
706 ! If not specified, default is .FALSE.
707 ! UNITS: N/A
708 ! TYPE: LOGICAL
709 ! DIMENSION: Scalar
710 ! ATTRIBUTES: INTENT(IN), OPTIONAL
711 !
712 ! FUNCTION RESULT:
713 ! Error_Status: The return value is an integer defining the error status.
714 ! The error codes are defined in the Message_Handler module.
715 ! If == SUCCESS, the file write was successful
716 ! == FAILURE, an unrecoverable error occurred.
717 ! UNITS: N/A
718 ! TYPE: INTEGER
719 ! DIMENSION: Scalar
720 !
721 !:sdoc-:
722 !------------------------------------------------------------------------------
723 
724  FUNCTION zeeman_input_writefile( &
725  Zeeman_Input, & ! Input
726  Filename , & ! Input
727  No_Close , & ! Optional input
728  Quiet , & ! Optional input
729  Title , & ! Optional input
730  History , & ! Optional input
731  Comment , & ! Optional input
732  Debug ) & ! Optional input (Debug output control)
733  result( err_stat )
734  ! Arguments
735  TYPE(zeeman_input_type), INTENT(IN) :: zeeman_input
736  CHARACTER(*), INTENT(IN) :: filename
737  LOGICAL, OPTIONAL, INTENT(IN) :: no_close
738  LOGICAL, OPTIONAL, INTENT(IN) :: quiet
739  CHARACTER(*), OPTIONAL, INTENT(IN) :: title
740  CHARACTER(*), OPTIONAL, INTENT(IN) :: history
741  CHARACTER(*), OPTIONAL, INTENT(IN) :: comment
742  LOGICAL, OPTIONAL, INTENT(IN) :: debug
743  ! Function result
744  INTEGER :: err_stat
745  ! Function parameters
746  CHARACTER(*), PARAMETER :: routine_name = 'Zeeman_Input_WriteFile'
747  ! Function variables
748  CHARACTER(ML) :: msg
749  CHARACTER(ML) :: io_msg
750  LOGICAL :: close_file
751  LOGICAL :: noisy
752  INTEGER :: io_stat
753  INTEGER :: fid
754 
755 
756  ! Setup
757  err_stat = success
758  ! ...Check No_Close argument
759  close_file = .true.
760  IF ( PRESENT(no_close) ) close_file = .NOT. no_close
761  ! ...Check Quiet argument
762  noisy = .true.
763  IF ( PRESENT(quiet) ) noisy = .NOT. quiet
764  ! ...Override Quiet settings if debug set.
765  IF ( PRESENT(debug) ) THEN
766  IF ( debug ) noisy = .true.
767  END IF
768 
769 
770  ! Check if the file is open.
771  IF ( file_open( filename ) ) THEN
772  ! ...Inquire for the logical unit number
773  INQUIRE( file=filename, number=fid )
774  ! ...Ensure it's valid
775  IF ( fid < 0 ) THEN
776  msg = 'Error inquiring '//trim(filename)//' for its FileID'
777  CALL write_cleanup(); RETURN
778  END IF
779  ELSE
780  ! ...Open the file for output
781  err_stat = open_binary_file( filename, fid, for_output=.true. )
782  IF ( err_stat /= success ) THEN
783  msg = 'Error opening '//trim(filename)
784  CALL write_cleanup(); RETURN
785  END IF
786  END IF
787 
788 
789  ! Write the release and version
790  WRITE( fid, iostat=io_stat, iomsg=io_msg ) &
791  zeeman_input%Release, &
792  zeeman_input%Version
793  IF ( io_stat /= 0 ) THEN
794  msg = 'Error writing Release/Version - '//trim(io_msg)
795  CALL write_cleanup(); RETURN
796  END IF
797 
798 
799  ! Write the global attributes
800  err_stat = writegatts_binary_file( &
801  fid, &
802  write_module = module_version_id, &
803  title = title , &
804  history = history, &
805  comment = comment )
806  IF ( err_stat /= success ) THEN
807  msg = 'Error writing global attributes'
808  CALL write_cleanup(); RETURN
809  END IF
810 
811 
812  ! Write the scalars
813  WRITE( fid, iostat=io_stat, iomsg=io_msg ) &
814  zeeman_input%Be , &
815  zeeman_input%Cos_ThetaB , &
816  zeeman_input%Cos_PhiB , &
817  zeeman_input%Doppler_Shift
818  IF ( io_stat /= 0 ) THEN
819  msg = 'Error writing data - '//trim(io_msg)
820  CALL write_cleanup(); RETURN
821  END IF
822 
823 
824  ! Close the file
825  IF ( close_file ) THEN
826  CLOSE( fid, iostat=io_stat, iomsg=io_msg )
827  IF ( io_stat /= 0 ) THEN
828  msg = 'Error closing '//trim(filename)//' - '//trim(io_msg)
829  CALL write_cleanup(); RETURN
830  END IF
831  END IF
832 
833  CONTAINS
834 
835  SUBROUTINE write_cleanup()
836  IF ( file_open(filename) ) THEN
837  CLOSE( fid, iostat=io_stat, iomsg=io_msg )
838  IF ( io_stat /= 0 ) &
839  msg = trim(msg)//'; Error closing output file during error cleanup - '//trim(io_msg)
840  END IF
841  err_stat = failure
842  CALL display_message( routine_name, msg, err_stat )
843  END SUBROUTINE write_cleanup
844 
845  END FUNCTION zeeman_input_writefile
846 
847 
848 
849 !################################################################################
850 !################################################################################
851 !## ##
852 !## ## PRIVATE MODULE ROUTINES ## ##
853 !## ##
854 !################################################################################
855 !################################################################################
856 
857  ELEMENTAL FUNCTION zeeman_input_equal(x, y) RESULT(is_equal)
858  TYPE(zeeman_input_type), INTENT(IN) :: x, y
859  LOGICAL :: is_equal
860  is_equal = (x%Be .equalto. y%Be ) .AND. &
861  (x%Cos_ThetaB .equalto. y%Cos_ThetaB ) .AND. &
862  (x%Cos_PhiB .equalto. y%Cos_PhiB ) .AND. &
863  (x%Doppler_Shift .equalto. y%Doppler_Shift)
864  END FUNCTION zeeman_input_equal
865 
866 END MODULE zeeman_input_define
integer function, public zeeman_input_writefile(Zeeman_Input, Filename, No_Close, Quiet, Title, History, Comment, Debug)
integer, parameter zeeman_input_release
integer, parameter, public failure
logical function, public zeeman_input_isvalid(z)
real(fp), parameter, public zero
integer, parameter, public long
Definition: Type_Kinds.f90:76
subroutine, public zeeman_input_defineversion(Id)
integer, parameter, public fp
Definition: Type_Kinds.f90:124
integer function, public readgatts_binary_file(fid, Write_Module, Created_On, Title, History, Comment)
elemental logical function zeeman_input_equal(x, y)
integer, parameter, public double
Definition: Type_Kinds.f90:106
subroutine read_cleanup()
subroutine write_cleanup()
character(*), parameter write_error_status
integer function, public open_binary_file(Filename, FileID, For_Output, No_Check)
recursive subroutine, public display_message(Routine_Name, Message, Error_State, Message_Log)
elemental subroutine, public zeeman_input_getvalue(Zeeman_Input, Field_Strength, Cos_ThetaB, Cos_PhiB, Doppler_Shift)
integer, parameter ml
integer, parameter zeeman_input_version
integer function, public zeeman_input_readfile(Zeeman_Input, Filename, No_Close, Quiet, Title, History, Comment, Debug)
integer function, public writegatts_binary_file(fid, Write_Module, Created_On, Title, History, Comment)
elemental subroutine, public zeeman_input_setvalue(Zeeman_Input, Field_Strength, Cos_ThetaB, Cos_PhiB, Doppler_Shift)
real(double), parameter default_magentic_field
character(*), parameter, private module_version_id
logical function, public zeeman_input_validrelease(self)
integer, parameter, public success
integer, parameter, public information
subroutine, public zeeman_input_inspect(z)