c kspectrum (http://www.meso-star.com/en_Products.html) - This file is part of kspectrum c Copyright (C) 2008-2015 - Méso-Star - Vincent Eymet c c This file must be used under the terms of the CeCILL license. c This source file is licensed as described in the file COPYING, which c you should have received as part of this distribution. The terms c are also available at c http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt c subroutine read_molparam(input_file, & Nmol,mol_index,mol_niso,mol_name, & iso_index,iso_abundance,iso_Qref,iso_g,iso_mass) implicit none include 'max.inc' include 'formats.inc' c c Purpose: to read the 'molparam.txt' file c c Inputs: c + input_file: molparam file to read c c Ouputs: c + Nmol: number of molecules used in the HITRAN04.par database c + mol_index(mol) is the index of the molecule (index 'mol') used in the HITRAN04.par database c + mol_niso(mol) is the number of isotopes for molecule index 'mol' c + mol_name(mol) is a character string that describes molecule 'mol' c + iso_index(mol,iso) is the index (used in the "molparam.txt" file) of the isotope index 'iso' for molecule index 'mol' c + iso_abundance(mol,iso) is the abundance of isotope 'iso' for molecule 'mol' c + iso_Qref(mol,iso) are reference (@ T=Tref) partition functions c + iso_g(mol,iso) are state independent degeneracy factors c + iso_mass(mol,iso) are molar masses [g/mol] c c I/O character*(Nchar_mx) input_file integer Nmol integer mol_index(1:Nmol_max) integer mol_niso(1:Nmol_max) character*10 mol_name(1:Nmol_max) integer iso_index(1:Nmol_max,1:Niso_max) double precision iso_abundance(1:Nmol_max,1:Niso_max) double precision iso_Qref(1:Nmol_max,1:Niso_max) integer iso_g(1:Nmol_max,1:Niso_max) double precision iso_mass(1:Nmol_max,1:Niso_max) c temp integer nl,i,ncm,mol,iso,ios integer line_index(1:Nmol_max) character*(Nchar_mx) line,nlines_file character*(Nchar_mx) file_out character*1 spch c label integer strlen character*(Nchar_mx) label label='subroutine read_molparam' ncm=50 nlines_file='./nlines' call get_nlines(input_file,nlines_file,nl) open(10,file=input_file(1:strlen(input_file)), & status='old',iostat=ios) if (ios.ne.0) then ! file not found write(*,*) 'Error from routine read_composition:' write(*,*) 'Data file could not be found:' write(*,*) input_file(1:strlen(input_file)) stop endif read(10,*) Nmol=0 do i=2,nl-1 read(10,10) line if (strlen(line).lt.ncm) then Nmol=Nmol+1 if (Nmol.gt.Nmol_max) then call error(label) write(*,*) 'Nmol=',Nmol write(*,*) 'while Nmol_max=',Nmol_max stop endif line_index(Nmol)=i endif enddo ! i rewind(10) mol=0 read(10,*) c Debug c write(*,*) 'Nmol=',Nmol c stop c do i=1,Nmol c write(*,*) 'line_index(',i,')=',line_index(i) c enddo c Debug do i=2,nl c Debug c write(*,*) 'reading line i=',i c Debug if (i.eq.line_index(mol+1)) then read(10,10) line c Debug c write(*,*) line(1:strlen(line)) c Debug mol=mol+1 call get_mnami(line,mol_name(mol),mol_index(mol)) c Debug c write(*,*) 'mol_name(',mol,')="', c & mol_name(mol)(1:strlen(mol_name(mol))), c & '" mol_index(',mol,')=',mol_index(mol) c Debug if (mol-1.ge.1) then mol_niso(mol-1)=iso c Debug c write(*,*) 'mol_niso(',mol-1,')=',mol_niso(mol-1) c Debug endif iso=0 else iso=iso+1 if (iso.gt.Niso_max) then call error(label) write(*,*) 'mol=',mol,' iso=',iso write(*,*) 'while Niso_max=',Niso_max stop endif read(10,62) iso_index(mol,iso),iso_abundance(mol,iso) & ,iso_Qref(mol,iso),iso_g(mol,iso),iso_mass(mol,iso) endif if (i.eq.nl) then mol_niso(Nmol)=iso endif enddo ! i close(10) return end subroutine get_mnami(line,name,index) implicit none include 'max.inc' include 'formats.inc' integer strlen integer index,i,i1,i2,i3,i4,i1f,i2f,i3f,i4f integer n,num character*10 name character*(Nchar_mx) line character*1 spch,ch1,ch2,str i1f=0 i2f=0 i3f=0 i4f=0 write(spch,21) ' ' write(ch1,21) '(' write(ch2,21) ')' do i=1,strlen(line) if ((line(i:i).ne.spch).and.(i1f.eq.0)) then i1=i i1f=1 endif if ((line(i:i).eq.spch).and.(i1f.eq.1).and.(i2f.eq.0)) then i2=i-1 i2f=1 endif if ((line(i:i).eq.ch1).and.(i3f.eq.0)) then i3=i+1 i3f=1 endif if ((line(i:i).eq.ch2).and.(i4f.eq.0).and.(i3f.eq.1)) then i4=i-1 i4f=1 endif enddo ! i name=line(i1:i2) index=0 n=i4-i3+1 do i=1,n str=line(i3+i-1:i3+i-1) call StrToNum(str,num) index=index+num*10**(n-i) enddo return end subroutine StrToNum(str,num) implicit none include 'max.inc' character*1 str integer num if (str.eq."0") then num=0 else if (str.eq."1") then num=1 else if (str.eq."2") then num=2 else if (str.eq."3") then num=3 else if (str.eq."4") then num=4 else if (str.eq."5") then num=5 else if (str.eq."6") then num=6 else if (str.eq."7") then num=7 else if (str.eq."8") then num=8 else if (str.eq."9") then num=9 else write(*,*) 'StrToNum could not convert: "',str,'"' stop endif return end