Index: trunk/src/readcommand.f90
===================================================================
--- trunk/src/readcommand.f90	(revision 24)
+++ trunk/src/readcommand.f90	(revision 27)
@@ -29,4 +29,6 @@
   !                                                                            *
   !     18 May 1996                                                            *
+  !     HSO, 1 July 2014                                                       *
+  !     Added optional namelist input                                          *
   !                                                                            *
   !*****************************************************************************
@@ -80,5 +82,4 @@
   character(len=50) :: line
   logical :: old
-  logical :: nml_COMMAND=.true. , nmlout=.true.  !.false.
   integer :: readerror
 
@@ -111,5 +112,5 @@
 
   ! Presetting namelist command
-  ldirect=1
+  ldirect=0
   ibdate=20000101
   ibtime=0
@@ -142,44 +143,14 @@
   ! Namelist input first: try to read as namelist file
   !**************************************************************************
-  open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old', &
-         form='formatted',iostat=readerror)
-   ! If fail, check if file does not exist
-   if (readerror.ne.0) then
-     print*,'***ERROR: file COMMAND not found in ' 
-     print*, path(1)(1:length(1))//'COMMAND'
-     print*, 'Check your pathnames file.'
-     stop
-   endif
-
-   ! print error code
-   !write(*,*) 'readcommand > readerror open=' , readerror
-   !probe first line  
-   read (unitcommand,901) line
-   !write(*,*) 'index(line,COMMAND) =', index(line,'COMMAND') 
-
+  open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old',form='formatted',err=999)
+
+  ! try namelist input (default)
+  read(unitcommand,command,iostat=readerror)
+  close(unitcommand)
+
+  ! distinguish namelist from fixed text input
+  if ((readerror.ne.0).or.(ldirect.eq.0)) then ! parse as text file format
  
-   !default is namelist input 
-   ! distinguish namelist from fixed text input
-   if (index(line,'COMMAND') .eq. 0) then
-   nml_COMMAND = .false. 
-   !write(*,*) 'COMMAND file does not contain the string COMMAND in the first line'      
-   endif
-   !write(*,*) 'readcommand > read as namelist? ' , nml_COMMAND
-   rewind(unitcommand)
-   read(unitcommand,command,iostat=readerror)
-
-  close(unitcommand)
-
-  !write(*,*) 'readcommand > readerror read=' , readerror
-  ! If error in namelist format, try to open with old input code
-  ! if (readerror.ne.0) then
-  ! IP 21/5/2014 the previous line cause the old long format 
-  ! to be confused with namelist input
-  
-  ! use text input 
-  if (nml_COMMAND .eqv. .false.) then 
-
-    open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old', &
-         err=999)
+    open(unitcommand,file=path(1)(1:length(1))//'COMMAND',status='old', err=999)
 
     ! Check the format of the COMMAND file (either in free format,
@@ -193,8 +164,8 @@
     if (index(line,'LDIRECT') .eq. 0) then
       old = .false.
-    !write(*,*) 'readcommand old short'
+      write(*,*) 'COMMAND in old short format, please update to namelist format'
     else
       old = .true.
-    !write(*,*) 'readcommand old long'
+      write(*,*) 'COMMAND in old long format, please update to namelist format'
     endif
     rewind(unitcommand)
@@ -206,5 +177,4 @@
     call skplin(7,unitcommand)
     if (old) call skplin(1,unitcommand)
-
     read(unitcommand,*) ldirect
     if (old) call skplin(3,unitcommand)
@@ -265,7 +235,4 @@
     write(unitcommand,nml=command)
     close(unitcommand)
-     ! open(unitheader,file=path(2)(1:length(2))//'header_nml',status='new',err=999)
-     ! write(unitheader,NML=COMMAND)
-     !close(unitheader) 
   endif
 
@@ -616,6 +583,6 @@
 
 1000   write(*,*) ' #### FLEXPART MODEL ERROR! FILE "COMMAND"    #### '
-       write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
-        write(*,'(a)') path(2)(1:length(1))
-        stop
+  write(*,*) ' #### CANNOT BE OPENED IN THE DIRECTORY       #### '
+  write(*,'(a)') path(2)(1:length(1))
+  stop
 end subroutine readcommand
