source: trunk/LMDZ.TITAN/utilities/prepare_startkim.bash @ 3026

Last change on this file since 3026 was 1898, checked in by jvatant, 7 years ago

Making chemistry handling more flexible - final step for all concerning startfi files
+ Added the vert_regrid_kim.F90 regriding upper fields and chemistry tracers if needed
in the newstart according to the new pressure grid
+ Fix some typos from lasts commit
( e.g. missing init of tracer_surf names in lect_start_archive )
--JVO

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/bin/bash
2
3################################################################################
4#
5# Author : Jan Vatant d'Ollone (2018)
6# ------
7#
8# Purpose : * Modify Titan startfi.nc files to fill them with upper chemistry
9# -------   fields from old comp_XX files that were used in ye old days with
10#           a 32x48x55 GCM grid which implied 70 upper levels.
11#
12#           * You can either just fill the fields or create them if needed
13#
14#           * Allows you to do the same for pressure grid "preskim" field :
15#            just give a vertical grid as second input file !i
16#
17#           * You need to run it in a folder containing comp_01->49 files !
18#
19#           * Requirements : NCO tool ncap2
20#
21# Inputs  : $1 : startfi.nc file
22# ------
23#          $2 (optional) : upper mid-layers pressure grid ASCII file
24#          NB : It should be 1D with decreasing pressure
25#
26# Execution exemple : ./prepare_startkim.bash startfi.nc preskim.dat
27# -----------------
28#
29# Approx. run time ~ 1h30-2h
30# ----------------
31#
32###############################################################################
33
34ncfile="$1" # startfi.nc file
35
36tmpfile="tmp" # temporary file
37
38
39# User choice :
40# * 1 Create upper chemistry dimension and fields
41# * 2 Just fill them, assuming you already have them in file
42
43while true; do
44    read -p "Choose : - 1 - Create upper chemistry dimension and fields - 2 - Just fill fields assuming they pre-exist : " yn
45    case $yn in
46        [1]* ) echo "Ok I will create dimension upper_chemistry_layers=70 and upper chemistry fields..." ; create=true ; break ;;
47        [2]* ) echo "Ok I assume you have upper chemistry fields in startfi.nc file, I will just fill them..."; create=false; break ;;
48        * ) echo "Please enter 1 or 2 !";;
49    esac
50done
51
52# If needed, we create the 70 levels dimension in the startfi.nc file
53
54if [ "$create" = true ] ; then
55    echo "I add to startfi a upper_chemistry_layers=70 dimension ..."
56    ncap2 -s 'defdim("upper_chemistry_layers",70)' -O $ncfile
57fi
58
59# If a second argument is given it will create and fill preskim
60
61if [ -z "$2" ] ; then
62    echo " No second argument found, skipping pressure grid stuff ... "
63else
64    presfile="$2"
65    if [ "$create" = true ] ; then
66        echo "I create an empty preskim field..."
67        ncap2 -s 'preskim[$upper_chemistry_layers]=0.0;preskim@title="Upper chemistry mid-layer pressure"' $ncfile
68    fi
69
70    echo "I fill preskim field with input profile ..."
71    i=0
72    while read -r pres
73    do
74        ncap2 -s "preskim($i)=$pres" -h -A $ncfile
75        i=$((i+1))
76    done < "$presfile"
77fi
78
79# Loop on all 44 Titan chemistry species
80echo "Starting loop on all 44 Titan chemistry species ..."
81for ((iq=1;iq<=44;iq++)) ; do
82   
83    # First calculates lines where specie name and values are written in old comp file
84    qline=$(( 2 + 71*$((iq-1)) )) # Specie name
85   
86    qdeb=$((qline+1))              # First line of composition for this specie
87    qend=$((qline+70))             # Last   "   "     "         "   "    "
88   
89    specie=$(sed -n "${qline}p" comp_01) # Read specie name
90    specie=$(echo $specie) # Trim it
91   
92    echo $specie
93
94    # Create field if needed
95    if [ "$create" = true ] ; then
96        echo "I create an empty upper chemistry field for", $specie
97        ncap2 -s "${specie}_up[$upper_chemistry_layers,$physical_points]=0.0;${specie}_up@title='${specie} in upper atmosphere'" $ncfile
98    fi
99   
100    # Loop on latitudes
101   
102    for ((ilat=1;ilat<=49;ilat++)) ; do
103       
104        # Deal with comp_0X filenames
105        if [ $ilat -lt 10 ] ; then 
106            lat=0$ilat
107        else
108            lat=$ilat
109        fi
110
111        # Extract the current specie section in latitude file
112        sed -n "${qdeb},${qend}p" comp_$lat > tmp
113       
114        i=0
115       
116        echo "Filling : " $specie "-" comp_$lat
117
118        # Deal with special mono-gridpoint for North and South Poles
119        if [ $ilat -eq 1 ] ; then
120            ngrid0=0
121            ngrid1=0
122        elif [ $lat -eq 49 ] ; then
123            ngrid0=1505
124            ngrid1=1505
125        else
126            ngrid0=$((1+$(($ilat-2))*32))
127            ngrid1=$(($ngrid0+31))
128        fi
129       
130        # Read tmp file and fill the grid points
131        while read -r dum1 dum2 ykim
132        do
133            ncap2 -s "${specie}_up($i,$ngrid0:$ngrid1)=$ykim" -h -A $ncfile
134            i=$((i+1))
135        done < "$tmpfile"
136
137    done # Latitude loop
138
139    rm tmp
140
141done # Specie loop
142
143echo "Everything's finished !"
Note: See TracBrowser for help on using the repository browser.